From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 9A7B82BBD for ; Fri, 31 Mar 2017 12:22:45 +0200 (CEST) Received: from pure.maildistiller.com (unknown [10.110.50.29]) by dispatch1-us1.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTP id 4436360064 for ; Fri, 31 Mar 2017 10:22:45 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from mx1-us4.ppe-hosted.com (unknown [10.110.49.251]) by pure.maildistiller.com (Proofpoint Essentials ESMTP Server) with ESMTPS id CBD1A60049 for ; Fri, 31 Mar 2017 10:22:44 +0000 (UTC) Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us4.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id AD67280073 for ; Fri, 31 Mar 2017 10:22:44 +0000 (UTC) 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; Fri, 31 Mar 2017 03:22:31 -0700 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; Fri, 31 Mar 2017 03:22:30 -0700 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 v2VAMTqM030677 for ; Fri, 31 Mar 2017 11:22:29 +0100 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 v2VAMTQp009951 for ; Fri, 31 Mar 2017 11:22:29 +0100 From: Andrew Rybchenko To: Date: Fri, 31 Mar 2017 11:22:21 +0100 Message-ID: <1490955743-9868-12-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1490955743-9868-1-git-send-email-arybchenko@solarflare.com> References: <1490955743-9868-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-MDID: 1490955765-n6j-MgjecvxA Subject: [dpdk-dev] [PATCH 11/13] net/sfc: support changing the number of receive queues X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2017 10:22:46 -0000 Fixes: a8e64c6b455f ("net/sfc: implement Rx subsystem stubs") Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- drivers/net/sfc/sfc_rx.c | 87 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 92c5424..05f7436 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -1208,9 +1208,29 @@ sfc_rx_check_mode(struct sfc_adapter *sa, struct rte_eth_rxmode *rxmode) } /** + * Destroy excess queues that are no longer needed after reconfiguration + * or complete close. + */ +static void +sfc_rx_fini_queues(struct sfc_adapter *sa, unsigned int nb_rx_queues) +{ + int sw_index; + + SFC_ASSERT(nb_rx_queues <= sa->rxq_count); + + sw_index = sa->rxq_count; + while (--sw_index >= (int)nb_rx_queues) { + if (sa->rxq_info[sw_index].rxq != NULL) + sfc_rx_qfini(sa, sw_index); + } + + sa->rxq_count = nb_rx_queues; +} + +/** * Initialize Rx subsystem. * - * Called at device configuration stage when number of receive queues is + * Called at device (re)configuration stage when number of receive queues is * specified together with other device level receive configuration. * * It should be used to allocate NUMA-unaware resources. @@ -1219,26 +1239,53 @@ int sfc_rx_configure(struct sfc_adapter *sa) { struct rte_eth_conf *dev_conf = &sa->eth_dev->data->dev_conf; + const unsigned int nb_rx_queues = sa->eth_dev->data->nb_rx_queues; unsigned int sw_index; int rc; + sfc_log_init(sa, "nb_rx_queues=%u (old %u)", + nb_rx_queues, sa->rxq_count); + rc = sfc_rx_check_mode(sa, &dev_conf->rxmode); if (rc != 0) goto fail_check_mode; - sa->rxq_count = sa->eth_dev->data->nb_rx_queues; + if (nb_rx_queues == sa->rxq_count) + goto done; - rc = ENOMEM; - sa->rxq_info = rte_calloc_socket("sfc-rxqs", sa->rxq_count, - sizeof(struct sfc_rxq_info), 0, - sa->socket_id); - if (sa->rxq_info == NULL) - goto fail_rxqs_alloc; + if (sa->rxq_info == NULL) { + rc = ENOMEM; + sa->rxq_info = rte_calloc_socket("sfc-rxqs", nb_rx_queues, + sizeof(sa->rxq_info[0]), 0, + sa->socket_id); + if (sa->rxq_info == NULL) + goto fail_rxqs_alloc; + } else { + struct sfc_rxq_info *new_rxq_info; + + if (nb_rx_queues < sa->rxq_count) + sfc_rx_fini_queues(sa, nb_rx_queues); + + rc = ENOMEM; + new_rxq_info = + rte_realloc(sa->rxq_info, + nb_rx_queues * sizeof(sa->rxq_info[0]), 0); + if (new_rxq_info == NULL && nb_rx_queues > 0) + goto fail_rxqs_realloc; + + sa->rxq_info = new_rxq_info; + if (nb_rx_queues > sa->rxq_count) + memset(&sa->rxq_info[sa->rxq_count], 0, + (nb_rx_queues - sa->rxq_count) * + sizeof(sa->rxq_info[0])); + } - for (sw_index = 0; sw_index < sa->rxq_count; ++sw_index) { - rc = sfc_rx_qinit_info(sa, sw_index); + while (sa->rxq_count < nb_rx_queues) { + rc = sfc_rx_qinit_info(sa, sa->rxq_count); if (rc != 0) goto fail_rx_qinit_info; + + sa->rxq_count++; } #if EFSYS_OPT_RX_SCALE @@ -1251,14 +1298,14 @@ sfc_rx_configure(struct sfc_adapter *sa) } #endif +done: return 0; fail_rx_qinit_info: - rte_free(sa->rxq_info); - sa->rxq_info = NULL; - +fail_rxqs_realloc: fail_rxqs_alloc: - sa->rxq_count = 0; + sfc_rx_close(sa); + fail_check_mode: sfc_log_init(sa, "failed %d", rc); return rc; @@ -1267,21 +1314,13 @@ sfc_rx_configure(struct sfc_adapter *sa) /** * Shutdown Rx subsystem. * - * Called at device close stage, for example, before device - * reconfiguration or shutdown. + * Called at device close stage, for example, before device shutdown. */ void sfc_rx_close(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); - } + sfc_rx_fini_queues(sa, 0); rte_free(sa->rxq_info); sa->rxq_info = NULL; - sa->rxq_count = 0; } -- 2.9.3