From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 58DDEA034F; Mon, 11 Oct 2021 16:51:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C59B74118A; Mon, 11 Oct 2021 16:49:57 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 4CB2941174 for ; Mon, 11 Oct 2021 16:49:55 +0200 (CEST) Received: by shelob.oktetlabs.ru (Postfix, from userid 122) id 1702F7F701; Mon, 11 Oct 2021 17:49:55 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shelob.oktetlabs.ru X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=ALL_TRUSTED, DKIM_ADSP_DISCARD, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from aros.oktetlabs.ru (aros.oktetlabs.ru [192.168.38.17]) by shelob.oktetlabs.ru (Postfix) with ESMTP id 33FD27F70C; Mon, 11 Oct 2021 17:49:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 33FD27F70C Authentication-Results: shelob.oktetlabs.ru/33FD27F70C; dkim=none; dkim-atps=neutral From: Andrew Rybchenko To: dev@dpdk.org Cc: Igor Romanov , Andy Moreton , Ivan Malov Date: Mon, 11 Oct 2021 17:48:40 +0300 Message-Id: <20211011144857.446802-22-andrew.rybchenko@oktetlabs.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211011144857.446802-1-andrew.rybchenko@oktetlabs.ru> References: <20210827065717.1838258-1-andrew.rybchenko@oktetlabs.ru> <20211011144857.446802-1-andrew.rybchenko@oktetlabs.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 21/38] net/sfc: support multiple device probe X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Igor Romanov Support probing the device multiple times so that additional port representors can be created with hotplug EAL API. To hotplug a representor, the PF must be hotplugged with different representor device argument. Signed-off-by: Igor Romanov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton Reviewed-by: Ivan Malov --- drivers/net/sfc/sfc_ethdev.c | 55 ++++++++++++++++++++++++------------ drivers/net/sfc/sfc_repr.c | 35 +++++++++++++---------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index efd5e6b1ab..f69bbde11a 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -2440,31 +2440,40 @@ sfc_parse_rte_devargs(const char *args, struct rte_eth_devargs *devargs) } static int -sfc_eth_dev_create(struct rte_pci_device *pci_dev, - struct sfc_ethdev_init_data *init_data, - struct rte_eth_dev **devp) +sfc_eth_dev_find_or_create(struct rte_pci_device *pci_dev, + struct sfc_ethdev_init_data *init_data, + struct rte_eth_dev **devp, + bool *dev_created) { struct rte_eth_dev *dev; + bool created = false; int rc; - rc = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name, - sizeof(struct sfc_adapter_shared), - eth_dev_pci_specific_init, pci_dev, - sfc_eth_dev_init, init_data); - if (rc != 0) { - SFC_GENERIC_LOG(ERR, "Failed to create sfc ethdev '%s'", - pci_dev->device.name); - return rc; - } - dev = rte_eth_dev_allocated(pci_dev->device.name); if (dev == NULL) { - SFC_GENERIC_LOG(ERR, "Failed to find allocated sfc ethdev '%s'", + rc = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name, + sizeof(struct sfc_adapter_shared), + eth_dev_pci_specific_init, pci_dev, + sfc_eth_dev_init, init_data); + if (rc != 0) { + SFC_GENERIC_LOG(ERR, "Failed to create sfc ethdev '%s'", + pci_dev->device.name); + return rc; + } + + created = true; + + dev = rte_eth_dev_allocated(pci_dev->device.name); + if (dev == NULL) { + SFC_GENERIC_LOG(ERR, + "Failed to find allocated sfc ethdev '%s'", pci_dev->device.name); - return -ENODEV; + return -ENODEV; + } } *devp = dev; + *dev_created = created; return 0; } @@ -2525,6 +2534,7 @@ static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct sfc_ethdev_init_data init_data; struct rte_eth_devargs eth_da; struct rte_eth_dev *dev; + bool dev_created; int rc; if (pci_dev->device.devargs != NULL) { @@ -2546,13 +2556,21 @@ static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, return -ENOTSUP; } - rc = sfc_eth_dev_create(pci_dev, &init_data, &dev); + /* + * Driver supports RTE_PCI_DRV_PROBE_AGAIN. Hence create device only + * if it does not already exist. Re-probing an existing device is + * expected to allow additional representors to be configured. + */ + rc = sfc_eth_dev_find_or_create(pci_dev, &init_data, &dev, + &dev_created); if (rc != 0) return rc; rc = sfc_eth_dev_create_representors(dev, ð_da); if (rc != 0) { - (void)rte_eth_dev_destroy(dev, sfc_eth_dev_uninit); + if (dev_created) + (void)rte_eth_dev_destroy(dev, sfc_eth_dev_uninit); + return rc; } @@ -2568,7 +2586,8 @@ static struct rte_pci_driver sfc_efx_pmd = { .id_table = pci_id_sfc_efx_map, .drv_flags = RTE_PCI_DRV_INTR_LSC | - RTE_PCI_DRV_NEED_MAPPING, + RTE_PCI_DRV_NEED_MAPPING | + RTE_PCI_DRV_PROBE_AGAIN, .probe = sfc_eth_dev_pci_probe, .remove = sfc_eth_dev_pci_remove, }; diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c index 9b70a3be76..922f4da432 100644 --- a/drivers/net/sfc/sfc_repr.c +++ b/drivers/net/sfc/sfc_repr.c @@ -908,6 +908,7 @@ sfc_repr_create(struct rte_eth_dev *parent, uint16_t representor_id, struct sfc_repr_init_data repr_data; char name[RTE_ETH_NAME_MAX_LEN]; int ret; + struct rte_eth_dev *dev; if (snprintf(name, sizeof(name), "net_%s_representor_%u", parent->device->name, representor_id) >= @@ -916,20 +917,24 @@ sfc_repr_create(struct rte_eth_dev *parent, uint16_t representor_id, return -ENAMETOOLONG; } - memset(&repr_data, 0, sizeof(repr_data)); - repr_data.pf_port_id = parent->data->port_id; - repr_data.repr_id = representor_id; - repr_data.switch_domain_id = switch_domain_id; - repr_data.mport_sel = *mport_sel; - - ret = rte_eth_dev_create(parent->device, name, - sizeof(struct sfc_repr_shared), - NULL, NULL, - sfc_repr_eth_dev_init, &repr_data); - if (ret != 0) - SFC_GENERIC_LOG(ERR, "%s() failed to create device", __func__); - - SFC_GENERIC_LOG(INFO, "%s() done: %s", __func__, rte_strerror(-ret)); + dev = rte_eth_dev_allocated(name); + if (dev == NULL) { + memset(&repr_data, 0, sizeof(repr_data)); + repr_data.pf_port_id = parent->data->port_id; + repr_data.repr_id = representor_id; + repr_data.switch_domain_id = switch_domain_id; + repr_data.mport_sel = *mport_sel; + + ret = rte_eth_dev_create(parent->device, name, + sizeof(struct sfc_repr_shared), + NULL, NULL, + sfc_repr_eth_dev_init, &repr_data); + if (ret != 0) { + SFC_GENERIC_LOG(ERR, "%s() failed to create device", + __func__); + return ret; + } + } - return ret; + return 0; } -- 2.30.2