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 E2F35A034E; Thu, 17 Feb 2022 17:12:09 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 95EC7411B6; Thu, 17 Feb 2022 17:11:02 +0100 (CET) Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by mails.dpdk.org (Postfix) with ESMTP id 027D640042 for ; Thu, 17 Feb 2022 17:07:00 +0100 (CET) Received: by mail-pj1-f66.google.com with SMTP id qe15so6003547pjb.3 for ; Thu, 17 Feb 2022 08:06:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BEpDKAeDbz1GNZlqcVjcUBf83yZNy9f8hz+YSThexrc=; b=PlkqOtJceHsjAwKny8WjUHGruDtw236/hHMbYAxgQezZ7GUXQmrFS43pTy6RDOCjMX X50vTJo7IIoFBMHbyfHA2Z1hrGehQZazoV5J70lJRFToAhb8kxl1DhK7YCsQtlySe/w5 031YyBJRMTWzPfgXsJB2EChGP/z0grNXhr/vE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BEpDKAeDbz1GNZlqcVjcUBf83yZNy9f8hz+YSThexrc=; b=IuM1J1GWByuTd1s7EEA/IwpnCyiEV4GYzH7JPhnGX2f7uFiUkx0dKuQzmNUlU/oVsh 1lAAFrHJxozd3o+XkykZmmV8Ab8iieDKKGZHU8iyU1FDYk57JmjHBAwH/AfM/c0Y6uMl jNI+8eC81JOrFost4pbLYGzlqUiuSyohvRMZ15fqqenjU6YurWlEcRfEwAgaEbPfCuuh 4c0ZveSG6TXCKezeSP5KV4kV0FLdVPCusZDTE3avE5g6r+aAk+mF0mUt8+w0KpSo4o/g mMF/QUladcDXY8t4Ve1Y3objjQpuJinl8zWZmKf32I543DfJZmLj3xxUPUuaJEuVhDeg zWXg== X-Gm-Message-State: AOAM533lMprf75loISBrAQn6PbB9I0OvSihEkRyDYxpH+kVFkn0eo/Wh PITJW38Tqc4O3TVC8MxnsXsunQ== X-Google-Smtp-Source: ABdhPJxDlrTBJ2rNFW9fQvrBpV3VFtqmAksuZByZCGVBdIrzHrrkqnUdnX5NmLUqpG+vQYW5yCPirg== X-Received: by 2002:a17:90b:3806:b0:1b8:e628:d88 with SMTP id mq6-20020a17090b380600b001b8e6280d88mr8048624pjb.32.1645114019174; Thu, 17 Feb 2022 08:06:59 -0800 (PST) Received: from srikanth-ThinkPad-T450.. ([49.37.144.122]) by smtp.gmail.com with ESMTPSA id z14sm47807pfh.173.2022.02.17.08.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 08:06:58 -0800 (PST) From: Srikanth Kaka To: sthemmin@microsoft.com, longli@microsoft.com Cc: dev@dpdk.org, vag.singh@oneconvergence.com, avelu@juniper.net, Srikanth Kaka Subject: [PATCH v3 11/15] net/netvsc: moving hotplug retry to OS dir Date: Thu, 17 Feb 2022 21:36:09 +0530 Message-Id: <20220217160613.70161-12-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220217160613.70161-1-srikanth.k@oneconvergence.com> References: <20210927134231.11177-1-srikanth.k@oneconvergence.com> <20220217160613.70161-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 17 Feb 2022 17:10:51 +0100 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 Moved netvsc_hotplug_retry to respective OS dir as it contains OS dependent code. For Linux, it is copied as is and for FreeBSD it is not supported yet. Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/net/netvsc/freebsd/hn_os.c | 6 ++ drivers/net/netvsc/hn_ethdev.c | 84 ---------------------------- drivers/net/netvsc/hn_os.h | 2 + drivers/net/netvsc/linux/hn_os.c | 90 ++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 84 deletions(-) diff --git a/drivers/net/netvsc/freebsd/hn_os.c b/drivers/net/netvsc/freebsd/hn_os.c index 4c6a79872d..2ba4c32a76 100644 --- a/drivers/net/netvsc/freebsd/hn_os.c +++ b/drivers/net/netvsc/freebsd/hn_os.c @@ -14,3 +14,9 @@ int eth_hn_os_dev_event(void) PMD_DRV_LOG(DEBUG, "rte_dev_event_monitor_start not supported on FreeBSD"); return 0; } + +void netvsc_hotplug_retry(void *args) +{ + RTE_SET_USED(args); + return; +} diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c index 104c7aebc5..dd4b872fed 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -57,9 +57,6 @@ #define NETVSC_ARG_TXBREAK "tx_copybreak" #define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable" -/* The max number of retry when hot adding a VF device */ -#define NETVSC_MAX_HOTADD_RETRY 10 - struct hn_xstats_name_off { char name[RTE_ETH_XSTATS_NAME_SIZE]; unsigned int offset; @@ -556,87 +553,6 @@ static int hn_subchan_configure(struct hn_data *hv, return err; } -static void netvsc_hotplug_retry(void *args) -{ - int ret; - struct hn_data *hv = args; - struct rte_eth_dev *dev = &rte_eth_devices[hv->port_id]; - struct rte_devargs *d = &hv->devargs; - char buf[256]; - - DIR *di; - struct dirent *dir; - struct ifreq req; - struct rte_ether_addr eth_addr; - int s; - - PMD_DRV_LOG(DEBUG, "%s: retry count %d", - __func__, hv->eal_hot_plug_retry); - - if (hv->eal_hot_plug_retry++ > NETVSC_MAX_HOTADD_RETRY) - return; - - snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/net", d->name); - di = opendir(buf); - if (!di) { - PMD_DRV_LOG(DEBUG, "%s: can't open directory %s, " - "retrying in 1 second", __func__, buf); - goto retry; - } - - while ((dir = readdir(di))) { - /* Skip . and .. directories */ - if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) - continue; - - /* trying to get mac address if this is a network device*/ - s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - if (s == -1) { - PMD_DRV_LOG(ERR, "Failed to create socket errno %d", - errno); - break; - } - strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name)); - ret = ioctl(s, SIOCGIFHWADDR, &req); - close(s); - if (ret == -1) { - PMD_DRV_LOG(ERR, - "Failed to send SIOCGIFHWADDR for device %s", - dir->d_name); - break; - } - if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) { - closedir(di); - return; - } - memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data, - RTE_DIM(eth_addr.addr_bytes)); - - if (rte_is_same_ether_addr(ð_addr, dev->data->mac_addrs)) { - PMD_DRV_LOG(NOTICE, - "Found matching MAC address, adding device %s network name %s", - d->name, dir->d_name); - ret = rte_eal_hotplug_add(d->bus->name, d->name, - d->args); - if (ret) { - PMD_DRV_LOG(ERR, - "Failed to add PCI device %s", - d->name); - break; - } - } - /* When the code reaches here, we either have already added - * the device, or its MAC address did not match. - */ - closedir(di); - return; - } - closedir(di); -retry: - /* The device is still being initialized, retry after 1 second */ - rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv); -} - static void netvsc_hotadd_callback(const char *device_name, enum rte_dev_event_type type, void *arg) diff --git a/drivers/net/netvsc/hn_os.h b/drivers/net/netvsc/hn_os.h index 618c53cdcd..1fb7292b17 100644 --- a/drivers/net/netvsc/hn_os.h +++ b/drivers/net/netvsc/hn_os.h @@ -4,3 +4,5 @@ */ int eth_hn_os_dev_event(void); + +void netvsc_hotplug_retry(void *args); diff --git a/drivers/net/netvsc/linux/hn_os.c b/drivers/net/netvsc/linux/hn_os.c index 1ea12ce928..9c2f4cd7a8 100644 --- a/drivers/net/netvsc/linux/hn_os.c +++ b/drivers/net/netvsc/linux/hn_os.c @@ -3,12 +3,21 @@ */ #include +#include +#include +#include +#include #include +#include #include "hn_logs.h" +#include "hn_var.h" #include "hn_os.h" +/* The max number of retry when hot adding a VF device */ +#define NETVSC_MAX_HOTADD_RETRY 10 + int eth_hn_os_dev_event(void) { int ret; @@ -19,3 +28,84 @@ int eth_hn_os_dev_event(void) return ret; } + +void netvsc_hotplug_retry(void *args) +{ + int ret; + struct hn_data *hv = args; + struct rte_eth_dev *dev = &rte_eth_devices[hv->port_id]; + struct rte_devargs *d = &hv->devargs; + char buf[256]; + + DIR *di; + struct dirent *dir; + struct ifreq req; + struct rte_ether_addr eth_addr; + int s; + + PMD_DRV_LOG(DEBUG, "%s: retry count %d", + __func__, hv->eal_hot_plug_retry); + + if (hv->eal_hot_plug_retry++ > NETVSC_MAX_HOTADD_RETRY) + return; + + snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/net", d->name); + di = opendir(buf); + if (!di) { + PMD_DRV_LOG(DEBUG, "%s: can't open directory %s, " + "retrying in 1 second", __func__, buf); + goto retry; + } + + while ((dir = readdir(di))) { + /* Skip . and .. directories */ + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + continue; + + /* trying to get mac address if this is a network device*/ + s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + if (s == -1) { + PMD_DRV_LOG(ERR, "Failed to create socket errno %d", + errno); + break; + } + strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name)); + ret = ioctl(s, SIOCGIFHWADDR, &req); + close(s); + if (ret == -1) { + PMD_DRV_LOG(ERR, + "Failed to send SIOCGIFHWADDR for device %s", + dir->d_name); + break; + } + if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) { + closedir(di); + return; + } + memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data, + RTE_DIM(eth_addr.addr_bytes)); + + if (rte_is_same_ether_addr(ð_addr, dev->data->mac_addrs)) { + PMD_DRV_LOG(NOTICE, + "Found matching MAC address, adding device %s network name %s", + d->name, dir->d_name); + ret = rte_eal_hotplug_add(d->bus->name, d->name, + d->args); + if (ret) { + PMD_DRV_LOG(ERR, + "Failed to add PCI device %s", + d->name); + break; + } + } + /* When the code reaches here, we either have already added + * the device, or its MAC address did not match. + */ + closedir(di); + return; + } + closedir(di); +retry: + /* The device is still being initialized, retry after 1 second */ + rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv); +} -- 2.30.2