1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 6WIND S.A.
3 * Copyright 2017 Mellanox Technologies, Ltd
10 #include <rte_debug.h>
11 #include <rte_atomic.h>
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
15 #include <rte_cycles.h>
17 #include "failsafe_private.h"
19 static struct rte_eth_dev_info default_infos = {
20 /* Max possible number of elements */
21 .max_rx_pktlen = UINT32_MAX,
22 .max_rx_queues = RTE_MAX_QUEUES_PER_PORT,
23 .max_tx_queues = RTE_MAX_QUEUES_PER_PORT,
24 .max_mac_addrs = FAILSAFE_MAX_ETHADDR,
25 .max_hash_mac_addrs = UINT32_MAX,
26 .max_vfs = UINT16_MAX,
27 .max_vmdq_pools = UINT16_MAX,
32 .nb_seg_max = UINT16_MAX,
33 .nb_mtu_seg_max = UINT16_MAX,
39 .nb_seg_max = UINT16_MAX,
40 .nb_mtu_seg_max = UINT16_MAX,
43 * Set of capabilities that can be verified upon
44 * configuring a sub-device.
47 DEV_RX_OFFLOAD_VLAN_STRIP |
48 DEV_RX_OFFLOAD_IPV4_CKSUM |
49 DEV_RX_OFFLOAD_UDP_CKSUM |
50 DEV_RX_OFFLOAD_TCP_CKSUM |
51 DEV_RX_OFFLOAD_TCP_LRO |
52 DEV_RX_OFFLOAD_QINQ_STRIP |
53 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
54 DEV_RX_OFFLOAD_MACSEC_STRIP |
55 DEV_RX_OFFLOAD_HEADER_SPLIT |
56 DEV_RX_OFFLOAD_VLAN_FILTER |
57 DEV_RX_OFFLOAD_VLAN_EXTEND |
58 DEV_RX_OFFLOAD_JUMBO_FRAME |
59 DEV_RX_OFFLOAD_CRC_STRIP |
60 DEV_RX_OFFLOAD_SCATTER |
61 DEV_RX_OFFLOAD_TIMESTAMP |
62 DEV_RX_OFFLOAD_SECURITY,
63 .rx_queue_offload_capa =
64 DEV_RX_OFFLOAD_VLAN_STRIP |
65 DEV_RX_OFFLOAD_IPV4_CKSUM |
66 DEV_RX_OFFLOAD_UDP_CKSUM |
67 DEV_RX_OFFLOAD_TCP_CKSUM |
68 DEV_RX_OFFLOAD_TCP_LRO |
69 DEV_RX_OFFLOAD_QINQ_STRIP |
70 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
71 DEV_RX_OFFLOAD_MACSEC_STRIP |
72 DEV_RX_OFFLOAD_HEADER_SPLIT |
73 DEV_RX_OFFLOAD_VLAN_FILTER |
74 DEV_RX_OFFLOAD_VLAN_EXTEND |
75 DEV_RX_OFFLOAD_JUMBO_FRAME |
76 DEV_RX_OFFLOAD_CRC_STRIP |
77 DEV_RX_OFFLOAD_SCATTER |
78 DEV_RX_OFFLOAD_TIMESTAMP |
79 DEV_RX_OFFLOAD_SECURITY,
81 DEV_TX_OFFLOAD_MULTI_SEGS |
82 DEV_TX_OFFLOAD_IPV4_CKSUM |
83 DEV_TX_OFFLOAD_UDP_CKSUM |
84 DEV_TX_OFFLOAD_TCP_CKSUM |
85 DEV_TX_OFFLOAD_TCP_TSO,
86 .flow_type_rss_offloads =
93 fs_dev_configure(struct rte_eth_dev *dev)
95 struct sub_device *sdev;
96 uint64_t supp_tx_offloads;
102 supp_tx_offloads = PRIV(dev)->infos.tx_offload_capa;
103 tx_offloads = dev->data->dev_conf.txmode.offloads;
104 if ((tx_offloads & supp_tx_offloads) != tx_offloads) {
106 ERROR("Some Tx offloads are not supported, "
107 "requested 0x%" PRIx64 " supported 0x%" PRIx64,
108 tx_offloads, supp_tx_offloads);
112 FOREACH_SUBDEV(sdev, i, dev) {
113 int rmv_interrupt = 0;
114 int lsc_interrupt = 0;
117 if (sdev->state != DEV_PROBED &&
118 !(PRIV(dev)->alarm_lock == 0 && sdev->state == DEV_ACTIVE))
121 rmv_interrupt = ETH(sdev)->data->dev_flags &
122 RTE_ETH_DEV_INTR_RMV;
124 DEBUG("Enabling RMV interrupts for sub_device %d", i);
125 dev->data->dev_conf.intr_conf.rmv = 1;
127 DEBUG("sub_device %d does not support RMV event", i);
129 lsc_enabled = dev->data->dev_conf.intr_conf.lsc;
130 lsc_interrupt = lsc_enabled &&
131 (ETH(sdev)->data->dev_flags &
132 RTE_ETH_DEV_INTR_LSC);
134 DEBUG("Enabling LSC interrupts for sub_device %d", i);
135 dev->data->dev_conf.intr_conf.lsc = 1;
136 } else if (lsc_enabled && !lsc_interrupt) {
137 DEBUG("Disabling LSC interrupts for sub_device %d", i);
138 dev->data->dev_conf.intr_conf.lsc = 0;
140 DEBUG("Configuring sub-device %d", i);
141 ret = rte_eth_dev_configure(PORT_ID(sdev),
142 dev->data->nb_rx_queues,
143 dev->data->nb_tx_queues,
144 &dev->data->dev_conf);
146 if (!fs_err(sdev, ret))
148 ERROR("Could not configure sub_device %d", i);
153 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
154 RTE_ETH_EVENT_INTR_RMV,
155 failsafe_eth_rmv_event_callback,
158 WARN("Failed to register RMV callback for sub_device %d",
161 dev->data->dev_conf.intr_conf.rmv = 0;
163 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
164 RTE_ETH_EVENT_INTR_LSC,
165 failsafe_eth_lsc_event_callback,
168 WARN("Failed to register LSC callback for sub_device %d",
171 dev->data->dev_conf.intr_conf.lsc = lsc_enabled;
172 sdev->state = DEV_ACTIVE;
174 if (PRIV(dev)->state < DEV_ACTIVE)
175 PRIV(dev)->state = DEV_ACTIVE;
181 fs_dev_start(struct rte_eth_dev *dev)
183 struct sub_device *sdev;
188 ret = failsafe_rx_intr_install(dev);
193 FOREACH_SUBDEV(sdev, i, dev) {
194 if (sdev->state != DEV_ACTIVE)
196 DEBUG("Starting sub_device %d", i);
197 ret = rte_eth_dev_start(PORT_ID(sdev));
199 if (!fs_err(sdev, ret))
204 ret = failsafe_rx_intr_install_subdevice(sdev);
206 if (!fs_err(sdev, ret))
208 rte_eth_dev_stop(PORT_ID(sdev));
212 sdev->state = DEV_STARTED;
214 if (PRIV(dev)->state < DEV_STARTED)
215 PRIV(dev)->state = DEV_STARTED;
216 fs_switch_dev(dev, NULL);
222 fs_dev_stop(struct rte_eth_dev *dev)
224 struct sub_device *sdev;
228 PRIV(dev)->state = DEV_STARTED - 1;
229 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
230 rte_eth_dev_stop(PORT_ID(sdev));
231 failsafe_rx_intr_uninstall_subdevice(sdev);
232 sdev->state = DEV_STARTED - 1;
234 failsafe_rx_intr_uninstall(dev);
239 fs_dev_set_link_up(struct rte_eth_dev *dev)
241 struct sub_device *sdev;
246 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
247 DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
248 ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
249 if ((ret = fs_err(sdev, ret))) {
250 ERROR("Operation rte_eth_dev_set_link_up failed for sub_device %d"
251 " with error %d", i, ret);
261 fs_dev_set_link_down(struct rte_eth_dev *dev)
263 struct sub_device *sdev;
268 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
269 DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
270 ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
271 if ((ret = fs_err(sdev, ret))) {
272 ERROR("Operation rte_eth_dev_set_link_down failed for sub_device %d"
273 " with error %d", i, ret);
282 static void fs_dev_free_queues(struct rte_eth_dev *dev);
284 fs_dev_close(struct rte_eth_dev *dev)
286 struct sub_device *sdev;
290 failsafe_hotplug_alarm_cancel(dev);
291 if (PRIV(dev)->state == DEV_STARTED)
292 dev->dev_ops->dev_stop(dev);
293 PRIV(dev)->state = DEV_ACTIVE - 1;
294 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
295 DEBUG("Closing sub_device %d", i);
296 rte_eth_dev_close(PORT_ID(sdev));
297 sdev->state = DEV_ACTIVE - 1;
299 fs_dev_free_queues(dev);
304 fs_rxq_offloads_valid(struct rte_eth_dev *dev, uint64_t offloads)
306 uint64_t port_offloads;
307 uint64_t queue_supp_offloads;
308 uint64_t port_supp_offloads;
310 port_offloads = dev->data->dev_conf.rxmode.offloads;
311 queue_supp_offloads = PRIV(dev)->infos.rx_queue_offload_capa;
312 port_supp_offloads = PRIV(dev)->infos.rx_offload_capa;
313 if ((offloads & (queue_supp_offloads | port_supp_offloads)) !=
316 /* Verify we have no conflict with port offloads */
317 if ((port_offloads ^ offloads) & port_supp_offloads)
323 fs_rx_queue_release(void *queue)
325 struct rte_eth_dev *dev;
326 struct sub_device *sdev;
333 dev = rxq->priv->dev;
335 if (rxq->event_fd > 0)
336 close(rxq->event_fd);
337 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
338 SUBOPS(sdev, rx_queue_release)
339 (ETH(sdev)->data->rx_queues[rxq->qid]);
340 dev->data->rx_queues[rxq->qid] = NULL;
346 fs_rx_queue_setup(struct rte_eth_dev *dev,
347 uint16_t rx_queue_id,
349 unsigned int socket_id,
350 const struct rte_eth_rxconf *rx_conf,
351 struct rte_mempool *mb_pool)
354 * FIXME: Add a proper interface in rte_eal_interrupts for
355 * allocating eventfd as an interrupt vector.
356 * For the time being, fake as if we are using MSIX interrupts,
357 * this will cause rte_intr_efd_enable to allocate an eventfd for us.
359 struct rte_intr_handle intr_handle = {
360 .type = RTE_INTR_HANDLE_VFIO_MSIX,
363 struct sub_device *sdev;
369 rxq = dev->data->rx_queues[rx_queue_id];
371 fs_rx_queue_release(rxq);
372 dev->data->rx_queues[rx_queue_id] = NULL;
374 /* Verify application offloads are valid for our port and queue. */
375 if (fs_rxq_offloads_valid(dev, rx_conf->offloads) == false) {
377 ERROR("Rx queue offloads 0x%" PRIx64
378 " don't match port offloads 0x%" PRIx64
379 " or supported offloads 0x%" PRIx64,
381 dev->data->dev_conf.rxmode.offloads,
382 PRIV(dev)->infos.rx_offload_capa |
383 PRIV(dev)->infos.rx_queue_offload_capa);
387 rxq = rte_zmalloc(NULL,
389 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
390 RTE_CACHE_LINE_SIZE);
395 FOREACH_SUBDEV(sdev, i, dev)
396 rte_atomic64_init(&rxq->refcnt[i]);
397 rxq->qid = rx_queue_id;
398 rxq->socket_id = socket_id;
399 rxq->info.mp = mb_pool;
400 rxq->info.conf = *rx_conf;
401 rxq->info.nb_desc = nb_rx_desc;
402 rxq->priv = PRIV(dev);
403 rxq->sdev = PRIV(dev)->subs;
404 ret = rte_intr_efd_enable(&intr_handle, 1);
409 rxq->event_fd = intr_handle.efds[0];
410 dev->data->rx_queues[rx_queue_id] = rxq;
411 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
412 ret = rte_eth_rx_queue_setup(PORT_ID(sdev),
414 nb_rx_desc, socket_id,
416 if ((ret = fs_err(sdev, ret))) {
417 ERROR("RX queue setup failed for sub_device %d", i);
424 fs_rx_queue_release(rxq);
430 fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
433 struct sub_device *sdev;
439 if (idx >= dev->data->nb_rx_queues) {
443 rxq = dev->data->rx_queues[idx];
444 if (rxq == NULL || rxq->event_fd <= 0) {
448 /* Fail if proxy service is nor running. */
449 if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
450 ERROR("failsafe interrupt services are not running");
454 rxq->enable_events = 1;
455 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
456 ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
457 ret = fs_err(sdev, ret);
469 fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
472 struct sub_device *sdev;
479 if (idx >= dev->data->nb_rx_queues) {
483 rxq = dev->data->rx_queues[idx];
484 if (rxq == NULL || rxq->event_fd <= 0) {
488 rxq->enable_events = 0;
489 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
490 ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
491 ret = fs_err(sdev, ret);
495 /* Clear pending events */
496 while (read(rxq->event_fd, &u64, sizeof(uint64_t)) > 0)
506 fs_txq_offloads_valid(struct rte_eth_dev *dev, uint64_t offloads)
508 uint64_t port_offloads;
509 uint64_t queue_supp_offloads;
510 uint64_t port_supp_offloads;
512 port_offloads = dev->data->dev_conf.txmode.offloads;
513 queue_supp_offloads = PRIV(dev)->infos.tx_queue_offload_capa;
514 port_supp_offloads = PRIV(dev)->infos.tx_offload_capa;
515 if ((offloads & (queue_supp_offloads | port_supp_offloads)) !=
518 /* Verify we have no conflict with port offloads */
519 if ((port_offloads ^ offloads) & port_supp_offloads)
525 fs_tx_queue_release(void *queue)
527 struct rte_eth_dev *dev;
528 struct sub_device *sdev;
535 dev = txq->priv->dev;
537 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
538 SUBOPS(sdev, tx_queue_release)
539 (ETH(sdev)->data->tx_queues[txq->qid]);
540 dev->data->tx_queues[txq->qid] = NULL;
546 fs_tx_queue_setup(struct rte_eth_dev *dev,
547 uint16_t tx_queue_id,
549 unsigned int socket_id,
550 const struct rte_eth_txconf *tx_conf)
552 struct sub_device *sdev;
558 txq = dev->data->tx_queues[tx_queue_id];
560 fs_tx_queue_release(txq);
561 dev->data->tx_queues[tx_queue_id] = NULL;
564 * Don't verify queue offloads for applications which
567 if (tx_conf != NULL &&
568 (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) &&
569 fs_txq_offloads_valid(dev, tx_conf->offloads) == false) {
571 ERROR("Tx queue offloads 0x%" PRIx64
572 " don't match port offloads 0x%" PRIx64
573 " or supported offloads 0x%" PRIx64,
575 dev->data->dev_conf.txmode.offloads,
576 PRIV(dev)->infos.tx_offload_capa |
577 PRIV(dev)->infos.tx_queue_offload_capa);
581 txq = rte_zmalloc("ethdev TX queue",
583 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
584 RTE_CACHE_LINE_SIZE);
589 FOREACH_SUBDEV(sdev, i, dev)
590 rte_atomic64_init(&txq->refcnt[i]);
591 txq->qid = tx_queue_id;
592 txq->socket_id = socket_id;
593 txq->info.conf = *tx_conf;
594 txq->info.nb_desc = nb_tx_desc;
595 txq->priv = PRIV(dev);
596 dev->data->tx_queues[tx_queue_id] = txq;
597 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
598 ret = rte_eth_tx_queue_setup(PORT_ID(sdev),
600 nb_tx_desc, socket_id,
602 if ((ret = fs_err(sdev, ret))) {
603 ERROR("TX queue setup failed for sub_device %d", i);
610 fs_tx_queue_release(txq);
616 fs_dev_free_queues(struct rte_eth_dev *dev)
620 for (i = 0; i < dev->data->nb_rx_queues; i++) {
621 fs_rx_queue_release(dev->data->rx_queues[i]);
622 dev->data->rx_queues[i] = NULL;
624 dev->data->nb_rx_queues = 0;
625 for (i = 0; i < dev->data->nb_tx_queues; i++) {
626 fs_tx_queue_release(dev->data->tx_queues[i]);
627 dev->data->tx_queues[i] = NULL;
629 dev->data->nb_tx_queues = 0;
633 fs_promiscuous_enable(struct rte_eth_dev *dev)
635 struct sub_device *sdev;
639 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
640 rte_eth_promiscuous_enable(PORT_ID(sdev));
645 fs_promiscuous_disable(struct rte_eth_dev *dev)
647 struct sub_device *sdev;
651 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
652 rte_eth_promiscuous_disable(PORT_ID(sdev));
657 fs_allmulticast_enable(struct rte_eth_dev *dev)
659 struct sub_device *sdev;
663 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
664 rte_eth_allmulticast_enable(PORT_ID(sdev));
669 fs_allmulticast_disable(struct rte_eth_dev *dev)
671 struct sub_device *sdev;
675 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
676 rte_eth_allmulticast_disable(PORT_ID(sdev));
681 fs_link_update(struct rte_eth_dev *dev,
682 int wait_to_complete)
684 struct sub_device *sdev;
689 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
690 DEBUG("Calling link_update on sub_device %d", i);
691 ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
692 if (ret && ret != -1 && sdev->remove == 0 &&
693 rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
694 ERROR("Link update failed for sub_device %d with error %d",
700 if (TX_SUBDEV(dev)) {
701 struct rte_eth_link *l1;
702 struct rte_eth_link *l2;
704 l1 = &dev->data->dev_link;
705 l2 = Ð(TX_SUBDEV(dev))->data->dev_link;
706 if (memcmp(l1, l2, sizeof(*l1))) {
717 fs_stats_get(struct rte_eth_dev *dev,
718 struct rte_eth_stats *stats)
720 struct rte_eth_stats backup;
721 struct sub_device *sdev;
726 rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
727 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
728 struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
729 uint64_t *timestamp = &sdev->stats_snapshot.timestamp;
731 rte_memcpy(&backup, snapshot, sizeof(backup));
732 ret = rte_eth_stats_get(PORT_ID(sdev), snapshot);
734 if (!fs_err(sdev, ret)) {
735 rte_memcpy(snapshot, &backup, sizeof(backup));
738 ERROR("Operation rte_eth_stats_get failed for sub_device %d with error %d",
744 *timestamp = rte_rdtsc();
746 failsafe_stats_increment(stats, snapshot);
753 fs_stats_reset(struct rte_eth_dev *dev)
755 struct sub_device *sdev;
759 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
760 rte_eth_stats_reset(PORT_ID(sdev));
761 memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats));
763 memset(&PRIV(dev)->stats_accumulator, 0, sizeof(struct rte_eth_stats));
768 * Fail-safe dev_infos_get rules:
772 * Use the maximum possible values for any field, so as not
773 * to impede any further configuration effort.
775 * Limits capabilities to those that are understood by the
776 * fail-safe PMD. This understanding stems from the fail-safe
777 * being capable of verifying that the related capability is
778 * expressed within the device configuration (struct rte_eth_conf).
780 * At least one probed sub_device:
782 * Uses values from the active probed sub_device
783 * The rationale here is that if any sub_device is less capable
784 * (for example concerning the number of queues) than the active
785 * sub_device, then its subsequent configuration will fail.
786 * It is impossible to foresee this failure when the failing sub_device
787 * is supposed to be plugged-in later on, so the configuration process
788 * is the single point of failure and error reporting.
790 * Uses a logical AND of RX capabilities among
791 * all sub_devices and the default capabilities.
792 * Uses a logical AND of TX capabilities among
793 * the active probed sub_device and the default capabilities.
797 fs_dev_infos_get(struct rte_eth_dev *dev,
798 struct rte_eth_dev_info *infos)
800 struct sub_device *sdev;
803 sdev = TX_SUBDEV(dev);
805 DEBUG("No probed device, using default infos");
806 rte_memcpy(&PRIV(dev)->infos, &default_infos,
807 sizeof(default_infos));
809 uint64_t rx_offload_capa;
810 uint64_t rxq_offload_capa;
811 uint64_t rss_hf_offload_capa;
813 rx_offload_capa = default_infos.rx_offload_capa;
814 rxq_offload_capa = default_infos.rx_queue_offload_capa;
815 rss_hf_offload_capa = default_infos.flow_type_rss_offloads;
816 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
817 rte_eth_dev_info_get(PORT_ID(sdev),
819 rx_offload_capa &= PRIV(dev)->infos.rx_offload_capa;
821 PRIV(dev)->infos.rx_queue_offload_capa;
822 rss_hf_offload_capa &=
823 PRIV(dev)->infos.flow_type_rss_offloads;
825 sdev = TX_SUBDEV(dev);
826 rte_eth_dev_info_get(PORT_ID(sdev), &PRIV(dev)->infos);
827 PRIV(dev)->infos.rx_offload_capa = rx_offload_capa;
828 PRIV(dev)->infos.rx_queue_offload_capa = rxq_offload_capa;
829 PRIV(dev)->infos.flow_type_rss_offloads = rss_hf_offload_capa;
830 PRIV(dev)->infos.tx_offload_capa &=
831 default_infos.tx_offload_capa;
832 PRIV(dev)->infos.tx_queue_offload_capa &=
833 default_infos.tx_queue_offload_capa;
835 rte_memcpy(infos, &PRIV(dev)->infos, sizeof(*infos));
838 static const uint32_t *
839 fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
841 struct sub_device *sdev;
842 struct rte_eth_dev *edev;
846 sdev = TX_SUBDEV(dev);
852 /* ENOTSUP: counts as no supported ptypes */
853 if (SUBOPS(sdev, dev_supported_ptypes_get) == NULL) {
858 * The API does not permit to do a clean AND of all ptypes,
859 * It is also incomplete by design and we do not really care
860 * to have a best possible value in this context.
861 * We just return the ptypes of the device of highest
862 * priority, usually the PREFERRED device.
864 ret = SUBOPS(sdev, dev_supported_ptypes_get)(edev);
871 fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
873 struct sub_device *sdev;
878 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
879 DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
880 ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
881 if ((ret = fs_err(sdev, ret))) {
882 ERROR("Operation rte_eth_dev_set_mtu failed for sub_device %d with error %d",
893 fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
895 struct sub_device *sdev;
900 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
901 DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
902 ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
903 if ((ret = fs_err(sdev, ret))) {
904 ERROR("Operation rte_eth_dev_vlan_filter failed for sub_device %d"
905 " with error %d", i, ret);
915 fs_flow_ctrl_get(struct rte_eth_dev *dev,
916 struct rte_eth_fc_conf *fc_conf)
918 struct sub_device *sdev;
922 sdev = TX_SUBDEV(dev);
927 if (SUBOPS(sdev, flow_ctrl_get) == NULL) {
931 ret = SUBOPS(sdev, flow_ctrl_get)(ETH(sdev), fc_conf);
938 fs_flow_ctrl_set(struct rte_eth_dev *dev,
939 struct rte_eth_fc_conf *fc_conf)
941 struct sub_device *sdev;
946 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
947 DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
948 ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
949 if ((ret = fs_err(sdev, ret))) {
950 ERROR("Operation rte_eth_dev_flow_ctrl_set failed for sub_device %d"
951 " with error %d", i, ret);
961 fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
963 struct sub_device *sdev;
967 /* No check: already done within the rte_eth_dev_mac_addr_remove
968 * call for the fail-safe device.
970 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
971 rte_eth_dev_mac_addr_remove(PORT_ID(sdev),
972 &dev->data->mac_addrs[index]);
973 PRIV(dev)->mac_addr_pool[index] = 0;
978 fs_mac_addr_add(struct rte_eth_dev *dev,
979 struct ether_addr *mac_addr,
983 struct sub_device *sdev;
987 RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
989 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
990 ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
991 if ((ret = fs_err(sdev, ret))) {
992 ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %"
993 PRIu8 " with error %d", i, ret);
998 if (index >= PRIV(dev)->nb_mac_addr) {
999 DEBUG("Growing mac_addrs array");
1000 PRIV(dev)->nb_mac_addr = index;
1002 PRIV(dev)->mac_addr_pool[index] = vmdq;
1008 fs_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
1010 struct sub_device *sdev;
1015 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1016 ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
1017 ret = fs_err(sdev, ret);
1019 ERROR("Operation rte_eth_dev_mac_addr_set failed for sub_device %d with error %d",
1031 fs_filter_ctrl(struct rte_eth_dev *dev,
1032 enum rte_filter_type type,
1033 enum rte_filter_op op,
1036 struct sub_device *sdev;
1040 if (type == RTE_ETH_FILTER_GENERIC &&
1041 op == RTE_ETH_FILTER_GET) {
1042 *(const void **)arg = &fs_flow_ops;
1046 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1047 DEBUG("Calling rte_eth_dev_filter_ctrl on sub_device %d", i);
1048 ret = rte_eth_dev_filter_ctrl(PORT_ID(sdev), type, op, arg);
1049 if ((ret = fs_err(sdev, ret))) {
1050 ERROR("Operation rte_eth_dev_filter_ctrl failed for sub_device %d"
1051 " with error %d", i, ret);
1060 const struct eth_dev_ops failsafe_ops = {
1061 .dev_configure = fs_dev_configure,
1062 .dev_start = fs_dev_start,
1063 .dev_stop = fs_dev_stop,
1064 .dev_set_link_down = fs_dev_set_link_down,
1065 .dev_set_link_up = fs_dev_set_link_up,
1066 .dev_close = fs_dev_close,
1067 .promiscuous_enable = fs_promiscuous_enable,
1068 .promiscuous_disable = fs_promiscuous_disable,
1069 .allmulticast_enable = fs_allmulticast_enable,
1070 .allmulticast_disable = fs_allmulticast_disable,
1071 .link_update = fs_link_update,
1072 .stats_get = fs_stats_get,
1073 .stats_reset = fs_stats_reset,
1074 .dev_infos_get = fs_dev_infos_get,
1075 .dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
1076 .mtu_set = fs_mtu_set,
1077 .vlan_filter_set = fs_vlan_filter_set,
1078 .rx_queue_setup = fs_rx_queue_setup,
1079 .tx_queue_setup = fs_tx_queue_setup,
1080 .rx_queue_release = fs_rx_queue_release,
1081 .tx_queue_release = fs_tx_queue_release,
1082 .rx_queue_intr_enable = fs_rx_intr_enable,
1083 .rx_queue_intr_disable = fs_rx_intr_disable,
1084 .flow_ctrl_get = fs_flow_ctrl_get,
1085 .flow_ctrl_set = fs_flow_ctrl_set,
1086 .mac_addr_remove = fs_mac_addr_remove,
1087 .mac_addr_add = fs_mac_addr_add,
1088 .mac_addr_set = fs_mac_addr_set,
1089 .filter_ctrl = fs_filter_ctrl,