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"
31 #include "sfc_sw_stats.h"
33 #define SFC_XSTAT_ID_INVALID_VAL UINT64_MAX
34 #define SFC_XSTAT_ID_INVALID_NAME '\0'
36 uint32_t sfc_logtype_driver;
38 static struct sfc_dp_list sfc_dp_head =
39 TAILQ_HEAD_INITIALIZER(sfc_dp_head);
42 static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
46 sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
48 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
49 efx_nic_fw_info_t enfi;
53 rc = efx_nic_get_fw_version(sa->nic, &enfi);
57 ret = snprintf(fw_version, fw_size,
58 "%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
59 enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
60 enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
64 if (enfi.enfi_dpcpu_fw_ids_valid) {
65 size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
68 ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
69 fw_size - dpcpu_fw_ids_offset,
70 " rx%" PRIx16 " tx%" PRIx16,
71 enfi.enfi_rx_dpcpu_fw_id,
72 enfi.enfi_tx_dpcpu_fw_id);
79 if (fw_size < (size_t)(++ret))
86 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
88 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
89 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
90 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
91 struct sfc_rss *rss = &sas->rss;
92 struct sfc_mae *mae = &sa->mae;
93 uint64_t txq_offloads_def = 0;
95 sfc_log_init(sa, "entry");
97 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
98 dev_info->max_mtu = EFX_MAC_SDU_MAX;
100 dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
102 dev_info->max_vfs = sa->sriov.num_vfs;
104 /* Autonegotiation may be disabled */
105 dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
106 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
107 dev_info->speed_capa |= ETH_LINK_SPEED_1G;
108 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
109 dev_info->speed_capa |= ETH_LINK_SPEED_10G;
110 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
111 dev_info->speed_capa |= ETH_LINK_SPEED_25G;
112 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
113 dev_info->speed_capa |= ETH_LINK_SPEED_40G;
114 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
115 dev_info->speed_capa |= ETH_LINK_SPEED_50G;
116 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
117 dev_info->speed_capa |= ETH_LINK_SPEED_100G;
119 dev_info->max_rx_queues = sa->rxq_max;
120 dev_info->max_tx_queues = sa->txq_max;
122 /* By default packets are dropped if no descriptors are available */
123 dev_info->default_rxconf.rx_drop_en = 1;
125 dev_info->rx_queue_offload_capa = sfc_rx_get_queue_offload_caps(sa);
128 * rx_offload_capa includes both device and queue offloads since
129 * the latter may be requested on a per device basis which makes
130 * sense when some offloads are needed to be set on all queues.
132 dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
133 dev_info->rx_queue_offload_capa;
135 dev_info->tx_queue_offload_capa = sfc_tx_get_queue_offload_caps(sa);
138 * tx_offload_capa includes both device and queue offloads since
139 * the latter may be requested on a per device basis which makes
140 * sense when some offloads are needed to be set on all queues.
142 dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
143 dev_info->tx_queue_offload_capa;
145 if (dev_info->tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
146 txq_offloads_def |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
148 dev_info->default_txconf.offloads |= txq_offloads_def;
150 if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
154 for (i = 0; i < rss->hf_map_nb_entries; ++i)
155 rte_hf |= rss->hf_map[i].rte;
157 dev_info->reta_size = EFX_RSS_TBL_SIZE;
158 dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
159 dev_info->flow_type_rss_offloads = rte_hf;
162 /* Initialize to hardware limits */
163 dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
164 dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
165 /* The RXQ hardware requires that the descriptor count is a power
166 * of 2, but rx_desc_lim cannot properly describe that constraint.
168 dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
170 /* Initialize to hardware limits */
171 dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
172 dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
174 * The TXQ hardware requires that the descriptor count is a power
175 * of 2, but tx_desc_lim cannot properly describe that constraint
177 dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
179 if (sap->dp_rx->get_dev_info != NULL)
180 sap->dp_rx->get_dev_info(dev_info);
181 if (sap->dp_tx->get_dev_info != NULL)
182 sap->dp_tx->get_dev_info(dev_info);
184 dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
185 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
187 if (mae->status == SFC_MAE_STATUS_SUPPORTED) {
188 dev_info->switch_info.name = dev->device->driver->name;
189 dev_info->switch_info.domain_id = mae->switch_domain_id;
190 dev_info->switch_info.port_id = mae->switch_port_id;
196 static const uint32_t *
197 sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
199 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
201 return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps);
205 sfc_dev_configure(struct rte_eth_dev *dev)
207 struct rte_eth_dev_data *dev_data = dev->data;
208 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
211 sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
212 dev_data->nb_rx_queues, dev_data->nb_tx_queues);
214 sfc_adapter_lock(sa);
216 case SFC_ADAPTER_CONFIGURED:
218 case SFC_ADAPTER_INITIALIZED:
219 rc = sfc_configure(sa);
222 sfc_err(sa, "unexpected adapter state %u to configure",
227 sfc_adapter_unlock(sa);
229 sfc_log_init(sa, "done %d", rc);
235 sfc_dev_start(struct rte_eth_dev *dev)
237 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
240 sfc_log_init(sa, "entry");
242 sfc_adapter_lock(sa);
244 sfc_adapter_unlock(sa);
246 sfc_log_init(sa, "done %d", rc);
252 sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
254 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
255 struct rte_eth_link current_link;
258 sfc_log_init(sa, "entry");
260 if (sa->state != SFC_ADAPTER_STARTED) {
261 sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, ¤t_link);
262 } else if (wait_to_complete) {
263 efx_link_mode_t link_mode;
265 if (efx_port_poll(sa->nic, &link_mode) != 0)
266 link_mode = EFX_LINK_UNKNOWN;
267 sfc_port_link_mode_to_info(link_mode, ¤t_link);
270 sfc_ev_mgmt_qpoll(sa);
271 rte_eth_linkstatus_get(dev, ¤t_link);
274 ret = rte_eth_linkstatus_set(dev, ¤t_link);
276 sfc_notice(sa, "Link status is %s",
277 current_link.link_status ? "UP" : "DOWN");
283 sfc_dev_stop(struct rte_eth_dev *dev)
285 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
287 sfc_log_init(sa, "entry");
289 sfc_adapter_lock(sa);
291 sfc_adapter_unlock(sa);
293 sfc_log_init(sa, "done");
299 sfc_dev_set_link_up(struct rte_eth_dev *dev)
301 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
304 sfc_log_init(sa, "entry");
306 sfc_adapter_lock(sa);
308 sfc_adapter_unlock(sa);
315 sfc_dev_set_link_down(struct rte_eth_dev *dev)
317 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
319 sfc_log_init(sa, "entry");
321 sfc_adapter_lock(sa);
323 sfc_adapter_unlock(sa);
329 sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
331 free(dev->process_private);
332 rte_eth_dev_release_port(dev);
336 sfc_dev_close(struct rte_eth_dev *dev)
338 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
340 sfc_log_init(sa, "entry");
342 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
343 sfc_eth_dev_secondary_clear_ops(dev);
347 sfc_adapter_lock(sa);
349 case SFC_ADAPTER_STARTED:
351 SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED);
353 case SFC_ADAPTER_CONFIGURED:
355 SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
357 case SFC_ADAPTER_INITIALIZED:
360 sfc_err(sa, "unexpected adapter state %u on close", sa->state);
365 * Cleanup all resources.
366 * Rollback primary process sfc_eth_dev_init() below.
369 sfc_eth_dev_clear_ops(dev);
374 sfc_kvargs_cleanup(sa);
376 sfc_adapter_unlock(sa);
377 sfc_adapter_lock_fini(sa);
379 sfc_log_init(sa, "done");
381 /* Required for logging, so cleanup last */
390 sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
393 struct sfc_port *port;
395 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
396 boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
397 const char *desc = (allmulti) ? "all-multi" : "promiscuous";
400 sfc_adapter_lock(sa);
403 toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
405 if (*toggle != enabled) {
408 if (sfc_sa2shared(sa)->isolated) {
409 sfc_warn(sa, "isolated mode is active on the port");
410 sfc_warn(sa, "the change is to be applied on the next "
411 "start provided that isolated mode is "
412 "disabled prior the next start");
413 } else if ((sa->state == SFC_ADAPTER_STARTED) &&
414 ((rc = sfc_set_rx_mode(sa)) != 0)) {
415 *toggle = !(enabled);
416 sfc_warn(sa, "Failed to %s %s mode, rc = %d",
417 ((enabled) ? "enable" : "disable"), desc, rc);
420 * For promiscuous and all-multicast filters a
421 * permission failure should be reported as an
422 * unsupported filter.
429 sfc_adapter_unlock(sa);
434 sfc_dev_promisc_enable(struct rte_eth_dev *dev)
436 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
443 sfc_dev_promisc_disable(struct rte_eth_dev *dev)
445 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
452 sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
454 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
461 sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
463 int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
470 sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
471 uint16_t nb_rx_desc, unsigned int socket_id,
472 const struct rte_eth_rxconf *rx_conf,
473 struct rte_mempool *mb_pool)
475 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
476 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
477 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
478 struct sfc_rxq_info *rxq_info;
479 sfc_sw_index_t sw_index;
482 sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
483 ethdev_qid, nb_rx_desc, socket_id);
485 sfc_adapter_lock(sa);
487 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
488 rc = sfc_rx_qinit(sa, sw_index, nb_rx_desc, socket_id,
493 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
494 dev->data->rx_queues[ethdev_qid] = rxq_info->dp;
496 sfc_adapter_unlock(sa);
501 sfc_adapter_unlock(sa);
507 sfc_rx_queue_release(void *queue)
509 struct sfc_dp_rxq *dp_rxq = queue;
511 struct sfc_adapter *sa;
512 sfc_sw_index_t sw_index;
517 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
519 sfc_adapter_lock(sa);
521 sw_index = dp_rxq->dpq.queue_id;
523 sfc_log_init(sa, "RxQ=%u", sw_index);
525 sfc_rx_qfini(sa, sw_index);
527 sfc_adapter_unlock(sa);
531 sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
532 uint16_t nb_tx_desc, unsigned int socket_id,
533 const struct rte_eth_txconf *tx_conf)
535 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
536 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
537 struct sfc_txq_info *txq_info;
538 sfc_sw_index_t sw_index;
541 sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
542 ethdev_qid, nb_tx_desc, socket_id);
544 sfc_adapter_lock(sa);
546 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
547 rc = sfc_tx_qinit(sa, sw_index, nb_tx_desc, socket_id, tx_conf);
551 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
552 dev->data->tx_queues[ethdev_qid] = txq_info->dp;
554 sfc_adapter_unlock(sa);
558 sfc_adapter_unlock(sa);
564 sfc_tx_queue_release(void *queue)
566 struct sfc_dp_txq *dp_txq = queue;
568 sfc_sw_index_t sw_index;
569 struct sfc_adapter *sa;
574 txq = sfc_txq_by_dp_txq(dp_txq);
575 sw_index = dp_txq->dpq.queue_id;
577 SFC_ASSERT(txq->evq != NULL);
580 sfc_log_init(sa, "TxQ = %u", sw_index);
582 sfc_adapter_lock(sa);
584 sfc_tx_qfini(sa, sw_index);
586 sfc_adapter_unlock(sa);
590 * Some statistics are computed as A - B where A and B each increase
591 * monotonically with some hardware counter(s) and the counters are read
594 * If packet X is counted in A, but not counted in B yet, computed value is
597 * If packet X is not counted in A at the moment of reading the counter,
598 * but counted in B at the moment of reading the counter, computed value
601 * However, counter which grows backward is worse evil than slightly wrong
602 * value. So, let's try to guarantee that it never happens except may be
603 * the case when the MAC stats are zeroed as a result of a NIC reset.
606 sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
608 if ((int64_t)(newval - *stat) > 0 || newval == 0)
613 sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
615 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
616 struct sfc_port *port = &sa->port;
620 sfc_adapter_lock(sa);
622 ret = sfc_port_update_mac_stats(sa, B_FALSE);
626 mac_stats = port->mac_stats_buf;
628 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
629 EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
631 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
632 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
633 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
635 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
636 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
637 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
639 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
640 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
641 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
643 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
644 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
645 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
646 stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
647 stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
649 /* CRC is included in these stats, but shouldn't be */
650 stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
651 stats->obytes -= stats->opackets * RTE_ETHER_CRC_LEN;
653 stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
654 stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS];
655 stats->obytes = mac_stats[EFX_MAC_TX_OCTETS];
657 /* CRC is included in these stats, but shouldn't be */
658 stats->ibytes -= mac_stats[EFX_MAC_RX_PKTS] * RTE_ETHER_CRC_LEN;
659 stats->obytes -= mac_stats[EFX_MAC_TX_PKTS] * RTE_ETHER_CRC_LEN;
662 * Take into account stats which are whenever supported
663 * on EF10. If some stat is not supported by current
664 * firmware variant or HW revision, it is guaranteed
665 * to be zero in mac_stats.
668 mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
669 mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
670 mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
671 mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
672 mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
673 mac_stats[EFX_MAC_PM_TRUNC_QBB] +
674 mac_stats[EFX_MAC_PM_DISCARD_QBB] +
675 mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
676 mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
677 mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
679 mac_stats[EFX_MAC_RX_FCS_ERRORS] +
680 mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
681 mac_stats[EFX_MAC_RX_JABBER_PKTS];
682 /* no oerrors counters supported on EF10 */
684 /* Exclude missed, errors and pauses from Rx packets */
685 sfc_update_diff_stat(&port->ipackets,
686 mac_stats[EFX_MAC_RX_PKTS] -
687 mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
688 stats->imissed - stats->ierrors);
689 stats->ipackets = port->ipackets;
693 sfc_adapter_unlock(sa);
694 SFC_ASSERT(ret >= 0);
699 sfc_stats_reset(struct rte_eth_dev *dev)
701 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
702 struct sfc_port *port = &sa->port;
705 sfc_adapter_lock(sa);
707 if (sa->state != SFC_ADAPTER_STARTED) {
709 * The operation cannot be done if port is not started; it
710 * will be scheduled to be done during the next port start
712 port->mac_stats_reset_pending = B_TRUE;
713 sfc_adapter_unlock(sa);
717 rc = sfc_port_reset_mac_stats(sa);
719 sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
721 sfc_sw_xstats_reset(sa);
723 sfc_adapter_unlock(sa);
730 sfc_xstats_get_nb_supported(struct sfc_adapter *sa)
732 struct sfc_port *port = &sa->port;
733 unsigned int nb_supported;
735 sfc_adapter_lock(sa);
736 nb_supported = port->mac_stats_nb_supported +
737 sfc_sw_xstats_get_nb_supported(sa);
738 sfc_adapter_unlock(sa);
744 sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
745 unsigned int xstats_count)
747 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
748 unsigned int nb_written = 0;
749 unsigned int nb_supported = 0;
752 if (unlikely(xstats == NULL))
753 return sfc_xstats_get_nb_supported(sa);
755 rc = sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written);
760 sfc_sw_xstats_get_vals(sa, xstats, xstats_count, &nb_written,
767 sfc_xstats_get_names(struct rte_eth_dev *dev,
768 struct rte_eth_xstat_name *xstats_names,
769 unsigned int xstats_count)
771 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
772 struct sfc_port *port = &sa->port;
774 unsigned int nstats = 0;
775 unsigned int nb_written = 0;
778 if (unlikely(xstats_names == NULL))
779 return sfc_xstats_get_nb_supported(sa);
781 for (i = 0; i < EFX_MAC_NSTATS; ++i) {
782 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
783 if (nstats < xstats_count) {
784 strlcpy(xstats_names[nstats].name,
785 efx_mac_stat_name(sa->nic, i),
786 sizeof(xstats_names[0].name));
793 ret = sfc_sw_xstats_get_names(sa, xstats_names, xstats_count,
794 &nb_written, &nstats);
804 sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
805 uint64_t *values, unsigned int n)
807 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
808 struct sfc_port *port = &sa->port;
809 unsigned int nb_supported;
813 if (unlikely(ids == NULL || values == NULL))
817 * Values array could be filled in nonsequential order. Fill values with
818 * constant indicating invalid ID first.
820 for (i = 0; i < n; i++)
821 values[i] = SFC_XSTAT_ID_INVALID_VAL;
823 rc = sfc_port_get_mac_stats_by_id(sa, ids, values, n);
827 nb_supported = port->mac_stats_nb_supported;
828 sfc_sw_xstats_get_vals_by_id(sa, ids, values, n, &nb_supported);
830 /* Return number of written stats before invalid ID is encountered. */
831 for (i = 0; i < n; i++) {
832 if (values[i] == SFC_XSTAT_ID_INVALID_VAL)
840 sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
841 struct rte_eth_xstat_name *xstats_names,
842 const uint64_t *ids, unsigned int size)
844 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
845 struct sfc_port *port = &sa->port;
846 unsigned int nb_supported;
850 if (unlikely(xstats_names == NULL && ids != NULL) ||
851 unlikely(xstats_names != NULL && ids == NULL))
854 if (unlikely(xstats_names == NULL && ids == NULL))
855 return sfc_xstats_get_nb_supported(sa);
858 * Names array could be filled in nonsequential order. Fill names with
859 * string indicating invalid ID first.
861 for (i = 0; i < size; i++)
862 xstats_names[i].name[0] = SFC_XSTAT_ID_INVALID_NAME;
864 sfc_adapter_lock(sa);
866 SFC_ASSERT(port->mac_stats_nb_supported <=
867 RTE_DIM(port->mac_stats_by_id));
869 for (i = 0; i < size; i++) {
870 if (ids[i] < port->mac_stats_nb_supported) {
871 strlcpy(xstats_names[i].name,
872 efx_mac_stat_name(sa->nic,
873 port->mac_stats_by_id[ids[i]]),
874 sizeof(xstats_names[0].name));
878 nb_supported = port->mac_stats_nb_supported;
880 sfc_adapter_unlock(sa);
882 ret = sfc_sw_xstats_get_names_by_id(sa, ids, xstats_names, size,
889 /* Return number of written names before invalid ID is encountered. */
890 for (i = 0; i < size; i++) {
891 if (xstats_names[i].name[0] == SFC_XSTAT_ID_INVALID_NAME)
899 sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
901 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
902 unsigned int wanted_fc, link_fc;
904 memset(fc_conf, 0, sizeof(*fc_conf));
906 sfc_adapter_lock(sa);
908 if (sa->state == SFC_ADAPTER_STARTED)
909 efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
911 link_fc = sa->port.flow_ctrl;
915 fc_conf->mode = RTE_FC_NONE;
917 case EFX_FCNTL_RESPOND:
918 fc_conf->mode = RTE_FC_RX_PAUSE;
920 case EFX_FCNTL_GENERATE:
921 fc_conf->mode = RTE_FC_TX_PAUSE;
923 case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
924 fc_conf->mode = RTE_FC_FULL;
927 sfc_err(sa, "%s: unexpected flow control value %#x",
931 fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
933 sfc_adapter_unlock(sa);
939 sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
941 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
942 struct sfc_port *port = &sa->port;
946 if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
947 fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
948 fc_conf->mac_ctrl_frame_fwd != 0) {
949 sfc_err(sa, "unsupported flow control settings specified");
954 switch (fc_conf->mode) {
958 case RTE_FC_RX_PAUSE:
959 fcntl = EFX_FCNTL_RESPOND;
961 case RTE_FC_TX_PAUSE:
962 fcntl = EFX_FCNTL_GENERATE;
965 fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
972 sfc_adapter_lock(sa);
974 if (sa->state == SFC_ADAPTER_STARTED) {
975 rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
977 goto fail_mac_fcntl_set;
980 port->flow_ctrl = fcntl;
981 port->flow_ctrl_autoneg = fc_conf->autoneg;
983 sfc_adapter_unlock(sa);
988 sfc_adapter_unlock(sa);
995 sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
997 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
998 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
999 boolean_t scatter_enabled;
1003 for (i = 0; i < sas->rxq_count; i++) {
1004 if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
1007 scatter_enabled = (sas->rxq_info[i].type_flags &
1008 EFX_RXQ_FLAG_SCATTER);
1010 if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
1011 encp->enc_rx_prefix_size,
1013 encp->enc_rx_scatter_max, &error)) {
1014 sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
1024 sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1026 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1027 size_t pdu = EFX_MAC_PDU(mtu);
1031 sfc_log_init(sa, "mtu=%u", mtu);
1034 if (pdu < EFX_MAC_PDU_MIN) {
1035 sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
1036 (unsigned int)mtu, (unsigned int)pdu,
1040 if (pdu > EFX_MAC_PDU_MAX) {
1041 sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
1042 (unsigned int)mtu, (unsigned int)pdu,
1043 (unsigned int)EFX_MAC_PDU_MAX);
1047 sfc_adapter_lock(sa);
1049 rc = sfc_check_scatter_on_all_rx_queues(sa, pdu);
1051 goto fail_check_scatter;
1053 if (pdu != sa->port.pdu) {
1054 if (sa->state == SFC_ADAPTER_STARTED) {
1057 old_pdu = sa->port.pdu;
1068 * The driver does not use it, but other PMDs update jumbo frame
1069 * flag and max_rx_pkt_len when MTU is set.
1071 if (mtu > RTE_ETHER_MTU) {
1072 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1073 rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1076 dev->data->dev_conf.rxmode.max_rx_pkt_len = sa->port.pdu;
1078 sfc_adapter_unlock(sa);
1080 sfc_log_init(sa, "done");
1084 sa->port.pdu = old_pdu;
1085 if (sfc_start(sa) != 0)
1086 sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
1087 "PDU max size - port is stopped",
1088 (unsigned int)pdu, (unsigned int)old_pdu);
1091 sfc_adapter_unlock(sa);
1094 sfc_log_init(sa, "failed %d", rc);
1099 sfc_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1101 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1102 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1103 struct sfc_port *port = &sa->port;
1104 struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
1107 sfc_adapter_lock(sa);
1109 if (rte_is_same_ether_addr(mac_addr, &port->default_mac_addr))
1113 * Copy the address to the device private data so that
1114 * it could be recalled in the case of adapter restart.
1116 rte_ether_addr_copy(mac_addr, &port->default_mac_addr);
1119 * Neither of the two following checks can return
1120 * an error. The new MAC address is preserved in
1121 * the device private data and can be activated
1122 * on the next port start if the user prevents
1123 * isolated mode from being enabled.
1125 if (sfc_sa2shared(sa)->isolated) {
1126 sfc_warn(sa, "isolated mode is active on the port");
1127 sfc_warn(sa, "will not set MAC address");
1131 if (sa->state != SFC_ADAPTER_STARTED) {
1132 sfc_notice(sa, "the port is not started");
1133 sfc_notice(sa, "the new MAC address will be set on port start");
1138 if (encp->enc_allow_set_mac_with_installed_filters) {
1139 rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
1141 sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
1146 * Changing the MAC address by means of MCDI request
1147 * has no effect on received traffic, therefore
1148 * we also need to update unicast filters
1150 rc = sfc_set_rx_mode_unchecked(sa);
1152 sfc_err(sa, "cannot set filter (rc = %u)", rc);
1153 /* Rollback the old address */
1154 (void)efx_mac_addr_set(sa->nic, old_addr->addr_bytes);
1155 (void)sfc_set_rx_mode_unchecked(sa);
1158 sfc_warn(sa, "cannot set MAC address with filters installed");
1159 sfc_warn(sa, "adapter will be restarted to pick the new MAC");
1160 sfc_warn(sa, "(some traffic may be dropped)");
1163 * Since setting MAC address with filters installed is not
1164 * allowed on the adapter, the new MAC address will be set
1165 * by means of adapter restart. sfc_start() shall retrieve
1166 * the new address from the device private data and set it.
1171 sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
1176 rte_ether_addr_copy(old_addr, &port->default_mac_addr);
1178 sfc_adapter_unlock(sa);
1180 SFC_ASSERT(rc >= 0);
1186 sfc_set_mc_addr_list(struct rte_eth_dev *dev,
1187 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1189 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1190 struct sfc_port *port = &sa->port;
1191 uint8_t *mc_addrs = port->mcast_addrs;
1195 if (sfc_sa2shared(sa)->isolated) {
1196 sfc_err(sa, "isolated mode is active on the port");
1197 sfc_err(sa, "will not set multicast address list");
1201 if (mc_addrs == NULL)
1204 if (nb_mc_addr > port->max_mcast_addrs) {
1205 sfc_err(sa, "too many multicast addresses: %u > %u",
1206 nb_mc_addr, port->max_mcast_addrs);
1210 for (i = 0; i < nb_mc_addr; ++i) {
1211 rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
1213 mc_addrs += EFX_MAC_ADDR_LEN;
1216 port->nb_mcast_addrs = nb_mc_addr;
1218 if (sa->state != SFC_ADAPTER_STARTED)
1221 rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
1222 port->nb_mcast_addrs);
1224 sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
1226 SFC_ASSERT(rc >= 0);
1231 * The function is used by the secondary process as well. It must not
1232 * use any process-local pointers from the adapter data.
1235 sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1236 struct rte_eth_rxq_info *qinfo)
1238 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1239 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1240 struct sfc_rxq_info *rxq_info;
1242 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1244 qinfo->mp = rxq_info->refill_mb_pool;
1245 qinfo->conf.rx_free_thresh = rxq_info->refill_threshold;
1246 qinfo->conf.rx_drop_en = 1;
1247 qinfo->conf.rx_deferred_start = rxq_info->deferred_start;
1248 qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
1249 if (rxq_info->type_flags & EFX_RXQ_FLAG_SCATTER) {
1250 qinfo->conf.offloads |= DEV_RX_OFFLOAD_SCATTER;
1251 qinfo->scattered_rx = 1;
1253 qinfo->nb_desc = rxq_info->entries;
1257 * The function is used by the secondary process as well. It must not
1258 * use any process-local pointers from the adapter data.
1261 sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1262 struct rte_eth_txq_info *qinfo)
1264 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1265 struct sfc_txq_info *txq_info;
1267 SFC_ASSERT(ethdev_qid < sas->ethdev_txq_count);
1269 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1271 memset(qinfo, 0, sizeof(*qinfo));
1273 qinfo->conf.offloads = txq_info->offloads;
1274 qinfo->conf.tx_free_thresh = txq_info->free_thresh;
1275 qinfo->conf.tx_deferred_start = txq_info->deferred_start;
1276 qinfo->nb_desc = txq_info->entries;
1280 * The function is used by the secondary process as well. It must not
1281 * use any process-local pointers from the adapter data.
1284 sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1286 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1287 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1288 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1289 struct sfc_rxq_info *rxq_info;
1291 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1293 if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
1296 return sap->dp_rx->qdesc_npending(rxq_info->dp);
1300 * The function is used by the secondary process as well. It must not
1301 * use any process-local pointers from the adapter data.
1304 sfc_rx_descriptor_done(void *queue, uint16_t offset)
1306 struct sfc_dp_rxq *dp_rxq = queue;
1307 const struct sfc_dp_rx *dp_rx;
1309 dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1311 return offset < dp_rx->qdesc_npending(dp_rxq);
1315 * The function is used by the secondary process as well. It must not
1316 * use any process-local pointers from the adapter data.
1319 sfc_rx_descriptor_status(void *queue, uint16_t offset)
1321 struct sfc_dp_rxq *dp_rxq = queue;
1322 const struct sfc_dp_rx *dp_rx;
1324 dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1326 return dp_rx->qdesc_status(dp_rxq, offset);
1330 * The function is used by the secondary process as well. It must not
1331 * use any process-local pointers from the adapter data.
1334 sfc_tx_descriptor_status(void *queue, uint16_t offset)
1336 struct sfc_dp_txq *dp_txq = queue;
1337 const struct sfc_dp_tx *dp_tx;
1339 dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
1341 return dp_tx->qdesc_status(dp_txq, offset);
1345 sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1347 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1348 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1349 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1350 struct sfc_rxq_info *rxq_info;
1351 sfc_sw_index_t sw_index;
1354 sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1356 sfc_adapter_lock(sa);
1359 if (sa->state != SFC_ADAPTER_STARTED)
1360 goto fail_not_started;
1362 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1363 if (rxq_info->state != SFC_RXQ_INITIALIZED)
1364 goto fail_not_setup;
1366 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1367 rc = sfc_rx_qstart(sa, sw_index);
1369 goto fail_rx_qstart;
1371 rxq_info->deferred_started = B_TRUE;
1373 sfc_adapter_unlock(sa);
1380 sfc_adapter_unlock(sa);
1386 sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1388 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1389 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1390 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1391 struct sfc_rxq_info *rxq_info;
1392 sfc_sw_index_t sw_index;
1394 sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1396 sfc_adapter_lock(sa);
1398 sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1399 sfc_rx_qstop(sa, sw_index);
1401 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1402 rxq_info->deferred_started = B_FALSE;
1404 sfc_adapter_unlock(sa);
1410 sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1412 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1413 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1414 struct sfc_txq_info *txq_info;
1415 sfc_sw_index_t sw_index;
1418 sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1420 sfc_adapter_lock(sa);
1423 if (sa->state != SFC_ADAPTER_STARTED)
1424 goto fail_not_started;
1426 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1427 if (txq_info->state != SFC_TXQ_INITIALIZED)
1428 goto fail_not_setup;
1430 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1431 rc = sfc_tx_qstart(sa, sw_index);
1433 goto fail_tx_qstart;
1435 txq_info->deferred_started = B_TRUE;
1437 sfc_adapter_unlock(sa);
1444 sfc_adapter_unlock(sa);
1450 sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1452 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1453 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1454 struct sfc_txq_info *txq_info;
1455 sfc_sw_index_t sw_index;
1457 sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1459 sfc_adapter_lock(sa);
1461 sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1462 sfc_tx_qstop(sa, sw_index);
1464 txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1465 txq_info->deferred_started = B_FALSE;
1467 sfc_adapter_unlock(sa);
1471 static efx_tunnel_protocol_t
1472 sfc_tunnel_rte_type_to_efx_udp_proto(enum rte_eth_tunnel_type rte_type)
1475 case RTE_TUNNEL_TYPE_VXLAN:
1476 return EFX_TUNNEL_PROTOCOL_VXLAN;
1477 case RTE_TUNNEL_TYPE_GENEVE:
1478 return EFX_TUNNEL_PROTOCOL_GENEVE;
1480 return EFX_TUNNEL_NPROTOS;
1484 enum sfc_udp_tunnel_op_e {
1485 SFC_UDP_TUNNEL_ADD_PORT,
1486 SFC_UDP_TUNNEL_DEL_PORT,
1490 sfc_dev_udp_tunnel_op(struct rte_eth_dev *dev,
1491 struct rte_eth_udp_tunnel *tunnel_udp,
1492 enum sfc_udp_tunnel_op_e op)
1494 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1495 efx_tunnel_protocol_t tunnel_proto;
1498 sfc_log_init(sa, "%s udp_port=%u prot_type=%u",
1499 (op == SFC_UDP_TUNNEL_ADD_PORT) ? "add" :
1500 (op == SFC_UDP_TUNNEL_DEL_PORT) ? "delete" : "unknown",
1501 tunnel_udp->udp_port, tunnel_udp->prot_type);
1504 sfc_tunnel_rte_type_to_efx_udp_proto(tunnel_udp->prot_type);
1505 if (tunnel_proto >= EFX_TUNNEL_NPROTOS) {
1507 goto fail_bad_proto;
1510 sfc_adapter_lock(sa);
1513 case SFC_UDP_TUNNEL_ADD_PORT:
1514 rc = efx_tunnel_config_udp_add(sa->nic,
1515 tunnel_udp->udp_port,
1518 case SFC_UDP_TUNNEL_DEL_PORT:
1519 rc = efx_tunnel_config_udp_remove(sa->nic,
1520 tunnel_udp->udp_port,
1531 if (sa->state == SFC_ADAPTER_STARTED) {
1532 rc = efx_tunnel_reconfigure(sa->nic);
1535 * Configuration is accepted by FW and MC reboot
1536 * is initiated to apply the changes. MC reboot
1537 * will be handled in a usual way (MC reboot
1538 * event on management event queue and adapter
1542 } else if (rc != 0) {
1543 goto fail_reconfigure;
1547 sfc_adapter_unlock(sa);
1551 /* Remove/restore entry since the change makes the trouble */
1553 case SFC_UDP_TUNNEL_ADD_PORT:
1554 (void)efx_tunnel_config_udp_remove(sa->nic,
1555 tunnel_udp->udp_port,
1558 case SFC_UDP_TUNNEL_DEL_PORT:
1559 (void)efx_tunnel_config_udp_add(sa->nic,
1560 tunnel_udp->udp_port,
1567 sfc_adapter_unlock(sa);
1575 sfc_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
1576 struct rte_eth_udp_tunnel *tunnel_udp)
1578 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_ADD_PORT);
1582 sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1583 struct rte_eth_udp_tunnel *tunnel_udp)
1585 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
1589 * The function is used by the secondary process as well. It must not
1590 * use any process-local pointers from the adapter data.
1593 sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1594 struct rte_eth_rss_conf *rss_conf)
1596 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1597 struct sfc_rss *rss = &sas->rss;
1599 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE)
1603 * Mapping of hash configuration between RTE and EFX is not one-to-one,
1604 * hence, conversion is done here to derive a correct set of ETH_RSS
1605 * flags which corresponds to the active EFX configuration stored
1606 * locally in 'sfc_adapter' and kept up-to-date
1608 rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(rss, rss->hash_types);
1609 rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
1610 if (rss_conf->rss_key != NULL)
1611 rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
1617 sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
1618 struct rte_eth_rss_conf *rss_conf)
1620 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1621 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1622 unsigned int efx_hash_types;
1623 uint32_t contexts[] = {EFX_RSS_CONTEXT_DEFAULT, rss->dummy_rss_context};
1624 unsigned int n_contexts;
1625 unsigned int mode_i = 0;
1626 unsigned int key_i = 0;
1630 n_contexts = rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT ? 1 : 2;
1632 if (sfc_sa2shared(sa)->isolated)
1635 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1636 sfc_err(sa, "RSS is not available");
1640 if (rss->channels == 0) {
1641 sfc_err(sa, "RSS is not configured");
1645 if ((rss_conf->rss_key != NULL) &&
1646 (rss_conf->rss_key_len != sizeof(rss->key))) {
1647 sfc_err(sa, "RSS key size is wrong (should be %zu)",
1652 sfc_adapter_lock(sa);
1654 rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
1656 goto fail_rx_hf_rte_to_efx;
1658 for (mode_i = 0; mode_i < n_contexts; mode_i++) {
1659 rc = efx_rx_scale_mode_set(sa->nic, contexts[mode_i],
1660 rss->hash_alg, efx_hash_types,
1663 goto fail_scale_mode_set;
1666 if (rss_conf->rss_key != NULL) {
1667 if (sa->state == SFC_ADAPTER_STARTED) {
1668 for (key_i = 0; key_i < n_contexts; key_i++) {
1669 rc = efx_rx_scale_key_set(sa->nic,
1674 goto fail_scale_key_set;
1678 rte_memcpy(rss->key, rss_conf->rss_key, sizeof(rss->key));
1681 rss->hash_types = efx_hash_types;
1683 sfc_adapter_unlock(sa);
1688 for (i = 0; i < key_i; i++) {
1689 if (efx_rx_scale_key_set(sa->nic, contexts[i], rss->key,
1690 sizeof(rss->key)) != 0)
1691 sfc_err(sa, "failed to restore RSS key");
1694 fail_scale_mode_set:
1695 for (i = 0; i < mode_i; i++) {
1696 if (efx_rx_scale_mode_set(sa->nic, contexts[i],
1697 EFX_RX_HASHALG_TOEPLITZ,
1698 rss->hash_types, B_TRUE) != 0)
1699 sfc_err(sa, "failed to restore RSS mode");
1702 fail_rx_hf_rte_to_efx:
1703 sfc_adapter_unlock(sa);
1708 * The function is used by the secondary process as well. It must not
1709 * use any process-local pointers from the adapter data.
1712 sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
1713 struct rte_eth_rss_reta_entry64 *reta_conf,
1716 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1717 struct sfc_rss *rss = &sas->rss;
1720 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE || sas->isolated)
1723 if (rss->channels == 0)
1726 if (reta_size != EFX_RSS_TBL_SIZE)
1729 for (entry = 0; entry < reta_size; entry++) {
1730 int grp = entry / RTE_RETA_GROUP_SIZE;
1731 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1733 if ((reta_conf[grp].mask >> grp_idx) & 1)
1734 reta_conf[grp].reta[grp_idx] = rss->tbl[entry];
1741 sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
1742 struct rte_eth_rss_reta_entry64 *reta_conf,
1745 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1746 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1747 unsigned int *rss_tbl_new;
1752 if (sfc_sa2shared(sa)->isolated)
1755 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1756 sfc_err(sa, "RSS is not available");
1760 if (rss->channels == 0) {
1761 sfc_err(sa, "RSS is not configured");
1765 if (reta_size != EFX_RSS_TBL_SIZE) {
1766 sfc_err(sa, "RETA size is wrong (should be %u)",
1771 rss_tbl_new = rte_zmalloc("rss_tbl_new", sizeof(rss->tbl), 0);
1772 if (rss_tbl_new == NULL)
1775 sfc_adapter_lock(sa);
1777 rte_memcpy(rss_tbl_new, rss->tbl, sizeof(rss->tbl));
1779 for (entry = 0; entry < reta_size; entry++) {
1780 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1781 struct rte_eth_rss_reta_entry64 *grp;
1783 grp = &reta_conf[entry / RTE_RETA_GROUP_SIZE];
1785 if (grp->mask & (1ull << grp_idx)) {
1786 if (grp->reta[grp_idx] >= rss->channels) {
1788 goto bad_reta_entry;
1790 rss_tbl_new[entry] = grp->reta[grp_idx];
1794 if (sa->state == SFC_ADAPTER_STARTED) {
1795 rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1796 rss_tbl_new, EFX_RSS_TBL_SIZE);
1798 goto fail_scale_tbl_set;
1801 rte_memcpy(rss->tbl, rss_tbl_new, sizeof(rss->tbl));
1805 sfc_adapter_unlock(sa);
1807 rte_free(rss_tbl_new);
1809 SFC_ASSERT(rc >= 0);
1814 sfc_dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
1815 const struct rte_flow_ops **ops)
1817 *ops = &sfc_flow_ops;
1822 sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
1824 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1827 * If Rx datapath does not provide callback to check mempool,
1828 * all pools are supported.
1830 if (sap->dp_rx->pool_ops_supported == NULL)
1833 return sap->dp_rx->pool_ops_supported(pool);
1837 sfc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1839 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1840 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1841 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1842 struct sfc_rxq_info *rxq_info;
1844 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1846 return sap->dp_rx->intr_enable(rxq_info->dp);
1850 sfc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1852 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1853 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1854 sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1855 struct sfc_rxq_info *rxq_info;
1857 rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1859 return sap->dp_rx->intr_disable(rxq_info->dp);
1862 static const struct eth_dev_ops sfc_eth_dev_ops = {
1863 .dev_configure = sfc_dev_configure,
1864 .dev_start = sfc_dev_start,
1865 .dev_stop = sfc_dev_stop,
1866 .dev_set_link_up = sfc_dev_set_link_up,
1867 .dev_set_link_down = sfc_dev_set_link_down,
1868 .dev_close = sfc_dev_close,
1869 .promiscuous_enable = sfc_dev_promisc_enable,
1870 .promiscuous_disable = sfc_dev_promisc_disable,
1871 .allmulticast_enable = sfc_dev_allmulti_enable,
1872 .allmulticast_disable = sfc_dev_allmulti_disable,
1873 .link_update = sfc_dev_link_update,
1874 .stats_get = sfc_stats_get,
1875 .stats_reset = sfc_stats_reset,
1876 .xstats_get = sfc_xstats_get,
1877 .xstats_reset = sfc_stats_reset,
1878 .xstats_get_names = sfc_xstats_get_names,
1879 .dev_infos_get = sfc_dev_infos_get,
1880 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
1881 .mtu_set = sfc_dev_set_mtu,
1882 .rx_queue_start = sfc_rx_queue_start,
1883 .rx_queue_stop = sfc_rx_queue_stop,
1884 .tx_queue_start = sfc_tx_queue_start,
1885 .tx_queue_stop = sfc_tx_queue_stop,
1886 .rx_queue_setup = sfc_rx_queue_setup,
1887 .rx_queue_release = sfc_rx_queue_release,
1888 .rx_queue_intr_enable = sfc_rx_queue_intr_enable,
1889 .rx_queue_intr_disable = sfc_rx_queue_intr_disable,
1890 .tx_queue_setup = sfc_tx_queue_setup,
1891 .tx_queue_release = sfc_tx_queue_release,
1892 .flow_ctrl_get = sfc_flow_ctrl_get,
1893 .flow_ctrl_set = sfc_flow_ctrl_set,
1894 .mac_addr_set = sfc_mac_addr_set,
1895 .udp_tunnel_port_add = sfc_dev_udp_tunnel_port_add,
1896 .udp_tunnel_port_del = sfc_dev_udp_tunnel_port_del,
1897 .reta_update = sfc_dev_rss_reta_update,
1898 .reta_query = sfc_dev_rss_reta_query,
1899 .rss_hash_update = sfc_dev_rss_hash_update,
1900 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
1901 .flow_ops_get = sfc_dev_flow_ops_get,
1902 .set_mc_addr_list = sfc_set_mc_addr_list,
1903 .rxq_info_get = sfc_rx_queue_info_get,
1904 .txq_info_get = sfc_tx_queue_info_get,
1905 .fw_version_get = sfc_fw_version_get,
1906 .xstats_get_by_id = sfc_xstats_get_by_id,
1907 .xstats_get_names_by_id = sfc_xstats_get_names_by_id,
1908 .pool_ops_supported = sfc_pool_ops_supported,
1912 * Duplicate a string in potentially shared memory required for
1913 * multi-process support.
1915 * strdup() allocates from process-local heap/memory.
1918 sfc_strdup(const char *str)
1926 size = strlen(str) + 1;
1927 copy = rte_malloc(__func__, size, 0);
1929 rte_memcpy(copy, str, size);
1935 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
1937 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1938 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1939 const struct sfc_dp_rx *dp_rx;
1940 const struct sfc_dp_tx *dp_tx;
1941 const efx_nic_cfg_t *encp;
1942 unsigned int avail_caps = 0;
1943 const char *rx_name = NULL;
1944 const char *tx_name = NULL;
1947 switch (sa->family) {
1948 case EFX_FAMILY_HUNTINGTON:
1949 case EFX_FAMILY_MEDFORD:
1950 case EFX_FAMILY_MEDFORD2:
1951 avail_caps |= SFC_DP_HW_FW_CAP_EF10;
1952 avail_caps |= SFC_DP_HW_FW_CAP_RX_EFX;
1953 avail_caps |= SFC_DP_HW_FW_CAP_TX_EFX;
1955 case EFX_FAMILY_RIVERHEAD:
1956 avail_caps |= SFC_DP_HW_FW_CAP_EF100;
1962 encp = efx_nic_cfg_get(sa->nic);
1963 if (encp->enc_rx_es_super_buffer_supported)
1964 avail_caps |= SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER;
1966 rc = sfc_kvargs_process(sa, SFC_KVARG_RX_DATAPATH,
1967 sfc_kvarg_string_handler, &rx_name);
1969 goto fail_kvarg_rx_datapath;
1971 if (rx_name != NULL) {
1972 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
1973 if (dp_rx == NULL) {
1974 sfc_err(sa, "Rx datapath %s not found", rx_name);
1978 if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
1980 "Insufficient Hw/FW capabilities to use Rx datapath %s",
1983 goto fail_dp_rx_caps;
1986 dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
1987 if (dp_rx == NULL) {
1988 sfc_err(sa, "Rx datapath by caps %#x not found",
1995 sas->dp_rx_name = sfc_strdup(dp_rx->dp.name);
1996 if (sas->dp_rx_name == NULL) {
1998 goto fail_dp_rx_name;
2001 sfc_notice(sa, "use %s Rx datapath", sas->dp_rx_name);
2003 rc = sfc_kvargs_process(sa, SFC_KVARG_TX_DATAPATH,
2004 sfc_kvarg_string_handler, &tx_name);
2006 goto fail_kvarg_tx_datapath;
2008 if (tx_name != NULL) {
2009 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
2010 if (dp_tx == NULL) {
2011 sfc_err(sa, "Tx datapath %s not found", tx_name);
2015 if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
2017 "Insufficient Hw/FW capabilities to use Tx datapath %s",
2020 goto fail_dp_tx_caps;
2023 dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
2024 if (dp_tx == NULL) {
2025 sfc_err(sa, "Tx datapath by caps %#x not found",
2032 sas->dp_tx_name = sfc_strdup(dp_tx->dp.name);
2033 if (sas->dp_tx_name == NULL) {
2035 goto fail_dp_tx_name;
2038 sfc_notice(sa, "use %s Tx datapath", sas->dp_tx_name);
2040 sa->priv.dp_rx = dp_rx;
2041 sa->priv.dp_tx = dp_tx;
2043 dev->rx_pkt_burst = dp_rx->pkt_burst;
2044 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2045 dev->tx_pkt_burst = dp_tx->pkt_burst;
2047 dev->rx_queue_count = sfc_rx_queue_count;
2048 dev->rx_descriptor_done = sfc_rx_descriptor_done;
2049 dev->rx_descriptor_status = sfc_rx_descriptor_status;
2050 dev->tx_descriptor_status = sfc_tx_descriptor_status;
2051 dev->dev_ops = &sfc_eth_dev_ops;
2058 fail_kvarg_tx_datapath:
2059 rte_free(sas->dp_rx_name);
2060 sas->dp_rx_name = NULL;
2065 fail_kvarg_rx_datapath:
2070 sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
2072 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2073 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2075 dev->dev_ops = NULL;
2076 dev->tx_pkt_prepare = NULL;
2077 dev->rx_pkt_burst = NULL;
2078 dev->tx_pkt_burst = NULL;
2080 rte_free(sas->dp_tx_name);
2081 sas->dp_tx_name = NULL;
2082 sa->priv.dp_tx = NULL;
2084 rte_free(sas->dp_rx_name);
2085 sas->dp_rx_name = NULL;
2086 sa->priv.dp_rx = NULL;
2089 static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
2090 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
2091 .reta_query = sfc_dev_rss_reta_query,
2092 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
2093 .rxq_info_get = sfc_rx_queue_info_get,
2094 .txq_info_get = sfc_tx_queue_info_get,
2098 sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
2100 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2101 struct sfc_adapter_priv *sap;
2102 const struct sfc_dp_rx *dp_rx;
2103 const struct sfc_dp_tx *dp_tx;
2107 * Allocate process private data from heap, since it should not
2108 * be located in shared memory allocated using rte_malloc() API.
2110 sap = calloc(1, sizeof(*sap));
2113 goto fail_alloc_priv;
2116 sap->logtype_main = logtype_main;
2118 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sas->dp_rx_name);
2119 if (dp_rx == NULL) {
2120 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2121 "cannot find %s Rx datapath", sas->dp_rx_name);
2125 if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
2126 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2127 "%s Rx datapath does not support multi-process",
2130 goto fail_dp_rx_multi_process;
2133 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sas->dp_tx_name);
2134 if (dp_tx == NULL) {
2135 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2136 "cannot find %s Tx datapath", sas->dp_tx_name);
2140 if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
2141 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2142 "%s Tx datapath does not support multi-process",
2145 goto fail_dp_tx_multi_process;
2151 dev->process_private = sap;
2152 dev->rx_pkt_burst = dp_rx->pkt_burst;
2153 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2154 dev->tx_pkt_burst = dp_tx->pkt_burst;
2155 dev->rx_queue_count = sfc_rx_queue_count;
2156 dev->rx_descriptor_done = sfc_rx_descriptor_done;
2157 dev->rx_descriptor_status = sfc_rx_descriptor_status;
2158 dev->tx_descriptor_status = sfc_tx_descriptor_status;
2159 dev->dev_ops = &sfc_eth_dev_secondary_ops;
2163 fail_dp_tx_multi_process:
2165 fail_dp_rx_multi_process:
2174 sfc_register_dp(void)
2177 if (TAILQ_EMPTY(&sfc_dp_head)) {
2178 /* Prefer EF10 datapath */
2179 sfc_dp_register(&sfc_dp_head, &sfc_ef100_rx.dp);
2180 sfc_dp_register(&sfc_dp_head, &sfc_ef10_essb_rx.dp);
2181 sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
2182 sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
2184 sfc_dp_register(&sfc_dp_head, &sfc_ef100_tx.dp);
2185 sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
2186 sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
2187 sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
2192 sfc_eth_dev_init(struct rte_eth_dev *dev)
2194 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2195 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2196 uint32_t logtype_main;
2197 struct sfc_adapter *sa;
2199 const efx_nic_cfg_t *encp;
2200 const struct rte_ether_addr *from;
2203 if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
2204 SFC_EFX_DEV_CLASS_NET) {
2205 SFC_GENERIC_LOG(DEBUG,
2206 "Incompatible device class: skip probing, should be probed by other sfc driver.");
2212 logtype_main = sfc_register_logtype(&pci_dev->addr,
2213 SFC_LOGTYPE_MAIN_STR,
2216 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2217 return -sfc_eth_dev_secondary_init(dev, logtype_main);
2219 /* Required for logging */
2220 ret = snprintf(sas->log_prefix, sizeof(sas->log_prefix),
2221 "PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu16 ": ",
2222 pci_dev->addr.domain, pci_dev->addr.bus,
2223 pci_dev->addr.devid, pci_dev->addr.function,
2224 dev->data->port_id);
2225 if (ret < 0 || ret >= (int)sizeof(sas->log_prefix)) {
2226 SFC_GENERIC_LOG(ERR,
2227 "reserved log prefix is too short for " PCI_PRI_FMT,
2228 pci_dev->addr.domain, pci_dev->addr.bus,
2229 pci_dev->addr.devid, pci_dev->addr.function);
2232 sas->pci_addr = pci_dev->addr;
2233 sas->port_id = dev->data->port_id;
2236 * Allocate process private data from heap, since it should not
2237 * be located in shared memory allocated using rte_malloc() API.
2239 sa = calloc(1, sizeof(*sa));
2245 dev->process_private = sa;
2247 /* Required for logging */
2248 sa->priv.shared = sas;
2249 sa->priv.logtype_main = logtype_main;
2253 /* Copy PCI device info to the dev->data */
2254 rte_eth_copy_pci_info(dev, pci_dev);
2255 dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2256 dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
2258 rc = sfc_kvargs_parse(sa);
2260 goto fail_kvargs_parse;
2262 sfc_log_init(sa, "entry");
2264 dev->data->mac_addrs = rte_zmalloc("sfc", RTE_ETHER_ADDR_LEN, 0);
2265 if (dev->data->mac_addrs == NULL) {
2267 goto fail_mac_addrs;
2270 sfc_adapter_lock_init(sa);
2271 sfc_adapter_lock(sa);
2273 sfc_log_init(sa, "probing");
2278 sfc_log_init(sa, "set device ops");
2279 rc = sfc_eth_dev_set_ops(dev);
2283 sfc_log_init(sa, "attaching");
2284 rc = sfc_attach(sa);
2288 encp = efx_nic_cfg_get(sa->nic);
2291 * The arguments are really reverse order in comparison to
2292 * Linux kernel. Copy from NIC config to Ethernet device data.
2294 from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
2295 rte_ether_addr_copy(from, &dev->data->mac_addrs[0]);
2297 sfc_adapter_unlock(sa);
2299 sfc_log_init(sa, "done");
2303 sfc_eth_dev_clear_ops(dev);
2309 sfc_adapter_unlock(sa);
2310 sfc_adapter_lock_fini(sa);
2311 rte_free(dev->data->mac_addrs);
2312 dev->data->mac_addrs = NULL;
2315 sfc_kvargs_cleanup(sa);
2318 sfc_log_init(sa, "failed %d", rc);
2319 dev->process_private = NULL;
2328 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
2335 static const struct rte_pci_id pci_id_sfc_efx_map[] = {
2336 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
2337 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE_VF) },
2338 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
2339 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT_VF) },
2340 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
2341 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD_VF) },
2342 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2) },
2343 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2_VF) },
2344 { RTE_PCI_DEVICE(EFX_PCI_VENID_XILINX, EFX_PCI_DEVID_RIVERHEAD) },
2345 { .vendor_id = 0 /* sentinel */ }
2348 static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2349 struct rte_pci_device *pci_dev)
2351 return rte_eth_dev_pci_generic_probe(pci_dev,
2352 sizeof(struct sfc_adapter_shared), sfc_eth_dev_init);
2355 static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2357 return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
2360 static struct rte_pci_driver sfc_efx_pmd = {
2361 .id_table = pci_id_sfc_efx_map,
2363 RTE_PCI_DRV_INTR_LSC |
2364 RTE_PCI_DRV_NEED_MAPPING,
2365 .probe = sfc_eth_dev_pci_probe,
2366 .remove = sfc_eth_dev_pci_remove,
2369 RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
2370 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
2371 RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
2372 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
2373 SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
2374 SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
2375 SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
2376 SFC_KVARG_FW_VARIANT "=" SFC_KVARG_VALUES_FW_VARIANT " "
2377 SFC_KVARG_RXD_WAIT_TIMEOUT_NS "=<long> "
2378 SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long>");
2380 RTE_INIT(sfc_driver_register_logtype)
2384 ret = rte_log_register_type_and_pick_level(SFC_LOGTYPE_PREFIX "driver",
2386 sfc_logtype_driver = (ret < 0) ? RTE_LOGTYPE_PMD : ret;