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 1C39A54AF for ; Mon, 21 Nov 2016 16:01:37 +0100 (CET) Received: from unknown [12.187.104.26] by nbfkord-smmo02.seg.att.com(mxl_mta-7.2.4-7) with SMTP id 05c03385.0.1541303.00-2309.3424224.nbfkord-smmo02.seg.att.com (envelope-from ); Mon, 21 Nov 2016 15:01:37 +0000 (UTC) X-MXL-Hash: 58330c51735a3461-a5415dadc8f5b163f400c3956a6dd44fd75e8de0 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 uALF1K6P007203 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 uALF1J3Q006765 for ; Mon, 21 Nov 2016 15:01:20 GMT From: Andrew Rybchenko To: Date: Mon, 21 Nov 2016 15:00:49 +0000 Message-ID: <1479740470-6723-36-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=ost_VK3OpwOC5PQxD] X-AnalysisOut: [04A:9 a=PA03WX8tBzeizutn5_OT:22] X-Spam: [F=0.2000000000; CM=0.500; S=0.200(2015072901)] X-MAIL-FROM: X-SOURCE-IP: [12.187.104.26] Subject: [dpdk-dev] [PATCH 35/56] net/sfc: implement device start and stop 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:37 -0000 Reviewed-by: Andy Moreton Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/efx/sfc.c | 65 ++++++++++++++++++++++++++++++++++++++++ drivers/net/sfc/efx/sfc.h | 19 ++++++++++++ drivers/net/sfc/efx/sfc_ethdev.c | 37 +++++++++++++++++++++++ 3 files changed, 121 insertions(+) diff --git a/drivers/net/sfc/efx/sfc.c b/drivers/net/sfc/efx/sfc.c index befe68d..8c780ac 100644 --- a/drivers/net/sfc/efx/sfc.c +++ b/drivers/net/sfc/efx/sfc.c @@ -127,6 +127,71 @@ sfc_check_conf(struct sfc_adapter *sa) } int +sfc_start(struct sfc_adapter *sa) +{ + int rc; + + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + switch (sa->state) { + case SFC_ADAPTER_CONFIGURED: + break; + case SFC_ADAPTER_STARTED: + sfc_info(sa, "already started"); + return 0; + default: + rc = EINVAL; + goto fail_bad_state; + } + + sa->state = SFC_ADAPTER_STARTING; + + sfc_log_init(sa, "init nic"); + rc = efx_nic_init(sa->nic); + if (rc != 0) + goto fail_nic_init; + + sa->state = SFC_ADAPTER_STARTED; + sfc_log_init(sa, "done"); + return 0; + +fail_nic_init: + sa->state = SFC_ADAPTER_CONFIGURED; +fail_bad_state: + sfc_log_init(sa, "failed %d", rc); + return rc; +} + +void +sfc_stop(struct sfc_adapter *sa) +{ + sfc_log_init(sa, "entry"); + + SFC_ASSERT(sfc_adapter_is_locked(sa)); + + switch (sa->state) { + case SFC_ADAPTER_STARTED: + break; + case SFC_ADAPTER_CONFIGURED: + sfc_info(sa, "already stopped"); + return; + default: + sfc_err(sa, "stop in unexpected state %u", sa->state); + SFC_ASSERT(B_FALSE); + return; + } + + sa->state = SFC_ADAPTER_STOPPING; + + efx_nic_fini(sa->nic); + + sa->state = SFC_ADAPTER_CONFIGURED; + sfc_log_init(sa, "done"); +} + +int sfc_configure(struct sfc_adapter *sa) { int rc; diff --git a/drivers/net/sfc/efx/sfc.h b/drivers/net/sfc/efx/sfc.h index d040f98..42d6898 100644 --- a/drivers/net/sfc/efx/sfc.h +++ b/drivers/net/sfc/efx/sfc.h @@ -64,6 +64,20 @@ extern "C" { * V |.dev_close * +---------------+------------+ * | CONFIGURED | + * +---------------+<-----------+ + * |.dev_start | + * V | + * +---------------+ | + * | STARTING |------------^ + * +---------------+ failed | + * |success | + * | +---------------+ + * | | STOPPING | + * | +---------------+ + * | ^ + * V |.dev_stop + * +---------------+------------+ + * | STARTED | * +---------------+ */ enum sfc_adapter_state { @@ -72,6 +86,9 @@ enum sfc_adapter_state { SFC_ADAPTER_CONFIGURING, SFC_ADAPTER_CONFIGURED, SFC_ADAPTER_CLOSING, + SFC_ADAPTER_STARTING, + SFC_ADAPTER_STARTED, + SFC_ADAPTER_STOPPING, SFC_ADAPTER_NSTATES }; @@ -158,6 +175,8 @@ void sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp); int sfc_attach(struct sfc_adapter *sa); void sfc_detach(struct sfc_adapter *sa); +int sfc_start(struct sfc_adapter *sa); +void sfc_stop(struct sfc_adapter *sa); int sfc_mcdi_init(struct sfc_adapter *sa); void sfc_mcdi_fini(struct sfc_adapter *sa); diff --git a/drivers/net/sfc/efx/sfc_ethdev.c b/drivers/net/sfc/efx/sfc_ethdev.c index 120ee45..ba99516 100644 --- a/drivers/net/sfc/efx/sfc_ethdev.c +++ b/drivers/net/sfc/efx/sfc_ethdev.c @@ -79,6 +79,37 @@ sfc_dev_configure(struct rte_eth_dev *dev) return -rc; } +static int +sfc_dev_start(struct rte_eth_dev *dev) +{ + struct sfc_adapter *sa = dev->data->dev_private; + int rc; + + sfc_log_init(sa, "entry"); + + sfc_adapter_lock(sa); + rc = sfc_start(sa); + sfc_adapter_unlock(sa); + + sfc_log_init(sa, "done %d", rc); + SFC_ASSERT(rc >= 0); + return -rc; +} + +static void +sfc_dev_stop(struct rte_eth_dev *dev) +{ + struct sfc_adapter *sa = dev->data->dev_private; + + sfc_log_init(sa, "entry"); + + sfc_adapter_lock(sa); + sfc_stop(sa); + sfc_adapter_unlock(sa); + + sfc_log_init(sa, "done"); +} + static void sfc_dev_close(struct rte_eth_dev *dev) { @@ -88,6 +119,10 @@ sfc_dev_close(struct rte_eth_dev *dev) sfc_adapter_lock(sa); switch (sa->state) { + case SFC_ADAPTER_STARTED: + sfc_stop(sa); + SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED); + /* FALLTHROUGH */ case SFC_ADAPTER_CONFIGURED: sfc_close(sa); SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED); @@ -105,6 +140,8 @@ sfc_dev_close(struct rte_eth_dev *dev) static const struct eth_dev_ops sfc_eth_dev_ops = { .dev_configure = sfc_dev_configure, + .dev_start = sfc_dev_start, + .dev_stop = sfc_dev_stop, .dev_close = sfc_dev_close, .dev_infos_get = sfc_dev_infos_get, }; -- 2.5.5