diff options
Diffstat (limited to 'drivers/net/sfc')
-rw-r--r-- | drivers/net/sfc/sfc.c | 4 | ||||
-rw-r--r-- | drivers/net/sfc/sfc.h | 23 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_debug.h | 9 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_dp_rx.h | 1 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_dp_tx.h | 1 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_ef10_rx.c | 2 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_ef10_tx.c | 72 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_ethdev.c | 290 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_ev.c | 3 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_flow.c | 23 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_intr.c | 16 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_log.h | 13 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_port.c | 59 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_rx.c | 14 | ||||
-rw-r--r-- | drivers/net/sfc/sfc_tx.c | 9 |
15 files changed, 453 insertions, 86 deletions
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index 4e241b22..6cecfc00 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -465,7 +465,7 @@ static int sfc_mem_bar_init(struct sfc_adapter *sa) { struct rte_eth_dev *eth_dev = sa->eth_dev; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); efsys_bar_t *ebp = &sa->mem_bar; unsigned int i; struct rte_mem_resource *res; @@ -666,7 +666,7 @@ sfc_detach(struct sfc_adapter *sa) int sfc_probe(struct sfc_adapter *sa) { - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); efx_nic_t *enp; int rc; diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index fad0ce04..286d1ac1 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -34,6 +34,7 @@ #include <stdbool.h> +#include <rte_pci.h> #include <rte_ethdev.h> #include <rte_kvargs.h> #include <rte_spinlock.h> @@ -46,9 +47,6 @@ extern "C" { #endif -#define SFC_DEV_TO_PCI(eth_dev) \ - RTE_DEV_TO_PCI((eth_dev)->device) - #if EFSYS_OPT_RX_SCALE /** RSS key length (bytes) */ #define SFC_RSS_KEY_SIZE 40 @@ -153,6 +151,11 @@ struct sfc_port { boolean_t flow_ctrl_autoneg; size_t pdu; + /* + * Flow API isolated mode overrides promisc and allmulti settings; + * they won't be applied if isolated mode is active + */ + boolean_t isolated; boolean_t promisc; boolean_t allmulti; @@ -162,6 +165,7 @@ struct sfc_port { rte_spinlock_t mac_stats_lock; uint64_t *mac_stats_buf; + unsigned int mac_stats_nb_supported; efsys_mem_t mac_stats_dma_mem; boolean_t mac_stats_reset_pending; uint16_t mac_stats_update_period_ms; @@ -182,6 +186,8 @@ struct sfc_adapter { */ rte_spinlock_t lock; enum sfc_adapter_state state; + struct rte_pci_addr pci_addr; + uint16_t port_id; struct rte_eth_dev *eth_dev; struct rte_kvargs *kvargs; bool debug_init; @@ -226,7 +232,18 @@ struct sfc_adapter { uint8_t rss_key[SFC_RSS_KEY_SIZE]; #endif + /* + * Shared memory copy of the Rx datapath name to be used by + * the secondary process to find Rx datapath to be used. + */ + char *dp_rx_name; const struct sfc_dp_rx *dp_rx; + + /* + * Shared memory copy of the Tx datapath name to be used by + * the secondary process to find Rx datapath to be used. + */ + char *dp_tx_name; const struct sfc_dp_tx *dp_tx; }; diff --git a/drivers/net/sfc/sfc_debug.h b/drivers/net/sfc/sfc_debug.h index c0b48677..92eba9c3 100644 --- a/drivers/net/sfc/sfc_debug.h +++ b/drivers/net/sfc/sfc_debug.h @@ -47,13 +47,12 @@ /* Log PMD message, automatically add prefix and \n */ #define sfc_panic(sa, fmt, args...) \ do { \ - const struct rte_eth_dev *_dev = (sa)->eth_dev; \ - const struct rte_pci_device *_pci_dev = SFC_DEV_TO_PCI(_dev); \ + const struct sfc_adapter *_sa = (sa); \ \ rte_panic("sfc " PCI_PRI_FMT " #%" PRIu8 ": " fmt "\n", \ - _pci_dev->addr.domain, _pci_dev->addr.bus, \ - _pci_dev->addr.devid, _pci_dev->addr.function,\ - _dev->data->port_id, ##args); \ + _sa->pci_addr.domain, _sa->pci_addr.bus, \ + _sa->pci_addr.devid, _sa->pci_addr.function, \ + _sa->port_id, ##args); \ } while (0) #endif /* _SFC_DEBUG_H_ */ diff --git a/drivers/net/sfc/sfc_dp_rx.h b/drivers/net/sfc/sfc_dp_rx.h index 9d05a4b3..a7b82784 100644 --- a/drivers/net/sfc/sfc_dp_rx.h +++ b/drivers/net/sfc/sfc_dp_rx.h @@ -161,6 +161,7 @@ struct sfc_dp_rx { unsigned int features; #define SFC_DP_RX_FEAT_SCATTER 0x1 +#define SFC_DP_RX_FEAT_MULTI_PROCESS 0x2 sfc_dp_rx_qcreate_t *qcreate; sfc_dp_rx_qdestroy_t *qdestroy; sfc_dp_rx_qstart_t *qstart; diff --git a/drivers/net/sfc/sfc_dp_tx.h b/drivers/net/sfc/sfc_dp_tx.h index 2bb9a2e7..c1c34191 100644 --- a/drivers/net/sfc/sfc_dp_tx.h +++ b/drivers/net/sfc/sfc_dp_tx.h @@ -135,6 +135,7 @@ struct sfc_dp_tx { #define SFC_DP_TX_FEAT_VLAN_INSERT 0x1 #define SFC_DP_TX_FEAT_TSO 0x2 #define SFC_DP_TX_FEAT_MULTI_SEG 0x4 +#define SFC_DP_TX_FEAT_MULTI_PROCESS 0x8 sfc_dp_tx_qcreate_t *qcreate; sfc_dp_tx_qdestroy_t *qdestroy; sfc_dp_tx_qstart_t *qstart; diff --git a/drivers/net/sfc/sfc_ef10_rx.c b/drivers/net/sfc/sfc_ef10_rx.c index 1484baba..60812cbe 100644 --- a/drivers/net/sfc/sfc_ef10_rx.c +++ b/drivers/net/sfc/sfc_ef10_rx.c @@ -699,7 +699,7 @@ struct sfc_dp_rx sfc_ef10_rx = { .type = SFC_DP_RX, .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10, }, - .features = 0, + .features = SFC_DP_RX_FEAT_MULTI_PROCESS, .qcreate = sfc_ef10_rx_qcreate, .qdestroy = sfc_ef10_rx_qdestroy, .qstart = sfc_ef10_rx_qstart, diff --git a/drivers/net/sfc/sfc_ef10_tx.c b/drivers/net/sfc/sfc_ef10_tx.c index bac9baa9..da2b5edb 100644 --- a/drivers/net/sfc/sfc_ef10_tx.c +++ b/drivers/net/sfc/sfc_ef10_tx.c @@ -128,14 +128,10 @@ sfc_ef10_tx_get_event(struct sfc_ef10_txq *txq, efx_qword_t *tx_ev) return true; } -static void -sfc_ef10_tx_reap(struct sfc_ef10_txq *txq) +static unsigned int +sfc_ef10_tx_process_events(struct sfc_ef10_txq *txq) { - const unsigned int old_read_ptr = txq->evq_read_ptr; - const unsigned int ptr_mask = txq->ptr_mask; - unsigned int completed = txq->completed; - unsigned int pending = completed; - const unsigned int curr_done = pending - 1; + const unsigned int curr_done = txq->completed - 1; unsigned int anew_done = curr_done; efx_qword_t tx_ev; @@ -148,7 +144,18 @@ sfc_ef10_tx_reap(struct sfc_ef10_txq *txq) /* Update the latest done descriptor */ anew_done = EFX_QWORD_FIELD(tx_ev, ESF_DZ_TX_DESCR_INDX); } - pending += (anew_done - curr_done) & ptr_mask; + return (anew_done - curr_done) & txq->ptr_mask; +} + +static void +sfc_ef10_tx_reap(struct sfc_ef10_txq *txq) +{ + const unsigned int old_read_ptr = txq->evq_read_ptr; + const unsigned int ptr_mask = txq->ptr_mask; + unsigned int completed = txq->completed; + unsigned int pending = completed; + + pending += sfc_ef10_tx_process_events(txq); if (pending != completed) { do { @@ -349,6 +356,33 @@ sfc_ef10_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) return pktp - &tx_pkts[0]; } +static void +sfc_ef10_simple_tx_reap(struct sfc_ef10_txq *txq) +{ + const unsigned int old_read_ptr = txq->evq_read_ptr; + const unsigned int ptr_mask = txq->ptr_mask; + unsigned int completed = txq->completed; + unsigned int pending = completed; + + pending += sfc_ef10_tx_process_events(txq); + + if (pending != completed) { + do { + struct sfc_ef10_tx_sw_desc *txd; + + txd = &txq->sw_ring[completed & ptr_mask]; + + rte_pktmbuf_free_seg(txd->mbuf); + } while (++completed != pending); + + txq->completed = completed; + } + + sfc_ef10_ev_qclear(txq->evq_hw_ring, ptr_mask, old_read_ptr, + txq->evq_read_ptr); +} + + static uint16_t sfc_ef10_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) @@ -372,7 +406,7 @@ sfc_ef10_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, reap_done = (dma_desc_space < RTE_MAX(txq->free_thresh, nb_pkts)); if (reap_done) { - sfc_ef10_tx_reap(txq); + sfc_ef10_simple_tx_reap(txq); dma_desc_space = SFC_EF10_TXQ_LIMIT(ptr_mask + 1) - (added - txq->completed); } @@ -401,7 +435,7 @@ sfc_ef10_simple_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, #if SFC_TX_XMIT_PKTS_REAP_AT_LEAST_ONCE if (!reap_done) - sfc_ef10_tx_reap(txq); + sfc_ef10_simple_tx_reap(txq); #endif return pktp - &tx_pkts[0]; @@ -516,12 +550,15 @@ static void sfc_ef10_tx_qreap(struct sfc_dp_txq *dp_txq) { struct sfc_ef10_txq *txq = sfc_ef10_txq_by_dp_txq(dp_txq); - unsigned int txds; + unsigned int completed; + + for (completed = txq->completed; completed != txq->added; ++completed) { + struct sfc_ef10_tx_sw_desc *txd; - for (txds = 0; txds <= txq->ptr_mask; ++txds) { - if (txq->sw_ring[txds].mbuf != NULL) { - rte_pktmbuf_free(txq->sw_ring[txds].mbuf); - txq->sw_ring[txds].mbuf = NULL; + txd = &txq->sw_ring[completed & txq->ptr_mask]; + if (txd->mbuf != NULL) { + rte_pktmbuf_free(txd->mbuf); + txd->mbuf = NULL; } } @@ -534,7 +571,8 @@ struct sfc_dp_tx sfc_ef10_tx = { .type = SFC_DP_TX, .hw_fw_caps = SFC_DP_HW_FW_CAP_EF10, }, - .features = SFC_DP_TX_FEAT_MULTI_SEG, + .features = SFC_DP_TX_FEAT_MULTI_SEG | + SFC_DP_TX_FEAT_MULTI_PROCESS, .qcreate = sfc_ef10_tx_qcreate, .qdestroy = sfc_ef10_tx_qdestroy, .qstart = sfc_ef10_tx_qstart, @@ -549,7 +587,7 @@ struct sfc_dp_tx sfc_ef10_simple_tx = { .name = SFC_KVARG_DATAPATH_EF10_SIMPLE, .type = SFC_DP_TX, }, - .features = 0, + .features = SFC_DP_TX_FEAT_MULTI_PROCESS, .qcreate = sfc_ef10_tx_qcreate, .qdestroy = sfc_ef10_tx_qdestroy, .qstart = sfc_ef10_tx_qstart, diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index bdb4c466..12bcd6fa 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -107,7 +107,7 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) sfc_log_init(sa, "entry"); - dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device); + dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev); dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX; /* Autonegotiation may be disabled */ @@ -361,8 +361,13 @@ sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode, if (*toggle != enabled) { *toggle = enabled; - if ((sa->state == SFC_ADAPTER_STARTED) && - (sfc_set_rx_mode(sa) != 0)) { + if (port->isolated) { + sfc_warn(sa, "isolated mode is active on the port"); + sfc_warn(sa, "the change is to be applied on the next " + "start provided that isolated mode is " + "disabled prior the next start"); + } else if ((sa->state == SFC_ADAPTER_STARTED) && + (sfc_set_rx_mode(sa) != 0)) { *toggle = !(enabled); sfc_warn(sa, "Failed to %s %s mode", ((enabled) ? "enable" : "disable"), desc); @@ -661,6 +666,85 @@ sfc_xstats_get_names(struct rte_eth_dev *dev, } static int +sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, + uint64_t *values, unsigned int n) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + uint64_t *mac_stats; + unsigned int nb_supported = 0; + unsigned int nb_written = 0; + unsigned int i; + int ret; + int rc; + + if (unlikely(values == NULL) || + unlikely((ids == NULL) && (n < port->mac_stats_nb_supported))) + return port->mac_stats_nb_supported; + + rte_spinlock_lock(&port->mac_stats_lock); + + rc = sfc_port_update_mac_stats(sa); + if (rc != 0) { + SFC_ASSERT(rc > 0); + ret = -rc; + goto unlock; + } + + mac_stats = port->mac_stats_buf; + + for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) { + if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + continue; + + if ((ids == NULL) || (ids[nb_written] == nb_supported)) + values[nb_written++] = mac_stats[i]; + + ++nb_supported; + } + + ret = nb_written; + +unlock: + rte_spinlock_unlock(&port->mac_stats_lock); + + return ret; +} + +static int +sfc_xstats_get_names_by_id(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + const uint64_t *ids, unsigned int size) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + unsigned int nb_supported = 0; + unsigned int nb_written = 0; + unsigned int i; + + if (unlikely(xstats_names == NULL) || + unlikely((ids == NULL) && (size < port->mac_stats_nb_supported))) + return port->mac_stats_nb_supported; + + for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) { + if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + continue; + + if ((ids == NULL) || (ids[nb_written] == nb_supported)) { + char *name = xstats_names[nb_written++].name; + + strncpy(name, efx_mac_stat_name(sa->nic, i), + sizeof(xstats_names[0].name)); + name[sizeof(xstats_names[0].name) - 1] = '\0'; + } + + ++nb_supported; + } + + return nb_written; +} + +static int sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) { struct sfc_adapter *sa = dev->data->dev_private; @@ -826,10 +910,17 @@ sfc_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr) { struct sfc_adapter *sa = dev->data->dev_private; const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic); + struct sfc_port *port = &sa->port; int rc; sfc_adapter_lock(sa); + if (port->isolated) { + sfc_err(sa, "isolated mode is active on the port"); + sfc_err(sa, "will not set MAC address"); + goto unlock; + } + if (sa->state != SFC_ADAPTER_STARTED) { sfc_info(sa, "the port is not started"); sfc_info(sa, "the new MAC address will be set on port start"); @@ -884,6 +975,12 @@ sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set, int rc; unsigned int i; + if (port->isolated) { + sfc_err(sa, "isolated mode is active on the port"); + sfc_err(sa, "will not set multicast address list"); + return -ENOTSUP; + } + if (mc_addrs == NULL) return -ENOBUFS; @@ -913,6 +1010,10 @@ sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set, return -rc; } +/* + * The function is used by the secondary process as well. It must not + * use any process-local pointers from the adapter data. + */ static void sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, struct rte_eth_rxq_info *qinfo) @@ -939,6 +1040,10 @@ sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, sfc_adapter_unlock(sa); } +/* + * The function is used by the secondary process as well. It must not + * use any process-local pointers from the adapter data. + */ static void sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id, struct rte_eth_txq_info *qinfo) @@ -1083,8 +1188,9 @@ sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf) { struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; - if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) + if ((sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) || port->isolated) return -ENOTSUP; if (sa->rss_channels == 0) @@ -1113,9 +1219,13 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf) { struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; unsigned int efx_hash_types; int rc = 0; + if (port->isolated) + return -ENOTSUP; + if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) { sfc_err(sa, "RSS is not available"); return -ENOTSUP; @@ -1180,9 +1290,10 @@ sfc_dev_rss_reta_query(struct rte_eth_dev *dev, uint16_t reta_size) { struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; int entry; - if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) + if ((sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) || port->isolated) return -ENOTSUP; if (sa->rss_channels == 0) @@ -1212,11 +1323,15 @@ sfc_dev_rss_reta_update(struct rte_eth_dev *dev, uint16_t reta_size) { struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; unsigned int *rss_tbl_new; uint16_t entry; int rc; + if (port->isolated) + return -ENOTSUP; + if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) { sfc_err(sa, "RSS is not available"); return -ENOTSUP; @@ -1370,8 +1485,33 @@ static const struct eth_dev_ops sfc_eth_dev_ops = { .rxq_info_get = sfc_rx_queue_info_get, .txq_info_get = sfc_tx_queue_info_get, .fw_version_get = sfc_fw_version_get, + .xstats_get_by_id = sfc_xstats_get_by_id, + .xstats_get_names_by_id = sfc_xstats_get_names_by_id, }; +/** + * Duplicate a string in potentially shared memory required for + * multi-process support. + * + * strdup() allocates from process-local heap/memory. + */ +static char * +sfc_strdup(const char *str) +{ + size_t size; + char *copy; + + if (str == NULL) + return NULL; + + size = strlen(str) + 1; + copy = rte_malloc(__func__, size, 0); + if (copy != NULL) + rte_memcpy(copy, str, size); + + return copy; +} + static int sfc_eth_dev_set_ops(struct rte_eth_dev *dev) { @@ -1407,7 +1547,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) "Insufficient Hw/FW capabilities to use Rx datapath %s", rx_name); rc = EINVAL; - goto fail_dp_rx; + goto fail_dp_rx_caps; } } else { sa->dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps); @@ -1419,7 +1559,13 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) } } - sfc_info(sa, "use %s Rx datapath", sa->dp_rx->dp.name); + sa->dp_rx_name = sfc_strdup(sa->dp_rx->dp.name); + if (sa->dp_rx_name == NULL) { + rc = ENOMEM; + goto fail_dp_rx_name; + } + + sfc_info(sa, "use %s Rx datapath", sa->dp_rx_name); dev->rx_pkt_burst = sa->dp_rx->pkt_burst; @@ -1440,7 +1586,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) "Insufficient Hw/FW capabilities to use Tx datapath %s", tx_name); rc = EINVAL; - goto fail_dp_tx; + goto fail_dp_tx_caps; } } else { sa->dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps); @@ -1452,7 +1598,13 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) } } - sfc_info(sa, "use %s Tx datapath", sa->dp_tx->dp.name); + sa->dp_tx_name = sfc_strdup(sa->dp_tx->dp.name); + if (sa->dp_tx_name == NULL) { + rc = ENOMEM; + goto fail_dp_tx_name; + } + + sfc_info(sa, "use %s Tx datapath", sa->dp_tx_name); dev->tx_pkt_burst = sa->dp_tx->pkt_burst; @@ -1460,14 +1612,108 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) return 0; +fail_dp_tx_name: +fail_dp_tx_caps: + sa->dp_tx = NULL; + fail_dp_tx: fail_kvarg_tx_datapath: + rte_free(sa->dp_rx_name); + sa->dp_rx_name = NULL; + +fail_dp_rx_name: +fail_dp_rx_caps: + sa->dp_rx = NULL; + fail_dp_rx: fail_kvarg_rx_datapath: return rc; } static void +sfc_eth_dev_clear_ops(struct rte_eth_dev *dev) +{ + struct sfc_adapter *sa = dev->data->dev_private; + + dev->dev_ops = NULL; + dev->rx_pkt_burst = NULL; + dev->tx_pkt_burst = NULL; + + rte_free(sa->dp_tx_name); + sa->dp_tx_name = NULL; + sa->dp_tx = NULL; + + rte_free(sa->dp_rx_name); + sa->dp_rx_name = NULL; + sa->dp_rx = NULL; +} + +static const struct eth_dev_ops sfc_eth_dev_secondary_ops = { + .rxq_info_get = sfc_rx_queue_info_get, + .txq_info_get = sfc_tx_queue_info_get, +}; + +static int +sfc_eth_dev_secondary_set_ops(struct rte_eth_dev *dev) +{ + /* + * Device private data has really many process-local pointers. + * Below code should be extremely careful to use data located + * in shared memory only. + */ + struct sfc_adapter *sa = dev->data->dev_private; + const struct sfc_dp_rx *dp_rx; + const struct sfc_dp_tx *dp_tx; + int rc; + + dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sa->dp_rx_name); + if (dp_rx == NULL) { + sfc_err(sa, "cannot find %s Rx datapath", sa->dp_tx_name); + rc = ENOENT; + goto fail_dp_rx; + } + if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) { + sfc_err(sa, "%s Rx datapath does not support multi-process", + sa->dp_tx_name); + rc = EINVAL; + goto fail_dp_rx_multi_process; + } + + dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sa->dp_tx_name); + if (dp_tx == NULL) { + sfc_err(sa, "cannot find %s Tx datapath", sa->dp_tx_name); + rc = ENOENT; + goto fail_dp_tx; + } + if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) { + sfc_err(sa, "%s Tx datapath does not support multi-process", + sa->dp_tx_name); + rc = EINVAL; + goto fail_dp_tx_multi_process; + } + + dev->rx_pkt_burst = dp_rx->pkt_burst; + dev->tx_pkt_burst = dp_tx->pkt_burst; + dev->dev_ops = &sfc_eth_dev_secondary_ops; + + return 0; + +fail_dp_tx_multi_process: +fail_dp_tx: +fail_dp_rx_multi_process: +fail_dp_rx: + return rc; +} + +static void +sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev) +{ + dev->dev_ops = NULL; + dev->tx_pkt_burst = NULL; + dev->rx_pkt_burst = NULL; +} + +static void sfc_register_dp(void) { /* Register once */ @@ -1486,19 +1732,27 @@ static int sfc_eth_dev_init(struct rte_eth_dev *dev) { struct sfc_adapter *sa = dev->data->dev_private; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev); int rc; const efx_nic_cfg_t *encp; const struct ether_addr *from; sfc_register_dp(); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return -sfc_eth_dev_secondary_set_ops(dev); + /* Required for logging */ + sa->pci_addr = pci_dev->addr; + sa->port_id = dev->data->port_id; + sa->eth_dev = dev; /* Copy PCI device info to the dev->data */ rte_eth_copy_pci_info(dev, pci_dev); + dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE; + rc = sfc_kvargs_parse(sa); if (rc != 0) goto fail_kvargs_parse; @@ -1549,6 +1803,8 @@ sfc_eth_dev_init(struct rte_eth_dev *dev) return 0; fail_attach: + sfc_eth_dev_clear_ops(dev); + fail_set_ops: sfc_unprobe(sa); @@ -1571,22 +1827,26 @@ fail_kvargs_parse: static int sfc_eth_dev_uninit(struct rte_eth_dev *dev) { - struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_adapter *sa; + if (rte_eal_process_type() != RTE_PROC_PRIMARY) { + sfc_eth_dev_secondary_clear_ops(dev); + return 0; + } + + sa = dev->data->dev_private; sfc_log_init(sa, "entry"); sfc_adapter_lock(sa); + sfc_eth_dev_clear_ops(dev); + sfc_detach(sa); sfc_unprobe(sa); rte_free(dev->data->mac_addrs); dev->data->mac_addrs = NULL; - dev->dev_ops = NULL; - dev->rx_pkt_burst = NULL; - dev->tx_pkt_burst = NULL; - sfc_kvargs_cleanup(sa); sfc_adapter_unlock(sa); diff --git a/drivers/net/sfc/sfc_ev.c b/drivers/net/sfc/sfc_ev.c index 160d39f9..a16dc27b 100644 --- a/drivers/net/sfc/sfc_ev.c +++ b/drivers/net/sfc/sfc_ev.c @@ -237,8 +237,7 @@ sfc_ev_dp_tx(void *arg, __rte_unused uint32_t label, uint32_t id) } static boolean_t -sfc_ev_exception(void *arg, __rte_unused uint32_t code, - __rte_unused uint32_t data) +sfc_ev_exception(void *arg, uint32_t code, __rte_unused uint32_t data) { struct sfc_evq *evq = arg; diff --git a/drivers/net/sfc/sfc_flow.c b/drivers/net/sfc/sfc_flow.c index c3ea43a6..110dfb89 100644 --- a/drivers/net/sfc/sfc_flow.c +++ b/drivers/net/sfc/sfc_flow.c @@ -1112,12 +1112,35 @@ sfc_flow_flush(struct rte_eth_dev *dev, return -ret; } +static int +sfc_flow_isolate(struct rte_eth_dev *dev, int enable, + struct rte_flow_error *error) +{ + struct sfc_adapter *sa = dev->data->dev_private; + struct sfc_port *port = &sa->port; + int ret = 0; + + sfc_adapter_lock(sa); + if (sa->state != SFC_ADAPTER_INITIALIZED) { + rte_flow_error_set(error, EBUSY, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "please close the port first"); + ret = -rte_errno; + } else { + port->isolated = (enable) ? B_TRUE : B_FALSE; + } + sfc_adapter_unlock(sa); + + return ret; +} + const struct rte_flow_ops sfc_flow_ops = { .validate = sfc_flow_validate, .create = sfc_flow_create, .destroy = sfc_flow_destroy, .flush = sfc_flow_flush, .query = NULL, + .isolate = sfc_flow_isolate, }; void diff --git a/drivers/net/sfc/sfc_intr.c b/drivers/net/sfc/sfc_intr.c index 7eb4b86c..ee59cb1c 100644 --- a/drivers/net/sfc/sfc_intr.c +++ b/drivers/net/sfc/sfc_intr.c @@ -77,7 +77,7 @@ sfc_intr_line_handler(void *cb_arg) boolean_t fatal; uint32_t qmask; unsigned int lsc_seq = sa->port.lsc_seq; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); sfc_log_init(sa, "entry"); @@ -111,7 +111,8 @@ exit: sa->eth_dev->data->dev_link.link_status ? "UP" : "DOWN"); _rte_eth_dev_callback_process(sa->eth_dev, - RTE_ETH_EVENT_INTR_LSC, NULL); + RTE_ETH_EVENT_INTR_LSC, + NULL, NULL); } } @@ -122,7 +123,7 @@ sfc_intr_message_handler(void *cb_arg) efx_nic_t *enp = sa->nic; boolean_t fatal; unsigned int lsc_seq = sa->port.lsc_seq; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); sfc_log_init(sa, "entry"); @@ -152,7 +153,8 @@ exit: if (lsc_seq != sa->port.lsc_seq) { sfc_info(sa, "link status change event"); _rte_eth_dev_callback_process(sa->eth_dev, - RTE_ETH_EVENT_INTR_LSC, NULL); + RTE_ETH_EVENT_INTR_LSC, + NULL, NULL); } } @@ -177,7 +179,7 @@ sfc_intr_start(struct sfc_adapter *sa) if (rc != 0) goto fail_intr_init; - pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); intr_handle = &pci_dev->intr_handle; if (intr->handler != NULL) { @@ -232,7 +234,7 @@ void sfc_intr_stop(struct sfc_adapter *sa) { struct sfc_intr *intr = &sa->intr; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); sfc_log_init(sa, "entry"); @@ -306,7 +308,7 @@ int sfc_intr_attach(struct sfc_adapter *sa) { struct sfc_intr *intr = &sa->intr; - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(sa->eth_dev); sfc_log_init(sa, "entry"); diff --git a/drivers/net/sfc/sfc_log.h b/drivers/net/sfc/sfc_log.h index 8a5e2302..b1a9df44 100644 --- a/drivers/net/sfc/sfc_log.h +++ b/drivers/net/sfc/sfc_log.h @@ -35,17 +35,16 @@ /* Log PMD message, automatically add prefix and \n */ #define SFC_LOG(sa, level, ...) \ do { \ - const struct rte_eth_dev *_dev = (sa)->eth_dev; \ - const struct rte_pci_device *_pci_dev = SFC_DEV_TO_PCI(_dev); \ + const struct sfc_adapter *__sa = (sa); \ \ RTE_LOG(level, PMD, \ RTE_FMT("sfc_efx " PCI_PRI_FMT " #%" PRIu8 ": " \ RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ - _pci_dev->addr.domain, \ - _pci_dev->addr.bus, \ - _pci_dev->addr.devid, \ - _pci_dev->addr.function, \ - _dev->data->port_id, \ + __sa->pci_addr.domain, \ + __sa->pci_addr.bus, \ + __sa->pci_addr.devid, \ + __sa->pci_addr.function, \ + __sa->port_id, \ RTE_FMT_TAIL(__VA_ARGS__,))); \ } while (0) diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index ee96bcde..c1466a77 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -151,6 +151,7 @@ sfc_port_start(struct sfc_adapter *sa) uint32_t phy_adv_cap; const uint32_t phy_pause_caps = ((1u << EFX_PHY_CAP_PAUSE) | (1u << EFX_PHY_CAP_ASYM)); + unsigned int i; sfc_log_init(sa, "entry"); @@ -186,26 +187,29 @@ sfc_port_start(struct sfc_adapter *sa) if (rc != 0) goto fail_mac_pdu_set; - sfc_log_init(sa, "set MAC address"); - rc = efx_mac_addr_set(sa->nic, - sa->eth_dev->data->mac_addrs[0].addr_bytes); - if (rc != 0) - goto fail_mac_addr_set; - - sfc_log_init(sa, "set MAC filters"); - port->promisc = (sa->eth_dev->data->promiscuous != 0) ? - B_TRUE : B_FALSE; - port->allmulti = (sa->eth_dev->data->all_multicast != 0) ? - B_TRUE : B_FALSE; - rc = sfc_set_rx_mode(sa); - if (rc != 0) - goto fail_mac_filter_set; + if (!port->isolated) { + struct ether_addr *mac_addrs = sa->eth_dev->data->mac_addrs; - sfc_log_init(sa, "set multicast address list"); - rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs, - port->nb_mcast_addrs); - if (rc != 0) - goto fail_mcast_address_list_set; + sfc_log_init(sa, "set MAC address"); + rc = efx_mac_addr_set(sa->nic, mac_addrs[0].addr_bytes); + if (rc != 0) + goto fail_mac_addr_set; + + sfc_log_init(sa, "set MAC filters"); + port->promisc = (sa->eth_dev->data->promiscuous != 0) ? + B_TRUE : B_FALSE; + port->allmulti = (sa->eth_dev->data->all_multicast != 0) ? + B_TRUE : B_FALSE; + rc = sfc_set_rx_mode(sa); + if (rc != 0) + goto fail_mac_filter_set; + + sfc_log_init(sa, "set multicast address list"); + rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs, + port->nb_mcast_addrs); + if (rc != 0) + goto fail_mcast_address_list_set; + } if (port->mac_stats_reset_pending) { rc = sfc_port_reset_mac_stats(sa); @@ -219,6 +223,10 @@ sfc_port_start(struct sfc_adapter *sa) efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask, sizeof(port->mac_stats_mask)); + for (i = 0, port->mac_stats_nb_supported = 0; i < EFX_MAC_NSTATS; ++i) + if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) + port->mac_stats_nb_supported++; + port->mac_stats_update_generation = 0; if (port->mac_stats_update_period_ms != 0) { @@ -242,6 +250,18 @@ sfc_port_start(struct sfc_adapter *sa) } } + if ((port->mac_stats_update_period_ms != 0) && + port->mac_stats_periodic_dma_supported) { + /* + * Request an explicit MAC stats upload immediately to + * preclude bogus figures readback if the user decides + * to read stats before periodic DMA is really started + */ + rc = efx_mac_stats_upload(sa->nic, &port->mac_stats_dma_mem); + if (rc != 0) + goto fail_mac_stats_upload; + } + sfc_log_init(sa, "disable MAC drain"); rc = efx_mac_drain(sa->nic, B_FALSE); if (rc != 0) @@ -262,6 +282,7 @@ fail_mac_drain: (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, 0, B_FALSE); +fail_mac_stats_upload: fail_mac_stats_periodic: fail_mcast_address_list_set: fail_mac_filter_set: diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 2ecd6f26..1bf86445 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -292,7 +292,7 @@ sfc_efx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) if (desc_flags & EFX_PKT_CONT) { /* The packet is scattered, more fragments to come */ scatter_pkt = m; - /* Futher fragments have no prefix */ + /* Further fragments have no prefix */ prefix_size = 0; continue; } @@ -529,6 +529,7 @@ sfc_rx_qflush(struct sfc_adapter *sa, unsigned int sw_index) struct sfc_rxq *rxq; unsigned int retry_count; unsigned int wait_count; + int rc; rxq = sa->rxq_info[sw_index].rxq; SFC_ASSERT(rxq->state & SFC_RXQ_STARTED); @@ -541,8 +542,10 @@ sfc_rx_qflush(struct sfc_adapter *sa, unsigned int sw_index) ((rxq->state & SFC_RXQ_FLUSHED) == 0) && (retry_count < SFC_RX_QFLUSH_ATTEMPTS); ++retry_count) { - if (efx_rx_qflush(rxq->common) != 0) { - rxq->state |= SFC_RXQ_FLUSH_FAILED; + rc = efx_rx_qflush(rxq->common); + if (rc != 0) { + rxq->state |= (rc == EALREADY) ? + SFC_RXQ_FLUSHED : SFC_RXQ_FLUSH_FAILED; break; } rxq->state &= ~SFC_RXQ_FLUSH_FAILED; @@ -627,6 +630,7 @@ retry: int sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index) { + struct sfc_port *port = &sa->port; struct sfc_rxq_info *rxq_info; struct sfc_rxq *rxq; struct sfc_evq *evq; @@ -661,7 +665,7 @@ sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index) rxq->state |= SFC_RXQ_STARTED; - if (sw_index == 0) { + if ((sw_index == 0) && !port->isolated) { rc = sfc_rx_default_rxq_set_filter(sa, rxq); if (rc != 0) goto fail_mac_filter_default_rxq_set; @@ -942,7 +946,7 @@ sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index, info.mem_bar = sa->mem_bar.esb_base; rc = sa->dp_rx->qcreate(sa->eth_dev->data->port_id, sw_index, - &SFC_DEV_TO_PCI(sa->eth_dev)->addr, + &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr, socket_id, &info, &rxq->dp); if (rc != 0) goto fail_dp_rx_qcreate; diff --git a/drivers/net/sfc/sfc_tx.c b/drivers/net/sfc/sfc_tx.c index 23230144..fc439cb6 100644 --- a/drivers/net/sfc/sfc_tx.c +++ b/drivers/net/sfc/sfc_tx.c @@ -185,7 +185,7 @@ sfc_tx_qinit(struct sfc_adapter *sa, unsigned int sw_index, info.mem_bar = sa->mem_bar.esb_base; rc = sa->dp_tx->qcreate(sa->eth_dev->data->port_id, sw_index, - &SFC_DEV_TO_PCI(sa->eth_dev)->addr, + &RTE_ETH_DEV_TO_PCI(sa->eth_dev)->addr, socket_id, &info, &txq->dp); if (rc != 0) goto fail_dp_tx_qinit; @@ -479,6 +479,7 @@ sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index) struct sfc_txq *txq; unsigned int retry_count; unsigned int wait_count; + int rc; sfc_log_init(sa, "TxQ = %u", sw_index); @@ -502,8 +503,10 @@ sfc_tx_qstop(struct sfc_adapter *sa, unsigned int sw_index) ((txq->state & SFC_TXQ_FLUSHED) == 0) && (retry_count < SFC_TX_QFLUSH_ATTEMPTS); ++retry_count) { - if (efx_tx_qflush(txq->common) != 0) { - txq->state |= SFC_TXQ_FLUSH_FAILED; + rc = efx_tx_qflush(txq->common); + if (rc != 0) { + txq->state |= (rc == EALREADY) ? + SFC_TXQ_FLUSHED : SFC_TXQ_FLUSH_FAILED; break; } |