4 * Copyright 2017 6WIND S.A.
5 * Copyright 2017 Mellanox
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/queue.h>
40 /* Verbs headers do not support -pedantic. */
42 #pragma GCC diagnostic ignored "-Wpedantic"
44 #include <infiniband/verbs.h>
46 #pragma GCC diagnostic error "-Wpedantic"
49 #include <rte_ethdev.h>
51 #include <rte_mempool.h>
55 /** Rx queue counters. */
56 struct mlx4_rxq_stats {
57 unsigned int idx; /**< Mapping index. */
58 uint64_t ipackets; /**< Total of successfully received packets. */
59 uint64_t ibytes; /**< Total of successfully received bytes. */
60 uint64_t idropped; /**< Total of packets dropped when Rx ring full. */
61 uint64_t rx_nombuf; /**< Total of Rx mbuf allocation failures. */
66 struct ibv_recv_wr wr; /**< Work request. */
67 struct ibv_sge sge; /**< Scatter/gather element. */
68 struct rte_mbuf *buf; /**< Buffer. */
71 /** Rx queue descriptor. */
73 struct priv *priv; /**< Back pointer to private data. */
74 struct rte_mempool *mp; /**< Memory pool for allocations. */
75 struct ibv_mr *mr; /**< Memory region (for mp). */
76 struct ibv_cq *cq; /**< Completion queue. */
77 struct ibv_wq *wq; /**< Work queue. */
78 struct ibv_comp_channel *channel; /**< Rx completion channel. */
79 unsigned int port_id; /**< Port ID for incoming packets. */
80 unsigned int elts_n; /**< (*elts)[] length. */
81 unsigned int elts_head; /**< Current index in (*elts)[]. */
82 struct rxq_elt (*elts)[]; /**< Rx elements. */
83 struct mlx4_rxq_stats stats; /**< Rx queue counters. */
84 unsigned int socket; /**< CPU socket ID for allocations. */
85 uint8_t data[]; /**< Remaining queue resources. */
88 /** Shared flow target for Rx queues. */
90 LIST_ENTRY(mlx4_rss) next; /**< Next entry in list. */
91 struct priv *priv; /**< Back pointer to private data. */
92 uint32_t refcnt; /**< Reference count for this object. */
93 uint32_t usecnt; /**< Number of users relying on @p qp and @p ind. */
94 struct ibv_qp *qp; /**< Queue pair. */
95 struct ibv_rwq_ind_table *ind; /**< Indirection table. */
96 uint64_t fields; /**< Fields for RSS processing (Verbs format). */
97 uint8_t key[MLX4_RSS_HASH_KEY_SIZE]; /**< Hash key to use. */
98 uint16_t queues; /**< Number of target queues. */
99 uint16_t queue_id[]; /**< Target queues. */
104 struct ibv_send_wr wr; /**< Work request. */
105 struct ibv_sge sge; /**< Scatter/gather element. */
106 struct rte_mbuf *buf; /**< Buffer. */
109 /** Rx queue counters. */
110 struct mlx4_txq_stats {
111 unsigned int idx; /**< Mapping index. */
112 uint64_t opackets; /**< Total of successfully sent packets. */
113 uint64_t obytes; /**< Total of successfully sent bytes. */
114 uint64_t odropped; /**< Total of packets not sent when Tx ring full. */
117 /** Tx queue descriptor. */
119 struct priv *priv; /**< Back pointer to private data. */
121 const struct rte_mempool *mp; /**< Cached memory pool. */
122 struct ibv_mr *mr; /**< Memory region (for mp). */
123 uint32_t lkey; /**< mr->lkey copy. */
124 } mp2mr[MLX4_PMD_TX_MP_CACHE]; /**< MP to MR translation table. */
125 struct ibv_cq *cq; /**< Completion queue. */
126 struct ibv_qp *qp; /**< Queue pair. */
127 uint32_t max_inline; /**< Max inline send size. */
128 unsigned int elts_n; /**< (*elts)[] length. */
129 struct txq_elt (*elts)[]; /**< Tx elements. */
130 unsigned int elts_head; /**< Current index in (*elts)[]. */
131 unsigned int elts_tail; /**< First element awaiting completion. */
132 unsigned int elts_comp; /**< Number of completion requests. */
133 unsigned int elts_comp_cd; /**< Countdown for next completion. */
134 unsigned int elts_comp_cd_init; /**< Initial value for countdown. */
135 struct mlx4_txq_stats stats; /**< Tx queue counters. */
136 unsigned int socket; /**< CPU socket ID for allocations. */
137 uint8_t data[]; /**< Remaining queue resources. */
142 uint8_t mlx4_rss_hash_key_default[MLX4_RSS_HASH_KEY_SIZE];
143 struct mlx4_rss *mlx4_rss_get(struct priv *priv, uint64_t fields,
144 uint8_t key[MLX4_RSS_HASH_KEY_SIZE],
145 uint16_t queues, const uint16_t queue_id[]);
146 void mlx4_rss_put(struct mlx4_rss *rss);
147 int mlx4_rss_attach(struct mlx4_rss *rss);
148 void mlx4_rss_detach(struct mlx4_rss *rss);
149 int mlx4_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
150 uint16_t desc, unsigned int socket,
151 const struct rte_eth_rxconf *conf,
152 struct rte_mempool *mp);
153 void mlx4_rx_queue_release(void *dpdk_rxq);
157 uint32_t mlx4_txq_mp2mr(struct txq *txq, struct rte_mempool *mp);
158 uint16_t mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts,
160 uint16_t mlx4_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts,
162 uint16_t mlx4_tx_burst_removed(void *dpdk_txq, struct rte_mbuf **pkts,
164 uint16_t mlx4_rx_burst_removed(void *dpdk_rxq, struct rte_mbuf **pkts,
169 int mlx4_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
170 uint16_t desc, unsigned int socket,
171 const struct rte_eth_txconf *conf);
172 void mlx4_tx_queue_release(void *dpdk_txq);
174 #endif /* MLX4_RXTX_H_ */