From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nbfkord-smmo01.seg.att.com (nbfkord-smmo01.seg.att.com [209.65.160.76]) by dpdk.org (Postfix) with ESMTP id 8CB184A59 for ; Tue, 29 Nov 2016 17:20:56 +0100 (CET) Received: from unknown [12.187.104.26] (EHLO nbfkord-smmo01.seg.att.com) by nbfkord-smmo01.seg.att.com(mxl_mta-7.2.4-7) with ESMTP id 8eaad385.2b3e4de02940.83618.00-2486.174003.nbfkord-smmo01.seg.att.com (envelope-from ); Tue, 29 Nov 2016 16:20:56 +0000 (UTC) X-MXL-Hash: 583daae81f962cce-e6bd97982b3ae853848e80bfd5d8ca9f5897e9c7 Received: from unknown [12.187.104.26] by nbfkord-smmo01.seg.att.com(mxl_mta-7.2.4-7) with SMTP id 6eaad385.0.83424.00-2358.173938.nbfkord-smmo01.seg.att.com (envelope-from ); Tue, 29 Nov 2016 16:20:55 +0000 (UTC) X-MXL-Hash: 583daae71c673de7-26a611eb1ee68755940214f09a31ab138a13eec7 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; Tue, 29 Nov 2016 08:20:26 -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; Tue, 29 Nov 2016 08:20:25 -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 uATGKOlE030035; Tue, 29 Nov 2016 16:20:24 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 uATGKM1r021233; Tue, 29 Nov 2016 16:20:24 GMT From: Andrew Rybchenko To: CC: Date: Tue, 29 Nov 2016 16:19:17 +0000 Message-ID: <1480436367-20749-46-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1480436367-20749-1-git-send-email-arybchenko@solarflare.com> References: <1479740470-6723-1-git-send-email-arybchenko@solarflare.com> <1480436367-20749-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-AnalysisOut: [v=2.1 cv=UoJlQrEB 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.4296722620; CM=0.500; S=0.429(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [12.187.104.26] Subject: [dpdk-dev] [PATCH v2 45/55] 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: Tue, 29 Nov 2016 16:20:57 -0000 Reviewed-by: Andy Moreton Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/sfc_ethdev.c | 60 ++++++++++++++++++ drivers/net/sfc/sfc_ev.h | 2 + drivers/net/sfc/sfc_rx.c | 147 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/sfc/sfc_rx.h | 64 +++++++++++++++++++ 4 files changed, 273 insertions(+) diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index f39addb..594ae7a 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/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 @@ -51,6 +52,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; @@ -193,6 +196,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, @@ -200,6 +258,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/sfc_ev.h b/drivers/net/sfc/sfc_ev.h index 8455fda..f38e6b8 100644 --- a/drivers/net/sfc/sfc_ev.h +++ b/drivers/net/sfc/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/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 88e3319..00bcc9d 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/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]; @@ -158,6 +297,14 @@ sfc_rx_init(struct sfc_adapter *sa) 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; diff --git a/drivers/net/sfc/sfc_rx.h b/drivers/net/sfc/sfc_rx.h index 2e27b53..b506d9a 100644 --- a/drivers/net/sfc/sfc_rx.h +++ b/drivers/net/sfc/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