From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nbfkord-smmo02.seg.att.com (nbfkord-smmo02.seg.att.com [209.65.160.78]) by dpdk.org (Postfix) with ESMTP id 54CA454AF for ; Mon, 21 Nov 2016 16:01:40 +0100 (CET) Received: from unknown [12.187.104.26] by nbfkord-smmo02.seg.att.com(mxl_mta-7.2.4-7) with SMTP id 35c03385.0.1541294.00-2389.3424240.nbfkord-smmo02.seg.att.com (envelope-from ); Mon, 21 Nov 2016 15:01:40 +0000 (UTC) X-MXL-Hash: 58330c5471974f61-9ed80de5e1b3072b4f06a3a36821645db3a2a5a8 Received: from ocex03.SolarFlarecom.com (10.20.40.36) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Mon, 21 Nov 2016 07:01:22 -0800 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Mon, 21 Nov 2016 07:01:22 -0800 Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com [10.17.10.10]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id uALF1LfU007236 for ; Mon, 21 Nov 2016 15:01:21 GMT Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1]) by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id uALF1J3b006765 for ; Mon, 21 Nov 2016 15:01:21 GMT From: Andrew Rybchenko To: Date: Mon, 21 Nov 2016 15:01:00 +0000 Message-ID: <1479740470-6723-47-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1479740470-6723-1-git-send-email-arybchenko@solarflare.com> References: <1479740470-6723-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-AnalysisOut: [v=2.1 cv=UI/baXry c=1 sm=1 tr=0 a=8BlWFWvVlq5taO8ncb8nKg==] X-AnalysisOut: [:17 a=L24OOQBejmoA:10 a=zRKbQ67AAAAA:8 a=7SYgjl-cy90FXsqJQ] X-AnalysisOut: [kMA:9 a=PA03WX8tBzeizutn5_OT:22] X-Spam: [F=0.4086264918; CM=0.500; S=0.408(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [12.187.104.26] Subject: [dpdk-dev] [PATCH 46/56] net/sfc: implement Rx queue setup release operations X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Nov 2016 15:01:41 -0000 Reviewed-by: Andy Moreton Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/efx/sfc_ethdev.c | 60 ++++++++++++++++ drivers/net/sfc/efx/sfc_ev.h | 2 + drivers/net/sfc/efx/sfc_rx.c | 147 +++++++++++++++++++++++++++++++++++++++ drivers/net/sfc/efx/sfc_rx.h | 64 +++++++++++++++++ 4 files changed, 273 insertions(+) diff --git a/drivers/net/sfc/efx/sfc_ethdev.c b/drivers/net/sfc/efx/sfc_ethdev.c index 8d628fe..c889325 100644 --- a/drivers/net/sfc/efx/sfc_ethdev.c +++ b/drivers/net/sfc/efx/sfc_ethdev.c @@ -38,6 +38,7 @@ #include "sfc_log.h" #include "sfc_kvargs.h" #include "sfc_ev.h" +#include "sfc_rx.h" static void @@ -49,6 +50,8 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) 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; @@ -191,6 +194,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, @@ -198,6 +256,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 diff --git a/drivers/net/sfc/efx/sfc_ev.h b/drivers/net/sfc/efx/sfc_ev.h index f7bcf01..d053182 100644 --- a/drivers/net/sfc/efx/sfc_ev.h +++ b/drivers/net/sfc/efx/sfc_ev.h @@ -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; diff --git a/drivers/net/sfc/efx/sfc_rx.c b/drivers/net/sfc/efx/sfc_rx.c index bc43e4e..d4a1a02 100644 --- a/drivers/net/sfc/efx/sfc_rx.c +++ b/drivers/net/sfc/efx/sfc_rx.c @@ -31,9 +31,148 @@ #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) { struct sfc_rxq_info *rxq_info = &sa->rxq_info[sw_index]; @@ -159,6 +298,14 @@ sfc_rx_init(struct sfc_adapter *sa) void sfc_rx_fini(struct sfc_adapter *sa) { + 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; diff --git a/drivers/net/sfc/efx/sfc_rx.h b/drivers/net/sfc/efx/sfc_rx.h index c1758a1..503c3df 100644 --- a/drivers/net/sfc/efx/sfc_rx.h +++ b/drivers/net/sfc/efx/sfc_rx.h @@ -30,11 +30,66 @@ #ifndef _SFC_RX_H #define _SFC_RX_H +#include +#include +#include + +#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 -- 2.5.5