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 5EAAB376D for ; Mon, 21 Nov 2016 16:01:34 +0100 (CET) Received: from unknown [12.187.104.26] by nbfkord-smmo02.seg.att.com(mxl_mta-7.2.4-7) with SMTP id d4c03385.0.1541303.00-2325.3424209.nbfkord-smmo02.seg.att.com (envelope-from ); Mon, 21 Nov 2016 15:01:34 +0000 (UTC) X-MXL-Hash: 58330c4e1250d8fc-f878173090385cb40c6f098320bfd8f74da43fed 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:21 -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 uALF1KD1007197 for ; Mon, 21 Nov 2016 15:01:20 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 uALF1J3O006765 for ; Mon, 21 Nov 2016 15:01:20 GMT From: Andrew Rybchenko To: Date: Mon, 21 Nov 2016 15:00:47 +0000 Message-ID: <1479740470-6723-34-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=gcGGuJGV13JUM21jy] X-AnalysisOut: [lEA:9 a=PA03WX8tBzeizutn5_OT:22] X-Spam: [F=0.4902604395; CM=0.500; S=0.490(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [12.187.104.26] Subject: [dpdk-dev] [PATCH 33/56] net/sfc: add device configure and close stubs 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:34 -0000 Reviewed-by: Andy Moreton Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/efx/sfc.c | 29 +++++++++++++++++++ drivers/net/sfc/efx/sfc.h | 31 ++++++++++++++++---- drivers/net/sfc/efx/sfc_ethdev.c | 62 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 8 deletions(-) diff --git a/drivers/net/sfc/efx/sfc.c b/drivers/net/sfc/efx/sfc.c index 2a17d26..cbb14d7 100644 --- a/drivers/net/sfc/efx/sfc.c +++ b/drivers/net/sfc/efx/sfc.c @@ -82,6 +82,35 @@ sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp) memset(esmp, 0, sizeof(*esmp)); } +int +sfc_configure(struct sfc_adapter *sa) +{ + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED); + sa->state = SFC_ADAPTER_CONFIGURING; + + sa->state = SFC_ADAPTER_CONFIGURED; + sfc_log_init(sa, "done"); + return 0; +} + +void +sfc_close(struct sfc_adapter *sa) +{ + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED); + sa->state = SFC_ADAPTER_CLOSING; + + sa->state = SFC_ADAPTER_INITIALIZED; + sfc_log_init(sa, "done"); +} + static int sfc_mem_bar_init(struct sfc_adapter *sa) { diff --git a/drivers/net/sfc/efx/sfc.h b/drivers/net/sfc/efx/sfc.h index 01d652d..d040f98 100644 --- a/drivers/net/sfc/efx/sfc.h +++ b/drivers/net/sfc/efx/sfc.h @@ -50,11 +50,28 @@ extern "C" { * V | * +---------------+------------+ * | INITIALIZED | + * +---------------+<-----------+ + * |.dev_configure | + * V | + * +---------------+ | + * | CONFIGURING |------------^ + * +---------------+ failed | + * |success | + * | +---------------+ + * | | CLOSING | + * | +---------------+ + * | ^ + * V |.dev_close + * +---------------+------------+ + * | CONFIGURED | * +---------------+ */ enum sfc_adapter_state { SFC_ADAPTER_UNINITIALIZED = 0, SFC_ADAPTER_INITIALIZED, + SFC_ADAPTER_CONFIGURING, + SFC_ADAPTER_CONFIGURED, + SFC_ADAPTER_CLOSING, SFC_ADAPTER_NSTATES }; @@ -78,11 +95,10 @@ struct sfc_mcdi { /* Adapter private data */ struct sfc_adapter { /* - * PMD setup and configuration is not thread safe. - * Since it is not performance sensitive, it is better to guarantee - * thread-safety and add device level lock. - * Adapter control operations which change its state should - * acquire the lock. + * PMD setup and configuration is not thread safe. Since it is not + * performance sensitive, it is better to guarantee thread-safety + * and add device level lock. Adapter control operations which + * change its state should acquire the lock. */ rte_spinlock_t lock; enum sfc_adapter_state state; @@ -131,7 +147,7 @@ sfc_adapter_unlock(struct sfc_adapter *sa) } static inline void -sfc_adapter_lock_destroy(struct sfc_adapter *sa) +sfc_adapter_lock_fini(struct sfc_adapter *sa) { /* Just for symmetry of the API */ } @@ -146,6 +162,9 @@ void sfc_detach(struct sfc_adapter *sa); int sfc_mcdi_init(struct sfc_adapter *sa); void sfc_mcdi_fini(struct sfc_adapter *sa); +int sfc_configure(struct sfc_adapter *sa); +void sfc_close(struct sfc_adapter *sa); + #ifdef __cplusplus } #endif diff --git a/drivers/net/sfc/efx/sfc_ethdev.c b/drivers/net/sfc/efx/sfc_ethdev.c index e5b609c..120ee45 100644 --- a/drivers/net/sfc/efx/sfc_ethdev.c +++ b/drivers/net/sfc/efx/sfc_ethdev.c @@ -47,7 +47,65 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) sfc_log_init(sa, "entry"); } +static int +sfc_dev_configure(struct rte_eth_dev *dev) +{ + struct rte_eth_dev_data *dev_data = dev->data; + struct sfc_adapter *sa = dev_data->dev_private; + int rc; + + sfc_log_init(sa, "entry n_rxq=%u n_txq=%u", + dev_data->nb_rx_queues, dev_data->nb_tx_queues); + + sfc_adapter_lock(sa); + switch (sa->state) { + case SFC_ADAPTER_CONFIGURED: + sfc_close(sa); + SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED); + /* FALLTHROUGH */ + case SFC_ADAPTER_INITIALIZED: + rc = sfc_configure(sa); + break; + default: + sfc_err(sa, "unexpected adapter state %u to configure", + sa->state); + rc = EINVAL; + break; + } + sfc_adapter_unlock(sa); + + sfc_log_init(sa, "done %d", rc); + SFC_ASSERT(rc >= 0); + return -rc; +} + +static void +sfc_dev_close(struct rte_eth_dev *dev) +{ + struct sfc_adapter *sa = dev->data->dev_private; + + sfc_log_init(sa, "entry"); + + sfc_adapter_lock(sa); + switch (sa->state) { + case SFC_ADAPTER_CONFIGURED: + sfc_close(sa); + SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED); + /* FALLTHROUGH */ + case SFC_ADAPTER_INITIALIZED: + break; + default: + sfc_err(sa, "unexpected adapter state %u on close", sa->state); + break; + } + sfc_adapter_unlock(sa); + + sfc_log_init(sa, "done"); +} + static const struct eth_dev_ops sfc_eth_dev_ops = { + .dev_configure = sfc_dev_configure, + .dev_close = sfc_dev_close, .dev_infos_get = sfc_dev_infos_get, }; @@ -109,7 +167,7 @@ sfc_eth_dev_init(struct rte_eth_dev *dev) fail_attach: sfc_adapter_unlock(sa); - sfc_adapter_lock_destroy(sa); + sfc_adapter_lock_fini(sa); rte_free(dev->data->mac_addrs); dev->data->mac_addrs = NULL; @@ -142,7 +200,7 @@ sfc_eth_dev_uninit(struct rte_eth_dev *dev) sfc_kvargs_cleanup(sa); sfc_adapter_unlock(sa); - sfc_adapter_lock_destroy(sa); + sfc_adapter_lock_fini(sa); sfc_log_init(sa, "done"); -- 2.5.5