From patchwork Mon Sep 27 13:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srikanth Kaka X-Patchwork-Id: 99826 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7CDDDA0C46; Mon, 27 Sep 2021 17:01:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 65689411B1; Mon, 27 Sep 2021 16:58:40 +0200 (CEST) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mails.dpdk.org (Postfix) with ESMTP id 5F7FD40E3C for ; Mon, 27 Sep 2021 15:43:24 +0200 (CEST) Received: by mail-pg1-f177.google.com with SMTP id 75so1466759pga.3 for ; Mon, 27 Sep 2021 06:43:24 -0700 (PDT) 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=XFHfzkQkAtV9RoDpC48spl+nGb211hhWKaRZYzd9n2g=; b=NNSxDsEDhi5dh4z4MCftARVKtK0fd/+/P08/hMUrBEwwsgOiGEv7aER38220LAdlZx jJDzJwBleMQJzdQM+sq17DkaUcXOC5GlGbTgGgNLfj9BRerWm1DG5JU28lE868+59kmW fhIFu/61CAqHcRmcTmRV+vrD4AABZ2taXMc8M= 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=XFHfzkQkAtV9RoDpC48spl+nGb211hhWKaRZYzd9n2g=; b=QyU+R+Bm+JCajpJJnWSXIiiJJVkKSuEs0IjGh8SJdP3ZXnW6TK9mfcbESvMsjyYijK xzpXGtZvesU+N/4is5DIwmt0MAE+WZzpeuNsCtZdtLPhGuOaEAgug8gjbrVVIHXg6eAa WCbsDpnXcUcQza8sfDyvC2siLEsNfb2ZHCkAaDzW9HCMZyheNRtxo+EeZp825glh0PeE PXX15OcWmBOnMIG8KrUSyDA2gpynu1x0v1N5eqqKsG94GGBVUTXFDuYPxBFM8yo2jNk1 ekA+2KEfAUDREy7/FGacjfcFDZI6xypxHDhjJO8SRUyMglPty1tOTLlGTrpmjk2qdM1G TRVw== X-Gm-Message-State: AOAM531gB3h9Kem3ZVRCKzH7HUo6rk7549o3g9s9z/U3nEXWzvkoL6LX kLo32ELyQaX3xS8uscto7OW7jg== X-Google-Smtp-Source: ABdhPJxKi2kphyvs/vVmayUGUw0MQcAW4jFp7vs15//yD48fswP1JTT1caY6q4f+REsDXCCMbEZ5Wg== X-Received: by 2002:aa7:9682:0:b0:440:3c00:febd with SMTP id f2-20020aa79682000000b004403c00febdmr23857989pfk.81.1632750203535; Mon, 27 Sep 2021 06:43:23 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([223.178.22.200]) by smtp.gmail.com with ESMTPSA id b3sm16960665pfo.23.2021.09.27.06.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:43:23 -0700 (PDT) From: Srikanth Kaka To: Stephen Hemminger , Long Li Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Mon, 27 Sep 2021 19:12:29 +0530 Message-Id: <20210927134231.11177-10-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210927134231.11177-1-srikanth.k@oneconvergence.com> References: <20210927134231.11177-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 27 Sep 2021 16:58:07 +0200 Subject: [dpdk-dev] [PATCH 09/11] net/netvsc: moving hotplug retry to OS dir 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" 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 Reviewed-by: Long Li --- drivers/net/netvsc/freebsd/hn_os.c | 8 +++ drivers/net/netvsc/hn_ethdev.c | 84 --------------------------- drivers/net/netvsc/hn_os.h | 2 + drivers/net/netvsc/linux/hn_os.c | 92 ++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 84 deletions(-) diff --git a/drivers/net/netvsc/freebsd/hn_os.c b/drivers/net/netvsc/freebsd/hn_os.c index 3bd67e06c8..2ba4c32a76 100644 --- a/drivers/net/netvsc/freebsd/hn_os.c +++ b/drivers/net/netvsc/freebsd/hn_os.c @@ -4,6 +4,8 @@ #include +#include + #include "hn_logs.h" #include "hn_os.h" @@ -12,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 61d7d3daeb..c299b98a6c 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 862dc190c1..9c2f4cd7a8 100644 --- a/drivers/net/netvsc/linux/hn_os.c +++ b/drivers/net/netvsc/linux/hn_os.c @@ -2,11 +2,22 @@ * Copyright(c) 2016-2021 Microsoft Corporation */ +#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; @@ -17,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); +}