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