Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2015 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <unistd.h>
7 : :
8 : : #include <rte_ether.h>
9 : : #include <ethdev_driver.h>
10 : : #include <rte_interrupts.h>
11 : : #include <rte_alarm.h>
12 : : #include <rte_cycles.h>
13 : :
14 : : #include <mlx5_malloc.h>
15 : :
16 : : #include "mlx5.h"
17 : : #include "mlx5_flow.h"
18 : : #include "mlx5_rx.h"
19 : : #include "mlx5_tx.h"
20 : : #include "mlx5_utils.h"
21 : : #include "mlx5_lsc_intr.h"
22 : : #include "rte_pmd_mlx5.h"
23 : :
24 : : static void mlx5_traffic_disable_legacy(struct rte_eth_dev *dev);
25 : :
26 : : /**
27 : : * Stop traffic on Tx queues.
28 : : *
29 : : * @param dev
30 : : * Pointer to Ethernet device structure.
31 : : */
32 : : static void
33 : 0 : mlx5_txq_stop(struct rte_eth_dev *dev)
34 : : {
35 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
36 : : unsigned int i;
37 : :
38 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i)
39 : 0 : mlx5_txq_release(dev, i);
40 : 0 : }
41 : :
42 : : /**
43 : : * Start traffic on Tx queues.
44 : : *
45 : : * @param dev
46 : : * Pointer to Ethernet device structure.
47 : : *
48 : : * @return
49 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
50 : : */
51 : : static int
52 : 0 : mlx5_txq_start(struct rte_eth_dev *dev)
53 : : {
54 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
55 : 0 : uint32_t log_max_wqe = log2above(mlx5_dev_get_max_wq_size(priv->sh));
56 : : uint32_t flags = MLX5_MEM_RTE | MLX5_MEM_ZERO;
57 : : unsigned int i, cnt;
58 : : int ret;
59 : :
60 [ # # ]: 0 : for (cnt = log_max_wqe; cnt > 0; cnt -= 1) {
61 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
62 : 0 : struct mlx5_txq_ctrl *txq_ctrl = mlx5_txq_get(dev, i);
63 : : struct mlx5_txq_data *txq_data;
64 : :
65 [ # # ]: 0 : if (!txq_ctrl)
66 : 0 : continue;
67 : : txq_data = &txq_ctrl->txq;
68 [ # # ]: 0 : if (txq_data->elts_n != cnt) {
69 : 0 : mlx5_txq_release(dev, i);
70 : 0 : continue;
71 : : }
72 [ # # ]: 0 : if (!txq_ctrl->is_hairpin)
73 : 0 : mlx5_txq_alloc_elts(txq_ctrl);
74 : : MLX5_ASSERT(!txq_ctrl->obj);
75 [ # # # # : 0 : txq_ctrl->obj = mlx5_malloc_numa_tolerant(flags,
# # ]
76 : : sizeof(struct mlx5_txq_obj),
77 : : 0, txq_ctrl->socket);
78 [ # # ]: 0 : if (!txq_ctrl->obj) {
79 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u cannot allocate "
80 : : "memory resources.", dev->data->port_id,
81 : : txq_data->idx);
82 : 0 : rte_errno = ENOMEM;
83 : 0 : goto error;
84 : : }
85 : 0 : ret = priv->obj_ops.txq_obj_new(dev, i);
86 [ # # ]: 0 : if (ret < 0) {
87 : 0 : mlx5_free(txq_ctrl->obj);
88 : 0 : txq_ctrl->obj = NULL;
89 : 0 : goto error;
90 : : }
91 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
92 : 0 : size_t size = txq_data->cqe_s * sizeof(*txq_data->fcqs);
93 : :
94 [ # # # # : 0 : txq_data->fcqs = mlx5_malloc_numa_tolerant(flags, size,
# # ]
95 : : RTE_CACHE_LINE_SIZE,
96 : : txq_ctrl->socket);
97 [ # # ]: 0 : if (!txq_data->fcqs) {
98 : 0 : DRV_LOG(ERR, "Port %u Tx queue %u cannot "
99 : : "allocate memory (FCQ).",
100 : : dev->data->port_id, i);
101 : 0 : priv->obj_ops.txq_obj_release(txq_ctrl->obj);
102 : 0 : mlx5_free(txq_ctrl->obj);
103 : 0 : txq_ctrl->obj = NULL;
104 : 0 : rte_errno = ENOMEM;
105 : 0 : goto error;
106 : : }
107 : : }
108 : 0 : DRV_LOG(DEBUG, "Port %u txq %u updated with %p.",
109 : : dev->data->port_id, i, (void *)&txq_ctrl->obj);
110 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->txqsobj, txq_ctrl->obj, next);
111 : : }
112 : : }
113 : : return 0;
114 : 0 : error:
115 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
116 : : do {
117 : 0 : mlx5_txq_release(dev, i);
118 [ # # ]: 0 : } while (i-- != 0);
119 : 0 : rte_errno = ret; /* Restore rte_errno. */
120 : 0 : return -rte_errno;
121 : : }
122 : :
123 : : static struct rte_mbuf *
124 : 0 : mlx5_alloc_null_mbuf(uint32_t data_len)
125 : : {
126 : 0 : size_t alloc_size = sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM +
127 : 0 : rte_align32pow2(data_len);
128 : : struct rte_mbuf *m;
129 : :
130 : 0 : m = mlx5_malloc(MLX5_MEM_ZERO, alloc_size, 0, SOCKET_ID_ANY);
131 [ # # ]: 0 : if (m == NULL)
132 : : return NULL;
133 : 0 : m->buf_addr = RTE_PTR_ADD(m, sizeof(*m));
134 : 0 : m->buf_len = alloc_size - sizeof(*m);
135 : 0 : rte_mbuf_iova_set(m, rte_mem_virt2iova(m->buf_addr));
136 : 0 : m->data_off = RTE_PKTMBUF_HEADROOM;
137 : 0 : m->refcnt = 1;
138 : 0 : m->nb_segs = 1;
139 : 0 : m->port = RTE_MBUF_PORT_INVALID;
140 : 0 : m->pool = NULL;
141 : 0 : return m;
142 : : }
143 : :
144 : : /**
145 : : * Register Rx queue mempools and fill the Rx queue cache.
146 : : * This function tolerates repeated mempool registration.
147 : : *
148 : : * @param[in] rxq_ctrl
149 : : * Rx queue control data.
150 : : *
151 : : * @return
152 : : * 0 on success, (-1) on failure and rte_errno is set.
153 : : */
154 : : static int
155 : 0 : mlx5_rxq_mempool_register(struct mlx5_rxq_ctrl *rxq_ctrl)
156 : : {
157 : : struct rte_mempool *mp;
158 : : struct mlx5_eth_rxseg *seg;
159 : : uint16_t s;
160 : : int ret = 0;
161 : :
162 : 0 : mlx5_mr_flush_local_cache(&rxq_ctrl->rxq.mr_ctrl);
163 : : /* MPRQ mempool is registered on creation, just fill the cache. */
164 [ # # ]: 0 : if (mlx5_rxq_mprq_enabled(&rxq_ctrl->rxq))
165 : 0 : return mlx5_mr_mempool_populate_cache(&rxq_ctrl->rxq.mr_ctrl,
166 : : rxq_ctrl->rxq.mprq_mp);
167 [ # # ]: 0 : for (s = 0; s < rxq_ctrl->rxq.rxseg_n; s++) {
168 : 0 : seg = &rxq_ctrl->rxq.rxseg[s];
169 : 0 : mp = seg->mp;
170 [ # # ]: 0 : if (mp) { /* Regular segment */
171 : 0 : bool is_extmem = (rte_pktmbuf_priv_flags(mp) &
172 : : RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF) != 0;
173 : 0 : ret = mlx5_mr_mempool_register(rxq_ctrl->sh->cdev, mp, is_extmem);
174 [ # # # # ]: 0 : if (ret < 0 && rte_errno != EEXIST)
175 : 0 : goto error;
176 : 0 : ret = mlx5_mr_mempool_populate_cache(&rxq_ctrl->rxq.mr_ctrl, mp);
177 [ # # ]: 0 : if (ret < 0)
178 : 0 : goto error;
179 : : } else { /* NULL segment used in selective Rx */
180 : 0 : seg->null_mbuf = mlx5_alloc_null_mbuf(seg->length);
181 [ # # ]: 0 : if (seg->null_mbuf == NULL) {
182 : 0 : rte_errno = ENOMEM;
183 : : ret = -rte_errno;
184 : 0 : goto error;
185 : : }
186 : : }
187 : : }
188 : : return 0;
189 : :
190 : 0 : error:
191 [ # # ]: 0 : while (s-- > 0) {
192 : 0 : seg = &rxq_ctrl->rxq.rxseg[s];
193 : 0 : mlx5_free(seg->null_mbuf);
194 : 0 : seg->null_mbuf = NULL;
195 : : }
196 : : return ret;
197 : : }
198 : :
199 : : /**
200 : : * Stop traffic on Rx queues.
201 : : *
202 : : * @param dev
203 : : * Pointer to Ethernet device structure.
204 : : */
205 : : static void
206 : 0 : mlx5_rxq_stop(struct rte_eth_dev *dev)
207 : : {
208 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
209 : : unsigned int i;
210 : :
211 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i)
212 : 0 : mlx5_rxq_release(dev, i);
213 : 0 : }
214 : :
215 : : static int
216 : 0 : mlx5_rxq_ctrl_prepare(struct rte_eth_dev *dev, struct mlx5_rxq_ctrl *rxq_ctrl,
217 : : unsigned int idx)
218 : : {
219 : : int ret = 0;
220 : :
221 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin) {
222 : : /*
223 : : * Pre-register the mempools. Regardless of whether
224 : : * the implicit registration is enabled or not,
225 : : * Rx mempool destruction is tracked to free MRs.
226 : : */
227 [ # # ]: 0 : if (mlx5_rxq_mempool_register(rxq_ctrl) < 0)
228 : 0 : return -rte_errno;
229 : 0 : ret = mlx5_rxq_alloc_elts(rxq_ctrl);
230 [ # # ]: 0 : if (ret)
231 : : return ret;
232 : : }
233 : : MLX5_ASSERT(!rxq_ctrl->obj);
234 [ # # # # : 0 : rxq_ctrl->obj = mlx5_malloc_numa_tolerant(MLX5_MEM_RTE | MLX5_MEM_ZERO,
# # ]
235 : : sizeof(*rxq_ctrl->obj), 0,
236 : : rxq_ctrl->socket);
237 [ # # ]: 0 : if (!rxq_ctrl->obj) {
238 : 0 : DRV_LOG(ERR, "Port %u Rx queue %u can't allocate resources.",
239 : : dev->data->port_id, idx);
240 : 0 : rte_errno = ENOMEM;
241 : 0 : return -rte_errno;
242 : : }
243 : 0 : DRV_LOG(DEBUG, "Port %u rxq %u updated with %p.", dev->data->port_id,
244 : : idx, (void *)&rxq_ctrl->obj);
245 : 0 : return 0;
246 : : }
247 : :
248 : : /**
249 : : * Start traffic on Rx queues.
250 : : *
251 : : * @param dev
252 : : * Pointer to Ethernet device structure.
253 : : *
254 : : * @return
255 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
256 : : */
257 : : static int
258 : 0 : mlx5_rxq_start(struct rte_eth_dev *dev)
259 : : {
260 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
261 : : unsigned int i;
262 : : int ret = 0;
263 : :
264 : : /* Allocate/reuse/resize mempool for Multi-Packet RQ. */
265 [ # # ]: 0 : if (mlx5_mprq_alloc_mp(dev)) {
266 : : /* Should not release Rx queues but return immediately. */
267 : 0 : return -rte_errno;
268 : : }
269 : 0 : DRV_LOG(DEBUG, "Port %u max work queue size is %d.",
270 : : dev->data->port_id, mlx5_dev_get_max_wq_size(priv->sh));
271 : 0 : DRV_LOG(DEBUG, "Port %u dev_cap.max_sge is %d.",
272 : : dev->data->port_id, priv->sh->dev_cap.max_sge);
273 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
274 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_ref(dev, i);
275 : : struct mlx5_rxq_ctrl *rxq_ctrl;
276 : :
277 [ # # ]: 0 : if (rxq == NULL)
278 : 0 : continue;
279 : 0 : rxq_ctrl = rxq->ctrl;
280 [ # # ]: 0 : if (!rxq_ctrl->started)
281 [ # # ]: 0 : if (mlx5_rxq_ctrl_prepare(dev, rxq_ctrl, i) < 0)
282 : 0 : goto error;
283 : 0 : ret = priv->obj_ops.rxq_obj_new(rxq);
284 [ # # ]: 0 : if (ret) {
285 : 0 : mlx5_free(rxq_ctrl->obj);
286 : 0 : rxq_ctrl->obj = NULL;
287 : 0 : goto error;
288 : : }
289 [ # # ]: 0 : if (!rxq_ctrl->started)
290 [ # # ]: 0 : LIST_INSERT_HEAD(&priv->rxqsobj, rxq_ctrl->obj, next);
291 : 0 : rxq_ctrl->started = true;
292 : : }
293 : : return 0;
294 : 0 : error:
295 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
296 : : do {
297 : 0 : mlx5_rxq_release(dev, i);
298 [ # # ]: 0 : } while (i-- != 0);
299 : 0 : rte_errno = ret; /* Restore rte_errno. */
300 : 0 : return -rte_errno;
301 : : }
302 : :
303 : : /**
304 : : * Binds Tx queues to Rx queues for hairpin.
305 : : *
306 : : * Binds Tx queues to the target Rx queues.
307 : : *
308 : : * @param dev
309 : : * Pointer to Ethernet device structure.
310 : : *
311 : : * @return
312 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
313 : : */
314 : : static int
315 : 0 : mlx5_hairpin_auto_bind(struct rte_eth_dev *dev)
316 : : {
317 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
318 : 0 : struct mlx5_devx_modify_sq_attr sq_attr = { 0 };
319 : 0 : struct mlx5_devx_modify_rq_attr rq_attr = { 0 };
320 : : struct mlx5_txq_ctrl *txq_ctrl;
321 : : struct mlx5_rxq_priv *rxq;
322 : : struct mlx5_rxq_ctrl *rxq_ctrl;
323 : : struct mlx5_devx_obj *sq;
324 : : struct mlx5_devx_obj *rq;
325 : : unsigned int i;
326 : : int ret = 0;
327 : : bool need_auto = false;
328 : 0 : uint16_t self_port = dev->data->port_id;
329 : :
330 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
331 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
332 [ # # ]: 0 : if (!txq_ctrl)
333 : 0 : continue;
334 [ # # ]: 0 : if (!txq_ctrl->is_hairpin ||
335 [ # # ]: 0 : txq_ctrl->hairpin_conf.peers[0].port != self_port) {
336 : 0 : mlx5_txq_release(dev, i);
337 : 0 : continue;
338 : : }
339 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.manual_bind) {
340 : 0 : mlx5_txq_release(dev, i);
341 : 0 : return 0;
342 : : }
343 : : need_auto = true;
344 : 0 : mlx5_txq_release(dev, i);
345 : : }
346 [ # # ]: 0 : if (!need_auto)
347 : : return 0;
348 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
349 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
350 [ # # ]: 0 : if (!txq_ctrl)
351 : 0 : continue;
352 : : /* Skip hairpin queues with other peer ports. */
353 [ # # ]: 0 : if (!txq_ctrl->is_hairpin ||
354 [ # # ]: 0 : txq_ctrl->hairpin_conf.peers[0].port != self_port) {
355 : 0 : mlx5_txq_release(dev, i);
356 : 0 : continue;
357 : : }
358 [ # # ]: 0 : if (!txq_ctrl->obj) {
359 : 0 : rte_errno = ENOMEM;
360 : 0 : DRV_LOG(ERR, "port %u no txq object found: %d",
361 : : dev->data->port_id, i);
362 : 0 : mlx5_txq_release(dev, i);
363 : 0 : return -rte_errno;
364 : : }
365 : 0 : sq = txq_ctrl->obj->sq;
366 : 0 : rxq = mlx5_rxq_get(dev, txq_ctrl->hairpin_conf.peers[0].queue);
367 [ # # ]: 0 : if (rxq == NULL) {
368 : 0 : mlx5_txq_release(dev, i);
369 : 0 : rte_errno = EINVAL;
370 : 0 : DRV_LOG(ERR, "port %u no rxq object found: %d",
371 : : dev->data->port_id,
372 : : txq_ctrl->hairpin_conf.peers[0].queue);
373 : 0 : return -rte_errno;
374 : : }
375 : 0 : rxq_ctrl = rxq->ctrl;
376 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin ||
377 [ # # ]: 0 : rxq->hairpin_conf.peers[0].queue != i) {
378 : 0 : rte_errno = ENOMEM;
379 : 0 : DRV_LOG(ERR, "port %u Tx queue %d can't be binded to "
380 : : "Rx queue %d", dev->data->port_id,
381 : : i, txq_ctrl->hairpin_conf.peers[0].queue);
382 : 0 : goto error;
383 : : }
384 : 0 : rq = rxq_ctrl->obj->rq;
385 [ # # ]: 0 : if (!rq) {
386 : 0 : rte_errno = ENOMEM;
387 : 0 : DRV_LOG(ERR, "port %u hairpin no matching rxq: %d",
388 : : dev->data->port_id,
389 : : txq_ctrl->hairpin_conf.peers[0].queue);
390 : 0 : goto error;
391 : : }
392 : 0 : sq_attr.state = MLX5_SQC_STATE_RDY;
393 : 0 : sq_attr.sq_state = MLX5_SQC_STATE_RST;
394 : 0 : sq_attr.hairpin_peer_rq = rq->id;
395 : 0 : sq_attr.hairpin_peer_vhca =
396 : 0 : priv->sh->cdev->config.hca_attr.vhca_id;
397 : 0 : ret = mlx5_devx_cmd_modify_sq(sq, &sq_attr);
398 [ # # ]: 0 : if (ret)
399 : 0 : goto error;
400 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
401 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RST;
402 : 0 : rq_attr.hairpin_peer_sq = sq->id;
403 : 0 : rq_attr.hairpin_peer_vhca =
404 : 0 : priv->sh->cdev->config.hca_attr.vhca_id;
405 : 0 : ret = mlx5_devx_cmd_modify_rq(rq, &rq_attr);
406 [ # # ]: 0 : if (ret)
407 : 0 : goto error;
408 : : /* Qs with auto-bind will be destroyed directly. */
409 : 0 : rxq->hairpin_status = 1;
410 : 0 : txq_ctrl->hairpin_status = 1;
411 : 0 : mlx5_txq_release(dev, i);
412 : : }
413 : : return 0;
414 : 0 : error:
415 : 0 : mlx5_txq_release(dev, i);
416 : 0 : return -rte_errno;
417 : : }
418 : :
419 : : /*
420 : : * Fetch the peer queue's SW & HW information.
421 : : *
422 : : * @param dev
423 : : * Pointer to Ethernet device structure.
424 : : * @param peer_queue
425 : : * Index of the queue to fetch the information.
426 : : * @param current_info
427 : : * Pointer to the input peer information, not used currently.
428 : : * @param peer_info
429 : : * Pointer to the structure to store the information, output.
430 : : * @param direction
431 : : * Positive to get the RxQ information, zero to get the TxQ information.
432 : : *
433 : : * @return
434 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
435 : : */
436 : : int
437 : 0 : mlx5_hairpin_queue_peer_update(struct rte_eth_dev *dev, uint16_t peer_queue,
438 : : struct rte_hairpin_peer_info *current_info,
439 : : struct rte_hairpin_peer_info *peer_info,
440 : : uint32_t direction)
441 : : {
442 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
443 : : RTE_SET_USED(current_info);
444 : :
445 [ # # ]: 0 : if (dev->data->dev_started == 0) {
446 : 0 : rte_errno = EBUSY;
447 : 0 : DRV_LOG(ERR, "peer port %u is not started",
448 : : dev->data->port_id);
449 : 0 : return -rte_errno;
450 : : }
451 : : /*
452 : : * Peer port used as egress. In the current design, hairpin Tx queue
453 : : * will be bound to the peer Rx queue. Indeed, only the information of
454 : : * peer Rx queue needs to be fetched.
455 : : */
456 [ # # ]: 0 : if (direction == 0) {
457 : : struct mlx5_txq_ctrl *txq_ctrl;
458 : :
459 : 0 : txq_ctrl = mlx5_txq_get(dev, peer_queue);
460 [ # # ]: 0 : if (txq_ctrl == NULL) {
461 : 0 : rte_errno = EINVAL;
462 : 0 : DRV_LOG(ERR, "Failed to get port %u Tx queue %d",
463 : : dev->data->port_id, peer_queue);
464 : 0 : return -rte_errno;
465 : : }
466 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
467 : 0 : rte_errno = EINVAL;
468 : 0 : DRV_LOG(ERR, "port %u queue %d is not a hairpin Txq",
469 : : dev->data->port_id, peer_queue);
470 : 0 : mlx5_txq_release(dev, peer_queue);
471 : 0 : return -rte_errno;
472 : : }
473 [ # # # # ]: 0 : if (txq_ctrl->obj == NULL || txq_ctrl->obj->sq == NULL) {
474 : 0 : rte_errno = ENOMEM;
475 : 0 : DRV_LOG(ERR, "port %u no Txq object found: %d",
476 : : dev->data->port_id, peer_queue);
477 : 0 : mlx5_txq_release(dev, peer_queue);
478 : 0 : return -rte_errno;
479 : : }
480 : 0 : peer_info->qp_id = mlx5_txq_get_sqn(txq_ctrl);
481 : 0 : peer_info->vhca_id = priv->sh->cdev->config.hca_attr.vhca_id;
482 : : /* 1-to-1 mapping, only the first one is used. */
483 : 0 : peer_info->peer_q = txq_ctrl->hairpin_conf.peers[0].queue;
484 : 0 : peer_info->tx_explicit = txq_ctrl->hairpin_conf.tx_explicit;
485 : 0 : peer_info->manual_bind = txq_ctrl->hairpin_conf.manual_bind;
486 : 0 : mlx5_txq_release(dev, peer_queue);
487 : : } else { /* Peer port used as ingress. */
488 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, peer_queue);
489 : : struct mlx5_rxq_ctrl *rxq_ctrl;
490 : :
491 [ # # ]: 0 : if (rxq == NULL) {
492 : 0 : rte_errno = EINVAL;
493 : 0 : DRV_LOG(ERR, "Failed to get port %u Rx queue %d",
494 : : dev->data->port_id, peer_queue);
495 : 0 : return -rte_errno;
496 : : }
497 : 0 : rxq_ctrl = rxq->ctrl;
498 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin) {
499 : 0 : rte_errno = EINVAL;
500 : 0 : DRV_LOG(ERR, "port %u queue %d is not a hairpin Rxq",
501 : : dev->data->port_id, peer_queue);
502 : 0 : return -rte_errno;
503 : : }
504 [ # # # # ]: 0 : if (rxq_ctrl->obj == NULL || rxq_ctrl->obj->rq == NULL) {
505 : 0 : rte_errno = ENOMEM;
506 : 0 : DRV_LOG(ERR, "port %u no Rxq object found: %d",
507 : : dev->data->port_id, peer_queue);
508 : 0 : return -rte_errno;
509 : : }
510 : 0 : peer_info->qp_id = rxq_ctrl->obj->rq->id;
511 : 0 : peer_info->vhca_id = priv->sh->cdev->config.hca_attr.vhca_id;
512 : 0 : peer_info->peer_q = rxq->hairpin_conf.peers[0].queue;
513 : 0 : peer_info->tx_explicit = rxq->hairpin_conf.tx_explicit;
514 : 0 : peer_info->manual_bind = rxq->hairpin_conf.manual_bind;
515 : : }
516 : : return 0;
517 : : }
518 : :
519 : : /*
520 : : * Bind the hairpin queue with the peer HW information.
521 : : * This needs to be called twice both for Tx and Rx queues of a pair.
522 : : * If the queue is already bound, it is considered successful.
523 : : *
524 : : * @param dev
525 : : * Pointer to Ethernet device structure.
526 : : * @param cur_queue
527 : : * Index of the queue to change the HW configuration to bind.
528 : : * @param peer_info
529 : : * Pointer to information of the peer queue.
530 : : * @param direction
531 : : * Positive to configure the TxQ, zero to configure the RxQ.
532 : : *
533 : : * @return
534 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
535 : : */
536 : : int
537 : 0 : mlx5_hairpin_queue_peer_bind(struct rte_eth_dev *dev, uint16_t cur_queue,
538 : : struct rte_hairpin_peer_info *peer_info,
539 : : uint32_t direction)
540 : : {
541 : : int ret = 0;
542 : :
543 : : /*
544 : : * Consistency checking of the peer queue: opposite direction is used
545 : : * to get the peer queue info with ethdev port ID, no need to check.
546 : : */
547 [ # # ]: 0 : if (peer_info->peer_q != cur_queue) {
548 : 0 : rte_errno = EINVAL;
549 : 0 : DRV_LOG(ERR, "port %u queue %d and peer queue %d mismatch",
550 : : dev->data->port_id, cur_queue, peer_info->peer_q);
551 : 0 : return -rte_errno;
552 : : }
553 [ # # ]: 0 : if (direction != 0) {
554 : : struct mlx5_txq_ctrl *txq_ctrl;
555 : 0 : struct mlx5_devx_modify_sq_attr sq_attr = { 0 };
556 : :
557 : 0 : txq_ctrl = mlx5_txq_get(dev, cur_queue);
558 [ # # ]: 0 : if (txq_ctrl == NULL) {
559 : 0 : rte_errno = EINVAL;
560 : 0 : DRV_LOG(ERR, "Failed to get port %u Tx queue %d",
561 : : dev->data->port_id, cur_queue);
562 : 0 : return -rte_errno;
563 : : }
564 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
565 : 0 : rte_errno = EINVAL;
566 : 0 : DRV_LOG(ERR, "port %u queue %d not a hairpin Txq",
567 : : dev->data->port_id, cur_queue);
568 : 0 : mlx5_txq_release(dev, cur_queue);
569 : 0 : return -rte_errno;
570 : : }
571 [ # # # # ]: 0 : if (txq_ctrl->obj == NULL || txq_ctrl->obj->sq == NULL) {
572 : 0 : rte_errno = ENOMEM;
573 : 0 : DRV_LOG(ERR, "port %u no Txq object found: %d",
574 : : dev->data->port_id, cur_queue);
575 : 0 : mlx5_txq_release(dev, cur_queue);
576 : 0 : return -rte_errno;
577 : : }
578 [ # # ]: 0 : if (txq_ctrl->hairpin_status != 0) {
579 : 0 : DRV_LOG(DEBUG, "port %u Tx queue %d is already bound",
580 : : dev->data->port_id, cur_queue);
581 : 0 : mlx5_txq_release(dev, cur_queue);
582 : 0 : return 0;
583 : : }
584 : : /*
585 : : * All queues' of one port consistency checking is done in the
586 : : * bind() function, and that is optional.
587 : : */
588 : 0 : if (peer_info->tx_explicit !=
589 [ # # ]: 0 : txq_ctrl->hairpin_conf.tx_explicit) {
590 : 0 : rte_errno = EINVAL;
591 : 0 : DRV_LOG(ERR, "port %u Tx queue %d and peer Tx rule mode"
592 : : " mismatch", dev->data->port_id, cur_queue);
593 : 0 : mlx5_txq_release(dev, cur_queue);
594 : 0 : return -rte_errno;
595 : : }
596 : 0 : if (peer_info->manual_bind !=
597 [ # # ]: 0 : txq_ctrl->hairpin_conf.manual_bind) {
598 : 0 : rte_errno = EINVAL;
599 : 0 : DRV_LOG(ERR, "port %u Tx queue %d and peer binding mode"
600 : : " mismatch", dev->data->port_id, cur_queue);
601 : 0 : mlx5_txq_release(dev, cur_queue);
602 : 0 : return -rte_errno;
603 : : }
604 : 0 : sq_attr.state = MLX5_SQC_STATE_RDY;
605 : 0 : sq_attr.sq_state = MLX5_SQC_STATE_RST;
606 : 0 : sq_attr.hairpin_peer_rq = peer_info->qp_id;
607 : 0 : sq_attr.hairpin_peer_vhca = peer_info->vhca_id;
608 : 0 : ret = mlx5_devx_cmd_modify_sq(txq_ctrl->obj->sq, &sq_attr);
609 [ # # ]: 0 : if (ret == 0)
610 : 0 : txq_ctrl->hairpin_status = 1;
611 : 0 : mlx5_txq_release(dev, cur_queue);
612 : : } else {
613 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, cur_queue);
614 : : struct mlx5_rxq_ctrl *rxq_ctrl;
615 : 0 : struct mlx5_devx_modify_rq_attr rq_attr = { 0 };
616 : :
617 [ # # ]: 0 : if (rxq == NULL) {
618 : 0 : rte_errno = EINVAL;
619 : 0 : DRV_LOG(ERR, "Failed to get port %u Rx queue %d",
620 : : dev->data->port_id, cur_queue);
621 : 0 : return -rte_errno;
622 : : }
623 : 0 : rxq_ctrl = rxq->ctrl;
624 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin) {
625 : 0 : rte_errno = EINVAL;
626 : 0 : DRV_LOG(ERR, "port %u queue %d not a hairpin Rxq",
627 : : dev->data->port_id, cur_queue);
628 : 0 : return -rte_errno;
629 : : }
630 [ # # # # ]: 0 : if (rxq_ctrl->obj == NULL || rxq_ctrl->obj->rq == NULL) {
631 : 0 : rte_errno = ENOMEM;
632 : 0 : DRV_LOG(ERR, "port %u no Rxq object found: %d",
633 : : dev->data->port_id, cur_queue);
634 : 0 : return -rte_errno;
635 : : }
636 [ # # ]: 0 : if (rxq->hairpin_status != 0) {
637 : 0 : DRV_LOG(DEBUG, "port %u Rx queue %d is already bound",
638 : : dev->data->port_id, cur_queue);
639 : 0 : return 0;
640 : : }
641 : 0 : if (peer_info->tx_explicit !=
642 [ # # ]: 0 : rxq->hairpin_conf.tx_explicit) {
643 : 0 : rte_errno = EINVAL;
644 : 0 : DRV_LOG(ERR, "port %u Rx queue %d and peer Tx rule mode"
645 : : " mismatch", dev->data->port_id, cur_queue);
646 : 0 : return -rte_errno;
647 : : }
648 : 0 : if (peer_info->manual_bind !=
649 [ # # ]: 0 : rxq->hairpin_conf.manual_bind) {
650 : 0 : rte_errno = EINVAL;
651 : 0 : DRV_LOG(ERR, "port %u Rx queue %d and peer binding mode"
652 : : " mismatch", dev->data->port_id, cur_queue);
653 : 0 : return -rte_errno;
654 : : }
655 : 0 : rq_attr.state = MLX5_RQC_STATE_RDY;
656 : : rq_attr.rq_state = MLX5_RQC_STATE_RST;
657 : 0 : rq_attr.hairpin_peer_sq = peer_info->qp_id;
658 : 0 : rq_attr.hairpin_peer_vhca = peer_info->vhca_id;
659 : 0 : ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
660 [ # # ]: 0 : if (ret == 0)
661 : 0 : rxq->hairpin_status = 1;
662 : : }
663 : : return ret;
664 : : }
665 : :
666 : : /*
667 : : * Unbind the hairpin queue and reset its HW configuration.
668 : : * This needs to be called twice both for Tx and Rx queues of a pair.
669 : : * If the queue is already unbound, it is considered successful.
670 : : *
671 : : * @param dev
672 : : * Pointer to Ethernet device structure.
673 : : * @param cur_queue
674 : : * Index of the queue to change the HW configuration to unbind.
675 : : * @param direction
676 : : * Positive to reset the TxQ, zero to reset the RxQ.
677 : : *
678 : : * @return
679 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
680 : : */
681 : : int
682 : 0 : mlx5_hairpin_queue_peer_unbind(struct rte_eth_dev *dev, uint16_t cur_queue,
683 : : uint32_t direction)
684 : : {
685 : : int ret = 0;
686 : :
687 [ # # ]: 0 : if (direction != 0) {
688 : : struct mlx5_txq_ctrl *txq_ctrl;
689 : 0 : struct mlx5_devx_modify_sq_attr sq_attr = { 0 };
690 : :
691 : 0 : txq_ctrl = mlx5_txq_get(dev, cur_queue);
692 [ # # ]: 0 : if (txq_ctrl == NULL) {
693 : 0 : rte_errno = EINVAL;
694 : 0 : DRV_LOG(ERR, "Failed to get port %u Tx queue %d",
695 : : dev->data->port_id, cur_queue);
696 : 0 : return -rte_errno;
697 : : }
698 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
699 : 0 : rte_errno = EINVAL;
700 : 0 : DRV_LOG(ERR, "port %u queue %d not a hairpin Txq",
701 : : dev->data->port_id, cur_queue);
702 : 0 : mlx5_txq_release(dev, cur_queue);
703 : 0 : return -rte_errno;
704 : : }
705 : : /* Already unbound, return success before obj checking. */
706 [ # # ]: 0 : if (txq_ctrl->hairpin_status == 0) {
707 : 0 : DRV_LOG(DEBUG, "port %u Tx queue %d is already unbound",
708 : : dev->data->port_id, cur_queue);
709 : 0 : mlx5_txq_release(dev, cur_queue);
710 : 0 : return 0;
711 : : }
712 [ # # # # ]: 0 : if (!txq_ctrl->obj || !txq_ctrl->obj->sq) {
713 : 0 : rte_errno = ENOMEM;
714 : 0 : DRV_LOG(ERR, "port %u no Txq object found: %d",
715 : : dev->data->port_id, cur_queue);
716 : 0 : mlx5_txq_release(dev, cur_queue);
717 : 0 : return -rte_errno;
718 : : }
719 : 0 : sq_attr.state = MLX5_SQC_STATE_RST;
720 : 0 : sq_attr.sq_state = MLX5_SQC_STATE_RDY;
721 : 0 : ret = mlx5_devx_cmd_modify_sq(txq_ctrl->obj->sq, &sq_attr);
722 [ # # ]: 0 : if (ret == 0)
723 : 0 : txq_ctrl->hairpin_status = 0;
724 : 0 : mlx5_txq_release(dev, cur_queue);
725 : : } else {
726 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, cur_queue);
727 : : struct mlx5_rxq_ctrl *rxq_ctrl;
728 : 0 : struct mlx5_devx_modify_rq_attr rq_attr = { 0 };
729 : :
730 [ # # ]: 0 : if (rxq == NULL) {
731 : 0 : rte_errno = EINVAL;
732 : 0 : DRV_LOG(ERR, "Failed to get port %u Rx queue %d",
733 : : dev->data->port_id, cur_queue);
734 : 0 : return -rte_errno;
735 : : }
736 : 0 : rxq_ctrl = rxq->ctrl;
737 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin) {
738 : 0 : rte_errno = EINVAL;
739 : 0 : DRV_LOG(ERR, "port %u queue %d not a hairpin Rxq",
740 : : dev->data->port_id, cur_queue);
741 : 0 : return -rte_errno;
742 : : }
743 [ # # ]: 0 : if (rxq->hairpin_status == 0) {
744 : 0 : DRV_LOG(DEBUG, "port %u Rx queue %d is already unbound",
745 : : dev->data->port_id, cur_queue);
746 : 0 : return 0;
747 : : }
748 [ # # # # ]: 0 : if (rxq_ctrl->obj == NULL || rxq_ctrl->obj->rq == NULL) {
749 : 0 : rte_errno = ENOMEM;
750 : 0 : DRV_LOG(ERR, "port %u no Rxq object found: %d",
751 : : dev->data->port_id, cur_queue);
752 : 0 : return -rte_errno;
753 : : }
754 : : rq_attr.state = MLX5_RQC_STATE_RST;
755 : 0 : rq_attr.rq_state = MLX5_RQC_STATE_RDY;
756 : 0 : ret = mlx5_devx_cmd_modify_rq(rxq_ctrl->obj->rq, &rq_attr);
757 [ # # ]: 0 : if (ret == 0)
758 : 0 : rxq->hairpin_status = 0;
759 : : }
760 : : return ret;
761 : : }
762 : :
763 : : /*
764 : : * Bind the hairpin port pairs, from the Tx to the peer Rx.
765 : : * This function only supports to bind the Tx to one Rx.
766 : : *
767 : : * @param dev
768 : : * Pointer to Ethernet device structure.
769 : : * @param rx_port
770 : : * Port identifier of the Rx port.
771 : : *
772 : : * @return
773 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
774 : : */
775 : : static int
776 : 0 : mlx5_hairpin_bind_single_port(struct rte_eth_dev *dev, uint16_t rx_port)
777 : : {
778 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
779 : : int ret = 0;
780 : : struct mlx5_txq_ctrl *txq_ctrl;
781 : : uint32_t i;
782 : 0 : struct rte_hairpin_peer_info peer = {0xffffff};
783 : : struct rte_hairpin_peer_info cur;
784 : : const struct rte_eth_hairpin_conf *conf;
785 : : uint16_t num_q = 0;
786 : 0 : uint16_t local_port = priv->dev_data->port_id;
787 : : uint32_t manual;
788 : : uint32_t explicit;
789 : : uint16_t rx_queue;
790 : :
791 [ # # ]: 0 : if (mlx5_eth_find_next(rx_port, dev->device) != rx_port) {
792 : 0 : rte_errno = ENODEV;
793 : 0 : DRV_LOG(ERR, "Rx port %u does not belong to mlx5", rx_port);
794 : 0 : return -rte_errno;
795 : : }
796 : : /*
797 : : * Before binding TxQ to peer RxQ, first round loop will be used for
798 : : * checking the queues' configuration consistency. This would be a
799 : : * little time consuming but better than doing the rollback.
800 : : */
801 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; i++) {
802 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
803 [ # # ]: 0 : if (txq_ctrl == NULL)
804 : 0 : continue;
805 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
806 : 0 : mlx5_txq_release(dev, i);
807 : 0 : continue;
808 : : }
809 : : /*
810 : : * All hairpin Tx queues of a single port that connected to the
811 : : * same peer Rx port should have the same "auto binding" and
812 : : * "implicit Tx flow" modes.
813 : : * Peer consistency checking will be done in per queue binding.
814 : : */
815 : : conf = &txq_ctrl->hairpin_conf;
816 [ # # ]: 0 : if (conf->peers[0].port == rx_port) {
817 [ # # ]: 0 : if (num_q == 0) {
818 : 0 : manual = conf->manual_bind;
819 : 0 : explicit = conf->tx_explicit;
820 : : } else {
821 [ # # ]: 0 : if (manual != conf->manual_bind ||
822 [ # # ]: 0 : explicit != conf->tx_explicit) {
823 : 0 : rte_errno = EINVAL;
824 : 0 : DRV_LOG(ERR, "port %u queue %d mode"
825 : : " mismatch: %u %u, %u %u",
826 : : local_port, i, manual,
827 : : conf->manual_bind, explicit,
828 : : conf->tx_explicit);
829 : 0 : mlx5_txq_release(dev, i);
830 : 0 : return -rte_errno;
831 : : }
832 : : }
833 : 0 : num_q++;
834 : : }
835 : 0 : mlx5_txq_release(dev, i);
836 : : }
837 : : /* Once no queue is configured, success is returned directly. */
838 [ # # ]: 0 : if (num_q == 0)
839 : : return ret;
840 : : /* All the hairpin TX queues need to be traversed again. */
841 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; i++) {
842 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
843 [ # # ]: 0 : if (txq_ctrl == NULL)
844 : 0 : continue;
845 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
846 : 0 : mlx5_txq_release(dev, i);
847 : 0 : continue;
848 : : }
849 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.peers[0].port != rx_port) {
850 : 0 : mlx5_txq_release(dev, i);
851 : 0 : continue;
852 : : }
853 : 0 : rx_queue = txq_ctrl->hairpin_conf.peers[0].queue;
854 : : /*
855 : : * Fetch peer RxQ's information.
856 : : * No need to pass the information of the current queue.
857 : : */
858 : 0 : ret = rte_eth_hairpin_queue_peer_update(rx_port, rx_queue,
859 : : NULL, &peer, 1);
860 [ # # ]: 0 : if (ret != 0) {
861 : 0 : mlx5_txq_release(dev, i);
862 : 0 : goto error;
863 : : }
864 : : /* Accessing its own device, inside mlx5 PMD. */
865 : 0 : ret = mlx5_hairpin_queue_peer_bind(dev, i, &peer, 1);
866 [ # # ]: 0 : if (ret != 0) {
867 : 0 : mlx5_txq_release(dev, i);
868 : 0 : goto error;
869 : : }
870 : : /* Pass TxQ's information to peer RxQ and try binding. */
871 : 0 : cur.peer_q = rx_queue;
872 : 0 : cur.qp_id = mlx5_txq_get_sqn(txq_ctrl);
873 : 0 : cur.vhca_id = priv->sh->cdev->config.hca_attr.vhca_id;
874 : 0 : cur.tx_explicit = txq_ctrl->hairpin_conf.tx_explicit;
875 : 0 : cur.manual_bind = txq_ctrl->hairpin_conf.manual_bind;
876 : : /*
877 : : * In order to access another device in a proper way, RTE level
878 : : * private function is needed.
879 : : */
880 : 0 : ret = rte_eth_hairpin_queue_peer_bind(rx_port, rx_queue,
881 : : &cur, 0);
882 [ # # ]: 0 : if (ret != 0) {
883 : 0 : mlx5_txq_release(dev, i);
884 : 0 : goto error;
885 : : }
886 : 0 : mlx5_txq_release(dev, i);
887 : : }
888 : : return 0;
889 : 0 : error:
890 : : /*
891 : : * Do roll-back process for the queues already bound.
892 : : * No need to check the return value of the queue unbind function.
893 : : */
894 : : do {
895 : : /* No validation is needed here. */
896 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
897 [ # # ]: 0 : if (txq_ctrl == NULL)
898 : 0 : continue;
899 [ # # ]: 0 : if (!txq_ctrl->is_hairpin ||
900 [ # # ]: 0 : txq_ctrl->hairpin_conf.peers[0].port != rx_port) {
901 : 0 : mlx5_txq_release(dev, i);
902 : 0 : continue;
903 : : }
904 : 0 : rx_queue = txq_ctrl->hairpin_conf.peers[0].queue;
905 : 0 : rte_eth_hairpin_queue_peer_unbind(rx_port, rx_queue, 0);
906 : 0 : mlx5_hairpin_queue_peer_unbind(dev, i, 1);
907 : 0 : mlx5_txq_release(dev, i);
908 [ # # ]: 0 : } while (i--);
909 : : return ret;
910 : : }
911 : :
912 : : /*
913 : : * Unbind the hairpin port pair, HW configuration of both devices will be clear
914 : : * and status will be reset for all the queues used between them.
915 : : * This function only supports to unbind the Tx from one Rx.
916 : : *
917 : : * @param dev
918 : : * Pointer to Ethernet device structure.
919 : : * @param rx_port
920 : : * Port identifier of the Rx port.
921 : : *
922 : : * @return
923 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
924 : : */
925 : : static int
926 : 0 : mlx5_hairpin_unbind_single_port(struct rte_eth_dev *dev, uint16_t rx_port)
927 : : {
928 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
929 : : struct mlx5_txq_ctrl *txq_ctrl;
930 : : uint32_t i;
931 : : int ret;
932 : 0 : uint16_t cur_port = priv->dev_data->port_id;
933 : :
934 [ # # ]: 0 : if (mlx5_eth_find_next(rx_port, dev->device) != rx_port) {
935 : 0 : rte_errno = ENODEV;
936 : 0 : DRV_LOG(ERR, "Rx port %u does not belong to mlx5", rx_port);
937 : 0 : return -rte_errno;
938 : : }
939 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; i++) {
940 : : uint16_t rx_queue;
941 : :
942 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
943 [ # # ]: 0 : if (txq_ctrl == NULL)
944 : 0 : continue;
945 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
946 : 0 : mlx5_txq_release(dev, i);
947 : 0 : continue;
948 : : }
949 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.peers[0].port != rx_port) {
950 : 0 : mlx5_txq_release(dev, i);
951 : 0 : continue;
952 : : }
953 : : /* Indeed, only the first used queue needs to be checked. */
954 [ # # ]: 0 : if (txq_ctrl->hairpin_conf.manual_bind == 0) {
955 : 0 : mlx5_txq_release(dev, i);
956 [ # # ]: 0 : if (cur_port != rx_port) {
957 : 0 : rte_errno = EINVAL;
958 : 0 : DRV_LOG(ERR, "port %u and port %u are in"
959 : : " auto-bind mode", cur_port, rx_port);
960 : 0 : return -rte_errno;
961 : : } else {
962 : : return 0;
963 : : }
964 : : }
965 : 0 : rx_queue = txq_ctrl->hairpin_conf.peers[0].queue;
966 : 0 : mlx5_txq_release(dev, i);
967 : 0 : ret = rte_eth_hairpin_queue_peer_unbind(rx_port, rx_queue, 0);
968 [ # # ]: 0 : if (ret) {
969 : 0 : DRV_LOG(ERR, "port %u Rx queue %d unbind - failure",
970 : : rx_port, rx_queue);
971 : 0 : return ret;
972 : : }
973 : 0 : ret = mlx5_hairpin_queue_peer_unbind(dev, i, 1);
974 [ # # ]: 0 : if (ret) {
975 : 0 : DRV_LOG(ERR, "port %u Tx queue %d unbind - failure",
976 : : cur_port, i);
977 : 0 : return ret;
978 : : }
979 : : }
980 : : return 0;
981 : : }
982 : :
983 : : /*
984 : : * Bind hairpin ports, Rx could be all ports when using RTE_MAX_ETHPORTS.
985 : : * @see mlx5_hairpin_bind_single_port()
986 : : */
987 : : int
988 : 0 : mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port)
989 : : {
990 : : int ret = 0;
991 : : uint16_t p, pp;
992 : :
993 : : /*
994 : : * If the Rx port has no hairpin configuration with the current port,
995 : : * the binding will be skipped in the called function of single port.
996 : : * Device started status will be checked only before the queue
997 : : * information updating.
998 : : */
999 [ # # ]: 0 : if (rx_port == RTE_MAX_ETHPORTS) {
1000 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(p, dev->device) {
1001 : 0 : ret = mlx5_hairpin_bind_single_port(dev, p);
1002 [ # # ]: 0 : if (ret != 0)
1003 : 0 : goto unbind;
1004 : : }
1005 : : return ret;
1006 : : } else {
1007 : 0 : return mlx5_hairpin_bind_single_port(dev, rx_port);
1008 : : }
1009 : : unbind:
1010 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(pp, dev->device)
1011 [ # # ]: 0 : if (pp < p)
1012 : 0 : mlx5_hairpin_unbind_single_port(dev, pp);
1013 : : return ret;
1014 : : }
1015 : :
1016 : : /*
1017 : : * Unbind hairpin ports, Rx could be all ports when using RTE_MAX_ETHPORTS.
1018 : : * @see mlx5_hairpin_unbind_single_port()
1019 : : */
1020 : : int
1021 : 0 : mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port)
1022 : : {
1023 : : int ret = 0;
1024 : : uint16_t p;
1025 : :
1026 [ # # ]: 0 : if (rx_port == RTE_MAX_ETHPORTS)
1027 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(p, dev->device) {
1028 : 0 : ret = mlx5_hairpin_unbind_single_port(dev, p);
1029 [ # # ]: 0 : if (ret != 0)
1030 : 0 : return ret;
1031 : : }
1032 : : else
1033 : 0 : ret = mlx5_hairpin_unbind_single_port(dev, rx_port);
1034 : : return ret;
1035 : : }
1036 : :
1037 : : /*
1038 : : * DPDK callback to get the hairpin peer ports list.
1039 : : * This will return the actual number of peer ports and save the identifiers
1040 : : * into the array (sorted, may be different from that when setting up the
1041 : : * hairpin peer queues).
1042 : : * The peer port ID could be the same as the port ID of the current device.
1043 : : *
1044 : : * @param dev
1045 : : * Pointer to Ethernet device structure.
1046 : : * @param peer_ports
1047 : : * Pointer to array to save the port identifiers.
1048 : : * @param len
1049 : : * The length of the array.
1050 : : * @param direction
1051 : : * Current port to peer port direction.
1052 : : * positive - current used as Tx to get all peer Rx ports.
1053 : : * zero - current used as Rx to get all peer Tx ports.
1054 : : *
1055 : : * @return
1056 : : * 0 or positive value on success, actual number of peer ports.
1057 : : * a negative errno value otherwise and rte_errno is set.
1058 : : */
1059 : : int
1060 : 0 : mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports,
1061 : : size_t len, uint32_t direction)
1062 : : {
1063 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1064 : : struct mlx5_txq_ctrl *txq_ctrl;
1065 : : uint32_t i;
1066 : : uint16_t pp;
1067 : : uint32_t bits[(RTE_MAX_ETHPORTS + 31) / 32] = {0};
1068 : : int ret = 0;
1069 : :
1070 [ # # ]: 0 : if (direction) {
1071 [ # # ]: 0 : for (i = 0; i < priv->txqs_n; i++) {
1072 : 0 : txq_ctrl = mlx5_txq_get(dev, i);
1073 [ # # ]: 0 : if (!txq_ctrl)
1074 : 0 : continue;
1075 [ # # ]: 0 : if (!txq_ctrl->is_hairpin) {
1076 : 0 : mlx5_txq_release(dev, i);
1077 : 0 : continue;
1078 : : }
1079 : 0 : pp = txq_ctrl->hairpin_conf.peers[0].port;
1080 [ # # ]: 0 : if (pp >= RTE_MAX_ETHPORTS) {
1081 : 0 : rte_errno = ERANGE;
1082 : 0 : mlx5_txq_release(dev, i);
1083 : 0 : DRV_LOG(ERR, "port %hu queue %u peer port "
1084 : : "out of range %hu",
1085 : : priv->dev_data->port_id, i, pp);
1086 : 0 : return -rte_errno;
1087 : : }
1088 : 0 : bits[pp / 32] |= 1 << (pp % 32);
1089 : 0 : mlx5_txq_release(dev, i);
1090 : : }
1091 : : } else {
1092 [ # # ]: 0 : for (i = 0; i < priv->rxqs_n; i++) {
1093 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
1094 : : struct mlx5_rxq_ctrl *rxq_ctrl;
1095 : :
1096 [ # # ]: 0 : if (rxq == NULL)
1097 : 0 : continue;
1098 : 0 : rxq_ctrl = rxq->ctrl;
1099 [ # # ]: 0 : if (!rxq_ctrl->is_hairpin)
1100 : 0 : continue;
1101 : 0 : pp = rxq->hairpin_conf.peers[0].port;
1102 [ # # ]: 0 : if (pp >= RTE_MAX_ETHPORTS) {
1103 : 0 : rte_errno = ERANGE;
1104 : 0 : DRV_LOG(ERR, "port %hu queue %u peer port "
1105 : : "out of range %hu",
1106 : : priv->dev_data->port_id, i, pp);
1107 : 0 : return -rte_errno;
1108 : : }
1109 : 0 : bits[pp / 32] |= 1 << (pp % 32);
1110 : : }
1111 : : }
1112 [ # # ]: 0 : for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
1113 [ # # ]: 0 : if (bits[i / 32] & (1 << (i % 32))) {
1114 [ # # ]: 0 : if ((size_t)ret >= len) {
1115 : 0 : rte_errno = E2BIG;
1116 : 0 : return -rte_errno;
1117 : : }
1118 : 0 : peer_ports[ret++] = i;
1119 : : }
1120 : : }
1121 : : return ret;
1122 : : }
1123 : :
1124 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1125 : :
1126 : : /**
1127 : : * Check if starting representor port is allowed.
1128 : : *
1129 : : * If transfer proxy port is configured for HWS, then starting representor port
1130 : : * is allowed if and only if transfer proxy port is started as well.
1131 : : *
1132 : : * @param dev
1133 : : * Pointer to Ethernet device structure.
1134 : : *
1135 : : * @return
1136 : : * If stopping representor port is allowed, then 0 is returned.
1137 : : * Otherwise rte_errno is set, and negative errno value is returned.
1138 : : */
1139 : : static int
1140 : 0 : mlx5_hw_representor_port_allowed_start(struct rte_eth_dev *dev)
1141 : : {
1142 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1143 : : struct rte_eth_dev *proxy_dev;
1144 : : struct mlx5_priv *proxy_priv;
1145 : 0 : uint16_t proxy_port_id = UINT16_MAX;
1146 : : int ret;
1147 : :
1148 : : MLX5_ASSERT(priv->sh->config.dv_flow_en == 2);
1149 : : MLX5_ASSERT(priv->sh->config.dv_esw_en);
1150 : : MLX5_ASSERT(priv->representor);
1151 : 0 : ret = rte_flow_pick_transfer_proxy(dev->data->port_id, &proxy_port_id, NULL);
1152 [ # # ]: 0 : if (ret) {
1153 [ # # ]: 0 : if (ret == -ENODEV)
1154 : 0 : DRV_LOG(ERR, "Starting representor port %u is not allowed. Transfer "
1155 : : "proxy port is not available.", dev->data->port_id);
1156 : : else
1157 : 0 : DRV_LOG(ERR, "Failed to pick transfer proxy for port %u (ret = %d)",
1158 : : dev->data->port_id, ret);
1159 : 0 : return ret;
1160 : : }
1161 : 0 : proxy_dev = &rte_eth_devices[proxy_port_id];
1162 : 0 : proxy_priv = proxy_dev->data->dev_private;
1163 [ # # ]: 0 : if (proxy_priv->dr_ctx == NULL) {
1164 : 0 : DRV_LOG(DEBUG, "Starting representor port %u is allowed, but default traffic flows"
1165 : : " will not be created. Transfer proxy port must be configured"
1166 : : " for HWS and started.",
1167 : : dev->data->port_id);
1168 : 0 : return 0;
1169 : : }
1170 [ # # ]: 0 : if (!proxy_dev->data->dev_started) {
1171 : 0 : DRV_LOG(ERR, "Failed to start port %u: transfer proxy (port %u) must be started",
1172 : : dev->data->port_id, proxy_port_id);
1173 : 0 : rte_errno = EAGAIN;
1174 : 0 : return -rte_errno;
1175 : : }
1176 [ # # ]: 0 : if (priv->dr_ctx == NULL) {
1177 : 0 : DRV_LOG(ERR, "Failed to start port %u: port must be configured for HWS",
1178 : : dev->data->port_id);
1179 : 0 : rte_errno = EINVAL;
1180 : 0 : return -rte_errno;
1181 : : }
1182 : : return 0;
1183 : : }
1184 : :
1185 : : #endif
1186 : :
1187 : : /*
1188 : : * Allocate TxQs unique umem and register its MR.
1189 : : *
1190 : : * @param dev
1191 : : * Pointer to Ethernet device structure.
1192 : : *
1193 : : * @return
1194 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1195 : : */
1196 : 0 : static int mlx5_dev_allocate_consec_tx_mem(struct rte_eth_dev *dev)
1197 : : {
1198 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1199 : : size_t alignment;
1200 : : uint32_t total_size;
1201 : : struct mlx5dv_devx_umem *umem_obj = NULL;
1202 : : void *umem_buf = NULL;
1203 : :
1204 : : /* Legacy per queue allocation, do nothing here. */
1205 [ # # # # ]: 0 : if (priv->sh->config.txq_mem_algn == 0 || !mlx5_devx_obj_ops_en(priv))
1206 : : return 0;
1207 : 0 : alignment = (size_t)1 << priv->sh->config.txq_mem_algn;
1208 : 0 : total_size = priv->consec_tx_mem.sq_total_size + priv->consec_tx_mem.cq_total_size;
1209 : : /*
1210 : : * Hairpin queues can be skipped later
1211 : : * queue size alignment is bigger than doorbell alignment, no need to align or
1212 : : * round-up again. One queue have two DBs (for CQ + WQ).
1213 : : */
1214 : 0 : total_size += MLX5_DBR_SIZE * priv->txqs_n * 2;
1215 [ # # # # : 0 : umem_buf = mlx5_malloc_numa_tolerant(MLX5_MEM_RTE | MLX5_MEM_ZERO, total_size,
# # ]
1216 : : alignment, priv->sh->numa_node);
1217 [ # # ]: 0 : if (!umem_buf) {
1218 : 0 : DRV_LOG(ERR, "Failed to allocate consecutive memory for TxQs.");
1219 : 0 : rte_errno = ENOMEM;
1220 : 0 : return -rte_errno;
1221 : : }
1222 : 0 : umem_obj = mlx5_os_umem_reg(priv->sh->cdev->ctx, (void *)(uintptr_t)umem_buf,
1223 : : total_size, IBV_ACCESS_LOCAL_WRITE);
1224 [ # # ]: 0 : if (!umem_obj) {
1225 : 0 : DRV_LOG(ERR, "Failed to register unique umem for all SQs.");
1226 : 0 : rte_errno = errno;
1227 : : if (umem_buf)
1228 : 0 : mlx5_free(umem_buf);
1229 : 0 : return -rte_errno;
1230 : : }
1231 : 0 : priv->consec_tx_mem.umem = umem_buf;
1232 : 0 : priv->consec_tx_mem.sq_cur_off = 0;
1233 : 0 : priv->consec_tx_mem.cq_cur_off = priv->consec_tx_mem.sq_total_size;
1234 : 0 : priv->consec_tx_mem.umem_obj = umem_obj;
1235 : 0 : DRV_LOG(DEBUG, "Allocated umem %p with size %u for %u queues with sq_len %u,"
1236 : : " cq_len %u and registered object %p on port %u",
1237 : : umem_buf, total_size, priv->txqs_n, priv->consec_tx_mem.sq_total_size,
1238 : : priv->consec_tx_mem.cq_total_size, (void *)umem_obj, dev->data->port_id);
1239 : 0 : return 0;
1240 : : }
1241 : :
1242 : : /*
1243 : : * Release TxQs unique umem and register its MR.
1244 : : *
1245 : : * @param dev
1246 : : * Pointer to Ethernet device structure.
1247 : : * @param on_stop
1248 : : * If this is on device stop stage.
1249 : : */
1250 : 0 : static void mlx5_dev_free_consec_tx_mem(struct rte_eth_dev *dev, bool on_stop)
1251 : : {
1252 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1253 : :
1254 [ # # ]: 0 : if (priv->consec_tx_mem.umem_obj) {
1255 : : mlx5_os_umem_dereg(priv->consec_tx_mem.umem_obj);
1256 : 0 : priv->consec_tx_mem.umem_obj = NULL;
1257 : : }
1258 [ # # ]: 0 : if (priv->consec_tx_mem.umem) {
1259 : 0 : mlx5_free(priv->consec_tx_mem.umem);
1260 : 0 : priv->consec_tx_mem.umem = NULL;
1261 : : }
1262 : : /* Queues information will not be reset. */
1263 [ # # ]: 0 : if (on_stop) {
1264 : : /* Reset to 0s for re-setting up queues. */
1265 : 0 : priv->consec_tx_mem.sq_cur_off = 0;
1266 : 0 : priv->consec_tx_mem.cq_cur_off = 0;
1267 : : }
1268 : 0 : }
1269 : :
1270 : : #define SAVE_RTE_ERRNO_AND_STOP(ret, dev) do { \
1271 : : ret = rte_errno; \
1272 : : (dev)->data->dev_started = 0; \
1273 : : } while (0)
1274 : :
1275 : : /**
1276 : : * DPDK callback to start the device.
1277 : : *
1278 : : * Simulate device start by attaching all configured flows.
1279 : : *
1280 : : * @param dev
1281 : : * Pointer to Ethernet device structure.
1282 : : *
1283 : : * @return
1284 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1285 : : * The following error values are defined:
1286 : : *
1287 : : * - -EAGAIN: If port representor cannot be started,
1288 : : * because transfer proxy port is not started.
1289 : : */
1290 : : int
1291 : 0 : mlx5_dev_start(struct rte_eth_dev *dev)
1292 : : {
1293 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1294 : : int ret;
1295 : : int fine_inline;
1296 : :
1297 : 0 : DRV_LOG(DEBUG, "port %u starting device", dev->data->port_id);
1298 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1299 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1300 : 0 : struct rte_flow_error error = { 0, };
1301 : :
1302 : : /*
1303 : : * If steering is disabled, then:
1304 : : * - There are no limitations regarding port start ordering,
1305 : : * since no flow rules need to be created as part of port start.
1306 : : * - Non template API initialization will be skipped.
1307 : : */
1308 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1309 : 0 : goto continue_dev_start;
1310 : : /*If previous configuration does not exist. */
1311 [ # # ]: 0 : if (!(priv->dr_ctx)) {
1312 : 0 : ret = mlx5_flow_hw_init(dev, &error);
1313 [ # # ]: 0 : if (ret) {
1314 : 0 : DRV_LOG(ERR, "Failed to start port %u %s: %s",
1315 : : dev->data->port_id, dev->data->name,
1316 : : error.message);
1317 : 0 : return ret;
1318 : : }
1319 : : }
1320 : : /* If there is no E-Switch, then there are no start/stop order limitations. */
1321 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
1322 : 0 : goto continue_dev_start;
1323 : : /* If master is being started, then it is always allowed. */
1324 [ # # ]: 0 : if (priv->master)
1325 : 0 : goto continue_dev_start;
1326 [ # # ]: 0 : if (mlx5_hw_representor_port_allowed_start(dev))
1327 : 0 : return -rte_errno;
1328 : : }
1329 : 0 : continue_dev_start:
1330 : : #endif
1331 : 0 : fine_inline = rte_mbuf_dynflag_lookup
1332 : : (RTE_PMD_MLX5_FINE_GRANULARITY_INLINE, NULL);
1333 [ # # ]: 0 : if (fine_inline >= 0)
1334 : 0 : rte_net_mlx5_dynf_inline_mask = RTE_BIT64(fine_inline);
1335 : : else
1336 : 0 : rte_net_mlx5_dynf_inline_mask = 0;
1337 [ # # ]: 0 : if (dev->data->nb_rx_queues > 0) {
1338 : 0 : uint32_t max_lro_msg_size = priv->max_lro_msg_size;
1339 : :
1340 [ # # ]: 0 : if (max_lro_msg_size < MLX5_LRO_SEG_CHUNK_SIZE) {
1341 : : uint32_t i;
1342 : : struct mlx5_rxq_priv *rxq;
1343 : :
1344 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1345 : 0 : rxq = mlx5_rxq_get(dev, i);
1346 [ # # # # : 0 : if (rxq && rxq->ctrl && rxq->ctrl->rxq.lro) {
# # ]
1347 : 0 : DRV_LOG(ERR, "port %u invalid max LRO size",
1348 : : dev->data->port_id);
1349 : 0 : rte_errno = EINVAL;
1350 : 0 : return -rte_errno;
1351 : : }
1352 : : }
1353 : : }
1354 : 0 : ret = mlx5_dev_configure_rss_reta(dev);
1355 [ # # ]: 0 : if (ret) {
1356 : 0 : DRV_LOG(ERR, "port %u reta config failed: %s",
1357 : : dev->data->port_id, strerror(rte_errno));
1358 : 0 : return -rte_errno;
1359 : : }
1360 : : }
1361 : 0 : ret = mlx5_txpp_start(dev);
1362 [ # # ]: 0 : if (ret) {
1363 : 0 : DRV_LOG(ERR, "port %u Tx packet pacing init failed: %s",
1364 : : dev->data->port_id, strerror(rte_errno));
1365 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1366 : 0 : goto error;
1367 : : }
1368 [ # # ]: 0 : if (mlx5_devx_obj_ops_en(priv) &&
1369 [ # # ]: 0 : priv->obj_ops.lb_dummy_queue_create) {
1370 : 0 : ret = priv->obj_ops.lb_dummy_queue_create(dev);
1371 [ # # ]: 0 : if (ret) {
1372 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1373 : 0 : goto txpp_stop;
1374 : : }
1375 : : }
1376 : 0 : ret = mlx5_dev_allocate_consec_tx_mem(dev);
1377 [ # # ]: 0 : if (ret) {
1378 : 0 : DRV_LOG(ERR, "port %u Tx queues memory allocation failed: %s",
1379 : : dev->data->port_id, strerror(rte_errno));
1380 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1381 : 0 : goto lb_dummy_queue_release;
1382 : : }
1383 : 0 : ret = mlx5_txq_start(dev);
1384 [ # # ]: 0 : if (ret) {
1385 : 0 : DRV_LOG(ERR, "port %u Tx queue allocation failed: %s",
1386 : : dev->data->port_id, strerror(rte_errno));
1387 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1388 : 0 : goto free_consec_tx_mem;
1389 : : }
1390 [ # # ]: 0 : if (priv->config.std_delay_drop || priv->config.hp_delay_drop) {
1391 [ # # ]: 0 : if (!priv->sh->dev_cap.vf && !priv->sh->dev_cap.sf &&
1392 [ # # ]: 0 : !priv->representor) {
1393 : 0 : ret = mlx5_get_flag_dropless_rq(dev);
1394 [ # # ]: 0 : if (ret < 0)
1395 : 0 : DRV_LOG(WARNING,
1396 : : "port %u cannot query dropless flag",
1397 : : dev->data->port_id);
1398 [ # # ]: 0 : else if (!ret)
1399 : 0 : DRV_LOG(WARNING,
1400 : : "port %u dropless_rq OFF, no rearming",
1401 : : dev->data->port_id);
1402 : : } else {
1403 : 0 : DRV_LOG(DEBUG,
1404 : : "port %u doesn't support dropless_rq flag",
1405 : : dev->data->port_id);
1406 : : }
1407 : : }
1408 : 0 : ret = mlx5_rxq_start(dev);
1409 [ # # ]: 0 : if (ret) {
1410 : 0 : DRV_LOG(ERR, "port %u Rx queue allocation failed: %s",
1411 : : dev->data->port_id, strerror(rte_errno));
1412 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1413 : 0 : goto txq_stop;
1414 : : }
1415 : : /*
1416 : : * Such step will be skipped if there is no hairpin TX queue configured
1417 : : * with RX peer queue from the same device.
1418 : : */
1419 : 0 : ret = mlx5_hairpin_auto_bind(dev);
1420 [ # # ]: 0 : if (ret) {
1421 : 0 : DRV_LOG(ERR, "port %u hairpin auto binding failed: %s",
1422 : : dev->data->port_id, strerror(rte_errno));
1423 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1424 : 0 : goto rxq_stop;
1425 : : }
1426 : : /* Set started flag here for the following steps like control flow. */
1427 : 0 : dev->data->dev_started = 1;
1428 : 0 : ret = mlx5_rx_intr_vec_enable(dev);
1429 [ # # ]: 0 : if (ret) {
1430 : 0 : DRV_LOG(ERR, "port %u Rx interrupt vector creation failed",
1431 : : dev->data->port_id);
1432 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1433 : 0 : goto rxq_stop;
1434 : : }
1435 : 0 : mlx5_os_stats_init(dev);
1436 : : /*
1437 : : * Attach indirection table objects detached on port stop.
1438 : : * They may be needed to create RSS in non-isolated mode.
1439 : : */
1440 : 0 : ret = mlx5_action_handle_attach(dev);
1441 [ # # ]: 0 : if (ret) {
1442 : 0 : DRV_LOG(ERR,
1443 : : "port %u failed to attach indirect actions: %s",
1444 : : dev->data->port_id, rte_strerror(rte_errno));
1445 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1446 : 0 : goto rx_intr_vec_disable;
1447 : : }
1448 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1449 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1450 : 0 : ret = mlx5_flow_hw_table_update(dev, NULL);
1451 [ # # ]: 0 : if (ret) {
1452 : 0 : DRV_LOG(ERR, "port %u failed to update HWS tables",
1453 : : dev->data->port_id);
1454 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1455 : 0 : goto action_handle_detach;
1456 : : }
1457 : : }
1458 : : #endif
1459 [ # # ]: 0 : if (priv->sh->dev_cap.vf || priv->sh->dev_cap.sf) {
1460 [ # # ]: 0 : if (mlx5_os_get_promisc(dev) != dev->data->promiscuous) {
1461 [ # # ]: 0 : DRV_LOG(INFO, "port %u forcing promiscuous mode to %s",
1462 : : dev->data->port_id,
1463 : : dev->data->promiscuous ? "enabled" : "disabled");
1464 : 0 : mlx5_os_set_promisc(dev, dev->data->promiscuous);
1465 : : }
1466 [ # # ]: 0 : if (mlx5_os_get_allmulti(dev) != dev->data->all_multicast) {
1467 [ # # ]: 0 : DRV_LOG(INFO, "port %u forcing all multicast mode to %s",
1468 : : dev->data->port_id,
1469 : : dev->data->all_multicast ? "enabled" : "disabled");
1470 : 0 : mlx5_os_set_allmulti(dev, dev->data->all_multicast);
1471 : : }
1472 : : }
1473 : 0 : ret = mlx5_traffic_enable(dev);
1474 [ # # ]: 0 : if (ret) {
1475 : 0 : DRV_LOG(ERR, "port %u failed to set defaults flows",
1476 : : dev->data->port_id);
1477 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1478 : 0 : goto action_handle_detach;
1479 : : }
1480 : : /* Set dynamic fields and flags into Rx queues. */
1481 : 0 : mlx5_flow_rxq_dynf_set(dev);
1482 : : /* Set flags and context to convert Rx timestamps. */
1483 : 0 : mlx5_rxq_timestamp_set(dev);
1484 : : /* Set a mask and offset of scheduling on timestamp into Tx queues. */
1485 : 0 : mlx5_txq_dynf_timestamp_set(dev);
1486 : : /*
1487 : : * In non-cached mode, it only needs to start the default mreg copy
1488 : : * action and no flow created by application exists anymore.
1489 : : * But it is worth wrapping the interface for further usage.
1490 : : */
1491 : 0 : ret = mlx5_flow_start_default(dev);
1492 [ # # ]: 0 : if (ret) {
1493 : 0 : DRV_LOG(DEBUG, "port %u failed to start default actions: %s",
1494 : : dev->data->port_id, strerror(rte_errno));
1495 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1496 : 0 : goto traffic_disable;
1497 : : }
1498 [ # # ]: 0 : if (mlx5_dev_ctx_shared_mempool_subscribe(dev) != 0) {
1499 : 0 : DRV_LOG(ERR, "port %u failed to subscribe for mempool life cycle: %s",
1500 : : dev->data->port_id, rte_strerror(rte_errno));
1501 : 0 : SAVE_RTE_ERRNO_AND_STOP(ret, dev);
1502 : 0 : goto stop_default;
1503 : : }
1504 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1505 : 0 : mlx5_flow_rxq_mark_flag_set(dev);
1506 : : rte_wmb();
1507 : 0 : dev->tx_pkt_burst = mlx5_select_tx_function(dev);
1508 : 0 : dev->rx_pkt_burst = mlx5_select_rx_function(dev);
1509 : : /* Enable datapath on secondary process. */
1510 : 0 : mlx5_mp_os_req_start_rxtx(dev);
1511 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc) {
1512 : 0 : ret = mlx5_lsc_intr_setup(dev);
1513 [ # # ]: 0 : if (ret < 0) {
1514 : 0 : DRV_LOG(INFO,
1515 : : "port %u failed to configure LSC interrupts, starting without",
1516 : : dev->data->port_id);
1517 : 0 : dev->data->dev_conf.intr_conf.lsc = 0;
1518 : : }
1519 : : }
1520 [ # # ]: 0 : if (rte_intr_fd_get(priv->sh->intr_handle) >= 0) {
1521 : 0 : priv->sh->port[priv->dev_port - 1].ih_port_id =
1522 : 0 : (uint32_t)dev->data->port_id;
1523 : : } else {
1524 : 0 : DRV_LOG(INFO, "port %u starts without RMV interrupts.",
1525 : : dev->data->port_id);
1526 : 0 : dev->data->dev_conf.intr_conf.rmv = 0;
1527 : : }
1528 [ # # ]: 0 : if (rte_intr_fd_get(priv->sh->intr_handle_devx) >= 0)
1529 : 0 : priv->sh->port[priv->dev_port - 1].devx_ih_port_id =
1530 : 0 : (uint32_t)dev->data->port_id;
1531 : : return 0;
1532 : : stop_default:
1533 : 0 : mlx5_flow_stop_default(dev);
1534 : 0 : traffic_disable:
1535 : 0 : mlx5_traffic_disable(dev);
1536 : 0 : action_handle_detach:
1537 : 0 : mlx5_action_handle_detach(dev);
1538 : 0 : rx_intr_vec_disable:
1539 : 0 : mlx5_rx_intr_vec_disable(dev);
1540 : 0 : rxq_stop:
1541 : 0 : mlx5_rxq_stop(dev);
1542 : 0 : txq_stop:
1543 : 0 : mlx5_txq_stop(dev);
1544 : 0 : free_consec_tx_mem:
1545 : 0 : mlx5_dev_free_consec_tx_mem(dev, false);
1546 : 0 : lb_dummy_queue_release:
1547 [ # # ]: 0 : if (priv->obj_ops.lb_dummy_queue_release)
1548 : 0 : priv->obj_ops.lb_dummy_queue_release(dev);
1549 : 0 : txpp_stop:
1550 : 0 : mlx5_txpp_stop(dev);
1551 : 0 : error:
1552 : 0 : rte_errno = ret;
1553 : 0 : return -rte_errno;
1554 : : }
1555 : :
1556 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1557 : : /**
1558 : : * Check if stopping transfer proxy port is allowed.
1559 : : *
1560 : : * If transfer proxy port is configured for HWS, then it is allowed to stop it
1561 : : * if and only if all other representor ports are stopped.
1562 : : *
1563 : : * @param dev
1564 : : * Pointer to Ethernet device structure.
1565 : : *
1566 : : * @return
1567 : : * If stopping transfer proxy port is allowed, then 0 is returned.
1568 : : * Otherwise rte_errno is set, and negative errno value is returned.
1569 : : */
1570 : : static int
1571 : 0 : mlx5_hw_proxy_port_allowed_stop(struct rte_eth_dev *dev)
1572 : : {
1573 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1574 : : bool representor_started = false;
1575 : : uint16_t port_id;
1576 : :
1577 : : MLX5_ASSERT(priv->sh->config.dv_flow_en == 2);
1578 : : MLX5_ASSERT(priv->sh->config.dv_esw_en);
1579 : : MLX5_ASSERT(priv->master);
1580 : : /* If transfer proxy port was not configured for HWS, then stopping it is allowed. */
1581 [ # # ]: 0 : if (!priv->dr_ctx)
1582 : : return 0;
1583 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1584 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
1585 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
1586 : :
1587 [ # # ]: 0 : if (port_id != dev->data->port_id &&
1588 [ # # # # ]: 0 : port_priv->domain_id == priv->domain_id &&
1589 : : port_dev->data->dev_started)
1590 : : representor_started = true;
1591 : : }
1592 [ # # ]: 0 : if (representor_started) {
1593 : 0 : DRV_LOG(ERR, "Failed to stop port %u: attached representor ports"
1594 : : " must be stopped before stopping transfer proxy port",
1595 : : dev->data->port_id);
1596 : 0 : rte_errno = EBUSY;
1597 : 0 : return -rte_errno;
1598 : : }
1599 : : return 0;
1600 : : }
1601 : : #endif
1602 : :
1603 : : /**
1604 : : * DPDK callback to stop the device.
1605 : : *
1606 : : * Simulate device stop by detaching all configured flows.
1607 : : *
1608 : : * @param dev
1609 : : * Pointer to Ethernet device structure.
1610 : : *
1611 : : * @return
1612 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1613 : : * The following error values are defined:
1614 : : *
1615 : : * - -EBUSY: If transfer proxy port cannot be stopped,
1616 : : * because other port representors are still running.
1617 : : */
1618 : : int
1619 : 0 : mlx5_dev_stop(struct rte_eth_dev *dev)
1620 : : {
1621 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1622 : :
1623 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1624 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1625 : : /*
1626 : : * If steering is disabled,
1627 : : * then there are no limitations regarding port stop ordering,
1628 : : * since no flow rules need to be destroyed as part of port stop.
1629 : : */
1630 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1631 : 0 : goto continue_dev_stop;
1632 : : /* If there is no E-Switch, then there are no start/stop order limitations. */
1633 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
1634 : 0 : goto continue_dev_stop;
1635 : : /* If representor is being stopped, then it is always allowed. */
1636 [ # # ]: 0 : if (priv->representor)
1637 : 0 : goto continue_dev_stop;
1638 [ # # ]: 0 : if (mlx5_hw_proxy_port_allowed_stop(dev)) {
1639 : 0 : dev->data->dev_started = 1;
1640 : 0 : return -rte_errno;
1641 : : }
1642 : : }
1643 : 0 : continue_dev_stop:
1644 : : #endif
1645 : 0 : dev->data->dev_started = 0;
1646 : : /* Prevent crashes when queues are still in use. */
1647 : 0 : dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1648 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
1649 : : rte_wmb();
1650 : : /* Disable datapath on secondary process. */
1651 : 0 : mlx5_mp_os_req_stop_rxtx(dev);
1652 : 0 : rte_delay_us_sleep(1000 * priv->rxqs_n);
1653 : 0 : DRV_LOG(DEBUG, "port %u stopping device", dev->data->port_id);
1654 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1655 : 0 : mlx5_flow_rxq_flags_clear(dev);
1656 : 0 : mlx5_flow_stop_default(dev);
1657 : : /* Control flows for default traffic can be removed firstly. */
1658 : 0 : mlx5_traffic_disable(dev);
1659 : : /* All RX queue flags will be cleared in the flush interface. */
1660 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
1661 : 0 : mlx5_flow_meter_rxq_flush(dev);
1662 : 0 : mlx5_action_handle_detach(dev);
1663 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1664 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
1665 : : #endif
1666 : 0 : mlx5_rx_intr_vec_disable(dev);
1667 : 0 : priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
1668 : 0 : priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
1669 : 0 : mlx5_lsc_intr_cleanup(dev);
1670 : 0 : mlx5_txq_stop(dev);
1671 : 0 : mlx5_rxq_stop(dev);
1672 : 0 : mlx5_dev_free_consec_tx_mem(dev, true);
1673 [ # # ]: 0 : if (priv->obj_ops.lb_dummy_queue_release)
1674 : 0 : priv->obj_ops.lb_dummy_queue_release(dev);
1675 : 0 : mlx5_txpp_stop(dev);
1676 : :
1677 : 0 : return 0;
1678 : : }
1679 : :
1680 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1681 : :
1682 : : static int
1683 : 0 : mlx5_traffic_enable_hws(struct rte_eth_dev *dev)
1684 : : {
1685 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1686 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1687 : : uint64_t flags = 0;
1688 : : unsigned int i;
1689 : : int ret = 0;
1690 : :
1691 [ # # ]: 0 : for (i = 0; i < priv->txqs_n; ++i) {
1692 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
1693 : : uint32_t queue;
1694 : :
1695 [ # # ]: 0 : if (!txq)
1696 : 0 : continue;
1697 : 0 : queue = mlx5_txq_get_sqn(txq);
1698 [ # # ]: 0 : if ((priv->representor || priv->master) &&
1699 [ # # ]: 0 : config->dv_esw_en &&
1700 : : config->fdb_def_rule) {
1701 [ # # ]: 0 : if (mlx5_flow_hw_esw_create_sq_miss_flow(dev, queue, false)) {
1702 : 0 : mlx5_txq_release(dev, i);
1703 : 0 : goto error;
1704 : : }
1705 : : }
1706 [ # # ]: 0 : if (config->dv_esw_en) {
1707 [ # # ]: 0 : if (mlx5_flow_hw_create_tx_repr_matching_flow(dev, queue, false)) {
1708 : 0 : mlx5_txq_release(dev, i);
1709 : 0 : goto error;
1710 : : }
1711 : : }
1712 [ # # ]: 0 : if (mlx5_vport_tx_metadata_passing_enabled(priv->sh)) {
1713 [ # # ]: 0 : if (mlx5_flow_hw_create_nic_tx_default_mreg_copy_flow(dev, queue)) {
1714 : 0 : mlx5_txq_release(dev, i);
1715 : 0 : goto error;
1716 : : }
1717 : : }
1718 : 0 : mlx5_txq_release(dev, i);
1719 : : }
1720 [ # # ]: 0 : if (config->fdb_def_rule) {
1721 [ # # # # ]: 0 : if ((priv->master || priv->representor) && config->dv_esw_en) {
1722 [ # # ]: 0 : if (!mlx5_flow_hw_esw_create_default_jump_flow(dev))
1723 : 0 : priv->fdb_def_rule = 1;
1724 : : else
1725 : 0 : goto error;
1726 : : }
1727 : : } else {
1728 : 0 : DRV_LOG(INFO, "port %u FDB default rule is disabled", dev->data->port_id);
1729 : : }
1730 [ # # # # ]: 0 : if (mlx5_flow_lacp_miss_needed(dev) && mlx5_flow_hw_lacp_rx_flow(dev) != 0)
1731 : 0 : goto error;
1732 [ # # ]: 0 : if (priv->isolated)
1733 : : return 0;
1734 : 0 : ret = mlx5_flow_hw_create_ctrl_rx_tables(dev);
1735 [ # # ]: 0 : if (ret) {
1736 : 0 : DRV_LOG(ERR, "Failed to set up Rx control flow templates for port %u, %d",
1737 : : dev->data->port_id, -ret);
1738 : 0 : goto error;
1739 : : }
1740 [ # # ]: 0 : if (dev->data->promiscuous) {
1741 : : flags |= MLX5_CTRL_PROMISCUOUS;
1742 : : } else {
1743 [ # # ]: 0 : if (dev->data->all_multicast)
1744 : : flags |= MLX5_CTRL_ALL_MULTICAST;
1745 : : else
1746 : : flags |= (MLX5_CTRL_BROADCAST |
1747 : : MLX5_CTRL_IPV4_MULTICAST |
1748 : : MLX5_CTRL_IPV6_MULTICAST);
1749 : 0 : flags |= MLX5_CTRL_DMAC;
1750 : : }
1751 [ # # ]: 0 : if (priv->vlan_filter_n)
1752 : 0 : flags |= MLX5_CTRL_VLAN_FILTER;
1753 : 0 : return mlx5_flow_hw_ctrl_flows(dev, flags);
1754 : 0 : error:
1755 : 0 : ret = rte_errno;
1756 : 0 : mlx5_flow_hw_flush_ctrl_flows(dev);
1757 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_tables(dev);
1758 : 0 : rte_errno = ret;
1759 : 0 : return -rte_errno;
1760 : : }
1761 : :
1762 : : #endif
1763 : :
1764 : : /**
1765 : : * Enable traffic flows configured by control plane
1766 : : *
1767 : : * @param dev
1768 : : * Pointer to Ethernet device structure.
1769 : : *
1770 : : * @return
1771 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1772 : : */
1773 : : int
1774 : 0 : mlx5_traffic_enable(struct rte_eth_dev *dev)
1775 : : {
1776 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1777 : 0 : struct rte_flow_item_eth bcast = {
1778 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
1779 : : };
1780 : 0 : struct rte_flow_item_eth ipv6_multi_spec = {
1781 : : .hdr.dst_addr.addr_bytes = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 },
1782 : : };
1783 : 0 : struct rte_flow_item_eth ipv6_multi_mask = {
1784 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
1785 : : };
1786 : 0 : struct rte_flow_item_eth unicast = {
1787 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1788 : : };
1789 : 0 : struct rte_flow_item_eth unicast_mask = {
1790 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
1791 : : };
1792 : 0 : const unsigned int vlan_filter_n = priv->vlan_filter_n;
1793 : 0 : const struct rte_ether_addr cmp = {
1794 : : .addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1795 : : };
1796 : : unsigned int i;
1797 : : unsigned int j;
1798 : : int ret;
1799 : :
1800 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1801 : : return 0;
1802 : :
1803 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1804 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1805 : 0 : return mlx5_traffic_enable_hws(dev);
1806 : : #endif
1807 : : /*
1808 : : * Hairpin txq default flow should be created no matter if it is
1809 : : * isolation mode. Or else all the packets to be sent will be sent
1810 : : * out directly without the TX flow actions, e.g. encapsulation.
1811 : : */
1812 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
1813 : 0 : struct mlx5_txq_ctrl *txq_ctrl = mlx5_txq_get(dev, i);
1814 [ # # ]: 0 : if (!txq_ctrl)
1815 : 0 : continue;
1816 : : /* Only Tx implicit mode requires the default Tx flow. */
1817 [ # # ]: 0 : if (txq_ctrl->is_hairpin &&
1818 [ # # ]: 0 : txq_ctrl->hairpin_conf.tx_explicit == 0 &&
1819 : 0 : txq_ctrl->hairpin_conf.peers[0].port ==
1820 [ # # ]: 0 : priv->dev_data->port_id) {
1821 : 0 : ret = mlx5_ctrl_flow_source_queue(dev,
1822 : 0 : mlx5_txq_get_sqn(txq_ctrl));
1823 [ # # ]: 0 : if (ret) {
1824 : 0 : mlx5_txq_release(dev, i);
1825 : 0 : goto error;
1826 : : }
1827 : : }
1828 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
1829 : 0 : uint32_t q = mlx5_txq_get_sqn(txq_ctrl);
1830 : :
1831 [ # # ]: 0 : if (mlx5_flow_create_devx_sq_miss_flow(dev, q) == 0) {
1832 : 0 : mlx5_txq_release(dev, i);
1833 : 0 : DRV_LOG(ERR,
1834 : : "Port %u Tx queue %u SQ create representor devx default miss rule failed.",
1835 : : dev->data->port_id, i);
1836 : 0 : goto error;
1837 : : }
1838 : : }
1839 : 0 : mlx5_txq_release(dev, i);
1840 : : }
1841 [ # # ]: 0 : if (priv->sh->config.fdb_def_rule) {
1842 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
1843 [ # # ]: 0 : if (mlx5_flow_create_esw_table_zero_flow(dev))
1844 : 0 : priv->fdb_def_rule = 1;
1845 : : else
1846 : 0 : DRV_LOG(INFO, "port %u FDB default rule cannot be configured - only Eswitch group 0 flows are supported.",
1847 : : dev->data->port_id);
1848 : : }
1849 : : } else {
1850 : 0 : DRV_LOG(INFO, "port %u FDB default rule is disabled",
1851 : : dev->data->port_id);
1852 : : }
1853 [ # # ]: 0 : if (mlx5_flow_lacp_miss_needed(dev)) {
1854 : 0 : ret = mlx5_flow_lacp_miss(dev);
1855 [ # # ]: 0 : if (ret)
1856 : 0 : DRV_LOG(INFO, "port %u LACP rule cannot be created - "
1857 : : "forward LACP to kernel.", dev->data->port_id);
1858 : : else
1859 : 0 : DRV_LOG(INFO, "LACP traffic will be missed in port %u.",
1860 : : dev->data->port_id);
1861 : : }
1862 [ # # ]: 0 : if (priv->isolated)
1863 : : return 0;
1864 [ # # ]: 0 : if (dev->data->promiscuous) {
1865 : 0 : struct rte_flow_item_eth promisc = {
1866 : : .hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1867 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1868 : : .hdr.ether_type = 0,
1869 : : };
1870 : :
1871 : 0 : ret = mlx5_ctrl_flow(dev, &promisc, &promisc);
1872 [ # # ]: 0 : if (ret)
1873 : 0 : goto error;
1874 : : }
1875 [ # # ]: 0 : if (dev->data->all_multicast) {
1876 : 0 : struct rte_flow_item_eth multicast = {
1877 : : .hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
1878 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1879 : : .hdr.ether_type = 0,
1880 : : };
1881 : :
1882 : 0 : ret = mlx5_ctrl_flow(dev, &multicast, &multicast);
1883 [ # # ]: 0 : if (ret)
1884 : 0 : goto error;
1885 : : } else {
1886 : : /* Add broadcast/multicast flows. */
1887 [ # # ]: 0 : for (i = 0; i != vlan_filter_n; ++i) {
1888 : 0 : uint16_t vlan = priv->vlan_filter[i];
1889 : :
1890 : 0 : struct rte_flow_item_vlan vlan_spec = {
1891 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
1892 : : };
1893 : 0 : struct rte_flow_item_vlan vlan_mask =
1894 : : rte_flow_item_vlan_mask;
1895 : :
1896 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
1897 : : &vlan_spec, &vlan_mask);
1898 [ # # ]: 0 : if (ret)
1899 : 0 : goto error;
1900 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
1901 : : &ipv6_multi_mask,
1902 : : &vlan_spec, &vlan_mask);
1903 [ # # ]: 0 : if (ret)
1904 : 0 : goto error;
1905 : : }
1906 [ # # ]: 0 : if (!vlan_filter_n) {
1907 : 0 : ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
1908 [ # # ]: 0 : if (ret)
1909 : 0 : goto error;
1910 : 0 : ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
1911 : : &ipv6_multi_mask);
1912 [ # # ]: 0 : if (ret) {
1913 : : /* Do not fail on IPv6 broadcast creation failure. */
1914 : 0 : DRV_LOG(WARNING,
1915 : : "IPv6 broadcast is not supported");
1916 : : ret = 0;
1917 : : }
1918 : : }
1919 : : }
1920 : : /* Add MAC address flows. */
1921 [ # # ]: 0 : for (i = 0; i != priv->sh->dev_cap.max_mac_addrs; ++i) {
1922 : 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
1923 : :
1924 : : /* Add flows for unicast and multicast mac addresses added by API. */
1925 [ # # # # ]: 0 : if (!memcmp(mac, &cmp, sizeof(*mac)) ||
1926 [ # # ]: 0 : !rte_bitset_test(priv->mac_own, i) ||
1927 [ # # # # ]: 0 : (dev->data->all_multicast && rte_is_multicast_ether_addr(mac)))
1928 : 0 : continue;
1929 : : memcpy(&unicast.hdr.dst_addr.addr_bytes,
1930 : : mac->addr_bytes,
1931 : : RTE_ETHER_ADDR_LEN);
1932 [ # # ]: 0 : for (j = 0; j != vlan_filter_n; ++j) {
1933 : 0 : uint16_t vlan = priv->vlan_filter[j];
1934 : :
1935 : 0 : struct rte_flow_item_vlan vlan_spec = {
1936 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
1937 : : };
1938 : 0 : struct rte_flow_item_vlan vlan_mask =
1939 : : rte_flow_item_vlan_mask;
1940 : :
1941 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &unicast,
1942 : : &unicast_mask,
1943 : : &vlan_spec,
1944 : : &vlan_mask);
1945 [ # # ]: 0 : if (ret)
1946 : 0 : goto error;
1947 : : }
1948 [ # # ]: 0 : if (!vlan_filter_n) {
1949 : 0 : ret = mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
1950 [ # # ]: 0 : if (ret)
1951 : 0 : goto error;
1952 : : }
1953 : : }
1954 : : return 0;
1955 : 0 : error:
1956 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1957 : 0 : mlx5_traffic_disable_legacy(dev);
1958 : 0 : rte_errno = ret; /* Restore rte_errno. */
1959 : 0 : return -rte_errno;
1960 : : }
1961 : :
1962 : : static void
1963 : 0 : mlx5_traffic_disable_legacy(struct rte_eth_dev *dev)
1964 : : {
1965 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1966 : : struct mlx5_ctrl_flow_entry *entry;
1967 : : struct mlx5_ctrl_flow_entry *tmp;
1968 : :
1969 : : /*
1970 : : * Free registered control flow rules first,
1971 : : * to free the memory allocated for list entries
1972 : : */
1973 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
1974 [ # # ]: 0 : while (entry != NULL) {
1975 : 0 : tmp = LIST_NEXT(entry, next);
1976 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
1977 : : entry = tmp;
1978 : : }
1979 : :
1980 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
1981 : 0 : }
1982 : :
1983 : : /**
1984 : : * Disable traffic flows configured by control plane
1985 : : *
1986 : : * @param dev
1987 : : * Pointer to Ethernet device private data.
1988 : : */
1989 : : void
1990 : 0 : mlx5_traffic_disable(struct rte_eth_dev *dev)
1991 : : {
1992 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
1993 : : return;
1994 : :
1995 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1996 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1997 : :
1998 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1999 : : /* Device started flag was cleared before, this is used to derefer the Rx queues. */
2000 : 0 : priv->hws_rule_flushing = true;
2001 : 0 : mlx5_flow_hw_flush_ctrl_flows(dev);
2002 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_tables(dev);
2003 : 0 : priv->hws_rule_flushing = false;
2004 : : }
2005 : : else
2006 : : #endif
2007 : 0 : mlx5_traffic_disable_legacy(dev);
2008 : : }
2009 : :
2010 : : /**
2011 : : * Restart traffic flows configured by control plane
2012 : : *
2013 : : * @param dev
2014 : : * Pointer to Ethernet device private data.
2015 : : *
2016 : : * @return
2017 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2018 : : */
2019 : : int
2020 : 0 : mlx5_traffic_restart(struct rte_eth_dev *dev)
2021 : : {
2022 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
2023 : : return 0;
2024 : :
2025 [ # # ]: 0 : if (dev->data->dev_started) {
2026 : 0 : mlx5_traffic_disable(dev);
2027 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2028 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
2029 : : #endif
2030 : 0 : return mlx5_traffic_enable(dev);
2031 : : }
2032 : : return 0;
2033 : : }
2034 : :
2035 : : static bool
2036 : 0 : mac_flows_update_needed(struct rte_eth_dev *dev)
2037 : : {
2038 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2039 : :
2040 [ # # ]: 0 : if (mlx5_flow_is_steering_disabled())
2041 : : return false;
2042 [ # # ]: 0 : if (!dev->data->dev_started)
2043 : : return false;
2044 [ # # ]: 0 : if (dev->data->promiscuous)
2045 : : return false;
2046 [ # # ]: 0 : if (priv->isolated)
2047 : 0 : return false;
2048 : :
2049 : : return true;
2050 : : }
2051 : :
2052 : : static int
2053 : 0 : traffic_dmac_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
2054 : : {
2055 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2056 : :
2057 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2058 : 0 : return mlx5_flow_hw_ctrl_flow_dmac(dev, addr);
2059 : : else
2060 : 0 : return mlx5_legacy_dmac_flow_create(dev, addr);
2061 : : }
2062 : :
2063 : : static int
2064 : 0 : traffic_dmac_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
2065 : : {
2066 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2067 : :
2068 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2069 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_destroy(dev, addr);
2070 : : else
2071 : 0 : return mlx5_legacy_dmac_flow_destroy(dev, addr);
2072 : : }
2073 : :
2074 : : static int
2075 : 0 : traffic_dmac_vlan_create(struct rte_eth_dev *dev,
2076 : : const struct rte_ether_addr *addr,
2077 : : const uint16_t vid)
2078 : : {
2079 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2080 : :
2081 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2082 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_vlan(dev, addr, vid);
2083 : : else
2084 : 0 : return mlx5_legacy_dmac_vlan_flow_create(dev, addr, vid);
2085 : : }
2086 : :
2087 : : static int
2088 : 0 : traffic_dmac_vlan_destroy(struct rte_eth_dev *dev,
2089 : : const struct rte_ether_addr *addr,
2090 : : const uint16_t vid)
2091 : : {
2092 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2093 : :
2094 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2095 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(dev, addr, vid);
2096 : : else
2097 : 0 : return mlx5_legacy_dmac_vlan_flow_destroy(dev, addr, vid);
2098 : : }
2099 : :
2100 : : /**
2101 : : * Adjust Rx control flow rules to allow traffic on provided MAC address.
2102 : : */
2103 : : int
2104 : 0 : mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
2105 : : {
2106 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2107 : :
2108 [ # # ]: 0 : if (!mac_flows_update_needed(dev))
2109 : : return 0;
2110 : :
2111 [ # # ]: 0 : if (priv->vlan_filter_n > 0) {
2112 : : unsigned int i;
2113 : :
2114 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
2115 : 0 : uint16_t vlan = priv->vlan_filter[i];
2116 : : int ret;
2117 : :
2118 [ # # ]: 0 : if (mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan))
2119 : 0 : continue;
2120 : :
2121 : 0 : ret = traffic_dmac_vlan_create(dev, addr, vlan);
2122 [ # # ]: 0 : if (ret != 0)
2123 : 0 : return ret;
2124 : : }
2125 : :
2126 : : return 0;
2127 : : }
2128 : :
2129 [ # # ]: 0 : if (mlx5_ctrl_flow_uc_dmac_exists(dev, addr))
2130 : : return 0;
2131 : :
2132 : 0 : return traffic_dmac_create(dev, addr);
2133 : : }
2134 : :
2135 : : /**
2136 : : * Adjust Rx control flow rules to disallow traffic with removed MAC address.
2137 : : */
2138 : : int
2139 : 0 : mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
2140 : : {
2141 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2142 : :
2143 [ # # ]: 0 : if (!mac_flows_update_needed(dev))
2144 : : return 0;
2145 : :
2146 [ # # ]: 0 : if (priv->vlan_filter_n > 0) {
2147 : : unsigned int i;
2148 : :
2149 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
2150 : 0 : uint16_t vlan = priv->vlan_filter[i];
2151 : : int ret;
2152 : :
2153 [ # # ]: 0 : if (!mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan))
2154 : 0 : continue;
2155 : :
2156 : 0 : ret = traffic_dmac_vlan_destroy(dev, addr, vlan);
2157 [ # # ]: 0 : if (ret != 0)
2158 : 0 : return ret;
2159 : : }
2160 : :
2161 : : return 0;
2162 : : }
2163 : :
2164 [ # # ]: 0 : if (!mlx5_ctrl_flow_uc_dmac_exists(dev, addr))
2165 : : return 0;
2166 : :
2167 : 0 : return traffic_dmac_destroy(dev, addr);
2168 : : }
2169 : :
2170 : : /**
2171 : : * Adjust Rx control flow rules to allow traffic on provided VLAN.
2172 : : *
2173 : : * Assumptions:
2174 : : * - Called when VLAN is added.
2175 : : * - At least one VLAN is enabled before function call.
2176 : : *
2177 : : * This functions assumes that VLAN is new and was not included in
2178 : : * Rx control flow rules set up before calling it.
2179 : : */
2180 : : int
2181 : 0 : mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid)
2182 : : {
2183 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2184 : : unsigned int i;
2185 : : int ret;
2186 : :
2187 [ # # ]: 0 : if (!mac_flows_update_needed(dev))
2188 : : return 0;
2189 : :
2190 : : /* Add all unicast DMAC flow rules with new VLAN attached. */
2191 [ # # ]: 0 : for (i = 0; i != priv->sh->dev_cap.max_mac_addrs; ++i) {
2192 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2193 : :
2194 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2195 : 0 : continue;
2196 : :
2197 : 0 : ret = traffic_dmac_vlan_create(dev, mac, vid);
2198 [ # # ]: 0 : if (ret != 0)
2199 : 0 : return ret;
2200 : : }
2201 : :
2202 [ # # ]: 0 : if (priv->vlan_filter_n == 1) {
2203 : : /*
2204 : : * Adding first VLAN. Need to remove unicast DMAC rules before adding new rules.
2205 : : * Removing after creating VLAN rules so that traffic "gap" is not introduced.
2206 : : */
2207 : :
2208 [ # # ]: 0 : for (i = 0; i != priv->sh->dev_cap.max_mac_addrs; ++i) {
2209 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2210 : :
2211 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2212 : 0 : continue;
2213 : :
2214 : 0 : ret = traffic_dmac_destroy(dev, mac);
2215 [ # # ]: 0 : if (ret != 0)
2216 : 0 : return ret;
2217 : : }
2218 : : }
2219 : :
2220 : : return 0;
2221 : : }
2222 : :
2223 : : /**
2224 : : * Adjust Rx control flow rules to disallow traffic with removed VLAN.
2225 : : *
2226 : : * Assumptions:
2227 : : *
2228 : : * - VLAN was really removed.
2229 : : */
2230 : : int
2231 : 0 : mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid)
2232 : : {
2233 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2234 : : unsigned int i;
2235 : : int ret;
2236 : :
2237 [ # # ]: 0 : if (!mac_flows_update_needed(dev))
2238 : : return 0;
2239 : :
2240 [ # # ]: 0 : if (priv->vlan_filter_n == 0) {
2241 : : /*
2242 : : * If there are no VLANs as a result, unicast DMAC flow rules must be recreated.
2243 : : * Recreating first to ensure no traffic "gap".
2244 : : */
2245 : :
2246 [ # # ]: 0 : for (i = 0; i != priv->sh->dev_cap.max_mac_addrs; ++i) {
2247 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2248 : :
2249 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2250 : 0 : continue;
2251 : :
2252 : 0 : ret = traffic_dmac_create(dev, mac);
2253 [ # # ]: 0 : if (ret != 0)
2254 : 0 : return ret;
2255 : : }
2256 : : }
2257 : :
2258 : : /* Remove all unicast DMAC flow rules with this VLAN. */
2259 [ # # ]: 0 : for (i = 0; i != priv->sh->dev_cap.max_mac_addrs; ++i) {
2260 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2261 : :
2262 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2263 : 0 : continue;
2264 : :
2265 : 0 : ret = traffic_dmac_vlan_destroy(dev, mac, vid);
2266 [ # # ]: 0 : if (ret != 0)
2267 : 0 : return ret;
2268 : : }
2269 : :
2270 : : return 0;
2271 : : }
|