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