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->sh->config.repr_matching && !priv->dr_ctx) {
1136 : 0 : DRV_LOG(ERR, "Failed to start port %u: with representor matching enabled, port "
1137 : : "must be configured for HWS", 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 : : /**
1230 : : * DPDK callback to start the device.
1231 : : *
1232 : : * Simulate device start by attaching all configured flows.
1233 : : *
1234 : : * @param dev
1235 : : * Pointer to Ethernet device structure.
1236 : : *
1237 : : * @return
1238 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1239 : : * The following error values are defined:
1240 : : *
1241 : : * - -EAGAIN: If port representor cannot be started,
1242 : : * because transfer proxy port is not started.
1243 : : */
1244 : : int
1245 : 0 : mlx5_dev_start(struct rte_eth_dev *dev)
1246 : : {
1247 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1248 : : int ret;
1249 : : int fine_inline;
1250 : :
1251 : 0 : DRV_LOG(DEBUG, "port %u starting device", dev->data->port_id);
1252 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1253 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1254 : 0 : struct rte_flow_error error = { 0, };
1255 : :
1256 : : /*If previous configuration does not exist. */
1257 [ # # ]: 0 : if (!(priv->dr_ctx)) {
1258 : 0 : ret = flow_hw_init(dev, &error);
1259 [ # # ]: 0 : if (ret) {
1260 : 0 : DRV_LOG(ERR, "Failed to start port %u %s: %s",
1261 : : dev->data->port_id, dev->data->name,
1262 : : error.message);
1263 : 0 : return ret;
1264 : : }
1265 : : }
1266 : : /* If there is no E-Switch, then there are no start/stop order limitations. */
1267 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
1268 : 0 : goto continue_dev_start;
1269 : : /* If master is being started, then it is always allowed. */
1270 [ # # ]: 0 : if (priv->master)
1271 : 0 : goto continue_dev_start;
1272 [ # # ]: 0 : if (mlx5_hw_representor_port_allowed_start(dev))
1273 : 0 : return -rte_errno;
1274 : : }
1275 : 0 : continue_dev_start:
1276 : : #endif
1277 : 0 : fine_inline = rte_mbuf_dynflag_lookup
1278 : : (RTE_PMD_MLX5_FINE_GRANULARITY_INLINE, NULL);
1279 [ # # ]: 0 : if (fine_inline >= 0)
1280 : 0 : rte_net_mlx5_dynf_inline_mask = RTE_BIT64(fine_inline);
1281 : : else
1282 : 0 : rte_net_mlx5_dynf_inline_mask = 0;
1283 [ # # ]: 0 : if (dev->data->nb_rx_queues > 0) {
1284 : 0 : uint32_t max_lro_msg_size = priv->max_lro_msg_size;
1285 : :
1286 [ # # ]: 0 : if (max_lro_msg_size < MLX5_LRO_SEG_CHUNK_SIZE) {
1287 : : uint32_t i;
1288 : : struct mlx5_rxq_priv *rxq;
1289 : :
1290 [ # # ]: 0 : for (i = 0; i != priv->rxqs_n; ++i) {
1291 : 0 : rxq = mlx5_rxq_get(dev, i);
1292 [ # # # # : 0 : if (rxq && rxq->ctrl && rxq->ctrl->rxq.lro) {
# # ]
1293 : 0 : DRV_LOG(ERR, "port %u invalid max LRO size",
1294 : : dev->data->port_id);
1295 : 0 : rte_errno = EINVAL;
1296 : 0 : return -rte_errno;
1297 : : }
1298 : : }
1299 : : }
1300 : 0 : ret = mlx5_dev_configure_rss_reta(dev);
1301 [ # # ]: 0 : if (ret) {
1302 : 0 : DRV_LOG(ERR, "port %u reta config failed: %s",
1303 : : dev->data->port_id, strerror(rte_errno));
1304 : 0 : return -rte_errno;
1305 : : }
1306 : : }
1307 : 0 : ret = mlx5_txpp_start(dev);
1308 [ # # ]: 0 : if (ret) {
1309 : 0 : DRV_LOG(ERR, "port %u Tx packet pacing init failed: %s",
1310 : : dev->data->port_id, strerror(rte_errno));
1311 : 0 : goto error;
1312 : : }
1313 [ # # # # ]: 0 : if (mlx5_devx_obj_ops_en(priv->sh) &&
1314 [ # # ]: 0 : priv->obj_ops.lb_dummy_queue_create) {
1315 : 0 : ret = priv->obj_ops.lb_dummy_queue_create(dev);
1316 [ # # ]: 0 : if (ret)
1317 : 0 : goto error;
1318 : : }
1319 : 0 : ret = mlx5_dev_allocate_consec_tx_mem(dev);
1320 [ # # ]: 0 : if (ret) {
1321 : 0 : DRV_LOG(ERR, "port %u Tx queues memory allocation failed: %s",
1322 : : dev->data->port_id, strerror(rte_errno));
1323 : 0 : goto error;
1324 : : }
1325 : 0 : ret = mlx5_txq_start(dev);
1326 [ # # ]: 0 : if (ret) {
1327 : 0 : DRV_LOG(ERR, "port %u Tx queue allocation failed: %s",
1328 : : dev->data->port_id, strerror(rte_errno));
1329 : 0 : goto error;
1330 : : }
1331 [ # # ]: 0 : if (priv->config.std_delay_drop || priv->config.hp_delay_drop) {
1332 [ # # ]: 0 : if (!priv->sh->dev_cap.vf && !priv->sh->dev_cap.sf &&
1333 [ # # ]: 0 : !priv->representor) {
1334 : 0 : ret = mlx5_get_flag_dropless_rq(dev);
1335 [ # # ]: 0 : if (ret < 0)
1336 : 0 : DRV_LOG(WARNING,
1337 : : "port %u cannot query dropless flag",
1338 : : dev->data->port_id);
1339 [ # # ]: 0 : else if (!ret)
1340 : 0 : DRV_LOG(WARNING,
1341 : : "port %u dropless_rq OFF, no rearming",
1342 : : dev->data->port_id);
1343 : : } else {
1344 : 0 : DRV_LOG(DEBUG,
1345 : : "port %u doesn't support dropless_rq flag",
1346 : : dev->data->port_id);
1347 : : }
1348 : : }
1349 : 0 : ret = mlx5_rxq_start(dev);
1350 [ # # ]: 0 : if (ret) {
1351 : 0 : DRV_LOG(ERR, "port %u Rx queue allocation failed: %s",
1352 : : dev->data->port_id, strerror(rte_errno));
1353 : 0 : goto error;
1354 : : }
1355 : : /*
1356 : : * Such step will be skipped if there is no hairpin TX queue configured
1357 : : * with RX peer queue from the same device.
1358 : : */
1359 : 0 : ret = mlx5_hairpin_auto_bind(dev);
1360 [ # # ]: 0 : if (ret) {
1361 : 0 : DRV_LOG(ERR, "port %u hairpin auto binding failed: %s",
1362 : : dev->data->port_id, strerror(rte_errno));
1363 : 0 : goto error;
1364 : : }
1365 : : /* Set started flag here for the following steps like control flow. */
1366 : 0 : dev->data->dev_started = 1;
1367 : 0 : ret = mlx5_rx_intr_vec_enable(dev);
1368 [ # # ]: 0 : if (ret) {
1369 : 0 : DRV_LOG(ERR, "port %u Rx interrupt vector creation failed",
1370 : : dev->data->port_id);
1371 : 0 : goto error;
1372 : : }
1373 : 0 : mlx5_os_stats_init(dev);
1374 : : /*
1375 : : * Attach indirection table objects detached on port stop.
1376 : : * They may be needed to create RSS in non-isolated mode.
1377 : : */
1378 : 0 : ret = mlx5_action_handle_attach(dev);
1379 [ # # ]: 0 : if (ret) {
1380 : 0 : DRV_LOG(ERR,
1381 : : "port %u failed to attach indirect actions: %s",
1382 : : dev->data->port_id, rte_strerror(rte_errno));
1383 : 0 : goto error;
1384 : : }
1385 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1386 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1387 : 0 : ret = flow_hw_table_update(dev, NULL);
1388 [ # # ]: 0 : if (ret) {
1389 : 0 : DRV_LOG(ERR, "port %u failed to update HWS tables",
1390 : : dev->data->port_id);
1391 : 0 : goto error;
1392 : : }
1393 : : }
1394 : : #endif
1395 : 0 : ret = mlx5_traffic_enable(dev);
1396 [ # # ]: 0 : if (ret) {
1397 : 0 : DRV_LOG(ERR, "port %u failed to set defaults flows",
1398 : : dev->data->port_id);
1399 : 0 : goto error;
1400 : : }
1401 : : /* Set dynamic fields and flags into Rx queues. */
1402 : 0 : mlx5_flow_rxq_dynf_set(dev);
1403 : : /* Set flags and context to convert Rx timestamps. */
1404 : 0 : mlx5_rxq_timestamp_set(dev);
1405 : : /* Set a mask and offset of scheduling on timestamp into Tx queues. */
1406 : 0 : mlx5_txq_dynf_timestamp_set(dev);
1407 : : /*
1408 : : * In non-cached mode, it only needs to start the default mreg copy
1409 : : * action and no flow created by application exists anymore.
1410 : : * But it is worth wrapping the interface for further usage.
1411 : : */
1412 : 0 : ret = mlx5_flow_start_default(dev);
1413 [ # # ]: 0 : if (ret) {
1414 : 0 : DRV_LOG(DEBUG, "port %u failed to start default actions: %s",
1415 : : dev->data->port_id, strerror(rte_errno));
1416 : 0 : goto error;
1417 : : }
1418 [ # # ]: 0 : if (mlx5_dev_ctx_shared_mempool_subscribe(dev) != 0) {
1419 : 0 : DRV_LOG(ERR, "port %u failed to subscribe for mempool life cycle: %s",
1420 : : dev->data->port_id, rte_strerror(rte_errno));
1421 : 0 : goto error;
1422 : : }
1423 : : rte_wmb();
1424 : 0 : dev->tx_pkt_burst = mlx5_select_tx_function(dev);
1425 : 0 : dev->rx_pkt_burst = mlx5_select_rx_function(dev);
1426 : : /* Enable datapath on secondary process. */
1427 : 0 : mlx5_mp_os_req_start_rxtx(dev);
1428 [ # # ]: 0 : if (rte_intr_fd_get(priv->sh->intr_handle) >= 0) {
1429 : 0 : priv->sh->port[priv->dev_port - 1].ih_port_id =
1430 : 0 : (uint32_t)dev->data->port_id;
1431 : : } else {
1432 : 0 : DRV_LOG(INFO, "port %u starts without RMV interrupts.",
1433 : : dev->data->port_id);
1434 : 0 : dev->data->dev_conf.intr_conf.rmv = 0;
1435 : : }
1436 [ # # ]: 0 : if (rte_intr_fd_get(priv->sh->intr_handle_nl) >= 0) {
1437 : 0 : priv->sh->port[priv->dev_port - 1].nl_ih_port_id =
1438 : 0 : (uint32_t)dev->data->port_id;
1439 : : } else {
1440 : 0 : DRV_LOG(INFO, "port %u starts without LSC interrupts.",
1441 : : dev->data->port_id);
1442 : 0 : dev->data->dev_conf.intr_conf.lsc = 0;
1443 : : }
1444 [ # # ]: 0 : if (rte_intr_fd_get(priv->sh->intr_handle_devx) >= 0)
1445 : 0 : priv->sh->port[priv->dev_port - 1].devx_ih_port_id =
1446 : 0 : (uint32_t)dev->data->port_id;
1447 : : return 0;
1448 : 0 : error:
1449 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1450 : : /* Rollback. */
1451 : 0 : dev->data->dev_started = 0;
1452 : 0 : mlx5_flow_stop_default(dev);
1453 : 0 : mlx5_traffic_disable(dev);
1454 : 0 : mlx5_txq_stop(dev);
1455 : 0 : mlx5_rxq_stop(dev);
1456 [ # # ]: 0 : if (priv->obj_ops.lb_dummy_queue_release)
1457 : 0 : priv->obj_ops.lb_dummy_queue_release(dev);
1458 : 0 : mlx5_dev_free_consec_tx_mem(dev, false);
1459 : 0 : mlx5_txpp_stop(dev); /* Stop last. */
1460 : 0 : rte_errno = ret; /* Restore rte_errno. */
1461 : 0 : return -rte_errno;
1462 : : }
1463 : :
1464 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1465 : : /**
1466 : : * Check if stopping transfer proxy port is allowed.
1467 : : *
1468 : : * If transfer proxy port is configured for HWS, then it is allowed to stop it
1469 : : * if and only if all other representor ports are stopped.
1470 : : *
1471 : : * @param dev
1472 : : * Pointer to Ethernet device structure.
1473 : : *
1474 : : * @return
1475 : : * If stopping transfer proxy port is allowed, then 0 is returned.
1476 : : * Otherwise rte_errno is set, and negative errno value is returned.
1477 : : */
1478 : : static int
1479 : 0 : mlx5_hw_proxy_port_allowed_stop(struct rte_eth_dev *dev)
1480 : : {
1481 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1482 : : bool representor_started = false;
1483 : : uint16_t port_id;
1484 : :
1485 : : MLX5_ASSERT(priv->sh->config.dv_flow_en == 2);
1486 : : MLX5_ASSERT(priv->sh->config.dv_esw_en);
1487 : : MLX5_ASSERT(priv->master);
1488 : : /* If transfer proxy port was not configured for HWS, then stopping it is allowed. */
1489 [ # # ]: 0 : if (!priv->dr_ctx)
1490 : : return 0;
1491 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1492 : 0 : const struct rte_eth_dev *port_dev = &rte_eth_devices[port_id];
1493 : 0 : const struct mlx5_priv *port_priv = port_dev->data->dev_private;
1494 : :
1495 [ # # ]: 0 : if (port_id != dev->data->port_id &&
1496 [ # # # # ]: 0 : port_priv->domain_id == priv->domain_id &&
1497 : : port_dev->data->dev_started)
1498 : : representor_started = true;
1499 : : }
1500 [ # # ]: 0 : if (representor_started) {
1501 : 0 : DRV_LOG(ERR, "Failed to stop port %u: attached representor ports"
1502 : : " must be stopped before stopping transfer proxy port",
1503 : : dev->data->port_id);
1504 : 0 : rte_errno = EBUSY;
1505 : 0 : return -rte_errno;
1506 : : }
1507 : : return 0;
1508 : : }
1509 : : #endif
1510 : :
1511 : : /**
1512 : : * DPDK callback to stop the device.
1513 : : *
1514 : : * Simulate device stop by detaching all configured flows.
1515 : : *
1516 : : * @param dev
1517 : : * Pointer to Ethernet device structure.
1518 : : *
1519 : : * @return
1520 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1521 : : * The following error values are defined:
1522 : : *
1523 : : * - -EBUSY: If transfer proxy port cannot be stopped,
1524 : : * because other port representors are still running.
1525 : : */
1526 : : int
1527 : 0 : mlx5_dev_stop(struct rte_eth_dev *dev)
1528 : : {
1529 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1530 : :
1531 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1532 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1533 : : /* If there is no E-Switch, then there are no start/stop order limitations. */
1534 [ # # ]: 0 : if (!priv->sh->config.dv_esw_en)
1535 : 0 : goto continue_dev_stop;
1536 : : /* If representor is being stopped, then it is always allowed. */
1537 [ # # ]: 0 : if (priv->representor)
1538 : 0 : goto continue_dev_stop;
1539 [ # # ]: 0 : if (mlx5_hw_proxy_port_allowed_stop(dev)) {
1540 : 0 : dev->data->dev_started = 1;
1541 : 0 : return -rte_errno;
1542 : : }
1543 : : }
1544 : 0 : continue_dev_stop:
1545 : : #endif
1546 : 0 : dev->data->dev_started = 0;
1547 : : /* Prevent crashes when queues are still in use. */
1548 : 0 : dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1549 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
1550 : : rte_wmb();
1551 : : /* Disable datapath on secondary process. */
1552 : 0 : mlx5_mp_os_req_stop_rxtx(dev);
1553 : 0 : rte_delay_us_sleep(1000 * priv->rxqs_n);
1554 : 0 : DRV_LOG(DEBUG, "port %u stopping device", dev->data->port_id);
1555 : 0 : mlx5_flow_stop_default(dev);
1556 : : /* Control flows for default traffic can be removed firstly. */
1557 : 0 : mlx5_traffic_disable(dev);
1558 : : /* All RX queue flags will be cleared in the flush interface. */
1559 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
1560 : 0 : mlx5_flow_meter_rxq_flush(dev);
1561 : 0 : mlx5_action_handle_detach(dev);
1562 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1563 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
1564 : : #endif
1565 : 0 : mlx5_rx_intr_vec_disable(dev);
1566 : 0 : priv->sh->port[priv->dev_port - 1].ih_port_id = RTE_MAX_ETHPORTS;
1567 : 0 : priv->sh->port[priv->dev_port - 1].devx_ih_port_id = RTE_MAX_ETHPORTS;
1568 : 0 : priv->sh->port[priv->dev_port - 1].nl_ih_port_id = RTE_MAX_ETHPORTS;
1569 : 0 : mlx5_txq_stop(dev);
1570 : 0 : mlx5_rxq_stop(dev);
1571 : 0 : mlx5_dev_free_consec_tx_mem(dev, true);
1572 [ # # ]: 0 : if (priv->obj_ops.lb_dummy_queue_release)
1573 : 0 : priv->obj_ops.lb_dummy_queue_release(dev);
1574 : 0 : mlx5_txpp_stop(dev);
1575 : :
1576 : 0 : return 0;
1577 : : }
1578 : :
1579 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1580 : :
1581 : : static int
1582 : 0 : mlx5_traffic_enable_hws(struct rte_eth_dev *dev)
1583 : : {
1584 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1585 : 0 : struct mlx5_sh_config *config = &priv->sh->config;
1586 : : uint64_t flags = 0;
1587 : : unsigned int i;
1588 : : int ret;
1589 : :
1590 : : /*
1591 : : * With extended metadata enabled, the Tx metadata copy is handled by default
1592 : : * Tx tagging flow rules, so default Tx flow rule is not needed. It is only
1593 : : * required when representor matching is disabled.
1594 : : */
1595 : 0 : if (config->dv_esw_en &&
1596 [ # # ]: 0 : !config->repr_matching &&
1597 [ # # ]: 0 : config->dv_xmeta_en == MLX5_XMETA_MODE_META32_HWS &&
1598 : : priv->master) {
1599 [ # # ]: 0 : if (mlx5_flow_hw_create_tx_default_mreg_copy_flow(dev))
1600 : 0 : goto error;
1601 : : }
1602 [ # # ]: 0 : for (i = 0; i < priv->txqs_n; ++i) {
1603 : 0 : struct mlx5_txq_ctrl *txq = mlx5_txq_get(dev, i);
1604 : : uint32_t queue;
1605 : :
1606 [ # # ]: 0 : if (!txq)
1607 : 0 : continue;
1608 : 0 : queue = mlx5_txq_get_sqn(txq);
1609 [ # # ]: 0 : if ((priv->representor || priv->master) &&
1610 [ # # ]: 0 : config->dv_esw_en &&
1611 : : config->fdb_def_rule) {
1612 [ # # ]: 0 : if (mlx5_flow_hw_esw_create_sq_miss_flow(dev, queue, false)) {
1613 : 0 : mlx5_txq_release(dev, i);
1614 : 0 : goto error;
1615 : : }
1616 : : }
1617 [ # # ]: 0 : if (config->dv_esw_en && config->repr_matching) {
1618 [ # # ]: 0 : if (mlx5_flow_hw_tx_repr_matching_flow(dev, queue, false)) {
1619 : 0 : mlx5_txq_release(dev, i);
1620 : 0 : goto error;
1621 : : }
1622 : : }
1623 : 0 : mlx5_txq_release(dev, i);
1624 : : }
1625 [ # # ]: 0 : if (config->fdb_def_rule) {
1626 [ # # # # ]: 0 : if ((priv->master || priv->representor) && config->dv_esw_en) {
1627 [ # # ]: 0 : if (!mlx5_flow_hw_esw_create_default_jump_flow(dev))
1628 : 0 : priv->fdb_def_rule = 1;
1629 : : else
1630 : 0 : goto error;
1631 : : }
1632 : : } else {
1633 : 0 : DRV_LOG(INFO, "port %u FDB default rule is disabled", dev->data->port_id);
1634 : : }
1635 [ # # # # : 0 : if (!priv->sh->config.lacp_by_user && priv->pf_bond >= 0 && priv->master)
# # ]
1636 [ # # ]: 0 : if (mlx5_flow_hw_lacp_rx_flow(dev))
1637 : 0 : goto error;
1638 [ # # ]: 0 : if (priv->isolated)
1639 : : return 0;
1640 [ # # ]: 0 : if (dev->data->promiscuous)
1641 : : flags |= MLX5_CTRL_PROMISCUOUS;
1642 [ # # ]: 0 : if (dev->data->all_multicast)
1643 : 0 : flags |= MLX5_CTRL_ALL_MULTICAST;
1644 : : else
1645 : 0 : flags |= MLX5_CTRL_BROADCAST | MLX5_CTRL_IPV4_MULTICAST | MLX5_CTRL_IPV6_MULTICAST;
1646 : 0 : flags |= MLX5_CTRL_DMAC;
1647 [ # # ]: 0 : if (priv->vlan_filter_n)
1648 : 0 : flags |= MLX5_CTRL_VLAN_FILTER;
1649 : 0 : return mlx5_flow_hw_ctrl_flows(dev, flags);
1650 : 0 : error:
1651 : 0 : ret = rte_errno;
1652 : 0 : mlx5_flow_hw_flush_ctrl_flows(dev);
1653 : 0 : rte_errno = ret;
1654 : 0 : return -rte_errno;
1655 : : }
1656 : :
1657 : : #endif
1658 : :
1659 : : /**
1660 : : * Enable traffic flows configured by control plane
1661 : : *
1662 : : * @param dev
1663 : : * Pointer to Ethernet device structure.
1664 : : *
1665 : : * @return
1666 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1667 : : */
1668 : : int
1669 : 0 : mlx5_traffic_enable(struct rte_eth_dev *dev)
1670 : : {
1671 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1672 : 0 : struct rte_flow_item_eth bcast = {
1673 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
1674 : : };
1675 : 0 : struct rte_flow_item_eth ipv6_multi_spec = {
1676 : : .hdr.dst_addr.addr_bytes = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 },
1677 : : };
1678 : 0 : struct rte_flow_item_eth ipv6_multi_mask = {
1679 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 },
1680 : : };
1681 : 0 : struct rte_flow_item_eth unicast = {
1682 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1683 : : };
1684 : 0 : struct rte_flow_item_eth unicast_mask = {
1685 : : .hdr.dst_addr.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
1686 : : };
1687 : 0 : const unsigned int vlan_filter_n = priv->vlan_filter_n;
1688 : 0 : const struct rte_ether_addr cmp = {
1689 : : .addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1690 : : };
1691 : : unsigned int i;
1692 : : unsigned int j;
1693 : : int ret;
1694 : :
1695 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1696 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1697 : 0 : return mlx5_traffic_enable_hws(dev);
1698 : : #endif
1699 : : /*
1700 : : * Hairpin txq default flow should be created no matter if it is
1701 : : * isolation mode. Or else all the packets to be sent will be sent
1702 : : * out directly without the TX flow actions, e.g. encapsulation.
1703 : : */
1704 [ # # ]: 0 : for (i = 0; i != priv->txqs_n; ++i) {
1705 : 0 : struct mlx5_txq_ctrl *txq_ctrl = mlx5_txq_get(dev, i);
1706 [ # # ]: 0 : if (!txq_ctrl)
1707 : 0 : continue;
1708 : : /* Only Tx implicit mode requires the default Tx flow. */
1709 [ # # ]: 0 : if (txq_ctrl->is_hairpin &&
1710 [ # # ]: 0 : txq_ctrl->hairpin_conf.tx_explicit == 0 &&
1711 : 0 : txq_ctrl->hairpin_conf.peers[0].port ==
1712 [ # # ]: 0 : priv->dev_data->port_id) {
1713 : 0 : ret = mlx5_ctrl_flow_source_queue(dev,
1714 : 0 : mlx5_txq_get_sqn(txq_ctrl));
1715 [ # # ]: 0 : if (ret) {
1716 : 0 : mlx5_txq_release(dev, i);
1717 : 0 : goto error;
1718 : : }
1719 : : }
1720 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
1721 : 0 : uint32_t q = mlx5_txq_get_sqn(txq_ctrl);
1722 : :
1723 [ # # ]: 0 : if (mlx5_flow_create_devx_sq_miss_flow(dev, q) == 0) {
1724 : 0 : mlx5_txq_release(dev, i);
1725 : 0 : DRV_LOG(ERR,
1726 : : "Port %u Tx queue %u SQ create representor devx default miss rule failed.",
1727 : : dev->data->port_id, i);
1728 : 0 : goto error;
1729 : : }
1730 : : }
1731 : 0 : mlx5_txq_release(dev, i);
1732 : : }
1733 [ # # ]: 0 : if (priv->sh->config.fdb_def_rule) {
1734 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
1735 [ # # ]: 0 : if (mlx5_flow_create_esw_table_zero_flow(dev))
1736 : 0 : priv->fdb_def_rule = 1;
1737 : : else
1738 : 0 : DRV_LOG(INFO, "port %u FDB default rule cannot be configured - only Eswitch group 0 flows are supported.",
1739 : : dev->data->port_id);
1740 : : }
1741 : : } else {
1742 : 0 : DRV_LOG(INFO, "port %u FDB default rule is disabled",
1743 : : dev->data->port_id);
1744 : : }
1745 [ # # # # : 0 : if (!priv->sh->config.lacp_by_user && priv->pf_bond >= 0 && priv->master) {
# # ]
1746 : 0 : ret = mlx5_flow_lacp_miss(dev);
1747 [ # # ]: 0 : if (ret)
1748 : 0 : DRV_LOG(INFO, "port %u LACP rule cannot be created - "
1749 : : "forward LACP to kernel.", dev->data->port_id);
1750 : : else
1751 : 0 : DRV_LOG(INFO, "LACP traffic will be missed in port %u.",
1752 : : dev->data->port_id);
1753 : : }
1754 [ # # ]: 0 : if (priv->isolated)
1755 : : return 0;
1756 [ # # ]: 0 : if (dev->data->promiscuous) {
1757 : 0 : struct rte_flow_item_eth promisc = {
1758 : : .hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1759 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1760 : : .hdr.ether_type = 0,
1761 : : };
1762 : :
1763 : 0 : ret = mlx5_ctrl_flow(dev, &promisc, &promisc);
1764 [ # # ]: 0 : if (ret)
1765 : 0 : goto error;
1766 : : }
1767 [ # # ]: 0 : if (dev->data->all_multicast) {
1768 : 0 : struct rte_flow_item_eth multicast = {
1769 : : .hdr.dst_addr.addr_bytes = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
1770 : : .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1771 : : .hdr.ether_type = 0,
1772 : : };
1773 : :
1774 : 0 : ret = mlx5_ctrl_flow(dev, &multicast, &multicast);
1775 [ # # ]: 0 : if (ret)
1776 : 0 : goto error;
1777 : : } else {
1778 : : /* Add broadcast/multicast flows. */
1779 [ # # ]: 0 : for (i = 0; i != vlan_filter_n; ++i) {
1780 : 0 : uint16_t vlan = priv->vlan_filter[i];
1781 : :
1782 : 0 : struct rte_flow_item_vlan vlan_spec = {
1783 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
1784 : : };
1785 : 0 : struct rte_flow_item_vlan vlan_mask =
1786 : : rte_flow_item_vlan_mask;
1787 : :
1788 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &bcast, &bcast,
1789 : : &vlan_spec, &vlan_mask);
1790 [ # # ]: 0 : if (ret)
1791 : 0 : goto error;
1792 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &ipv6_multi_spec,
1793 : : &ipv6_multi_mask,
1794 : : &vlan_spec, &vlan_mask);
1795 [ # # ]: 0 : if (ret)
1796 : 0 : goto error;
1797 : : }
1798 [ # # ]: 0 : if (!vlan_filter_n) {
1799 : 0 : ret = mlx5_ctrl_flow(dev, &bcast, &bcast);
1800 [ # # ]: 0 : if (ret)
1801 : 0 : goto error;
1802 : 0 : ret = mlx5_ctrl_flow(dev, &ipv6_multi_spec,
1803 : : &ipv6_multi_mask);
1804 [ # # ]: 0 : if (ret) {
1805 : : /* Do not fail on IPv6 broadcast creation failure. */
1806 : 0 : DRV_LOG(WARNING,
1807 : : "IPv6 broadcast is not supported");
1808 : : ret = 0;
1809 : : }
1810 : : }
1811 : : }
1812 : : /* Add MAC address flows. */
1813 [ # # ]: 0 : for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
1814 : 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
1815 : :
1816 [ # # # # ]: 0 : if (!memcmp(mac, &cmp, sizeof(*mac)) || rte_is_multicast_ether_addr(mac))
1817 : 0 : continue;
1818 : : memcpy(&unicast.hdr.dst_addr.addr_bytes,
1819 : : mac->addr_bytes,
1820 : : RTE_ETHER_ADDR_LEN);
1821 [ # # ]: 0 : for (j = 0; j != vlan_filter_n; ++j) {
1822 : 0 : uint16_t vlan = priv->vlan_filter[j];
1823 : :
1824 : 0 : struct rte_flow_item_vlan vlan_spec = {
1825 [ # # ]: 0 : .hdr.vlan_tci = rte_cpu_to_be_16(vlan),
1826 : : };
1827 : 0 : struct rte_flow_item_vlan vlan_mask =
1828 : : rte_flow_item_vlan_mask;
1829 : :
1830 : 0 : ret = mlx5_ctrl_flow_vlan(dev, &unicast,
1831 : : &unicast_mask,
1832 : : &vlan_spec,
1833 : : &vlan_mask);
1834 [ # # ]: 0 : if (ret)
1835 : 0 : goto error;
1836 : : }
1837 [ # # ]: 0 : if (!vlan_filter_n) {
1838 : 0 : ret = mlx5_ctrl_flow(dev, &unicast, &unicast_mask);
1839 [ # # ]: 0 : if (ret)
1840 : 0 : goto error;
1841 : : }
1842 : : }
1843 : : return 0;
1844 : 0 : error:
1845 : 0 : ret = rte_errno; /* Save rte_errno before cleanup. */
1846 : 0 : mlx5_traffic_disable_legacy(dev);
1847 : 0 : rte_errno = ret; /* Restore rte_errno. */
1848 : 0 : return -rte_errno;
1849 : : }
1850 : :
1851 : : static void
1852 : 0 : mlx5_traffic_disable_legacy(struct rte_eth_dev *dev)
1853 : : {
1854 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1855 : : struct mlx5_ctrl_flow_entry *entry;
1856 : : struct mlx5_ctrl_flow_entry *tmp;
1857 : :
1858 : : /*
1859 : : * Free registered control flow rules first,
1860 : : * to free the memory allocated for list entries
1861 : : */
1862 : 0 : entry = LIST_FIRST(&priv->hw_ctrl_flows);
1863 [ # # ]: 0 : while (entry != NULL) {
1864 : 0 : tmp = LIST_NEXT(entry, next);
1865 : 0 : mlx5_legacy_ctrl_flow_destroy(dev, entry);
1866 : : entry = tmp;
1867 : : }
1868 : :
1869 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_CTL, false);
1870 : 0 : }
1871 : :
1872 : : /**
1873 : : * Disable traffic flows configured by control plane
1874 : : *
1875 : : * @param dev
1876 : : * Pointer to Ethernet device private data.
1877 : : */
1878 : : void
1879 : 0 : mlx5_traffic_disable(struct rte_eth_dev *dev)
1880 : : {
1881 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1882 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1883 : :
1884 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1885 : 0 : mlx5_flow_hw_flush_ctrl_flows(dev);
1886 : : else
1887 : : #endif
1888 : 0 : mlx5_traffic_disable_legacy(dev);
1889 : 0 : }
1890 : :
1891 : : /**
1892 : : * Restart traffic flows configured by control plane
1893 : : *
1894 : : * @param dev
1895 : : * Pointer to Ethernet device private data.
1896 : : *
1897 : : * @return
1898 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1899 : : */
1900 : : int
1901 : 0 : mlx5_traffic_restart(struct rte_eth_dev *dev)
1902 : : {
1903 [ # # ]: 0 : if (dev->data->dev_started) {
1904 : 0 : mlx5_traffic_disable(dev);
1905 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1906 : 0 : mlx5_flow_hw_cleanup_ctrl_rx_templates(dev);
1907 : : #endif
1908 : 0 : return mlx5_traffic_enable(dev);
1909 : : }
1910 : : return 0;
1911 : : }
1912 : :
1913 : : static bool
1914 : : mac_flows_update_needed(struct rte_eth_dev *dev)
1915 : : {
1916 : : struct mlx5_priv *priv = dev->data->dev_private;
1917 : :
1918 : 0 : if (!dev->data->dev_started)
1919 : : return false;
1920 [ # # # # : 0 : if (dev->data->promiscuous)
# # # # ]
1921 : : return false;
1922 [ # # # # : 0 : if (priv->isolated)
# # # # ]
1923 : : return false;
1924 : :
1925 : : return true;
1926 : : }
1927 : :
1928 : : static int
1929 : 0 : traffic_dmac_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
1930 : : {
1931 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1932 : :
1933 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1934 : 0 : return mlx5_flow_hw_ctrl_flow_dmac(dev, addr);
1935 : : else
1936 : 0 : return mlx5_legacy_dmac_flow_create(dev, addr);
1937 : : }
1938 : :
1939 : : static int
1940 : 0 : traffic_dmac_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
1941 : : {
1942 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1943 : :
1944 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1945 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_destroy(dev, addr);
1946 : : else
1947 : 0 : return mlx5_legacy_dmac_flow_destroy(dev, addr);
1948 : : }
1949 : :
1950 : : static int
1951 : 0 : traffic_dmac_vlan_create(struct rte_eth_dev *dev,
1952 : : const struct rte_ether_addr *addr,
1953 : : const uint16_t vid)
1954 : : {
1955 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1956 : :
1957 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1958 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_vlan(dev, addr, vid);
1959 : : else
1960 : 0 : return mlx5_legacy_dmac_vlan_flow_create(dev, addr, vid);
1961 : : }
1962 : :
1963 : : static int
1964 : 0 : traffic_dmac_vlan_destroy(struct rte_eth_dev *dev,
1965 : : const struct rte_ether_addr *addr,
1966 : : const uint16_t vid)
1967 : : {
1968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1969 : :
1970 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
1971 : 0 : return mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(dev, addr, vid);
1972 : : else
1973 : 0 : return mlx5_legacy_dmac_vlan_flow_destroy(dev, addr, vid);
1974 : : }
1975 : :
1976 : : /**
1977 : : * Adjust Rx control flow rules to allow traffic on provided MAC address.
1978 : : */
1979 : : int
1980 : 0 : mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
1981 : : {
1982 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
1983 : :
1984 : : if (!mac_flows_update_needed(dev))
1985 : : return 0;
1986 : :
1987 [ # # ]: 0 : if (priv->vlan_filter_n > 0) {
1988 : : unsigned int i;
1989 : :
1990 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
1991 : 0 : uint16_t vlan = priv->vlan_filter[i];
1992 : : int ret;
1993 : :
1994 [ # # ]: 0 : if (mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan))
1995 : 0 : continue;
1996 : :
1997 : 0 : ret = traffic_dmac_vlan_create(dev, addr, vlan);
1998 [ # # ]: 0 : if (ret != 0)
1999 : 0 : return ret;
2000 : : }
2001 : :
2002 : : return 0;
2003 : : }
2004 : :
2005 [ # # ]: 0 : if (mlx5_ctrl_flow_uc_dmac_exists(dev, addr))
2006 : : return 0;
2007 : :
2008 : 0 : return traffic_dmac_create(dev, addr);
2009 : : }
2010 : :
2011 : : /**
2012 : : * Adjust Rx control flow rules to disallow traffic with removed MAC address.
2013 : : */
2014 : : int
2015 : 0 : mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr)
2016 : : {
2017 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2018 : :
2019 : : if (!mac_flows_update_needed(dev))
2020 : : return 0;
2021 : :
2022 [ # # ]: 0 : if (priv->vlan_filter_n > 0) {
2023 : : unsigned int i;
2024 : :
2025 [ # # ]: 0 : for (i = 0; i < priv->vlan_filter_n; ++i) {
2026 : 0 : uint16_t vlan = priv->vlan_filter[i];
2027 : : int ret;
2028 : :
2029 [ # # ]: 0 : if (!mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan))
2030 : 0 : continue;
2031 : :
2032 : 0 : ret = traffic_dmac_vlan_destroy(dev, addr, vlan);
2033 [ # # ]: 0 : if (ret != 0)
2034 : 0 : return ret;
2035 : : }
2036 : :
2037 : : return 0;
2038 : : }
2039 : :
2040 [ # # ]: 0 : if (!mlx5_ctrl_flow_uc_dmac_exists(dev, addr))
2041 : : return 0;
2042 : :
2043 : 0 : return traffic_dmac_destroy(dev, addr);
2044 : : }
2045 : :
2046 : : /**
2047 : : * Adjust Rx control flow rules to allow traffic on provided VLAN.
2048 : : *
2049 : : * Assumptions:
2050 : : * - Called when VLAN is added.
2051 : : * - At least one VLAN is enabled before function call.
2052 : : *
2053 : : * This functions assumes that VLAN is new and was not included in
2054 : : * Rx control flow rules set up before calling it.
2055 : : */
2056 : : int
2057 : 0 : mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid)
2058 : : {
2059 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2060 : : unsigned int i;
2061 : : int ret;
2062 : :
2063 : : if (!mac_flows_update_needed(dev))
2064 : : return 0;
2065 : :
2066 : : /* Add all unicast DMAC flow rules with new VLAN attached. */
2067 [ # # ]: 0 : for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
2068 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2069 : :
2070 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2071 : 0 : continue;
2072 : :
2073 : 0 : ret = traffic_dmac_vlan_create(dev, mac, vid);
2074 [ # # ]: 0 : if (ret != 0)
2075 : 0 : return ret;
2076 : : }
2077 : :
2078 [ # # ]: 0 : if (priv->vlan_filter_n == 1) {
2079 : : /*
2080 : : * Adding first VLAN. Need to remove unicast DMAC rules before adding new rules.
2081 : : * Removing after creating VLAN rules so that traffic "gap" is not introduced.
2082 : : */
2083 : :
2084 [ # # ]: 0 : for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
2085 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2086 : :
2087 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2088 : 0 : continue;
2089 : :
2090 : 0 : ret = traffic_dmac_destroy(dev, mac);
2091 [ # # ]: 0 : if (ret != 0)
2092 : 0 : return ret;
2093 : : }
2094 : : }
2095 : :
2096 : : return 0;
2097 : : }
2098 : :
2099 : : /**
2100 : : * Adjust Rx control flow rules to disallow traffic with removed VLAN.
2101 : : *
2102 : : * Assumptions:
2103 : : *
2104 : : * - VLAN was really removed.
2105 : : */
2106 : : int
2107 : 0 : mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid)
2108 : : {
2109 [ # # ]: 0 : struct mlx5_priv *priv = dev->data->dev_private;
2110 : : unsigned int i;
2111 : : int ret;
2112 : :
2113 : : if (!mac_flows_update_needed(dev))
2114 : : return 0;
2115 : :
2116 [ # # ]: 0 : if (priv->vlan_filter_n == 0) {
2117 : : /*
2118 : : * If there are no VLANs as a result, unicast DMAC flow rules must be recreated.
2119 : : * Recreating first to ensure no traffic "gap".
2120 : : */
2121 : :
2122 [ # # ]: 0 : for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
2123 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2124 : :
2125 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2126 : 0 : continue;
2127 : :
2128 : 0 : ret = traffic_dmac_create(dev, mac);
2129 [ # # ]: 0 : if (ret != 0)
2130 : 0 : return ret;
2131 : : }
2132 : : }
2133 : :
2134 : : /* Remove all unicast DMAC flow rules with this VLAN. */
2135 [ # # ]: 0 : for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) {
2136 [ # # ]: 0 : struct rte_ether_addr *mac = &dev->data->mac_addrs[i];
2137 : :
2138 [ # # ]: 0 : if (rte_is_zero_ether_addr(mac))
2139 : 0 : continue;
2140 : :
2141 : 0 : ret = traffic_dmac_vlan_destroy(dev, mac, vid);
2142 [ # # ]: 0 : if (ret != 0)
2143 : 0 : return ret;
2144 : : }
2145 : :
2146 : : return 0;
2147 : : }
|