Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2017 6WIND S.A.
3 : : * Copyright 2017 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stdbool.h>
7 : : #include <stdint.h>
8 : : #include <unistd.h>
9 : : #ifdef RTE_EXEC_ENV_LINUX
10 : : #include <sys/eventfd.h>
11 : : #endif
12 : :
13 : : #include <rte_debug.h>
14 : : #include <rte_stdatomic.h>
15 : : #include <ethdev_driver.h>
16 : : #include <rte_malloc.h>
17 : : #include <rte_flow.h>
18 : : #include <rte_cycles.h>
19 : : #include <rte_ethdev.h>
20 : : #include <rte_string_fns.h>
21 : :
22 : : #include "failsafe_private.h"
23 : :
24 : : static int
25 : 0 : fs_dev_configure(struct rte_eth_dev *dev)
26 : : {
27 : : struct sub_device *sdev;
28 : : uint8_t i;
29 : : int ret;
30 : :
31 : 0 : ret = fs_lock(dev, 0);
32 [ # # ]: 0 : if (ret != 0)
33 : : return ret;
34 [ # # # # ]: 0 : FOREACH_SUBDEV(sdev, i, dev) {
35 : : int rmv_interrupt = 0;
36 : : int lsc_interrupt = 0;
37 : : int lsc_enabled;
38 : :
39 [ # # ]: 0 : if (sdev->state != DEV_PROBED &&
40 [ # # # # ]: 0 : !(PRIV(dev)->alarm_lock == 0 && sdev->state == DEV_ACTIVE))
41 : 0 : continue;
42 : :
43 [ # # ]: 0 : rmv_interrupt = ETH(sdev)->data->dev_flags &
44 : : RTE_ETH_DEV_INTR_RMV;
45 [ # # ]: 0 : if (rmv_interrupt) {
46 : 0 : DEBUG("Enabling RMV interrupts for sub_device %d", i);
47 : 0 : dev->data->dev_conf.intr_conf.rmv = 1;
48 : : } else {
49 : 0 : DEBUG("sub_device %d does not support RMV event", i);
50 : : }
51 : 0 : lsc_enabled = dev->data->dev_conf.intr_conf.lsc;
52 [ # # ]: 0 : lsc_interrupt = lsc_enabled &&
53 [ # # # # ]: 0 : (ETH(sdev)->data->dev_flags &
54 : : RTE_ETH_DEV_INTR_LSC);
55 : : if (lsc_interrupt) {
56 : 0 : DEBUG("Enabling LSC interrupts for sub_device %d", i);
57 : 0 : dev->data->dev_conf.intr_conf.lsc = 1;
58 [ # # ]: 0 : } else if (lsc_enabled && !lsc_interrupt) {
59 : 0 : DEBUG("Disabling LSC interrupts for sub_device %d", i);
60 : 0 : dev->data->dev_conf.intr_conf.lsc = 0;
61 : : }
62 : 0 : DEBUG("Configuring sub-device %d", i);
63 : 0 : ret = rte_eth_dev_configure(PORT_ID(sdev),
64 : 0 : dev->data->nb_rx_queues,
65 : 0 : dev->data->nb_tx_queues,
66 : 0 : &dev->data->dev_conf);
67 [ # # ]: 0 : if (ret) {
68 : 0 : if (!fs_err(sdev, ret))
69 : 0 : continue;
70 : 0 : ERROR("Could not configure sub_device %d", i);
71 : 0 : fs_unlock(dev, 0);
72 : 0 : return ret;
73 : : }
74 [ # # # # ]: 0 : if (rmv_interrupt && sdev->rmv_callback == 0) {
75 : 0 : ret = rte_eth_dev_callback_register(PORT_ID(sdev),
76 : : RTE_ETH_EVENT_INTR_RMV,
77 : : failsafe_eth_rmv_event_callback,
78 : : sdev);
79 [ # # ]: 0 : if (ret)
80 : 0 : WARN("Failed to register RMV callback for sub_device %d",
81 : : SUB_ID(sdev));
82 : : else
83 : 0 : sdev->rmv_callback = 1;
84 : : }
85 : 0 : dev->data->dev_conf.intr_conf.rmv = 0;
86 [ # # # # ]: 0 : if (lsc_interrupt && sdev->lsc_callback == 0) {
87 : 0 : ret = rte_eth_dev_callback_register(PORT_ID(sdev),
88 : : RTE_ETH_EVENT_INTR_LSC,
89 : : failsafe_eth_lsc_event_callback,
90 : : dev);
91 [ # # ]: 0 : if (ret)
92 : 0 : WARN("Failed to register LSC callback for sub_device %d",
93 : : SUB_ID(sdev));
94 : : else
95 : 0 : sdev->lsc_callback = 1;
96 : : }
97 : 0 : dev->data->dev_conf.intr_conf.lsc = lsc_enabled;
98 : 0 : sdev->state = DEV_ACTIVE;
99 : : }
100 [ # # ]: 0 : if (PRIV(dev)->state < DEV_ACTIVE)
101 : 0 : PRIV(dev)->state = DEV_ACTIVE;
102 : 0 : fs_unlock(dev, 0);
103 : 0 : return 0;
104 : : }
105 : :
106 : : static void
107 : 0 : fs_set_queues_state_start(struct rte_eth_dev *dev)
108 : : {
109 : : struct rxq *rxq;
110 : : struct txq *txq;
111 : : uint16_t i;
112 : :
113 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
114 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
115 : 0 : rxq = dev->data->rx_queues[i];
116 [ # # # # ]: 0 : if (rxq != NULL && !rxq->info.conf.rx_deferred_start)
117 : 0 : dev->data->rx_queue_state[i] =
118 : : RTE_ETH_QUEUE_STATE_STARTED;
119 : : }
120 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
121 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
122 : 0 : txq = dev->data->tx_queues[i];
123 [ # # # # ]: 0 : if (txq != NULL && !txq->info.conf.tx_deferred_start)
124 : 0 : dev->data->tx_queue_state[i] =
125 : : RTE_ETH_QUEUE_STATE_STARTED;
126 : : }
127 : 0 : }
128 : :
129 : : static int
130 : 0 : fs_dev_start(struct rte_eth_dev *dev)
131 : : {
132 : : struct sub_device *sdev;
133 : : uint8_t i;
134 : : int ret;
135 : :
136 : 0 : ret = fs_lock(dev, 0);
137 [ # # ]: 0 : if (ret != 0)
138 : : return ret;
139 : 0 : ret = failsafe_rx_intr_install(dev);
140 [ # # ]: 0 : if (ret) {
141 : 0 : fs_unlock(dev, 0);
142 : 0 : return ret;
143 : : }
144 [ # # # # ]: 0 : FOREACH_SUBDEV(sdev, i, dev) {
145 [ # # ]: 0 : if (sdev->state != DEV_ACTIVE)
146 : 0 : continue;
147 : 0 : DEBUG("Starting sub_device %d", i);
148 : 0 : ret = rte_eth_dev_start(PORT_ID(sdev));
149 [ # # ]: 0 : if (ret) {
150 : 0 : if (!fs_err(sdev, ret))
151 : 0 : continue;
152 : 0 : fs_unlock(dev, 0);
153 : 0 : return ret;
154 : : }
155 : 0 : ret = failsafe_rx_intr_install_subdevice(sdev);
156 [ # # ]: 0 : if (ret) {
157 : 0 : if (!fs_err(sdev, ret))
158 : 0 : continue;
159 [ # # ]: 0 : if (fs_err(sdev, rte_eth_dev_stop(PORT_ID(sdev))) < 0)
160 : 0 : ERROR("Failed to stop sub-device %u",
161 : : SUB_ID(sdev));
162 : 0 : fs_unlock(dev, 0);
163 : 0 : return ret;
164 : : }
165 : 0 : sdev->state = DEV_STARTED;
166 : : }
167 [ # # ]: 0 : if (PRIV(dev)->state < DEV_STARTED) {
168 : 0 : PRIV(dev)->state = DEV_STARTED;
169 : 0 : fs_set_queues_state_start(dev);
170 : : }
171 : 0 : fs_switch_dev(dev, NULL);
172 : 0 : fs_unlock(dev, 0);
173 : 0 : return 0;
174 : : }
175 : :
176 : : static void
177 : 0 : fs_set_queues_state_stop(struct rte_eth_dev *dev)
178 : : {
179 : : uint16_t i;
180 : :
181 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
182 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
183 [ # # ]: 0 : if (dev->data->rx_queues[i] != NULL)
184 : 0 : dev->data->rx_queue_state[i] =
185 : : RTE_ETH_QUEUE_STATE_STOPPED;
186 : : }
187 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
188 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
189 [ # # ]: 0 : if (dev->data->tx_queues[i] != NULL)
190 : 0 : dev->data->tx_queue_state[i] =
191 : : RTE_ETH_QUEUE_STATE_STOPPED;
192 : : }
193 : 0 : }
194 : :
195 : : static int
196 : 0 : fs_dev_stop(struct rte_eth_dev *dev)
197 : : {
198 : : struct sub_device *sdev;
199 : : uint8_t i;
200 : : int ret;
201 : :
202 : 0 : ret = fs_lock(dev, 0);
203 [ # # ]: 0 : if (ret != 0)
204 : : return ret;
205 : 0 : PRIV(dev)->state = DEV_STARTED - 1;
206 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
207 : 0 : ret = rte_eth_dev_stop(PORT_ID(sdev));
208 [ # # ]: 0 : if (fs_err(sdev, ret) < 0) {
209 : 0 : ERROR("Failed to stop device %u",
210 : : PORT_ID(sdev));
211 : 0 : PRIV(dev)->state = DEV_STARTED + 1;
212 : 0 : fs_unlock(dev, 0);
213 : 0 : return ret;
214 : : }
215 : 0 : failsafe_rx_intr_uninstall_subdevice(sdev);
216 : 0 : sdev->state = DEV_STARTED - 1;
217 : : }
218 : 0 : failsafe_rx_intr_uninstall(dev);
219 : 0 : fs_set_queues_state_stop(dev);
220 : 0 : fs_unlock(dev, 0);
221 : :
222 : 0 : return 0;
223 : : }
224 : :
225 : : static int
226 : 0 : fs_dev_set_link_up(struct rte_eth_dev *dev)
227 : : {
228 : : struct sub_device *sdev;
229 : : uint8_t i;
230 : : int ret;
231 : :
232 : 0 : ret = fs_lock(dev, 0);
233 [ # # ]: 0 : if (ret != 0)
234 : : return ret;
235 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
236 : 0 : DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
237 : 0 : ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
238 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
239 : 0 : ERROR("Operation rte_eth_dev_set_link_up failed for sub_device %d"
240 : : " with error %d", i, ret);
241 : 0 : fs_unlock(dev, 0);
242 : 0 : return ret;
243 : : }
244 : : }
245 : 0 : fs_unlock(dev, 0);
246 : 0 : return 0;
247 : : }
248 : :
249 : : static int
250 : 0 : fs_dev_set_link_down(struct rte_eth_dev *dev)
251 : : {
252 : : struct sub_device *sdev;
253 : : uint8_t i;
254 : : int ret;
255 : :
256 : 0 : ret = fs_lock(dev, 0);
257 [ # # ]: 0 : if (ret != 0)
258 : : return ret;
259 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
260 : 0 : DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
261 : 0 : ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
262 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
263 : 0 : ERROR("Operation rte_eth_dev_set_link_down failed for sub_device %d"
264 : : " with error %d", i, ret);
265 : 0 : fs_unlock(dev, 0);
266 : 0 : return ret;
267 : : }
268 : : }
269 : 0 : fs_unlock(dev, 0);
270 : 0 : return 0;
271 : : }
272 : :
273 : : static int
274 : 0 : fs_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
275 : : {
276 : : struct sub_device *sdev;
277 : : uint8_t i;
278 : : int ret;
279 : : int err = 0;
280 : : bool failure = true;
281 : :
282 : 0 : ret = fs_lock(dev, 0);
283 [ # # ]: 0 : if (ret != 0)
284 : : return ret;
285 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
286 [ # # ]: 0 : uint16_t port_id = ETH(sdev)->data->port_id;
287 : :
288 : 0 : ret = rte_eth_dev_rx_queue_stop(port_id, rx_queue_id);
289 : : ret = fs_err(sdev, ret);
290 [ # # ]: 0 : if (ret) {
291 : 0 : ERROR("Rx queue stop failed for subdevice %d", i);
292 : : err = ret;
293 : : } else {
294 : : failure = false;
295 : : }
296 : : }
297 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
298 : 0 : fs_unlock(dev, 0);
299 : : /* Return 0 in case of at least one successful queue stop */
300 [ # # ]: 0 : return (failure) ? err : 0;
301 : : }
302 : :
303 : : static int
304 : 0 : fs_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
305 : : {
306 : : struct sub_device *sdev;
307 : : uint8_t i;
308 : : int ret;
309 : :
310 : 0 : ret = fs_lock(dev, 0);
311 [ # # ]: 0 : if (ret != 0)
312 : : return ret;
313 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
314 [ # # ]: 0 : uint16_t port_id = ETH(sdev)->data->port_id;
315 : :
316 : 0 : ret = rte_eth_dev_rx_queue_start(port_id, rx_queue_id);
317 : : ret = fs_err(sdev, ret);
318 [ # # ]: 0 : if (ret) {
319 : 0 : ERROR("Rx queue start failed for subdevice %d", i);
320 : 0 : fs_rx_queue_stop(dev, rx_queue_id);
321 : 0 : fs_unlock(dev, 0);
322 : 0 : return ret;
323 : : }
324 : : }
325 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
326 : 0 : fs_unlock(dev, 0);
327 : 0 : return 0;
328 : : }
329 : :
330 : : static int
331 : 0 : fs_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
332 : : {
333 : : struct sub_device *sdev;
334 : : uint8_t i;
335 : : int ret;
336 : : int err = 0;
337 : : bool failure = true;
338 : :
339 : 0 : ret = fs_lock(dev, 0);
340 [ # # ]: 0 : if (ret != 0)
341 : : return ret;
342 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
343 [ # # ]: 0 : uint16_t port_id = ETH(sdev)->data->port_id;
344 : :
345 : 0 : ret = rte_eth_dev_tx_queue_stop(port_id, tx_queue_id);
346 : : ret = fs_err(sdev, ret);
347 [ # # ]: 0 : if (ret) {
348 : 0 : ERROR("Tx queue stop failed for subdevice %d", i);
349 : : err = ret;
350 : : } else {
351 : : failure = false;
352 : : }
353 : : }
354 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
355 : 0 : fs_unlock(dev, 0);
356 : : /* Return 0 in case of at least one successful queue stop */
357 [ # # ]: 0 : return (failure) ? err : 0;
358 : : }
359 : :
360 : : static int
361 : 0 : fs_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
362 : : {
363 : : struct sub_device *sdev;
364 : : uint8_t i;
365 : : int ret;
366 : :
367 : 0 : ret = fs_lock(dev, 0);
368 [ # # ]: 0 : if (ret != 0)
369 : : return ret;
370 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
371 [ # # ]: 0 : uint16_t port_id = ETH(sdev)->data->port_id;
372 : :
373 : 0 : ret = rte_eth_dev_tx_queue_start(port_id, tx_queue_id);
374 : : ret = fs_err(sdev, ret);
375 [ # # ]: 0 : if (ret) {
376 : 0 : ERROR("Tx queue start failed for subdevice %d", i);
377 : 0 : fs_tx_queue_stop(dev, tx_queue_id);
378 : 0 : fs_unlock(dev, 0);
379 : 0 : return ret;
380 : : }
381 : : }
382 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
383 : 0 : fs_unlock(dev, 0);
384 : 0 : return 0;
385 : : }
386 : :
387 : : static void
388 : 0 : fs_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
389 : : {
390 : : struct sub_device *sdev;
391 : : uint8_t i;
392 : 0 : struct rxq *rxq = dev->data->rx_queues[qid];
393 : :
394 [ # # ]: 0 : if (rxq == NULL)
395 : : return;
396 [ # # ]: 0 : if (fs_lock(dev, 0) != 0)
397 : : return;
398 [ # # ]: 0 : if (rxq->event_fd >= 0)
399 : 0 : close(rxq->event_fd);
400 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
401 [ # # # # ]: 0 : if (ETH(sdev)->data->rx_queues != NULL &&
402 [ # # ]: 0 : ETH(sdev)->data->rx_queues[rxq->qid] != NULL)
403 : 0 : SUBOPS(sdev, rx_queue_release)(ETH(sdev), rxq->qid);
404 : : }
405 : 0 : dev->data->rx_queues[rxq->qid] = NULL;
406 : 0 : rte_free(rxq);
407 : 0 : fs_unlock(dev, 0);
408 : : }
409 : :
410 : : static int
411 : 0 : fs_rx_queue_setup(struct rte_eth_dev *dev,
412 : : uint16_t rx_queue_id,
413 : : uint16_t nb_rx_desc,
414 : : unsigned int socket_id,
415 : : const struct rte_eth_rxconf *rx_conf,
416 : : struct rte_mempool *mb_pool)
417 : : {
418 : : struct sub_device *sdev;
419 : : struct rxq *rxq;
420 : : uint8_t i;
421 : : int ret;
422 : :
423 : 0 : ret = fs_lock(dev, 0);
424 [ # # ]: 0 : if (ret != 0)
425 : : return ret;
426 [ # # ]: 0 : if (rx_conf->rx_deferred_start) {
427 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
428 [ # # # # ]: 0 : if (SUBOPS(sdev, rx_queue_start) == NULL) {
429 : 0 : ERROR("Rx queue deferred start is not "
430 : : "supported for subdevice %d", i);
431 : 0 : fs_unlock(dev, 0);
432 : 0 : return -EINVAL;
433 : : }
434 : : }
435 : : }
436 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
437 [ # # ]: 0 : if (rxq != NULL) {
438 : 0 : fs_rx_queue_release(dev, rx_queue_id);
439 : 0 : dev->data->rx_queues[rx_queue_id] = NULL;
440 : : }
441 : 0 : rxq = rte_zmalloc("ethdev RX queue",
442 : 0 : sizeof(*rxq) + sizeof(*rxq->refcnt) * PRIV(dev)->subs_tail,
443 : : RTE_CACHE_LINE_SIZE);
444 [ # # ]: 0 : if (rxq == NULL) {
445 : 0 : fs_unlock(dev, 0);
446 : 0 : return -ENOMEM;
447 : : }
448 : :
449 : 0 : rxq->qid = rx_queue_id;
450 : 0 : rxq->socket_id = socket_id;
451 : 0 : rxq->info.mp = mb_pool;
452 : 0 : rxq->info.conf = *rx_conf;
453 : 0 : rxq->info.nb_desc = nb_rx_desc;
454 : 0 : rxq->priv = PRIV(dev);
455 : 0 : rxq->sdev = PRIV(dev)->subs;
456 : : #ifdef RTE_EXEC_ENV_LINUX
457 : 0 : rxq->event_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
458 [ # # ]: 0 : if (rxq->event_fd < 0) {
459 : 0 : ERROR("Failed to create an eventfd: %s", strerror(errno));
460 : 0 : fs_unlock(dev, 0);
461 : 0 : return -errno;
462 : : }
463 : : #else
464 : : rxq->event_fd = -1;
465 : : #endif
466 : 0 : dev->data->rx_queues[rx_queue_id] = rxq;
467 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
468 : 0 : ret = rte_eth_rx_queue_setup(PORT_ID(sdev),
469 : : rx_queue_id,
470 : : nb_rx_desc, socket_id,
471 : : rx_conf, mb_pool);
472 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
473 : 0 : ERROR("RX queue setup failed for sub_device %d", i);
474 : 0 : goto free_rxq;
475 : : }
476 : : }
477 : 0 : fs_unlock(dev, 0);
478 : 0 : return 0;
479 : : free_rxq:
480 : 0 : fs_rx_queue_release(dev, rx_queue_id);
481 : 0 : fs_unlock(dev, 0);
482 : 0 : return ret;
483 : : }
484 : :
485 : : static int
486 : 0 : fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
487 : : {
488 : : struct rxq *rxq;
489 : : struct sub_device *sdev;
490 : : uint8_t i;
491 : : int ret;
492 : : int rc = 0;
493 : :
494 : 0 : ret = fs_lock(dev, 0);
495 [ # # ]: 0 : if (ret != 0)
496 : : return ret;
497 [ # # ]: 0 : if (idx >= dev->data->nb_rx_queues) {
498 : : rc = -EINVAL;
499 : 0 : goto unlock;
500 : : }
501 : 0 : rxq = dev->data->rx_queues[idx];
502 [ # # # # ]: 0 : if (rxq == NULL || rxq->event_fd <= 0) {
503 : : rc = -EINVAL;
504 : 0 : goto unlock;
505 : : }
506 : : /* Fail if proxy service is nor running. */
507 [ # # ]: 0 : if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
508 : 0 : ERROR("failsafe interrupt services are not running");
509 : : rc = -EAGAIN;
510 : 0 : goto unlock;
511 : : }
512 : 0 : rxq->enable_events = 1;
513 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
514 : 0 : ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
515 : : ret = fs_err(sdev, ret);
516 [ # # ]: 0 : if (ret)
517 : : rc = ret;
518 : : }
519 : 0 : unlock:
520 : 0 : fs_unlock(dev, 0);
521 [ # # ]: 0 : if (rc)
522 : 0 : rte_errno = -rc;
523 : : return rc;
524 : : }
525 : :
526 : : static int
527 : 0 : fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
528 : : {
529 : : struct rxq *rxq;
530 : : struct sub_device *sdev;
531 : : uint64_t u64;
532 : : uint8_t i;
533 : : int rc = 0;
534 : : int ret;
535 : :
536 : 0 : ret = fs_lock(dev, 0);
537 [ # # ]: 0 : if (ret != 0)
538 : : return ret;
539 [ # # ]: 0 : if (idx >= dev->data->nb_rx_queues) {
540 : : rc = -EINVAL;
541 : 0 : goto unlock;
542 : : }
543 : 0 : rxq = dev->data->rx_queues[idx];
544 [ # # # # ]: 0 : if (rxq == NULL || rxq->event_fd <= 0) {
545 : : rc = -EINVAL;
546 : 0 : goto unlock;
547 : : }
548 : 0 : rxq->enable_events = 0;
549 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
550 : 0 : ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
551 : : ret = fs_err(sdev, ret);
552 [ # # ]: 0 : if (ret)
553 : : rc = ret;
554 : : }
555 : : /* Clear pending events */
556 [ # # ]: 0 : while (read(rxq->event_fd, &u64, sizeof(uint64_t)) > 0)
557 : : ;
558 : 0 : unlock:
559 : 0 : fs_unlock(dev, 0);
560 [ # # ]: 0 : if (rc)
561 : 0 : rte_errno = -rc;
562 : : return rc;
563 : : }
564 : :
565 : : static void
566 : 0 : fs_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
567 : : {
568 : : struct sub_device *sdev;
569 : : uint8_t i;
570 : 0 : struct txq *txq = dev->data->tx_queues[qid];
571 : :
572 [ # # ]: 0 : if (txq == NULL)
573 : : return;
574 [ # # ]: 0 : if (fs_lock(dev, 0) != 0)
575 : : return;
576 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
577 [ # # # # ]: 0 : if (ETH(sdev)->data->tx_queues != NULL &&
578 [ # # ]: 0 : ETH(sdev)->data->tx_queues[txq->qid] != NULL)
579 : 0 : SUBOPS(sdev, tx_queue_release)(ETH(sdev), txq->qid);
580 : : }
581 : 0 : dev->data->tx_queues[txq->qid] = NULL;
582 : 0 : rte_free(txq);
583 : 0 : fs_unlock(dev, 0);
584 : : }
585 : :
586 : : static int
587 : 0 : fs_tx_queue_setup(struct rte_eth_dev *dev,
588 : : uint16_t tx_queue_id,
589 : : uint16_t nb_tx_desc,
590 : : unsigned int socket_id,
591 : : const struct rte_eth_txconf *tx_conf)
592 : : {
593 : : struct sub_device *sdev;
594 : : struct txq *txq;
595 : : uint8_t i;
596 : : int ret;
597 : :
598 : 0 : ret = fs_lock(dev, 0);
599 [ # # ]: 0 : if (ret != 0)
600 : : return ret;
601 [ # # ]: 0 : if (tx_conf->tx_deferred_start) {
602 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
603 [ # # # # ]: 0 : if (SUBOPS(sdev, tx_queue_start) == NULL) {
604 : 0 : ERROR("Tx queue deferred start is not "
605 : : "supported for subdevice %d", i);
606 : 0 : fs_unlock(dev, 0);
607 : 0 : return -EINVAL;
608 : : }
609 : : }
610 : : }
611 : 0 : txq = dev->data->tx_queues[tx_queue_id];
612 [ # # ]: 0 : if (txq != NULL) {
613 : 0 : fs_tx_queue_release(dev, tx_queue_id);
614 : 0 : dev->data->tx_queues[tx_queue_id] = NULL;
615 : : }
616 : 0 : txq = rte_zmalloc("ethdev TX queue",
617 : 0 : sizeof(*txq) + sizeof(*txq->refcnt) * PRIV(dev)->subs_tail,
618 : : RTE_CACHE_LINE_SIZE);
619 [ # # ]: 0 : if (txq == NULL) {
620 : 0 : fs_unlock(dev, 0);
621 : 0 : return -ENOMEM;
622 : : }
623 : :
624 : 0 : txq->qid = tx_queue_id;
625 : 0 : txq->socket_id = socket_id;
626 : 0 : txq->info.conf = *tx_conf;
627 : 0 : txq->info.nb_desc = nb_tx_desc;
628 : 0 : txq->priv = PRIV(dev);
629 : 0 : dev->data->tx_queues[tx_queue_id] = txq;
630 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
631 : 0 : ret = rte_eth_tx_queue_setup(PORT_ID(sdev),
632 : : tx_queue_id,
633 : : nb_tx_desc, socket_id,
634 : : tx_conf);
635 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
636 : 0 : ERROR("TX queue setup failed for sub_device %d", i);
637 : 0 : goto free_txq;
638 : : }
639 : : }
640 : 0 : fs_unlock(dev, 0);
641 : 0 : return 0;
642 : : free_txq:
643 : 0 : fs_tx_queue_release(dev, tx_queue_id);
644 : 0 : fs_unlock(dev, 0);
645 : 0 : return ret;
646 : : }
647 : :
648 : : static void
649 : 0 : fs_dev_free_queues(struct rte_eth_dev *dev)
650 : : {
651 : : uint16_t i;
652 : :
653 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
654 : 0 : fs_rx_queue_release(dev, i);
655 : 0 : dev->data->rx_queues[i] = NULL;
656 : : }
657 : 0 : dev->data->nb_rx_queues = 0;
658 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
659 : 0 : fs_tx_queue_release(dev, i);
660 : 0 : dev->data->tx_queues[i] = NULL;
661 : : }
662 : 0 : dev->data->nb_tx_queues = 0;
663 : 0 : }
664 : :
665 : : int
666 : 0 : failsafe_eth_dev_close(struct rte_eth_dev *dev)
667 : : {
668 : : struct sub_device *sdev;
669 : : uint8_t i;
670 : : int err, ret = 0;
671 : :
672 : 0 : ret = fs_lock(dev, 0);
673 [ # # ]: 0 : if (ret != 0)
674 : : return ret;
675 : 0 : failsafe_hotplug_alarm_cancel(dev);
676 [ # # ]: 0 : if (PRIV(dev)->state == DEV_STARTED) {
677 : 0 : ret = dev->dev_ops->dev_stop(dev);
678 [ # # ]: 0 : if (ret != 0) {
679 : 0 : fs_unlock(dev, 0);
680 : 0 : return ret;
681 : : }
682 : : }
683 : 0 : PRIV(dev)->state = DEV_ACTIVE - 1;
684 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
685 : 0 : DEBUG("Closing sub_device %d", i);
686 : 0 : failsafe_eth_dev_unregister_callbacks(sdev);
687 : 0 : err = rte_eth_dev_close(PORT_ID(sdev));
688 [ # # ]: 0 : if (err) {
689 [ # # ]: 0 : ret = ret ? ret : err;
690 : 0 : ERROR("Error while closing sub-device %u",
691 : : PORT_ID(sdev));
692 : : }
693 : 0 : sdev->state = DEV_ACTIVE - 1;
694 : : }
695 : 0 : rte_eth_dev_callback_unregister(RTE_ETH_ALL, RTE_ETH_EVENT_NEW,
696 : : failsafe_eth_new_event_callback, dev);
697 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
698 : 0 : fs_unlock(dev, 0);
699 : 0 : return ret;
700 : : }
701 : 0 : fs_dev_free_queues(dev);
702 : 0 : err = failsafe_eal_uninit(dev);
703 [ # # ]: 0 : if (err) {
704 [ # # ]: 0 : ret = ret ? ret : err;
705 : 0 : ERROR("Error while uninitializing sub-EAL");
706 : : }
707 : 0 : failsafe_args_free(dev);
708 : 0 : rte_free(PRIV(dev)->subs);
709 : 0 : rte_free(PRIV(dev)->mcast_addrs);
710 : : /* mac_addrs must not be freed alone because part of dev_private */
711 : 0 : dev->data->mac_addrs = NULL;
712 : 0 : fs_unlock(dev, 0);
713 : 0 : err = pthread_mutex_destroy(&PRIV(dev)->hotplug_mutex);
714 [ # # ]: 0 : if (err) {
715 [ # # ]: 0 : ret = ret ? ret : err;
716 : 0 : ERROR("Error while destroying hotplug mutex");
717 : : }
718 : : return ret;
719 : : }
720 : :
721 : : static int
722 : 0 : fs_promiscuous_enable(struct rte_eth_dev *dev)
723 : : {
724 : : struct sub_device *sdev;
725 : : uint8_t i;
726 : : int ret = 0;
727 : :
728 : 0 : ret = fs_lock(dev, 0);
729 [ # # ]: 0 : if (ret != 0)
730 : : return ret;
731 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
732 : 0 : ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
733 : : ret = fs_err(sdev, ret);
734 [ # # ]: 0 : if (ret != 0) {
735 : 0 : ERROR("Promiscuous mode enable failed for subdevice %d",
736 : : PORT_ID(sdev));
737 : 0 : break;
738 : : }
739 : : }
740 [ # # ]: 0 : if (ret != 0) {
741 : : /* Rollback in the case of failure */
742 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
743 : 0 : ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
744 : : ret = fs_err(sdev, ret);
745 [ # # ]: 0 : if (ret != 0)
746 : 0 : ERROR("Promiscuous mode disable during rollback failed for subdevice %d",
747 : : PORT_ID(sdev));
748 : : }
749 : : }
750 : 0 : fs_unlock(dev, 0);
751 : :
752 : 0 : return ret;
753 : : }
754 : :
755 : : static int
756 : 0 : fs_promiscuous_disable(struct rte_eth_dev *dev)
757 : : {
758 : : struct sub_device *sdev;
759 : : uint8_t i;
760 : : int ret = 0;
761 : :
762 : 0 : ret = fs_lock(dev, 0);
763 [ # # ]: 0 : if (ret != 0)
764 : : return ret;
765 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
766 : 0 : ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
767 : : ret = fs_err(sdev, ret);
768 [ # # ]: 0 : if (ret != 0) {
769 : 0 : ERROR("Promiscuous mode disable failed for subdevice %d",
770 : : PORT_ID(sdev));
771 : 0 : break;
772 : : }
773 : : }
774 [ # # ]: 0 : if (ret != 0) {
775 : : /* Rollback in the case of failure */
776 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
777 : 0 : ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
778 : : ret = fs_err(sdev, ret);
779 [ # # ]: 0 : if (ret != 0)
780 : 0 : ERROR("Promiscuous mode enable during rollback failed for subdevice %d",
781 : : PORT_ID(sdev));
782 : : }
783 : : }
784 : 0 : fs_unlock(dev, 0);
785 : :
786 : 0 : return ret;
787 : : }
788 : :
789 : : static int
790 : 0 : fs_allmulticast_enable(struct rte_eth_dev *dev)
791 : : {
792 : : struct sub_device *sdev;
793 : : uint8_t i;
794 : : int ret = 0;
795 : :
796 : 0 : ret = fs_lock(dev, 0);
797 [ # # ]: 0 : if (ret != 0)
798 : : return ret;
799 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
800 : 0 : ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
801 : : ret = fs_err(sdev, ret);
802 [ # # ]: 0 : if (ret != 0) {
803 : 0 : ERROR("All-multicast mode enable failed for subdevice %d",
804 : : PORT_ID(sdev));
805 : 0 : break;
806 : : }
807 : : }
808 [ # # ]: 0 : if (ret != 0) {
809 : : /* Rollback in the case of failure */
810 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
811 : 0 : ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
812 : : ret = fs_err(sdev, ret);
813 [ # # ]: 0 : if (ret != 0)
814 : 0 : ERROR("All-multicast mode disable during rollback failed for subdevice %d",
815 : : PORT_ID(sdev));
816 : : }
817 : : }
818 : 0 : fs_unlock(dev, 0);
819 : :
820 : 0 : return ret;
821 : : }
822 : :
823 : : static int
824 : 0 : fs_allmulticast_disable(struct rte_eth_dev *dev)
825 : : {
826 : : struct sub_device *sdev;
827 : : uint8_t i;
828 : : int ret = 0;
829 : :
830 : 0 : ret = fs_lock(dev, 0);
831 [ # # ]: 0 : if (ret != 0)
832 : : return ret;
833 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
834 : 0 : ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
835 : : ret = fs_err(sdev, ret);
836 [ # # ]: 0 : if (ret != 0) {
837 : 0 : ERROR("All-multicast mode disable failed for subdevice %d",
838 : : PORT_ID(sdev));
839 : 0 : break;
840 : : }
841 : : }
842 [ # # ]: 0 : if (ret != 0) {
843 : : /* Rollback in the case of failure */
844 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
845 : 0 : ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
846 : : ret = fs_err(sdev, ret);
847 [ # # ]: 0 : if (ret != 0)
848 : 0 : ERROR("All-multicast mode enable during rollback failed for subdevice %d",
849 : : PORT_ID(sdev));
850 : : }
851 : : }
852 : 0 : fs_unlock(dev, 0);
853 : :
854 : 0 : return ret;
855 : : }
856 : :
857 : : static int
858 : 0 : fs_link_update(struct rte_eth_dev *dev,
859 : : int wait_to_complete)
860 : : {
861 : : struct sub_device *sdev;
862 : : uint8_t i;
863 : : int ret;
864 : :
865 : 0 : ret = fs_lock(dev, 0);
866 [ # # ]: 0 : if (ret != 0)
867 : : return ret;
868 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
869 : 0 : DEBUG("Calling link_update on sub_device %d", i);
870 [ # # ]: 0 : ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
871 [ # # # # : 0 : if (ret && ret != -1 && sdev->remove == 0 &&
# # ]
872 : 0 : rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
873 : 0 : ERROR("Link update failed for sub_device %d with error %d",
874 : : i, ret);
875 : 0 : fs_unlock(dev, 0);
876 : 0 : return ret;
877 : : }
878 : : }
879 [ # # # # ]: 0 : if (TX_SUBDEV(dev)) {
880 : : struct rte_eth_link *l1;
881 : : struct rte_eth_link *l2;
882 : :
883 : 0 : l1 = &dev->data->dev_link;
884 [ # # ]: 0 : l2 = Ð(TX_SUBDEV(dev))->data->dev_link;
885 [ # # ]: 0 : if (memcmp(l1, l2, sizeof(*l1))) {
886 : 0 : *l1 = *l2;
887 : 0 : fs_unlock(dev, 0);
888 : 0 : return 0;
889 : : }
890 : : }
891 : 0 : fs_unlock(dev, 0);
892 : 0 : return -1;
893 : : }
894 : :
895 : : static int
896 : 0 : fs_stats_get(struct rte_eth_dev *dev,
897 : : struct rte_eth_stats *stats,
898 : : struct eth_queue_stats *qstats __rte_unused)
899 : : {
900 : : struct rte_eth_stats backup;
901 : : struct sub_device *sdev;
902 : : uint8_t i;
903 : : int ret;
904 : :
905 : 0 : ret = fs_lock(dev, 0);
906 [ # # ]: 0 : if (ret != 0)
907 : : return ret;
908 : 0 : rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
909 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
910 : 0 : struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
911 : : uint64_t *timestamp = &sdev->stats_snapshot.timestamp;
912 : :
913 : : rte_memcpy(&backup, snapshot, sizeof(backup));
914 : 0 : ret = rte_eth_stats_get(PORT_ID(sdev), snapshot);
915 [ # # ]: 0 : if (ret) {
916 : : if (!fs_err(sdev, ret)) {
917 : : rte_memcpy(snapshot, &backup, sizeof(backup));
918 : 0 : goto inc;
919 : : }
920 : 0 : ERROR("Operation rte_eth_stats_get failed for sub_device %d with error %d",
921 : : i, ret);
922 : 0 : *timestamp = 0;
923 : 0 : fs_unlock(dev, 0);
924 : 0 : return ret;
925 : : }
926 : 0 : *timestamp = rte_rdtsc();
927 : 0 : inc:
928 : 0 : failsafe_stats_increment(stats, snapshot);
929 : : }
930 : 0 : fs_unlock(dev, 0);
931 : 0 : return 0;
932 : : }
933 : :
934 : : static int
935 : 0 : fs_stats_reset(struct rte_eth_dev *dev)
936 : : {
937 : : struct sub_device *sdev;
938 : : uint8_t i;
939 : : int ret;
940 : :
941 : 0 : ret = fs_lock(dev, 0);
942 [ # # ]: 0 : if (ret != 0)
943 : : return ret;
944 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
945 : 0 : ret = rte_eth_stats_reset(PORT_ID(sdev));
946 [ # # ]: 0 : if (ret) {
947 : 0 : if (!fs_err(sdev, ret))
948 : 0 : continue;
949 : :
950 : 0 : ERROR("Operation rte_eth_stats_reset failed for sub_device %d with error %d",
951 : : i, ret);
952 : 0 : fs_unlock(dev, 0);
953 : 0 : return ret;
954 : : }
955 : 0 : memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats));
956 : : }
957 : 0 : memset(&PRIV(dev)->stats_accumulator, 0, sizeof(struct rte_eth_stats));
958 : 0 : fs_unlock(dev, 0);
959 : :
960 : 0 : return 0;
961 : : }
962 : :
963 : : static int
964 : 0 : __fs_xstats_count(struct rte_eth_dev *dev)
965 : : {
966 : : struct sub_device *sdev;
967 : : int count = 0;
968 : : uint8_t i;
969 : : int ret;
970 : :
971 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
972 : 0 : ret = rte_eth_xstats_get_names(PORT_ID(sdev), NULL, 0);
973 [ # # ]: 0 : if (ret < 0)
974 : 0 : return ret;
975 : 0 : count += ret;
976 : : }
977 : :
978 : : return count;
979 : : }
980 : :
981 : : static int
982 : 0 : __fs_xstats_get_names(struct rte_eth_dev *dev,
983 : : struct rte_eth_xstat_name *xstats_names,
984 : : unsigned int limit)
985 : : {
986 : : struct sub_device *sdev;
987 : : unsigned int count = 0;
988 : : uint8_t i;
989 : :
990 : : /* Caller only cares about count */
991 [ # # ]: 0 : if (!xstats_names)
992 : 0 : return __fs_xstats_count(dev);
993 : :
994 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
995 : 0 : struct rte_eth_xstat_name *sub_names = xstats_names + count;
996 : : int j, r;
997 : :
998 [ # # ]: 0 : if (count >= limit)
999 : : break;
1000 : :
1001 : 0 : r = rte_eth_xstats_get_names(PORT_ID(sdev),
1002 : : sub_names, limit - count);
1003 [ # # ]: 0 : if (r < 0)
1004 : 0 : return r;
1005 : :
1006 : : /* add subN_ prefix to names */
1007 [ # # ]: 0 : for (j = 0; j < r; j++) {
1008 : 0 : char *xname = sub_names[j].name;
1009 : : char tmp[RTE_ETH_XSTATS_NAME_SIZE];
1010 : :
1011 [ # # ]: 0 : if ((xname[0] == 't' || xname[0] == 'r') &&
1012 [ # # # # ]: 0 : xname[1] == 'x' && xname[2] == '_')
1013 : 0 : snprintf(tmp, sizeof(tmp), "%.3ssub%u_%s",
1014 : : xname, i, xname + 3);
1015 : : else
1016 : 0 : snprintf(tmp, sizeof(tmp), "sub%u_%s",
1017 : : i, xname);
1018 : :
1019 : : strlcpy(xname, tmp, RTE_ETH_XSTATS_NAME_SIZE);
1020 : : }
1021 : 0 : count += r;
1022 : : }
1023 : 0 : return count;
1024 : : }
1025 : :
1026 : : static int
1027 : 0 : fs_xstats_get_names(struct rte_eth_dev *dev,
1028 : : struct rte_eth_xstat_name *xstats_names,
1029 : : unsigned int limit)
1030 : : {
1031 : : int ret;
1032 : :
1033 : 0 : ret = fs_lock(dev, 0);
1034 [ # # ]: 0 : if (ret != 0)
1035 : : return ret;
1036 : 0 : ret = __fs_xstats_get_names(dev, xstats_names, limit);
1037 : 0 : fs_unlock(dev, 0);
1038 : 0 : return ret;
1039 : : }
1040 : :
1041 : : static int
1042 : 0 : __fs_xstats_get(struct rte_eth_dev *dev,
1043 : : struct rte_eth_xstat *xstats,
1044 : : unsigned int n)
1045 : : {
1046 : : unsigned int count = 0;
1047 : : struct sub_device *sdev;
1048 : : uint8_t i;
1049 : : int j, ret;
1050 : :
1051 : 0 : ret = __fs_xstats_count(dev);
1052 : : /*
1053 : : * if error
1054 : : * or caller did not give enough space
1055 : : * or just querying
1056 : : */
1057 [ # # # # ]: 0 : if (ret < 0 || ret > (int)n || xstats == NULL)
1058 : : return ret;
1059 : :
1060 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1061 : 0 : ret = rte_eth_xstats_get(PORT_ID(sdev), xstats, n);
1062 [ # # ]: 0 : if (ret < 0)
1063 : 0 : return ret;
1064 : :
1065 [ # # ]: 0 : if (ret > (int)n)
1066 : 0 : return n + count;
1067 : :
1068 : : /* add offset to id's from sub-device */
1069 [ # # ]: 0 : for (j = 0; j < ret; j++)
1070 : 0 : xstats[j].id += count;
1071 : :
1072 : 0 : xstats += ret;
1073 : 0 : n -= ret;
1074 : 0 : count += ret;
1075 : : }
1076 : :
1077 : 0 : return count;
1078 : : }
1079 : :
1080 : : static int
1081 : 0 : fs_xstats_get(struct rte_eth_dev *dev,
1082 : : struct rte_eth_xstat *xstats,
1083 : : unsigned int n)
1084 : : {
1085 : : int ret;
1086 : :
1087 : 0 : ret = fs_lock(dev, 0);
1088 [ # # ]: 0 : if (ret != 0)
1089 : : return ret;
1090 : 0 : ret = __fs_xstats_get(dev, xstats, n);
1091 : 0 : fs_unlock(dev, 0);
1092 : :
1093 : 0 : return ret;
1094 : : }
1095 : :
1096 : :
1097 : : static int
1098 : 0 : fs_xstats_reset(struct rte_eth_dev *dev)
1099 : : {
1100 : : struct sub_device *sdev;
1101 : : uint8_t i;
1102 : : int r;
1103 : :
1104 : 0 : r = fs_lock(dev, 0);
1105 [ # # ]: 0 : if (r != 0)
1106 : : return r;
1107 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1108 : 0 : r = rte_eth_xstats_reset(PORT_ID(sdev));
1109 [ # # ]: 0 : if (r < 0)
1110 : : break;
1111 : : }
1112 : 0 : fs_unlock(dev, 0);
1113 : :
1114 : 0 : return r;
1115 : : }
1116 : :
1117 : : static void
1118 : : fs_dev_merge_desc_lim(struct rte_eth_desc_lim *to,
1119 : : const struct rte_eth_desc_lim *from)
1120 : : {
1121 : 0 : to->nb_max = RTE_MIN(to->nb_max, from->nb_max);
1122 : 0 : to->nb_min = RTE_MAX(to->nb_min, from->nb_min);
1123 : 0 : to->nb_align = RTE_MAX(to->nb_align, from->nb_align);
1124 : :
1125 : 0 : to->nb_seg_max = RTE_MIN(to->nb_seg_max, from->nb_seg_max);
1126 : 0 : to->nb_mtu_seg_max = RTE_MIN(to->nb_mtu_seg_max, from->nb_mtu_seg_max);
1127 : : }
1128 : :
1129 : : /*
1130 : : * Merge the information from sub-devices.
1131 : : *
1132 : : * The reported values must be the common subset of all sub devices
1133 : : */
1134 : : static void
1135 : 0 : fs_dev_merge_info(struct rte_eth_dev_info *info,
1136 : : const struct rte_eth_dev_info *sinfo)
1137 : : {
1138 : 0 : info->min_mtu = RTE_MAX(info->min_mtu, sinfo->min_mtu);
1139 : 0 : info->max_mtu = RTE_MIN(info->max_mtu, sinfo->max_mtu);
1140 : 0 : info->max_rx_pktlen = RTE_MIN(info->max_rx_pktlen, sinfo->max_rx_pktlen);
1141 : 0 : info->max_rx_queues = RTE_MIN(info->max_rx_queues, sinfo->max_rx_queues);
1142 : 0 : info->max_tx_queues = RTE_MIN(info->max_tx_queues, sinfo->max_tx_queues);
1143 : 0 : info->max_mac_addrs = RTE_MIN(info->max_mac_addrs, sinfo->max_mac_addrs);
1144 : 0 : info->max_hash_mac_addrs = RTE_MIN(info->max_hash_mac_addrs,
1145 : : sinfo->max_hash_mac_addrs);
1146 : 0 : info->max_vmdq_pools = RTE_MIN(info->max_vmdq_pools, sinfo->max_vmdq_pools);
1147 : 0 : info->max_vfs = RTE_MIN(info->max_vfs, sinfo->max_vfs);
1148 : :
1149 : : fs_dev_merge_desc_lim(&info->rx_desc_lim, &sinfo->rx_desc_lim);
1150 : : fs_dev_merge_desc_lim(&info->tx_desc_lim, &sinfo->tx_desc_lim);
1151 : :
1152 : 0 : info->rx_offload_capa &= sinfo->rx_offload_capa;
1153 : 0 : info->tx_offload_capa &= sinfo->tx_offload_capa;
1154 : 0 : info->rx_queue_offload_capa &= sinfo->rx_queue_offload_capa;
1155 : 0 : info->tx_queue_offload_capa &= sinfo->tx_queue_offload_capa;
1156 : 0 : info->flow_type_rss_offloads &= sinfo->flow_type_rss_offloads;
1157 : :
1158 : : /*
1159 : : * RETA size is a GCD of RETA sizes indicated by sub-devices.
1160 : : * Each of these sizes is a power of 2, so use the lower one.
1161 : : */
1162 : 0 : info->reta_size = RTE_MIN(info->reta_size, sinfo->reta_size);
1163 : :
1164 : 0 : info->hash_key_size = RTE_MIN(info->hash_key_size,
1165 : : sinfo->hash_key_size);
1166 : 0 : }
1167 : :
1168 : : /**
1169 : : * Fail-safe dev_infos_get rules:
1170 : : *
1171 : : * No sub_device:
1172 : : * Numerables:
1173 : : * Use the maximum possible values for any field, so as not
1174 : : * to impede any further configuration effort.
1175 : : * Capabilities:
1176 : : * Limits capabilities to those that are understood by the
1177 : : * fail-safe PMD. This understanding stems from the fail-safe
1178 : : * being capable of verifying that the related capability is
1179 : : * expressed within the device configuration (struct rte_eth_conf).
1180 : : *
1181 : : * At least one probed sub_device:
1182 : : * Numerables:
1183 : : * Uses values from the active probed sub_device
1184 : : * The rationale here is that if any sub_device is less capable
1185 : : * (for example concerning the number of queues) than the active
1186 : : * sub_device, then its subsequent configuration will fail.
1187 : : * It is impossible to foresee this failure when the failing sub_device
1188 : : * is supposed to be plugged-in later on, so the configuration process
1189 : : * is the single point of failure and error reporting.
1190 : : * Capabilities:
1191 : : * Uses a logical AND of RX capabilities among
1192 : : * all sub_devices and the default capabilities.
1193 : : * Uses a logical AND of TX capabilities among
1194 : : * the active probed sub_device and the default capabilities.
1195 : : * Uses a logical AND of device capabilities among
1196 : : * all sub_devices and the default capabilities.
1197 : : *
1198 : : */
1199 : : static int
1200 : 0 : fs_dev_infos_get(struct rte_eth_dev *dev,
1201 : : struct rte_eth_dev_info *infos)
1202 : : {
1203 : : struct sub_device *sdev;
1204 : : uint8_t i;
1205 : : int ret;
1206 : :
1207 : : /* Use maximum upper bounds by default */
1208 : 0 : infos->min_mtu = RTE_ETHER_MIN_MTU;
1209 : 0 : infos->max_mtu = UINT16_MAX;
1210 : 0 : infos->max_rx_pktlen = UINT32_MAX;
1211 : 0 : infos->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
1212 : 0 : infos->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
1213 : 0 : infos->max_mac_addrs = FAILSAFE_MAX_ETHADDR;
1214 : 0 : infos->max_hash_mac_addrs = UINT32_MAX;
1215 : 0 : infos->max_vfs = UINT16_MAX;
1216 : 0 : infos->max_vmdq_pools = UINT16_MAX;
1217 : 0 : infos->reta_size = UINT16_MAX;
1218 : 0 : infos->hash_key_size = UINT8_MAX;
1219 : :
1220 : : /*
1221 : : * Set of capabilities that can be verified upon
1222 : : * configuring a sub-device.
1223 : : */
1224 : 0 : infos->rx_offload_capa =
1225 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1226 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1227 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1228 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1229 : : RTE_ETH_RX_OFFLOAD_TCP_LRO |
1230 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
1231 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1232 : : RTE_ETH_RX_OFFLOAD_MACSEC_STRIP |
1233 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1234 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
1235 : : RTE_ETH_RX_OFFLOAD_SCATTER |
1236 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
1237 : : RTE_ETH_RX_OFFLOAD_SECURITY |
1238 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
1239 : :
1240 : 0 : infos->rx_queue_offload_capa =
1241 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1242 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1243 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1244 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1245 : : RTE_ETH_RX_OFFLOAD_TCP_LRO |
1246 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
1247 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
1248 : : RTE_ETH_RX_OFFLOAD_MACSEC_STRIP |
1249 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1250 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
1251 : : RTE_ETH_RX_OFFLOAD_SCATTER |
1252 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP |
1253 : : RTE_ETH_RX_OFFLOAD_SECURITY |
1254 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
1255 : :
1256 : 0 : infos->tx_offload_capa =
1257 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1258 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE |
1259 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1260 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1261 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1262 : : RTE_ETH_TX_OFFLOAD_TCP_TSO;
1263 : :
1264 : 0 : infos->flow_type_rss_offloads =
1265 : : RTE_ETH_RSS_IP |
1266 : : RTE_ETH_RSS_UDP |
1267 : : RTE_ETH_RSS_TCP;
1268 : 0 : infos->dev_capa =
1269 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
1270 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
1271 : : infos->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
1272 : :
1273 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
1274 : : struct rte_eth_dev_info sub_info;
1275 : :
1276 : 0 : ret = rte_eth_dev_info_get(PORT_ID(sdev), &sub_info);
1277 : : ret = fs_err(sdev, ret);
1278 [ # # ]: 0 : if (ret != 0)
1279 : 0 : return ret;
1280 : :
1281 : 0 : fs_dev_merge_info(infos, &sub_info);
1282 : : }
1283 : :
1284 : : return 0;
1285 : : }
1286 : :
1287 : : static const uint32_t *
1288 : 0 : fs_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1289 : : {
1290 : : struct sub_device *sdev;
1291 : : struct rte_eth_dev *edev;
1292 : : const uint32_t *ret;
1293 : :
1294 [ # # ]: 0 : if (fs_lock(dev, 0) != 0)
1295 : : return NULL;
1296 [ # # # # ]: 0 : sdev = TX_SUBDEV(dev);
1297 : : if (sdev == NULL) {
1298 : : ret = NULL;
1299 : 0 : goto unlock;
1300 : : }
1301 [ # # ]: 0 : edev = ETH(sdev);
1302 : : /* ENOTSUP: counts as no supported ptypes */
1303 [ # # ]: 0 : if (SUBOPS(sdev, dev_supported_ptypes_get) == NULL) {
1304 : : ret = NULL;
1305 : 0 : goto unlock;
1306 : : }
1307 : : /*
1308 : : * The API does not permit to do a clean AND of all ptypes,
1309 : : * It is also incomplete by design and we do not really care
1310 : : * to have a best possible value in this context.
1311 : : * We just return the ptypes of the device of highest
1312 : : * priority, usually the PREFERRED device.
1313 : : */
1314 : 0 : ret = SUBOPS(sdev, dev_supported_ptypes_get)(edev, no_of_elements);
1315 : 0 : unlock:
1316 : 0 : fs_unlock(dev, 0);
1317 : 0 : return ret;
1318 : : }
1319 : :
1320 : : static int
1321 : 0 : fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1322 : : {
1323 : : struct sub_device *sdev;
1324 : : uint8_t i;
1325 : : int ret;
1326 : :
1327 : 0 : ret = fs_lock(dev, 0);
1328 [ # # ]: 0 : if (ret != 0)
1329 : : return ret;
1330 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1331 : 0 : DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
1332 : 0 : ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
1333 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
1334 : 0 : ERROR("Operation rte_eth_dev_set_mtu failed for sub_device %d with error %d",
1335 : : i, ret);
1336 : 0 : fs_unlock(dev, 0);
1337 : 0 : return ret;
1338 : : }
1339 : : }
1340 : 0 : fs_unlock(dev, 0);
1341 : 0 : return 0;
1342 : : }
1343 : :
1344 : : static int
1345 : 0 : fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1346 : : {
1347 : : struct sub_device *sdev;
1348 : : uint8_t i;
1349 : : int ret;
1350 : :
1351 : 0 : ret = fs_lock(dev, 0);
1352 [ # # ]: 0 : if (ret != 0)
1353 : : return ret;
1354 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1355 : 0 : DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
1356 : 0 : ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
1357 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
1358 : 0 : ERROR("Operation rte_eth_dev_vlan_filter failed for sub_device %d"
1359 : : " with error %d", i, ret);
1360 : 0 : fs_unlock(dev, 0);
1361 : 0 : return ret;
1362 : : }
1363 : : }
1364 : 0 : fs_unlock(dev, 0);
1365 : 0 : return 0;
1366 : : }
1367 : :
1368 : : static int
1369 : 0 : fs_flow_ctrl_get(struct rte_eth_dev *dev,
1370 : : struct rte_eth_fc_conf *fc_conf)
1371 : : {
1372 : : struct sub_device *sdev;
1373 : : int ret;
1374 : :
1375 : 0 : ret = fs_lock(dev, 0);
1376 [ # # ]: 0 : if (ret != 0)
1377 : : return ret;
1378 [ # # # # ]: 0 : sdev = TX_SUBDEV(dev);
1379 : : if (sdev == NULL) {
1380 : : ret = 0;
1381 : 0 : goto unlock;
1382 : : }
1383 [ # # # # ]: 0 : if (SUBOPS(sdev, flow_ctrl_get) == NULL) {
1384 : : ret = -ENOTSUP;
1385 : 0 : goto unlock;
1386 : : }
1387 : 0 : ret = SUBOPS(sdev, flow_ctrl_get)(ETH(sdev), fc_conf);
1388 : 0 : unlock:
1389 : 0 : fs_unlock(dev, 0);
1390 : 0 : return ret;
1391 : : }
1392 : :
1393 : : static int
1394 : 0 : fs_flow_ctrl_set(struct rte_eth_dev *dev,
1395 : : struct rte_eth_fc_conf *fc_conf)
1396 : : {
1397 : : struct sub_device *sdev;
1398 : : uint8_t i;
1399 : : int ret;
1400 : :
1401 : 0 : ret = fs_lock(dev, 0);
1402 [ # # ]: 0 : if (ret != 0)
1403 : : return ret;
1404 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1405 : 0 : DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
1406 : 0 : ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
1407 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
1408 : 0 : ERROR("Operation rte_eth_dev_flow_ctrl_set failed for sub_device %d"
1409 : : " with error %d", i, ret);
1410 : 0 : fs_unlock(dev, 0);
1411 : 0 : return ret;
1412 : : }
1413 : : }
1414 : 0 : fs_unlock(dev, 0);
1415 : 0 : return 0;
1416 : : }
1417 : :
1418 : : static void
1419 : 0 : fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1420 : : {
1421 : : struct sub_device *sdev;
1422 : : uint8_t i;
1423 : :
1424 [ # # ]: 0 : if (fs_lock(dev, 0) != 0)
1425 : : return;
1426 : : /* No check: already done within the rte_eth_dev_mac_addr_remove
1427 : : * call for the fail-safe device.
1428 : : */
1429 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
1430 : 0 : rte_eth_dev_mac_addr_remove(PORT_ID(sdev),
1431 : 0 : &dev->data->mac_addrs[index]);
1432 : 0 : PRIV(dev)->mac_addr_pool[index] = 0;
1433 : 0 : fs_unlock(dev, 0);
1434 : : }
1435 : :
1436 : : static int
1437 : 0 : fs_mac_addr_add(struct rte_eth_dev *dev,
1438 : : struct rte_ether_addr *mac_addr,
1439 : : uint32_t index,
1440 : : uint32_t vmdq)
1441 : : {
1442 : : struct sub_device *sdev;
1443 : : int ret;
1444 : : uint8_t i;
1445 : :
1446 : : RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
1447 : 0 : ret = fs_lock(dev, 0);
1448 [ # # ]: 0 : if (ret != 0)
1449 : : return ret;
1450 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1451 : 0 : ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
1452 [ # # ]: 0 : if ((ret = fs_err(sdev, ret))) {
1453 : 0 : ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %"
1454 : : PRIu8 " with error %d", i, ret);
1455 : 0 : fs_unlock(dev, 0);
1456 : 0 : return ret;
1457 : : }
1458 : : }
1459 [ # # ]: 0 : if (index >= PRIV(dev)->nb_mac_addr) {
1460 : 0 : DEBUG("Growing mac_addrs array");
1461 : 0 : PRIV(dev)->nb_mac_addr = index;
1462 : : }
1463 : 0 : PRIV(dev)->mac_addr_pool[index] = vmdq;
1464 : 0 : fs_unlock(dev, 0);
1465 : 0 : return 0;
1466 : : }
1467 : :
1468 : : static int
1469 : 0 : fs_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1470 : : {
1471 : : struct sub_device *sdev;
1472 : : uint8_t i;
1473 : : int ret;
1474 : :
1475 : 0 : ret = fs_lock(dev, 0);
1476 [ # # ]: 0 : if (ret != 0)
1477 : : return ret;
1478 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1479 : 0 : ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
1480 : : ret = fs_err(sdev, ret);
1481 [ # # ]: 0 : if (ret) {
1482 : 0 : ERROR("Operation rte_eth_dev_mac_addr_set failed for sub_device %d with error %d",
1483 : : i, ret);
1484 : 0 : fs_unlock(dev, 0);
1485 : 0 : return ret;
1486 : : }
1487 : : }
1488 : 0 : fs_unlock(dev, 0);
1489 : :
1490 : 0 : return 0;
1491 : : }
1492 : :
1493 : : static int
1494 : 0 : fs_set_mc_addr_list(struct rte_eth_dev *dev,
1495 : : struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1496 : : {
1497 : : struct sub_device *sdev;
1498 : : uint8_t i;
1499 : : int ret;
1500 : : void *mcast_addrs;
1501 : :
1502 : 0 : ret = fs_lock(dev, 0);
1503 [ # # ]: 0 : if (ret != 0)
1504 : : return ret;
1505 : :
1506 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1507 : 0 : ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1508 : : mc_addr_set, nb_mc_addr);
1509 [ # # ]: 0 : if (ret != 0) {
1510 : 0 : ERROR("Operation rte_eth_dev_set_mc_addr_list failed for sub_device %d with error %d",
1511 : : i, ret);
1512 : 0 : goto rollback;
1513 : : }
1514 : : }
1515 : :
1516 : 0 : mcast_addrs = rte_realloc(PRIV(dev)->mcast_addrs,
1517 : : nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]), 0);
1518 [ # # ]: 0 : if (mcast_addrs == NULL && nb_mc_addr > 0) {
1519 : : ret = -ENOMEM;
1520 : 0 : goto rollback;
1521 : : }
1522 : : rte_memcpy(mcast_addrs, mc_addr_set,
1523 : : nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]));
1524 : 0 : PRIV(dev)->nb_mcast_addr = nb_mc_addr;
1525 : 0 : PRIV(dev)->mcast_addrs = mcast_addrs;
1526 : :
1527 : 0 : fs_unlock(dev, 0);
1528 : 0 : return 0;
1529 : :
1530 : 0 : rollback:
1531 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1532 : 0 : int rc = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1533 : 0 : PRIV(dev)->mcast_addrs, PRIV(dev)->nb_mcast_addr);
1534 [ # # ]: 0 : if (rc != 0) {
1535 : 0 : ERROR("Multicast MAC address list rollback for sub_device %d failed with error %d",
1536 : : i, rc);
1537 : : }
1538 : : }
1539 : :
1540 : 0 : fs_unlock(dev, 0);
1541 : 0 : return ret;
1542 : : }
1543 : :
1544 : : static int
1545 : 0 : fs_rss_hash_update(struct rte_eth_dev *dev,
1546 : : struct rte_eth_rss_conf *rss_conf)
1547 : : {
1548 : : struct sub_device *sdev;
1549 : : uint8_t i;
1550 : : int ret;
1551 : :
1552 : 0 : ret = fs_lock(dev, 0);
1553 [ # # ]: 0 : if (ret != 0)
1554 : : return ret;
1555 [ # # ]: 0 : FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1556 : 0 : ret = rte_eth_dev_rss_hash_update(PORT_ID(sdev), rss_conf);
1557 : : ret = fs_err(sdev, ret);
1558 [ # # ]: 0 : if (ret) {
1559 : 0 : ERROR("Operation rte_eth_dev_rss_hash_update"
1560 : : " failed for sub_device %d with error %d",
1561 : : i, ret);
1562 : 0 : fs_unlock(dev, 0);
1563 : 0 : return ret;
1564 : : }
1565 : : }
1566 : 0 : fs_unlock(dev, 0);
1567 : :
1568 : 0 : return 0;
1569 : : }
1570 : :
1571 : : static int
1572 : 0 : fs_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
1573 : : const struct rte_flow_ops **ops)
1574 : : {
1575 : 0 : *ops = &fs_flow_ops;
1576 : 0 : return 0;
1577 : : }
1578 : :
1579 : : const struct eth_dev_ops failsafe_ops = {
1580 : : .dev_configure = fs_dev_configure,
1581 : : .dev_start = fs_dev_start,
1582 : : .dev_stop = fs_dev_stop,
1583 : : .dev_set_link_down = fs_dev_set_link_down,
1584 : : .dev_set_link_up = fs_dev_set_link_up,
1585 : : .dev_close = failsafe_eth_dev_close,
1586 : : .promiscuous_enable = fs_promiscuous_enable,
1587 : : .promiscuous_disable = fs_promiscuous_disable,
1588 : : .allmulticast_enable = fs_allmulticast_enable,
1589 : : .allmulticast_disable = fs_allmulticast_disable,
1590 : : .link_update = fs_link_update,
1591 : : .stats_get = fs_stats_get,
1592 : : .stats_reset = fs_stats_reset,
1593 : : .xstats_get = fs_xstats_get,
1594 : : .xstats_get_names = fs_xstats_get_names,
1595 : : .xstats_reset = fs_xstats_reset,
1596 : : .dev_infos_get = fs_dev_infos_get,
1597 : : .dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
1598 : : .mtu_set = fs_mtu_set,
1599 : : .vlan_filter_set = fs_vlan_filter_set,
1600 : : .rx_queue_start = fs_rx_queue_start,
1601 : : .rx_queue_stop = fs_rx_queue_stop,
1602 : : .tx_queue_start = fs_tx_queue_start,
1603 : : .tx_queue_stop = fs_tx_queue_stop,
1604 : : .rx_queue_setup = fs_rx_queue_setup,
1605 : : .tx_queue_setup = fs_tx_queue_setup,
1606 : : .rx_queue_release = fs_rx_queue_release,
1607 : : .tx_queue_release = fs_tx_queue_release,
1608 : : .rx_queue_intr_enable = fs_rx_intr_enable,
1609 : : .rx_queue_intr_disable = fs_rx_intr_disable,
1610 : : .flow_ctrl_get = fs_flow_ctrl_get,
1611 : : .flow_ctrl_set = fs_flow_ctrl_set,
1612 : : .mac_addr_remove = fs_mac_addr_remove,
1613 : : .mac_addr_add = fs_mac_addr_add,
1614 : : .mac_addr_set = fs_mac_addr_set,
1615 : : .set_mc_addr_list = fs_set_mc_addr_list,
1616 : : .rss_hash_update = fs_rss_hash_update,
1617 : : .flow_ops_get = fs_flow_ops_get,
1618 : : };
|