net/sfc: implement Rx queue setup release operations
authorAndrew Rybchenko <arybchenko@solarflare.com>
Tue, 29 Nov 2016 16:19:17 +0000 (16:19 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 17 Jan 2017 18:39:26 +0000 (19:39 +0100)
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_ev.h
drivers/net/sfc/sfc_rx.c
drivers/net/sfc/sfc_rx.h

index fe6beb3..1aec388 100644 (file)
@@ -38,6 +38,7 @@
 #include "sfc_log.h"
 #include "sfc_kvargs.h"
 #include "sfc_ev.h"
+#include "sfc_rx.h"
 
 
 static void
@@ -50,6 +51,8 @@ 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;
+
        /* By default packets are dropped if no descriptors are available */
        dev_info->default_rxconf.rx_drop_en = 1;
 
@@ -192,6 +195,61 @@ 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 const struct eth_dev_ops sfc_eth_dev_ops = {
        .dev_configure                  = sfc_dev_configure,
        .dev_start                      = sfc_dev_start,
@@ -199,6 +257,8 @@ 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,
 };
 
 static int
index 8455fda..f38e6b8 100644 (file)
@@ -40,6 +40,7 @@ extern "C" {
 #define SFC_MGMT_EVQ_ENTRIES   (EFX_EVQ_MINNEVS)
 
 struct sfc_adapter;
+struct sfc_rxq;
 
 enum sfc_evq_state {
        SFC_EVQ_UNINITIALIZED = 0,
@@ -56,6 +57,7 @@ struct sfc_evq {
        unsigned int            read_ptr;
        boolean_t               exception;
        efsys_mem_t             mem;
+       struct sfc_rxq          *rxq;
 
        /* Not used on datapath */
        struct sfc_adapter      *sa;
index 88e3319..00bcc9d 100644 (file)
 
 #include "sfc.h"
 #include "sfc_log.h"
+#include "sfc_ev.h"
 #include "sfc_rx.h"
 
+static int
+sfc_rx_qcheck_conf(struct sfc_adapter *sa,
+                  const struct rte_eth_rxconf *rx_conf)
+{
+       int rc = 0;
+
+       if (rx_conf->rx_thresh.pthresh != 0 ||
+           rx_conf->rx_thresh.hthresh != 0 ||
+           rx_conf->rx_thresh.wthresh != 0) {
+               sfc_err(sa,
+                       "RxQ prefetch/host/writeback thresholds are not supported");
+               rc = EINVAL;
+       }
+
+       if (rx_conf->rx_free_thresh != 0) {
+               sfc_err(sa, "RxQ free threshold is not supported");
+               rc = EINVAL;
+       }
+
+       if (rx_conf->rx_drop_en == 0) {
+               sfc_err(sa, "RxQ drop disable is not supported");
+               rc = EINVAL;
+       }
+
+       if (rx_conf->rx_deferred_start != 0) {
+               sfc_err(sa, "RxQ deferred start is not supported");
+               rc = EINVAL;
+       }
+
+       return rc;
+}
+
+int
+sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index,
+            uint16_t nb_rx_desc, unsigned int socket_id,
+            const struct rte_eth_rxconf *rx_conf,
+            struct rte_mempool *mb_pool)
+{
+       int rc;
+       struct sfc_rxq_info *rxq_info;
+       unsigned int evq_index;
+       struct sfc_evq *evq;
+       struct sfc_rxq *rxq;
+
+       rc = sfc_rx_qcheck_conf(sa, rx_conf);
+       if (rc != 0)
+               goto fail_bad_conf;
+
+       if (rte_pktmbuf_data_room_size(mb_pool) <= RTE_PKTMBUF_HEADROOM) {
+               sfc_err(sa, "RxQ %u mbuf is too small, %u vs headroom %u",
+                       sw_index, rte_pktmbuf_data_room_size(mb_pool),
+                       RTE_PKTMBUF_HEADROOM);
+               goto fail_bad_conf;
+       }
+
+       SFC_ASSERT(sw_index < sa->rxq_count);
+       rxq_info = &sa->rxq_info[sw_index];
+
+       SFC_ASSERT(nb_rx_desc <= rxq_info->max_entries);
+       rxq_info->entries = nb_rx_desc;
+       rxq_info->type = EFX_RXQ_TYPE_DEFAULT;
+
+       evq_index = sfc_evq_index_by_rxq_sw_index(sa, sw_index);
+
+       rc = sfc_ev_qinit(sa, evq_index, rxq_info->entries, socket_id);
+       if (rc != 0)
+               goto fail_ev_qinit;
+
+       evq = sa->evq_info[evq_index].evq;
+
+       rc = ENOMEM;
+       rxq = rte_zmalloc_socket("sfc-rxq", sizeof(*rxq), RTE_CACHE_LINE_SIZE,
+                                socket_id);
+       if (rxq == NULL)
+               goto fail_rxq_alloc;
+
+       rc = sfc_dma_alloc(sa, "rxq", sw_index, EFX_RXQ_SIZE(rxq_info->entries),
+                          socket_id, &rxq->mem);
+       if (rc != 0)
+               goto fail_dma_alloc;
+
+       rc = ENOMEM;
+       rxq->sw_desc = rte_calloc_socket("sfc-rxq-sw_desc", rxq_info->entries,
+                                        sizeof(*rxq->sw_desc),
+                                        RTE_CACHE_LINE_SIZE, socket_id);
+       if (rxq->sw_desc == NULL)
+               goto fail_desc_alloc;
+
+       evq->rxq = rxq;
+       rxq->evq = evq;
+       rxq->ptr_mask = rxq_info->entries - 1;
+       rxq->refill_mb_pool = mb_pool;
+       rxq->hw_index = sw_index;
+
+       rxq->state = SFC_RXQ_INITIALIZED;
+
+       rxq_info->rxq = rxq;
+
+       return 0;
+
+fail_desc_alloc:
+       sfc_dma_free(sa, &rxq->mem);
+
+fail_dma_alloc:
+       rte_free(rxq);
+
+fail_rxq_alloc:
+       sfc_ev_qfini(sa, evq_index);
+
+fail_ev_qinit:
+       rxq_info->entries = 0;
+
+fail_bad_conf:
+       sfc_log_init(sa, "failed %d", rc);
+       return rc;
+}
+
+void
+sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
+{
+       struct sfc_rxq_info *rxq_info;
+       struct sfc_rxq *rxq;
+
+       SFC_ASSERT(sw_index < sa->rxq_count);
+
+       rxq_info = &sa->rxq_info[sw_index];
+
+       rxq = rxq_info->rxq;
+       SFC_ASSERT(rxq->state == SFC_RXQ_INITIALIZED);
+
+       rxq_info->rxq = NULL;
+       rxq_info->entries = 0;
+
+       rte_free(rxq->sw_desc);
+       sfc_dma_free(sa, &rxq->mem);
+       rte_free(rxq);
+}
+
 static int
 sfc_rx_qinit_info(struct sfc_adapter *sa, unsigned int sw_index)
 {
@@ -158,6 +297,14 @@ fail_check_mode:
 void
 sfc_rx_fini(struct sfc_adapter *sa)
 {
+       unsigned int sw_index;
+
+       sw_index = sa->rxq_count;
+       while (sw_index-- > 0) {
+               if (sa->rxq_info[sw_index].rxq != NULL)
+                       sfc_rx_qfini(sa, sw_index);
+       }
+
        rte_free(sa->rxq_info);
        sa->rxq_info = NULL;
        sa->rxq_count = 0;
index 2e27b53..b506d9a 100644 (file)
 #ifndef _SFC_RX_H
 #define _SFC_RX_H
 
+#include <rte_mbuf.h>
+#include <rte_mempool.h>
+#include <rte_ethdev.h>
+
+#include "efx.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct sfc_adapter;
+struct sfc_evq;
+
+/**
+ * Software Rx descriptor information associated with hardware Rx
+ * descriptor.
+ */
+struct sfc_rx_sw_desc {
+       struct rte_mbuf         *mbuf;
+       unsigned int            flags;
+       unsigned int            size;
+};
+
+/** Receive queue state bits */
+enum sfc_rxq_state_bit {
+       SFC_RXQ_INITIALIZED_BIT = 0,
+#define SFC_RXQ_INITIALIZED    (1 << SFC_RXQ_INITIALIZED_BIT)
+};
+
+/**
+ * Receive queue information used on data path.
+ * Allocated on the socket specified on the queue setup.
+ */
+struct sfc_rxq {
+       /* Used on data path */
+       struct sfc_evq          *evq;
+       struct sfc_rx_sw_desc   *sw_desc;
+       unsigned int            state;
+       unsigned int            ptr_mask;
+
+       /* Used on refill */
+       struct rte_mempool      *refill_mb_pool;
+       efx_rxq_t               *common;
+       efsys_mem_t             mem;
+
+       /* Not used on data path */
+       unsigned int            hw_index;
+};
+
+static inline unsigned int
+sfc_rxq_sw_index_by_hw_index(unsigned int hw_index)
+{
+       return hw_index;
+}
+
+static inline unsigned int
+sfc_rxq_sw_index(const struct sfc_rxq *rxq)
+{
+       return sfc_rxq_sw_index_by_hw_index(rxq->hw_index);
+}
 
 /**
  * Receive queue information used during setup/release only.
@@ -42,11 +97,20 @@ struct sfc_adapter;
  */
 struct sfc_rxq_info {
        unsigned int            max_entries;
+       unsigned int            entries;
+       efx_rxq_type_t          type;
+       struct sfc_rxq          *rxq;
 };
 
 int sfc_rx_init(struct sfc_adapter *sa);
 void sfc_rx_fini(struct sfc_adapter *sa);
 
+int sfc_rx_qinit(struct sfc_adapter *sa, unsigned int rx_queue_id,
+                uint16_t nb_rx_desc, unsigned int socket_id,
+                const struct rte_eth_rxconf *rx_conf,
+                struct rte_mempool *mb_pool);
+void sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index);
+
 #ifdef __cplusplus
 }
 #endif