net/sfc: remove unnecessary functions to get TxQ index
[dpdk.git] / drivers / net / sfc / sfc_ethdev.c
index 87a2c94..a00ea9c 100644 (file)
@@ -84,6 +84,7 @@ sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
 static void
 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
+       const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
        struct sfc_adapter *sa = dev->data->dev_private;
        struct sfc_rss *rss = &sa->rss;
        uint64_t txq_offloads_def = 0;
@@ -167,10 +168,10 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
         */
        dev_info->tx_desc_lim.nb_align = EFX_TXQ_MINNDESCS;
 
-       if (sa->dp_rx->get_dev_info != NULL)
-               sa->dp_rx->get_dev_info(dev_info);
-       if (sa->dp_tx->get_dev_info != NULL)
-               sa->dp_tx->get_dev_info(dev_info);
+       if (sap->dp_rx->get_dev_info != NULL)
+               sap->dp_rx->get_dev_info(dev_info);
+       if (sap->dp_tx->get_dev_info != NULL)
+               sap->dp_tx->get_dev_info(dev_info);
 
        dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
                             RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
@@ -179,11 +180,12 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 static const uint32_t *
 sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 {
+       const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
        struct sfc_adapter *sa = dev->data->dev_private;
        const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
        uint32_t tunnel_encaps = encp->enc_tunnel_encapsulations_supported;
 
-       return sa->dp_rx->supported_ptypes_get(tunnel_encaps);
+       return sap->dp_rx->supported_ptypes_get(tunnel_encaps);
 }
 
 static int
@@ -413,7 +415,7 @@ sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
        if (rc != 0)
                goto fail_rx_qinit;
 
-       dev->data->rx_queues[rx_queue_id] = sa->rxq_info[rx_queue_id].rxq->dp;
+       dev->data->rx_queues[rx_queue_id] = sa->rxq_info[rx_queue_id].dp;
 
        sfc_adapter_unlock(sa);
 
@@ -440,7 +442,7 @@ sfc_rx_queue_release(void *queue)
        sa = rxq->evq->sa;
        sfc_adapter_lock(sa);
 
-       sw_index = sfc_rxq_sw_index(rxq);
+       sw_index = dp_rxq->dpq.queue_id;
 
        sfc_log_init(sa, "RxQ=%u", sw_index);
 
@@ -466,7 +468,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->dp;
+       dev->data->tx_queues[tx_queue_id] = sa->txq_info[tx_queue_id].dp;
 
        sfc_adapter_unlock(sa);
        return 0;
@@ -489,7 +491,7 @@ sfc_tx_queue_release(void *queue)
                return;
 
        txq = sfc_txq_by_dp_txq(dp_txq);
-       sw_index = sfc_txq_sw_index(txq);
+       sw_index = dp_txq->dpq.queue_id;
 
        SFC_ASSERT(txq->evq != NULL);
        sa = txq->evq->sa;
@@ -1115,38 +1117,69 @@ sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_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 uint32_t
 sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
+       const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_rxq_info *rxq_info;
+
+       SFC_ASSERT(rx_queue_id < sa->rxq_count);
+       rxq_info = &sa->rxq_info[rx_queue_id];
 
-       return sfc_rx_qdesc_npending(sa, rx_queue_id);
+       if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
+               return 0;
+
+       return sap->dp_rx->qdesc_npending(rxq_info->dp);
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static int
 sfc_rx_descriptor_done(void *queue, uint16_t offset)
 {
        struct sfc_dp_rxq *dp_rxq = queue;
+       const struct sfc_dp_rx *dp_rx;
+
+       dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
 
-       return sfc_rx_qdesc_done(dp_rxq, offset);
+       return offset < dp_rx->qdesc_npending(dp_rxq);
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static int
 sfc_rx_descriptor_status(void *queue, uint16_t offset)
 {
        struct sfc_dp_rxq *dp_rxq = queue;
-       struct sfc_rxq *rxq = sfc_rxq_by_dp_rxq(dp_rxq);
+       const struct sfc_dp_rx *dp_rx;
+
+       dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
 
-       return rxq->evq->sa->dp_rx->qdesc_status(dp_rxq, offset);
+       return dp_rx->qdesc_status(dp_rxq, offset);
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static int
 sfc_tx_descriptor_status(void *queue, uint16_t offset)
 {
        struct sfc_dp_txq *dp_txq = queue;
-       struct sfc_txq *txq = sfc_txq_by_dp_txq(dp_txq);
+       const struct sfc_dp_tx *dp_tx;
+
+       dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
 
-       return txq->evq->sa->dp_tx->qdesc_status(dp_txq, offset);
+       return dp_tx->qdesc_status(dp_txq, offset);
 }
 
 static int
@@ -1370,6 +1403,10 @@ sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
        return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static int
 sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
                          struct rte_eth_rss_conf *rss_conf)
@@ -1470,6 +1507,10 @@ fail_rx_hf_rte_to_efx:
        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 int
 sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
                       struct rte_eth_rss_reta_entry64 *reta_conf,
@@ -1637,16 +1678,16 @@ sfc_dev_filter_ctrl(struct rte_eth_dev *dev, enum rte_filter_type filter_type,
 static int
 sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
 {
-       struct sfc_adapter *sa = dev->data->dev_private;
+       const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
 
        /*
         * If Rx datapath does not provide callback to check mempool,
         * all pools are supported.
         */
-       if (sa->dp_rx->pool_ops_supported == NULL)
+       if (sap->dp_rx->pool_ops_supported == NULL)
                return 1;
 
-       return sa->dp_rx->pool_ops_supported(pool);
+       return sap->dp_rx->pool_ops_supported(pool);
 }
 
 static const struct eth_dev_ops sfc_eth_dev_ops = {
@@ -1727,6 +1768,8 @@ static int
 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
+       const struct sfc_dp_rx *dp_rx;
+       const struct sfc_dp_tx *dp_tx;
        const efx_nic_cfg_t *encp;
        unsigned int avail_caps = 0;
        const char *rx_name = NULL;
@@ -1753,13 +1796,13 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                goto fail_kvarg_rx_datapath;
 
        if (rx_name != NULL) {
-               sa->dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
-               if (sa->dp_rx == NULL) {
+               dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
+               if (dp_rx == NULL) {
                        sfc_err(sa, "Rx datapath %s not found", rx_name);
                        rc = ENOENT;
                        goto fail_dp_rx;
                }
-               if (!sfc_dp_match_hw_fw_caps(&sa->dp_rx->dp, avail_caps)) {
+               if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
                        sfc_err(sa,
                                "Insufficient Hw/FW capabilities to use Rx datapath %s",
                                rx_name);
@@ -1767,8 +1810,8 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                        goto fail_dp_rx_caps;
                }
        } else {
-               sa->dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
-               if (sa->dp_rx == NULL) {
+               dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
+               if (dp_rx == NULL) {
                        sfc_err(sa, "Rx datapath by caps %#x not found",
                                avail_caps);
                        rc = ENOENT;
@@ -1776,7 +1819,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                }
        }
 
-       sa->dp_rx_name = sfc_strdup(sa->dp_rx->dp.name);
+       sa->dp_rx_name = sfc_strdup(dp_rx->dp.name);
        if (sa->dp_rx_name == NULL) {
                rc = ENOMEM;
                goto fail_dp_rx_name;
@@ -1784,21 +1827,19 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
        sfc_notice(sa, "use %s Rx datapath", sa->dp_rx_name);
 
-       dev->rx_pkt_burst = sa->dp_rx->pkt_burst;
-
        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) {
+               dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
+               if (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)) {
+               if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
                        sfc_err(sa,
                                "Insufficient Hw/FW capabilities to use Tx datapath %s",
                                tx_name);
@@ -1806,8 +1847,8 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                        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) {
+               dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
+               if (dp_tx == NULL) {
                        sfc_err(sa, "Tx datapath by caps %#x not found",
                                avail_caps);
                        rc = ENOENT;
@@ -1815,7 +1856,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                }
        }
 
-       sa->dp_tx_name = sfc_strdup(sa->dp_tx->dp.name);
+       sa->dp_tx_name = sfc_strdup(dp_tx->dp.name);
        if (sa->dp_tx_name == NULL) {
                rc = ENOMEM;
                goto fail_dp_tx_name;
@@ -1823,7 +1864,11 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
        sfc_notice(sa, "use %s Tx datapath", sa->dp_tx_name);
 
-       dev->tx_pkt_burst = sa->dp_tx->pkt_burst;
+       sa->priv.dp_rx = dp_rx;
+       sa->priv.dp_tx = dp_tx;
+
+       dev->rx_pkt_burst = dp_rx->pkt_burst;
+       dev->tx_pkt_burst = dp_tx->pkt_burst;
 
        dev->dev_ops = &sfc_eth_dev_ops;
 
@@ -1831,8 +1876,6 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
 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);
@@ -1840,8 +1883,6 @@ fail_kvarg_tx_datapath:
 
 fail_dp_rx_name:
 fail_dp_rx_caps:
-       sa->dp_rx = NULL;
-
 fail_dp_rx:
 fail_kvarg_rx_datapath:
        return rc;
@@ -1858,20 +1899,26 @@ sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
 
        rte_free(sa->dp_tx_name);
        sa->dp_tx_name = NULL;
-       sa->dp_tx = NULL;
+       sa->priv.dp_tx = NULL;
 
        rte_free(sa->dp_rx_name);
        sa->dp_rx_name = NULL;
-       sa->dp_rx = NULL;
+       sa->priv.dp_rx = NULL;
 }
 
 static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
+       .rx_queue_count                 = sfc_rx_queue_count,
+       .rx_descriptor_done             = sfc_rx_descriptor_done,
+       .rx_descriptor_status           = sfc_rx_descriptor_status,
+       .tx_descriptor_status           = sfc_tx_descriptor_status,
+       .reta_query                     = sfc_dev_rss_reta_query,
+       .rss_hash_conf_get              = sfc_dev_rss_hash_conf_get,
        .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, uint32_t logtype_main)
+sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
 {
        /*
         * Device private data has really many process-local pointers.
@@ -1879,10 +1926,23 @@ sfc_eth_dev_secondary_set_ops(struct rte_eth_dev *dev, uint32_t logtype_main)
         * in shared memory only.
         */
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_adapter_priv *sap;
        const struct sfc_dp_rx *dp_rx;
        const struct sfc_dp_tx *dp_tx;
        int rc;
 
+       /*
+        * Allocate process private data from heap, since it should not
+        * be located in shared memory allocated using rte_malloc() API.
+        */
+       sap = calloc(1, sizeof(*sap));
+       if (sap == NULL) {
+               rc = ENOMEM;
+               goto fail_alloc_priv;
+       }
+
+       sap->logtype_main = logtype_main;
+
        dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sa->dp_rx_name);
        if (dp_rx == NULL) {
                SFC_LOG(sa, RTE_LOG_ERR, logtype_main,
@@ -1913,6 +1973,10 @@ sfc_eth_dev_secondary_set_ops(struct rte_eth_dev *dev, uint32_t logtype_main)
                goto fail_dp_tx_multi_process;
        }
 
+       sap->dp_rx = dp_rx;
+       sap->dp_tx = dp_tx;
+
+       dev->process_private = sap;
        dev->rx_pkt_burst = dp_rx->pkt_burst;
        dev->tx_pkt_burst = dp_tx->pkt_burst;
        dev->dev_ops = &sfc_eth_dev_secondary_ops;
@@ -1923,12 +1987,17 @@ fail_dp_tx_multi_process:
 fail_dp_tx:
 fail_dp_rx_multi_process:
 fail_dp_rx:
+       free(sap);
+
+fail_alloc_priv:
        return rc;
 }
 
 static void
 sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
 {
+       free(dev->process_private);
+       dev->process_private = NULL;
        dev->dev_ops = NULL;
        dev->tx_pkt_burst = NULL;
        dev->rx_pkt_burst = NULL;
@@ -1967,12 +2036,20 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
                                            RTE_LOG_NOTICE);
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               return -sfc_eth_dev_secondary_set_ops(dev, logtype_main);
+               return -sfc_eth_dev_secondary_init(dev, logtype_main);
+
+       /*
+        * sfc_adapter is a mixture of shared and process private data.
+        * During transition period use it in both kinds. When the
+        * driver becomes ready to separate it, sfc_adapter will become
+        * primary process private only.
+        */
+       dev->process_private = sa;
 
        /* Required for logging */
        sa->pci_addr = pci_dev->addr;
        sa->port_id = dev->data->port_id;
-       sa->logtype_main = logtype_main;
+       sa->priv.logtype_main = logtype_main;
 
        sa->eth_dev = dev;
 
@@ -2040,6 +2117,7 @@ fail_mac_addrs:
 
 fail_kvargs_parse:
        sfc_log_init(sa, "failed %d", rc);
+       dev->process_private = NULL;
        SFC_ASSERT(rc > 0);
        return -rc;
 }