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