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"
21 fs_dev_configure(struct rte_eth_dev *dev)
23 struct sub_device *sdev;
28 FOREACH_SUBDEV(sdev, i, dev) {
29 int rmv_interrupt = 0;
30 int lsc_interrupt = 0;
33 if (sdev->state != DEV_PROBED &&
34 !(PRIV(dev)->alarm_lock == 0 && sdev->state == DEV_ACTIVE))
37 rmv_interrupt = ETH(sdev)->data->dev_flags &
40 DEBUG("Enabling RMV interrupts for sub_device %d", i);
41 dev->data->dev_conf.intr_conf.rmv = 1;
43 DEBUG("sub_device %d does not support RMV event", i);
45 lsc_enabled = dev->data->dev_conf.intr_conf.lsc;
46 lsc_interrupt = lsc_enabled &&
47 (ETH(sdev)->data->dev_flags &
48 RTE_ETH_DEV_INTR_LSC);
50 DEBUG("Enabling LSC interrupts for sub_device %d", i);
51 dev->data->dev_conf.intr_conf.lsc = 1;
52 } else if (lsc_enabled && !lsc_interrupt) {
53 DEBUG("Disabling LSC interrupts for sub_device %d", i);
54 dev->data->dev_conf.intr_conf.lsc = 0;
56 DEBUG("Configuring sub-device %d", i);
57 ret = rte_eth_dev_configure(PORT_ID(sdev),
58 dev->data->nb_rx_queues,
59 dev->data->nb_tx_queues,
60 &dev->data->dev_conf);
62 if (!fs_err(sdev, ret))
64 ERROR("Could not configure sub_device %d", i);
68 if (rmv_interrupt && sdev->rmv_callback == 0) {
69 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
70 RTE_ETH_EVENT_INTR_RMV,
71 failsafe_eth_rmv_event_callback,
74 WARN("Failed to register RMV callback for sub_device %d",
77 sdev->rmv_callback = 1;
79 dev->data->dev_conf.intr_conf.rmv = 0;
80 if (lsc_interrupt && sdev->lsc_callback == 0) {
81 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
82 RTE_ETH_EVENT_INTR_LSC,
83 failsafe_eth_lsc_event_callback,
86 WARN("Failed to register LSC callback for sub_device %d",
89 sdev->lsc_callback = 1;
91 dev->data->dev_conf.intr_conf.lsc = lsc_enabled;
92 sdev->state = DEV_ACTIVE;
94 if (PRIV(dev)->state < DEV_ACTIVE)
95 PRIV(dev)->state = DEV_ACTIVE;
101 fs_set_queues_state_start(struct rte_eth_dev *dev)
107 for (i = 0; i < dev->data->nb_rx_queues; i++) {
108 rxq = dev->data->rx_queues[i];
109 if (rxq != NULL && !rxq->info.conf.rx_deferred_start)
110 dev->data->rx_queue_state[i] =
111 RTE_ETH_QUEUE_STATE_STARTED;
113 for (i = 0; i < dev->data->nb_tx_queues; i++) {
114 txq = dev->data->tx_queues[i];
115 if (txq != NULL && !txq->info.conf.tx_deferred_start)
116 dev->data->tx_queue_state[i] =
117 RTE_ETH_QUEUE_STATE_STARTED;
122 fs_dev_start(struct rte_eth_dev *dev)
124 struct sub_device *sdev;
129 ret = failsafe_rx_intr_install(dev);
134 FOREACH_SUBDEV(sdev, i, dev) {
135 if (sdev->state != DEV_ACTIVE)
137 DEBUG("Starting sub_device %d", i);
138 ret = rte_eth_dev_start(PORT_ID(sdev));
140 if (!fs_err(sdev, ret))
145 ret = failsafe_rx_intr_install_subdevice(sdev);
147 if (!fs_err(sdev, ret))
149 rte_eth_dev_stop(PORT_ID(sdev));
153 sdev->state = DEV_STARTED;
155 if (PRIV(dev)->state < DEV_STARTED) {
156 PRIV(dev)->state = DEV_STARTED;
157 fs_set_queues_state_start(dev);
159 fs_switch_dev(dev, NULL);
165 fs_set_queues_state_stop(struct rte_eth_dev *dev)
169 for (i = 0; i < dev->data->nb_rx_queues; i++)
170 if (dev->data->rx_queues[i] != NULL)
171 dev->data->rx_queue_state[i] =
172 RTE_ETH_QUEUE_STATE_STOPPED;
173 for (i = 0; i < dev->data->nb_tx_queues; i++)
174 if (dev->data->tx_queues[i] != NULL)
175 dev->data->tx_queue_state[i] =
176 RTE_ETH_QUEUE_STATE_STOPPED;
180 fs_dev_stop(struct rte_eth_dev *dev)
182 struct sub_device *sdev;
186 PRIV(dev)->state = DEV_STARTED - 1;
187 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
188 rte_eth_dev_stop(PORT_ID(sdev));
189 failsafe_rx_intr_uninstall_subdevice(sdev);
190 sdev->state = DEV_STARTED - 1;
192 failsafe_rx_intr_uninstall(dev);
193 fs_set_queues_state_stop(dev);
198 fs_dev_set_link_up(struct rte_eth_dev *dev)
200 struct sub_device *sdev;
205 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
206 DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
207 ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
208 if ((ret = fs_err(sdev, ret))) {
209 ERROR("Operation rte_eth_dev_set_link_up failed for sub_device %d"
210 " with error %d", i, ret);
220 fs_dev_set_link_down(struct rte_eth_dev *dev)
222 struct sub_device *sdev;
227 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
228 DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
229 ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
230 if ((ret = fs_err(sdev, ret))) {
231 ERROR("Operation rte_eth_dev_set_link_down failed for sub_device %d"
232 " with error %d", i, ret);
241 static void fs_dev_free_queues(struct rte_eth_dev *dev);
243 fs_dev_close(struct rte_eth_dev *dev)
245 struct sub_device *sdev;
249 failsafe_hotplug_alarm_cancel(dev);
250 if (PRIV(dev)->state == DEV_STARTED)
251 dev->dev_ops->dev_stop(dev);
252 PRIV(dev)->state = DEV_ACTIVE - 1;
253 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
254 DEBUG("Closing sub_device %d", i);
255 failsafe_eth_dev_unregister_callbacks(sdev);
256 rte_eth_dev_close(PORT_ID(sdev));
257 sdev->state = DEV_ACTIVE - 1;
259 fs_dev_free_queues(dev);
264 fs_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
266 struct sub_device *sdev;
273 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
274 uint16_t port_id = ETH(sdev)->data->port_id;
276 ret = rte_eth_dev_rx_queue_stop(port_id, rx_queue_id);
277 ret = fs_err(sdev, ret);
279 ERROR("Rx queue stop failed for subdevice %d", i);
285 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
287 /* Return 0 in case of at least one successful queue stop */
288 return (failure) ? err : 0;
292 fs_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
294 struct sub_device *sdev;
299 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
300 uint16_t port_id = ETH(sdev)->data->port_id;
302 ret = rte_eth_dev_rx_queue_start(port_id, rx_queue_id);
303 ret = fs_err(sdev, ret);
305 ERROR("Rx queue start failed for subdevice %d", i);
306 fs_rx_queue_stop(dev, rx_queue_id);
311 dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
317 fs_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
319 struct sub_device *sdev;
326 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
327 uint16_t port_id = ETH(sdev)->data->port_id;
329 ret = rte_eth_dev_tx_queue_stop(port_id, tx_queue_id);
330 ret = fs_err(sdev, ret);
332 ERROR("Tx queue stop failed for subdevice %d", i);
338 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
340 /* Return 0 in case of at least one successful queue stop */
341 return (failure) ? err : 0;
345 fs_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
347 struct sub_device *sdev;
352 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
353 uint16_t port_id = ETH(sdev)->data->port_id;
355 ret = rte_eth_dev_tx_queue_start(port_id, tx_queue_id);
356 ret = fs_err(sdev, ret);
358 ERROR("Tx queue start failed for subdevice %d", i);
359 fs_tx_queue_stop(dev, tx_queue_id);
364 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
370 fs_rx_queue_release(void *queue)
372 struct rte_eth_dev *dev;
373 struct sub_device *sdev;
380 dev = &rte_eth_devices[rxq->priv->data->port_id];
382 if (rxq->event_fd > 0)
383 close(rxq->event_fd);
384 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
385 if (ETH(sdev)->data->rx_queues != NULL &&
386 ETH(sdev)->data->rx_queues[rxq->qid] != NULL) {
387 SUBOPS(sdev, rx_queue_release)
388 (ETH(sdev)->data->rx_queues[rxq->qid]);
391 dev->data->rx_queues[rxq->qid] = NULL;
397 fs_rx_queue_setup(struct rte_eth_dev *dev,
398 uint16_t rx_queue_id,
400 unsigned int socket_id,
401 const struct rte_eth_rxconf *rx_conf,
402 struct rte_mempool *mb_pool)
405 * FIXME: Add a proper interface in rte_eal_interrupts for
406 * allocating eventfd as an interrupt vector.
407 * For the time being, fake as if we are using MSIX interrupts,
408 * this will cause rte_intr_efd_enable to allocate an eventfd for us.
410 struct rte_intr_handle intr_handle = {
411 .type = RTE_INTR_HANDLE_VFIO_MSIX,
414 struct sub_device *sdev;
420 if (rx_conf->rx_deferred_start) {
421 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
422 if (SUBOPS(sdev, rx_queue_start) == NULL) {
423 ERROR("Rx queue deferred start is not "
424 "supported for subdevice %d", i);
430 rxq = dev->data->rx_queues[rx_queue_id];
432 fs_rx_queue_release(rxq);
433 dev->data->rx_queues[rx_queue_id] = NULL;
435 rxq = rte_zmalloc(NULL,
437 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
438 RTE_CACHE_LINE_SIZE);
443 FOREACH_SUBDEV(sdev, i, dev)
444 rte_atomic64_init(&rxq->refcnt[i]);
445 rxq->qid = rx_queue_id;
446 rxq->socket_id = socket_id;
447 rxq->info.mp = mb_pool;
448 rxq->info.conf = *rx_conf;
449 rxq->info.nb_desc = nb_rx_desc;
450 rxq->priv = PRIV(dev);
451 rxq->sdev = PRIV(dev)->subs;
452 ret = rte_intr_efd_enable(&intr_handle, 1);
457 rxq->event_fd = intr_handle.efds[0];
458 dev->data->rx_queues[rx_queue_id] = rxq;
459 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
460 ret = rte_eth_rx_queue_setup(PORT_ID(sdev),
462 nb_rx_desc, socket_id,
464 if ((ret = fs_err(sdev, ret))) {
465 ERROR("RX queue setup failed for sub_device %d", i);
472 fs_rx_queue_release(rxq);
478 fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
481 struct sub_device *sdev;
487 if (idx >= dev->data->nb_rx_queues) {
491 rxq = dev->data->rx_queues[idx];
492 if (rxq == NULL || rxq->event_fd <= 0) {
496 /* Fail if proxy service is nor running. */
497 if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
498 ERROR("failsafe interrupt services are not running");
502 rxq->enable_events = 1;
503 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
504 ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
505 ret = fs_err(sdev, ret);
517 fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
520 struct sub_device *sdev;
527 if (idx >= dev->data->nb_rx_queues) {
531 rxq = dev->data->rx_queues[idx];
532 if (rxq == NULL || rxq->event_fd <= 0) {
536 rxq->enable_events = 0;
537 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
538 ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
539 ret = fs_err(sdev, ret);
543 /* Clear pending events */
544 while (read(rxq->event_fd, &u64, sizeof(uint64_t)) > 0)
554 fs_tx_queue_release(void *queue)
556 struct rte_eth_dev *dev;
557 struct sub_device *sdev;
564 dev = &rte_eth_devices[txq->priv->data->port_id];
566 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
567 if (ETH(sdev)->data->tx_queues != NULL &&
568 ETH(sdev)->data->tx_queues[txq->qid] != NULL) {
569 SUBOPS(sdev, tx_queue_release)
570 (ETH(sdev)->data->tx_queues[txq->qid]);
573 dev->data->tx_queues[txq->qid] = NULL;
579 fs_tx_queue_setup(struct rte_eth_dev *dev,
580 uint16_t tx_queue_id,
582 unsigned int socket_id,
583 const struct rte_eth_txconf *tx_conf)
585 struct sub_device *sdev;
591 if (tx_conf->tx_deferred_start) {
592 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
593 if (SUBOPS(sdev, tx_queue_start) == NULL) {
594 ERROR("Tx queue deferred start is not "
595 "supported for subdevice %d", i);
601 txq = dev->data->tx_queues[tx_queue_id];
603 fs_tx_queue_release(txq);
604 dev->data->tx_queues[tx_queue_id] = NULL;
606 txq = rte_zmalloc("ethdev TX queue",
608 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
609 RTE_CACHE_LINE_SIZE);
614 FOREACH_SUBDEV(sdev, i, dev)
615 rte_atomic64_init(&txq->refcnt[i]);
616 txq->qid = tx_queue_id;
617 txq->socket_id = socket_id;
618 txq->info.conf = *tx_conf;
619 txq->info.nb_desc = nb_tx_desc;
620 txq->priv = PRIV(dev);
621 dev->data->tx_queues[tx_queue_id] = txq;
622 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
623 ret = rte_eth_tx_queue_setup(PORT_ID(sdev),
625 nb_tx_desc, socket_id,
627 if ((ret = fs_err(sdev, ret))) {
628 ERROR("TX queue setup failed for sub_device %d", i);
635 fs_tx_queue_release(txq);
641 fs_dev_free_queues(struct rte_eth_dev *dev)
645 for (i = 0; i < dev->data->nb_rx_queues; i++) {
646 fs_rx_queue_release(dev->data->rx_queues[i]);
647 dev->data->rx_queues[i] = NULL;
649 dev->data->nb_rx_queues = 0;
650 for (i = 0; i < dev->data->nb_tx_queues; i++) {
651 fs_tx_queue_release(dev->data->tx_queues[i]);
652 dev->data->tx_queues[i] = NULL;
654 dev->data->nb_tx_queues = 0;
658 fs_promiscuous_enable(struct rte_eth_dev *dev)
660 struct sub_device *sdev;
665 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
666 ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
667 ret = fs_err(sdev, ret);
669 ERROR("Promiscuous mode enable failed for subdevice %d",
675 /* Rollback in the case of failure */
676 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
677 ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
678 ret = fs_err(sdev, ret);
680 ERROR("Promiscuous mode disable during rollback failed for subdevice %d",
690 fs_promiscuous_disable(struct rte_eth_dev *dev)
692 struct sub_device *sdev;
697 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
698 ret = rte_eth_promiscuous_disable(PORT_ID(sdev));
699 ret = fs_err(sdev, ret);
701 ERROR("Promiscuous mode disable failed for subdevice %d",
707 /* Rollback in the case of failure */
708 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
709 ret = rte_eth_promiscuous_enable(PORT_ID(sdev));
710 ret = fs_err(sdev, ret);
712 ERROR("Promiscuous mode enable during rollback failed for subdevice %d",
722 fs_allmulticast_enable(struct rte_eth_dev *dev)
724 struct sub_device *sdev;
729 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
730 ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
731 ret = fs_err(sdev, ret);
733 ERROR("All-multicast mode enable failed for subdevice %d",
739 /* Rollback in the case of failure */
740 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
741 ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
742 ret = fs_err(sdev, ret);
744 ERROR("All-multicast mode disable during rollback failed for subdevice %d",
752 fs_allmulticast_disable(struct rte_eth_dev *dev)
754 struct sub_device *sdev;
759 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
760 ret = rte_eth_allmulticast_disable(PORT_ID(sdev));
761 ret = fs_err(sdev, ret);
763 ERROR("All-multicast mode disable failed for subdevice %d",
769 /* Rollback in the case of failure */
770 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
771 ret = rte_eth_allmulticast_enable(PORT_ID(sdev));
772 ret = fs_err(sdev, ret);
774 ERROR("All-multicast mode enable during rollback failed for subdevice %d",
782 fs_link_update(struct rte_eth_dev *dev,
783 int wait_to_complete)
785 struct sub_device *sdev;
790 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
791 DEBUG("Calling link_update on sub_device %d", i);
792 ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
793 if (ret && ret != -1 && sdev->remove == 0 &&
794 rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
795 ERROR("Link update failed for sub_device %d with error %d",
801 if (TX_SUBDEV(dev)) {
802 struct rte_eth_link *l1;
803 struct rte_eth_link *l2;
805 l1 = &dev->data->dev_link;
806 l2 = Ð(TX_SUBDEV(dev))->data->dev_link;
807 if (memcmp(l1, l2, sizeof(*l1))) {
818 fs_stats_get(struct rte_eth_dev *dev,
819 struct rte_eth_stats *stats)
821 struct rte_eth_stats backup;
822 struct sub_device *sdev;
827 rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
828 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
829 struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
830 uint64_t *timestamp = &sdev->stats_snapshot.timestamp;
832 rte_memcpy(&backup, snapshot, sizeof(backup));
833 ret = rte_eth_stats_get(PORT_ID(sdev), snapshot);
835 if (!fs_err(sdev, ret)) {
836 rte_memcpy(snapshot, &backup, sizeof(backup));
839 ERROR("Operation rte_eth_stats_get failed for sub_device %d with error %d",
845 *timestamp = rte_rdtsc();
847 failsafe_stats_increment(stats, snapshot);
854 fs_stats_reset(struct rte_eth_dev *dev)
856 struct sub_device *sdev;
861 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
862 ret = rte_eth_stats_reset(PORT_ID(sdev));
864 if (!fs_err(sdev, ret))
867 ERROR("Operation rte_eth_stats_reset failed for sub_device %d with error %d",
872 memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats));
874 memset(&PRIV(dev)->stats_accumulator, 0, sizeof(struct rte_eth_stats));
881 fs_dev_merge_desc_lim(struct rte_eth_desc_lim *to,
882 const struct rte_eth_desc_lim *from)
884 to->nb_max = RTE_MIN(to->nb_max, from->nb_max);
885 to->nb_min = RTE_MAX(to->nb_min, from->nb_min);
886 to->nb_align = RTE_MAX(to->nb_align, from->nb_align);
888 to->nb_seg_max = RTE_MIN(to->nb_seg_max, from->nb_seg_max);
889 to->nb_mtu_seg_max = RTE_MIN(to->nb_mtu_seg_max, from->nb_mtu_seg_max);
893 * Merge the information from sub-devices.
895 * The reported values must be the common subset of all sub devices
898 fs_dev_merge_info(struct rte_eth_dev_info *info,
899 const struct rte_eth_dev_info *sinfo)
901 info->max_rx_pktlen = RTE_MIN(info->max_rx_pktlen, sinfo->max_rx_pktlen);
902 info->max_rx_queues = RTE_MIN(info->max_rx_queues, sinfo->max_rx_queues);
903 info->max_tx_queues = RTE_MIN(info->max_tx_queues, sinfo->max_tx_queues);
904 info->max_mac_addrs = RTE_MIN(info->max_mac_addrs, sinfo->max_mac_addrs);
905 info->max_hash_mac_addrs = RTE_MIN(info->max_hash_mac_addrs,
906 sinfo->max_hash_mac_addrs);
907 info->max_vmdq_pools = RTE_MIN(info->max_vmdq_pools, sinfo->max_vmdq_pools);
908 info->max_vfs = RTE_MIN(info->max_vfs, sinfo->max_vfs);
910 fs_dev_merge_desc_lim(&info->rx_desc_lim, &sinfo->rx_desc_lim);
911 fs_dev_merge_desc_lim(&info->tx_desc_lim, &sinfo->tx_desc_lim);
913 info->rx_offload_capa &= sinfo->rx_offload_capa;
914 info->tx_offload_capa &= sinfo->tx_offload_capa;
915 info->rx_queue_offload_capa &= sinfo->rx_queue_offload_capa;
916 info->tx_queue_offload_capa &= sinfo->tx_queue_offload_capa;
917 info->flow_type_rss_offloads &= sinfo->flow_type_rss_offloads;
921 * Fail-safe dev_infos_get rules:
925 * Use the maximum possible values for any field, so as not
926 * to impede any further configuration effort.
928 * Limits capabilities to those that are understood by the
929 * fail-safe PMD. This understanding stems from the fail-safe
930 * being capable of verifying that the related capability is
931 * expressed within the device configuration (struct rte_eth_conf).
933 * At least one probed sub_device:
935 * Uses values from the active probed sub_device
936 * The rationale here is that if any sub_device is less capable
937 * (for example concerning the number of queues) than the active
938 * sub_device, then its subsequent configuration will fail.
939 * It is impossible to foresee this failure when the failing sub_device
940 * is supposed to be plugged-in later on, so the configuration process
941 * is the single point of failure and error reporting.
943 * Uses a logical AND of RX capabilities among
944 * all sub_devices and the default capabilities.
945 * Uses a logical AND of TX capabilities among
946 * the active probed sub_device and the default capabilities.
947 * Uses a logical AND of device capabilities among
948 * all sub_devices and the default capabilities.
952 fs_dev_infos_get(struct rte_eth_dev *dev,
953 struct rte_eth_dev_info *infos)
955 struct sub_device *sdev;
959 /* Use maximum upper bounds by default */
960 infos->max_rx_pktlen = UINT32_MAX;
961 infos->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
962 infos->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
963 infos->max_mac_addrs = FAILSAFE_MAX_ETHADDR;
964 infos->max_hash_mac_addrs = UINT32_MAX;
965 infos->max_vfs = UINT16_MAX;
966 infos->max_vmdq_pools = UINT16_MAX;
969 * Set of capabilities that can be verified upon
970 * configuring a sub-device.
972 infos->rx_offload_capa =
973 DEV_RX_OFFLOAD_VLAN_STRIP |
974 DEV_RX_OFFLOAD_IPV4_CKSUM |
975 DEV_RX_OFFLOAD_UDP_CKSUM |
976 DEV_RX_OFFLOAD_TCP_CKSUM |
977 DEV_RX_OFFLOAD_TCP_LRO |
978 DEV_RX_OFFLOAD_QINQ_STRIP |
979 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
980 DEV_RX_OFFLOAD_MACSEC_STRIP |
981 DEV_RX_OFFLOAD_HEADER_SPLIT |
982 DEV_RX_OFFLOAD_VLAN_FILTER |
983 DEV_RX_OFFLOAD_VLAN_EXTEND |
984 DEV_RX_OFFLOAD_JUMBO_FRAME |
985 DEV_RX_OFFLOAD_SCATTER |
986 DEV_RX_OFFLOAD_TIMESTAMP |
987 DEV_RX_OFFLOAD_SECURITY;
989 infos->rx_queue_offload_capa =
990 DEV_RX_OFFLOAD_VLAN_STRIP |
991 DEV_RX_OFFLOAD_IPV4_CKSUM |
992 DEV_RX_OFFLOAD_UDP_CKSUM |
993 DEV_RX_OFFLOAD_TCP_CKSUM |
994 DEV_RX_OFFLOAD_TCP_LRO |
995 DEV_RX_OFFLOAD_QINQ_STRIP |
996 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
997 DEV_RX_OFFLOAD_MACSEC_STRIP |
998 DEV_RX_OFFLOAD_HEADER_SPLIT |
999 DEV_RX_OFFLOAD_VLAN_FILTER |
1000 DEV_RX_OFFLOAD_VLAN_EXTEND |
1001 DEV_RX_OFFLOAD_JUMBO_FRAME |
1002 DEV_RX_OFFLOAD_SCATTER |
1003 DEV_RX_OFFLOAD_TIMESTAMP |
1004 DEV_RX_OFFLOAD_SECURITY;
1006 infos->tx_offload_capa =
1007 DEV_TX_OFFLOAD_MULTI_SEGS |
1008 DEV_TX_OFFLOAD_MBUF_FAST_FREE |
1009 DEV_TX_OFFLOAD_IPV4_CKSUM |
1010 DEV_TX_OFFLOAD_UDP_CKSUM |
1011 DEV_TX_OFFLOAD_TCP_CKSUM |
1012 DEV_TX_OFFLOAD_TCP_TSO;
1014 infos->flow_type_rss_offloads =
1019 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
1020 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
1022 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
1023 struct rte_eth_dev_info sub_info;
1025 ret = rte_eth_dev_info_get(PORT_ID(sdev), &sub_info);
1026 ret = fs_err(sdev, ret);
1030 fs_dev_merge_info(infos, &sub_info);
1036 static const uint32_t *
1037 fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1039 struct sub_device *sdev;
1040 struct rte_eth_dev *edev;
1041 const uint32_t *ret;
1044 sdev = TX_SUBDEV(dev);
1050 /* ENOTSUP: counts as no supported ptypes */
1051 if (SUBOPS(sdev, dev_supported_ptypes_get) == NULL) {
1056 * The API does not permit to do a clean AND of all ptypes,
1057 * It is also incomplete by design and we do not really care
1058 * to have a best possible value in this context.
1059 * We just return the ptypes of the device of highest
1060 * priority, usually the PREFERRED device.
1062 ret = SUBOPS(sdev, dev_supported_ptypes_get)(edev);
1069 fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1071 struct sub_device *sdev;
1076 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1077 DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
1078 ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
1079 if ((ret = fs_err(sdev, ret))) {
1080 ERROR("Operation rte_eth_dev_set_mtu failed for sub_device %d with error %d",
1091 fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1093 struct sub_device *sdev;
1098 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1099 DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
1100 ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
1101 if ((ret = fs_err(sdev, ret))) {
1102 ERROR("Operation rte_eth_dev_vlan_filter failed for sub_device %d"
1103 " with error %d", i, ret);
1113 fs_flow_ctrl_get(struct rte_eth_dev *dev,
1114 struct rte_eth_fc_conf *fc_conf)
1116 struct sub_device *sdev;
1120 sdev = TX_SUBDEV(dev);
1125 if (SUBOPS(sdev, flow_ctrl_get) == NULL) {
1129 ret = SUBOPS(sdev, flow_ctrl_get)(ETH(sdev), fc_conf);
1136 fs_flow_ctrl_set(struct rte_eth_dev *dev,
1137 struct rte_eth_fc_conf *fc_conf)
1139 struct sub_device *sdev;
1144 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1145 DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
1146 ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
1147 if ((ret = fs_err(sdev, ret))) {
1148 ERROR("Operation rte_eth_dev_flow_ctrl_set failed for sub_device %d"
1149 " with error %d", i, ret);
1159 fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1161 struct sub_device *sdev;
1165 /* No check: already done within the rte_eth_dev_mac_addr_remove
1166 * call for the fail-safe device.
1168 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
1169 rte_eth_dev_mac_addr_remove(PORT_ID(sdev),
1170 &dev->data->mac_addrs[index]);
1171 PRIV(dev)->mac_addr_pool[index] = 0;
1176 fs_mac_addr_add(struct rte_eth_dev *dev,
1177 struct rte_ether_addr *mac_addr,
1181 struct sub_device *sdev;
1185 RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
1187 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1188 ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
1189 if ((ret = fs_err(sdev, ret))) {
1190 ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %"
1191 PRIu8 " with error %d", i, ret);
1196 if (index >= PRIV(dev)->nb_mac_addr) {
1197 DEBUG("Growing mac_addrs array");
1198 PRIV(dev)->nb_mac_addr = index;
1200 PRIV(dev)->mac_addr_pool[index] = vmdq;
1206 fs_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1208 struct sub_device *sdev;
1213 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1214 ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
1215 ret = fs_err(sdev, ret);
1217 ERROR("Operation rte_eth_dev_mac_addr_set failed for sub_device %d with error %d",
1229 fs_set_mc_addr_list(struct rte_eth_dev *dev,
1230 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1232 struct sub_device *sdev;
1239 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1240 ret = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1241 mc_addr_set, nb_mc_addr);
1243 ERROR("Operation rte_eth_dev_set_mc_addr_list failed for sub_device %d with error %d",
1249 mcast_addrs = rte_realloc(PRIV(dev)->mcast_addrs,
1250 nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]), 0);
1251 if (mcast_addrs == NULL && nb_mc_addr > 0) {
1255 rte_memcpy(mcast_addrs, mc_addr_set,
1256 nb_mc_addr * sizeof(PRIV(dev)->mcast_addrs[0]));
1257 PRIV(dev)->nb_mcast_addr = nb_mc_addr;
1258 PRIV(dev)->mcast_addrs = mcast_addrs;
1264 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1265 int rc = rte_eth_dev_set_mc_addr_list(PORT_ID(sdev),
1266 PRIV(dev)->mcast_addrs, PRIV(dev)->nb_mcast_addr);
1268 ERROR("Multicast MAC address list rollback for sub_device %d failed with error %d",
1278 fs_rss_hash_update(struct rte_eth_dev *dev,
1279 struct rte_eth_rss_conf *rss_conf)
1281 struct sub_device *sdev;
1286 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
1287 ret = rte_eth_dev_rss_hash_update(PORT_ID(sdev), rss_conf);
1288 ret = fs_err(sdev, ret);
1290 ERROR("Operation rte_eth_dev_rss_hash_update"
1291 " failed for sub_device %d with error %d",
1303 fs_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
1304 enum rte_filter_type type,
1305 enum rte_filter_op op,
1308 if (type == RTE_ETH_FILTER_GENERIC &&
1309 op == RTE_ETH_FILTER_GET) {
1310 *(const void **)arg = &fs_flow_ops;
1316 const struct eth_dev_ops failsafe_ops = {
1317 .dev_configure = fs_dev_configure,
1318 .dev_start = fs_dev_start,
1319 .dev_stop = fs_dev_stop,
1320 .dev_set_link_down = fs_dev_set_link_down,
1321 .dev_set_link_up = fs_dev_set_link_up,
1322 .dev_close = fs_dev_close,
1323 .promiscuous_enable = fs_promiscuous_enable,
1324 .promiscuous_disable = fs_promiscuous_disable,
1325 .allmulticast_enable = fs_allmulticast_enable,
1326 .allmulticast_disable = fs_allmulticast_disable,
1327 .link_update = fs_link_update,
1328 .stats_get = fs_stats_get,
1329 .stats_reset = fs_stats_reset,
1330 .dev_infos_get = fs_dev_infos_get,
1331 .dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
1332 .mtu_set = fs_mtu_set,
1333 .vlan_filter_set = fs_vlan_filter_set,
1334 .rx_queue_start = fs_rx_queue_start,
1335 .rx_queue_stop = fs_rx_queue_stop,
1336 .tx_queue_start = fs_tx_queue_start,
1337 .tx_queue_stop = fs_tx_queue_stop,
1338 .rx_queue_setup = fs_rx_queue_setup,
1339 .tx_queue_setup = fs_tx_queue_setup,
1340 .rx_queue_release = fs_rx_queue_release,
1341 .tx_queue_release = fs_tx_queue_release,
1342 .rx_queue_intr_enable = fs_rx_intr_enable,
1343 .rx_queue_intr_disable = fs_rx_intr_disable,
1344 .flow_ctrl_get = fs_flow_ctrl_get,
1345 .flow_ctrl_set = fs_flow_ctrl_set,
1346 .mac_addr_remove = fs_mac_addr_remove,
1347 .mac_addr_add = fs_mac_addr_add,
1348 .mac_addr_set = fs_mac_addr_set,
1349 .set_mc_addr_list = fs_set_mc_addr_list,
1350 .rss_hash_update = fs_rss_hash_update,
1351 .filter_ctrl = fs_filter_ctrl,