Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2021 6WIND S.A.
3 : : * Copyright 2021 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #ifndef RTE_PMD_MLX5_RX_H_
7 : : #define RTE_PMD_MLX5_RX_H_
8 : :
9 : : #include <stdint.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <rte_mbuf.h>
13 : : #include <rte_mempool.h>
14 : : #include <rte_common.h>
15 : : #include <rte_spinlock.h>
16 : :
17 : : #include <mlx5_common_mr.h>
18 : :
19 : : #include "mlx5.h"
20 : : #include "mlx5_autoconf.h"
21 : : #include "rte_pmd_mlx5.h"
22 : :
23 : : /* Support tunnel matching. */
24 : : #define MLX5_FLOW_TUNNEL 10
25 : : #define MLX5_WINOOO_BITS (sizeof(uint32_t) * CHAR_BIT)
26 : :
27 : : #define RXQ_PORT(rxq_ctrl) LIST_FIRST(&(rxq_ctrl)->owners)->priv
28 : : #define RXQ_DEV(rxq_ctrl) ETH_DEV(RXQ_PORT(rxq_ctrl))
29 : : #define RXQ_PORT_ID(rxq_ctrl) PORT_ID(RXQ_PORT(rxq_ctrl))
30 : :
31 : : /* First entry must be NULL for comparison. */
32 : : #define mlx5_mr_btree_len(bt) ((bt)->len - 1)
33 : :
34 : : struct mlx5_rxq_stat {
35 : : int id;
36 : : uint64_t count;
37 : : struct mlx5_stat_counter_ctrl ctrl;
38 : : };
39 : :
40 : : struct mlx5_rxq_stats {
41 : : #ifdef MLX5_PMD_SOFT_COUNTERS
42 : : uint64_t ipackets; /**< Total of successfully received packets. */
43 : : uint64_t ibytes; /**< Total of successfully received bytes. */
44 : : #endif
45 : : uint64_t idropped; /**< Total of packets dropped when RX ring full. */
46 : : uint64_t rx_nombuf; /**< Total of RX mbuf allocation failures. */
47 : : struct mlx5_rxq_stat oobs; /**< Total of hairpin queue out of buffers. */
48 : : };
49 : :
50 : : /* store statistics names and its offset in stats structure */
51 : : struct mlx5_xstats_name_off {
52 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
53 : : unsigned int offset;
54 : : };
55 : :
56 : : /* Only used with offsetof() for the xstats names table. */
57 : : struct mlx5_rq_stats {
58 : : /** Total number of hairpin queue packets received that are dropped. */
59 : : uint64_t q_oobs;
60 : : };
61 : :
62 : : /* Compressed CQE context. */
63 : : struct rxq_zip {
64 : : uint16_t cqe_cnt; /* Number of CQEs. */
65 : : uint16_t ai; /* Array index. */
66 : : uint32_t ca; /* Current array index. */
67 : : uint32_t na; /* Next array index. */
68 : : uint32_t cq_ci; /* The next CQE. */
69 : : uint16_t wqe_idx; /* WQE index */
70 : : };
71 : :
72 : : /* Get pointer to the first stride. */
73 : : #define mlx5_mprq_buf_addr(ptr, strd_n) (RTE_PTR_ADD((ptr), \
74 : : sizeof(struct mlx5_mprq_buf) + \
75 : : (strd_n) * \
76 : : sizeof(struct rte_mbuf_ext_shared_info) + \
77 : : RTE_PKTMBUF_HEADROOM))
78 : :
79 : : #define MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES 6
80 : : #define MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES 9
81 : :
82 : : enum mlx5_rxq_err_state {
83 : : MLX5_RXQ_ERR_STATE_NO_ERROR = 0,
84 : : MLX5_RXQ_ERR_STATE_NEED_RESET,
85 : : MLX5_RXQ_ERR_STATE_NEED_READY,
86 : : MLX5_RXQ_ERR_STATE_IGNORE,
87 : : };
88 : :
89 : : enum mlx5_rqx_code {
90 : : MLX5_RXQ_CODE_EXIT = 0,
91 : : MLX5_RXQ_CODE_NOMBUF,
92 : : MLX5_RXQ_CODE_DROPPED,
93 : : };
94 : :
95 : : struct mlx5_eth_rxseg {
96 : : struct rte_mempool *mp; /**< Memory pool to allocate segment from. */
97 : : uint16_t length; /**< Segment data length, configures split point. */
98 : : uint16_t offset; /**< Data offset from beginning of mbuf data buffer. */
99 : : uint32_t reserved; /**< Reserved field. */
100 : : struct rte_mbuf *null_mbuf; /**< For selective Rx. */
101 : : };
102 : :
103 : : /* RX queue descriptor. */
104 : : struct __rte_cache_aligned mlx5_rxq_data {
105 : : unsigned int csum:1; /* Enable checksum offloading. */
106 : : unsigned int hw_timestamp:1; /* Enable HW timestamp. */
107 : : unsigned int rt_timestamp:1; /* Realtime timestamp format. */
108 : : unsigned int vlan_strip:1; /* Enable VLAN stripping. */
109 : : unsigned int crc_present:1; /* CRC must be subtracted. */
110 : : unsigned int sges_n:3; /* Log 2 of SGEs (max buffers per packet). */
111 : : unsigned int cqe_n:4; /* Log 2 of CQ elements. */
112 : : unsigned int elts_n:4; /* Log 2 of Mbufs. */
113 : : unsigned int rss_hash:1; /* RSS hash result is enabled. */
114 : : unsigned int mark:1; /* Marked flow available on the queue. */
115 : : unsigned int log_strd_num:5; /* Log 2 of the number of stride. */
116 : : unsigned int log_strd_sz:4; /* Log 2 of stride size. */
117 : : unsigned int strd_shift_en:1; /* Enable 2bytes shift on a stride. */
118 : : unsigned int err_state:2; /* enum mlx5_rxq_err_state. */
119 : : unsigned int strd_scatter_en:1; /* Scattered packets from a stride. */
120 : : unsigned int lro:1; /* Enable LRO. */
121 : : unsigned int dynf_meta:1; /* Dynamic metadata is configured. */
122 : : unsigned int mcqe_format:3; /* CQE compression format. */
123 : : unsigned int shared:1; /* Shared RXQ. */
124 : : unsigned int delay_drop:1; /* Enable delay drop. */
125 : : unsigned int cqe_comp_layout:1; /* CQE Compression Layout*/
126 : : uint16_t port_id;
127 : : volatile uint32_t *rq_db;
128 : : volatile uint32_t *cq_db;
129 : : uint32_t elts_ci;
130 : : uint32_t rq_ci;
131 : : uint32_t rq_ci_ooo;
132 : : uint16_t consumed_strd; /* Number of consumed strides in WQE. */
133 : : uint32_t rq_pi;
134 : : uint32_t cq_ci:24;
135 : : uint16_t rq_repl_thresh; /* Threshold for buffer replenishment. */
136 : : uint32_t byte_mask;
137 : : union {
138 : : struct rxq_zip zip; /* Compressed context. */
139 : : uint16_t decompressed;
140 : : /* Number of ready mbufs decompressed from the CQ. */
141 : : };
142 : : struct mlx5_mr_ctrl mr_ctrl; /* MR control descriptor. */
143 : : uint16_t mprq_max_memcpy_len; /* Maximum size of packet to memcpy. */
144 : : volatile void *wqes;
145 : : volatile struct mlx5_cqe(*cqes)[];
146 : : struct mlx5_cqe title_cqe; /* Title CQE for CQE compression. */
147 : : struct rte_mbuf *(*elts)[];
148 : : struct rte_mbuf title_pkt; /* Title packet for CQE compression. */
149 : : struct mlx5_mprq_buf *(*mprq_bufs)[];
150 : : struct rte_mempool *mp;
151 : : struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */
152 : : struct mlx5_mprq_buf *mprq_repl; /* Stashed mbuf for replenish. */
153 : : struct mlx5_dev_ctx_shared *sh; /* Shared context. */
154 : : uint16_t idx; /* Queue index. */
155 : : struct mlx5_rxq_stats stats;
156 : : struct mlx5_rxq_stats stats_reset; /* stats on last reset. */
157 : : rte_xmm_t mbuf_initializer; /* Default rearm/flags for vectorized Rx. */
158 : : struct rte_mbuf fake_mbuf; /* elts padding for vectorized Rx. */
159 : : struct mlx5_uar_data uar_data; /* CQ doorbell. */
160 : : uint32_t cqn; /* CQ number. */
161 : : uint8_t cq_arm_sn; /* CQ arm seq number. */
162 : : uint64_t mark_flag; /* ol_flags to set with marks. */
163 : : uint32_t tunnel; /* Tunnel information. */
164 : : int timestamp_offset; /* Dynamic mbuf field for timestamp. */
165 : : uint64_t timestamp_rx_flag; /* Dynamic mbuf flag for timestamp. */
166 : : uint64_t flow_meta_mask;
167 : : int32_t flow_meta_offset;
168 : : uint32_t flow_meta_port_mask;
169 : : struct mlx5_eth_rxseg rxseg[MLX5_MAX_RXQ_NSEG];
170 : : /* Buffer split segment descriptions - sizes, offsets, pools. */
171 : : uint16_t rxseg_n; /* Number of split segment descriptions. */
172 : : uint16_t rq_win_cnt; /* Number of packets in the sliding window data. */
173 : : uint16_t rq_win_idx_mask; /* Sliding window index wrapping mask. */
174 : : uint16_t rq_win_idx; /* Index of the first element in sliding window. */
175 : : uint32_t *rq_win_data; /* Out-of-Order completions sliding window. */
176 : : };
177 : :
178 : : /* RX queue control descriptor. */
179 : : struct mlx5_rxq_ctrl {
180 : : struct mlx5_rxq_data rxq; /* Data path structure. */
181 : : uint16_t mtu; /* Original MTU that the queue was allocated with. */
182 : : LIST_ENTRY(mlx5_rxq_ctrl) next; /* Pointer to the next element. */
183 : : LIST_HEAD(priv, mlx5_rxq_priv) owners; /* Owner rxq list. */
184 : : struct mlx5_rxq_obj *obj; /* Verbs/DevX elements. */
185 : : struct mlx5_dev_ctx_shared *sh; /* Shared context. */
186 : : bool is_hairpin; /* Whether RxQ type is Hairpin. */
187 : : unsigned int socket; /* CPU socket ID for allocations. */
188 : : LIST_ENTRY(mlx5_rxq_ctrl) share_entry; /* Entry in shared RXQ list. */
189 : : RTE_ATOMIC(int32_t) ctrl_ref; /* Reference counter. */
190 : : uint32_t share_group; /* Group ID of shared RXQ. */
191 : : uint16_t share_qid; /* Shared RxQ ID in group. */
192 : : unsigned int started:1; /* Whether (shared) RXQ has been started. */
193 : : unsigned int irq:1; /* Whether IRQ is enabled. */
194 : : uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
195 : : uint32_t wqn; /* WQ number. */
196 : : struct rte_eth_rxseg_split rxseg[MLX5_MAX_RXQ_NSEG];
197 : : /* Saved original buffer split segment configuration. */
198 : : uint16_t rxseg_n; /* Number of split segment descriptions. */
199 : : uint16_t dump_file_n; /* Number of dump files. */
200 : : };
201 : :
202 : : /* RX queue private data. */
203 : : struct mlx5_rxq_priv {
204 : : uint16_t idx; /* Queue index. */
205 : : RTE_ATOMIC(uint32_t) refcnt; /* Reference counter. */
206 : : struct mlx5_rxq_ctrl *ctrl; /* Shared Rx Queue. */
207 : : LIST_ENTRY(mlx5_rxq_priv) owner_entry; /* Entry in shared rxq_ctrl. */
208 : : struct mlx5_priv *priv; /* Back pointer to private data. */
209 : : struct mlx5_devx_rq devx_rq;
210 : : struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
211 : : uint32_t hairpin_status; /* Hairpin binding status. */
212 : : uint32_t lwm:16;
213 : : uint32_t lwm_event_pending:1;
214 : : uint32_t lwm_devx_subscribed:1;
215 : : struct mlx5_devx_obj *q_counter; /* DevX hairpin queue counter object. */
216 : : };
217 : :
218 : : /* mlx5_rxq.c */
219 : :
220 : : extern uint8_t mlx5_rss_hash_default_key[];
221 : :
222 : : unsigned int mlx5_rxq_cqe_num(struct mlx5_rxq_data *rxq_data);
223 : : int mlx5_mprq_free_mp(struct rte_eth_dev *dev);
224 : : int mlx5_mprq_alloc_mp(struct rte_eth_dev *dev);
225 : : int mlx5_rx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id);
226 : : int mlx5_rx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id);
227 : : int mlx5_rx_queue_start_primary(struct rte_eth_dev *dev, uint16_t queue_id);
228 : : int mlx5_rx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t queue_id);
229 : : int mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
230 : : unsigned int socket, const struct rte_eth_rxconf *conf,
231 : : struct rte_mempool *mp);
232 : : int mlx5_rx_hairpin_queue_setup
233 : : (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
234 : : const struct rte_eth_hairpin_conf *hairpin_conf);
235 : : void mlx5_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
236 : : int mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev);
237 : : void mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev);
238 : : int mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
239 : : int mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
240 : : int mlx5_rxq_obj_verify(struct rte_eth_dev *dev);
241 : : void mlx5_q_counters_destroy(struct rte_eth_dev *dev);
242 : : struct mlx5_rxq_ctrl *mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx,
243 : : uint16_t desc, unsigned int socket,
244 : : const struct rte_eth_rxconf *conf,
245 : : const struct rte_eth_rxseg_split *rx_seg,
246 : : uint16_t n_seg, bool is_extmem);
247 : : struct mlx5_rxq_ctrl *mlx5_rxq_hairpin_new
248 : : (struct rte_eth_dev *dev, struct mlx5_rxq_priv *rxq, uint16_t desc,
249 : : const struct rte_eth_hairpin_conf *hairpin_conf);
250 : : struct mlx5_rxq_priv *mlx5_rxq_ref(struct rte_eth_dev *dev, uint16_t idx);
251 : : uint32_t mlx5_rxq_deref(struct rte_eth_dev *dev, uint16_t idx);
252 : : struct mlx5_rxq_priv *mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx);
253 : : struct mlx5_rxq_ctrl *mlx5_rxq_ctrl_get(struct rte_eth_dev *dev, uint16_t idx);
254 : : struct mlx5_rxq_data *mlx5_rxq_data_get(struct rte_eth_dev *dev, uint16_t idx);
255 : : struct mlx5_external_q *mlx5_ext_rxq_ref(struct rte_eth_dev *dev,
256 : : uint16_t idx);
257 : : uint32_t mlx5_ext_rxq_deref(struct rte_eth_dev *dev, uint16_t idx);
258 : : struct mlx5_external_q *mlx5_ext_rxq_get(struct rte_eth_dev *dev,
259 : : uint16_t idx);
260 : : int mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx);
261 : : int mlx5_rxq_verify(struct rte_eth_dev *dev);
262 : : int mlx5_ext_rxq_verify(struct rte_eth_dev *dev);
263 : : int mlx5_rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl);
264 : : int mlx5_ind_table_obj_verify(struct rte_eth_dev *dev);
265 : : struct mlx5_ind_table_obj *mlx5_ind_table_obj_get(struct rte_eth_dev *dev,
266 : : const uint16_t *queues,
267 : : uint32_t queues_n);
268 : : struct mlx5_ind_table_obj *mlx5_ind_table_obj_new(struct rte_eth_dev *dev,
269 : : const uint16_t *queues,
270 : : uint32_t queues_n,
271 : : bool standalone,
272 : : bool ref_qs);
273 : : int mlx5_ind_table_obj_release(struct rte_eth_dev *dev,
274 : : struct mlx5_ind_table_obj *ind_tbl,
275 : : bool deref_rxqs);
276 : : int mlx5_ind_table_obj_setup(struct rte_eth_dev *dev,
277 : : struct mlx5_ind_table_obj *ind_tbl,
278 : : bool ref_qs);
279 : : int mlx5_ind_table_obj_modify(struct rte_eth_dev *dev,
280 : : struct mlx5_ind_table_obj *ind_tbl,
281 : : uint16_t *queues, const uint32_t queues_n,
282 : : bool standalone,
283 : : bool ref_new_qs, bool deref_old_qs);
284 : : int mlx5_ind_table_obj_attach(struct rte_eth_dev *dev,
285 : : struct mlx5_ind_table_obj *ind_tbl);
286 : : int mlx5_ind_table_obj_detach(struct rte_eth_dev *dev,
287 : : struct mlx5_ind_table_obj *ind_tbl);
288 : : struct mlx5_list_entry *mlx5_hrxq_create_cb(void *tool_ctx, void *cb_ctx);
289 : : int mlx5_hrxq_match_cb(void *tool_ctx, struct mlx5_list_entry *entry,
290 : : void *cb_ctx);
291 : : void mlx5_hrxq_remove_cb(void *tool_ctx, struct mlx5_list_entry *entry);
292 : : struct mlx5_list_entry *mlx5_hrxq_clone_cb(void *tool_ctx,
293 : : struct mlx5_list_entry *entry,
294 : : void *cb_ctx __rte_unused);
295 : : void mlx5_hrxq_clone_free_cb(void *tool_ctx __rte_unused,
296 : : struct mlx5_list_entry *entry);
297 : : struct mlx5_hrxq *mlx5_hrxq_get(struct rte_eth_dev *dev,
298 : : struct mlx5_flow_rss_desc *rss_desc);
299 : : int mlx5_hrxq_obj_release(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq);
300 : : int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hxrq_idx);
301 : : uint32_t mlx5_hrxq_verify(struct rte_eth_dev *dev);
302 : : bool mlx5_rxq_is_hairpin(struct rte_eth_dev *dev, uint16_t idx);
303 : : const struct rte_eth_hairpin_conf *mlx5_rxq_get_hairpin_conf
304 : : (struct rte_eth_dev *dev, uint16_t idx);
305 : : struct mlx5_hrxq *mlx5_drop_action_create(struct rte_eth_dev *dev);
306 : : void mlx5_drop_action_destroy(struct rte_eth_dev *dev);
307 : : uint64_t mlx5_get_rx_port_offloads(void);
308 : : uint64_t mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev);
309 : : void mlx5_rxq_timestamp_set(struct rte_eth_dev *dev);
310 : : int mlx5_hrxq_modify(struct rte_eth_dev *dev, uint32_t hxrq_idx,
311 : : const uint8_t *rss_key, uint32_t rss_key_len,
312 : : uint64_t hash_fields, bool symmetric_hash_function,
313 : : const uint16_t *queues, uint32_t queues_n);
314 : :
315 : : /* mlx5_rx.c */
316 : :
317 : : uint16_t mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
318 : : uint16_t mlx5_rx_burst_out_of_order(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
319 : : int mlx5_rxq_initialize(struct mlx5_rxq_data *rxq);
320 : : __rte_noinline int mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec,
321 : : uint16_t err_n, uint16_t *skip_cnt);
322 : : void mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf);
323 : : uint16_t mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts,
324 : : uint16_t pkts_n);
325 : : int mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset);
326 : : int mlx5_rx_queue_count(void *rx_queue);
327 : : void mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
328 : : struct rte_eth_rxq_info *qinfo);
329 : : int mlx5_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
330 : : struct rte_eth_burst_mode *mode);
331 : : int mlx5_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc);
332 : : void mlx5_dev_interrupt_handler_lwm(void *args);
333 : : int mlx5_rx_queue_lwm_set(struct rte_eth_dev *dev, uint16_t rx_queue_id,
334 : : uint8_t lwm);
335 : : int mlx5_rx_queue_lwm_query(struct rte_eth_dev *dev, uint16_t *rx_queue_id,
336 : : uint8_t *lwm);
337 : :
338 : : /* Vectorized version of mlx5_rx.c */
339 : : int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data);
340 : : int mlx5_check_vec_rx_support(struct rte_eth_dev *dev);
341 : : uint16_t mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
342 : : uint16_t pkts_n);
343 : : uint16_t mlx5_rx_burst_mprq_vec(void *dpdk_rxq, struct rte_mbuf **pkts,
344 : : uint16_t pkts_n);
345 : : void mlx5_rxq_sync_cq(struct mlx5_rxq_data *rxq);
346 : :
347 : : static int mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq);
348 : :
349 : : /**
350 : : * Query LKey for an address on Rx. No need to flush local caches
351 : : * as the Rx mempool database entries are valid for the lifetime of the queue.
352 : : *
353 : : * @param rxq
354 : : * Pointer to Rx queue structure.
355 : : * @param addr
356 : : * Address to search.
357 : : *
358 : : * @return
359 : : * Searched LKey on success, UINT32_MAX on no match.
360 : : * This function always succeeds on valid input.
361 : : */
362 : : static __rte_always_inline uint32_t
363 : : mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr)
364 : : {
365 : 0 : struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl;
366 : : struct rte_mempool *mp;
367 : : uint32_t lkey;
368 : :
369 : : /* Linear search on MR cache array. */
370 [ # # # # : 0 : lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
# # ]
371 : : MLX5_MR_CACHE_N, addr);
372 [ # # # # : 0 : if (likely(lkey != UINT32_MAX))
# # ]
373 : : return lkey;
374 : 0 : mp = mlx5_rxq_mprq_enabled(rxq) ? rxq->mprq_mp : rxq->mp;
375 : 0 : return mlx5_mr_mempool2mr_bh(mr_ctrl, mp, addr);
376 : : }
377 : :
378 : : /**
379 : : * Query LKey from a packet buffer for Rx. No need to flush local caches
380 : : * as the Rx mempool database entries are valid for the lifetime of the queue.
381 : : *
382 : : * @param rxq
383 : : * Pointer to Rx queue structure.
384 : : * @param mb
385 : : * Buffer to search the address of.
386 : : *
387 : : * @return
388 : : * Searched LKey on success, UINT32_MAX on no match.
389 : : * This function always succeeds on valid input.
390 : : */
391 : : static __rte_always_inline uint32_t
392 : : mlx5_rx_mb2mr(struct mlx5_rxq_data *rxq, struct rte_mbuf *mb)
393 : : {
394 : 0 : struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl;
395 : 0 : uintptr_t addr = (uintptr_t)mb->buf_addr;
396 : : uint32_t lkey;
397 : :
398 : : /* Linear search on MR cache array. */
399 [ # # # # : 0 : lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
# # ]
400 : : MLX5_MR_CACHE_N, addr);
401 [ # # # # : 0 : if (likely(lkey != UINT32_MAX))
# # ]
402 : : return lkey;
403 : : /* Slower search in the mempool database on miss. */
404 : 0 : return mlx5_mr_mempool2mr_bh(mr_ctrl, mb->pool, addr);
405 : : }
406 : :
407 : : /**
408 : : * Set timestamp in mbuf dynamic field.
409 : : *
410 : : * @param mbuf
411 : : * Structure to write into.
412 : : * @param offset
413 : : * Dynamic field offset in mbuf structure.
414 : : * @param timestamp
415 : : * Value to write.
416 : : */
417 : : static __rte_always_inline void
418 : : mlx5_timestamp_set(struct rte_mbuf *mbuf, int offset,
419 : : rte_mbuf_timestamp_t timestamp)
420 : : {
421 : 0 : *RTE_MBUF_DYNFIELD(mbuf, offset, rte_mbuf_timestamp_t *) = timestamp;
422 : 0 : }
423 : :
424 : : /**
425 : : * Replace MPRQ buffer.
426 : : *
427 : : * @param rxq
428 : : * Pointer to Rx queue structure.
429 : : * @param rq_idx
430 : : * RQ index to replace.
431 : : */
432 : : static __rte_always_inline void
433 : : mprq_buf_replace(struct mlx5_rxq_data *rxq, uint16_t rq_idx)
434 : : {
435 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
436 : 0 : struct mlx5_mprq_buf *rep = rxq->mprq_repl;
437 : : volatile struct mlx5_wqe_data_seg *wqe =
438 : 0 : &((volatile struct mlx5_wqe_mprq *)rxq->wqes)[rq_idx].dseg;
439 : 0 : struct mlx5_mprq_buf *buf = (*rxq->mprq_bufs)[rq_idx];
440 : : void *addr;
441 : :
442 [ # # # # ]: 0 : if (rte_atomic_load_explicit(&buf->refcnt, rte_memory_order_relaxed) > 1) {
443 : : MLX5_ASSERT(rep != NULL);
444 : : /* Replace MPRQ buf. */
445 : 0 : (*rxq->mprq_bufs)[rq_idx] = rep;
446 : : /* Replace WQE. */
447 : 0 : addr = mlx5_mprq_buf_addr(rep, strd_n);
448 : 0 : wqe->addr = rte_cpu_to_be_64((uintptr_t)addr);
449 : : /* If there's only one MR, no need to replace LKey in WQE. */
450 [ # # # # ]: 0 : if (unlikely(mlx5_mr_btree_len(&rxq->mr_ctrl.cache_bh) > 1))
451 : 0 : wqe->lkey = mlx5_rx_addr2mr(rxq, (uintptr_t)addr);
452 : : /* Stash a mbuf for next replacement. */
453 [ # # # # : 0 : if (likely(!rte_mempool_get(rxq->mprq_mp, (void **)&rep)))
# # # # ]
454 : 0 : rxq->mprq_repl = rep;
455 : : else
456 : 0 : rxq->mprq_repl = NULL;
457 : : /* Release the old buffer. */
458 : 0 : mlx5_mprq_buf_free(buf);
459 [ # # # # ]: 0 : } else if (unlikely(rxq->mprq_repl == NULL)) {
460 : : struct mlx5_mprq_buf *rep;
461 : :
462 : : /*
463 : : * Currently, the MPRQ mempool is out of buffer
464 : : * and doing memcpy regardless of the size of Rx
465 : : * packet. Retry allocation to get back to
466 : : * normal.
467 : : */
468 [ # # # # : 0 : if (!rte_mempool_get(rxq->mprq_mp, (void **)&rep))
# # # # ]
469 : 0 : rxq->mprq_repl = rep;
470 : : }
471 : : }
472 : :
473 : : /**
474 : : * Attach or copy MPRQ buffer content to a packet.
475 : : *
476 : : * @param rxq
477 : : * Pointer to Rx queue structure.
478 : : * @param pkt
479 : : * Pointer to a packet to fill.
480 : : * @param len
481 : : * Packet length.
482 : : * @param buf
483 : : * Pointer to a MPRQ buffer to take the data from.
484 : : * @param strd_idx
485 : : * Stride index to start from.
486 : : * @param strd_cnt
487 : : * Number of strides to consume.
488 : : */
489 : : static __rte_always_inline enum mlx5_rqx_code
490 : : mprq_buf_to_pkt(struct mlx5_rxq_data *rxq, struct rte_mbuf *pkt, uint32_t len,
491 : : struct mlx5_mprq_buf *buf, uint16_t strd_idx, uint16_t strd_cnt)
492 : : {
493 : 0 : const uint32_t strd_n = RTE_BIT32(rxq->log_strd_num);
494 : 0 : const uint16_t strd_sz = RTE_BIT32(rxq->log_strd_sz);
495 : 0 : const uint16_t strd_shift =
496 : 0 : MLX5_MPRQ_STRIDE_SHIFT_BYTE * rxq->strd_shift_en;
497 : 0 : const int32_t hdrm_overlap =
498 : 0 : len + RTE_PKTMBUF_HEADROOM - strd_cnt * strd_sz;
499 : 0 : const uint32_t offset = strd_idx * strd_sz + strd_shift;
500 : 0 : void *addr = RTE_PTR_ADD(mlx5_mprq_buf_addr(buf, strd_n), offset);
501 : :
502 : : /*
503 : : * Memcpy packets to the target mbuf if:
504 : : * - The size of packet is smaller than mprq_max_memcpy_len.
505 : : * - Out of buffer in the Mempool for Multi-Packet RQ.
506 : : * - The packet's stride overlaps a headroom and scatter is off.
507 : : */
508 [ # # ]: 0 : if (len <= rxq->mprq_max_memcpy_len ||
509 [ # # # # ]: 0 : rxq->mprq_repl == NULL ||
510 [ # # ]: 0 : (hdrm_overlap > 0 && !rxq->strd_scatter_en)) {
511 [ # # ]: 0 : if (likely(len <=
512 : : (uint32_t)(pkt->buf_len - RTE_PKTMBUF_HEADROOM))) {
513 [ # # ]: 0 : rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
514 : : addr, len);
515 : 0 : DATA_LEN(pkt) = len;
516 [ # # ]: 0 : } else if (rxq->strd_scatter_en) {
517 : : struct rte_mbuf *prev = pkt;
518 : 0 : uint32_t seg_len = RTE_MIN(len, (uint32_t)
519 : : (pkt->buf_len - RTE_PKTMBUF_HEADROOM));
520 : 0 : uint32_t rem_len = len - seg_len;
521 : :
522 [ # # ]: 0 : rte_memcpy(rte_pktmbuf_mtod(pkt, void *),
523 : : addr, seg_len);
524 : 0 : DATA_LEN(pkt) = seg_len;
525 [ # # ]: 0 : while (rem_len) {
526 : : struct rte_mbuf *next =
527 : 0 : rte_pktmbuf_alloc(rxq->mp);
528 : :
529 [ # # ]: 0 : if (unlikely(next == NULL))
530 : : return MLX5_RXQ_CODE_NOMBUF;
531 : 0 : NEXT(prev) = next;
532 : 0 : SET_DATA_OFF(next, 0);
533 : 0 : addr = RTE_PTR_ADD(addr, seg_len);
534 : 0 : seg_len = RTE_MIN(rem_len, (uint32_t)
535 : : (next->buf_len - RTE_PKTMBUF_HEADROOM));
536 : 0 : rte_memcpy
537 [ # # ]: 0 : (rte_pktmbuf_mtod(next, void *),
538 : : addr, seg_len);
539 : 0 : DATA_LEN(next) = seg_len;
540 : 0 : rem_len -= seg_len;
541 : : prev = next;
542 : 0 : ++NB_SEGS(pkt);
543 : : }
544 : : } else {
545 : : return MLX5_RXQ_CODE_DROPPED;
546 : : }
547 : : } else {
548 : : rte_iova_t buf_iova;
549 : : struct rte_mbuf_ext_shared_info *shinfo;
550 : 0 : uint16_t buf_len = strd_cnt * strd_sz;
551 : : void *buf_addr;
552 : :
553 : : /* Increment the refcnt of the whole chunk. */
554 : 0 : rte_atomic_fetch_add_explicit(&buf->refcnt, 1, rte_memory_order_relaxed);
555 : : MLX5_ASSERT(rte_atomic_load_explicit(&buf->refcnt,
556 : : rte_memory_order_relaxed) <= strd_n + 1);
557 : 0 : buf_addr = RTE_PTR_SUB(addr, RTE_PKTMBUF_HEADROOM);
558 : : /*
559 : : * MLX5 device doesn't use iova but it is necessary in a
560 : : * case where the Rx packet is transmitted via a
561 : : * different PMD.
562 : : */
563 : 0 : buf_iova = rte_mempool_virt2iova(buf) +
564 : 0 : RTE_PTR_DIFF(buf_addr, buf);
565 : 0 : shinfo = &buf->shinfos[strd_idx];
566 : 0 : rte_mbuf_ext_refcnt_set(shinfo, 1);
567 : : /*
568 : : * RTE_MBUF_F_EXTERNAL will be set to pkt->ol_flags when
569 : : * attaching the stride to mbuf and more offload flags
570 : : * will be added below by calling rxq_cq_to_mbuf().
571 : : * Other fields will be overwritten.
572 : : */
573 : : rte_pktmbuf_attach_extbuf(pkt, buf_addr, buf_iova,
574 : : buf_len, shinfo);
575 : : /* Set mbuf head-room. */
576 : 0 : SET_DATA_OFF(pkt, RTE_PKTMBUF_HEADROOM);
577 : : MLX5_ASSERT(pkt->ol_flags & RTE_MBUF_F_EXTERNAL);
578 : : MLX5_ASSERT(rte_pktmbuf_tailroom(pkt) >=
579 : : len - (hdrm_overlap > 0 ? hdrm_overlap : 0));
580 : 0 : DATA_LEN(pkt) = len;
581 : : /*
582 : : * Copy the last fragment of a packet (up to headroom
583 : : * size bytes) in case there is a stride overlap with
584 : : * a next packet's headroom. Allocate a separate mbuf
585 : : * to store this fragment and link it. Scatter is on.
586 : : */
587 [ # # ]: 0 : if (hdrm_overlap > 0) {
588 : : MLX5_ASSERT(rxq->strd_scatter_en);
589 : : struct rte_mbuf *seg =
590 : 0 : rte_pktmbuf_alloc(rxq->mp);
591 : :
592 [ # # ]: 0 : if (unlikely(seg == NULL))
593 : : return MLX5_RXQ_CODE_NOMBUF;
594 : 0 : SET_DATA_OFF(seg, 0);
595 : 0 : rte_memcpy(rte_pktmbuf_mtod(seg, void *),
596 [ # # ]: 0 : RTE_PTR_ADD(addr, len - hdrm_overlap),
597 : : hdrm_overlap);
598 : 0 : DATA_LEN(seg) = hdrm_overlap;
599 : 0 : DATA_LEN(pkt) = len - hdrm_overlap;
600 : 0 : NEXT(pkt) = seg;
601 : 0 : NB_SEGS(pkt) = 2;
602 : : }
603 : : }
604 : : return MLX5_RXQ_CODE_EXIT;
605 : : }
606 : :
607 : : /**
608 : : * Check whether Shared RQ is enabled for the device.
609 : : *
610 : : * @param dev
611 : : * Pointer to Ethernet device.
612 : : *
613 : : * @return
614 : : * 0 if disabled, otherwise enabled.
615 : : */
616 : : static __rte_always_inline int
617 : : mlx5_shared_rq_enabled(struct rte_eth_dev *dev)
618 : : {
619 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
620 : :
621 [ # # ]: 0 : return !LIST_EMPTY(&priv->sh->shared_rxqs);
622 : : }
623 : :
624 : : /**
625 : : * Check whether Multi-Packet RQ can be enabled for the device.
626 : : *
627 : : * @param dev
628 : : * Pointer to Ethernet device.
629 : : *
630 : : * @return
631 : : * 1 if supported, negative errno value if not.
632 : : */
633 : : static __rte_always_inline int
634 : : mlx5_check_mprq_support(struct rte_eth_dev *dev)
635 : : {
636 : : struct mlx5_priv *priv = dev->data->dev_private;
637 : :
638 [ # # # # ]: 0 : if (mlx5_shared_rq_enabled(dev))
639 : : return -ENOTSUP;
640 [ # # # # ]: 0 : if (priv->config.mprq.enabled &&
641 [ # # # # ]: 0 : priv->rxqs_n >= priv->config.mprq.min_rxqs_num)
642 : : return 1;
643 : : return -ENOTSUP;
644 : : }
645 : :
646 : : /**
647 : : * Check whether Multi-Packet RQ is enabled for the Rx queue.
648 : : *
649 : : * @param rxq
650 : : * Pointer to receive queue structure.
651 : : *
652 : : * @return
653 : : * 0 if disabled, otherwise enabled.
654 : : */
655 : : static __rte_always_inline int
656 : : mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq)
657 : : {
658 [ # # # # : 0 : return rxq->log_strd_num > 0;
# # # # #
# # # ]
659 : : }
660 : :
661 : : /**
662 : : * Check whether Multi-Packet RQ is enabled for the device.
663 : : *
664 : : * @param dev
665 : : * Pointer to Ethernet device.
666 : : *
667 : : * @return
668 : : * 0 if disabled, otherwise enabled.
669 : : */
670 : : static __rte_always_inline int
671 : : mlx5_mprq_enabled(struct rte_eth_dev *dev)
672 : : {
673 [ # # # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
674 : : uint32_t i;
675 : : uint16_t n = 0;
676 : : uint16_t n_ibv = 0;
677 : :
678 : : if (mlx5_check_mprq_support(dev) < 0)
679 : : return 0;
680 : : /* All the configured queues should be enabled. */
681 [ # # # # ]: 0 : for (i = 0; i < priv->rxqs_n; ++i) {
682 : 0 : struct mlx5_rxq_ctrl *rxq_ctrl = mlx5_rxq_ctrl_get(dev, i);
683 : :
684 [ # # # # : 0 : if (rxq_ctrl == NULL || rxq_ctrl->is_hairpin)
# # # # ]
685 : 0 : continue;
686 : 0 : n_ibv++;
687 [ # # # # ]: 0 : if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
688 : 0 : ++n;
689 : : }
690 : : /* Multi-Packet RQ can't be partially configured. */
691 : : MLX5_ASSERT(n == 0 || n == n_ibv);
692 [ # # # # ]: 0 : return n == n_ibv;
693 : : }
694 : :
695 : : /**
696 : : * Check whether given RxQ is external.
697 : : *
698 : : * @param dev
699 : : * Pointer to Ethernet device.
700 : : * @param queue_idx
701 : : * Rx queue index.
702 : : *
703 : : * @return
704 : : * True if is external RxQ, otherwise false.
705 : : */
706 : : static __rte_always_inline bool
707 : : mlx5_is_external_rxq(struct rte_eth_dev *dev, uint16_t queue_idx)
708 : : {
709 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
710 : : struct mlx5_external_q *rxq;
711 : :
712 [ # # # # : 0 : if (!priv->ext_rxqs || queue_idx < RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN)
# # # # #
# # # # #
# # ]
713 : : return false;
714 : 0 : rxq = &priv->ext_rxqs[queue_idx - RTE_PMD_MLX5_EXTERNAL_RX_QUEUE_ID_MIN];
715 [ # # # # : 0 : return !!rte_atomic_load_explicit(&rxq->refcnt, rte_memory_order_relaxed);
# # # # ]
716 : : }
717 : :
718 : : #define LWM_COOKIE_RXQID_OFFSET 0
719 : : #define LWM_COOKIE_RXQID_MASK 0xffff
720 : : #define LWM_COOKIE_PORTID_OFFSET 16
721 : : #define LWM_COOKIE_PORTID_MASK 0xffff
722 : :
723 : : #endif /* RTE_PMD_MLX5_RX_H_ */
|