1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
11 #include <rte_ethdev_driver.h>
12 #include <rte_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 uint32_t sfc_logtype_driver;
34 static struct sfc_dp_list sfc_dp_head =
35 TAILQ_HEAD_INITIALIZER(sfc_dp_head);
38 static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
42 sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
44 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
45 efx_nic_fw_info_t enfi;
50 * Return value of the callback is likely supposed to be
51 * equal to or greater than 0, nevertheless, if an error
52 * occurs, it will be desirable to pass it to the caller
54 if ((fw_version == NULL) || (fw_size == 0))
57 rc = efx_nic_get_fw_version(sa->nic, &enfi);
61 ret = snprintf(fw_version, fw_size,
62 "%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
63 enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
64 enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
68 if (enfi.enfi_dpcpu_fw_ids_valid) {
69 size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
72 ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
73 fw_size - dpcpu_fw_ids_offset,
74 " rx%" PRIx16 " tx%" PRIx16,
75 enfi.enfi_rx_dpcpu_fw_id,
76 enfi.enfi_tx_dpcpu_fw_id);
83 if (fw_size < (size_t)(++ret))
90 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
92 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
93 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
94 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
95 struct sfc_rss *rss = &sas->rss;
96 uint64_t txq_offloads_def = 0;
98 sfc_log_init(sa, "entry");
100 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
101 dev_info->max_mtu = EFX_MAC_SDU_MAX;
103 dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
105 /* Autonegotiation may be disabled */
106 dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
107 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
108 dev_info->speed_capa |= ETH_LINK_SPEED_1G;
109 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
110 dev_info->speed_capa |= ETH_LINK_SPEED_10G;
111 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
112 dev_info->speed_capa |= ETH_LINK_SPEED_25G;
113 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
114 dev_info->speed_capa |= ETH_LINK_SPEED_40G;
115 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
116 dev_info->speed_capa |= ETH_LINK_SPEED_50G;
117 if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
118 dev_info->speed_capa |= ETH_LINK_SPEED_100G;
120 dev_info->max_rx_queues = sa->rxq_max;
121 dev_info->max_tx_queues = sa->txq_max;
123 /* By default packets are dropped if no descriptors are available */
124 dev_info->default_rxconf.rx_drop_en = 1;
126 dev_info->rx_queue_offload_capa = sfc_rx_get_queue_offload_caps(sa);
129 * rx_offload_capa includes both device and queue offloads since
130 * the latter may be requested on a per device basis which makes
131 * sense when some offloads are needed to be set on all queues.
133 dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
134 dev_info->rx_queue_offload_capa;
136 dev_info->tx_queue_offload_capa = sfc_tx_get_queue_offload_caps(sa);
139 * tx_offload_capa includes both device and queue offloads since
140 * the latter may be requested on a per device basis which makes
141 * sense when some offloads are needed to be set on all queues.
143 dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
144 dev_info->tx_queue_offload_capa;
146 if (dev_info->tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
147 txq_offloads_def |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
149 dev_info->default_txconf.offloads |= txq_offloads_def;
151 if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
155 for (i = 0; i < rss->hf_map_nb_entries; ++i)
156 rte_hf |= rss->hf_map[i].rte;
158 dev_info->reta_size = EFX_RSS_TBL_SIZE;
159 dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
160 dev_info->flow_type_rss_offloads = rte_hf;
163 /* Initialize to hardware limits */
164 dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
165 dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
166 /* The RXQ hardware requires that the descriptor count is a power
167 * of 2, but rx_desc_lim cannot properly describe that constraint.
169 dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
171 /* Initialize to hardware limits */
172 dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
173 dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
175 * The TXQ hardware requires that the descriptor count is a power
176 * of 2, but tx_desc_lim cannot properly describe that constraint
178 dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
180 if (sap->dp_rx->get_dev_info != NULL)
181 sap->dp_rx->get_dev_info(dev_info);
182 if (sap->dp_tx->get_dev_info != NULL)
183 sap->dp_tx->get_dev_info(dev_info);
185 dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
186 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
189 static const uint32_t *
190 sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
192 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
194 return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps);
198 sfc_dev_configure(struct rte_eth_dev *dev)
200 struct rte_eth_dev_data *dev_data = dev->data;
201 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
204 sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
205 dev_data->nb_rx_queues, dev_data->nb_tx_queues);
207 sfc_adapter_lock(sa);
209 case SFC_ADAPTER_CONFIGURED:
211 case SFC_ADAPTER_INITIALIZED:
212 rc = sfc_configure(sa);
215 sfc_err(sa, "unexpected adapter state %u to configure",
220 sfc_adapter_unlock(sa);
222 sfc_log_init(sa, "done %d", rc);
228 sfc_dev_start(struct rte_eth_dev *dev)
230 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
233 sfc_log_init(sa, "entry");
235 sfc_adapter_lock(sa);
237 sfc_adapter_unlock(sa);
239 sfc_log_init(sa, "done %d", rc);
245 sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
247 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
248 struct rte_eth_link current_link;
251 sfc_log_init(sa, "entry");
253 if (sa->state != SFC_ADAPTER_STARTED) {
254 sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, ¤t_link);
255 } else if (wait_to_complete) {
256 efx_link_mode_t link_mode;
258 if (efx_port_poll(sa->nic, &link_mode) != 0)
259 link_mode = EFX_LINK_UNKNOWN;
260 sfc_port_link_mode_to_info(link_mode, ¤t_link);
263 sfc_ev_mgmt_qpoll(sa);
264 rte_eth_linkstatus_get(dev, ¤t_link);
267 ret = rte_eth_linkstatus_set(dev, ¤t_link);
269 sfc_notice(sa, "Link status is %s",
270 current_link.link_status ? "UP" : "DOWN");
276 sfc_dev_stop(struct rte_eth_dev *dev)
278 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
280 sfc_log_init(sa, "entry");
282 sfc_adapter_lock(sa);
284 sfc_adapter_unlock(sa);
286 sfc_log_init(sa, "done");
290 sfc_dev_set_link_up(struct rte_eth_dev *dev)
292 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
295 sfc_log_init(sa, "entry");
297 sfc_adapter_lock(sa);
299 sfc_adapter_unlock(sa);
306 sfc_dev_set_link_down(struct rte_eth_dev *dev)
308 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
310 sfc_log_init(sa, "entry");
312 sfc_adapter_lock(sa);
314 sfc_adapter_unlock(sa);
320 sfc_dev_close(struct rte_eth_dev *dev)
322 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
324 sfc_log_init(sa, "entry");
326 sfc_adapter_lock(sa);
328 case SFC_ADAPTER_STARTED:
330 SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED);
332 case SFC_ADAPTER_CONFIGURED:
334 SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
336 case SFC_ADAPTER_INITIALIZED:
339 sfc_err(sa, "unexpected adapter state %u on close", sa->state);
344 * Cleanup all resources in accordance with RTE_ETH_DEV_CLOSE_REMOVE.
345 * Rollback primary process sfc_eth_dev_init() below.
348 sfc_eth_dev_clear_ops(dev);
353 sfc_kvargs_cleanup(sa);
355 sfc_adapter_unlock(sa);
356 sfc_adapter_lock_fini(sa);
358 sfc_log_init(sa, "done");
360 /* Required for logging, so cleanup last */
363 dev->process_private = NULL;
368 sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
371 struct sfc_port *port;
373 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
374 boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
375 const char *desc = (allmulti) ? "all-multi" : "promiscuous";
377 sfc_adapter_lock(sa);
380 toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
382 if (*toggle != enabled) {
385 if (sfc_sa2shared(sa)->isolated) {
386 sfc_warn(sa, "isolated mode is active on the port");
387 sfc_warn(sa, "the change is to be applied on the next "
388 "start provided that isolated mode is "
389 "disabled prior the next start");
390 } else if ((sa->state == SFC_ADAPTER_STARTED) &&
391 (sfc_set_rx_mode(sa) != 0)) {
392 *toggle = !(enabled);
393 sfc_warn(sa, "Failed to %s %s mode",
394 ((enabled) ? "enable" : "disable"), desc);
398 sfc_adapter_unlock(sa);
402 sfc_dev_promisc_enable(struct rte_eth_dev *dev)
404 sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
408 sfc_dev_promisc_disable(struct rte_eth_dev *dev)
410 sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
414 sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
416 sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
420 sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
422 sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
426 sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
427 uint16_t nb_rx_desc, unsigned int socket_id,
428 const struct rte_eth_rxconf *rx_conf,
429 struct rte_mempool *mb_pool)
431 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
432 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
435 sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
436 rx_queue_id, nb_rx_desc, socket_id);
438 sfc_adapter_lock(sa);
440 rc = sfc_rx_qinit(sa, rx_queue_id, nb_rx_desc, socket_id,
445 dev->data->rx_queues[rx_queue_id] = sas->rxq_info[rx_queue_id].dp;
447 sfc_adapter_unlock(sa);
452 sfc_adapter_unlock(sa);
458 sfc_rx_queue_release(void *queue)
460 struct sfc_dp_rxq *dp_rxq = queue;
462 struct sfc_adapter *sa;
463 unsigned int sw_index;
468 rxq = sfc_rxq_by_dp_rxq(dp_rxq);
470 sfc_adapter_lock(sa);
472 sw_index = dp_rxq->dpq.queue_id;
474 sfc_log_init(sa, "RxQ=%u", sw_index);
476 sfc_rx_qfini(sa, sw_index);
478 sfc_adapter_unlock(sa);
482 sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
483 uint16_t nb_tx_desc, unsigned int socket_id,
484 const struct rte_eth_txconf *tx_conf)
486 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
487 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
490 sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
491 tx_queue_id, nb_tx_desc, socket_id);
493 sfc_adapter_lock(sa);
495 rc = sfc_tx_qinit(sa, tx_queue_id, nb_tx_desc, socket_id, tx_conf);
499 dev->data->tx_queues[tx_queue_id] = sas->txq_info[tx_queue_id].dp;
501 sfc_adapter_unlock(sa);
505 sfc_adapter_unlock(sa);
511 sfc_tx_queue_release(void *queue)
513 struct sfc_dp_txq *dp_txq = queue;
515 unsigned int sw_index;
516 struct sfc_adapter *sa;
521 txq = sfc_txq_by_dp_txq(dp_txq);
522 sw_index = dp_txq->dpq.queue_id;
524 SFC_ASSERT(txq->evq != NULL);
527 sfc_log_init(sa, "TxQ = %u", sw_index);
529 sfc_adapter_lock(sa);
531 sfc_tx_qfini(sa, sw_index);
533 sfc_adapter_unlock(sa);
537 * Some statistics are computed as A - B where A and B each increase
538 * monotonically with some hardware counter(s) and the counters are read
541 * If packet X is counted in A, but not counted in B yet, computed value is
544 * If packet X is not counted in A at the moment of reading the counter,
545 * but counted in B at the moment of reading the counter, computed value
548 * However, counter which grows backward is worse evil than slightly wrong
549 * value. So, let's try to guarantee that it never happens except may be
550 * the case when the MAC stats are zeroed as a result of a NIC reset.
553 sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
555 if ((int64_t)(newval - *stat) > 0 || newval == 0)
560 sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
562 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
563 struct sfc_port *port = &sa->port;
567 rte_spinlock_lock(&port->mac_stats_lock);
569 ret = sfc_port_update_mac_stats(sa);
573 mac_stats = port->mac_stats_buf;
575 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
576 EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
578 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
579 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
580 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
582 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
583 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
584 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
586 mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
587 mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
588 mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
590 mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
591 mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
592 mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
593 stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
594 stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
596 stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
597 stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS];
598 stats->obytes = mac_stats[EFX_MAC_TX_OCTETS];
600 * Take into account stats which are whenever supported
601 * on EF10. If some stat is not supported by current
602 * firmware variant or HW revision, it is guaranteed
603 * to be zero in mac_stats.
606 mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
607 mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
608 mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
609 mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
610 mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
611 mac_stats[EFX_MAC_PM_TRUNC_QBB] +
612 mac_stats[EFX_MAC_PM_DISCARD_QBB] +
613 mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
614 mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
615 mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
617 mac_stats[EFX_MAC_RX_FCS_ERRORS] +
618 mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
619 mac_stats[EFX_MAC_RX_JABBER_PKTS];
620 /* no oerrors counters supported on EF10 */
622 /* Exclude missed, errors and pauses from Rx packets */
623 sfc_update_diff_stat(&port->ipackets,
624 mac_stats[EFX_MAC_RX_PKTS] -
625 mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
626 stats->imissed - stats->ierrors);
627 stats->ipackets = port->ipackets;
631 rte_spinlock_unlock(&port->mac_stats_lock);
632 SFC_ASSERT(ret >= 0);
637 sfc_stats_reset(struct rte_eth_dev *dev)
639 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
640 struct sfc_port *port = &sa->port;
643 if (sa->state != SFC_ADAPTER_STARTED) {
645 * The operation cannot be done if port is not started; it
646 * will be scheduled to be done during the next port start
648 port->mac_stats_reset_pending = B_TRUE;
652 rc = sfc_port_reset_mac_stats(sa);
654 sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
658 sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
659 unsigned int xstats_count)
661 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
662 struct sfc_port *port = &sa->port;
668 rte_spinlock_lock(&port->mac_stats_lock);
670 rc = sfc_port_update_mac_stats(sa);
677 mac_stats = port->mac_stats_buf;
679 for (i = 0; i < EFX_MAC_NSTATS; ++i) {
680 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
681 if (xstats != NULL && nstats < (int)xstats_count) {
682 xstats[nstats].id = nstats;
683 xstats[nstats].value = mac_stats[i];
690 rte_spinlock_unlock(&port->mac_stats_lock);
696 sfc_xstats_get_names(struct rte_eth_dev *dev,
697 struct rte_eth_xstat_name *xstats_names,
698 unsigned int xstats_count)
700 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
701 struct sfc_port *port = &sa->port;
703 unsigned int nstats = 0;
705 for (i = 0; i < EFX_MAC_NSTATS; ++i) {
706 if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
707 if (xstats_names != NULL && nstats < xstats_count)
708 strlcpy(xstats_names[nstats].name,
709 efx_mac_stat_name(sa->nic, i),
710 sizeof(xstats_names[0].name));
719 sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
720 uint64_t *values, unsigned int n)
722 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
723 struct sfc_port *port = &sa->port;
725 unsigned int nb_supported = 0;
726 unsigned int nb_written = 0;
731 if (unlikely(values == NULL) ||
732 unlikely((ids == NULL) && (n < port->mac_stats_nb_supported)))
733 return port->mac_stats_nb_supported;
735 rte_spinlock_lock(&port->mac_stats_lock);
737 rc = sfc_port_update_mac_stats(sa);
744 mac_stats = port->mac_stats_buf;
746 for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) {
747 if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
750 if ((ids == NULL) || (ids[nb_written] == nb_supported))
751 values[nb_written++] = mac_stats[i];
759 rte_spinlock_unlock(&port->mac_stats_lock);
765 sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
766 struct rte_eth_xstat_name *xstats_names,
767 const uint64_t *ids, unsigned int size)
769 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
770 struct sfc_port *port = &sa->port;
771 unsigned int nb_supported = 0;
772 unsigned int nb_written = 0;
775 if (unlikely(xstats_names == NULL) ||
776 unlikely((ids == NULL) && (size < port->mac_stats_nb_supported)))
777 return port->mac_stats_nb_supported;
779 for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) {
780 if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
783 if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
784 char *name = xstats_names[nb_written++].name;
786 strlcpy(name, efx_mac_stat_name(sa->nic, i),
787 sizeof(xstats_names[0].name));
797 sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
799 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
800 unsigned int wanted_fc, link_fc;
802 memset(fc_conf, 0, sizeof(*fc_conf));
804 sfc_adapter_lock(sa);
806 if (sa->state == SFC_ADAPTER_STARTED)
807 efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
809 link_fc = sa->port.flow_ctrl;
813 fc_conf->mode = RTE_FC_NONE;
815 case EFX_FCNTL_RESPOND:
816 fc_conf->mode = RTE_FC_RX_PAUSE;
818 case EFX_FCNTL_GENERATE:
819 fc_conf->mode = RTE_FC_TX_PAUSE;
821 case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
822 fc_conf->mode = RTE_FC_FULL;
825 sfc_err(sa, "%s: unexpected flow control value %#x",
829 fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
831 sfc_adapter_unlock(sa);
837 sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
839 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
840 struct sfc_port *port = &sa->port;
844 if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
845 fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
846 fc_conf->mac_ctrl_frame_fwd != 0) {
847 sfc_err(sa, "unsupported flow control settings specified");
852 switch (fc_conf->mode) {
856 case RTE_FC_RX_PAUSE:
857 fcntl = EFX_FCNTL_RESPOND;
859 case RTE_FC_TX_PAUSE:
860 fcntl = EFX_FCNTL_GENERATE;
863 fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
870 sfc_adapter_lock(sa);
872 if (sa->state == SFC_ADAPTER_STARTED) {
873 rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
875 goto fail_mac_fcntl_set;
878 port->flow_ctrl = fcntl;
879 port->flow_ctrl_autoneg = fc_conf->autoneg;
881 sfc_adapter_unlock(sa);
886 sfc_adapter_unlock(sa);
893 sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
895 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
896 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
897 boolean_t scatter_enabled;
901 for (i = 0; i < sas->rxq_count; i++) {
902 if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
905 scatter_enabled = (sas->rxq_info[i].type_flags &
906 EFX_RXQ_FLAG_SCATTER);
908 if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
909 encp->enc_rx_prefix_size,
910 scatter_enabled, &error)) {
911 sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
921 sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
923 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
924 size_t pdu = EFX_MAC_PDU(mtu);
928 sfc_log_init(sa, "mtu=%u", mtu);
931 if (pdu < EFX_MAC_PDU_MIN) {
932 sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
933 (unsigned int)mtu, (unsigned int)pdu,
937 if (pdu > EFX_MAC_PDU_MAX) {
938 sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
939 (unsigned int)mtu, (unsigned int)pdu,
944 sfc_adapter_lock(sa);
946 rc = sfc_check_scatter_on_all_rx_queues(sa, pdu);
948 goto fail_check_scatter;
950 if (pdu != sa->port.pdu) {
951 if (sa->state == SFC_ADAPTER_STARTED) {
954 old_pdu = sa->port.pdu;
965 * The driver does not use it, but other PMDs update jumbo frame
966 * flag and max_rx_pkt_len when MTU is set.
968 if (mtu > RTE_ETHER_MAX_LEN) {
969 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
970 rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
973 dev->data->dev_conf.rxmode.max_rx_pkt_len = sa->port.pdu;
975 sfc_adapter_unlock(sa);
977 sfc_log_init(sa, "done");
981 sa->port.pdu = old_pdu;
982 if (sfc_start(sa) != 0)
983 sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
984 "PDU max size - port is stopped",
985 (unsigned int)pdu, (unsigned int)old_pdu);
988 sfc_adapter_unlock(sa);
991 sfc_log_init(sa, "failed %d", rc);
996 sfc_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
998 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
999 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1000 struct sfc_port *port = &sa->port;
1001 struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
1004 sfc_adapter_lock(sa);
1007 * Copy the address to the device private data so that
1008 * it could be recalled in the case of adapter restart.
1010 rte_ether_addr_copy(mac_addr, &port->default_mac_addr);
1013 * Neither of the two following checks can return
1014 * an error. The new MAC address is preserved in
1015 * the device private data and can be activated
1016 * on the next port start if the user prevents
1017 * isolated mode from being enabled.
1019 if (sfc_sa2shared(sa)->isolated) {
1020 sfc_warn(sa, "isolated mode is active on the port");
1021 sfc_warn(sa, "will not set MAC address");
1025 if (sa->state != SFC_ADAPTER_STARTED) {
1026 sfc_notice(sa, "the port is not started");
1027 sfc_notice(sa, "the new MAC address will be set on port start");
1032 if (encp->enc_allow_set_mac_with_installed_filters) {
1033 rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
1035 sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
1040 * Changing the MAC address by means of MCDI request
1041 * has no effect on received traffic, therefore
1042 * we also need to update unicast filters
1044 rc = sfc_set_rx_mode(sa);
1046 sfc_err(sa, "cannot set filter (rc = %u)", rc);
1047 /* Rollback the old address */
1048 (void)efx_mac_addr_set(sa->nic, old_addr->addr_bytes);
1049 (void)sfc_set_rx_mode(sa);
1052 sfc_warn(sa, "cannot set MAC address with filters installed");
1053 sfc_warn(sa, "adapter will be restarted to pick the new MAC");
1054 sfc_warn(sa, "(some traffic may be dropped)");
1057 * Since setting MAC address with filters installed is not
1058 * allowed on the adapter, the new MAC address will be set
1059 * by means of adapter restart. sfc_start() shall retrieve
1060 * the new address from the device private data and set it.
1065 sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
1070 rte_ether_addr_copy(old_addr, &port->default_mac_addr);
1072 sfc_adapter_unlock(sa);
1074 SFC_ASSERT(rc >= 0);
1080 sfc_set_mc_addr_list(struct rte_eth_dev *dev,
1081 struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1083 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1084 struct sfc_port *port = &sa->port;
1085 uint8_t *mc_addrs = port->mcast_addrs;
1089 if (sfc_sa2shared(sa)->isolated) {
1090 sfc_err(sa, "isolated mode is active on the port");
1091 sfc_err(sa, "will not set multicast address list");
1095 if (mc_addrs == NULL)
1098 if (nb_mc_addr > port->max_mcast_addrs) {
1099 sfc_err(sa, "too many multicast addresses: %u > %u",
1100 nb_mc_addr, port->max_mcast_addrs);
1104 for (i = 0; i < nb_mc_addr; ++i) {
1105 rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
1107 mc_addrs += EFX_MAC_ADDR_LEN;
1110 port->nb_mcast_addrs = nb_mc_addr;
1112 if (sa->state != SFC_ADAPTER_STARTED)
1115 rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
1116 port->nb_mcast_addrs);
1118 sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
1120 SFC_ASSERT(rc >= 0);
1125 * The function is used by the secondary process as well. It must not
1126 * use any process-local pointers from the adapter data.
1129 sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1130 struct rte_eth_rxq_info *qinfo)
1132 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1133 struct sfc_rxq_info *rxq_info;
1135 SFC_ASSERT(rx_queue_id < sas->rxq_count);
1137 rxq_info = &sas->rxq_info[rx_queue_id];
1139 qinfo->mp = rxq_info->refill_mb_pool;
1140 qinfo->conf.rx_free_thresh = rxq_info->refill_threshold;
1141 qinfo->conf.rx_drop_en = 1;
1142 qinfo->conf.rx_deferred_start = rxq_info->deferred_start;
1143 qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
1144 if (rxq_info->type_flags & EFX_RXQ_FLAG_SCATTER) {
1145 qinfo->conf.offloads |= DEV_RX_OFFLOAD_SCATTER;
1146 qinfo->scattered_rx = 1;
1148 qinfo->nb_desc = rxq_info->entries;
1152 * The function is used by the secondary process as well. It must not
1153 * use any process-local pointers from the adapter data.
1156 sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1157 struct rte_eth_txq_info *qinfo)
1159 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1160 struct sfc_txq_info *txq_info;
1162 SFC_ASSERT(tx_queue_id < sas->txq_count);
1164 txq_info = &sas->txq_info[tx_queue_id];
1166 memset(qinfo, 0, sizeof(*qinfo));
1168 qinfo->conf.offloads = txq_info->offloads;
1169 qinfo->conf.tx_free_thresh = txq_info->free_thresh;
1170 qinfo->conf.tx_deferred_start = txq_info->deferred_start;
1171 qinfo->nb_desc = txq_info->entries;
1175 * The function is used by the secondary process as well. It must not
1176 * use any process-local pointers from the adapter data.
1179 sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1181 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1182 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1183 struct sfc_rxq_info *rxq_info;
1185 SFC_ASSERT(rx_queue_id < sas->rxq_count);
1186 rxq_info = &sas->rxq_info[rx_queue_id];
1188 if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
1191 return sap->dp_rx->qdesc_npending(rxq_info->dp);
1195 * The function is used by the secondary process as well. It must not
1196 * use any process-local pointers from the adapter data.
1199 sfc_rx_descriptor_done(void *queue, uint16_t offset)
1201 struct sfc_dp_rxq *dp_rxq = queue;
1202 const struct sfc_dp_rx *dp_rx;
1204 dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1206 return offset < dp_rx->qdesc_npending(dp_rxq);
1210 * The function is used by the secondary process as well. It must not
1211 * use any process-local pointers from the adapter data.
1214 sfc_rx_descriptor_status(void *queue, uint16_t offset)
1216 struct sfc_dp_rxq *dp_rxq = queue;
1217 const struct sfc_dp_rx *dp_rx;
1219 dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1221 return dp_rx->qdesc_status(dp_rxq, offset);
1225 * The function is used by the secondary process as well. It must not
1226 * use any process-local pointers from the adapter data.
1229 sfc_tx_descriptor_status(void *queue, uint16_t offset)
1231 struct sfc_dp_txq *dp_txq = queue;
1232 const struct sfc_dp_tx *dp_tx;
1234 dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
1236 return dp_tx->qdesc_status(dp_txq, offset);
1240 sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1242 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1243 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1246 sfc_log_init(sa, "RxQ=%u", rx_queue_id);
1248 sfc_adapter_lock(sa);
1251 if (sa->state != SFC_ADAPTER_STARTED)
1252 goto fail_not_started;
1254 if (sas->rxq_info[rx_queue_id].state != SFC_RXQ_INITIALIZED)
1255 goto fail_not_setup;
1257 rc = sfc_rx_qstart(sa, rx_queue_id);
1259 goto fail_rx_qstart;
1261 sas->rxq_info[rx_queue_id].deferred_started = B_TRUE;
1263 sfc_adapter_unlock(sa);
1270 sfc_adapter_unlock(sa);
1276 sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1278 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1279 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1281 sfc_log_init(sa, "RxQ=%u", rx_queue_id);
1283 sfc_adapter_lock(sa);
1284 sfc_rx_qstop(sa, rx_queue_id);
1286 sas->rxq_info[rx_queue_id].deferred_started = B_FALSE;
1288 sfc_adapter_unlock(sa);
1294 sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1296 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1297 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1300 sfc_log_init(sa, "TxQ = %u", tx_queue_id);
1302 sfc_adapter_lock(sa);
1305 if (sa->state != SFC_ADAPTER_STARTED)
1306 goto fail_not_started;
1308 if (sas->txq_info[tx_queue_id].state != SFC_TXQ_INITIALIZED)
1309 goto fail_not_setup;
1311 rc = sfc_tx_qstart(sa, tx_queue_id);
1313 goto fail_tx_qstart;
1315 sas->txq_info[tx_queue_id].deferred_started = B_TRUE;
1317 sfc_adapter_unlock(sa);
1324 sfc_adapter_unlock(sa);
1330 sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1332 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1333 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1335 sfc_log_init(sa, "TxQ = %u", tx_queue_id);
1337 sfc_adapter_lock(sa);
1339 sfc_tx_qstop(sa, tx_queue_id);
1341 sas->txq_info[tx_queue_id].deferred_started = B_FALSE;
1343 sfc_adapter_unlock(sa);
1347 static efx_tunnel_protocol_t
1348 sfc_tunnel_rte_type_to_efx_udp_proto(enum rte_eth_tunnel_type rte_type)
1351 case RTE_TUNNEL_TYPE_VXLAN:
1352 return EFX_TUNNEL_PROTOCOL_VXLAN;
1353 case RTE_TUNNEL_TYPE_GENEVE:
1354 return EFX_TUNNEL_PROTOCOL_GENEVE;
1356 return EFX_TUNNEL_NPROTOS;
1360 enum sfc_udp_tunnel_op_e {
1361 SFC_UDP_TUNNEL_ADD_PORT,
1362 SFC_UDP_TUNNEL_DEL_PORT,
1366 sfc_dev_udp_tunnel_op(struct rte_eth_dev *dev,
1367 struct rte_eth_udp_tunnel *tunnel_udp,
1368 enum sfc_udp_tunnel_op_e op)
1370 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1371 efx_tunnel_protocol_t tunnel_proto;
1374 sfc_log_init(sa, "%s udp_port=%u prot_type=%u",
1375 (op == SFC_UDP_TUNNEL_ADD_PORT) ? "add" :
1376 (op == SFC_UDP_TUNNEL_DEL_PORT) ? "delete" : "unknown",
1377 tunnel_udp->udp_port, tunnel_udp->prot_type);
1380 sfc_tunnel_rte_type_to_efx_udp_proto(tunnel_udp->prot_type);
1381 if (tunnel_proto >= EFX_TUNNEL_NPROTOS) {
1383 goto fail_bad_proto;
1386 sfc_adapter_lock(sa);
1389 case SFC_UDP_TUNNEL_ADD_PORT:
1390 rc = efx_tunnel_config_udp_add(sa->nic,
1391 tunnel_udp->udp_port,
1394 case SFC_UDP_TUNNEL_DEL_PORT:
1395 rc = efx_tunnel_config_udp_remove(sa->nic,
1396 tunnel_udp->udp_port,
1407 if (sa->state == SFC_ADAPTER_STARTED) {
1408 rc = efx_tunnel_reconfigure(sa->nic);
1411 * Configuration is accepted by FW and MC reboot
1412 * is initiated to apply the changes. MC reboot
1413 * will be handled in a usual way (MC reboot
1414 * event on management event queue and adapter
1418 } else if (rc != 0) {
1419 goto fail_reconfigure;
1423 sfc_adapter_unlock(sa);
1427 /* Remove/restore entry since the change makes the trouble */
1429 case SFC_UDP_TUNNEL_ADD_PORT:
1430 (void)efx_tunnel_config_udp_remove(sa->nic,
1431 tunnel_udp->udp_port,
1434 case SFC_UDP_TUNNEL_DEL_PORT:
1435 (void)efx_tunnel_config_udp_add(sa->nic,
1436 tunnel_udp->udp_port,
1443 sfc_adapter_unlock(sa);
1451 sfc_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
1452 struct rte_eth_udp_tunnel *tunnel_udp)
1454 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_ADD_PORT);
1458 sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1459 struct rte_eth_udp_tunnel *tunnel_udp)
1461 return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
1465 * The function is used by the secondary process as well. It must not
1466 * use any process-local pointers from the adapter data.
1469 sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1470 struct rte_eth_rss_conf *rss_conf)
1472 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1473 struct sfc_rss *rss = &sas->rss;
1475 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE)
1479 * Mapping of hash configuration between RTE and EFX is not one-to-one,
1480 * hence, conversion is done here to derive a correct set of ETH_RSS
1481 * flags which corresponds to the active EFX configuration stored
1482 * locally in 'sfc_adapter' and kept up-to-date
1484 rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(rss, rss->hash_types);
1485 rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
1486 if (rss_conf->rss_key != NULL)
1487 rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
1493 sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
1494 struct rte_eth_rss_conf *rss_conf)
1496 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1497 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1498 unsigned int efx_hash_types;
1501 if (sfc_sa2shared(sa)->isolated)
1504 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1505 sfc_err(sa, "RSS is not available");
1509 if (rss->channels == 0) {
1510 sfc_err(sa, "RSS is not configured");
1514 if ((rss_conf->rss_key != NULL) &&
1515 (rss_conf->rss_key_len != sizeof(rss->key))) {
1516 sfc_err(sa, "RSS key size is wrong (should be %lu)",
1521 sfc_adapter_lock(sa);
1523 rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
1525 goto fail_rx_hf_rte_to_efx;
1527 rc = efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1528 rss->hash_alg, efx_hash_types, B_TRUE);
1530 goto fail_scale_mode_set;
1532 if (rss_conf->rss_key != NULL) {
1533 if (sa->state == SFC_ADAPTER_STARTED) {
1534 rc = efx_rx_scale_key_set(sa->nic,
1535 EFX_RSS_CONTEXT_DEFAULT,
1539 goto fail_scale_key_set;
1542 rte_memcpy(rss->key, rss_conf->rss_key, sizeof(rss->key));
1545 rss->hash_types = efx_hash_types;
1547 sfc_adapter_unlock(sa);
1552 if (efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1553 EFX_RX_HASHALG_TOEPLITZ,
1554 rss->hash_types, B_TRUE) != 0)
1555 sfc_err(sa, "failed to restore RSS mode");
1557 fail_scale_mode_set:
1558 fail_rx_hf_rte_to_efx:
1559 sfc_adapter_unlock(sa);
1564 * The function is used by the secondary process as well. It must not
1565 * use any process-local pointers from the adapter data.
1568 sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
1569 struct rte_eth_rss_reta_entry64 *reta_conf,
1572 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1573 struct sfc_rss *rss = &sas->rss;
1576 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE || sas->isolated)
1579 if (rss->channels == 0)
1582 if (reta_size != EFX_RSS_TBL_SIZE)
1585 for (entry = 0; entry < reta_size; entry++) {
1586 int grp = entry / RTE_RETA_GROUP_SIZE;
1587 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1589 if ((reta_conf[grp].mask >> grp_idx) & 1)
1590 reta_conf[grp].reta[grp_idx] = rss->tbl[entry];
1597 sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
1598 struct rte_eth_rss_reta_entry64 *reta_conf,
1601 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1602 struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1603 unsigned int *rss_tbl_new;
1608 if (sfc_sa2shared(sa)->isolated)
1611 if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1612 sfc_err(sa, "RSS is not available");
1616 if (rss->channels == 0) {
1617 sfc_err(sa, "RSS is not configured");
1621 if (reta_size != EFX_RSS_TBL_SIZE) {
1622 sfc_err(sa, "RETA size is wrong (should be %u)",
1627 rss_tbl_new = rte_zmalloc("rss_tbl_new", sizeof(rss->tbl), 0);
1628 if (rss_tbl_new == NULL)
1631 sfc_adapter_lock(sa);
1633 rte_memcpy(rss_tbl_new, rss->tbl, sizeof(rss->tbl));
1635 for (entry = 0; entry < reta_size; entry++) {
1636 int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1637 struct rte_eth_rss_reta_entry64 *grp;
1639 grp = &reta_conf[entry / RTE_RETA_GROUP_SIZE];
1641 if (grp->mask & (1ull << grp_idx)) {
1642 if (grp->reta[grp_idx] >= rss->channels) {
1644 goto bad_reta_entry;
1646 rss_tbl_new[entry] = grp->reta[grp_idx];
1650 if (sa->state == SFC_ADAPTER_STARTED) {
1651 rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1652 rss_tbl_new, EFX_RSS_TBL_SIZE);
1654 goto fail_scale_tbl_set;
1657 rte_memcpy(rss->tbl, rss_tbl_new, sizeof(rss->tbl));
1661 sfc_adapter_unlock(sa);
1663 rte_free(rss_tbl_new);
1665 SFC_ASSERT(rc >= 0);
1670 sfc_dev_filter_ctrl(struct rte_eth_dev *dev, enum rte_filter_type filter_type,
1671 enum rte_filter_op filter_op,
1674 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1677 sfc_log_init(sa, "entry");
1679 switch (filter_type) {
1680 case RTE_ETH_FILTER_NONE:
1681 sfc_err(sa, "Global filters configuration not supported");
1683 case RTE_ETH_FILTER_MACVLAN:
1684 sfc_err(sa, "MACVLAN filters not supported");
1686 case RTE_ETH_FILTER_ETHERTYPE:
1687 sfc_err(sa, "EtherType filters not supported");
1689 case RTE_ETH_FILTER_FLEXIBLE:
1690 sfc_err(sa, "Flexible filters not supported");
1692 case RTE_ETH_FILTER_SYN:
1693 sfc_err(sa, "SYN filters not supported");
1695 case RTE_ETH_FILTER_NTUPLE:
1696 sfc_err(sa, "NTUPLE filters not supported");
1698 case RTE_ETH_FILTER_TUNNEL:
1699 sfc_err(sa, "Tunnel filters not supported");
1701 case RTE_ETH_FILTER_FDIR:
1702 sfc_err(sa, "Flow Director filters not supported");
1704 case RTE_ETH_FILTER_HASH:
1705 sfc_err(sa, "Hash filters not supported");
1707 case RTE_ETH_FILTER_GENERIC:
1708 if (filter_op != RTE_ETH_FILTER_GET) {
1711 *(const void **)arg = &sfc_flow_ops;
1716 sfc_err(sa, "Unknown filter type %u", filter_type);
1720 sfc_log_init(sa, "exit: %d", -rc);
1721 SFC_ASSERT(rc >= 0);
1726 sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
1728 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1731 * If Rx datapath does not provide callback to check mempool,
1732 * all pools are supported.
1734 if (sap->dp_rx->pool_ops_supported == NULL)
1737 return sap->dp_rx->pool_ops_supported(pool);
1741 sfc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1743 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1744 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1745 struct sfc_rxq_info *rxq_info;
1747 SFC_ASSERT(queue_id < sas->rxq_count);
1748 rxq_info = &sas->rxq_info[queue_id];
1750 return sap->dp_rx->intr_enable(rxq_info->dp);
1754 sfc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1756 const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1757 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1758 struct sfc_rxq_info *rxq_info;
1760 SFC_ASSERT(queue_id < sas->rxq_count);
1761 rxq_info = &sas->rxq_info[queue_id];
1763 return sap->dp_rx->intr_disable(rxq_info->dp);
1766 static const struct eth_dev_ops sfc_eth_dev_ops = {
1767 .dev_configure = sfc_dev_configure,
1768 .dev_start = sfc_dev_start,
1769 .dev_stop = sfc_dev_stop,
1770 .dev_set_link_up = sfc_dev_set_link_up,
1771 .dev_set_link_down = sfc_dev_set_link_down,
1772 .dev_close = sfc_dev_close,
1773 .promiscuous_enable = sfc_dev_promisc_enable,
1774 .promiscuous_disable = sfc_dev_promisc_disable,
1775 .allmulticast_enable = sfc_dev_allmulti_enable,
1776 .allmulticast_disable = sfc_dev_allmulti_disable,
1777 .link_update = sfc_dev_link_update,
1778 .stats_get = sfc_stats_get,
1779 .stats_reset = sfc_stats_reset,
1780 .xstats_get = sfc_xstats_get,
1781 .xstats_reset = sfc_stats_reset,
1782 .xstats_get_names = sfc_xstats_get_names,
1783 .dev_infos_get = sfc_dev_infos_get,
1784 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
1785 .mtu_set = sfc_dev_set_mtu,
1786 .rx_queue_start = sfc_rx_queue_start,
1787 .rx_queue_stop = sfc_rx_queue_stop,
1788 .tx_queue_start = sfc_tx_queue_start,
1789 .tx_queue_stop = sfc_tx_queue_stop,
1790 .rx_queue_setup = sfc_rx_queue_setup,
1791 .rx_queue_release = sfc_rx_queue_release,
1792 .rx_queue_count = sfc_rx_queue_count,
1793 .rx_descriptor_done = sfc_rx_descriptor_done,
1794 .rx_descriptor_status = sfc_rx_descriptor_status,
1795 .tx_descriptor_status = sfc_tx_descriptor_status,
1796 .rx_queue_intr_enable = sfc_rx_queue_intr_enable,
1797 .rx_queue_intr_disable = sfc_rx_queue_intr_disable,
1798 .tx_queue_setup = sfc_tx_queue_setup,
1799 .tx_queue_release = sfc_tx_queue_release,
1800 .flow_ctrl_get = sfc_flow_ctrl_get,
1801 .flow_ctrl_set = sfc_flow_ctrl_set,
1802 .mac_addr_set = sfc_mac_addr_set,
1803 .udp_tunnel_port_add = sfc_dev_udp_tunnel_port_add,
1804 .udp_tunnel_port_del = sfc_dev_udp_tunnel_port_del,
1805 .reta_update = sfc_dev_rss_reta_update,
1806 .reta_query = sfc_dev_rss_reta_query,
1807 .rss_hash_update = sfc_dev_rss_hash_update,
1808 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
1809 .filter_ctrl = sfc_dev_filter_ctrl,
1810 .set_mc_addr_list = sfc_set_mc_addr_list,
1811 .rxq_info_get = sfc_rx_queue_info_get,
1812 .txq_info_get = sfc_tx_queue_info_get,
1813 .fw_version_get = sfc_fw_version_get,
1814 .xstats_get_by_id = sfc_xstats_get_by_id,
1815 .xstats_get_names_by_id = sfc_xstats_get_names_by_id,
1816 .pool_ops_supported = sfc_pool_ops_supported,
1820 * Duplicate a string in potentially shared memory required for
1821 * multi-process support.
1823 * strdup() allocates from process-local heap/memory.
1826 sfc_strdup(const char *str)
1834 size = strlen(str) + 1;
1835 copy = rte_malloc(__func__, size, 0);
1837 rte_memcpy(copy, str, size);
1843 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
1845 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1846 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1847 const struct sfc_dp_rx *dp_rx;
1848 const struct sfc_dp_tx *dp_tx;
1849 const efx_nic_cfg_t *encp;
1850 unsigned int avail_caps = 0;
1851 const char *rx_name = NULL;
1852 const char *tx_name = NULL;
1855 switch (sa->family) {
1856 case EFX_FAMILY_HUNTINGTON:
1857 case EFX_FAMILY_MEDFORD:
1858 case EFX_FAMILY_MEDFORD2:
1859 avail_caps |= SFC_DP_HW_FW_CAP_EF10;
1865 encp = efx_nic_cfg_get(sa->nic);
1866 if (encp->enc_rx_es_super_buffer_supported)
1867 avail_caps |= SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER;
1869 rc = sfc_kvargs_process(sa, SFC_KVARG_RX_DATAPATH,
1870 sfc_kvarg_string_handler, &rx_name);
1872 goto fail_kvarg_rx_datapath;
1874 if (rx_name != NULL) {
1875 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
1876 if (dp_rx == NULL) {
1877 sfc_err(sa, "Rx datapath %s not found", rx_name);
1881 if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
1883 "Insufficient Hw/FW capabilities to use Rx datapath %s",
1886 goto fail_dp_rx_caps;
1889 dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
1890 if (dp_rx == NULL) {
1891 sfc_err(sa, "Rx datapath by caps %#x not found",
1898 sas->dp_rx_name = sfc_strdup(dp_rx->dp.name);
1899 if (sas->dp_rx_name == NULL) {
1901 goto fail_dp_rx_name;
1904 sfc_notice(sa, "use %s Rx datapath", sas->dp_rx_name);
1906 rc = sfc_kvargs_process(sa, SFC_KVARG_TX_DATAPATH,
1907 sfc_kvarg_string_handler, &tx_name);
1909 goto fail_kvarg_tx_datapath;
1911 if (tx_name != NULL) {
1912 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
1913 if (dp_tx == NULL) {
1914 sfc_err(sa, "Tx datapath %s not found", tx_name);
1918 if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
1920 "Insufficient Hw/FW capabilities to use Tx datapath %s",
1923 goto fail_dp_tx_caps;
1926 dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
1927 if (dp_tx == NULL) {
1928 sfc_err(sa, "Tx datapath by caps %#x not found",
1935 sas->dp_tx_name = sfc_strdup(dp_tx->dp.name);
1936 if (sas->dp_tx_name == NULL) {
1938 goto fail_dp_tx_name;
1941 sfc_notice(sa, "use %s Tx datapath", sas->dp_tx_name);
1943 sa->priv.dp_rx = dp_rx;
1944 sa->priv.dp_tx = dp_tx;
1946 dev->rx_pkt_burst = dp_rx->pkt_burst;
1947 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
1948 dev->tx_pkt_burst = dp_tx->pkt_burst;
1950 dev->dev_ops = &sfc_eth_dev_ops;
1957 fail_kvarg_tx_datapath:
1958 rte_free(sas->dp_rx_name);
1959 sas->dp_rx_name = NULL;
1964 fail_kvarg_rx_datapath:
1969 sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
1971 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1972 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1974 dev->dev_ops = NULL;
1975 dev->tx_pkt_prepare = NULL;
1976 dev->rx_pkt_burst = NULL;
1977 dev->tx_pkt_burst = NULL;
1979 rte_free(sas->dp_tx_name);
1980 sas->dp_tx_name = NULL;
1981 sa->priv.dp_tx = NULL;
1983 rte_free(sas->dp_rx_name);
1984 sas->dp_rx_name = NULL;
1985 sa->priv.dp_rx = NULL;
1988 static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
1989 .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
1990 .rx_queue_count = sfc_rx_queue_count,
1991 .rx_descriptor_done = sfc_rx_descriptor_done,
1992 .rx_descriptor_status = sfc_rx_descriptor_status,
1993 .tx_descriptor_status = sfc_tx_descriptor_status,
1994 .reta_query = sfc_dev_rss_reta_query,
1995 .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
1996 .rxq_info_get = sfc_rx_queue_info_get,
1997 .txq_info_get = sfc_tx_queue_info_get,
2001 sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
2003 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2004 struct sfc_adapter_priv *sap;
2005 const struct sfc_dp_rx *dp_rx;
2006 const struct sfc_dp_tx *dp_tx;
2010 * Allocate process private data from heap, since it should not
2011 * be located in shared memory allocated using rte_malloc() API.
2013 sap = calloc(1, sizeof(*sap));
2016 goto fail_alloc_priv;
2019 sap->logtype_main = logtype_main;
2021 dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sas->dp_rx_name);
2022 if (dp_rx == NULL) {
2023 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2024 "cannot find %s Rx datapath", sas->dp_rx_name);
2028 if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
2029 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2030 "%s Rx datapath does not support multi-process",
2033 goto fail_dp_rx_multi_process;
2036 dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sas->dp_tx_name);
2037 if (dp_tx == NULL) {
2038 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2039 "cannot find %s Tx datapath", sas->dp_tx_name);
2043 if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
2044 SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2045 "%s Tx datapath does not support multi-process",
2048 goto fail_dp_tx_multi_process;
2054 dev->process_private = sap;
2055 dev->rx_pkt_burst = dp_rx->pkt_burst;
2056 dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2057 dev->tx_pkt_burst = dp_tx->pkt_burst;
2058 dev->dev_ops = &sfc_eth_dev_secondary_ops;
2062 fail_dp_tx_multi_process:
2064 fail_dp_rx_multi_process:
2073 sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
2075 free(dev->process_private);
2076 dev->process_private = NULL;
2077 dev->dev_ops = NULL;
2078 dev->tx_pkt_prepare = NULL;
2079 dev->tx_pkt_burst = NULL;
2080 dev->rx_pkt_burst = NULL;
2084 sfc_register_dp(void)
2087 if (TAILQ_EMPTY(&sfc_dp_head)) {
2088 /* Prefer EF10 datapath */
2089 sfc_dp_register(&sfc_dp_head, &sfc_ef10_essb_rx.dp);
2090 sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
2091 sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
2093 sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
2094 sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
2095 sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
2100 sfc_eth_dev_init(struct rte_eth_dev *dev)
2102 struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2103 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2104 uint32_t logtype_main;
2105 struct sfc_adapter *sa;
2107 const efx_nic_cfg_t *encp;
2108 const struct rte_ether_addr *from;
2112 logtype_main = sfc_register_logtype(&pci_dev->addr,
2113 SFC_LOGTYPE_MAIN_STR,
2116 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2117 return -sfc_eth_dev_secondary_init(dev, logtype_main);
2119 /* Required for logging */
2120 sas->pci_addr = pci_dev->addr;
2121 sas->port_id = dev->data->port_id;
2124 * Allocate process private data from heap, since it should not
2125 * be located in shared memory allocated using rte_malloc() API.
2127 sa = calloc(1, sizeof(*sa));
2133 dev->process_private = sa;
2135 /* Required for logging */
2136 sa->priv.shared = sas;
2137 sa->priv.logtype_main = logtype_main;
2141 /* Copy PCI device info to the dev->data */
2142 rte_eth_copy_pci_info(dev, pci_dev);
2144 rc = sfc_kvargs_parse(sa);
2146 goto fail_kvargs_parse;
2148 sfc_log_init(sa, "entry");
2150 dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
2152 dev->data->mac_addrs = rte_zmalloc("sfc", RTE_ETHER_ADDR_LEN, 0);
2153 if (dev->data->mac_addrs == NULL) {
2155 goto fail_mac_addrs;
2158 sfc_adapter_lock_init(sa);
2159 sfc_adapter_lock(sa);
2161 sfc_log_init(sa, "probing");
2166 sfc_log_init(sa, "set device ops");
2167 rc = sfc_eth_dev_set_ops(dev);
2171 sfc_log_init(sa, "attaching");
2172 rc = sfc_attach(sa);
2176 encp = efx_nic_cfg_get(sa->nic);
2179 * The arguments are really reverse order in comparison to
2180 * Linux kernel. Copy from NIC config to Ethernet device data.
2182 from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
2183 rte_ether_addr_copy(from, &dev->data->mac_addrs[0]);
2185 sfc_adapter_unlock(sa);
2187 sfc_log_init(sa, "done");
2191 sfc_eth_dev_clear_ops(dev);
2197 sfc_adapter_unlock(sa);
2198 sfc_adapter_lock_fini(sa);
2199 rte_free(dev->data->mac_addrs);
2200 dev->data->mac_addrs = NULL;
2203 sfc_kvargs_cleanup(sa);
2206 sfc_log_init(sa, "failed %d", rc);
2207 dev->process_private = NULL;
2216 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
2218 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2219 sfc_eth_dev_secondary_clear_ops(dev);
2228 static const struct rte_pci_id pci_id_sfc_efx_map[] = {
2229 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
2230 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE_VF) },
2231 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
2232 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT_VF) },
2233 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
2234 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD_VF) },
2235 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2) },
2236 { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2_VF) },
2237 { .vendor_id = 0 /* sentinel */ }
2240 static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2241 struct rte_pci_device *pci_dev)
2243 return rte_eth_dev_pci_generic_probe(pci_dev,
2244 sizeof(struct sfc_adapter_shared), sfc_eth_dev_init);
2247 static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2249 return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
2252 static struct rte_pci_driver sfc_efx_pmd = {
2253 .id_table = pci_id_sfc_efx_map,
2255 RTE_PCI_DRV_INTR_LSC |
2256 RTE_PCI_DRV_NEED_MAPPING,
2257 .probe = sfc_eth_dev_pci_probe,
2258 .remove = sfc_eth_dev_pci_remove,
2261 RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
2262 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
2263 RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
2264 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
2265 SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
2266 SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
2267 SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
2268 SFC_KVARG_FW_VARIANT "=" SFC_KVARG_VALUES_FW_VARIANT " "
2269 SFC_KVARG_RXD_WAIT_TIMEOUT_NS "=<long> "
2270 SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long>");
2272 RTE_INIT(sfc_driver_register_logtype)
2276 ret = rte_log_register_type_and_pick_level(SFC_LOGTYPE_PREFIX "driver",
2278 sfc_logtype_driver = (ret < 0) ? RTE_LOGTYPE_PMD : ret;