From 329472d44475f4240f89a899173fdf63df75afe9 Mon Sep 17 00:00:00 2001 From: Andrew Rybchenko Date: Wed, 29 Mar 2017 17:59:18 +0100 Subject: [PATCH] net/sfc: choose datapaths after probe and before attach Datapath choice requires NIC capabilities knowledge and, therefore, should be done after probe. Whereas NIC resources estimation needs to know chosen datapath (e.g. if Tx datapath is going to use TSO). Fixes: df1bfde4ff0d ("net/sfc: factor out libefx-based Rx datapath") Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/sfc.c | 107 ++++++++++++++++++++++------------- drivers/net/sfc/sfc.h | 2 + drivers/net/sfc/sfc_ethdev.c | 20 +++++-- 3 files changed, 84 insertions(+), 45 deletions(-) diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index 655d667b84..eda426c2dd 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -571,46 +571,14 @@ fail_intr_init: int sfc_attach(struct sfc_adapter *sa) { - struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); const efx_nic_cfg_t *encp; - efx_nic_t *enp; + efx_nic_t *enp = sa->nic; int rc; sfc_log_init(sa, "entry"); SFC_ASSERT(sfc_adapter_is_locked(sa)); - sa->socket_id = rte_socket_id(); - - sfc_log_init(sa, "init mem bar"); - rc = sfc_mem_bar_init(sa); - if (rc != 0) - goto fail_mem_bar_init; - - sfc_log_init(sa, "get family"); - rc = efx_family(pci_dev->id.vendor_id, pci_dev->id.device_id, - &sa->family); - if (rc != 0) - goto fail_family; - sfc_log_init(sa, "family is %u", sa->family); - - sfc_log_init(sa, "create nic"); - rte_spinlock_init(&sa->nic_lock); - rc = efx_nic_create(sa->family, (efsys_identifier_t *)sa, - &sa->mem_bar, &sa->nic_lock, &enp); - if (rc != 0) - goto fail_nic_create; - sa->nic = enp; - - rc = sfc_mcdi_init(sa); - if (rc != 0) - goto fail_mcdi_init; - - sfc_log_init(sa, "probe nic"); - rc = efx_nic_probe(enp); - if (rc != 0) - goto fail_nic_probe; - efx_mcdi_new_epoch(enp); sfc_log_init(sa, "reset nic"); @@ -666,8 +634,71 @@ fail_intr_attach: fail_estimate_rsrc_limits: fail_nic_reset: - sfc_log_init(sa, "unprobe nic"); - efx_nic_unprobe(enp); + + sfc_log_init(sa, "failed %d", rc); + return rc; +} + +void +sfc_detach(struct sfc_adapter *sa) +{ + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + sfc_flow_fini(sa); + + sfc_filter_detach(sa); + + sfc_intr_detach(sa); + + sa->state = SFC_ADAPTER_UNINITIALIZED; +} + +int +sfc_probe(struct sfc_adapter *sa) +{ + struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(sa->eth_dev); + efx_nic_t *enp; + int rc; + + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + sa->socket_id = rte_socket_id(); + + sfc_log_init(sa, "init mem bar"); + rc = sfc_mem_bar_init(sa); + if (rc != 0) + goto fail_mem_bar_init; + + sfc_log_init(sa, "get family"); + rc = efx_family(pci_dev->id.vendor_id, pci_dev->id.device_id, + &sa->family); + if (rc != 0) + goto fail_family; + sfc_log_init(sa, "family is %u", sa->family); + + sfc_log_init(sa, "create nic"); + rte_spinlock_init(&sa->nic_lock); + rc = efx_nic_create(sa->family, (efsys_identifier_t *)sa, + &sa->mem_bar, &sa->nic_lock, &enp); + if (rc != 0) + goto fail_nic_create; + sa->nic = enp; + + rc = sfc_mcdi_init(sa); + if (rc != 0) + goto fail_mcdi_init; + + sfc_log_init(sa, "probe nic"); + rc = efx_nic_probe(enp); + if (rc != 0) + goto fail_nic_probe; + + sfc_log_init(sa, "done"); + return 0; fail_nic_probe: sfc_mcdi_fini(sa); @@ -687,7 +718,7 @@ fail_mem_bar_init: } void -sfc_detach(struct sfc_adapter *sa) +sfc_unprobe(struct sfc_adapter *sa) { efx_nic_t *enp = sa->nic; @@ -695,10 +726,6 @@ sfc_detach(struct sfc_adapter *sa) SFC_ASSERT(sfc_adapter_is_locked(sa)); - sfc_filter_detach(sa); - - sfc_intr_detach(sa); - sfc_log_init(sa, "unprobe nic"); efx_nic_unprobe(enp); diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index c2961ea11a..a7a9868321 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -283,6 +283,8 @@ int sfc_dma_alloc(const struct sfc_adapter *sa, const char *name, uint16_t id, size_t len, int socket_id, efsys_mem_t *esmp); void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp); +int sfc_probe(struct sfc_adapter *sa); +void sfc_unprobe(struct sfc_adapter *sa); int sfc_attach(struct sfc_adapter *sa); void sfc_detach(struct sfc_adapter *sa); int sfc_start(struct sfc_adapter *sa); diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index bba8b0157d..7edb17d7e2 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -1370,9 +1370,6 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev) const char *tx_name = NULL; int rc; - if (sa == NULL || sa->state == SFC_ADAPTER_UNINITIALIZED) - return -E_RTE_SECONDARY; - switch (sa->family) { case EFX_FAMILY_HUNTINGTON: case EFX_FAMILY_MEDFORD: @@ -1511,6 +1508,16 @@ sfc_eth_dev_init(struct rte_eth_dev *dev) sfc_adapter_lock_init(sa); sfc_adapter_lock(sa); + sfc_log_init(sa, "probing"); + rc = sfc_probe(sa); + if (rc != 0) + goto fail_probe; + + sfc_log_init(sa, "set device ops"); + rc = sfc_eth_dev_set_ops(dev); + if (rc != 0) + goto fail_set_ops; + sfc_log_init(sa, "attaching"); rc = sfc_attach(sa); if (rc != 0) @@ -1527,12 +1534,14 @@ sfc_eth_dev_init(struct rte_eth_dev *dev) sfc_adapter_unlock(sa); - sfc_eth_dev_set_ops(dev); - sfc_log_init(sa, "done"); return 0; fail_attach: +fail_set_ops: + sfc_unprobe(sa); + +fail_probe: sfc_adapter_unlock(sa); sfc_adapter_lock_fini(sa); rte_free(dev->data->mac_addrs); @@ -1558,6 +1567,7 @@ sfc_eth_dev_uninit(struct rte_eth_dev *dev) sfc_adapter_lock(sa); sfc_detach(sa); + sfc_unprobe(sa); rte_free(dev->data->mac_addrs); dev->data->mac_addrs = NULL; -- 2.20.1