4 * Copyright 2017 6WIND S.A.
5 * Copyright 2017 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_debug.h>
39 #include <rte_atomic.h>
40 #include <rte_ethdev_driver.h>
41 #include <rte_malloc.h>
43 #include <rte_cycles.h>
45 #include "failsafe_private.h"
47 static struct rte_eth_dev_info default_infos = {
48 /* Max possible number of elements */
49 .max_rx_pktlen = UINT32_MAX,
50 .max_rx_queues = RTE_MAX_QUEUES_PER_PORT,
51 .max_tx_queues = RTE_MAX_QUEUES_PER_PORT,
52 .max_mac_addrs = FAILSAFE_MAX_ETHADDR,
53 .max_hash_mac_addrs = UINT32_MAX,
54 .max_vfs = UINT16_MAX,
55 .max_vmdq_pools = UINT16_MAX,
60 .nb_seg_max = UINT16_MAX,
61 .nb_mtu_seg_max = UINT16_MAX,
67 .nb_seg_max = UINT16_MAX,
68 .nb_mtu_seg_max = UINT16_MAX,
71 * Set of capabilities that can be verified upon
72 * configuring a sub-device.
75 DEV_RX_OFFLOAD_VLAN_STRIP |
76 DEV_RX_OFFLOAD_IPV4_CKSUM |
77 DEV_RX_OFFLOAD_UDP_CKSUM |
78 DEV_RX_OFFLOAD_TCP_CKSUM |
79 DEV_RX_OFFLOAD_TCP_LRO |
80 DEV_RX_OFFLOAD_QINQ_STRIP |
81 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
82 DEV_RX_OFFLOAD_MACSEC_STRIP |
83 DEV_RX_OFFLOAD_HEADER_SPLIT |
84 DEV_RX_OFFLOAD_VLAN_FILTER |
85 DEV_RX_OFFLOAD_VLAN_EXTEND |
86 DEV_RX_OFFLOAD_JUMBO_FRAME |
87 DEV_RX_OFFLOAD_CRC_STRIP |
88 DEV_RX_OFFLOAD_SCATTER |
89 DEV_RX_OFFLOAD_TIMESTAMP |
90 DEV_RX_OFFLOAD_SECURITY,
91 .rx_queue_offload_capa =
92 DEV_RX_OFFLOAD_VLAN_STRIP |
93 DEV_RX_OFFLOAD_IPV4_CKSUM |
94 DEV_RX_OFFLOAD_UDP_CKSUM |
95 DEV_RX_OFFLOAD_TCP_CKSUM |
96 DEV_RX_OFFLOAD_TCP_LRO |
97 DEV_RX_OFFLOAD_QINQ_STRIP |
98 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
99 DEV_RX_OFFLOAD_MACSEC_STRIP |
100 DEV_RX_OFFLOAD_HEADER_SPLIT |
101 DEV_RX_OFFLOAD_VLAN_FILTER |
102 DEV_RX_OFFLOAD_VLAN_EXTEND |
103 DEV_RX_OFFLOAD_JUMBO_FRAME |
104 DEV_RX_OFFLOAD_CRC_STRIP |
105 DEV_RX_OFFLOAD_SCATTER |
106 DEV_RX_OFFLOAD_TIMESTAMP |
107 DEV_RX_OFFLOAD_SECURITY,
108 .tx_offload_capa = 0x0,
109 .flow_type_rss_offloads = 0x0,
113 fs_dev_configure(struct rte_eth_dev *dev)
115 struct sub_device *sdev;
116 uint64_t supp_tx_offloads;
117 uint64_t tx_offloads;
121 supp_tx_offloads = PRIV(dev)->infos.tx_offload_capa;
122 tx_offloads = dev->data->dev_conf.txmode.offloads;
123 if ((tx_offloads & supp_tx_offloads) != tx_offloads) {
125 ERROR("Some Tx offloads are not supported, "
126 "requested 0x%" PRIx64 " supported 0x%" PRIx64,
127 tx_offloads, supp_tx_offloads);
130 FOREACH_SUBDEV(sdev, i, dev) {
131 int rmv_interrupt = 0;
132 int lsc_interrupt = 0;
135 if (sdev->state != DEV_PROBED)
138 rmv_interrupt = ETH(sdev)->data->dev_flags &
139 RTE_ETH_DEV_INTR_RMV;
141 DEBUG("Enabling RMV interrupts for sub_device %d", i);
142 dev->data->dev_conf.intr_conf.rmv = 1;
144 DEBUG("sub_device %d does not support RMV event", i);
146 lsc_enabled = dev->data->dev_conf.intr_conf.lsc;
147 lsc_interrupt = lsc_enabled &&
148 (ETH(sdev)->data->dev_flags &
149 RTE_ETH_DEV_INTR_LSC);
151 DEBUG("Enabling LSC interrupts for sub_device %d", i);
152 dev->data->dev_conf.intr_conf.lsc = 1;
153 } else if (lsc_enabled && !lsc_interrupt) {
154 DEBUG("Disabling LSC interrupts for sub_device %d", i);
155 dev->data->dev_conf.intr_conf.lsc = 0;
157 DEBUG("Configuring sub-device %d", i);
159 ret = rte_eth_dev_configure(PORT_ID(sdev),
160 dev->data->nb_rx_queues,
161 dev->data->nb_tx_queues,
162 &dev->data->dev_conf);
164 if (!fs_err(sdev, ret))
166 ERROR("Could not configure sub_device %d", i);
170 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
171 RTE_ETH_EVENT_INTR_RMV,
172 failsafe_eth_rmv_event_callback,
175 WARN("Failed to register RMV callback for sub_device %d",
178 dev->data->dev_conf.intr_conf.rmv = 0;
180 ret = rte_eth_dev_callback_register(PORT_ID(sdev),
181 RTE_ETH_EVENT_INTR_LSC,
182 failsafe_eth_lsc_event_callback,
185 WARN("Failed to register LSC callback for sub_device %d",
188 dev->data->dev_conf.intr_conf.lsc = lsc_enabled;
189 sdev->state = DEV_ACTIVE;
191 if (PRIV(dev)->state < DEV_ACTIVE)
192 PRIV(dev)->state = DEV_ACTIVE;
197 fs_dev_start(struct rte_eth_dev *dev)
199 struct sub_device *sdev;
203 ret = failsafe_rx_intr_install(dev);
206 FOREACH_SUBDEV(sdev, i, dev) {
207 if (sdev->state != DEV_ACTIVE)
209 DEBUG("Starting sub_device %d", i);
210 ret = rte_eth_dev_start(PORT_ID(sdev));
212 if (!fs_err(sdev, ret))
216 ret = failsafe_rx_intr_install_subdevice(sdev);
218 if (!fs_err(sdev, ret))
220 rte_eth_dev_stop(PORT_ID(sdev));
223 sdev->state = DEV_STARTED;
225 if (PRIV(dev)->state < DEV_STARTED)
226 PRIV(dev)->state = DEV_STARTED;
227 fs_switch_dev(dev, NULL);
232 fs_dev_stop(struct rte_eth_dev *dev)
234 struct sub_device *sdev;
237 PRIV(dev)->state = DEV_STARTED - 1;
238 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_STARTED) {
239 rte_eth_dev_stop(PORT_ID(sdev));
240 failsafe_rx_intr_uninstall_subdevice(sdev);
241 sdev->state = DEV_STARTED - 1;
243 failsafe_rx_intr_uninstall(dev);
247 fs_dev_set_link_up(struct rte_eth_dev *dev)
249 struct sub_device *sdev;
253 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
254 DEBUG("Calling rte_eth_dev_set_link_up on sub_device %d", i);
255 ret = rte_eth_dev_set_link_up(PORT_ID(sdev));
256 if ((ret = fs_err(sdev, ret))) {
257 ERROR("Operation rte_eth_dev_set_link_up failed for sub_device %d"
258 " with error %d", i, ret);
266 fs_dev_set_link_down(struct rte_eth_dev *dev)
268 struct sub_device *sdev;
272 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
273 DEBUG("Calling rte_eth_dev_set_link_down on sub_device %d", i);
274 ret = rte_eth_dev_set_link_down(PORT_ID(sdev));
275 if ((ret = fs_err(sdev, ret))) {
276 ERROR("Operation rte_eth_dev_set_link_down failed for sub_device %d"
277 " with error %d", i, ret);
284 static void fs_dev_free_queues(struct rte_eth_dev *dev);
286 fs_dev_close(struct rte_eth_dev *dev)
288 struct sub_device *sdev;
291 failsafe_hotplug_alarm_cancel(dev);
292 if (PRIV(dev)->state == DEV_STARTED)
293 dev->dev_ops->dev_stop(dev);
294 PRIV(dev)->state = DEV_ACTIVE - 1;
295 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
296 DEBUG("Closing sub_device %d", i);
297 rte_eth_dev_close(PORT_ID(sdev));
298 sdev->state = DEV_ACTIVE - 1;
300 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 if (rxq->event_fd > 0)
334 close(rxq->event_fd);
335 dev = rxq->priv->dev;
336 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
337 SUBOPS(sdev, rx_queue_release)
338 (ETH(sdev)->data->rx_queues[rxq->qid]);
339 dev->data->rx_queues[rxq->qid] = NULL;
344 fs_rx_queue_setup(struct rte_eth_dev *dev,
345 uint16_t rx_queue_id,
347 unsigned int socket_id,
348 const struct rte_eth_rxconf *rx_conf,
349 struct rte_mempool *mb_pool)
352 * FIXME: Add a proper interface in rte_eal_interrupts for
353 * allocating eventfd as an interrupt vector.
354 * For the time being, fake as if we are using MSIX interrupts,
355 * this will cause rte_intr_efd_enable to allocate an eventfd for us.
357 struct rte_intr_handle intr_handle = {
358 .type = RTE_INTR_HANDLE_VFIO_MSIX,
361 struct sub_device *sdev;
366 rxq = dev->data->rx_queues[rx_queue_id];
368 fs_rx_queue_release(rxq);
369 dev->data->rx_queues[rx_queue_id] = NULL;
371 /* Verify application offloads are valid for our port and queue. */
372 if (fs_rxq_offloads_valid(dev, rx_conf->offloads) == false) {
374 ERROR("Rx queue offloads 0x%" PRIx64
375 " don't match port offloads 0x%" PRIx64
376 " or supported offloads 0x%" PRIx64,
378 dev->data->dev_conf.rxmode.offloads,
379 PRIV(dev)->infos.rx_offload_capa |
380 PRIV(dev)->infos.rx_queue_offload_capa);
383 rxq = rte_zmalloc(NULL,
385 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
386 RTE_CACHE_LINE_SIZE);
389 FOREACH_SUBDEV(sdev, i, dev)
390 rte_atomic64_init(&rxq->refcnt[i]);
391 rxq->qid = rx_queue_id;
392 rxq->socket_id = socket_id;
393 rxq->info.mp = mb_pool;
394 rxq->info.conf = *rx_conf;
395 rxq->info.nb_desc = nb_rx_desc;
396 rxq->priv = PRIV(dev);
397 rxq->sdev = PRIV(dev)->subs;
398 ret = rte_intr_efd_enable(&intr_handle, 1);
401 rxq->event_fd = intr_handle.efds[0];
402 dev->data->rx_queues[rx_queue_id] = rxq;
403 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
404 ret = rte_eth_rx_queue_setup(PORT_ID(sdev),
406 nb_rx_desc, socket_id,
408 if ((ret = fs_err(sdev, ret))) {
409 ERROR("RX queue setup failed for sub_device %d", i);
415 fs_rx_queue_release(rxq);
420 fs_rx_intr_enable(struct rte_eth_dev *dev, uint16_t idx)
423 struct sub_device *sdev;
428 if (idx >= dev->data->nb_rx_queues) {
432 rxq = dev->data->rx_queues[idx];
433 if (rxq == NULL || rxq->event_fd <= 0) {
437 /* Fail if proxy service is nor running. */
438 if (PRIV(dev)->rxp.sstate != SS_RUNNING) {
439 ERROR("failsafe interrupt services are not running");
443 rxq->enable_events = 1;
444 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
445 ret = rte_eth_dev_rx_intr_enable(PORT_ID(sdev), idx);
446 ret = fs_err(sdev, ret);
456 fs_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
459 struct sub_device *sdev;
465 if (idx >= dev->data->nb_rx_queues) {
469 rxq = dev->data->rx_queues[idx];
470 if (rxq == NULL || rxq->event_fd <= 0) {
474 rxq->enable_events = 0;
475 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
476 ret = rte_eth_dev_rx_intr_disable(PORT_ID(sdev), idx);
477 ret = fs_err(sdev, ret);
481 /* Clear pending events */
482 while (read(rxq->event_fd, &u64, sizeof(uint64_t)) > 0)
490 fs_txq_offloads_valid(struct rte_eth_dev *dev, uint64_t offloads)
492 uint64_t port_offloads;
493 uint64_t queue_supp_offloads;
494 uint64_t port_supp_offloads;
496 port_offloads = dev->data->dev_conf.txmode.offloads;
497 queue_supp_offloads = PRIV(dev)->infos.tx_queue_offload_capa;
498 port_supp_offloads = PRIV(dev)->infos.tx_offload_capa;
499 if ((offloads & (queue_supp_offloads | port_supp_offloads)) !=
502 /* Verify we have no conflict with port offloads */
503 if ((port_offloads ^ offloads) & port_supp_offloads)
509 fs_tx_queue_release(void *queue)
511 struct rte_eth_dev *dev;
512 struct sub_device *sdev;
519 dev = txq->priv->dev;
520 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
521 SUBOPS(sdev, tx_queue_release)
522 (ETH(sdev)->data->tx_queues[txq->qid]);
523 dev->data->tx_queues[txq->qid] = NULL;
528 fs_tx_queue_setup(struct rte_eth_dev *dev,
529 uint16_t tx_queue_id,
531 unsigned int socket_id,
532 const struct rte_eth_txconf *tx_conf)
534 struct sub_device *sdev;
539 txq = dev->data->tx_queues[tx_queue_id];
541 fs_tx_queue_release(txq);
542 dev->data->tx_queues[tx_queue_id] = NULL;
545 * Don't verify queue offloads for applications which
548 if (tx_conf != NULL &&
549 (tx_conf->txq_flags & ETH_TXQ_FLAGS_IGNORE) &&
550 fs_txq_offloads_valid(dev, tx_conf->offloads) == false) {
552 ERROR("Tx queue offloads 0x%" PRIx64
553 " don't match port offloads 0x%" PRIx64
554 " or supported offloads 0x%" PRIx64,
556 dev->data->dev_conf.txmode.offloads,
557 PRIV(dev)->infos.tx_offload_capa |
558 PRIV(dev)->infos.tx_queue_offload_capa);
561 txq = rte_zmalloc("ethdev TX queue",
563 sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail,
564 RTE_CACHE_LINE_SIZE);
567 FOREACH_SUBDEV(sdev, i, dev)
568 rte_atomic64_init(&txq->refcnt[i]);
569 txq->qid = tx_queue_id;
570 txq->socket_id = socket_id;
571 txq->info.conf = *tx_conf;
572 txq->info.nb_desc = nb_tx_desc;
573 txq->priv = PRIV(dev);
574 dev->data->tx_queues[tx_queue_id] = txq;
575 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
576 ret = rte_eth_tx_queue_setup(PORT_ID(sdev),
578 nb_tx_desc, socket_id,
580 if ((ret = fs_err(sdev, ret))) {
581 ERROR("TX queue setup failed for sub_device %d", i);
587 fs_tx_queue_release(txq);
592 fs_dev_free_queues(struct rte_eth_dev *dev)
596 for (i = 0; i < dev->data->nb_rx_queues; i++) {
597 fs_rx_queue_release(dev->data->rx_queues[i]);
598 dev->data->rx_queues[i] = NULL;
600 dev->data->nb_rx_queues = 0;
601 for (i = 0; i < dev->data->nb_tx_queues; i++) {
602 fs_tx_queue_release(dev->data->tx_queues[i]);
603 dev->data->tx_queues[i] = NULL;
605 dev->data->nb_tx_queues = 0;
609 fs_promiscuous_enable(struct rte_eth_dev *dev)
611 struct sub_device *sdev;
614 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
615 rte_eth_promiscuous_enable(PORT_ID(sdev));
619 fs_promiscuous_disable(struct rte_eth_dev *dev)
621 struct sub_device *sdev;
624 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
625 rte_eth_promiscuous_disable(PORT_ID(sdev));
629 fs_allmulticast_enable(struct rte_eth_dev *dev)
631 struct sub_device *sdev;
634 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
635 rte_eth_allmulticast_enable(PORT_ID(sdev));
639 fs_allmulticast_disable(struct rte_eth_dev *dev)
641 struct sub_device *sdev;
644 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
645 rte_eth_allmulticast_disable(PORT_ID(sdev));
649 fs_link_update(struct rte_eth_dev *dev,
650 int wait_to_complete)
652 struct sub_device *sdev;
656 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
657 DEBUG("Calling link_update on sub_device %d", i);
658 ret = (SUBOPS(sdev, link_update))(ETH(sdev), wait_to_complete);
659 if (ret && ret != -1 && sdev->remove == 0 &&
660 rte_eth_dev_is_removed(PORT_ID(sdev)) == 0) {
661 ERROR("Link update failed for sub_device %d with error %d",
666 if (TX_SUBDEV(dev)) {
667 struct rte_eth_link *l1;
668 struct rte_eth_link *l2;
670 l1 = &dev->data->dev_link;
671 l2 = Ð(TX_SUBDEV(dev))->data->dev_link;
672 if (memcmp(l1, l2, sizeof(*l1))) {
681 fs_stats_get(struct rte_eth_dev *dev,
682 struct rte_eth_stats *stats)
684 struct rte_eth_stats backup;
685 struct sub_device *sdev;
689 rte_memcpy(stats, &PRIV(dev)->stats_accumulator, sizeof(*stats));
690 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
691 struct rte_eth_stats *snapshot = &sdev->stats_snapshot.stats;
692 uint64_t *timestamp = &sdev->stats_snapshot.timestamp;
694 rte_memcpy(&backup, snapshot, sizeof(backup));
695 ret = rte_eth_stats_get(PORT_ID(sdev), snapshot);
697 if (!fs_err(sdev, ret)) {
698 rte_memcpy(snapshot, &backup, sizeof(backup));
701 ERROR("Operation rte_eth_stats_get failed for sub_device %d with error %d",
706 *timestamp = rte_rdtsc();
708 failsafe_stats_increment(stats, snapshot);
714 fs_stats_reset(struct rte_eth_dev *dev)
716 struct sub_device *sdev;
719 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
720 rte_eth_stats_reset(PORT_ID(sdev));
721 memset(&sdev->stats_snapshot, 0, sizeof(struct rte_eth_stats));
723 memset(&PRIV(dev)->stats_accumulator, 0, sizeof(struct rte_eth_stats));
727 * Fail-safe dev_infos_get rules:
731 * Use the maximum possible values for any field, so as not
732 * to impede any further configuration effort.
734 * Limits capabilities to those that are understood by the
735 * fail-safe PMD. This understanding stems from the fail-safe
736 * being capable of verifying that the related capability is
737 * expressed within the device configuration (struct rte_eth_conf).
739 * At least one probed sub_device:
741 * Uses values from the active probed sub_device
742 * The rationale here is that if any sub_device is less capable
743 * (for example concerning the number of queues) than the active
744 * sub_device, then its subsequent configuration will fail.
745 * It is impossible to foresee this failure when the failing sub_device
746 * is supposed to be plugged-in later on, so the configuration process
747 * is the single point of failure and error reporting.
749 * Uses a logical AND of RX capabilities among
750 * all sub_devices and the default capabilities.
751 * Uses a logical AND of TX capabilities among
752 * the active probed sub_device and the default capabilities.
756 fs_dev_infos_get(struct rte_eth_dev *dev,
757 struct rte_eth_dev_info *infos)
759 struct sub_device *sdev;
762 sdev = TX_SUBDEV(dev);
764 DEBUG("No probed device, using default infos");
765 rte_memcpy(&PRIV(dev)->infos, &default_infos,
766 sizeof(default_infos));
768 uint64_t rx_offload_capa;
769 uint64_t rxq_offload_capa;
771 rx_offload_capa = default_infos.rx_offload_capa;
772 rxq_offload_capa = default_infos.rx_queue_offload_capa;
773 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
774 rte_eth_dev_info_get(PORT_ID(sdev),
776 rx_offload_capa &= PRIV(dev)->infos.rx_offload_capa;
778 PRIV(dev)->infos.rx_queue_offload_capa;
780 sdev = TX_SUBDEV(dev);
781 rte_eth_dev_info_get(PORT_ID(sdev), &PRIV(dev)->infos);
782 PRIV(dev)->infos.rx_offload_capa = rx_offload_capa;
783 PRIV(dev)->infos.rx_queue_offload_capa = rxq_offload_capa;
784 PRIV(dev)->infos.tx_offload_capa &=
785 default_infos.tx_offload_capa;
786 PRIV(dev)->infos.tx_queue_offload_capa &=
787 default_infos.tx_queue_offload_capa;
788 PRIV(dev)->infos.flow_type_rss_offloads &=
789 default_infos.flow_type_rss_offloads;
791 rte_memcpy(infos, &PRIV(dev)->infos, sizeof(*infos));
794 static const uint32_t *
795 fs_dev_supported_ptypes_get(struct rte_eth_dev *dev)
797 struct sub_device *sdev;
798 struct rte_eth_dev *edev;
800 sdev = TX_SUBDEV(dev);
804 /* ENOTSUP: counts as no supported ptypes */
805 if (SUBOPS(sdev, dev_supported_ptypes_get) == NULL)
808 * The API does not permit to do a clean AND of all ptypes,
809 * It is also incomplete by design and we do not really care
810 * to have a best possible value in this context.
811 * We just return the ptypes of the device of highest
812 * priority, usually the PREFERRED device.
814 return SUBOPS(sdev, dev_supported_ptypes_get)(edev);
818 fs_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
820 struct sub_device *sdev;
824 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
825 DEBUG("Calling rte_eth_dev_set_mtu on sub_device %d", i);
826 ret = rte_eth_dev_set_mtu(PORT_ID(sdev), mtu);
827 if ((ret = fs_err(sdev, ret))) {
828 ERROR("Operation rte_eth_dev_set_mtu failed for sub_device %d with error %d",
837 fs_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
839 struct sub_device *sdev;
843 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
844 DEBUG("Calling rte_eth_dev_vlan_filter on sub_device %d", i);
845 ret = rte_eth_dev_vlan_filter(PORT_ID(sdev), vlan_id, on);
846 if ((ret = fs_err(sdev, ret))) {
847 ERROR("Operation rte_eth_dev_vlan_filter failed for sub_device %d"
848 " with error %d", i, ret);
856 fs_flow_ctrl_get(struct rte_eth_dev *dev,
857 struct rte_eth_fc_conf *fc_conf)
859 struct sub_device *sdev;
861 sdev = TX_SUBDEV(dev);
864 if (SUBOPS(sdev, flow_ctrl_get) == NULL)
866 return SUBOPS(sdev, flow_ctrl_get)(ETH(sdev), fc_conf);
870 fs_flow_ctrl_set(struct rte_eth_dev *dev,
871 struct rte_eth_fc_conf *fc_conf)
873 struct sub_device *sdev;
877 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
878 DEBUG("Calling rte_eth_dev_flow_ctrl_set on sub_device %d", i);
879 ret = rte_eth_dev_flow_ctrl_set(PORT_ID(sdev), fc_conf);
880 if ((ret = fs_err(sdev, ret))) {
881 ERROR("Operation rte_eth_dev_flow_ctrl_set failed for sub_device %d"
882 " with error %d", i, ret);
890 fs_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
892 struct sub_device *sdev;
895 /* No check: already done within the rte_eth_dev_mac_addr_remove
896 * call for the fail-safe device.
898 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
899 rte_eth_dev_mac_addr_remove(PORT_ID(sdev),
900 &dev->data->mac_addrs[index]);
901 PRIV(dev)->mac_addr_pool[index] = 0;
905 fs_mac_addr_add(struct rte_eth_dev *dev,
906 struct ether_addr *mac_addr,
910 struct sub_device *sdev;
914 RTE_ASSERT(index < FAILSAFE_MAX_ETHADDR);
915 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
916 ret = rte_eth_dev_mac_addr_add(PORT_ID(sdev), mac_addr, vmdq);
917 if ((ret = fs_err(sdev, ret))) {
918 ERROR("Operation rte_eth_dev_mac_addr_add failed for sub_device %"
919 PRIu8 " with error %d", i, ret);
923 if (index >= PRIV(dev)->nb_mac_addr) {
924 DEBUG("Growing mac_addrs array");
925 PRIV(dev)->nb_mac_addr = index;
927 PRIV(dev)->mac_addr_pool[index] = vmdq;
932 fs_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
934 struct sub_device *sdev;
937 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE)
938 rte_eth_dev_default_mac_addr_set(PORT_ID(sdev), mac_addr);
942 fs_filter_ctrl(struct rte_eth_dev *dev,
943 enum rte_filter_type type,
944 enum rte_filter_op op,
947 struct sub_device *sdev;
951 if (type == RTE_ETH_FILTER_GENERIC &&
952 op == RTE_ETH_FILTER_GET) {
953 *(const void **)arg = &fs_flow_ops;
956 FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_ACTIVE) {
957 DEBUG("Calling rte_eth_dev_filter_ctrl on sub_device %d", i);
958 ret = rte_eth_dev_filter_ctrl(PORT_ID(sdev), type, op, arg);
959 if ((ret = fs_err(sdev, ret))) {
960 ERROR("Operation rte_eth_dev_filter_ctrl failed for sub_device %d"
961 " with error %d", i, ret);
968 const struct eth_dev_ops failsafe_ops = {
969 .dev_configure = fs_dev_configure,
970 .dev_start = fs_dev_start,
971 .dev_stop = fs_dev_stop,
972 .dev_set_link_down = fs_dev_set_link_down,
973 .dev_set_link_up = fs_dev_set_link_up,
974 .dev_close = fs_dev_close,
975 .promiscuous_enable = fs_promiscuous_enable,
976 .promiscuous_disable = fs_promiscuous_disable,
977 .allmulticast_enable = fs_allmulticast_enable,
978 .allmulticast_disable = fs_allmulticast_disable,
979 .link_update = fs_link_update,
980 .stats_get = fs_stats_get,
981 .stats_reset = fs_stats_reset,
982 .dev_infos_get = fs_dev_infos_get,
983 .dev_supported_ptypes_get = fs_dev_supported_ptypes_get,
984 .mtu_set = fs_mtu_set,
985 .vlan_filter_set = fs_vlan_filter_set,
986 .rx_queue_setup = fs_rx_queue_setup,
987 .tx_queue_setup = fs_tx_queue_setup,
988 .rx_queue_release = fs_rx_queue_release,
989 .tx_queue_release = fs_tx_queue_release,
990 .rx_queue_intr_enable = fs_rx_intr_enable,
991 .rx_queue_intr_disable = fs_rx_intr_disable,
992 .flow_ctrl_get = fs_flow_ctrl_get,
993 .flow_ctrl_set = fs_flow_ctrl_set,
994 .mac_addr_remove = fs_mac_addr_remove,
995 .mac_addr_add = fs_mac_addr_add,
996 .mac_addr_set = fs_mac_addr_set,
997 .filter_ctrl = fs_filter_ctrl,