1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2016-2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
11 #include <ethdev_driver.h>
12 #include <ethdev_pci.h>
14 #include <rte_bus_pci.h>
15 #include <rte_errno.h>
16 #include <rte_string_fns.h>
17 #include <rte_ether.h>
22 #include "sfc_debug.h"
24 #include "sfc_kvargs.h"
30 #include "sfc_dp_rx.h"
32 #include "sfc_sw_stats.h"
33 #include "sfc_switch.h"
35 #define SFC_XSTAT_ID_INVALID_VAL UINT64_MAX
36 #define SFC_XSTAT_ID_INVALID_NAME '\0'
38 uint32_t sfc_logtype_driver;
40 static struct sfc_dp_list sfc_dp_head =
41 TAILQ_HEAD_INITIALIZER(sfc_dp_head);
44 static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
48 sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
50 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
51 efx_nic_fw_info_t enfi;
55 rc = efx_nic_get_fw_version(sa->nic, &enfi);
59 ret = snprintf(fw_version, fw_size,
60 "%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
61 enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
62 enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
66 if (enfi.enfi_dpcpu_fw_ids_valid) {
67 size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
70 ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
71 fw_size - dpcpu_fw_ids_offset,
72 " rx%" PRIx16 " tx%" PRIx16,
73 enfi.enfi_rx_dpcpu_fw_id,
74 enfi.enfi_tx_dpcpu_fw_id);
81 if (fw_size < (size_t)(++ret))
88 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
90 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
91 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
92 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
93 struct sfc_rss *rss = &sas->rss;
94 struct sfc_mae *mae = &sa->mae;
95 uint64_t txq_offloads_def = 0;
97 sfc_log_init(sa, "entry");
99 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
100 dev_info->max_mtu = EFX_MAC_SDU_MAX;
102 dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
104 dev_info->max_vfs = sa->sriov.num_vfs;
106 /* Autonegotiation may be disabled */
107 dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
108 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
109 dev_info->speed_capa |= ETH_LINK_SPEED_1G;
110 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
111 dev_info->speed_capa |= ETH_LINK_SPEED_10G;
112 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
113 dev_info->speed_capa |= ETH_LINK_SPEED_25G;
114 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
115 dev_info->speed_capa |= ETH_LINK_SPEED_40G;
116 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
117 dev_info->speed_capa |= ETH_LINK_SPEED_50G;
118 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
119 dev_info->speed_capa |= ETH_LINK_SPEED_100G;
121 dev_info->max_rx_queues = sa->rxq_max;
122 dev_info->max_tx_queues = sa->txq_max;
124 /* By default packets are dropped if no descriptors are available */
125 dev_info->default_rxconf.rx_drop_en = 1;
127 dev_info->rx_queue_offload_capa = sfc_rx_get_queue_offload_caps(sa);
130 * rx_offload_capa includes both device and queue offloads since
131 * the latter may be requested on a per device basis which makes
132 * sense when some offloads are needed to be set on all queues.
134 dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
135 dev_info->rx_queue_offload_capa;
137 dev_info->tx_queue_offload_capa = sfc_tx_get_queue_offload_caps(sa);
140 * tx_offload_capa includes both device and queue offloads since
141 * the latter may be requested on a per device basis which makes
142 * sense when some offloads are needed to be set on all queues.
144 dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
145 dev_info->tx_queue_offload_capa;
147 if (dev_info->tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
148 txq_offloads_def |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
150 dev_info->default_txconf.offloads |= txq_offloads_def;
152 if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
156 for (i = 0; i < rss->hf_map_nb_entries; ++i)
157 rte_hf |= rss->hf_map[i].rte;
159 dev_info->reta_size = EFX_RSS_TBL_SIZE;
160 dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
161 dev_info->flow_type_rss_offloads = rte_hf;
164 /* Initialize to hardware limits */
165 dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
166 dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
167 /* The RXQ hardware requires that the descriptor count is a power
168 * of 2, but rx_desc_lim cannot properly describe that constraint.
170 dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
172 /* Initialize to hardware limits */
173 dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
174 dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
176 * The TXQ hardware requires that the descriptor count is a power
177 * of 2, but tx_desc_lim cannot properly describe that constraint
179 dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
181 if (sap->dp_rx->get_dev_info != NULL)
182 sap->dp_rx->get_dev_info(dev_info);
183 if (sap->dp_tx->get_dev_info != NULL)
184 sap->dp_tx->get_dev_info(dev_info);
186 dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
187 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
189 if (mae->status == SFC_MAE_STATUS_SUPPORTED) {
190 dev_info->switch_info.name = dev->device->driver->name;
191 dev_info->switch_info.domain_id = mae->switch_domain_id;
192 dev_info->switch_info.port_id = mae->switch_port_id;
198 static const uint32_t *
199 sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
201 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
203 return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps);
207 sfc_dev_configure(struct rte_eth_dev *dev)
209 struct rte_eth_dev_data *dev_data = dev->data;
210 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
213 sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
214 dev_data->nb_rx_queues, dev_data->nb_tx_queues);
216 sfc_adapter_lock(sa);
218 case SFC_ETHDEV_CONFIGURED:
220 case SFC_ETHDEV_INITIALIZED:
221 rc = sfc_configure(sa);
224 sfc_err(sa, "unexpected adapter state %u to configure",
229 sfc_adapter_unlock(sa);
231 sfc_log_init(sa, "done %d", rc);
237 sfc_dev_start(struct rte_eth_dev *dev)
239 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
242 sfc_log_init(sa, "entry");
244 sfc_adapter_lock(sa);
246 sfc_adapter_unlock(sa);
248 sfc_log_init(sa, "done %d", rc);
254 sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
256 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
257 struct rte_eth_link current_link;
260 sfc_log_init(sa, "entry");
262 if (sa->state != SFC_ETHDEV_STARTED) {
263 sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, ¤t_link);
264 } else if (wait_to_complete) {
265 efx_link_mode_t link_mode;
267 if (efx_port_poll(sa->nic, &link_mode) != 0)
268 link_mode = EFX_LINK_UNKNOWN;
269 sfc_port_link_mode_to_info(link_mode, ¤t_link);
272 sfc_ev_mgmt_qpoll(sa);
273 rte_eth_linkstatus_get(dev, ¤t_link);
276 ret = rte_eth_linkstatus_set(dev, ¤t_link);
278 sfc_notice(sa, "Link status is %s",
279 current_link.link_status ? "UP" : "DOWN");
285 sfc_dev_stop(struct rte_eth_dev *dev)
287 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
289 sfc_log_init(sa, "entry");
291 sfc_adapter_lock(sa);
293 sfc_adapter_unlock(sa);
295 sfc_log_init(sa, "done");
301 sfc_dev_set_link_up(struct rte_eth_dev *dev)
303 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
306 sfc_log_init(sa, "entry");
308 sfc_adapter_lock(sa);
310 sfc_adapter_unlock(sa);
317 sfc_dev_set_link_down(struct rte_eth_dev *dev)
319 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
321 sfc_log_init(sa, "entry");
323 sfc_adapter_lock(sa);
325 sfc_adapter_unlock(sa);
331 sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
333 free(dev->process_private);
334 rte_eth_dev_release_port(dev);
338 sfc_dev_close(struct rte_eth_dev *dev)
340 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
342 sfc_log_init(sa, "entry");
344 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
345 sfc_eth_dev_secondary_clear_ops(dev);
351 sfc_adapter_lock(sa);
353 case SFC_ETHDEV_STARTED:
355 SFC_ASSERT(sa->state == SFC_ETHDEV_CONFIGURED);
357 case SFC_ETHDEV_CONFIGURED:
359 SFC_ASSERT(sa->state == SFC_ETHDEV_INITIALIZED);
361 case SFC_ETHDEV_INITIALIZED:
364 sfc_err(sa, "unexpected adapter state %u on close", sa->state);
369 * Cleanup all resources.
370 * Rollback primary process sfc_eth_dev_init() below.
373 sfc_eth_dev_clear_ops(dev);
378 sfc_kvargs_cleanup(sa);
380 sfc_adapter_unlock(sa);
381 sfc_adapter_lock_fini(sa);
383 sfc_log_init(sa, "done");
385 /* Required for logging, so cleanup last */
394 sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
397 struct sfc_port *port;
399 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
400 boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
401 const char *desc = (allmulti) ? "all-multi" : "promiscuous";
404 sfc_adapter_lock(sa);
407 toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
409 if (*toggle != enabled) {
412 if (sfc_sa2shared(sa)->isolated) {
413 sfc_warn(sa, "isolated mode is active on the port");
414 sfc_warn(sa, "the change is to be applied on the next "
415 "start provided that isolated mode is "
416 "disabled prior the next start");
417 } else if ((sa->state == SFC_ETHDEV_STARTED) &&
418 ((rc = sfc_set_rx_mode(sa)) != 0)) {
419 *toggle = !(enabled);
420 sfc_warn(sa, "Failed to %s %s mode, rc = %d",
421 ((enabled) ? "enable" : "disable"), desc, rc);
424 * For promiscuous and all-multicast filters a
425 * permission failure should be reported as an
426 * unsupported filter.
433 sfc_adapter_unlock(sa);
438 sfc_dev_promisc_enable(struct rte_eth_dev *dev)
440 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
447 sfc_dev_promisc_disable(struct rte_eth_dev *dev)
449 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
456 sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
458 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
465 sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
467 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
474 sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
475 uint16_t nb_rx_desc, unsigned int socket_id,
476 const struct rte_eth_rxconf *rx_conf,
477 struct rte_mempool *mb_pool)
479 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
480 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
481 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
482 struct sfc_rxq_info *rxq_info;
483 sfc_sw_index_t sw_index;
486 sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
487 ethdev_qid, nb_rx_desc, socket_id);
489 sfc_adapter_lock(sa);
491 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
492 rc = sfc_rx_qinit(sa, sw_index, nb_rx_desc, socket_id,
497 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
498 dev->data->rx_queues[ethdev_qid] = rxq_info->dp;
500 sfc_adapter_unlock(sa);
505 sfc_adapter_unlock(sa);
511 sfc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
513 struct sfc_dp_rxq *dp_rxq = dev->data->rx_queues[qid];
515 struct sfc_adapter *sa;
516 sfc_sw_index_t sw_index;
521 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
523 sfc_adapter_lock(sa);
525 sw_index = dp_rxq->dpq.queue_id;
527 sfc_log_init(sa, "RxQ=%u", sw_index);
529 sfc_rx_qfini(sa, sw_index);
531 sfc_adapter_unlock(sa);
535 sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
536 uint16_t nb_tx_desc, unsigned int socket_id,
537 const struct rte_eth_txconf *tx_conf)
539 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
540 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
541 struct sfc_txq_info *txq_info;
542 sfc_sw_index_t sw_index;
545 sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
546 ethdev_qid, nb_tx_desc, socket_id);
548 sfc_adapter_lock(sa);
550 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
551 rc = sfc_tx_qinit(sa, sw_index, nb_tx_desc, socket_id, tx_conf);
555 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
556 dev->data->tx_queues[ethdev_qid] = txq_info->dp;
558 sfc_adapter_unlock(sa);
562 sfc_adapter_unlock(sa);
568 sfc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
570 struct sfc_dp_txq *dp_txq = dev->data->tx_queues[qid];
572 sfc_sw_index_t sw_index;
573 struct sfc_adapter *sa;
578 txq = sfc_txq_by_dp_txq(dp_txq);
579 sw_index = dp_txq->dpq.queue_id;
581 SFC_ASSERT(txq->evq != NULL);
584 sfc_log_init(sa, "TxQ = %u", sw_index);
586 sfc_adapter_lock(sa);
588 sfc_tx_qfini(sa, sw_index);
590 sfc_adapter_unlock(sa);
594 sfc_stats_get_dp_rx(struct sfc_adapter *sa, uint64_t *pkts, uint64_t *bytes)
596 struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
597 uint64_t pkts_sum = 0;
598 uint64_t bytes_sum = 0;
601 for (i = 0; i < sas->ethdev_rxq_count; ++i) {
602 struct sfc_rxq_info *rxq_info;
604 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, i);
605 if (rxq_info->state & SFC_RXQ_INITIALIZED) {
606 union sfc_pkts_bytes qstats;
608 sfc_pkts_bytes_get(&rxq_info->dp->dpq.stats, &qstats);
609 pkts_sum += qstats.pkts -
610 sa->sw_stats.reset_rx_pkts[i];
611 bytes_sum += qstats.bytes -
612 sa->sw_stats.reset_rx_bytes[i];
621 sfc_stats_get_dp_tx(struct sfc_adapter *sa, uint64_t *pkts, uint64_t *bytes)
623 struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
624 uint64_t pkts_sum = 0;
625 uint64_t bytes_sum = 0;
628 for (i = 0; i < sas->ethdev_txq_count; ++i) {
629 struct sfc_txq_info *txq_info;
631 txq_info = sfc_txq_info_by_ethdev_qid(sas, i);
632 if (txq_info->state & SFC_TXQ_INITIALIZED) {
633 union sfc_pkts_bytes qstats;
635 sfc_pkts_bytes_get(&txq_info->dp->dpq.stats, &qstats);
636 pkts_sum += qstats.pkts -
637 sa->sw_stats.reset_tx_pkts[i];
638 bytes_sum += qstats.bytes -
639 sa->sw_stats.reset_tx_bytes[i];
648 * Some statistics are computed as A - B where A and B each increase
649 * monotonically with some hardware counter(s) and the counters are read
652 * If packet X is counted in A, but not counted in B yet, computed value is
655 * If packet X is not counted in A at the moment of reading the counter,
656 * but counted in B at the moment of reading the counter, computed value
659 * However, counter which grows backward is worse evil than slightly wrong
660 * value. So, let's try to guarantee that it never happens except may be
661 * the case when the MAC stats are zeroed as a result of a NIC reset.
664 sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
666 if ((int64_t)(newval - *stat) > 0 || newval == 0)
671 sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
673 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
674 bool have_dp_rx_stats = sap->dp_rx->features & SFC_DP_RX_FEAT_STATS;
675 bool have_dp_tx_stats = sap->dp_tx->features & SFC_DP_TX_FEAT_STATS;
676 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
677 struct sfc_port *port = &sa->port;
681 sfc_adapter_lock(sa);
683 if (have_dp_rx_stats)
684 sfc_stats_get_dp_rx(sa, &stats->ipackets, &stats->ibytes);
685 if (have_dp_tx_stats)
686 sfc_stats_get_dp_tx(sa, &stats->opackets, &stats->obytes);
688 ret = sfc_port_update_mac_stats(sa, B_FALSE);
692 mac_stats = port->mac_stats_buf;
694 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
695 EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
696 if (!have_dp_rx_stats) {
698 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
699 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
700 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
702 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
703 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
704 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
706 /* CRC is included in these stats, but shouldn't be */
707 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
709 if (!have_dp_tx_stats) {
711 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
712 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
713 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
715 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
716 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
717 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
719 /* CRC is included in these stats, but shouldn't be */
720 stats->obytes -= stats->opackets * RTE_ETHER_CRC_LEN;
722 stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
723 stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
725 if (!have_dp_tx_stats) {
726 stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
727 stats->obytes = mac_stats[EFX_MAC_TX_OCTETS] -
728 mac_stats[EFX_MAC_TX_PKTS] * RTE_ETHER_CRC_LEN;
732 * Take into account stats which are whenever supported
733 * on EF10. If some stat is not supported by current
734 * firmware variant or HW revision, it is guaranteed
735 * to be zero in mac_stats.
738 mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
739 mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
740 mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
741 mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
742 mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
743 mac_stats[EFX_MAC_PM_TRUNC_QBB] +
744 mac_stats[EFX_MAC_PM_DISCARD_QBB] +
745 mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
746 mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
747 mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
749 mac_stats[EFX_MAC_RX_FCS_ERRORS] +
750 mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
751 mac_stats[EFX_MAC_RX_JABBER_PKTS];
752 /* no oerrors counters supported on EF10 */
754 if (!have_dp_rx_stats) {
755 /* Exclude missed, errors and pauses from Rx packets */
756 sfc_update_diff_stat(&port->ipackets,
757 mac_stats[EFX_MAC_RX_PKTS] -
758 mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
759 stats->imissed - stats->ierrors);
760 stats->ipackets = port->ipackets;
761 stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS] -
762 mac_stats[EFX_MAC_RX_PKTS] * RTE_ETHER_CRC_LEN;
767 sfc_adapter_unlock(sa);
768 SFC_ASSERT(ret >= 0);
773 sfc_stats_reset(struct rte_eth_dev *dev)
775 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
776 struct sfc_port *port = &sa->port;
779 sfc_adapter_lock(sa);
781 if (sa->state != SFC_ETHDEV_STARTED) {
783 * The operation cannot be done if port is not started; it
784 * will be scheduled to be done during the next port start
786 port->mac_stats_reset_pending = B_TRUE;
787 sfc_adapter_unlock(sa);
791 rc = sfc_port_reset_mac_stats(sa);
793 sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
795 sfc_sw_xstats_reset(sa);
797 sfc_adapter_unlock(sa);
804 sfc_xstats_get_nb_supported(struct sfc_adapter *sa)
806 struct sfc_port *port = &sa->port;
807 unsigned int nb_supported;
809 sfc_adapter_lock(sa);
810 nb_supported = port->mac_stats_nb_supported +
811 sfc_sw_xstats_get_nb_supported(sa);
812 sfc_adapter_unlock(sa);
818 sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
819 unsigned int xstats_count)
821 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
822 unsigned int nb_written = 0;
823 unsigned int nb_supported = 0;
826 if (unlikely(xstats == NULL))
827 return sfc_xstats_get_nb_supported(sa);
829 rc = sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written);
834 sfc_sw_xstats_get_vals(sa, xstats, xstats_count, &nb_written,
841 sfc_xstats_get_names(struct rte_eth_dev *dev,
842 struct rte_eth_xstat_name *xstats_names,
843 unsigned int xstats_count)
845 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
846 struct sfc_port *port = &sa->port;
848 unsigned int nstats = 0;
849 unsigned int nb_written = 0;
852 if (unlikely(xstats_names == NULL))
853 return sfc_xstats_get_nb_supported(sa);
855 for (i = 0; i < EFX_MAC_NSTATS; ++i) {
856 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
857 if (nstats < xstats_count) {
858 strlcpy(xstats_names[nstats].name,
859 efx_mac_stat_name(sa->nic, i),
860 sizeof(xstats_names[0].name));
867 ret = sfc_sw_xstats_get_names(sa, xstats_names, xstats_count,
868 &nb_written, &nstats);
878 sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
879 uint64_t *values, unsigned int n)
881 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
882 struct sfc_port *port = &sa->port;
883 unsigned int nb_supported;
887 if (unlikely(ids == NULL || values == NULL))
891 * Values array could be filled in nonsequential order. Fill values with
892 * constant indicating invalid ID first.
894 for (i = 0; i < n; i++)
895 values[i] = SFC_XSTAT_ID_INVALID_VAL;
897 rc = sfc_port_get_mac_stats_by_id(sa, ids, values, n);
901 nb_supported = port->mac_stats_nb_supported;
902 sfc_sw_xstats_get_vals_by_id(sa, ids, values, n, &nb_supported);
904 /* Return number of written stats before invalid ID is encountered. */
905 for (i = 0; i < n; i++) {
906 if (values[i] == SFC_XSTAT_ID_INVALID_VAL)
914 sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
916 struct rte_eth_xstat_name *xstats_names,
919 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
920 struct sfc_port *port = &sa->port;
921 unsigned int nb_supported;
925 if (unlikely(xstats_names == NULL && ids != NULL) ||
926 unlikely(xstats_names != NULL && ids == NULL))
929 if (unlikely(xstats_names == NULL && ids == NULL))
930 return sfc_xstats_get_nb_supported(sa);
933 * Names array could be filled in nonsequential order. Fill names with
934 * string indicating invalid ID first.
936 for (i = 0; i < size; i++)
937 xstats_names[i].name[0] = SFC_XSTAT_ID_INVALID_NAME;
939 sfc_adapter_lock(sa);
941 SFC_ASSERT(port->mac_stats_nb_supported <=
942 RTE_DIM(port->mac_stats_by_id));
944 for (i = 0; i < size; i++) {
945 if (ids[i] < port->mac_stats_nb_supported) {
946 strlcpy(xstats_names[i].name,
947 efx_mac_stat_name(sa->nic,
948 port->mac_stats_by_id[ids[i]]),
949 sizeof(xstats_names[0].name));
953 nb_supported = port->mac_stats_nb_supported;
955 sfc_adapter_unlock(sa);
957 ret = sfc_sw_xstats_get_names_by_id(sa, ids, xstats_names, size,
964 /* Return number of written names before invalid ID is encountered. */
965 for (i = 0; i < size; i++) {
966 if (xstats_names[i].name[0] == SFC_XSTAT_ID_INVALID_NAME)
974 sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
976 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
977 unsigned int wanted_fc, link_fc;
979 memset(fc_conf, 0, sizeof(*fc_conf));
981 sfc_adapter_lock(sa);
983 if (sa->state == SFC_ETHDEV_STARTED)
984 efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
986 link_fc = sa->port.flow_ctrl;
990 fc_conf->mode = RTE_FC_NONE;
992 case EFX_FCNTL_RESPOND:
993 fc_conf->mode = RTE_FC_RX_PAUSE;
995 case EFX_FCNTL_GENERATE:
996 fc_conf->mode = RTE_FC_TX_PAUSE;
998 case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
999 fc_conf->mode = RTE_FC_FULL;
1002 sfc_err(sa, "%s: unexpected flow control value %#x",
1006 fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
1008 sfc_adapter_unlock(sa);
1014 sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1016 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1017 struct sfc_port *port = &sa->port;
1021 if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
1022 fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
1023 fc_conf->mac_ctrl_frame_fwd != 0) {
1024 sfc_err(sa, "unsupported flow control settings specified");
1029 switch (fc_conf->mode) {
1033 case RTE_FC_RX_PAUSE:
1034 fcntl = EFX_FCNTL_RESPOND;
1036 case RTE_FC_TX_PAUSE:
1037 fcntl = EFX_FCNTL_GENERATE;
1040 fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
1047 sfc_adapter_lock(sa);
1049 if (sa->state == SFC_ETHDEV_STARTED) {
1050 rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
1052 goto fail_mac_fcntl_set;
1055 port->flow_ctrl = fcntl;
1056 port->flow_ctrl_autoneg = fc_conf->autoneg;
1058 sfc_adapter_unlock(sa);
1063 sfc_adapter_unlock(sa);
1070 sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
1072 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1073 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1074 boolean_t scatter_enabled;
1078 for (i = 0; i < sas->rxq_count; i++) {
1079 if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
1082 scatter_enabled = (sas->rxq_info[i].type_flags &
1083 EFX_RXQ_FLAG_SCATTER);
1085 if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
1086 encp->enc_rx_prefix_size,
1088 encp->enc_rx_scatter_max, &error)) {
1089 sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
1099 sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1101 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1102 size_t pdu = EFX_MAC_PDU(mtu);
1106 sfc_log_init(sa, "mtu=%u", mtu);
1109 if (pdu < EFX_MAC_PDU_MIN) {
1110 sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
1111 (unsigned int)mtu, (unsigned int)pdu,
1115 if (pdu > EFX_MAC_PDU_MAX) {
1116 sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
1117 (unsigned int)mtu, (unsigned int)pdu,
1118 (unsigned int)EFX_MAC_PDU_MAX);
1122 sfc_adapter_lock(sa);
1124 rc = sfc_check_scatter_on_all_rx_queues(sa, pdu);
1126 goto fail_check_scatter;
1128 if (pdu != sa->port.pdu) {
1129 if (sa->state == SFC_ETHDEV_STARTED) {
1132 old_pdu = sa->port.pdu;
1143 * The driver does not use it, but other PMDs update jumbo frame
1144 * flag and max_rx_pkt_len when MTU is set.
1146 if (mtu > RTE_ETHER_MTU) {
1147 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1148 rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1151 dev->data->dev_conf.rxmode.max_rx_pkt_len = sa->port.pdu;
1153 sfc_adapter_unlock(sa);
1155 sfc_log_init(sa, "done");
1159 sa->port.pdu = old_pdu;
1160 if (sfc_start(sa) != 0)
1161 sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
1162 "PDU max size - port is stopped",
1163 (unsigned int)pdu, (unsigned int)old_pdu);
1166 sfc_adapter_unlock(sa);
1169 sfc_log_init(sa, "failed %d", rc);
1174 sfc_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1176 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1177 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1178 struct sfc_port *port = &sa->port;
1179 struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
1182 sfc_adapter_lock(sa);
1184 if (rte_is_same_ether_addr(mac_addr, &port->default_mac_addr))
1188 * Copy the address to the device private data so that
1189 * it could be recalled in the case of adapter restart.
1191 rte_ether_addr_copy(mac_addr, &port->default_mac_addr);
1194 * Neither of the two following checks can return
1195 * an error. The new MAC address is preserved in
1196 * the device private data and can be activated
1197 * on the next port start if the user prevents
1198 * isolated mode from being enabled.
1200 if (sfc_sa2shared(sa)->isolated) {
1201 sfc_warn(sa, "isolated mode is active on the port");
1202 sfc_warn(sa, "will not set MAC address");
1206 if (sa->state != SFC_ETHDEV_STARTED) {
1207 sfc_notice(sa, "the port is not started");
1208 sfc_notice(sa, "the new MAC address will be set on port start");
1213 if (encp->enc_allow_set_mac_with_installed_filters) {
1214 rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
1216 sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
1221 * Changing the MAC address by means of MCDI request
1222 * has no effect on received traffic, therefore
1223 * we also need to update unicast filters
1225 rc = sfc_set_rx_mode_unchecked(sa);
1227 sfc_err(sa, "cannot set filter (rc = %u)", rc);
1228 /* Rollback the old address */
1229 (void)efx_mac_addr_set(sa->nic, old_addr->addr_bytes);
1230 (void)sfc_set_rx_mode_unchecked(sa);
1233 sfc_warn(sa, "cannot set MAC address with filters installed");
1234 sfc_warn(sa, "adapter will be restarted to pick the new MAC");
1235 sfc_warn(sa, "(some traffic may be dropped)");
1238 * Since setting MAC address with filters installed is not
1239 * allowed on the adapter, the new MAC address will be set
1240 * by means of adapter restart. sfc_start() shall retrieve
1241 * the new address from the device private data and set it.
1246 sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
1251 rte_ether_addr_copy(old_addr, &port->default_mac_addr);
1253 sfc_adapter_unlock(sa);
1255 SFC_ASSERT(rc >= 0);
1261 sfc_set_mc_addr_list(struct rte_eth_dev *dev,
1262 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1264 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1265 struct sfc_port *port = &sa->port;
1266 uint8_t *mc_addrs = port->mcast_addrs;
1270 if (sfc_sa2shared(sa)->isolated) {
1271 sfc_err(sa, "isolated mode is active on the port");
1272 sfc_err(sa, "will not set multicast address list");
1276 if (mc_addrs == NULL)
1279 if (nb_mc_addr > port->max_mcast_addrs) {
1280 sfc_err(sa, "too many multicast addresses: %u > %u",
1281 nb_mc_addr, port->max_mcast_addrs);
1285 for (i = 0; i < nb_mc_addr; ++i) {
1286 rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
1288 mc_addrs += EFX_MAC_ADDR_LEN;
1291 port->nb_mcast_addrs = nb_mc_addr;
1293 if (sa->state != SFC_ETHDEV_STARTED)
1296 rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
1297 port->nb_mcast_addrs);
1299 sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
1301 SFC_ASSERT(rc >= 0);
1306 * The function is used by the secondary process as well. It must not
1307 * use any process-local pointers from the adapter data.
1310 sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1311 struct rte_eth_rxq_info *qinfo)
1313 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1314 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1315 struct sfc_rxq_info *rxq_info;
1317 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1319 qinfo->mp = rxq_info->refill_mb_pool;
1320 qinfo->conf.rx_free_thresh = rxq_info->refill_threshold;
1321 qinfo->conf.rx_drop_en = 1;
1322 qinfo->conf.rx_deferred_start = rxq_info->deferred_start;
1323 qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
1324 if (rxq_info->type_flags & EFX_RXQ_FLAG_SCATTER) {
1325 qinfo->conf.offloads |= DEV_RX_OFFLOAD_SCATTER;
1326 qinfo->scattered_rx = 1;
1328 qinfo->nb_desc = rxq_info->entries;
1332 * The function is used by the secondary process as well. It must not
1333 * use any process-local pointers from the adapter data.
1336 sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1337 struct rte_eth_txq_info *qinfo)
1339 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1340 struct sfc_txq_info *txq_info;
1342 SFC_ASSERT(ethdev_qid < sas->ethdev_txq_count);
1344 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1346 memset(qinfo, 0, sizeof(*qinfo));
1348 qinfo->conf.offloads = txq_info->offloads;
1349 qinfo->conf.tx_free_thresh = txq_info->free_thresh;
1350 qinfo->conf.tx_deferred_start = txq_info->deferred_start;
1351 qinfo->nb_desc = txq_info->entries;
1355 * The function is used by the secondary process as well. It must not
1356 * use any process-local pointers from the adapter data.
1359 sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1361 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1362 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1363 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1364 struct sfc_rxq_info *rxq_info;
1366 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1368 if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
1371 return sap->dp_rx->qdesc_npending(rxq_info->dp);
1375 * The function is used by the secondary process as well. It must not
1376 * use any process-local pointers from the adapter data.
1379 sfc_rx_descriptor_status(void *queue, uint16_t offset)
1381 struct sfc_dp_rxq *dp_rxq = queue;
1382 const struct sfc_dp_rx *dp_rx;
1384 dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1386 return dp_rx->qdesc_status(dp_rxq, offset);
1390 * The function is used by the secondary process as well. It must not
1391 * use any process-local pointers from the adapter data.
1394 sfc_tx_descriptor_status(void *queue, uint16_t offset)
1396 struct sfc_dp_txq *dp_txq = queue;
1397 const struct sfc_dp_tx *dp_tx;
1399 dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
1401 return dp_tx->qdesc_status(dp_txq, offset);
1405 sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1407 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1408 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1409 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1410 struct sfc_rxq_info *rxq_info;
1411 sfc_sw_index_t sw_index;
1414 sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1416 sfc_adapter_lock(sa);
1419 if (sa->state != SFC_ETHDEV_STARTED)
1420 goto fail_not_started;
1422 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1423 if (rxq_info->state != SFC_RXQ_INITIALIZED)
1424 goto fail_not_setup;
1426 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1427 rc = sfc_rx_qstart(sa, sw_index);
1429 goto fail_rx_qstart;
1431 rxq_info->deferred_started = B_TRUE;
1433 sfc_adapter_unlock(sa);
1440 sfc_adapter_unlock(sa);
1446 sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1448 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1449 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1450 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1451 struct sfc_rxq_info *rxq_info;
1452 sfc_sw_index_t sw_index;
1454 sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1456 sfc_adapter_lock(sa);
1458 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1459 sfc_rx_qstop(sa, sw_index);
1461 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1462 rxq_info->deferred_started = B_FALSE;
1464 sfc_adapter_unlock(sa);
1470 sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1472 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1473 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1474 struct sfc_txq_info *txq_info;
1475 sfc_sw_index_t sw_index;
1478 sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1480 sfc_adapter_lock(sa);
1483 if (sa->state != SFC_ETHDEV_STARTED)
1484 goto fail_not_started;
1486 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1487 if (txq_info->state != SFC_TXQ_INITIALIZED)
1488 goto fail_not_setup;
1490 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1491 rc = sfc_tx_qstart(sa, sw_index);
1493 goto fail_tx_qstart;
1495 txq_info->deferred_started = B_TRUE;
1497 sfc_adapter_unlock(sa);
1504 sfc_adapter_unlock(sa);
1510 sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1512 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1513 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1514 struct sfc_txq_info *txq_info;
1515 sfc_sw_index_t sw_index;
1517 sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1519 sfc_adapter_lock(sa);
1521 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1522 sfc_tx_qstop(sa, sw_index);
1524 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1525 txq_info->deferred_started = B_FALSE;
1527 sfc_adapter_unlock(sa);
1531 static efx_tunnel_protocol_t
1532 sfc_tunnel_rte_type_to_efx_udp_proto(enum rte_eth_tunnel_type rte_type)
1535 case RTE_TUNNEL_TYPE_VXLAN:
1536 return EFX_TUNNEL_PROTOCOL_VXLAN;
1537 case RTE_TUNNEL_TYPE_GENEVE:
1538 return EFX_TUNNEL_PROTOCOL_GENEVE;
1540 return EFX_TUNNEL_NPROTOS;
1544 enum sfc_udp_tunnel_op_e {
1545 SFC_UDP_TUNNEL_ADD_PORT,
1546 SFC_UDP_TUNNEL_DEL_PORT,
1550 sfc_dev_udp_tunnel_op(struct rte_eth_dev *dev,
1551 struct rte_eth_udp_tunnel *tunnel_udp,
1552 enum sfc_udp_tunnel_op_e op)
1554 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1555 efx_tunnel_protocol_t tunnel_proto;
1558 sfc_log_init(sa, "%s udp_port=%u prot_type=%u",
1559 (op == SFC_UDP_TUNNEL_ADD_PORT) ? "add" :
1560 (op == SFC_UDP_TUNNEL_DEL_PORT) ? "delete" : "unknown",
1561 tunnel_udp->udp_port, tunnel_udp->prot_type);
1564 sfc_tunnel_rte_type_to_efx_udp_proto(tunnel_udp->prot_type);
1565 if (tunnel_proto >= EFX_TUNNEL_NPROTOS) {
1567 goto fail_bad_proto;
1570 sfc_adapter_lock(sa);
1573 case SFC_UDP_TUNNEL_ADD_PORT:
1574 rc = efx_tunnel_config_udp_add(sa->nic,
1575 tunnel_udp->udp_port,
1578 case SFC_UDP_TUNNEL_DEL_PORT:
1579 rc = efx_tunnel_config_udp_remove(sa->nic,
1580 tunnel_udp->udp_port,
1591 if (sa->state == SFC_ETHDEV_STARTED) {
1592 rc = efx_tunnel_reconfigure(sa->nic);
1595 * Configuration is accepted by FW and MC reboot
1596 * is initiated to apply the changes. MC reboot
1597 * will be handled in a usual way (MC reboot
1598 * event on management event queue and adapter
1602 } else if (rc != 0) {
1603 goto fail_reconfigure;
1607 sfc_adapter_unlock(sa);
1611 /* Remove/restore entry since the change makes the trouble */
1613 case SFC_UDP_TUNNEL_ADD_PORT:
1614 (void)efx_tunnel_config_udp_remove(sa->nic,
1615 tunnel_udp->udp_port,
1618 case SFC_UDP_TUNNEL_DEL_PORT:
1619 (void)efx_tunnel_config_udp_add(sa->nic,
1620 tunnel_udp->udp_port,
1627 sfc_adapter_unlock(sa);
1635 sfc_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
1636 struct rte_eth_udp_tunnel *tunnel_udp)
1638 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_ADD_PORT);
1642 sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1643 struct rte_eth_udp_tunnel *tunnel_udp)
1645 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
1649 * The function is used by the secondary process as well. It must not
1650 * use any process-local pointers from the adapter data.
1653 sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1654 struct rte_eth_rss_conf *rss_conf)
1656 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1657 struct sfc_rss *rss = &sas->rss;
1659 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE)
1663 * Mapping of hash configuration between RTE and EFX is not one-to-one,
1664 * hence, conversion is done here to derive a correct set of ETH_RSS
1665 * flags which corresponds to the active EFX configuration stored
1666 * locally in 'sfc_adapter' and kept up-to-date
1668 rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(rss, rss->hash_types);
1669 rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
1670 if (rss_conf->rss_key != NULL)
1671 rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
1677 sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
1678 struct rte_eth_rss_conf *rss_conf)
1680 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1681 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1682 unsigned int efx_hash_types;
1683 uint32_t contexts[] = {EFX_RSS_CONTEXT_DEFAULT, rss->dummy_rss_context};
1684 unsigned int n_contexts;
1685 unsigned int mode_i = 0;
1686 unsigned int key_i = 0;
1690 n_contexts = rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT ? 1 : 2;
1692 if (sfc_sa2shared(sa)->isolated)
1695 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1696 sfc_err(sa, "RSS is not available");
1700 if (rss->channels == 0) {
1701 sfc_err(sa, "RSS is not configured");
1705 if ((rss_conf->rss_key != NULL) &&
1706 (rss_conf->rss_key_len != sizeof(rss->key))) {
1707 sfc_err(sa, "RSS key size is wrong (should be %zu)",
1712 sfc_adapter_lock(sa);
1714 rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
1716 goto fail_rx_hf_rte_to_efx;
1718 for (mode_i = 0; mode_i < n_contexts; mode_i++) {
1719 rc = efx_rx_scale_mode_set(sa->nic, contexts[mode_i],
1720 rss->hash_alg, efx_hash_types,
1723 goto fail_scale_mode_set;
1726 if (rss_conf->rss_key != NULL) {
1727 if (sa->state == SFC_ETHDEV_STARTED) {
1728 for (key_i = 0; key_i < n_contexts; key_i++) {
1729 rc = efx_rx_scale_key_set(sa->nic,
1734 goto fail_scale_key_set;
1738 rte_memcpy(rss->key, rss_conf->rss_key, sizeof(rss->key));
1741 rss->hash_types = efx_hash_types;
1743 sfc_adapter_unlock(sa);
1748 for (i = 0; i < key_i; i++) {
1749 if (efx_rx_scale_key_set(sa->nic, contexts[i], rss->key,
1750 sizeof(rss->key)) != 0)
1751 sfc_err(sa, "failed to restore RSS key");
1754 fail_scale_mode_set:
1755 for (i = 0; i < mode_i; i++) {
1756 if (efx_rx_scale_mode_set(sa->nic, contexts[i],
1757 EFX_RX_HASHALG_TOEPLITZ,
1758 rss->hash_types, B_TRUE) != 0)
1759 sfc_err(sa, "failed to restore RSS mode");
1762 fail_rx_hf_rte_to_efx:
1763 sfc_adapter_unlock(sa);
1768 * The function is used by the secondary process as well. It must not
1769 * use any process-local pointers from the adapter data.
1772 sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
1773 struct rte_eth_rss_reta_entry64 *reta_conf,
1776 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1777 struct sfc_rss *rss = &sas->rss;
1780 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE || sas->isolated)
1783 if (rss->channels == 0)
1786 if (reta_size != EFX_RSS_TBL_SIZE)
1789 for (entry = 0; entry < reta_size; entry++) {
1790 int grp = entry / RTE_RETA_GROUP_SIZE;
1791 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1793 if ((reta_conf[grp].mask >> grp_idx) & 1)
1794 reta_conf[grp].reta[grp_idx] = rss->tbl[entry];
1801 sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
1802 struct rte_eth_rss_reta_entry64 *reta_conf,
1805 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1806 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1807 unsigned int *rss_tbl_new;
1812 if (sfc_sa2shared(sa)->isolated)
1815 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1816 sfc_err(sa, "RSS is not available");
1820 if (rss->channels == 0) {
1821 sfc_err(sa, "RSS is not configured");
1825 if (reta_size != EFX_RSS_TBL_SIZE) {
1826 sfc_err(sa, "RETA size is wrong (should be %u)",
1831 rss_tbl_new = rte_zmalloc("rss_tbl_new", sizeof(rss->tbl), 0);
1832 if (rss_tbl_new == NULL)
1835 sfc_adapter_lock(sa);
1837 rte_memcpy(rss_tbl_new, rss->tbl, sizeof(rss->tbl));
1839 for (entry = 0; entry < reta_size; entry++) {
1840 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1841 struct rte_eth_rss_reta_entry64 *grp;
1843 grp = &reta_conf[entry / RTE_RETA_GROUP_SIZE];
1845 if (grp->mask & (1ull << grp_idx)) {
1846 if (grp->reta[grp_idx] >= rss->channels) {
1848 goto bad_reta_entry;
1850 rss_tbl_new[entry] = grp->reta[grp_idx];
1854 if (sa->state == SFC_ETHDEV_STARTED) {
1855 rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1856 rss_tbl_new, EFX_RSS_TBL_SIZE);
1858 goto fail_scale_tbl_set;
1861 rte_memcpy(rss->tbl, rss_tbl_new, sizeof(rss->tbl));
1865 sfc_adapter_unlock(sa);
1867 rte_free(rss_tbl_new);
1869 SFC_ASSERT(rc >= 0);
1874 sfc_dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
1875 const struct rte_flow_ops **ops)
1877 *ops = &sfc_flow_ops;
1882 sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
1884 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1887 * If Rx datapath does not provide callback to check mempool,
1888 * all pools are supported.
1890 if (sap->dp_rx->pool_ops_supported == NULL)
1893 return sap->dp_rx->pool_ops_supported(pool);
1897 sfc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1899 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1900 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1901 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1902 struct sfc_rxq_info *rxq_info;
1904 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1906 return sap->dp_rx->intr_enable(rxq_info->dp);
1910 sfc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1912 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1913 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1914 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1915 struct sfc_rxq_info *rxq_info;
1917 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1919 return sap->dp_rx->intr_disable(rxq_info->dp);
1922 struct sfc_mport_journal_ctx {
1923 struct sfc_adapter *sa;
1924 uint16_t switch_domain_id;
1925 uint32_t mcdi_handle;
1926 bool controllers_assigned;
1927 efx_pcie_interface_t *controllers;
1928 size_t nb_controllers;
1932 sfc_journal_ctx_add_controller(struct sfc_mport_journal_ctx *ctx,
1933 efx_pcie_interface_t intf)
1935 efx_pcie_interface_t *new_controllers;
1939 if (ctx->controllers == NULL) {
1940 ctx->controllers = rte_malloc("sfc_controller_mapping",
1941 sizeof(ctx->controllers[0]), 0);
1942 if (ctx->controllers == NULL)
1945 ctx->controllers[0] = intf;
1946 ctx->nb_controllers = 1;
1951 for (i = 0; i < ctx->nb_controllers; i++) {
1952 if (ctx->controllers[i] == intf)
1954 if (ctx->controllers[i] > intf)
1959 ctx->nb_controllers += 1;
1960 new_size = ctx->nb_controllers * sizeof(ctx->controllers[0]);
1962 new_controllers = rte_realloc(ctx->controllers, new_size, 0);
1963 if (new_controllers == NULL) {
1964 rte_free(ctx->controllers);
1967 ctx->controllers = new_controllers;
1969 for (i = target + 1; i < ctx->nb_controllers; i++)
1970 ctx->controllers[i] = ctx->controllers[i - 1];
1972 ctx->controllers[target] = intf;
1978 sfc_process_mport_journal_entry(struct sfc_mport_journal_ctx *ctx,
1979 efx_mport_desc_t *mport)
1981 efx_mport_sel_t ethdev_mport;
1985 "processing mport id %u (controller %u pf %u vf %u)",
1986 mport->emd_id.id, mport->emd_vnic.ev_intf,
1987 mport->emd_vnic.ev_pf, mport->emd_vnic.ev_vf);
1988 efx_mae_mport_invalid(ðdev_mport);
1990 if (!ctx->controllers_assigned) {
1991 rc = sfc_journal_ctx_add_controller(ctx,
1992 mport->emd_vnic.ev_intf);
2001 sfc_process_mport_journal_cb(void *data, efx_mport_desc_t *mport,
2004 struct sfc_mport_journal_ctx *ctx = data;
2006 if (ctx == NULL || ctx->sa == NULL) {
2007 sfc_err(ctx->sa, "received NULL context or SFC adapter");
2011 if (mport_len != sizeof(*mport)) {
2012 sfc_err(ctx->sa, "actual and expected mport buffer sizes differ");
2016 SFC_ASSERT(sfc_adapter_is_locked(ctx->sa));
2019 * If a zombie flag is set, it means the mport has been marked for
2020 * deletion and cannot be used for any new operations. The mport will
2021 * be destroyed completely once all references to it are released.
2023 if (mport->emd_zombie) {
2024 sfc_dbg(ctx->sa, "mport is a zombie, skipping");
2027 if (mport->emd_type != EFX_MPORT_TYPE_VNIC) {
2028 sfc_dbg(ctx->sa, "mport is not a VNIC, skipping");
2031 if (mport->emd_vnic.ev_client_type != EFX_MPORT_VNIC_CLIENT_FUNCTION) {
2032 sfc_dbg(ctx->sa, "mport is not a function, skipping");
2035 if (mport->emd_vnic.ev_handle == ctx->mcdi_handle) {
2036 sfc_dbg(ctx->sa, "mport is this driver instance, skipping");
2040 return sfc_process_mport_journal_entry(ctx, mport);
2044 sfc_process_mport_journal(struct sfc_adapter *sa)
2046 struct sfc_mport_journal_ctx ctx;
2047 const efx_pcie_interface_t *controllers;
2048 size_t nb_controllers;
2052 memset(&ctx, 0, sizeof(ctx));
2054 ctx.switch_domain_id = sa->mae.switch_domain_id;
2056 efx_rc = efx_mcdi_get_own_client_handle(sa->nic, &ctx.mcdi_handle);
2058 sfc_err(sa, "failed to get own MCDI handle");
2059 SFC_ASSERT(efx_rc > 0);
2063 rc = sfc_mae_switch_domain_controllers(ctx.switch_domain_id,
2064 &controllers, &nb_controllers);
2066 sfc_err(sa, "failed to get controller mapping");
2070 ctx.controllers_assigned = controllers != NULL;
2071 ctx.controllers = NULL;
2072 ctx.nb_controllers = 0;
2074 efx_rc = efx_mae_read_mport_journal(sa->nic,
2075 sfc_process_mport_journal_cb, &ctx);
2077 sfc_err(sa, "failed to process MAE mport journal");
2078 SFC_ASSERT(efx_rc > 0);
2082 if (controllers == NULL) {
2083 rc = sfc_mae_switch_domain_map_controllers(ctx.switch_domain_id,
2085 ctx.nb_controllers);
2093 static const struct eth_dev_ops sfc_eth_dev_ops = {
2094 .dev_configure = sfc_dev_configure,
2095 .dev_start = sfc_dev_start,
2096 .dev_stop = sfc_dev_stop,
2097 .dev_set_link_up = sfc_dev_set_link_up,
2098 .dev_set_link_down = sfc_dev_set_link_down,
2099 .dev_close = sfc_dev_close,
2100 .promiscuous_enable = sfc_dev_promisc_enable,
2101 .promiscuous_disable = sfc_dev_promisc_disable,
2102 .allmulticast_enable = sfc_dev_allmulti_enable,
2103 .allmulticast_disable = sfc_dev_allmulti_disable,
2104 .link_update = sfc_dev_link_update,
2105 .stats_get = sfc_stats_get,
2106 .stats_reset = sfc_stats_reset,
2107 .xstats_get = sfc_xstats_get,
2108 .xstats_reset = sfc_stats_reset,
2109 .xstats_get_names = sfc_xstats_get_names,
2110 .dev_infos_get = sfc_dev_infos_get,
2111 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
2112 .mtu_set = sfc_dev_set_mtu,
2113 .rx_queue_start = sfc_rx_queue_start,
2114 .rx_queue_stop = sfc_rx_queue_stop,
2115 .tx_queue_start = sfc_tx_queue_start,
2116 .tx_queue_stop = sfc_tx_queue_stop,
2117 .rx_queue_setup = sfc_rx_queue_setup,
2118 .rx_queue_release = sfc_rx_queue_release,
2119 .rx_queue_intr_enable = sfc_rx_queue_intr_enable,
2120 .rx_queue_intr_disable = sfc_rx_queue_intr_disable,
2121 .tx_queue_setup = sfc_tx_queue_setup,
2122 .tx_queue_release = sfc_tx_queue_release,
2123 .flow_ctrl_get = sfc_flow_ctrl_get,
2124 .flow_ctrl_set = sfc_flow_ctrl_set,
2125 .mac_addr_set = sfc_mac_addr_set,
2126 .udp_tunnel_port_add = sfc_dev_udp_tunnel_port_add,
2127 .udp_tunnel_port_del = sfc_dev_udp_tunnel_port_del,
2128 .reta_update = sfc_dev_rss_reta_update,
2129 .reta_query = sfc_dev_rss_reta_query,
2130 .rss_hash_update = sfc_dev_rss_hash_update,
2131 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
2132 .flow_ops_get = sfc_dev_flow_ops_get,
2133 .set_mc_addr_list = sfc_set_mc_addr_list,
2134 .rxq_info_get = sfc_rx_queue_info_get,
2135 .txq_info_get = sfc_tx_queue_info_get,
2136 .fw_version_get = sfc_fw_version_get,
2137 .xstats_get_by_id = sfc_xstats_get_by_id,
2138 .xstats_get_names_by_id = sfc_xstats_get_names_by_id,
2139 .pool_ops_supported = sfc_pool_ops_supported,
2142 struct sfc_ethdev_init_data {
2143 uint16_t nb_representors;
2147 * Duplicate a string in potentially shared memory required for
2148 * multi-process support.
2150 * strdup() allocates from process-local heap/memory.
2153 sfc_strdup(const char *str)
2161 size = strlen(str) + 1;
2162 copy = rte_malloc(__func__, size, 0);
2164 rte_memcpy(copy, str, size);
2170 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
2172 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2173 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2174 const struct sfc_dp_rx *dp_rx;
2175 const struct sfc_dp_tx *dp_tx;
2176 const efx_nic_cfg_t *encp;
2177 unsigned int avail_caps = 0;
2178 const char *rx_name = NULL;
2179 const char *tx_name = NULL;
2182 switch (sa->family) {
2183 case EFX_FAMILY_HUNTINGTON:
2184 case EFX_FAMILY_MEDFORD:
2185 case EFX_FAMILY_MEDFORD2:
2186 avail_caps |= SFC_DP_HW_FW_CAP_EF10;
2187 avail_caps |= SFC_DP_HW_FW_CAP_RX_EFX;
2188 avail_caps |= SFC_DP_HW_FW_CAP_TX_EFX;
2190 case EFX_FAMILY_RIVERHEAD:
2191 avail_caps |= SFC_DP_HW_FW_CAP_EF100;
2197 encp = efx_nic_cfg_get(sa->nic);
2198 if (encp->enc_rx_es_super_buffer_supported)
2199 avail_caps |= SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER;
2201 rc = sfc_kvargs_process(sa, SFC_KVARG_RX_DATAPATH,
2202 sfc_kvarg_string_handler, &rx_name);
2204 goto fail_kvarg_rx_datapath;
2206 if (rx_name != NULL) {
2207 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
2208 if (dp_rx == NULL) {
2209 sfc_err(sa, "Rx datapath %s not found", rx_name);
2213 if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
2215 "Insufficient Hw/FW capabilities to use Rx datapath %s",
2218 goto fail_dp_rx_caps;
2221 dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
2222 if (dp_rx == NULL) {
2223 sfc_err(sa, "Rx datapath by caps %#x not found",
2230 sas->dp_rx_name = sfc_strdup(dp_rx->dp.name);
2231 if (sas->dp_rx_name == NULL) {
2233 goto fail_dp_rx_name;
2236 sfc_notice(sa, "use %s Rx datapath", sas->dp_rx_name);
2238 rc = sfc_kvargs_process(sa, SFC_KVARG_TX_DATAPATH,
2239 sfc_kvarg_string_handler, &tx_name);
2241 goto fail_kvarg_tx_datapath;
2243 if (tx_name != NULL) {
2244 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
2245 if (dp_tx == NULL) {
2246 sfc_err(sa, "Tx datapath %s not found", tx_name);
2250 if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
2252 "Insufficient Hw/FW capabilities to use Tx datapath %s",
2255 goto fail_dp_tx_caps;
2258 dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
2259 if (dp_tx == NULL) {
2260 sfc_err(sa, "Tx datapath by caps %#x not found",
2267 sas->dp_tx_name = sfc_strdup(dp_tx->dp.name);
2268 if (sas->dp_tx_name == NULL) {
2270 goto fail_dp_tx_name;
2273 sfc_notice(sa, "use %s Tx datapath", sas->dp_tx_name);
2275 sa->priv.dp_rx = dp_rx;
2276 sa->priv.dp_tx = dp_tx;
2278 dev->rx_pkt_burst = dp_rx->pkt_burst;
2279 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2280 dev->tx_pkt_burst = dp_tx->pkt_burst;
2282 dev->rx_queue_count = sfc_rx_queue_count;
2283 dev->rx_descriptor_status = sfc_rx_descriptor_status;
2284 dev->tx_descriptor_status = sfc_tx_descriptor_status;
2285 dev->dev_ops = &sfc_eth_dev_ops;
2292 fail_kvarg_tx_datapath:
2293 rte_free(sas->dp_rx_name);
2294 sas->dp_rx_name = NULL;
2299 fail_kvarg_rx_datapath:
2304 sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
2306 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2307 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2309 dev->dev_ops = NULL;
2310 dev->tx_pkt_prepare = NULL;
2311 dev->rx_pkt_burst = NULL;
2312 dev->tx_pkt_burst = NULL;
2314 rte_free(sas->dp_tx_name);
2315 sas->dp_tx_name = NULL;
2316 sa->priv.dp_tx = NULL;
2318 rte_free(sas->dp_rx_name);
2319 sas->dp_rx_name = NULL;
2320 sa->priv.dp_rx = NULL;
2323 static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
2324 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
2325 .reta_query = sfc_dev_rss_reta_query,
2326 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
2327 .rxq_info_get = sfc_rx_queue_info_get,
2328 .txq_info_get = sfc_tx_queue_info_get,
2332 sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
2334 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2335 struct sfc_adapter_priv *sap;
2336 const struct sfc_dp_rx *dp_rx;
2337 const struct sfc_dp_tx *dp_tx;
2341 * Allocate process private data from heap, since it should not
2342 * be located in shared memory allocated using rte_malloc() API.
2344 sap = calloc(1, sizeof(*sap));
2347 goto fail_alloc_priv;
2350 sap->logtype_main = logtype_main;
2352 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sas->dp_rx_name);
2353 if (dp_rx == NULL) {
2354 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2355 "cannot find %s Rx datapath", sas->dp_rx_name);
2359 if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
2360 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2361 "%s Rx datapath does not support multi-process",
2364 goto fail_dp_rx_multi_process;
2367 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sas->dp_tx_name);
2368 if (dp_tx == NULL) {
2369 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2370 "cannot find %s Tx datapath", sas->dp_tx_name);
2374 if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
2375 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2376 "%s Tx datapath does not support multi-process",
2379 goto fail_dp_tx_multi_process;
2385 dev->process_private = sap;
2386 dev->rx_pkt_burst = dp_rx->pkt_burst;
2387 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2388 dev->tx_pkt_burst = dp_tx->pkt_burst;
2389 dev->rx_queue_count = sfc_rx_queue_count;
2390 dev->rx_descriptor_status = sfc_rx_descriptor_status;
2391 dev->tx_descriptor_status = sfc_tx_descriptor_status;
2392 dev->dev_ops = &sfc_eth_dev_secondary_ops;
2396 fail_dp_tx_multi_process:
2398 fail_dp_rx_multi_process:
2407 sfc_register_dp(void)
2410 if (TAILQ_EMPTY(&sfc_dp_head)) {
2411 /* Prefer EF10 datapath */
2412 sfc_dp_register(&sfc_dp_head, &sfc_ef100_rx.dp);
2413 sfc_dp_register(&sfc_dp_head, &sfc_ef10_essb_rx.dp);
2414 sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
2415 sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
2417 sfc_dp_register(&sfc_dp_head, &sfc_ef100_tx.dp);
2418 sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
2419 sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
2420 sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
2425 sfc_parse_switch_mode(struct sfc_adapter *sa, bool has_representors)
2427 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
2428 const char *switch_mode = NULL;
2431 sfc_log_init(sa, "entry");
2433 rc = sfc_kvargs_process(sa, SFC_KVARG_SWITCH_MODE,
2434 sfc_kvarg_string_handler, &switch_mode);
2438 if (switch_mode == NULL) {
2439 sa->switchdev = encp->enc_mae_supported &&
2440 (!encp->enc_datapath_cap_evb ||
2442 } else if (strcasecmp(switch_mode, SFC_KVARG_SWITCH_MODE_LEGACY) == 0) {
2443 sa->switchdev = false;
2444 } else if (strcasecmp(switch_mode,
2445 SFC_KVARG_SWITCH_MODE_SWITCHDEV) == 0) {
2446 sa->switchdev = true;
2448 sfc_err(sa, "invalid switch mode device argument '%s'",
2454 sfc_log_init(sa, "done");
2460 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
2466 sfc_eth_dev_init(struct rte_eth_dev *dev, void *init_params)
2468 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2469 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2470 struct sfc_ethdev_init_data *init_data = init_params;
2471 uint32_t logtype_main;
2472 struct sfc_adapter *sa;
2474 const efx_nic_cfg_t *encp;
2475 const struct rte_ether_addr *from;
2478 if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
2479 SFC_EFX_DEV_CLASS_NET) {
2480 SFC_GENERIC_LOG(DEBUG,
2481 "Incompatible device class: skip probing, should be probed by other sfc driver.");
2485 rc = sfc_dp_mport_register();
2491 logtype_main = sfc_register_logtype(&pci_dev->addr,
2492 SFC_LOGTYPE_MAIN_STR,
2495 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2496 return -sfc_eth_dev_secondary_init(dev, logtype_main);
2498 /* Required for logging */
2499 ret = snprintf(sas->log_prefix, sizeof(sas->log_prefix),
2500 "PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu16 ": ",
2501 pci_dev->addr.domain, pci_dev->addr.bus,
2502 pci_dev->addr.devid, pci_dev->addr.function,
2503 dev->data->port_id);
2504 if (ret < 0 || ret >= (int)sizeof(sas->log_prefix)) {
2505 SFC_GENERIC_LOG(ERR,
2506 "reserved log prefix is too short for " PCI_PRI_FMT,
2507 pci_dev->addr.domain, pci_dev->addr.bus,
2508 pci_dev->addr.devid, pci_dev->addr.function);
2511 sas->pci_addr = pci_dev->addr;
2512 sas->port_id = dev->data->port_id;
2515 * Allocate process private data from heap, since it should not
2516 * be located in shared memory allocated using rte_malloc() API.
2518 sa = calloc(1, sizeof(*sa));
2524 dev->process_private = sa;
2526 /* Required for logging */
2527 sa->priv.shared = sas;
2528 sa->priv.logtype_main = logtype_main;
2532 /* Copy PCI device info to the dev->data */
2533 rte_eth_copy_pci_info(dev, pci_dev);
2534 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2535 dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
2537 rc = sfc_kvargs_parse(sa);
2539 goto fail_kvargs_parse;
2541 sfc_log_init(sa, "entry");
2543 dev->data->mac_addrs = rte_zmalloc("sfc", RTE_ETHER_ADDR_LEN, 0);
2544 if (dev->data->mac_addrs == NULL) {
2546 goto fail_mac_addrs;
2549 sfc_adapter_lock_init(sa);
2550 sfc_adapter_lock(sa);
2552 sfc_log_init(sa, "probing");
2558 * Selecting a default switch mode requires the NIC to be probed and
2559 * to have its capabilities filled in.
2561 rc = sfc_parse_switch_mode(sa, init_data->nb_representors > 0);
2563 goto fail_switch_mode;
2565 sfc_log_init(sa, "set device ops");
2566 rc = sfc_eth_dev_set_ops(dev);
2570 sfc_log_init(sa, "attaching");
2571 rc = sfc_attach(sa);
2575 if (sa->switchdev && sa->mae.status != SFC_MAE_STATUS_SUPPORTED) {
2577 "failed to enable switchdev mode without MAE support");
2579 goto fail_switchdev_no_mae;
2582 encp = efx_nic_cfg_get(sa->nic);
2585 * The arguments are really reverse order in comparison to
2586 * Linux kernel. Copy from NIC config to Ethernet device data.
2588 from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
2589 rte_ether_addr_copy(from, &dev->data->mac_addrs[0]);
2591 sfc_adapter_unlock(sa);
2593 sfc_log_init(sa, "done");
2596 fail_switchdev_no_mae:
2600 sfc_eth_dev_clear_ops(dev);
2607 sfc_adapter_unlock(sa);
2608 sfc_adapter_lock_fini(sa);
2609 rte_free(dev->data->mac_addrs);
2610 dev->data->mac_addrs = NULL;
2613 sfc_kvargs_cleanup(sa);
2616 sfc_log_init(sa, "failed %d", rc);
2617 dev->process_private = NULL;
2626 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
2633 static const struct rte_pci_id pci_id_sfc_efx_map[] = {
2634 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
2635 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE_VF) },
2636 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
2637 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT_VF) },
2638 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
2639 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD_VF) },
2640 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2) },
2641 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2_VF) },
2642 { RTE_PCI_DEVICE(EFX_PCI_VENID_XILINX, EFX_PCI_DEVID_RIVERHEAD) },
2643 { .vendor_id = 0 /* sentinel */ }
2647 sfc_parse_rte_devargs(const char *args, struct rte_eth_devargs *devargs)
2649 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
2653 rc = rte_eth_devargs_parse(args, ð_da);
2655 SFC_GENERIC_LOG(ERR,
2656 "Failed to parse generic devargs '%s'",
2668 sfc_eth_dev_find_or_create(struct rte_pci_device *pci_dev,
2669 struct sfc_ethdev_init_data *init_data,
2670 struct rte_eth_dev **devp,
2673 struct rte_eth_dev *dev;
2674 bool created = false;
2677 dev = rte_eth_dev_allocated(pci_dev->device.name);
2679 rc = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
2680 sizeof(struct sfc_adapter_shared),
2681 eth_dev_pci_specific_init, pci_dev,
2682 sfc_eth_dev_init, init_data);
2684 SFC_GENERIC_LOG(ERR, "Failed to create sfc ethdev '%s'",
2685 pci_dev->device.name);
2691 dev = rte_eth_dev_allocated(pci_dev->device.name);
2693 SFC_GENERIC_LOG(ERR,
2694 "Failed to find allocated sfc ethdev '%s'",
2695 pci_dev->device.name);
2701 *dev_created = created;
2707 sfc_eth_dev_create_representors(struct rte_eth_dev *dev,
2708 const struct rte_eth_devargs *eth_da)
2710 struct sfc_adapter *sa;
2714 if (eth_da->nb_representor_ports == 0)
2717 sa = sfc_adapter_by_eth_dev(dev);
2719 if (!sa->switchdev) {
2720 sfc_err(sa, "cannot create representors in non-switchdev mode");
2724 if (!sfc_repr_available(sfc_sa2shared(sa))) {
2725 sfc_err(sa, "cannot create representors: unsupported");
2731 * This is needed to construct the DPDK controller -> EFX interface
2734 sfc_adapter_lock(sa);
2735 rc = sfc_process_mport_journal(sa);
2736 sfc_adapter_unlock(sa);
2742 for (i = 0; i < eth_da->nb_representor_ports; ++i) {
2743 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
2744 efx_mport_sel_t mport_sel;
2746 rc = efx_mae_mport_by_pcie_function(encp->enc_pf,
2747 eth_da->representor_ports[i], &mport_sel);
2750 "failed to get representor %u m-port: %s - ignore",
2751 eth_da->representor_ports[i],
2756 rc = sfc_repr_create(dev, eth_da->representor_ports[i],
2757 sa->mae.switch_domain_id, &mport_sel);
2759 sfc_err(sa, "cannot create representor %u: %s - ignore",
2760 eth_da->representor_ports[i],
2768 static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2769 struct rte_pci_device *pci_dev)
2771 struct sfc_ethdev_init_data init_data;
2772 struct rte_eth_devargs eth_da;
2773 struct rte_eth_dev *dev;
2777 if (pci_dev->device.devargs != NULL) {
2778 rc = sfc_parse_rte_devargs(pci_dev->device.devargs->args,
2783 memset(ð_da, 0, sizeof(eth_da));
2786 init_data.nb_representors = eth_da.nb_representor_ports;
2788 if (eth_da.nb_representor_ports > 0 &&
2789 rte_eal_process_type() != RTE_PROC_PRIMARY) {
2790 SFC_GENERIC_LOG(ERR,
2791 "Create representors from secondary process not supported, dev '%s'",
2792 pci_dev->device.name);
2797 * Driver supports RTE_PCI_DRV_PROBE_AGAIN. Hence create device only
2798 * if it does not already exist. Re-probing an existing device is
2799 * expected to allow additional representors to be configured.
2801 rc = sfc_eth_dev_find_or_create(pci_dev, &init_data, &dev,
2806 rc = sfc_eth_dev_create_representors(dev, ð_da);
2809 (void)rte_eth_dev_destroy(dev, sfc_eth_dev_uninit);
2817 static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2819 return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
2822 static struct rte_pci_driver sfc_efx_pmd = {
2823 .id_table = pci_id_sfc_efx_map,
2825 RTE_PCI_DRV_INTR_LSC |
2826 RTE_PCI_DRV_NEED_MAPPING |
2827 RTE_PCI_DRV_PROBE_AGAIN,
2828 .probe = sfc_eth_dev_pci_probe,
2829 .remove = sfc_eth_dev_pci_remove,
2832 RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
2833 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
2834 RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
2835 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
2836 SFC_KVARG_SWITCH_MODE "=" SFC_KVARG_VALUES_SWITCH_MODE " "
2837 SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
2838 SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
2839 SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
2840 SFC_KVARG_FW_VARIANT "=" SFC_KVARG_VALUES_FW_VARIANT " "
2841 SFC_KVARG_RXD_WAIT_TIMEOUT_NS "=<long> "
2842 SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long>");
2844 RTE_INIT(sfc_driver_register_logtype)
2848 ret = rte_log_register_type_and_pick_level(SFC_LOGTYPE_PREFIX "driver",
2850 sfc_logtype_driver = (ret < 0) ? RTE_LOGTYPE_PMD : ret;