Patchwork [Open-FCoE,libhbalinux,4/6] move pci scanning to sub-function

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

Comments

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

Patch

diff --git a/lport.c b/lport.c
index 5aff2ca..1dd31bb 100644
--- a/lport.c
+++ b/lport.c
@@ -185,6 +185,116 @@  find_phys_if(char *hba_dir, char *buf, size_t len)
 	return 0;
 }
 
+static void 
+sysfs_scan_pci(const char *hba_dir,
+	struct hba_info *hba_info,
+	HBA_ADAPTERATTRIBUTES *atp
+	)
+{
+	char buf[256];
+	char *saveptr;	/* for strtok_r */
+
+	/* Get vendor_id */
+	sa_sys_read_u32(hba_dir, "vendor", &hba_info->vendor_id);
+
+	/* Get device_id */
+	sa_sys_read_u32(hba_dir, "device", &hba_info->device_id);
+
+	/* Get subsystem_vendor_id */
+	sa_sys_read_u32(hba_dir, "subsystem_vendor",
+				&hba_info->subsystem_vendor_id);
+
+	/* Get subsystem_device_id */
+	sa_sys_read_u32(hba_dir, "subsystem_device",
+				&hba_info->subsystem_device_id);
+
+	/* Get device_class */
+	sa_sys_read_u32(hba_dir, "class", &hba_info->device_class);
+	hba_info->device_class = hba_info->device_class>>8;
+
+	/*
+	 * Get Hardware Information via PCI Library
+	 */
+	(void) find_pci_device(hba_info);
+
+	/* Get Number of Ports */
+	atp->NumberOfPorts = hba_info->NumberOfPorts;
+
+	/* Get Manufacturer */
+	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
+			hba_info->Manufacturer, sizeof(hba_info->Manufacturer));
+
+	/* Get SerialNumber */
+	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
+			hba_info->SerialNumber, sizeof(hba_info->SerialNumber));
+
+
+	/* Get ModelDescription */
+	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
+			hba_info->ModelDescription,
+			sizeof(hba_info->ModelDescription));
+	if (!strncmp(hba_info->ModelDescription, "Unknown",
+		 sizeof(hba_info->ModelDescription))) {
+		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
+			"[%04x:%04x]-[%04x:%04x]-(%04x)",
+			hba_info->vendor_id, hba_info->device_id,
+			hba_info->subsystem_vendor_id,
+			hba_info->subsystem_device_id,
+			hba_info->device_class);
+		/*
+		 * Get Model
+		 *
+		 * If the device is a newly developed product, and
+		 * the model description is not in pci.ids yet, use
+		 * the model description constructed above as the
+		 * model string.
+		 */
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
+				atp->ModelDescription,
+				sizeof(atp->ModelDescription));
+	}
+
+	/*
+	 * Get Model
+	 *
+	 * If the device name has already been added into
+	 * the pci.ids file, use the first word of the model
+	 * description as the model. If the space after the
+	 * first word is not found (new product), use the
+	 * model description as the model.
+	 */
+	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
+			sizeof(atp->ModelDescription));
+	if (strtok_r(buf, " ", &saveptr))
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
+				buf, strnlen(buf, sizeof(buf)));
+	else
+		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
+				atp->ModelDescription,
+				sizeof(atp->ModelDescription));
+
+	/* Get HardwareVersion */
+	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
+			hba_info->HardwareVersion,
+			sizeof(hba_info->HardwareVersion));
+
+	/* Get OptionROMVersion (TODO) */
+	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
+			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
+
+	/* Get FirmwareVersion (TODO) */
+	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
+			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
+
+	/* Get VendorSpecificID (TODO) */
+	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
+
+	/* Get DriverVersion */
+	sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
+			atp->DriverVersion, sizeof(atp->DriverVersion));
+
+}
+
 static int
 sysfs_scan(struct udev_device *fc_host)
 {
@@ -201,7 +311,6 @@  sysfs_scan(struct udev_device *fc_host)
 	char *driverName;
 	int data[32], rc, i;
 	char *cp;
-	char *saveptr;	/* for strtok_r */
 	unsigned int ifindex;
 	unsigned int iflink;
 
@@ -431,104 +540,7 @@  sysfs_scan(struct udev_device *fc_host)
 	snprintf(buf, sizeof(buf), "fcoe:%s", ifname);
 	ap->ad_name = strdup(buf);
 
-	/* Get vendor_id */
-	rc = sa_sys_read_u32(hba_dir, "vendor", &hba_info.vendor_id);
-
-	/* Get device_id */
-	rc = sa_sys_read_u32(hba_dir, "device", &hba_info.device_id);
-
-	/* Get subsystem_vendor_id */
-	rc = sa_sys_read_u32(hba_dir, "subsystem_vendor",
-				&hba_info.subsystem_vendor_id);
-
-	/* Get subsystem_device_id */
-	rc = sa_sys_read_u32(hba_dir, "subsystem_device",
-				&hba_info.subsystem_device_id);
-
-	/* Get device_class */
-	rc = sa_sys_read_u32(hba_dir, "class", &hba_info.device_class);
-	hba_info.device_class = hba_info.device_class>>8;
-
-	/*
-	 * Get Hardware Information via PCI Library
-	 */
-	(void) find_pci_device(&hba_info);
-
-	/* Get Number of Ports */
-	atp->NumberOfPorts = hba_info.NumberOfPorts;
-
-	/* Get Manufacturer */
-	sa_strncpy_safe(atp->Manufacturer, sizeof(atp->Manufacturer),
-			hba_info.Manufacturer, sizeof(hba_info.Manufacturer));
-
-	/* Get SerialNumber */
-	sa_strncpy_safe(atp->SerialNumber, sizeof(atp->SerialNumber),
-			hba_info.SerialNumber, sizeof(hba_info.SerialNumber));
-
-
-	/* Get ModelDescription */
-	sa_strncpy_safe(atp->ModelDescription, sizeof(atp->ModelDescription),
-			hba_info.ModelDescription,
-			sizeof(hba_info.ModelDescription));
-	if (!strncmp(hba_info.ModelDescription, "Unknown",
-		 sizeof(hba_info.ModelDescription))) {
-		snprintf(atp->ModelDescription, sizeof(atp->ModelDescription),
-			"[%04x:%04x]-[%04x:%04x]-(%04x)",
-			hba_info.vendor_id, hba_info.device_id,
-			hba_info.subsystem_vendor_id,
-			hba_info.subsystem_device_id,
-			hba_info.device_class);
-		/*
-		 * Get Model
-		 *
-		 * If the device is a newly developed product, and
-		 * the model description is not in pci.ids yet, use
-		 * the model description constructed above as the
-		 * model string.
-		 */
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
-				atp->ModelDescription,
-				sizeof(atp->ModelDescription));
-	}
-
-	/*
-	 * Get Model
-	 *
-	 * If the device name has already been added into
-	 * the pci.ids file, use the first word of the model
-	 * description as the model. If the space after the
-	 * first word is not found (new product), use the
-	 * model description as the model.
-	 */
-	sa_strncpy_safe(buf, sizeof(buf), atp->ModelDescription,
-			sizeof(atp->ModelDescription));
-	if (strtok_r(buf, " ", &saveptr))
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
-				buf, strnlen(buf, sizeof(buf)));
-	else
-		sa_strncpy_safe(atp->Model, sizeof(atp->Model),
-				atp->ModelDescription,
-				sizeof(atp->ModelDescription));
-
-	/* Get HardwareVersion */
-	sa_strncpy_safe(atp->HardwareVersion, sizeof(atp->HardwareVersion),
-			hba_info.HardwareVersion,
-			sizeof(hba_info.HardwareVersion));
-
-	/* Get OptionROMVersion (TODO) */
-	sa_strncpy_safe(atp->OptionROMVersion, sizeof(atp->OptionROMVersion),
-			HBA_ROM_VERSION, sizeof(HBA_ROM_VERSION));
-
-	/* Get FirmwareVersion (TODO) */
-	sa_strncpy_safe(atp->FirmwareVersion, sizeof(atp->FirmwareVersion),
-			HBA_FW_VERSION, sizeof(HBA_FW_VERSION));
-
-	/* Get VendorSpecificID (TODO) */
-	atp->VendorSpecificID = HBA_VENDOR_SPECIFIC_ID;
-
-	/* Get DriverVersion */
-	rc = sa_sys_read_line(hba_dir, SYSFS_MODULE_VER,
-			atp->DriverVersion, sizeof(atp->DriverVersion));
+	sysfs_scan_pci(syspath, &hba_info, atp);
 
 	/* Get NodeSymbolicName */
 	sa_strncpy_safe(atp->NodeSymbolicName, sizeof(atp->NodeSymbolicName),