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