1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
6 #ifndef RTE_PMD_MLX5_RXTX_H_
7 #define RTE_PMD_MLX5_RXTX_H_
11 #include <sys/queue.h>
14 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
16 #pragma GCC diagnostic ignored "-Wpedantic"
18 #include <infiniband/verbs.h>
19 #include <infiniband/mlx5dv.h>
21 #pragma GCC diagnostic error "-Wpedantic"
25 #include <rte_mempool.h>
26 #include <rte_common.h>
27 #include <rte_hexdump.h>
28 #include <rte_atomic.h>
29 #include <rte_spinlock.h>
31 #include <rte_bus_pci.h>
32 #include <rte_malloc.h>
33 #include <rte_cycles.h>
35 #include <mlx5_glue.h>
37 #include <mlx5_common.h>
38 #include <mlx5_common_mr.h>
40 #include "mlx5_defs.h"
41 #include "mlx5_utils.h"
43 #include "mlx5_autoconf.h"
45 /* Support tunnel matching. */
46 #define MLX5_FLOW_TUNNEL 10
48 /* Mbuf dynamic flag offset for inline. */
49 extern uint64_t rte_net_mlx5_dynf_inline_mask;
51 struct mlx5_rxq_stats {
52 #ifdef MLX5_PMD_SOFT_COUNTERS
53 uint64_t ipackets; /**< Total of successfully received packets. */
54 uint64_t ibytes; /**< Total of successfully received bytes. */
56 uint64_t idropped; /**< Total of packets dropped when RX ring full. */
57 uint64_t rx_nombuf; /**< Total of RX mbuf allocation failures. */
60 struct mlx5_txq_stats {
61 #ifdef MLX5_PMD_SOFT_COUNTERS
62 uint64_t opackets; /**< Total of successfully sent packets. */
63 uint64_t obytes; /**< Total of successfully sent bytes. */
65 uint64_t oerrors; /**< Total number of failed transmitted packets. */
70 /* Compressed CQE context. */
72 uint16_t ai; /* Array index. */
73 uint16_t ca; /* Current array index. */
74 uint16_t na; /* Next array index. */
75 uint16_t cq_ci; /* The next CQE. */
76 uint32_t cqe_cnt; /* Number of CQEs. */
79 /* Multi-Packet RQ buffer header. */
80 struct mlx5_mprq_buf {
81 struct rte_mempool *mp;
82 rte_atomic16_t refcnt; /* Atomically accessed refcnt. */
83 uint8_t pad[RTE_PKTMBUF_HEADROOM]; /* Headroom for the first packet. */
84 struct rte_mbuf_ext_shared_info shinfos[];
86 * Shared information per stride.
87 * More memory will be allocated for the first stride head-room and for
90 } __rte_cache_aligned;
92 /* Get pointer to the first stride. */
93 #define mlx5_mprq_buf_addr(ptr, strd_n) (RTE_PTR_ADD((ptr), \
94 sizeof(struct mlx5_mprq_buf) + \
96 sizeof(struct rte_mbuf_ext_shared_info) + \
97 RTE_PKTMBUF_HEADROOM))
99 #define MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES 6
100 #define MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES 9
102 enum mlx5_rxq_err_state {
103 MLX5_RXQ_ERR_STATE_NO_ERROR = 0,
104 MLX5_RXQ_ERR_STATE_NEED_RESET,
105 MLX5_RXQ_ERR_STATE_NEED_READY,
108 /* RX queue descriptor. */
109 struct mlx5_rxq_data {
110 unsigned int csum:1; /* Enable checksum offloading. */
111 unsigned int hw_timestamp:1; /* Enable HW timestamp. */
112 unsigned int rt_timestamp:1; /* Realtime timestamp format. */
113 unsigned int vlan_strip:1; /* Enable VLAN stripping. */
114 unsigned int crc_present:1; /* CRC must be subtracted. */
115 unsigned int sges_n:3; /* Log 2 of SGEs (max buffers per packet). */
116 unsigned int cqe_n:4; /* Log 2 of CQ elements. */
117 unsigned int elts_n:4; /* Log 2 of Mbufs. */
118 unsigned int rss_hash:1; /* RSS hash result is enabled. */
119 unsigned int mark:1; /* Marked flow available on the queue. */
120 unsigned int strd_num_n:5; /* Log 2 of the number of stride. */
121 unsigned int strd_sz_n:4; /* Log 2 of stride size. */
122 unsigned int strd_shift_en:1; /* Enable 2bytes shift on a stride. */
123 unsigned int err_state:2; /* enum mlx5_rxq_err_state. */
124 unsigned int strd_scatter_en:1; /* Scattered packets from a stride. */
125 unsigned int lro:1; /* Enable LRO. */
126 unsigned int dynf_meta:1; /* Dynamic metadata is configured. */
127 volatile uint32_t *rq_db;
128 volatile uint32_t *cq_db;
131 uint16_t consumed_strd; /* Number of consumed strides in WQE. */
134 uint16_t rq_repl_thresh; /* Threshold for buffer replenishment. */
136 struct rxq_zip zip; /* Compressed context. */
137 uint16_t decompressed;
138 /* Number of ready mbufs decompressed from the CQ. */
140 struct mlx5_mr_ctrl mr_ctrl; /* MR control descriptor. */
141 uint16_t mprq_max_memcpy_len; /* Maximum size of packet to memcpy. */
143 volatile struct mlx5_cqe(*cqes)[];
146 struct rte_mbuf *(*elts)[];
147 struct mlx5_mprq_buf *(*mprq_bufs)[];
149 struct rte_mempool *mp;
150 struct rte_mempool *mprq_mp; /* Mempool for Multi-Packet RQ. */
151 struct mlx5_mprq_buf *mprq_repl; /* Stashed mbuf for replenish. */
152 struct mlx5_dev_ctx_shared *sh; /* Shared context. */
153 uint16_t idx; /* Queue index. */
154 struct mlx5_rxq_stats stats;
155 rte_xmm_t mbuf_initializer; /* Default rearm/flags for vectorized Rx. */
156 struct rte_mbuf fake_mbuf; /* elts padding for vectorized Rx. */
157 void *cq_uar; /* CQ user access region. */
158 uint32_t cqn; /* CQ number. */
159 uint8_t cq_arm_sn; /* CQ arm seq number. */
161 rte_spinlock_t *uar_lock_cq;
162 /* CQ (UAR) access lock required for 32bit implementations */
164 uint32_t tunnel; /* Tunnel information. */
165 uint64_t flow_meta_mask;
166 int32_t flow_meta_offset;
167 } __rte_cache_aligned;
169 enum mlx5_rxq_obj_type {
170 MLX5_RXQ_OBJ_TYPE_IBV, /* mlx5_rxq_obj with ibv_wq. */
171 MLX5_RXQ_OBJ_TYPE_DEVX_RQ, /* mlx5_rxq_obj with mlx5_devx_rq. */
172 MLX5_RXQ_OBJ_TYPE_DEVX_HAIRPIN,
173 /* mlx5_rxq_obj with mlx5_devx_rq and hairpin support. */
177 MLX5_RXQ_TYPE_STANDARD, /* Standard Rx queue. */
178 MLX5_RXQ_TYPE_HAIRPIN, /* Hairpin Rx queue. */
179 MLX5_RXQ_TYPE_UNDEFINED,
182 /* Verbs/DevX Rx queue elements. */
183 struct mlx5_rxq_obj {
184 LIST_ENTRY(mlx5_rxq_obj) next; /* Pointer to the next element. */
185 rte_atomic32_t refcnt; /* Reference counter. */
186 struct mlx5_rxq_ctrl *rxq_ctrl; /* Back pointer to parent. */
187 struct ibv_cq *cq; /* Completion Queue. */
188 enum mlx5_rxq_obj_type type;
191 struct ibv_wq *wq; /* Work Queue. */
192 struct mlx5_devx_obj *rq; /* DevX object for Rx Queue. */
194 struct ibv_comp_channel *channel;
197 /* RX queue control descriptor. */
198 struct mlx5_rxq_ctrl {
199 struct mlx5_rxq_data rxq; /* Data path structure. */
200 LIST_ENTRY(mlx5_rxq_ctrl) next; /* Pointer to the next element. */
201 rte_atomic32_t refcnt; /* Reference counter. */
202 struct mlx5_rxq_obj *obj; /* Verbs/DevX elements. */
203 struct mlx5_priv *priv; /* Back pointer to private data. */
204 enum mlx5_rxq_type type; /* Rxq type. */
205 unsigned int socket; /* CPU socket ID for allocations. */
206 unsigned int irq:1; /* Whether IRQ is enabled. */
207 unsigned int dbr_umem_id_valid:1; /* dbr_umem_id holds a valid value. */
208 uint32_t flow_mark_n; /* Number of Mark/Flag flows using this Queue. */
209 uint32_t flow_tunnels_n[MLX5_FLOW_TUNNEL]; /* Tunnels counters. */
210 uint32_t wqn; /* WQ number. */
211 uint16_t dump_file_n; /* Number of dump files. */
212 uint32_t dbr_umem_id; /* Storing door-bell information, */
213 uint64_t dbr_offset; /* needed when freeing door-bell. */
214 struct mlx5dv_devx_umem *wq_umem; /* WQ buffer registration info. */
215 struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
218 enum mlx5_ind_tbl_type {
219 MLX5_IND_TBL_TYPE_IBV,
220 MLX5_IND_TBL_TYPE_DEVX,
223 /* Indirection table. */
224 struct mlx5_ind_table_obj {
225 LIST_ENTRY(mlx5_ind_table_obj) next; /* Pointer to the next element. */
226 rte_atomic32_t refcnt; /* Reference counter. */
227 enum mlx5_ind_tbl_type type;
230 struct ibv_rwq_ind_table *ind_table; /**< Indirection table. */
231 struct mlx5_devx_obj *rqt; /* DevX RQT object. */
233 uint32_t queues_n; /**< Number of queues in the list. */
234 uint16_t queues[]; /**< Queue list. */
239 ILIST_ENTRY(uint32_t)next; /* Index to the next element. */
240 rte_atomic32_t refcnt; /* Reference counter. */
241 struct mlx5_ind_table_obj *ind_table; /* Indirection table. */
244 struct ibv_qp *qp; /* Verbs queue pair. */
245 struct mlx5_devx_obj *tir; /* DevX TIR object. */
247 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
248 void *action; /* DV QP action pointer. */
250 uint64_t hash_fields; /* Verbs Hash fields. */
251 uint32_t rss_key_len; /* Hash key length in bytes. */
252 uint8_t rss_key[]; /* Hash key. */
255 /* TX queue send local data. */
257 struct mlx5_txq_local {
258 struct mlx5_wqe *wqe_last; /* last sent WQE pointer. */
259 struct rte_mbuf *mbuf; /* first mbuf to process. */
260 uint16_t pkts_copy; /* packets copied to elts. */
261 uint16_t pkts_sent; /* packets sent. */
262 uint16_t pkts_loop; /* packets sent on loop entry. */
263 uint16_t elts_free; /* available elts remain. */
264 uint16_t wqe_free; /* available wqe remain. */
265 uint16_t mbuf_off; /* data offset in current mbuf. */
266 uint16_t mbuf_nseg; /* number of remaining mbuf. */
269 /* TX queue descriptor. */
271 struct mlx5_txq_data {
272 uint16_t elts_head; /* Current counter in (*elts)[]. */
273 uint16_t elts_tail; /* Counter of first element awaiting completion. */
274 uint16_t elts_comp; /* elts index since last completion request. */
275 uint16_t elts_s; /* Number of mbuf elements. */
276 uint16_t elts_m; /* Mask for mbuf elements indices. */
277 /* Fields related to elts mbuf storage. */
278 uint16_t wqe_ci; /* Consumer index for work queue. */
279 uint16_t wqe_pi; /* Producer index for work queue. */
280 uint16_t wqe_s; /* Number of WQ elements. */
281 uint16_t wqe_m; /* Mask Number for WQ elements. */
282 uint16_t wqe_comp; /* WQE index since last completion request. */
283 uint16_t wqe_thres; /* WQE threshold to request completion in CQ. */
284 /* WQ related fields. */
285 uint16_t cq_ci; /* Consumer index for completion queue. */
286 uint16_t cq_pi; /* Production index for completion queue. */
287 uint16_t cqe_s; /* Number of CQ elements. */
288 uint16_t cqe_m; /* Mask for CQ indices. */
289 /* CQ related fields. */
290 uint16_t elts_n:4; /* elts[] length (in log2). */
291 uint16_t cqe_n:4; /* Number of CQ elements (in log2). */
292 uint16_t wqe_n:4; /* Number of WQ elements (in log2). */
293 uint16_t tso_en:1; /* When set hardware TSO is enabled. */
294 uint16_t tunnel_en:1;
295 /* When set TX offload for tunneled packets are supported. */
296 uint16_t swp_en:1; /* Whether SW parser is enabled. */
297 uint16_t vlan_en:1; /* VLAN insertion in WQE is supported. */
298 uint16_t db_nc:1; /* Doorbell mapped to non-cached region. */
299 uint16_t db_heu:1; /* Doorbell heuristic write barrier. */
300 uint16_t inlen_send; /* Ordinary send data inline size. */
301 uint16_t inlen_empw; /* eMPW max packet size to inline. */
302 uint16_t inlen_mode; /* Minimal data length to inline. */
303 uint32_t qp_num_8s; /* QP number shifted by 8. */
304 uint64_t offloads; /* Offloads for Tx Queue. */
305 struct mlx5_mr_ctrl mr_ctrl; /* MR control descriptor. */
306 struct mlx5_wqe *wqes; /* Work queue. */
307 struct mlx5_wqe *wqes_end; /* Work queue array limit. */
308 #ifdef RTE_LIBRTE_MLX5_DEBUG
309 uint32_t *fcqs; /* Free completion queue (debug extended). */
311 uint16_t *fcqs; /* Free completion queue. */
313 volatile struct mlx5_cqe *cqes; /* Completion queue. */
314 volatile uint32_t *qp_db; /* Work queue doorbell. */
315 volatile uint32_t *cq_db; /* Completion queue doorbell. */
316 uint16_t port_id; /* Port ID of device. */
317 uint16_t idx; /* Queue index. */
318 uint64_t ts_mask; /* Timestamp flag dynamic mask. */
319 int32_t ts_offset; /* Timestamp field dynamic offset. */
320 struct mlx5_dev_ctx_shared *sh; /* Shared context. */
321 struct mlx5_txq_stats stats; /* TX queue counters. */
323 rte_spinlock_t *uar_lock;
324 /* UAR access lock required for 32bit implementations */
326 struct rte_mbuf *elts[0];
327 /* Storage for queued packets, must be the last field. */
328 } __rte_cache_aligned;
330 enum mlx5_txq_obj_type {
331 MLX5_TXQ_OBJ_TYPE_IBV, /* mlx5_txq_obj with ibv_wq. */
332 MLX5_TXQ_OBJ_TYPE_DEVX_SQ, /* mlx5_txq_obj with mlx5_devx_sq. */
333 MLX5_TXQ_OBJ_TYPE_DEVX_HAIRPIN,
334 /* mlx5_txq_obj with mlx5_devx_tq and hairpin support. */
338 MLX5_TXQ_TYPE_STANDARD, /* Standard Tx queue. */
339 MLX5_TXQ_TYPE_HAIRPIN, /* Hairpin Rx queue. */
342 /* Verbs/DevX Tx queue elements. */
343 struct mlx5_txq_obj {
344 LIST_ENTRY(mlx5_txq_obj) next; /* Pointer to the next element. */
345 rte_atomic32_t refcnt; /* Reference counter. */
346 struct mlx5_txq_ctrl *txq_ctrl; /* Pointer to the control queue. */
347 enum mlx5_txq_obj_type type; /* The txq object type. */
351 struct ibv_cq *cq; /* Completion Queue. */
352 struct ibv_qp *qp; /* Queue Pair. */
355 struct mlx5_devx_obj *sq;
356 /* DevX object for Sx queue. */
357 struct mlx5_devx_obj *tis; /* The TIS object. */
360 struct rte_eth_dev *dev;
361 struct mlx5_devx_obj *cq_devx;
362 struct mlx5dv_devx_umem *cq_umem;
364 int64_t cq_dbrec_offset;
365 struct mlx5_devx_dbr_page *cq_dbrec_page;
366 struct mlx5_devx_obj *sq_devx;
367 struct mlx5dv_devx_umem *sq_umem;
369 int64_t sq_dbrec_offset;
370 struct mlx5_devx_dbr_page *sq_dbrec_page;
375 /* TX queue control descriptor. */
376 struct mlx5_txq_ctrl {
377 LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
378 rte_atomic32_t refcnt; /* Reference counter. */
379 unsigned int socket; /* CPU socket ID for allocations. */
380 enum mlx5_txq_type type; /* The txq ctrl type. */
381 unsigned int max_inline_data; /* Max inline data. */
382 unsigned int max_tso_header; /* Max TSO header size. */
383 struct mlx5_txq_obj *obj; /* Verbs/DevX queue object. */
384 struct mlx5_priv *priv; /* Back pointer to private data. */
385 off_t uar_mmap_offset; /* UAR mmap offset for non-primary process. */
386 void *bf_reg; /* BlueFlame register from Verbs. */
387 uint16_t dump_file_n; /* Number of dump files. */
388 struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
389 struct mlx5_txq_data txq; /* Data path structure. */
390 /* Must be the last field in the structure, contains elts[]. */
393 #define MLX5_TX_BFREG(txq) \
394 (MLX5_PROC_PRIV((txq)->port_id)->uar_table[(txq)->idx])
398 extern uint8_t rss_hash_default_key[];
400 int mlx5_check_mprq_support(struct rte_eth_dev *dev);
401 int mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq);
402 int mlx5_mprq_enabled(struct rte_eth_dev *dev);
403 int mlx5_mprq_free_mp(struct rte_eth_dev *dev);
404 int mlx5_mprq_alloc_mp(struct rte_eth_dev *dev);
405 int mlx5_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
406 unsigned int socket, const struct rte_eth_rxconf *conf,
407 struct rte_mempool *mp);
408 int mlx5_rx_hairpin_queue_setup
409 (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
410 const struct rte_eth_hairpin_conf *hairpin_conf);
411 void mlx5_rx_queue_release(void *dpdk_rxq);
412 int mlx5_rx_intr_vec_enable(struct rte_eth_dev *dev);
413 void mlx5_rx_intr_vec_disable(struct rte_eth_dev *dev);
414 int mlx5_rx_intr_enable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
415 int mlx5_rx_intr_disable(struct rte_eth_dev *dev, uint16_t rx_queue_id);
416 struct mlx5_rxq_obj *mlx5_rxq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
417 enum mlx5_rxq_obj_type type);
418 int mlx5_rxq_obj_verify(struct rte_eth_dev *dev);
419 struct mlx5_rxq_ctrl *mlx5_rxq_new(struct rte_eth_dev *dev, uint16_t idx,
420 uint16_t desc, unsigned int socket,
421 const struct rte_eth_rxconf *conf,
422 struct rte_mempool *mp);
423 struct mlx5_rxq_ctrl *mlx5_rxq_hairpin_new
424 (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
425 const struct rte_eth_hairpin_conf *hairpin_conf);
426 struct mlx5_rxq_ctrl *mlx5_rxq_get(struct rte_eth_dev *dev, uint16_t idx);
427 int mlx5_rxq_release(struct rte_eth_dev *dev, uint16_t idx);
428 int mlx5_rxq_verify(struct rte_eth_dev *dev);
429 int rxq_alloc_elts(struct mlx5_rxq_ctrl *rxq_ctrl);
430 int mlx5_ind_table_obj_verify(struct rte_eth_dev *dev);
431 uint32_t mlx5_hrxq_new(struct rte_eth_dev *dev,
432 const uint8_t *rss_key, uint32_t rss_key_len,
433 uint64_t hash_fields,
434 const uint16_t *queues, uint32_t queues_n,
435 int tunnel __rte_unused);
436 uint32_t mlx5_hrxq_get(struct rte_eth_dev *dev,
437 const uint8_t *rss_key, uint32_t rss_key_len,
438 uint64_t hash_fields,
439 const uint16_t *queues, uint32_t queues_n);
440 int mlx5_hrxq_release(struct rte_eth_dev *dev, uint32_t hxrq_idx);
441 int mlx5_hrxq_verify(struct rte_eth_dev *dev);
442 enum mlx5_rxq_type mlx5_rxq_get_type(struct rte_eth_dev *dev, uint16_t idx);
443 struct mlx5_hrxq *mlx5_hrxq_drop_new(struct rte_eth_dev *dev);
444 void mlx5_hrxq_drop_release(struct rte_eth_dev *dev);
445 uint64_t mlx5_get_rx_port_offloads(void);
446 uint64_t mlx5_get_rx_queue_offloads(struct rte_eth_dev *dev);
447 void mlx5_rxq_timestamp_set(struct rte_eth_dev *dev);
452 int mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
453 unsigned int socket, const struct rte_eth_txconf *conf);
454 int mlx5_tx_hairpin_queue_setup
455 (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
456 const struct rte_eth_hairpin_conf *hairpin_conf);
457 void mlx5_tx_queue_release(void *dpdk_txq);
458 int mlx5_tx_uar_init_secondary(struct rte_eth_dev *dev, int fd);
459 void mlx5_tx_uar_uninit_secondary(struct rte_eth_dev *dev);
460 struct mlx5_txq_obj *mlx5_txq_obj_new(struct rte_eth_dev *dev, uint16_t idx,
461 enum mlx5_txq_obj_type type);
462 struct mlx5_txq_obj *mlx5_txq_obj_get(struct rte_eth_dev *dev, uint16_t idx);
463 int mlx5_txq_obj_release(struct mlx5_txq_obj *txq_ibv);
464 int mlx5_txq_obj_verify(struct rte_eth_dev *dev);
465 struct mlx5_txq_ctrl *mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx,
466 uint16_t desc, unsigned int socket,
467 const struct rte_eth_txconf *conf);
468 struct mlx5_txq_ctrl *mlx5_txq_hairpin_new
469 (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
470 const struct rte_eth_hairpin_conf *hairpin_conf);
471 struct mlx5_txq_ctrl *mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx);
472 int mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx);
473 int mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx);
474 int mlx5_txq_verify(struct rte_eth_dev *dev);
475 void txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl);
476 void txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl);
477 uint64_t mlx5_get_tx_port_offloads(struct rte_eth_dev *dev);
478 void mlx5_txq_dynf_timestamp_set(struct rte_eth_dev *dev);
482 extern uint32_t mlx5_ptype_table[];
483 extern uint8_t mlx5_cksum_table[];
484 extern uint8_t mlx5_swp_types_table[];
486 void mlx5_set_ptype_table(void);
487 void mlx5_set_cksum_table(void);
488 void mlx5_set_swp_types_table(void);
489 uint16_t mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n);
490 void mlx5_rxq_initialize(struct mlx5_rxq_data *rxq);
491 __rte_noinline int mlx5_rx_err_handle(struct mlx5_rxq_data *rxq, uint8_t vec);
492 void mlx5_mprq_buf_free_cb(void *addr, void *opaque);
493 void mlx5_mprq_buf_free(struct mlx5_mprq_buf *buf);
494 uint16_t mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts,
496 uint16_t removed_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
498 uint16_t removed_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
500 int mlx5_rx_descriptor_status(void *rx_queue, uint16_t offset);
501 int mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset);
502 uint32_t mlx5_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id);
503 void mlx5_dump_debug_information(const char *path, const char *title,
504 const void *buf, unsigned int len);
505 int mlx5_queue_state_modify_primary(struct rte_eth_dev *dev,
506 const struct mlx5_mp_arg_queue_state_modify *sm);
507 void mlx5_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
508 struct rte_eth_rxq_info *qinfo);
509 void mlx5_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
510 struct rte_eth_txq_info *qinfo);
511 int mlx5_rx_burst_mode_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
512 struct rte_eth_burst_mode *mode);
513 int mlx5_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
514 struct rte_eth_burst_mode *mode);
516 /* Vectorized version of mlx5_rxtx.c */
517 int mlx5_rxq_check_vec_support(struct mlx5_rxq_data *rxq_data);
518 int mlx5_check_vec_rx_support(struct rte_eth_dev *dev);
519 uint16_t mlx5_rx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts,
524 void mlx5_mr_flush_local_cache(struct mlx5_mr_ctrl *mr_ctrl);
525 uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr);
526 uint32_t mlx5_tx_mb2mr_bh(struct mlx5_txq_data *txq, struct rte_mbuf *mb);
527 uint32_t mlx5_tx_update_ext_mp(struct mlx5_txq_data *txq, uintptr_t addr,
528 struct rte_mempool *mp);
529 int mlx5_dma_map(struct rte_pci_device *pdev, void *addr, uint64_t iova,
531 int mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, uint64_t iova,
535 * Provide safe 64bit store operation to mlx5 UAR region for both 32bit and
536 * 64bit architectures.
539 * value to write in CPU endian format.
541 * Address to write to.
543 * Address of the lock to use for that UAR access.
545 static __rte_always_inline void
546 __mlx5_uar_write64_relaxed(uint64_t val, void *addr,
547 rte_spinlock_t *lock __rte_unused)
550 *(uint64_t *)addr = val;
551 #else /* !RTE_ARCH_64 */
552 rte_spinlock_lock(lock);
553 *(uint32_t *)addr = val;
555 *((uint32_t *)addr + 1) = val >> 32;
556 rte_spinlock_unlock(lock);
561 * Provide safe 64bit store operation to mlx5 UAR region for both 32bit and
562 * 64bit architectures while guaranteeing the order of execution with the
563 * code being executed.
566 * value to write in CPU endian format.
568 * Address to write to.
570 * Address of the lock to use for that UAR access.
572 static __rte_always_inline void
573 __mlx5_uar_write64(uint64_t val, void *addr, rte_spinlock_t *lock)
576 __mlx5_uar_write64_relaxed(val, addr, lock);
579 /* Assist macros, used instead of directly calling the functions they wrap. */
581 #define mlx5_uar_write64_relaxed(val, dst, lock) \
582 __mlx5_uar_write64_relaxed(val, dst, NULL)
583 #define mlx5_uar_write64(val, dst, lock) __mlx5_uar_write64(val, dst, NULL)
585 #define mlx5_uar_write64_relaxed(val, dst, lock) \
586 __mlx5_uar_write64_relaxed(val, dst, lock)
587 #define mlx5_uar_write64(val, dst, lock) __mlx5_uar_write64(val, dst, lock)
591 * Get Memory Pool (MP) from mbuf. If mbuf is indirect, the pool from which the
592 * cloned mbuf is allocated is returned instead.
598 * Memory pool where data is located for given mbuf.
600 static inline struct rte_mempool *
601 mlx5_mb2mp(struct rte_mbuf *buf)
603 if (unlikely(RTE_MBUF_CLONED(buf)))
604 return rte_mbuf_from_indirect(buf)->pool;
609 * Query LKey from a packet buffer for Rx. No need to flush local caches for Rx
610 * as mempool is pre-configured and static.
613 * Pointer to Rx queue structure.
618 * Searched LKey on success, UINT32_MAX on no match.
620 static __rte_always_inline uint32_t
621 mlx5_rx_addr2mr(struct mlx5_rxq_data *rxq, uintptr_t addr)
623 struct mlx5_mr_ctrl *mr_ctrl = &rxq->mr_ctrl;
626 /* Linear search on MR cache array. */
627 lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
628 MLX5_MR_CACHE_N, addr);
629 if (likely(lkey != UINT32_MAX))
631 /* Take slower bottom-half (Binary Search) on miss. */
632 return mlx5_rx_addr2mr_bh(rxq, addr);
635 #define mlx5_rx_mb2mr(rxq, mb) mlx5_rx_addr2mr(rxq, (uintptr_t)((mb)->buf_addr))
638 * Query LKey from a packet buffer for Tx. If not found, add the mempool.
641 * Pointer to Tx queue structure.
646 * Searched LKey on success, UINT32_MAX on no match.
648 static __rte_always_inline uint32_t
649 mlx5_tx_mb2mr(struct mlx5_txq_data *txq, struct rte_mbuf *mb)
651 struct mlx5_mr_ctrl *mr_ctrl = &txq->mr_ctrl;
652 uintptr_t addr = (uintptr_t)mb->buf_addr;
655 /* Check generation bit to see if there's any change on existing MRs. */
656 if (unlikely(*mr_ctrl->dev_gen_ptr != mr_ctrl->cur_gen))
657 mlx5_mr_flush_local_cache(mr_ctrl);
658 /* Linear search on MR cache array. */
659 lkey = mlx5_mr_lookup_lkey(mr_ctrl->cache, &mr_ctrl->mru,
660 MLX5_MR_CACHE_N, addr);
661 if (likely(lkey != UINT32_MAX))
663 /* Take slower bottom-half on miss. */
664 return mlx5_tx_mb2mr_bh(txq, mb);
668 * Ring TX queue doorbell and flush the update if requested.
671 * Pointer to TX queue structure.
673 * Pointer to the last WQE posted in the NIC.
675 * Request for write memory barrier after BlueFlame update.
677 static __rte_always_inline void
678 mlx5_tx_dbrec_cond_wmb(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe,
681 uint64_t *dst = MLX5_TX_BFREG(txq);
682 volatile uint64_t *src = ((volatile uint64_t *)wqe);
685 *txq->qp_db = rte_cpu_to_be_32(txq->wqe_ci);
686 /* Ensure ordering between DB record and BF copy. */
688 mlx5_uar_write64_relaxed(*src, dst, txq->uar_lock);
694 * Ring TX queue doorbell and flush the update by write memory barrier.
697 * Pointer to TX queue structure.
699 * Pointer to the last WQE posted in the NIC.
701 static __rte_always_inline void
702 mlx5_tx_dbrec(struct mlx5_txq_data *txq, volatile struct mlx5_wqe *wqe)
704 mlx5_tx_dbrec_cond_wmb(txq, wqe, 1);
708 * Convert timestamp from HW format to linear counter
709 * from Packet Pacing Clock Queue CQE timestamp format.
712 * Pointer to the device shared context. Might be needed
713 * to convert according current device configuration.
715 * Timestamp from CQE to convert.
719 static __rte_always_inline uint64_t
720 mlx5_txpp_convert_rx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t ts)
723 return (ts & UINT32_MAX) + (ts >> 32) * NS_PER_S;
727 * Convert timestamp from mbuf format to linear counter
728 * of Clock Queue completions (24 bits)
731 * Pointer to the device shared context to fetch Tx
732 * packet pacing timestamp and parameters.
734 * Timestamp from mbuf to convert.
736 * positive or zero value - completion ID to wait
737 * negative value - conversion error
739 static __rte_always_inline int32_t
740 mlx5_txpp_convert_tx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t mts)
747 * Read atomically two uint64_t fields and compare lsb bits.
748 * It there is no match - the timestamp was updated in
749 * the service thread, data should be re-read.
751 rte_compiler_barrier();
752 ci = rte_atomic64_read(&sh->txpp.ts.ci_ts);
753 ts = rte_atomic64_read(&sh->txpp.ts.ts);
754 rte_compiler_barrier();
755 if (!((ts ^ ci) << (64 - MLX5_CQ_INDEX_WIDTH)))
758 /* Perform the skew correction, positive value to send earlier. */
759 mts -= sh->txpp.skew;
761 if (unlikely(mts >= UINT64_MAX / 2)) {
762 /* We have negative integer, mts is in the past. */
763 rte_atomic32_inc(&sh->txpp.err_ts_past);
766 tick = sh->txpp.tick;
768 /* Convert delta to completions, round up. */
769 mts = (mts + tick - 1) / tick;
770 if (unlikely(mts >= (1 << MLX5_CQ_INDEX_WIDTH) / 2 - 1)) {
771 /* We have mts is too distant future. */
772 rte_atomic32_inc(&sh->txpp.err_ts_future);
775 mts <<= 64 - MLX5_CQ_INDEX_WIDTH;
777 ci >>= 64 - MLX5_CQ_INDEX_WIDTH;
781 #endif /* RTE_PMD_MLX5_RXTX_H_ */