1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 /* Verbs headers do not support -pedantic. */
14 #pragma GCC diagnostic ignored "-Wpedantic"
16 #include <infiniband/mlx4dv.h>
17 #include <infiniband/verbs.h>
19 #pragma GCC diagnostic error "-Wpedantic"
22 #include <rte_ethdev_driver.h>
24 #include <rte_mempool.h>
29 /** Rx queue counters. */
30 struct mlx4_rxq_stats {
31 unsigned int idx; /**< Mapping index. */
32 uint64_t ipackets; /**< Total of successfully received packets. */
33 uint64_t ibytes; /**< Total of successfully received bytes. */
34 uint64_t idropped; /**< Total of packets dropped when Rx ring full. */
35 uint64_t rx_nombuf; /**< Total of Rx mbuf allocation failures. */
38 /** Rx queue descriptor. */
40 struct priv *priv; /**< Back pointer to private data. */
41 struct rte_mempool *mp; /**< Memory pool for allocations. */
42 struct mlx4_mr *mr; /**< Memory region. */
43 struct ibv_cq *cq; /**< Completion queue. */
44 struct ibv_wq *wq; /**< Work queue. */
45 struct ibv_comp_channel *channel; /**< Rx completion channel. */
46 uint16_t rq_ci; /**< Saved RQ consumer index. */
47 uint16_t port_id; /**< Port ID for incoming packets. */
48 uint16_t sges_n; /**< Number of segments per packet (log2 value). */
49 uint16_t elts_n; /**< Mbuf queue size (log2 value). */
50 struct rte_mbuf *(*elts)[]; /**< Rx elements. */
51 volatile struct mlx4_wqe_data_seg (*wqes)[]; /**< HW queue entries. */
52 volatile uint32_t *rq_db; /**< RQ doorbell record. */
53 uint32_t csum:1; /**< Enable checksum offloading. */
54 uint32_t csum_l2tun:1; /**< Same for L2 tunnels. */
55 uint32_t crc_present:1; /**< CRC must be subtracted. */
56 uint32_t l2tun_offload:1; /**< L2 tunnel offload is enabled. */
57 struct mlx4_cq mcq; /**< Info for directly manipulating the CQ. */
58 struct mlx4_rxq_stats stats; /**< Rx queue counters. */
59 unsigned int socket; /**< CPU socket ID for allocations. */
60 uint32_t usecnt; /**< Number of users relying on queue resources. */
61 uint8_t data[]; /**< Remaining queue resources. */
64 /** Shared flow target for Rx queues. */
66 LIST_ENTRY(mlx4_rss) next; /**< Next entry in list. */
67 struct priv *priv; /**< Back pointer to private data. */
68 uint32_t refcnt; /**< Reference count for this object. */
69 uint32_t usecnt; /**< Number of users relying on @p qp and @p ind. */
70 struct ibv_qp *qp; /**< Queue pair. */
71 struct ibv_rwq_ind_table *ind; /**< Indirection table. */
72 uint64_t fields; /**< Fields for RSS processing (Verbs format). */
73 uint8_t key[MLX4_RSS_HASH_KEY_SIZE]; /**< Hash key to use. */
74 uint16_t queues; /**< Number of target queues. */
75 uint16_t queue_id[]; /**< Target queues. */
80 struct rte_mbuf *buf; /**< Buffer. */
82 volatile struct mlx4_wqe_ctrl_seg *wqe; /**< SQ WQE. */
83 volatile uint32_t *eocb; /**< End of completion burst. */
87 /** Tx queue counters. */
88 struct mlx4_txq_stats {
89 unsigned int idx; /**< Mapping index. */
90 uint64_t opackets; /**< Total of successfully sent packets. */
91 uint64_t obytes; /**< Total of successfully sent bytes. */
92 uint64_t odropped; /**< Total of packets not sent when Tx ring full. */
95 /** Tx queue descriptor. */
97 struct mlx4_sq msq; /**< Info for directly manipulating the SQ. */
98 struct mlx4_cq mcq; /**< Info for directly manipulating the CQ. */
99 unsigned int elts_head; /**< Current index in (*elts)[]. */
100 unsigned int elts_tail; /**< First element awaiting completion. */
101 int elts_comp_cd; /**< Countdown for next completion. */
102 unsigned int elts_comp_cd_init; /**< Initial value for countdown. */
103 unsigned int elts_n; /**< (*elts)[] length. */
104 struct txq_elt (*elts)[]; /**< Tx elements. */
105 struct mlx4_txq_stats stats; /**< Tx queue counters. */
106 uint32_t max_inline; /**< Max inline send size. */
107 uint32_t csum:1; /**< Enable checksum offloading. */
108 uint32_t csum_l2tun:1; /**< Same for L2 tunnels. */
109 uint32_t lb:1; /**< Whether packets should be looped back by eSwitch. */
111 /**< Memory used for storing the first DWORD of data TXBBs. */
113 const struct rte_mempool *mp; /**< Cached memory pool. */
114 struct mlx4_mr *mr; /**< Memory region (for mp). */
115 uint32_t lkey; /**< mr->lkey copy. */
116 } mp2mr[MLX4_PMD_TX_MP_CACHE]; /**< MP to MR translation table. */
117 struct priv *priv; /**< Back pointer to private data. */
118 unsigned int socket; /**< CPU socket ID for allocations. */
119 struct ibv_cq *cq; /**< Completion queue. */
120 struct ibv_qp *qp; /**< Queue pair. */
121 uint8_t data[]; /**< Remaining queue resources. */
126 uint8_t mlx4_rss_hash_key_default[MLX4_RSS_HASH_KEY_SIZE];
127 int mlx4_rss_init(struct priv *priv);
128 void mlx4_rss_deinit(struct priv *priv);
129 struct mlx4_rss *mlx4_rss_get(struct priv *priv, uint64_t fields,
130 const uint8_t key[MLX4_RSS_HASH_KEY_SIZE],
131 uint16_t queues, const uint16_t queue_id[]);
132 void mlx4_rss_put(struct mlx4_rss *rss);
133 int mlx4_rss_attach(struct mlx4_rss *rss);
134 void mlx4_rss_detach(struct mlx4_rss *rss);
135 int mlx4_rxq_attach(struct rxq *rxq);
136 void mlx4_rxq_detach(struct rxq *rxq);
137 uint64_t mlx4_get_rx_port_offloads(struct priv *priv);
138 uint64_t mlx4_get_rx_queue_offloads(struct priv *priv);
139 int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
140 uint16_t desc, unsigned int socket,
141 const struct rte_eth_rxconf *conf,
142 struct rte_mempool *mp);
143 void mlx4_rx_queue_release(void *dpdk_rxq);
147 uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
149 uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
151 uint16_t mlx4_tx_burst_removed(void *dpdk_txq, struct rte_mbuf **pkts,
153 uint16_t mlx4_rx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts,
158 uint64_t mlx4_get_tx_port_offloads(struct priv *priv);
159 int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
160 uint16_t desc, unsigned int socket,
161 const struct rte_eth_txconf *conf);
162 void mlx4_tx_queue_release(void *dpdk_txq);
165 * Get memory region (MR) <-> memory pool (MP) association from txq->mp2mr[].
166 * Call mlx4_txq_add_mr() if MP is not registered yet.
169 * Pointer to Tx queue structure.
171 * Memory pool for which a memory region lkey must be returned.
174 * mr->lkey on success, (uint32_t)-1 on failure.
176 static inline uint32_t
177 mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp)
181 for (i = 0; (i != RTE_DIM(txq->mp2mr)); ++i) {
182 if (unlikely(txq->mp2mr[i].mp == NULL)) {
183 /* Unknown MP, add a new MR for it. */
186 if (txq->mp2mr[i].mp == mp) {
188 return txq->mp2mr[i].lkey;
191 return mlx4_txq_add_mr(txq, mp, i);
194 #endif /* MLX4_RXTX_H_ */