[v5,12/14] net/netvsc: moving hotplug retry to OS dir

Message ID 20220423042849.7718-13-srikanth.k@oneconvergence.com (mailing list archive)
State Awaiting Upstream
Delegated to: Thomas Monjalon
Headers
Series add FreeBSD support to VMBUS & NetVSC PMDs |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Srikanth Kaka April 23, 2022, 4:28 a.m. UTC
  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 <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 drivers/net/netvsc/freebsd/hn_os.c |  5 +++
 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, 97 insertions(+), 84 deletions(-)
  

Patch

diff --git a/drivers/net/netvsc/freebsd/hn_os.c b/drivers/net/netvsc/freebsd/hn_os.c
index 4c6a798..fece1be 100644
--- a/drivers/net/netvsc/freebsd/hn_os.c
+++ b/drivers/net/netvsc/freebsd/hn_os.c
@@ -14,3 +14,8 @@  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);
+}
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 104c7ae..dd4b872 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(&eth_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 618c53c..1fb7292 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 1ea12ce..9c2f4cd 100644
--- a/drivers/net/netvsc/linux/hn_os.c
+++ b/drivers/net/netvsc/linux/hn_os.c
@@ -3,12 +3,21 @@ 
  */
 
 #include <unistd.h>
+#include <dirent.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <sys/ioctl.h>
 
 #include <rte_ethdev.h>
+#include <rte_alarm.h>
 
 #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(&eth_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);
+}