net/sfc: set up and release Tx queues
[dpdk.git] / drivers / net / sfc / sfc_ethdev.c
index fe6beb3..4a4c4dd 100644 (file)
@@ -38,6 +38,8 @@
 #include "sfc_log.h"
 #include "sfc_kvargs.h"
 #include "sfc_ev.h"
+#include "sfc_rx.h"
+#include "sfc_tx.h"
 
 
 static void
@@ -50,15 +52,34 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
        dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
 
+       dev_info->max_rx_queues = sa->rxq_max;
+       dev_info->max_tx_queues = sa->txq_max;
+
        /* By default packets are dropped if no descriptors are available */
        dev_info->default_rxconf.rx_drop_en = 1;
 
+       dev_info->tx_offload_capa =
+               DEV_TX_OFFLOAD_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_UDP_CKSUM |
+               DEV_TX_OFFLOAD_TCP_CKSUM;
+
+       dev_info->default_txconf.txq_flags = ETH_TXQ_FLAGS_NOVLANOFFL |
+                                            ETH_TXQ_FLAGS_NOXSUMSCTP;
+
        dev_info->rx_desc_lim.nb_max = EFX_RXQ_MAXNDESCS;
        dev_info->rx_desc_lim.nb_min = EFX_RXQ_MINNDESCS;
        /* The RXQ hardware requires that the descriptor count is a power
         * of 2, but rx_desc_lim cannot properly describe that constraint.
         */
        dev_info->rx_desc_lim.nb_align = EFX_RXQ_MINNDESCS;
+
+       dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
+       dev_info->tx_desc_lim.nb_min = EFX_TXQ_MINNDESCS;
+       /*
+        * The TXQ hardware requires that the descriptor count is a power
+        * of 2, but tx_desc_lim cannot properly describe that constraint
+        */
+       dev_info->tx_desc_lim.nb_align = EFX_TXQ_MINNDESCS;
 }
 
 static int
@@ -192,6 +213,116 @@ sfc_dev_close(struct rte_eth_dev *dev)
        sfc_log_init(sa, "done");
 }
 
+static int
+sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
+                  uint16_t nb_rx_desc, unsigned int socket_id,
+                  const struct rte_eth_rxconf *rx_conf,
+                  struct rte_mempool *mb_pool)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       int rc;
+
+       sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
+                    rx_queue_id, nb_rx_desc, socket_id);
+
+       sfc_adapter_lock(sa);
+
+       rc = sfc_rx_qinit(sa, rx_queue_id, nb_rx_desc, socket_id,
+                         rx_conf, mb_pool);
+       if (rc != 0)
+               goto fail_rx_qinit;
+
+       dev->data->rx_queues[rx_queue_id] = sa->rxq_info[rx_queue_id].rxq;
+
+       sfc_adapter_unlock(sa);
+
+       return 0;
+
+fail_rx_qinit:
+       sfc_adapter_unlock(sa);
+       SFC_ASSERT(rc > 0);
+       return -rc;
+}
+
+static void
+sfc_rx_queue_release(void *queue)
+{
+       struct sfc_rxq *rxq = queue;
+       struct sfc_adapter *sa;
+       unsigned int sw_index;
+
+       if (rxq == NULL)
+               return;
+
+       sa = rxq->evq->sa;
+       sfc_adapter_lock(sa);
+
+       sw_index = sfc_rxq_sw_index(rxq);
+
+       sfc_log_init(sa, "RxQ=%u", sw_index);
+
+       sa->eth_dev->data->rx_queues[sw_index] = NULL;
+
+       sfc_rx_qfini(sa, sw_index);
+
+       sfc_adapter_unlock(sa);
+}
+
+static int
+sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
+                  uint16_t nb_tx_desc, unsigned int socket_id,
+                  const struct rte_eth_txconf *tx_conf)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       int rc;
+
+       sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
+                    tx_queue_id, nb_tx_desc, socket_id);
+
+       sfc_adapter_lock(sa);
+
+       rc = sfc_tx_qinit(sa, tx_queue_id, nb_tx_desc, socket_id, tx_conf);
+       if (rc != 0)
+               goto fail_tx_qinit;
+
+       dev->data->tx_queues[tx_queue_id] = sa->txq_info[tx_queue_id].txq;
+
+       sfc_adapter_unlock(sa);
+       return 0;
+
+fail_tx_qinit:
+       sfc_adapter_unlock(sa);
+       SFC_ASSERT(rc > 0);
+       return -rc;
+}
+
+static void
+sfc_tx_queue_release(void *queue)
+{
+       struct sfc_txq *txq = queue;
+       unsigned int sw_index;
+       struct sfc_adapter *sa;
+
+       if (txq == NULL)
+               return;
+
+       sw_index = sfc_txq_sw_index(txq);
+
+       SFC_ASSERT(txq->evq != NULL);
+       sa = txq->evq->sa;
+
+       sfc_log_init(sa, "TxQ = %u", sw_index);
+
+       sfc_adapter_lock(sa);
+
+       SFC_ASSERT(sw_index < sa->eth_dev->data->nb_tx_queues);
+       sa->eth_dev->data->tx_queues[sw_index] = NULL;
+
+       sfc_tx_qfini(sa, sw_index);
+
+       sfc_adapter_unlock(sa);
+}
+
 static const struct eth_dev_ops sfc_eth_dev_ops = {
        .dev_configure                  = sfc_dev_configure,
        .dev_start                      = sfc_dev_start,
@@ -199,6 +330,10 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .dev_close                      = sfc_dev_close,
        .link_update                    = sfc_dev_link_update,
        .dev_infos_get                  = sfc_dev_infos_get,
+       .rx_queue_setup                 = sfc_rx_queue_setup,
+       .rx_queue_release               = sfc_rx_queue_release,
+       .tx_queue_setup                 = sfc_tx_queue_setup,
+       .tx_queue_release               = sfc_tx_queue_release,
 };
 
 static int
@@ -251,6 +386,7 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
        ether_addr_copy(from, &dev->data->mac_addrs[0]);
 
        dev->dev_ops = &sfc_eth_dev_ops;
+       dev->rx_pkt_burst = &sfc_recv_pkts;
 
        sfc_adapter_unlock(sa);
 
@@ -288,6 +424,7 @@ sfc_eth_dev_uninit(struct rte_eth_dev *dev)
        dev->data->mac_addrs = NULL;
 
        dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
 
        sfc_kvargs_cleanup(sa);