4 * Copyright 2012 6WIND S.A.
5 * Copyright 2012 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.
34 #ifndef RTE_PMD_MLX4_H_
35 #define RTE_PMD_MLX4_H_
41 * Runtime logging through RTE_LOG() is enabled when not in debugging mode.
42 * Intermediate LOG_*() macros add the required end-of-line characters.
45 #define INFO(...) DEBUG(__VA_ARGS__)
46 #define WARN(...) DEBUG(__VA_ARGS__)
47 #define ERROR(...) DEBUG(__VA_ARGS__)
49 #define LOG__(level, m, ...) \
50 RTE_LOG(level, PMD, MLX4_DRIVER_NAME ": " m "%c", __VA_ARGS__)
51 #define LOG_(level, ...) LOG__(level, __VA_ARGS__, '\n')
52 #define INFO(...) LOG_(INFO, __VA_ARGS__)
53 #define WARN(...) LOG_(WARNING, __VA_ARGS__)
54 #define ERROR(...) LOG_(ERR, __VA_ARGS__)
58 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
60 #pragma GCC diagnostic ignored "-Wpedantic"
62 #include <infiniband/verbs.h>
64 #pragma GCC diagnostic error "-Wpedantic"
68 * Maximum number of simultaneous MAC addresses supported.
70 * According to ConnectX's Programmer Reference Manual:
71 * The L2 Address Match is implemented by comparing a MAC/VLAN combination
72 * of 128 MAC addresses and 127 VLAN values, comprising 128x127 possible
75 #define MLX4_MAX_MAC_ADDRESSES 128
77 /* Request send completion once in every 64 sends, might be less. */
78 #define MLX4_PMD_TX_PER_COMP_REQ 64
80 /* Maximum number of Scatter/Gather Elements per Work Request. */
81 #define MLX4_PMD_SGE_WR_N 4
83 /* Maximum size for inline data. */
84 #define MLX4_PMD_MAX_INLINE 0
87 * Maximum number of cached Memory Pools (MPs) per TX queue. Each RTE MP
88 * from which buffers are to be transmitted will have to be mapped by this
89 * driver to their own Memory Region (MR). This is a slow operation.
91 * This value is always 1 for RX queues.
93 #ifndef MLX4_PMD_TX_MP_CACHE
94 #define MLX4_PMD_TX_MP_CACHE 8
98 #define MLX4_ALARM_TIMEOUT_US 100000
100 /* Port parameter. */
101 #define MLX4_PMD_PORT_KVARG "port"
104 PCI_VENDOR_ID_MELLANOX = 0x15b3,
108 PCI_DEVICE_ID_MELLANOX_CONNECTX3 = 0x1003,
109 PCI_DEVICE_ID_MELLANOX_CONNECTX3VF = 0x1004,
110 PCI_DEVICE_ID_MELLANOX_CONNECTX3PRO = 0x1007,
113 #define MLX4_DRIVER_NAME "net_mlx4"
115 /* Bit-field manipulation. */
116 #define BITFIELD_DECLARE(bf, type, size) \
117 type bf[(((size_t)(size) / (sizeof(type) * CHAR_BIT)) + \
118 !!((size_t)(size) % (sizeof(type) * CHAR_BIT)))]
119 #define BITFIELD_DEFINE(bf, type, size) \
120 BITFIELD_DECLARE((bf), type, (size)) = { 0 }
121 #define BITFIELD_SET(bf, b) \
122 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
123 (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] |= \
124 ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
125 #define BITFIELD_RESET(bf, b) \
126 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
127 (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &= \
128 ~((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))
129 #define BITFIELD_ISSET(bf, b) \
130 (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \
131 !!(((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] & \
132 ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))))
134 /* Number of elements in array. */
135 #define elemof(a) (sizeof(a) / sizeof((a)[0]))
140 #define DEBUG__(m, ...) \
141 (fprintf(stderr, "%s:%d: %s(): " m "%c", \
142 __FILE__, __LINE__, __func__, __VA_ARGS__), \
146 * Save/restore errno around DEBUG__().
147 * XXX somewhat undefined behavior, but works.
149 #define DEBUG_(...) \
150 (errno = ((int []){ \
151 *(volatile int *)&errno, \
152 (DEBUG__(__VA_ARGS__), 0) \
154 #define DEBUG(...) DEBUG_(__VA_ARGS__, '\n')
155 #ifndef MLX4_PMD_DEBUG_BROKEN_VERBS
156 #define claim_zero(...) assert((__VA_ARGS__) == 0)
157 #else /* MLX4_PMD_DEBUG_BROKEN_VERBS */
158 #define claim_zero(...) \
159 (void)(((__VA_ARGS__) == 0) || \
160 DEBUG("Assertion `(" # __VA_ARGS__ ") == 0' failed (IGNORED)."))
161 #endif /* MLX4_PMD_DEBUG_BROKEN_VERBS */
162 #define claim_nonzero(...) assert((__VA_ARGS__) != 0)
163 #define claim_positive(...) assert((__VA_ARGS__) >= 0)
166 #define DEBUG(...) (void)0
167 #define claim_zero(...) (__VA_ARGS__)
168 #define claim_nonzero(...) (__VA_ARGS__)
169 #define claim_positive(...) (__VA_ARGS__)
172 struct mlx4_rxq_stats {
173 unsigned int idx; /**< Mapping index. */
174 uint64_t ipackets; /**< Total of successfully received packets. */
175 uint64_t ibytes; /**< Total of successfully received bytes. */
176 uint64_t idropped; /**< Total of packets dropped when RX ring full. */
177 uint64_t rx_nombuf; /**< Total of RX mbuf allocation failures. */
180 /* RX element (scattered packets). */
182 struct ibv_recv_wr wr; /* Work Request. */
183 struct ibv_sge sges[MLX4_PMD_SGE_WR_N]; /* Scatter/Gather Elements. */
184 struct rte_mbuf *bufs[MLX4_PMD_SGE_WR_N]; /* SGEs buffers. */
189 struct ibv_recv_wr wr; /* Work Request. */
190 struct ibv_sge sge; /* Scatter/Gather Element. */
191 /* mbuf pointer is derived from WR_ID(wr.wr_id).offset. */
194 /* RX queue descriptor. */
196 LIST_ENTRY(rxq) next; /* Used by parent queue only */
197 struct priv *priv; /* Back pointer to private data. */
198 struct rte_mempool *mp; /* Memory Pool for allocations. */
199 struct ibv_mr *mr; /* Memory Region (for mp). */
200 struct ibv_cq *cq; /* Completion Queue. */
201 struct ibv_qp *qp; /* Queue Pair. */
202 struct ibv_exp_qp_burst_family *if_qp; /* QP burst interface. */
203 struct ibv_exp_cq_family *if_cq; /* CQ interface. */
204 struct ibv_comp_channel *channel;
205 BITFIELD_DECLARE(mac_configured, uint32_t, MLX4_MAX_MAC_ADDRESSES);
206 struct ibv_flow *mac_flow[MLX4_MAX_MAC_ADDRESSES];
207 unsigned int port_id; /* Port ID for incoming packets. */
208 unsigned int elts_n; /* (*elts)[] length. */
209 unsigned int elts_head; /* Current index in (*elts)[]. */
211 struct rxq_elt_sp (*sp)[]; /* Scattered RX elements. */
212 struct rxq_elt (*no_sp)[]; /* RX elements. */
214 unsigned int sp:1; /* Use scattered RX elements. */
215 unsigned int csum:1; /* Enable checksum offloading. */
216 unsigned int csum_l2tun:1; /* Same for L2 tunnels. */
217 struct mlx4_rxq_stats stats; /* RX queue counters. */
218 unsigned int socket; /* CPU socket ID for allocations. */
219 struct ibv_exp_res_domain *rd; /* Resource Domain. */
222 uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
228 struct rte_mbuf *buf;
231 struct mlx4_txq_stats {
232 unsigned int idx; /**< Mapping index. */
233 uint64_t opackets; /**< Total of successfully sent packets. */
234 uint64_t obytes; /**< Total of successfully sent bytes. */
235 uint64_t odropped; /**< Total of packets not sent when TX ring full. */
239 * Linear buffer type. It is used when transmitting buffers with too many
240 * segments that do not fit the hardware queue (see max_send_sge).
241 * Extra segments are copied (linearized) in such buffers, replacing the
242 * last SGE during TX.
243 * The size is arbitrary but large enough to hold a jumbo frame with
244 * 8 segments considering mbuf.buf_len is about 2048 bytes.
246 typedef uint8_t linear_t[16384];
248 /* TX queue descriptor. */
250 struct priv *priv; /* Back pointer to private data. */
252 const struct rte_mempool *mp; /* Cached Memory Pool. */
253 struct ibv_mr *mr; /* Memory Region (for mp). */
254 uint32_t lkey; /* mr->lkey */
255 } mp2mr[MLX4_PMD_TX_MP_CACHE]; /* MP to MR translation table. */
256 struct ibv_cq *cq; /* Completion Queue. */
257 struct ibv_qp *qp; /* Queue Pair. */
258 struct ibv_exp_qp_burst_family *if_qp; /* QP burst interface. */
259 struct ibv_exp_cq_family *if_cq; /* CQ interface. */
260 uint32_t max_inline; /* Max inline send size <= MLX4_PMD_MAX_INLINE. */
261 unsigned int elts_n; /* (*elts)[] length. */
262 struct txq_elt (*elts)[]; /* TX elements. */
263 unsigned int elts_head; /* Current index in (*elts)[]. */
264 unsigned int elts_tail; /* First element awaiting completion. */
265 unsigned int elts_comp; /* Number of completion requests. */
266 unsigned int elts_comp_cd; /* Countdown for next completion request. */
267 unsigned int elts_comp_cd_init; /* Initial value for countdown. */
268 struct mlx4_txq_stats stats; /* TX queue counters. */
269 linear_t (*elts_linear)[]; /* Linearized buffers. */
270 struct ibv_mr *mr_linear; /* Memory Region for linearized buffers. */
271 unsigned int socket; /* CPU socket ID for allocations. */
272 struct ibv_exp_res_domain *rd; /* Resource Domain. */
278 struct rte_eth_dev *dev; /* Ethernet device. */
279 struct ibv_context *ctx; /* Verbs context. */
280 struct ibv_device_attr device_attr; /* Device properties. */
281 struct ibv_pd *pd; /* Protection Domain. */
283 * MAC addresses array and configuration bit-field.
284 * An extra entry that cannot be modified by the DPDK is reserved
285 * for broadcast frames (destination MAC address ff:ff:ff:ff:ff:ff).
287 struct ether_addr mac[MLX4_MAX_MAC_ADDRESSES];
288 BITFIELD_DECLARE(mac_configured, uint32_t, MLX4_MAX_MAC_ADDRESSES);
289 /* Device properties. */
290 uint16_t mtu; /* Configured MTU. */
291 uint8_t port; /* Physical port number. */
292 unsigned int started:1; /* Device started, flows enabled. */
293 unsigned int hw_qpg:1; /* QP groups are supported. */
294 unsigned int hw_tss:1; /* TSS is supported. */
295 unsigned int hw_rss:1; /* RSS is supported. */
296 unsigned int hw_csum:1; /* Checksum offload is supported. */
297 unsigned int hw_csum_l2tun:1; /* Same for L2 tunnels. */
298 unsigned int rss:1; /* RSS is enabled. */
299 unsigned int vf:1; /* This is a VF device. */
300 unsigned int pending_alarm:1; /* An alarm is pending. */
301 unsigned int isolated:1; /* Toggle isolated mode. */
302 unsigned int inl_recv_size; /* Inline recv size */
303 unsigned int max_rss_tbl_sz; /* Maximum number of RSS queues. */
305 unsigned int rxqs_n; /* RX queues array size. */
306 unsigned int txqs_n; /* TX queues array size. */
307 struct rxq *(*rxqs)[]; /* RX queues. */
308 struct txq *(*txqs)[]; /* TX queues. */
309 struct rte_intr_handle intr_handle_dev; /* Device interrupt handler. */
310 struct rte_intr_handle intr_handle; /* Interrupt handler. */
311 struct rte_flow_drop *flow_drop_queue; /* Flow drop queue. */
312 LIST_HEAD(mlx4_flows, rte_flow) flows;
313 struct rte_intr_conf intr_conf; /* Active interrupt configuration. */
314 LIST_HEAD(mlx4_parents, rxq) parents;
315 rte_spinlock_t lock; /* Lock for control functions. */
318 void priv_lock(struct priv *priv);
319 void priv_unlock(struct priv *priv);
322 rxq_create_qp(struct rxq *rxq,
326 struct rxq *rxq_parent);
329 rxq_parent_cleanup(struct rxq *parent);
332 priv_parent_create(struct priv *priv,
334 uint16_t children_n);
336 #endif /* RTE_PMD_MLX4_H_ */