net/sfc: use locally stored data for logging
[dpdk.git] / drivers / net / sfc / sfc_ethdev.c
index 010641b..0660a00 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <rte_dev.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_pci.h>
 #include <rte_errno.h>
 
@@ -106,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 */
@@ -135,11 +136,15 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                DEV_TX_OFFLOAD_TCP_CKSUM;
 
        dev_info->default_txconf.txq_flags = ETH_TXQ_FLAGS_NOXSUMSCTP;
-       if (!encp->enc_hw_tx_insert_vlan_enabled)
+       if ((~sa->dp_tx->features & SFC_DP_TX_FEAT_VLAN_INSERT) ||
+           !encp->enc_hw_tx_insert_vlan_enabled)
                dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOVLANOFFL;
        else
                dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_VLAN_INSERT;
 
+       if (~sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_SEG)
+               dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
+
 #if EFSYS_OPT_RX_SCALE
        if (sa->rss_support != EFX_RX_SCALE_UNAVAILABLE) {
                dev_info->reta_size = EFX_RSS_TBL_SIZE;
@@ -188,8 +193,6 @@ sfc_dev_configure(struct rte_eth_dev *dev)
        sfc_adapter_lock(sa);
        switch (sa->state) {
        case SFC_ADAPTER_CONFIGURED:
-               sfc_close(sa);
-               SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
                /* FALLTHROUGH */
        case SFC_ADAPTER_INITIALIZED:
                rc = sfc_configure(sa);
@@ -467,7 +470,7 @@ sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
        if (rc != 0)
                goto fail_tx_qinit;
 
-       dev->data->tx_queues[tx_queue_id] = sa->txq_info[tx_queue_id].txq;
+       dev->data->tx_queues[tx_queue_id] = sa->txq_info[tx_queue_id].txq->dp;
 
        sfc_adapter_unlock(sa);
        return 0;
@@ -481,13 +484,15 @@ fail_tx_qinit:
 static void
 sfc_tx_queue_release(void *queue)
 {
-       struct sfc_txq *txq = queue;
+       struct sfc_dp_txq *dp_txq = queue;
+       struct sfc_txq *txq;
        unsigned int sw_index;
        struct sfc_adapter *sa;
 
-       if (txq == NULL)
+       if (dp_txq == NULL)
                return;
 
+       txq = sfc_txq_by_dp_txq(dp_txq);
        sw_index = sfc_txq_sw_index(txq);
 
        SFC_ASSERT(txq->evq != NULL);
@@ -1079,10 +1084,12 @@ sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
 {
        struct sfc_adapter *sa = dev->data->dev_private;
 
-       if ((sa->rss_channels == 1) ||
-           (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE))
+       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)
                return -ENOTSUP;
 
+       if (sa->rss_channels == 0)
+               return -EINVAL;
+
        sfc_adapter_lock(sa);
 
        /*
@@ -1109,12 +1116,16 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
        unsigned int efx_hash_types;
        int rc = 0;
 
-       if ((sa->rss_channels == 1) ||
-           (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)) {
+       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) {
                sfc_err(sa, "RSS is not available");
                return -ENOTSUP;
        }
 
+       if (sa->rss_channels == 0) {
+               sfc_err(sa, "RSS is not configured");
+               return -EINVAL;
+       }
+
        if ((rss_conf->rss_key != NULL) &&
            (rss_conf->rss_key_len != sizeof(sa->rss_key))) {
                sfc_err(sa, "RSS key size is wrong (should be %lu)",
@@ -1171,10 +1182,12 @@ sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
        struct sfc_adapter *sa = dev->data->dev_private;
        int entry;
 
-       if ((sa->rss_channels == 1) ||
-           (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE))
+       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)
                return -ENOTSUP;
 
+       if (sa->rss_channels == 0)
+               return -EINVAL;
+
        if (reta_size != EFX_RSS_TBL_SIZE)
                return -EINVAL;
 
@@ -1204,12 +1217,16 @@ sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
        int rc;
 
 
-       if ((sa->rss_channels == 1) ||
-           (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)) {
+       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) {
                sfc_err(sa, "RSS is not available");
                return -ENOTSUP;
        }
 
+       if (sa->rss_channels == 0) {
+               sfc_err(sa, "RSS is not configured");
+               return -EINVAL;
+       }
+
        if (reta_size != EFX_RSS_TBL_SIZE) {
                sfc_err(sa, "RETA size is wrong (should be %u)",
                        EFX_RSS_TBL_SIZE);
@@ -1361,11 +1378,9 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
        struct sfc_adapter *sa = dev->data->dev_private;
        unsigned int avail_caps = 0;
        const char *rx_name = NULL;
+       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:
@@ -1392,7 +1407,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);
@@ -1408,17 +1423,69 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
        dev->rx_pkt_burst = sa->dp_rx->pkt_burst;
 
-       dev->tx_pkt_burst = sfc_xmit_pkts;
+       rc = sfc_kvargs_process(sa, SFC_KVARG_TX_DATAPATH,
+                               sfc_kvarg_string_handler, &tx_name);
+       if (rc != 0)
+               goto fail_kvarg_tx_datapath;
+
+       if (tx_name != NULL) {
+               sa->dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
+               if (sa->dp_tx == NULL) {
+                       sfc_err(sa, "Tx datapath %s not found", tx_name);
+                       rc = ENOENT;
+                       goto fail_dp_tx;
+               }
+               if (!sfc_dp_match_hw_fw_caps(&sa->dp_tx->dp, avail_caps)) {
+                       sfc_err(sa,
+                               "Insufficient Hw/FW capabilities to use Tx datapath %s",
+                               tx_name);
+                       rc = EINVAL;
+                       goto fail_dp_tx_caps;
+               }
+       } else {
+               sa->dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
+               if (sa->dp_tx == NULL) {
+                       sfc_err(sa, "Tx datapath by caps %#x not found",
+                               avail_caps);
+                       rc = ENOENT;
+                       goto fail_dp_tx;
+               }
+       }
+
+       sfc_info(sa, "use %s Tx datapath", sa->dp_tx->dp.name);
+
+       dev->tx_pkt_burst = sa->dp_tx->pkt_burst;
 
        dev->dev_ops = &sfc_eth_dev_ops;
 
        return 0;
 
+fail_dp_tx_caps:
+       sa->dp_tx = NULL;
+
+fail_dp_tx:
+fail_kvarg_tx_datapath:
+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;
+
+       sa->dp_tx = NULL;
+       sa->dp_rx = NULL;
+}
+
 static void
 sfc_register_dp(void)
 {
@@ -1427,6 +1494,10 @@ sfc_register_dp(void)
                /* Prefer EF10 datapath */
                sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
                sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
+
+               sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
+               sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
+               sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
        }
 }
 
@@ -1434,7 +1505,7 @@ 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;
@@ -1442,6 +1513,9 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
        sfc_register_dp();
 
        /* 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 */
@@ -1467,6 +1541,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)
@@ -1483,12 +1567,16 @@ 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:
+       sfc_eth_dev_clear_ops(dev);
+
+fail_set_ops:
+       sfc_unprobe(sa);
+
+fail_probe:
        sfc_adapter_unlock(sa);
        sfc_adapter_lock_fini(sa);
        rte_free(dev->data->mac_addrs);
@@ -1513,15 +1601,14 @@ sfc_eth_dev_uninit(struct rte_eth_dev *dev)
 
        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);
@@ -1544,25 +1631,33 @@ static const struct rte_pci_id pci_id_sfc_efx_map[] = {
        { .vendor_id = 0 /* sentinel */ }
 };
 
-static struct eth_driver sfc_efx_pmd = {
-       .pci_drv = {
-               .id_table = pci_id_sfc_efx_map,
-               .drv_flags =
-                       RTE_PCI_DRV_INTR_LSC |
-                       RTE_PCI_DRV_NEED_MAPPING,
-               .probe = rte_eth_dev_pci_probe,
-               .remove = rte_eth_dev_pci_remove,
-       },
-       .eth_dev_init = sfc_eth_dev_init,
-       .eth_dev_uninit = sfc_eth_dev_uninit,
-       .dev_private_size = sizeof(struct sfc_adapter),
+static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+       struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_probe(pci_dev,
+               sizeof(struct sfc_adapter), sfc_eth_dev_init);
+}
+
+static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
+}
+
+static struct rte_pci_driver sfc_efx_pmd = {
+       .id_table = pci_id_sfc_efx_map,
+       .drv_flags =
+               RTE_PCI_DRV_INTR_LSC |
+               RTE_PCI_DRV_NEED_MAPPING,
+       .probe = sfc_eth_dev_pci_probe,
+       .remove = sfc_eth_dev_pci_remove,
 };
 
-RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
-RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio");
+RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
        SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
+       SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
        SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
        SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long> "
        SFC_KVARG_MCDI_LOGGING "=" SFC_KVARG_VALUES_BOOL " "