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>
16 #include <rte_ethdev.h>
18 #include "failsafe_private.h"
20 static struct rte_eth_dev_info default_infos = {
21 /* Max possible number of elements */
22 .max_rx_pktlen = UINT32_MAX,
23 .max_rx_queues = RTE_MAX_QUEUES_PER_PORT,
24 .max_tx_queues = RTE_MAX_QUEUES_PER_PORT,
25 .max_mac_addrs = FAILSAFE_MAX_ETHADDR,
26 .max_hash_mac_addrs = UINT32_MAX,
27 .max_vfs = UINT16_MAX,
28 .max_vmdq_pools = UINT16_MAX,
33 .nb_seg_max = UINT16_MAX,
34 .nb_mtu_seg_max = UINT16_MAX,
40 .nb_seg_max = UINT16_MAX,
41 .nb_mtu_seg_max = UINT16_MAX,
44 * Set of capabilities that can be verified upon
45 * configuring a sub-device.
48 DEV_RX_OFFLOAD_VLAN_STRIP |
49 DEV_RX_OFFLOAD_IPV4_CKSUM |
50 DEV_RX_OFFLOAD_UDP_CKSUM |
51 DEV_RX_OFFLOAD_TCP_CKSUM |
52 DEV_RX_OFFLOAD_TCP_LRO |
53 DEV_RX_OFFLOAD_QINQ_STRIP |
54 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
55 DEV_RX_OFFLOAD_MACSEC_STRIP |
56 DEV_RX_OFFLOAD_HEADER_SPLIT |
57 DEV_RX_OFFLOAD_VLAN_FILTER |
58 DEV_RX_OFFLOAD_VLAN_EXTEND |
59 DEV_RX_OFFLOAD_JUMBO_FRAME |
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_SCATTER |
77 DEV_RX_OFFLOAD_TIMESTAMP |
78 DEV_RX_OFFLOAD_SECURITY,
80 DEV_TX_OFFLOAD_MULTI_SEGS |
81 DEV_TX_OFFLOAD_IPV4_CKSUM |
82 DEV_TX_OFFLOAD_UDP_CKSUM |
83 DEV_TX_OFFLOAD_TCP_CKSUM |
84 DEV_TX_OFFLOAD_TCP_TSO,
85 .flow_type_rss_offloads =
90 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
91 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP,
95 fs_dev_configure(struct rte_eth_dev *dev)
97 struct sub_device *sdev;
102 FOREACH_SUBDEV(sdev, i, dev) {
103 int rmv_interrupt = 0;
104 int lsc_interrupt = 0;
107 if (sdev->state != DEV_PROBED &&
108 !(PRIV(dev)->alarm_lock == 0 && sdev->state == DEV_ACTIVE))
111 rmv_interrupt = ETH(sdev)->data->dev_flags &
112 RTE_ETH_DEV_INTR_RMV;
114 DEBUG("Enabling RMV interrupts for sub_device %d", i);
115 dev->data->dev_conf.intr_conf.rmv = 1;
117 DEBUG("sub_device %d does not support RMV event", i);
119 lsc_enabled = dev->data->dev_conf.intr_conf.lsc;
120 lsc_interrupt = lsc_enabled &&
121 (ETH(sdev)->data->dev_flags &
122 RTE_ETH_DEV_INTR_LSC);
124 DEBUG("Enabling LSC interrupts for sub_device %d", i);
125 dev->data->dev_conf.intr_conf.lsc = 1;
126 } else if (lsc_enabled && !lsc_interrupt) {
127 DEBUG("Disabling LSC interrupts for sub_device %d", i);
128 dev->data->dev_conf.intr_conf.lsc = 0;
130 DEBUG("Configuring sub-device %d", i);
131 ret = rte_eth_dev_configure(PORT_ID(sdev),
132 dev->data->nb_rx_queues,
133 dev->data->nb_tx_queues,
134 &dev->data->dev_conf);
136 if (!fs_err(sdev, ret))
138 ERROR("Could not configure sub_device %d", i);
142 if (rmv_interrupt && sdev->rmv_callback == 0) {
143 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
144 RTE_ETH_EVENT_INTR_RMV,
145 failsafe_eth_rmv_event_callback,
148 WARN("Failed to register RMV callback for sub_device %d",
151 sdev->rmv_callback = 1;
153 dev->data->dev_conf.intr_conf.rmv = 0;
154 if (lsc_interrupt && sdev->lsc_callback == 0) {
155 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
156 RTE_ETH_EVENT_INTR_LSC,
157 failsafe_eth_lsc_event_callback,
160 WARN("Failed to register LSC callback for sub_device %d",
163 sdev->lsc_callback = 1;
165 dev->data->dev_conf.intr_conf.lsc = lsc_enabled;
166 sdev->state = DEV_ACTIVE;
168 if (PRIV(dev)->state < DEV_ACTIVE)
169 PRIV(dev)->state = DEV_ACTIVE;
175 fs_set_queues_state_start(struct rte_eth_dev *dev)
181 for (i = 0; i < dev->data->nb_rx_queues; i++) {
182 rxq = dev->data->rx_queues[i];
183 if (rxq != NULL && !rxq->info.conf.rx_deferred_start)
184 dev->data->rx_queue_state[i] =
185 RTE_ETH_QUEUE_STATE_STARTED;
187 for (i = 0; i < dev->data->nb_tx_queues; i++) {
188 txq = dev->data->tx_queues[i];
189 if (txq != NULL && !txq->info.conf.tx_deferred_start)
190 dev->data->tx_queue_state[i] =
191 RTE_ETH_QUEUE_STATE_STARTED;
196 fs_dev_start(struct rte_eth_dev *dev)
198 struct sub_device *sdev;
203 ret = failsafe_rx_intr_install(dev);
208 FOREACH_SUBDEV(sdev, i, dev) {
209 if (sdev->state != DEV_ACTIVE)
211 DEBUG("Starting sub_device %d", i);
212 ret = rte_eth_dev_start(PORT_ID(sdev));
214 if (!fs_err(sdev, ret))
219 ret = failsafe_rx_intr_install_subdevice(sdev);
221 if (!fs_err(sdev, ret))
223 rte_eth_dev_stop(PORT_ID(sdev));
227 sdev->state = DEV_STARTED;
229 if (PRIV(dev)->state < DEV_STARTED) {
230 PRIV(dev)->state = DEV_STARTED;
231 fs_set_queues_state_start(dev);
233 fs_switch_dev(dev, NULL);
239 fs_set_queues_state_stop(struct rte_eth_dev *dev)
243 for (i = 0; i < dev->data->nb_rx_queues; i++)
244 if (dev->data->rx_queues[i] != NULL)
245 dev->data->rx_queue_state[i] =
246 RTE_ETH_QUEUE_STATE_STOPPED;
247 for (i = 0; i < dev->data->nb_tx_queues; i++)
248 if (dev->data->tx_queues[i] != NULL)
249 dev->data->tx_queue_state[i] =
250 RTE_ETH_QUEUE_STATE_STOPPED;
254 fs_dev_stop(struct rte_eth_dev *dev)
256 struct sub_device *sdev;
260 PRIV(dev)->state = DEV_STARTED - 1;
261 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
262 rte_eth_dev_stop(PORT_ID(sdev));
263 failsafe_rx_intr_uninstall_subdevice(sdev);
264 sdev->state = DEV_STARTED - 1;
266 failsafe_rx_intr_uninstall(dev);
267 fs_set_queues_state_stop(dev);
272 fs_dev_set_link_up(struct rte_eth_dev *dev)
274 struct sub_device *sdev;
279 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
280 DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
281 ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
282 if ((ret = fs_err(sdev, ret))) {
283 ERROR("Operation rte_eth_dev_set_link_up failed for sub_device %d"
284 " with error %d", i, ret);
294 fs_dev_set_link_down(struct rte_eth_dev *dev)
296 struct sub_device *sdev;
301 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
302 DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
303 ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
304 if ((ret = fs_err(sdev, ret))) {
305 ERROR("Operation rte_eth_dev_set_link_down failed for sub_device %d"
306 " with error %d", i, ret);
315 static void fs_dev_free_queues(struct rte_eth_dev *dev);
317 fs_dev_close(struct rte_eth_dev *dev)
319 struct sub_device *sdev;
323 failsafe_hotplug_alarm_cancel(dev);
324 if (PRIV(dev)->state == DEV_STARTED)
325 dev->dev_ops->dev_stop(dev);
326 PRIV(dev)->state = DEV_ACTIVE - 1;
327 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
328 DEBUG("Closing sub_device %d", i);
329 failsafe_eth_dev_unregister_callbacks(sdev);
330 rte_eth_dev_close(PORT_ID(sdev));
331 sdev->state = DEV_ACTIVE - 1;
333 fs_dev_free_queues(dev);
338 fs_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
340 struct sub_device *sdev;
347 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
348 uint16_t port_id = ETH(sdev)->data->port_id;
350 ret = rte_eth_dev_rx_queue_stop(port_id, rx_queue_id);
351 ret = fs_err(sdev, ret);
353 ERROR("Rx queue stop failed for subdevice %d", i);
359 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
361 /* Return 0 in case of at least one successful queue stop */
362 return (failure) ? err : 0;
366 fs_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
368 struct sub_device *sdev;
373 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
374 uint16_t port_id = ETH(sdev)->data->port_id;
376 ret = rte_eth_dev_rx_queue_start(port_id, rx_queue_id);
377 ret = fs_err(sdev, ret);
379 ERROR("Rx queue start failed for subdevice %d", i);
380 fs_rx_queue_stop(dev, rx_queue_id);
385 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
391 fs_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
393 struct sub_device *sdev;
400 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
401 uint16_t port_id = ETH(sdev)->data->port_id;
403 ret = rte_eth_dev_tx_queue_stop(port_id, tx_queue_id);
404 ret = fs_err(sdev, ret);
406 ERROR("Tx queue stop failed for subdevice %d", i);
412 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
414 /* Return 0 in case of at least one successful queue stop */
415 return (failure) ? err : 0;
419 fs_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
421 struct sub_device *sdev;
426 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
427 uint16_t port_id = ETH(sdev)->data->port_id;
429 ret = rte_eth_dev_tx_queue_start(port_id, tx_queue_id);
430 ret = fs_err(sdev, ret);
432 ERROR("Tx queue start failed for subdevice %d", i);
433 fs_tx_queue_stop(dev, tx_queue_id);
438 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
444 fs_rx_queue_release(void *queue)
446 struct rte_eth_dev *dev;
447 struct sub_device *sdev;
454 dev = rxq->priv->dev;
456 if (rxq->event_fd > 0)
457 close(rxq->event_fd);
458 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
459 if (ETH(sdev)->data->rx_queues != NULL &&
460 ETH(sdev)->data->rx_queues[rxq->qid] != NULL) {
461 SUBOPS(sdev, rx_queue_release)
462 (ETH(sdev)->data->rx_queues[rxq->qid]);
465 dev->data->rx_queues[rxq->qid] = NULL;
471 fs_rx_queue_setup(struct rte_eth_dev *dev,
472 uint16_t rx_queue_id,
474 unsigned int socket_id,
475 const struct rte_eth_rxconf *rx_conf,
476 struct rte_mempool *mb_pool)
479 * FIXME: Add a proper interface in rte_eal_interrupts for
480 * allocating eventfd as an interrupt vector.
481 * For the time being, fake as if we are using MSIX interrupts,
482 * this will cause rte_intr_efd_enable to allocate an eventfd for us.
484 struct rte_intr_handle intr_handle = {
485 .type = RTE_INTR_HANDLE_VFIO_MSIX,
488 struct sub_device *sdev;
494 if (rx_conf->rx_deferred_start) {
495 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
496 if (SUBOPS(sdev, rx_queue_start) == NULL) {
497 ERROR("Rx queue deferred start is not "
498 "supported for subdevice %d", i);
504 rxq = dev->data->rx_queues[rx_queue_id];
506 fs_rx_queue_release(rxq);
507 dev->data->rx_queues[rx_queue_id] = NULL;
509 rxq = rte_zmalloc(NULL,
511 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
512 RTE_CACHE_LINE_SIZE);
517 FOREACH_SUBDEV(sdev, i, dev)
518 rte_atomic64_init(&rxq->refcnt[i]);
519 rxq->qid = rx_queue_id;
520 rxq->socket_id = socket_id;
521 rxq->info.mp = mb_pool;
522 rxq->info.conf = *rx_conf;
523 rxq->info.nb_desc = nb_rx_desc;
524 rxq->priv = PRIV(dev);
525 rxq->sdev = PRIV(dev)->subs;
526 ret = rte_intr_efd_enable(&intr_handle, 1);
531 rxq->event_fd = intr_handle.efds[0];
532 dev->data->rx_queues[rx_queue_id] = rxq;
533 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
534 ret = rte_eth_rx_queue_setup(PORT_ID(sdev),
536 nb_rx_desc, socket_id,
538 if ((ret = fs_err(sdev, ret))) {
539 ERROR("RX queue setup failed for sub_device %d", i);
546 fs_rx_queue_release(rxq);
552 fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
555 struct sub_device *sdev;
561 if (idx >= dev->data->nb_rx_queues) {
565 rxq = dev->data->rx_queues[idx];
566 if (rxq == NULL || rxq->event_fd <= 0) {
570 /* Fail if proxy service is nor running. */
571 if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
572 ERROR("failsafe interrupt services are not running");
576 rxq->enable_events = 1;
577 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
578 ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
579 ret = fs_err(sdev, ret);
591 fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
594 struct sub_device *sdev;
601 if (idx >= dev->data->nb_rx_queues) {
605 rxq = dev->data->rx_queues[idx];
606 if (rxq == NULL || rxq->event_fd <= 0) {
610 rxq->enable_events = 0;
611 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
612 ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
613 ret = fs_err(sdev, ret);
617 /* Clear pending events */
618 while (read(rxq->event_fd, &u64, sizeof(uint64_t)) > 0)
628 fs_tx_queue_release(void *queue)
630 struct rte_eth_dev *dev;
631 struct sub_device *sdev;
638 dev = txq->priv->dev;
640 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
641 if (ETH(sdev)->data->tx_queues != NULL &&
642 ETH(sdev)->data->tx_queues[txq->qid] != NULL) {
643 SUBOPS(sdev, tx_queue_release)
644 (ETH(sdev)->data->tx_queues[txq->qid]);
647 dev->data->tx_queues[txq->qid] = NULL;
653 fs_tx_queue_setup(struct rte_eth_dev *dev,
654 uint16_t tx_queue_id,
656 unsigned int socket_id,
657 const struct rte_eth_txconf *tx_conf)
659 struct sub_device *sdev;
665 if (tx_conf->tx_deferred_start) {
666 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
667 if (SUBOPS(sdev, tx_queue_start) == NULL) {
668 ERROR("Tx queue deferred start is not "
669 "supported for subdevice %d", i);
675 txq = dev->data->tx_queues[tx_queue_id];
677 fs_tx_queue_release(txq);
678 dev->data->tx_queues[tx_queue_id] = NULL;
680 txq = rte_zmalloc("ethdev TX queue",
682 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
683 RTE_CACHE_LINE_SIZE);
688 FOREACH_SUBDEV(sdev, i, dev)
689 rte_atomic64_init(&txq->refcnt[i]);
690 txq->qid = tx_queue_id;
691 txq->socket_id = socket_id;
692 txq->info.conf = *tx_conf;
693 txq->info.nb_desc = nb_tx_desc;
694 txq->priv = PRIV(dev);
695 dev->data->tx_queues[tx_queue_id] = txq;
696 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
697 ret = rte_eth_tx_queue_setup(PORT_ID(sdev),
699 nb_tx_desc, socket_id,
701 if ((ret = fs_err(sdev, ret))) {
702 ERROR("TX queue setup failed for sub_device %d", i);
709 fs_tx_queue_release(txq);
715 fs_dev_free_queues(struct rte_eth_dev *dev)
719 for (i = 0; i < dev->data->nb_rx_queues; i++) {
720 fs_rx_queue_release(dev->data->rx_queues[i]);
721 dev->data->rx_queues[i] = NULL;
723 dev->data->nb_rx_queues = 0;
724 for (i = 0; i < dev->data->nb_tx_queues; i++) {
725 fs_tx_queue_release(dev->data->tx_queues[i]);
726 dev->data->tx_queues[i] = NULL;
728 dev->data->nb_tx_queues = 0;
732 fs_promiscuous_enable(struct rte_eth_dev *dev)
734 struct sub_device *sdev;
738 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
739 rte_eth_promiscuous_enable(PORT_ID(sdev));
744 fs_promiscuous_disable(struct rte_eth_dev *dev)
746 struct sub_device *sdev;
750 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
751 rte_eth_promiscuous_disable(PORT_ID(sdev));
756 fs_allmulticast_enable(struct rte_eth_dev *dev)
758 struct sub_device *sdev;
762 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
763 rte_eth_allmulticast_enable(PORT_ID(sdev));
768 fs_allmulticast_disable(struct rte_eth_dev *dev)
770 struct sub_device *sdev;
774 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
775 rte_eth_allmulticast_disable(PORT_ID(sdev));
780 fs_link_update(struct rte_eth_dev *dev,
781 int wait_to_complete)
783 struct sub_device *sdev;
788 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
789 DEBUG("Calling link_update on sub_device %d", i);
790 ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
791 if (ret && ret != -1 && sdev->remove == 0 &&
792 rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
793 ERROR("Link update failed for sub_device %d with error %d",
799 if (TX_SUBDEV(dev)) {
800 struct rte_eth_link *l1;
801 struct rte_eth_link *l2;
803 l1 = &dev->data->dev_link;
804 l2 = Ð(TX_SUBDEV(dev))->data->dev_link;
805 if (memcmp(l1, l2, sizeof(*l1))) {
816 fs_stats_get(struct rte_eth_dev *dev,
817 struct rte_eth_stats *stats)
819 struct rte_eth_stats backup;
820 struct sub_device *sdev;
825 rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
826 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
827 struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
828 uint64_t *timestamp = &sdev->stats_snapshot.timestamp;
830 rte_memcpy(&backup, snapshot, sizeof(backup));
831 ret = rte_eth_stats_get(PORT_ID(sdev), snapshot);
833 if (!fs_err(sdev, ret)) {
834 rte_memcpy(snapshot, &backup, sizeof(backup));
837 ERROR("Operation rte_eth_stats_get failed for sub_device %d with error %d",
843 *timestamp = rte_rdtsc();
845 failsafe_stats_increment(stats, snapshot);
852 fs_stats_reset(struct rte_eth_dev *dev)
854 struct sub_device *sdev;
858 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
859 rte_eth_stats_reset(PORT_ID(sdev));
860 memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats));
862 memset(&PRIV(dev)->stats_accumulator, 0, sizeof(struct rte_eth_stats));
867 * Fail-safe dev_infos_get rules:
871 * Use the maximum possible values for any field, so as not
872 * to impede any further configuration effort.
874 * Limits capabilities to those that are understood by the
875 * fail-safe PMD. This understanding stems from the fail-safe
876 * being capable of verifying that the related capability is
877 * expressed within the device configuration (struct rte_eth_conf).
879 * At least one probed sub_device:
881 * Uses values from the active probed sub_device
882 * The rationale here is that if any sub_device is less capable
883 * (for example concerning the number of queues) than the active
884 * sub_device, then its subsequent configuration will fail.
885 * It is impossible to foresee this failure when the failing sub_device
886 * is supposed to be plugged-in later on, so the configuration process
887 * is the single point of failure and error reporting.
889 * Uses a logical AND of RX capabilities among
890 * all sub_devices and the default capabilities.
891 * Uses a logical AND of TX capabilities among
892 * the active probed sub_device and the default capabilities.
893 * Uses a logical AND of device capabilities among
894 * all sub_devices and the default capabilities.
898 fs_dev_infos_get(struct rte_eth_dev *dev,
899 struct rte_eth_dev_info *infos)
901 struct sub_device *sdev;
904 sdev = TX_SUBDEV(dev);
906 DEBUG("No probed device, using default infos");
907 rte_memcpy(&PRIV(dev)->infos, &default_infos,
908 sizeof(default_infos));
910 uint64_t rx_offload_capa;
911 uint64_t rxq_offload_capa;
912 uint64_t rss_hf_offload_capa;
915 rx_offload_capa = default_infos.rx_offload_capa;
916 rxq_offload_capa = default_infos.rx_queue_offload_capa;
917 rss_hf_offload_capa = default_infos.flow_type_rss_offloads;
918 dev_capa = default_infos.dev_capa;
919 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
920 rte_eth_dev_info_get(PORT_ID(sdev),
922 rx_offload_capa &= PRIV(dev)->infos.rx_offload_capa;
924 PRIV(dev)->infos.rx_queue_offload_capa;
925 rss_hf_offload_capa &=
926 PRIV(dev)->infos.flow_type_rss_offloads;
927 dev_capa &= PRIV(dev)->infos.dev_capa;
929 sdev = TX_SUBDEV(dev);
930 rte_eth_dev_info_get(PORT_ID(sdev), &PRIV(dev)->infos);
931 PRIV(dev)->infos.rx_offload_capa = rx_offload_capa;
932 PRIV(dev)->infos.rx_queue_offload_capa = rxq_offload_capa;
933 PRIV(dev)->infos.flow_type_rss_offloads = rss_hf_offload_capa;
934 PRIV(dev)->infos.dev_capa = dev_capa;
935 PRIV(dev)->infos.tx_offload_capa &=
936 default_infos.tx_offload_capa;
937 PRIV(dev)->infos.tx_queue_offload_capa &=
938 default_infos.tx_queue_offload_capa;
940 rte_memcpy(infos, &PRIV(dev)->infos, sizeof(*infos));
943 static const uint32_t *
944 fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
946 struct sub_device *sdev;
947 struct rte_eth_dev *edev;
951 sdev = TX_SUBDEV(dev);
957 /* ENOTSUP: counts as no supported ptypes */
958 if (SUBOPS(sdev, dev_supported_ptypes_get) == NULL) {
963 * The API does not permit to do a clean AND of all ptypes,
964 * It is also incomplete by design and we do not really care
965 * to have a best possible value in this context.
966 * We just return the ptypes of the device of highest
967 * priority, usually the PREFERRED device.
969 ret = SUBOPS(sdev, dev_supported_ptypes_get)(edev);
976 fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
978 struct sub_device *sdev;
983 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
984 DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
985 ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
986 if ((ret = fs_err(sdev, ret))) {
987 ERROR("Operation rte_eth_dev_set_mtu failed for sub_device %d with error %d",
998 fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1000 struct sub_device *sdev;
1005 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1006 DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
1007 ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
1008 if ((ret = fs_err(sdev, ret))) {
1009 ERROR("Operation rte_eth_dev_vlan_filter failed for sub_device %d"
1010 " with error %d", i, ret);
1020 fs_flow_ctrl_get(struct rte_eth_dev *dev,
1021 struct rte_eth_fc_conf *fc_conf)
1023 struct sub_device *sdev;
1027 sdev = TX_SUBDEV(dev);
1032 if (SUBOPS(sdev, flow_ctrl_get) == NULL) {
1036 ret = SUBOPS(sdev, flow_ctrl_get)(ETH(sdev), fc_conf);
1043 fs_flow_ctrl_set(struct rte_eth_dev *dev,
1044 struct rte_eth_fc_conf *fc_conf)
1046 struct sub_device *sdev;
1051 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1052 DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
1053 ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
1054 if ((ret = fs_err(sdev, ret))) {
1055 ERROR("Operation rte_eth_dev_flow_ctrl_set failed for sub_device %d"
1056 " with error %d", i, ret);
1066 fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1068 struct sub_device *sdev;
1072 /* No check: already done within the rte_eth_dev_mac_addr_remove
1073 * call for the fail-safe device.
1075 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
1076 rte_eth_dev_mac_addr_remove(PORT_ID(sdev),
1077 &dev->data->mac_addrs[index]);
1078 PRIV(dev)->mac_addr_pool[index] = 0;
1083 fs_mac_addr_add(struct rte_eth_dev *dev,
1084 struct ether_addr *mac_addr,
1088 struct sub_device *sdev;
1092 RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
1094 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1095 ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
1096 if ((ret = fs_err(sdev, ret))) {
1097 ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %"
1098 PRIu8 " with error %d", i, ret);
1103 if (index >= PRIV(dev)->nb_mac_addr) {
1104 DEBUG("Growing mac_addrs array");
1105 PRIV(dev)->nb_mac_addr = index;
1107 PRIV(dev)->mac_addr_pool[index] = vmdq;
1113 fs_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
1115 struct sub_device *sdev;
1120 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1121 ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
1122 ret = fs_err(sdev, ret);
1124 ERROR("Operation rte_eth_dev_mac_addr_set failed for sub_device %d with error %d",
1136 fs_set_mc_addr_list(struct rte_eth_dev *dev,
1137 struct ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1139 struct sub_device *sdev;
1146 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1147 ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1148 mc_addr_set, nb_mc_addr);
1150 ERROR("Operation rte_eth_dev_set_mc_addr_list failed for sub_device %d with error %d",
1156 mcast_addrs = rte_realloc(PRIV(dev)->mcast_addrs,
1157 nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]), 0);
1158 if (mcast_addrs == NULL && nb_mc_addr > 0) {
1162 rte_memcpy(mcast_addrs, mc_addr_set,
1163 nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]));
1164 PRIV(dev)->nb_mcast_addr = nb_mc_addr;
1165 PRIV(dev)->mcast_addrs = mcast_addrs;
1171 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1172 int rc = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1173 PRIV(dev)->mcast_addrs, PRIV(dev)->nb_mcast_addr);
1175 ERROR("Multicast MAC address list rollback for sub_device %d failed with error %d",
1185 fs_rss_hash_update(struct rte_eth_dev *dev,
1186 struct rte_eth_rss_conf *rss_conf)
1188 struct sub_device *sdev;
1193 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1194 ret = rte_eth_dev_rss_hash_update(PORT_ID(sdev), rss_conf);
1195 ret = fs_err(sdev, ret);
1197 ERROR("Operation rte_eth_dev_rss_hash_update"
1198 " failed for sub_device %d with error %d",
1210 fs_filter_ctrl(struct rte_eth_dev *dev,
1211 enum rte_filter_type type,
1212 enum rte_filter_op op,
1215 struct sub_device *sdev;
1219 if (type == RTE_ETH_FILTER_GENERIC &&
1220 op == RTE_ETH_FILTER_GET) {
1221 *(const void **)arg = &fs_flow_ops;
1225 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1226 DEBUG("Calling rte_eth_dev_filter_ctrl on sub_device %d", i);
1227 ret = rte_eth_dev_filter_ctrl(PORT_ID(sdev), type, op, arg);
1228 if ((ret = fs_err(sdev, ret))) {
1229 ERROR("Operation rte_eth_dev_filter_ctrl failed for sub_device %d"
1230 " with error %d", i, ret);
1239 const struct eth_dev_ops failsafe_ops = {
1240 .dev_configure = fs_dev_configure,
1241 .dev_start = fs_dev_start,
1242 .dev_stop = fs_dev_stop,
1243 .dev_set_link_down = fs_dev_set_link_down,
1244 .dev_set_link_up = fs_dev_set_link_up,
1245 .dev_close = fs_dev_close,
1246 .promiscuous_enable = fs_promiscuous_enable,
1247 .promiscuous_disable = fs_promiscuous_disable,
1248 .allmulticast_enable = fs_allmulticast_enable,
1249 .allmulticast_disable = fs_allmulticast_disable,
1250 .link_update = fs_link_update,
1251 .stats_get = fs_stats_get,
1252 .stats_reset = fs_stats_reset,
1253 .dev_infos_get = fs_dev_infos_get,
1254 .dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
1255 .mtu_set = fs_mtu_set,
1256 .vlan_filter_set = fs_vlan_filter_set,
1257 .rx_queue_start = fs_rx_queue_start,
1258 .rx_queue_stop = fs_rx_queue_stop,
1259 .tx_queue_start = fs_tx_queue_start,
1260 .tx_queue_stop = fs_tx_queue_stop,
1261 .rx_queue_setup = fs_rx_queue_setup,
1262 .tx_queue_setup = fs_tx_queue_setup,
1263 .rx_queue_release = fs_rx_queue_release,
1264 .tx_queue_release = fs_tx_queue_release,
1265 .rx_queue_intr_enable = fs_rx_intr_enable,
1266 .rx_queue_intr_disable = fs_rx_intr_disable,
1267 .flow_ctrl_get = fs_flow_ctrl_get,
1268 .flow_ctrl_set = fs_flow_ctrl_set,
1269 .mac_addr_remove = fs_mac_addr_remove,
1270 .mac_addr_add = fs_mac_addr_add,
1271 .mac_addr_set = fs_mac_addr_set,
1272 .set_mc_addr_list = fs_set_mc_addr_list,
1273 .rss_hash_update = fs_rss_hash_update,
1274 .filter_ctrl = fs_filter_ctrl,