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