Patchwork [Open-FCoE,libhbalinux,5/6] read most pci attributes with libudev

login
register
mail settings
Submitter Chris Leech
Date Oct. 13, 2014, 11:13 p.m.
Message ID <1413242005-17786-6-git-send-email-cleech@redhat.com>
Download mbox | patch
Permalink /patch/168/
State RFC
Headers show

Comments

Chris Leech - Oct. 13, 2014, 11:13 p.m.
Signed-off-by: Chris Leech <cleech@redhat.com>
---
 lport.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

Patch

diff --git a/lport.c b/lport.c
index 1dd31bb..acd1737 100644
--- a/lport.c
+++ b/lport.c
@@ -186,30 +186,35 @@  find_phys_if(char *hba_dir, char *buf, size_t len)
 }
 
 static void 
-sysfs_scan_pci(const char *hba_dir,
+sysfs_scan_pci(struct udev_device *pci,
 	struct hba_info *hba_info,
 	HBA_ADAPTERATTRIBUTES *atp
 	)
 {
+	const char *attr;
+	const char *hba_dir;
 	char buf[256];
 	char *saveptr;	/* for strtok_r */
 
 	/* Get vendor_id */
-	sa_sys_read_u32(hba_dir, "vendor", &hba_info->vendor_id);
+	attr = udev_device_get_sysattr_value(pci, "vendor");
+	hba_info->vendor_id = strtoul(attr, NULL, 0);
 
 	/* Get device_id */
-	sa_sys_read_u32(hba_dir, "device", &hba_info->device_id);
+	attr = udev_device_get_sysattr_value(pci, "device");
+	hba_info->device_id = strtoul(attr, NULL, 0);
 
 	/* Get subsystem_vendor_id */
-	sa_sys_read_u32(hba_dir, "subsystem_vendor",
-				&hba_info->subsystem_vendor_id);
+	attr = udev_device_get_sysattr_value(pci, "subsystem_vendor");
+	hba_info->subsystem_vendor_id = strtoul(attr, NULL, 0);
 
 	/* Get subsystem_device_id */
-	sa_sys_read_u32(hba_dir, "subsystem_device",
-				&hba_info->subsystem_device_id);
+	attr = udev_device_get_sysattr_value(pci, "subsystem_device");
+	hba_info->subsystem_device_id = strtoul(attr, NULL, 0);
 
 	/* Get device_class */
-	sa_sys_read_u32(hba_dir, "class", &hba_info->device_class);
+	attr = udev_device_get_sysattr_value(pci, "class");
+	hba_info->device_class = strtoul(attr, NULL, 0);
 	hba_info->device_class = hba_info->device_class>>8;
 
 	/*
@@ -290,9 +295,9 @@  sysfs_scan_pci(const char *hba_dir,
 	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
 
 	/* Get DriverVersion */
+	hba_dir = udev_device_get_syspath(pci);
 	sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
 			atp->DriverVersion, sizeof(atp->DriverVersion));
-
 }
 
 static int
@@ -316,6 +321,7 @@  sysfs_scan(struct udev_device *fc_host)
 
 	const char *sysname = udev_device_get_sysname(fc_host);
 	const char *syspath = udev_device_get_syspath(fc_host);
+	struct udev_device *pci;
 	const char *ptr = NULL;
 	const char *attr;
 
@@ -540,7 +546,9 @@  sysfs_scan(struct udev_device *fc_host)
 	snprintf(buf, sizeof(buf), "fcoe:%s", ifname);
 	ap->ad_name = strdup(buf);
 
-	sysfs_scan_pci(syspath, &hba_info, atp);
+	pci = udev_device_get_parent_with_subsystem_devtype(fc_host, "pci", NULL);
+	if (pci)
+		sysfs_scan_pci(pci, &hba_info, atp);
 
 	/* Get NodeSymbolicName */
 	sa_strncpy_safe(atp->NodeSymbolicName, sizeof(atp->NodeSymbolicName),