Blame SOURCES/libhbalinux-fix-non-pci-netdev.patch

34fd11
diff --git a/Makefile.am b/Makefile.am
34fd11
index 1349e7b..068dc10 100644
34fd11
--- a/Makefile.am
34fd11
+++ b/Makefile.am
34fd11
@@ -1,12 +1,12 @@
34fd11
-AM_CFLAGS = $(HBAAPI_CFLAGS) $(PCIACCESS_CFLAGS)
34fd11
-AM_LDFLAGS= $(PCIACCESS_LIBS)
34fd11
+AM_CFLAGS = $(HBAAPI_CFLAGS) $(PCIACCESS_CFLAGS) $(LIBUDEV_CFLAGS)
34fd11
+AM_LDFLAGS= $(PCIACCESS_LIBS) $(LIBUDEV_LIBS)
34fd11
 
34fd11
 lib_LTLIBRARIES = libhbalinux.la
34fd11
 libhbalinux_la_SOURCES = adapt.c adapt_impl.h api_lib.h bind.c bind_impl.h \
34fd11
 fc_scsi.h fc_types.h lib.c lport.c net_types.h pci.c rport.c scsi.c sg.c \
34fd11
 utils.c utils.h
34fd11
 libhbalinux_la_LDFLAGS = -version-info 2:2:0
34fd11
-libhbalinux_la_LIBADD = $(PCIACCESS_LIBS)
34fd11
+libhbalinux_la_LIBADD = $(PCIACCESS_LIBS) $(LIBUDEV_LIBS)
34fd11
 
34fd11
 pkgconfigdir = $(libdir)/pkgconfig
34fd11
 pkgconfig_DATA = libhbalinux.pc
34fd11
diff --git a/adapt_impl.h b/adapt_impl.h
34fd11
index d86c2f8..9d9a347 100644
34fd11
--- a/adapt_impl.h
34fd11
+++ b/adapt_impl.h
34fd11
@@ -151,7 +151,7 @@ HBA_STATUS scsi_report_luns_v2(HBA_HANDLE, HBA_WWN, HBA_WWN,
34fd11
 HBA_STATUS sg_issue_inquiry(const char *, HBA_UINT8, HBA_UINT8,
34fd11
 		void *, HBA_UINT32 *, HBA_UINT8 *, void *, HBA_UINT32 *);
34fd11
 
34fd11
-void adapter_init(void);
34fd11
+int adapter_init(void);
34fd11
 void adapter_shutdown(void);
34fd11
 
34fd11
 /* struct port_stats; */
34fd11
diff --git a/configure.ac b/configure.ac
34fd11
index 8dadf29..758cadb 100644
34fd11
--- a/configure.ac
34fd11
+++ b/configure.ac
34fd11
@@ -13,6 +13,10 @@ AC_SUBST(PCIACCESS_LIBS)
34fd11
 PKG_CHECK_MODULES(HBAAPI, HBAAPI)
34fd11
 AC_SUBST(HBAAPI_CFLAGS)
34fd11
 
34fd11
+PKG_CHECK_MODULES(LIBUDEV, libudev)
34fd11
+AC_SUBST(LIBUDEV_CFLAGS)
34fd11
+AC_SUBST(LIBUDEV_LIBS)
34fd11
+
34fd11
 AC_CONFIG_FILES([Makefile libhbalinux.spec libhbalinux.pc])
34fd11
 AC_OUTPUT
34fd11
 
34fd11
diff --git a/libhbalinux.spec.in b/libhbalinux.spec.in
34fd11
index 344c166..4690da9 100644
34fd11
--- a/libhbalinux.spec.in
34fd11
+++ b/libhbalinux.spec.in
34fd11
@@ -9,7 +9,7 @@ URL:            http://www.open-fcoe.org
34fd11
 Source0:        http://www.open-fcoe.org/openfc/%{name}-%{version}.tar.gz
34fd11
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
34fd11
 
34fd11
-BuildRequires:  libHBAAPI-devel libpciaccess-devel
34fd11
+BuildRequires:  libHBAAPI-devel libpciaccess-devel systemd-devel
34fd11
 Requires:       libHBAAPI
34fd11
 
34fd11
 %description
34fd11
diff --git a/lport.c b/lport.c
34fd11
index bc34078..695bdc6 100644
34fd11
--- a/lport.c
34fd11
+++ b/lport.c
34fd11
@@ -20,6 +20,8 @@
34fd11
 #include "api_lib.h"
34fd11
 #include "adapt_impl.h"
34fd11
 
34fd11
+#include <libudev.h>
34fd11
+
34fd11
 #ifndef HBA_STATUS_ERROR_ILLEGAL_FCID
34fd11
 #define HBA_STATUS_ERROR_ILLEGAL_FCID 33	/* defined after HBA-API 2.2 */
34fd11
 #endif
34fd11
@@ -88,18 +90,16 @@ struct sa_nameval port_speeds_table[] = {
34fd11
  * and convert them to bitmasks for the HBA_PORTSPEED supported
34fd11
  * Format expected: "1 Gbit[, 10 Gbit]", etc.
34fd11
  */
34fd11
-static int sys_read_speed(const char *dir, const char *file, char *buf,
34fd11
-			  size_t buflen, HBA_PORTSPEED *speeds)
34fd11
+static int sys_read_speed(const char *speedstr, HBA_PORTSPEED *speeds)
34fd11
 {
34fd11
 	int rc = 0;
34fd11
 	u_int32_t val = 0;
34fd11
 	int len = 0;
34fd11
-	char *cp;
34fd11
+	const char *cp;
34fd11
 	struct sa_nameval *tp = port_speeds_table;
34fd11
 
34fd11
-	rc = sa_sys_read_line(dir, file, buf, buflen);
34fd11
-	if (rc == 0 && strstr(buf, "Unknown") == NULL) {
34fd11
-		for (cp = buf; *cp != '\0';) {
34fd11
+	if (rc == 0 && strstr(speedstr, "Unknown") == NULL) {
34fd11
+		for (cp = speedstr; *cp != '\0';) {
34fd11
 			for (; tp->nv_name != NULL; tp++) {
34fd11
 				len = strlen(tp->nv_name);
34fd11
 				if (strncasecmp(tp->nv_name, cp, len) == 0) {
34fd11
@@ -140,69 +140,189 @@ counting_rports(struct dirent *dp, void *arg)
34fd11
 	return HBA_STATUS_OK;
34fd11
 }
34fd11
 
34fd11
-static int
34fd11
-check_ifindex(struct dirent *dp, void *arg)
34fd11
+static void 
34fd11
+sysfs_scan_pci(struct udev_device *pci,
34fd11
+	struct hba_info *hba_info,
34fd11
+	HBA_ADAPTERATTRIBUTES *atp
34fd11
+	)
34fd11
 {
34fd11
-	char *ifindex = (char *)arg;
34fd11
-	char hba_dir[256];
34fd11
+	const char *attr;
34fd11
+	const char *hba_dir;
34fd11
 	char buf[256];
34fd11
-	int rc;
34fd11
-
34fd11
-	snprintf(hba_dir, sizeof(hba_dir),
34fd11
-		 SYSFS_HBA_DIR "/%s", dp->d_name);
34fd11
-	memset(buf, 0, sizeof(buf));
34fd11
-	rc = sa_sys_read_line(hba_dir, "ifindex", buf, sizeof(buf) - 1);
34fd11
-	if (rc)
34fd11
-		return 0;
34fd11
-	if (!strncmp(ifindex, buf, sizeof(buf))) {
34fd11
-		strcpy(arg, dp->d_name);
34fd11
-		return 1;
34fd11
+	char *saveptr;	/* for strtok_r */
34fd11
+
34fd11
+	/* Get vendor_id */
34fd11
+	attr = udev_device_get_sysattr_value(pci, "vendor");
34fd11
+	hba_info->vendor_id = strtoul(attr, NULL, 0);
34fd11
+
34fd11
+	/* Get device_id */
34fd11
+	attr = udev_device_get_sysattr_value(pci, "device");
34fd11
+	hba_info->device_id = strtoul(attr, NULL, 0);
34fd11
+
34fd11
+	/* Get subsystem_vendor_id */
34fd11
+	attr = udev_device_get_sysattr_value(pci, "subsystem_vendor");
34fd11
+	hba_info->subsystem_vendor_id = strtoul(attr, NULL, 0);
34fd11
+
34fd11
+	/* Get subsystem_device_id */
34fd11
+	attr = udev_device_get_sysattr_value(pci, "subsystem_device");
34fd11
+	hba_info->subsystem_device_id = strtoul(attr, NULL, 0);
34fd11
+
34fd11
+	/* Get device_class */
34fd11
+	attr = udev_device_get_sysattr_value(pci, "class");
34fd11
+	hba_info->device_class = strtoul(attr, NULL, 0);
34fd11
+	hba_info->device_class = hba_info->device_class>>8;
34fd11
+
34fd11
+	/*
34fd11
+	 * Get Hardware Information via PCI Library
34fd11
+	 */
34fd11
+
34fd11
+	sscanf(udev_device_get_sysname(pci), "%x:%x:%x:%x",
34fd11
+			&hba_info->domain, &hba_info->bus,
34fd11
+			&hba_info->dev, &hba_info->func);
34fd11
+	(void) find_pci_device(hba_info);
34fd11
+
34fd11
+	/* Get Number of Ports */
34fd11
+	atp->NumberOfPorts = hba_info->NumberOfPorts;
34fd11
+
34fd11
+	/* Get Manufacturer */
34fd11
+	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
34fd11
+			hba_info->Manufacturer, sizeof(hba_info->Manufacturer));
34fd11
+
34fd11
+	/* Get SerialNumber */
34fd11
+	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
34fd11
+			hba_info->SerialNumber, sizeof(hba_info->SerialNumber));
34fd11
+
34fd11
+
34fd11
+	/* Get ModelDescription */
34fd11
+	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
34fd11
+			hba_info->ModelDescription,
34fd11
+			sizeof(hba_info->ModelDescription));
34fd11
+	if (!strncmp(hba_info->ModelDescription, "Unknown",
34fd11
+		 sizeof(hba_info->ModelDescription))) {
34fd11
+		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
34fd11
+			"[%04x:%04x]-[%04x:%04x]-(%04x)",
34fd11
+			hba_info->vendor_id, hba_info->device_id,
34fd11
+			hba_info->subsystem_vendor_id,
34fd11
+			hba_info->subsystem_device_id,
34fd11
+			hba_info->device_class);
34fd11
+		/*
34fd11
+		 * Get Model
34fd11
+		 *
34fd11
+		 * If the device is a newly developed product, and
34fd11
+		 * the model description is not in pci.ids yet, use
34fd11
+		 * the model description constructed above as the
34fd11
+		 * model string.
34fd11
+		 */
34fd11
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
+				atp->ModelDescription,
34fd11
+				sizeof(atp->ModelDescription));
34fd11
 	}
34fd11
-	return 0;
34fd11
+
34fd11
+	/*
34fd11
+	 * Get Model
34fd11
+	 *
34fd11
+	 * If the device name has already been added into
34fd11
+	 * the pci.ids file, use the first word of the model
34fd11
+	 * description as the model. If the space after the
34fd11
+	 * first word is not found (new product), use the
34fd11
+	 * model description as the model.
34fd11
+	 */
34fd11
+	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
34fd11
+			sizeof(atp->ModelDescription));
34fd11
+	if (strtok_r(buf, " ", &saveptr))
34fd11
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
+				buf, strnlen(buf, sizeof(buf)));
34fd11
+	else
34fd11
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
+				atp->ModelDescription,
34fd11
+				sizeof(atp->ModelDescription));
34fd11
+
34fd11
+	/* Get HardwareVersion */
34fd11
+	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
34fd11
+			hba_info->HardwareVersion,
34fd11
+			sizeof(hba_info->HardwareVersion));
34fd11
+
34fd11
+	/* Get OptionROMVersion (TODO) */
34fd11
+	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
34fd11
+			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
34fd11
+
34fd11
+	/* Get FirmwareVersion (TODO) */
34fd11
+	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
34fd11
+			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
34fd11
+
34fd11
+	/* Get VendorSpecificID (TODO) */
34fd11
+	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
34fd11
+
34fd11
+	/* Get DriverVersion */
34fd11
+	hba_dir = udev_device_get_syspath(pci);
34fd11
+	sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
34fd11
+			atp->DriverVersion, sizeof(atp->DriverVersion));
34fd11
 }
34fd11
 
34fd11
-/*
34fd11
- * find_phys_if - find the regular network interface name that
34fd11
- *                has the ifindex that matches the specified iflink.
34fd11
- *                This ifname will be used to find the PCI info
34fd11
- *                of a VLAN interface.
34fd11
- * hba_dir: hba_dir of VLAN interface.
34fd11
- * buf: returns ifname of regular network interface.
34fd11
- */
34fd11
-static int
34fd11
-find_phys_if(char *hba_dir, char *buf, size_t len)
34fd11
+struct udev_device *
34fd11
+find_netdev_by_ifindex(struct udev *udev, const char *ifindex)
34fd11
 {
34fd11
-	int rc;
34fd11
+	struct udev_enumerate *ue;
34fd11
+	struct udev_list_entry *head;
34fd11
+	struct udev_device *newnet = NULL;
34fd11
 
34fd11
-	rc = sa_sys_read_line(hba_dir, "iflink", buf, len);
34fd11
-	if (rc)
34fd11
-		return 1;
34fd11
-	/*
34fd11
-	 * Search for the regular network interface and
34fd11
-	 * return the interface name in the buf.
34fd11
-	 */
34fd11
-	sa_dir_read(SYSFS_HBA_DIR, check_ifindex, buf);
34fd11
-	return 0;
34fd11
+	ue = udev_enumerate_new(udev);
34fd11
+	udev_enumerate_add_match_subsystem(ue, "net");
34fd11
+	udev_enumerate_add_match_sysattr(ue, "ifindex", ifindex); 
34fd11
+	udev_enumerate_scan_devices(ue);
34fd11
+	/* enumerate returns a list, but there should only ever be one device
34fd11
+	 * with a given ifindex */
34fd11
+	head = udev_enumerate_get_list_entry(ue);
34fd11
+	if (head)
34fd11
+		newnet = udev_device_new_from_syspath(udev, udev_list_entry_get_name(head));
34fd11
+	udev_enumerate_unref(ue);
34fd11
+	return newnet;
34fd11
+}
34fd11
+
34fd11
+struct udev_device *
34fd11
+find_phys_if(struct udev_device *net)
34fd11
+{
34fd11
+	const char *ifindex;
34fd11
+	const char *iflink;
34fd11
+	struct udev *udev;
34fd11
+	struct udev_device *lower = NULL;
34fd11
+
34fd11
+	ifindex = udev_device_get_sysattr_value(net, "ifindex");
34fd11
+	iflink = udev_device_get_sysattr_value(net, "iflink");
34fd11
+	if (strcmp(ifindex, iflink)) {
34fd11
+		udev = udev_device_get_udev(net);
34fd11
+		lower = find_netdev_by_ifindex(udev, iflink);
34fd11
+	}
34fd11
+	if (lower) {
34fd11
+		return lower;
34fd11
+	} else {
34fd11
+		udev_device_ref(net);
34fd11
+		return net;
34fd11
+	}
34fd11
 }
34fd11
 
34fd11
 static int
34fd11
-sysfs_scan(struct dirent *dp, void *arg)
34fd11
+sysfs_scan(struct udev_device *fc_host)
34fd11
 {
34fd11
 	HBA_ADAPTERATTRIBUTES *atp;
34fd11
 	HBA_PORTATTRIBUTES *pap;
34fd11
-	HBA_WWN wwnn;
34fd11
+	uint64_t wwnn;
34fd11
 	struct hba_info hba_info;
34fd11
 	struct adapter_info *ap;
34fd11
 	struct port_info *pp;
34fd11
-	char host_dir[80], hba_dir[80], drv_dir[80];
34fd11
-	char dev_dir[128];
34fd11
+	const char *hba_dir;
34fd11
+	char drv_dir[80];
34fd11
 	char ifname[20], buf[256];
34fd11
 	char *driverName;
34fd11
 	int data[32], rc, i;
34fd11
 	char *cp;
34fd11
-	char *saveptr;	/* for strtok_r */
34fd11
-	unsigned int ifindex;
34fd11
-	unsigned int iflink;
34fd11
+
34fd11
+	const char *sysname = udev_device_get_sysname(fc_host);
34fd11
+	const char *syspath = udev_device_get_syspath(fc_host);
34fd11
+	struct udev_device *pci;
34fd11
+	struct udev_device *net;
34fd11
+	const char *ptr = NULL;
34fd11
+	const char *attr;
34fd11
 
34fd11
 	memset(&hba_info, 0, sizeof(hba_info));
34fd11
 
34fd11
@@ -217,7 +337,7 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 		return HBA_STATUS_ERROR;
34fd11
 	}
34fd11
 	memset(ap, 0, sizeof(*ap));
34fd11
-	ap->ad_kern_index = atoi(dp->d_name + sizeof("host") - 1);
34fd11
+	ap->ad_kern_index = atoi(sysname + sizeof("host") - 1);
34fd11
 	ap->ad_port_count = 1;
34fd11
 
34fd11
 	/* atp points to the HBA attributes structure */
34fd11
@@ -239,137 +359,76 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 	memset(pp, 0, sizeof(*pp));
34fd11
 	pp->ap_adapt = ap;
34fd11
 	pp->ap_index = ap->ad_port_count - 1;
34fd11
-	pp->ap_kern_hba = atoi(dp->d_name + sizeof("host") - 1);
34fd11
+	pp->ap_kern_hba = atoi(sysname + sizeof("host") - 1);
34fd11
 
34fd11
 	/* pap points to the local port attributes structure */
34fd11
 	pap = &pp->ap_attr;
34fd11
 
34fd11
-	/* Construct the host directory name from the input name */
34fd11
-	snprintf(host_dir, sizeof(host_dir),
34fd11
-		SYSFS_HOST_DIR "/%s", dp->d_name);
34fd11
-
34fd11
-	rc = sa_sys_read_line(host_dir, "symbolic_name", buf, sizeof(buf));
34fd11
-
34fd11
 	/* Get PortSymbolicName */
34fd11
+	ptr = udev_device_get_sysattr_value(fc_host, "symbolic_name");
34fd11
 	sa_strncpy_safe(pap->PortSymbolicName, sizeof(pap->PortSymbolicName),
34fd11
-			buf, sizeof(buf));
34fd11
+			ptr, strlen(ptr));
34fd11
 
34fd11
 	/* Skip the HBA if it isn't OpenFC */
34fd11
 	cp = strstr(pap->PortSymbolicName, " over ");
34fd11
 	if (!cp)
34fd11
 		goto skip;
34fd11
 
34fd11
-	/*
34fd11
-	 * See if <host_dir>/device is a PCI symlink.
34fd11
-	 * If not, try it as a net device.
34fd11
-	 */
34fd11
-	snprintf(dev_dir, sizeof(dev_dir), "%s/device", host_dir);
34fd11
-	i = readlink(dev_dir, buf, sizeof(buf) - 1);
34fd11
-	if (i < 0)
34fd11
-		i = 0;
34fd11
-	buf[i] = '\0';
34fd11
-
34fd11
-	if (strstr(buf, "devices/pci") && !strstr(buf, "/net/")) {
34fd11
-		snprintf(hba_dir, sizeof(hba_dir), "%s/device/..", host_dir);
34fd11
-	} else {
34fd11
-		/* assume a net device */
34fd11
-		cp += 6;
34fd11
-		sa_strncpy_safe(ifname, sizeof(ifname), cp, strlen(cp));
34fd11
-		snprintf(hba_dir, sizeof(hba_dir),
34fd11
-			 SYSFS_HBA_DIR "/%s", ifname);
34fd11
-		/*
34fd11
-		 * Try as VLAN device or other virtual net device.
34fd11
-		 * If this is the case, ifindex and iflink will be different.
34fd11
-		 * iflink is the ifindex of the physical device.
34fd11
-		 */
34fd11
-		rc = sa_sys_read_u32(hba_dir, "ifindex", &ifindex);
34fd11
-		if (rc < 0)
34fd11
-			goto skip;
34fd11
-		rc = sa_sys_read_u32(hba_dir, "iflink", &iflink);
34fd11
-		if (rc < 0)
34fd11
-			goto skip;
34fd11
-		if (ifindex != iflink) {
34fd11
-			rc = find_phys_if(hba_dir, buf, sizeof(buf));
34fd11
-			if (rc)
34fd11
-				goto skip;
34fd11
-			strncpy(ifname, buf, sizeof(ifname));
34fd11
-		}
34fd11
-
34fd11
-		snprintf(hba_dir, sizeof(hba_dir),
34fd11
-			 SYSFS_HBA_DIR "/%s/device", ifname);
34fd11
-		i = readlink(hba_dir, buf, sizeof(buf) - 1);
34fd11
-		if (i < 0)
34fd11
-			goto skip;
34fd11
-		buf[i] = '\0';
34fd11
+	pci = udev_device_get_parent_with_subsystem_devtype(fc_host, "pci", NULL);
34fd11
+	net = udev_device_get_parent_with_subsystem_devtype(fc_host, "net", NULL);
34fd11
+	if (!pci && net) {
34fd11
+		/* check for a vlan device, stacked on a real PCI network device */
34fd11
+		net = find_phys_if(net);
34fd11
+		pci = udev_device_get_parent_with_subsystem_devtype(net, "pci", NULL);
34fd11
 	}
34fd11
 
34fd11
 	/*
34fd11
-	 * Assume a PCI symlink value is in buf.
34fd11
-	 * Back up to the last path component that looks like a PCI element.
34fd11
-	 * A sample link value is like:
34fd11
-	 *	../../devices/pci*.../0000:03:00.0
34fd11
-	 */
34fd11
-	rc = 0;
34fd11
-	do {
34fd11
-		cp = strrchr(buf, '/');
34fd11
-		if (!cp)
34fd11
-			break;
34fd11
-		rc = sscanf(cp + 1, "%x:%x:%x.%x",
34fd11
-			    &hba_info.domain, &hba_info.bus,
34fd11
-			    &hba_info.dev, &hba_info.func);
34fd11
-		if (rc == 4)
34fd11
-			break;
34fd11
-		*cp = '\0';
34fd11
-	} while (cp && cp > buf);
34fd11
-
34fd11
-	if (rc != 4)
34fd11
-		goto skip;
34fd11
-
34fd11
-	/*
34fd11
 	 * Save the host directory and the hba directory
34fd11
 	 * in local port structure
34fd11
 	 */
34fd11
 	sa_strncpy_safe(pp->host_dir, sizeof(pp->host_dir),
34fd11
-			host_dir, sizeof(host_dir));
34fd11
+			syspath, strlen(syspath));
34fd11
 
34fd11
 	/* Get NodeWWN */
34fd11
-	rc = sys_read_wwn(pp->host_dir, "node_name", &wwnn);
34fd11
-	memcpy(&pap->NodeWWN, &wwnn, sizeof(wwnn));
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "node_name");
34fd11
+	wwnn = strtoull(attr, NULL, 16);
34fd11
+	copy_wwn(&pap->NodeWWN, wwnn);
34fd11
 
34fd11
 	/* Get PortWWN */
34fd11
-	rc = sys_read_wwn(pp->host_dir, "port_name", &pap->PortWWN);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "port_name");
34fd11
+	wwnn = strtoull(attr, NULL, 16);
34fd11
+	copy_wwn(&pap->PortWWN, wwnn);
34fd11
 
34fd11
 	/* Get PortFcId */
34fd11
-	rc = sa_sys_read_u32(pp->host_dir, "port_id", &pap->PortFcId);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "port_id");
34fd11
+	pap->PortFcId = strtoul(attr, NULL, 0);
34fd11
 
34fd11
 	/* Get PortType */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "port_type", buf, sizeof(buf));
34fd11
-	rc = sa_enum_encode(port_types_table, buf, &pap->PortType);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "port_type");
34fd11
+	rc = sa_enum_encode(port_types_table, attr, &pap->PortType);
34fd11
 
34fd11
 	/* Get PortState */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "port_state", buf, sizeof(buf));
34fd11
-	rc = sa_enum_encode(port_states_table, buf, &pap->PortState);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "port_state");
34fd11
+	rc = sa_enum_encode(port_states_table, attr, &pap->PortState);
34fd11
 
34fd11
 	/* Get PortSpeed */
34fd11
-	rc = sys_read_speed(pp->host_dir, "speed",
34fd11
-				buf, sizeof(buf),
34fd11
-				&pap->PortSpeed);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "speed");
34fd11
+	rc = sys_read_speed(attr, &pap->PortSpeed);
34fd11
 
34fd11
 	/* Get PortSupportedSpeed */
34fd11
-	rc = sys_read_speed(pp->host_dir, "supported_speeds",
34fd11
-				buf, sizeof(buf),
34fd11
-				&pap->PortSupportedSpeed);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "supported_speeds");
34fd11
+	rc = sys_read_speed(attr, &pap->PortSupportedSpeed);
34fd11
 
34fd11
 	/* Get PortMaxFrameSize */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "maxframe_size", buf, sizeof(buf));
34fd11
-	sscanf(buf, "%d", &pap->PortMaxFrameSize);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "maxframe_size");
34fd11
+	sscanf(attr, "%d", &pap->PortMaxFrameSize);
34fd11
 
34fd11
 	/* Get PortSupportedFc4Types */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "supported_fc4s", buf, sizeof(buf));
34fd11
-	sscanf(buf, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "supported_fc4s");
34fd11
+	sscanf(attr, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
34fd11
 		&data[0], &data[1], &data[2], &data[3], &data[4], &data[5],
34fd11
 		&data[6], &data[7], &data[8], &data[9], &data[10], &data[11],
34fd11
 		&data[12], &data[13], &data[14], &data[15], &data[16],
34fd11
@@ -380,11 +439,11 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 		pap->PortSupportedFc4Types.bits[i] = data[i];
34fd11
 
34fd11
 	/* Get PortActiveFc4Types */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "active_fc4s", buf, sizeof(buf));
34fd11
-	sscanf(buf, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
-		    "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "active_fc4s");
34fd11
+	sscanf(attr, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x "
34fd11
+		     "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x",
34fd11
 		&data[0], &data[1], &data[2], &data[3], &data[4], &data[5],
34fd11
 		&data[6], &data[7], &data[8], &data[9], &data[10], &data[11],
34fd11
 		&data[12], &data[13], &data[14], &data[15], &data[16],
34fd11
@@ -395,19 +454,19 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 		pap->PortActiveFc4Types.bits[i] = data[i];
34fd11
 
34fd11
 	/* Get FabricName */
34fd11
-	rc = sys_read_wwn(pp->host_dir, "fabric_name", &pap->FabricName);
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "fabric_name");
34fd11
+	wwnn = strtoull(attr, NULL, 16);
34fd11
+	copy_wwn(&pap->FabricName, wwnn);
34fd11
 
34fd11
 	/* Get PortSupportedClassofService */
34fd11
-	rc = sa_sys_read_line(pp->host_dir, "supported_classes",
34fd11
-				buf, sizeof(buf));
34fd11
-
34fd11
-	cp = strstr(buf, "Class");
34fd11
+	attr = udev_device_get_sysattr_value(fc_host, "supported_classes");
34fd11
+	cp = strstr(attr, "Class");
34fd11
 	if (cp)
34fd11
 		pap->PortSupportedClassofService = *(cp + 6) - '0';
34fd11
 
34fd11
 	/* Get OSDeviceName */
34fd11
 	sa_strncpy_safe(pap->OSDeviceName, sizeof(pap->OSDeviceName),
34fd11
-			dp->d_name, sizeof(dp->d_name));
34fd11
+			sysname, sizeof(sysname));
34fd11
 
34fd11
 	/* Get NumberofDiscoveredPorts */
34fd11
 	snprintf(buf, sizeof(buf), "%s/device", pp->host_dir);
34fd11
@@ -428,104 +487,8 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 	snprintf(buf, sizeof(buf), "fcoe:%s", ifname);
34fd11
 	ap->ad_name = strdup(buf);
34fd11
 
34fd11
-	/* Get vendor_id */
34fd11
-	rc = sa_sys_read_u32(hba_dir, "vendor", &hba_info.vendor_id);
34fd11
-
34fd11
-	/* Get device_id */
34fd11
-	rc = sa_sys_read_u32(hba_dir, "device", &hba_info.device_id);
34fd11
-
34fd11
-	/* Get subsystem_vendor_id */
34fd11
-	rc = sa_sys_read_u32(hba_dir, "subsystem_vendor",
34fd11
-				&hba_info.subsystem_vendor_id);
34fd11
-
34fd11
-	/* Get subsystem_device_id */
34fd11
-	rc = sa_sys_read_u32(hba_dir, "subsystem_device",
34fd11
-				&hba_info.subsystem_device_id);
34fd11
-
34fd11
-	/* Get device_class */
34fd11
-	rc = sa_sys_read_u32(hba_dir, "class", &hba_info.device_class);
34fd11
-	hba_info.device_class = hba_info.device_class>>8;
34fd11
-
34fd11
-	/*
34fd11
-	 * Get Hardware Information via PCI Library
34fd11
-	 */
34fd11
-	(void) find_pci_device(&hba_info);
34fd11
-
34fd11
-	/* Get Number of Ports */
34fd11
-	atp->NumberOfPorts = hba_info.NumberOfPorts;
34fd11
-
34fd11
-	/* Get Manufacturer */
34fd11
-	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
34fd11
-			hba_info.Manufacturer, sizeof(hba_info.Manufacturer));
34fd11
-
34fd11
-	/* Get SerialNumber */
34fd11
-	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
34fd11
-			hba_info.SerialNumber, sizeof(hba_info.SerialNumber));
34fd11
-
34fd11
-
34fd11
-	/* Get ModelDescription */
34fd11
-	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
34fd11
-			hba_info.ModelDescription,
34fd11
-			sizeof(hba_info.ModelDescription));
34fd11
-	if (!strncmp(hba_info.ModelDescription, "Unknown",
34fd11
-		 sizeof(hba_info.ModelDescription))) {
34fd11
-		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
34fd11
-			"[%04x:%04x]-[%04x:%04x]-(%04x)",
34fd11
-			hba_info.vendor_id, hba_info.device_id,
34fd11
-			hba_info.subsystem_vendor_id,
34fd11
-			hba_info.subsystem_device_id,
34fd11
-			hba_info.device_class);
34fd11
-		/*
34fd11
-		 * Get Model
34fd11
-		 *
34fd11
-		 * If the device is a newly developed product, and
34fd11
-		 * the model description is not in pci.ids yet, use
34fd11
-		 * the model description constructed above as the
34fd11
-		 * model string.
34fd11
-		 */
34fd11
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
-				atp->ModelDescription,
34fd11
-				sizeof(atp->ModelDescription));
34fd11
-	}
34fd11
-
34fd11
-	/*
34fd11
-	 * Get Model
34fd11
-	 *
34fd11
-	 * If the device name has already been added into
34fd11
-	 * the pci.ids file, use the first word of the model
34fd11
-	 * description as the model. If the space after the
34fd11
-	 * first word is not found (new product), use the
34fd11
-	 * model description as the model.
34fd11
-	 */
34fd11
-	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
34fd11
-			sizeof(atp->ModelDescription));
34fd11
-	if (strtok_r(buf, " ", &saveptr))
34fd11
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
-				buf, strnlen(buf, sizeof(buf)));
34fd11
-	else
34fd11
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
34fd11
-				atp->ModelDescription,
34fd11
-				sizeof(atp->ModelDescription));
34fd11
-
34fd11
-	/* Get HardwareVersion */
34fd11
-	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
34fd11
-			hba_info.HardwareVersion,
34fd11
-			sizeof(hba_info.HardwareVersion));
34fd11
-
34fd11
-	/* Get OptionROMVersion (TODO) */
34fd11
-	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
34fd11
-			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
34fd11
-
34fd11
-	/* Get FirmwareVersion (TODO) */
34fd11
-	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
34fd11
-			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
34fd11
-
34fd11
-	/* Get VendorSpecificID (TODO) */
34fd11
-	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
34fd11
-
34fd11
-	/* Get DriverVersion */
34fd11
-	rc = sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
34fd11
-			atp->DriverVersion, sizeof(atp->DriverVersion));
34fd11
+	if (pci)
34fd11
+		sysfs_scan_pci(pci, &hba_info, atp);
34fd11
 
34fd11
 	/* Get NodeSymbolicName */
34fd11
 	sa_strncpy_safe(atp->NodeSymbolicName, sizeof(atp->NodeSymbolicName),
34fd11
@@ -538,6 +501,7 @@ sysfs_scan(struct dirent *dp, void *arg)
34fd11
 		sizeof(pap->NodeWWN));
34fd11
 
34fd11
 	/* Get DriverName */
34fd11
+	hba_dir = udev_device_get_syspath(pci);
34fd11
 	snprintf(drv_dir, sizeof(drv_dir), "%s" SYSFS_MODULE , hba_dir);
34fd11
 	i = readlink(drv_dir, buf, sizeof(buf));
34fd11
 	if (i < 0)
34fd11
@@ -662,10 +626,48 @@ sysfs_get_port_fc4stats(char *dir, HBA_FC4STATISTICS *fc4sp)
34fd11
 /*
34fd11
  * Open device and read adapter info if available.
34fd11
  */
34fd11
-void
34fd11
+int
34fd11
 adapter_init(void)
34fd11
 {
34fd11
-	sa_dir_read(SYSFS_HOST_DIR, sysfs_scan, NULL);
34fd11
+	struct udev *udev;
34fd11
+	struct udev_enumerate *ue;
34fd11
+	struct udev_list_entry *head, *ul;
34fd11
+	struct udev_device *fc_host;
34fd11
+	const char *syspath;
34fd11
+	int re = 0;
34fd11
+
34fd11
+	udev = udev_new();
34fd11
+	if (!udev) {
34fd11
+		return -ENOMEM;
34fd11
+	}
34fd11
+	ue = udev_enumerate_new(udev);
34fd11
+	if (!ue) {
34fd11
+		re = -ENOMEM;
34fd11
+		goto err_enum_new;
34fd11
+	}
34fd11
+	re = udev_enumerate_add_match_subsystem(ue, "fc_host");
34fd11
+	if (re) {
34fd11
+		goto err_add_match;
34fd11
+	}
34fd11
+	re = udev_enumerate_scan_devices(ue);
34fd11
+	if (re) {
34fd11
+		goto err_scan_devs;
34fd11
+	}
34fd11
+	head = udev_enumerate_get_list_entry(ue);
34fd11
+	udev_list_entry_foreach(ul, head) {
34fd11
+		syspath = udev_list_entry_get_name(ul);
34fd11
+		fc_host = udev_device_new_from_syspath(udev, syspath);
34fd11
+		if (!fc_host)
34fd11
+			continue;
34fd11
+		sysfs_scan(fc_host);
34fd11
+		udev_device_unref(fc_host);
34fd11
+	}
34fd11
+err_scan_devs:
34fd11
+err_add_match:
34fd11
+	udev_enumerate_unref(ue);
34fd11
+err_enum_new:
34fd11
+	udev_unref(udev);
34fd11
+	return re;
34fd11
 }
34fd11
 
34fd11
 void