Blame SOURCES/mdadm-3.3.2-imsm-detail-platform-improvements.patch

2ddfcf
From 0858eccf86e9b3611d711717ec65a042f5c7ff9f Mon Sep 17 00:00:00 2001
2ddfcf
From: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
2ddfcf
Date: Wed, 19 Nov 2014 13:53:29 +0100
2ddfcf
Subject: [PATCH] imsm: detail-platform improvements
2ddfcf
2ddfcf
Print platform details per OROM, not per controller, differentiate
2ddfcf
RST(e) platforms from legacy IMSM, print NVMe device paths, adjust port
2ddfcf
printing to newer sysfs path.
2ddfcf
2ddfcf
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
2ddfcf
Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
2ddfcf
Signed-off-by: NeilBrown <neilb@suse.de>
2ddfcf
---
2ddfcf
 platform-intel.c | 26 ++++++++++------
2ddfcf
 platform-intel.h | 23 ++++++++++++++
2ddfcf
 super-intel.c    | 93 ++++++++++++++++++++++++++++++++++++++------------------
2ddfcf
 3 files changed, 103 insertions(+), 39 deletions(-)
2ddfcf
2ddfcf
diff --git a/platform-intel.c b/platform-intel.c
2ddfcf
index ae72827..54ef37f 100644
2ddfcf
--- a/platform-intel.c
2ddfcf
+++ b/platform-intel.c
2ddfcf
@@ -134,6 +134,16 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
2ddfcf
 static struct sys_dev *intel_devices=NULL;
2ddfcf
 static time_t valid_time = 0;
2ddfcf
 
2ddfcf
+struct sys_dev *device_by_id(__u16 device_id)
2ddfcf
+{
2ddfcf
+	struct sys_dev *iter;
2ddfcf
+
2ddfcf
+	for (iter = intel_devices; iter != NULL; iter = iter->next)
2ddfcf
+		if (iter->dev_id == device_id)
2ddfcf
+			return iter;
2ddfcf
+	return NULL;
2ddfcf
+}
2ddfcf
+
2ddfcf
 static int devpath_to_ll(const char *dev_path, const char *entry, unsigned long long *val)
2ddfcf
 {
2ddfcf
 	char path[strlen(dev_path) + strlen(entry) + 2];
2ddfcf
@@ -219,18 +229,13 @@ struct pciExpDataStructFormat {
2ddfcf
 	__u16 devListOffset;
2ddfcf
 } __attribute__ ((packed));
2ddfcf
 
2ddfcf
-struct devid_list {
2ddfcf
-	__u16 devid;
2ddfcf
-	struct devid_list *next;
2ddfcf
-};
2ddfcf
-
2ddfcf
-struct orom_entry {
2ddfcf
-	struct imsm_orom orom;
2ddfcf
-	struct devid_list *devid_list;
2ddfcf
-};
2ddfcf
-
2ddfcf
 static struct orom_entry oroms[SYS_DEV_MAX];
2ddfcf
 
2ddfcf
+const struct orom_entry *get_oroms(void)
2ddfcf
+{
2ddfcf
+	return (const struct orom_entry *)&orom;;
2ddfcf
+}
2ddfcf
+
2ddfcf
 const struct imsm_orom *get_orom_by_device_id(__u16 dev_id)
2ddfcf
 {
2ddfcf
 	int i;
2ddfcf
@@ -529,6 +534,7 @@ const struct imsm_orom *find_imsm_nvme(struct sys_dev *hba)
2ddfcf
 			.vpa = IMSM_OROM_VOLUMES_PER_ARRAY,
2ddfcf
 			.vphba = IMSM_OROM_TOTAL_DISKS_NVME / 2 * IMSM_OROM_VOLUMES_PER_ARRAY,
2ddfcf
 			.attr = IMSM_OROM_ATTR_2TB | IMSM_OROM_ATTR_2TB_DISK,
2ddfcf
+			.driver_features = IMSM_OROM_CAPABILITIES_EnterpriseSystem
2ddfcf
 		};
2ddfcf
 		nvme_orom = add_orom(&nvme_orom_compat);
2ddfcf
 	}
2ddfcf
diff --git a/platform-intel.h b/platform-intel.h
2ddfcf
index 6b4ebd8..3e85d44 100644
2ddfcf
--- a/platform-intel.h
2ddfcf
+++ b/platform-intel.h
2ddfcf
@@ -173,6 +173,17 @@ static inline int fls(int x)
2ddfcf
 	return r;
2ddfcf
 }
2ddfcf
 
2ddfcf
+static inline int imsm_orom_is_enterprise(const struct imsm_orom *orom)
2ddfcf
+{
2ddfcf
+	return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_EnterpriseSystem);
2ddfcf
+}
2ddfcf
+
2ddfcf
+static inline int imsm_orom_is_nvme(const struct imsm_orom *orom)
2ddfcf
+{
2ddfcf
+	return memcmp(orom->signature, IMSM_NVME_OROM_COMPAT_SIGNATURE,
2ddfcf
+			sizeof(orom->signature)) == 0;
2ddfcf
+}
2ddfcf
+
2ddfcf
 enum sys_dev_type {
2ddfcf
 	SYS_DEV_UNKNOWN = 0,
2ddfcf
 	SYS_DEV_SAS,
2ddfcf
@@ -194,6 +205,16 @@ struct efi_guid {
2ddfcf
 	__u8 b[16];
2ddfcf
 };
2ddfcf
 
2ddfcf
+struct devid_list {
2ddfcf
+	__u16 devid;
2ddfcf
+	struct devid_list *next;
2ddfcf
+};
2ddfcf
+
2ddfcf
+struct orom_entry {
2ddfcf
+	struct imsm_orom orom;
2ddfcf
+	struct devid_list *devid_list;
2ddfcf
+};
2ddfcf
+
2ddfcf
 static inline char *guid_str(char *buf, struct efi_guid guid)
2ddfcf
 {
2ddfcf
 	sprintf(buf, "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
2ddfcf
@@ -215,4 +236,6 @@ int devt_attached_to_hba(dev_t dev, const char *hba_path);
2ddfcf
 char *devt_to_devpath(dev_t dev);
2ddfcf
 int path_attached_to_hba(const char *disk_path, const char *hba_path);
2ddfcf
 const char *get_sys_dev_type(enum sys_dev_type);
2ddfcf
+const struct orom_entry * get_oroms(void);
2ddfcf
 const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
2ddfcf
+struct sys_dev *device_by_id(__u16 device_id);
2ddfcf
diff --git a/super-intel.c b/super-intel.c
2ddfcf
index d2ee1c6..4c53019 100644
2ddfcf
--- a/super-intel.c
2ddfcf
+++ b/super-intel.c
2ddfcf
@@ -1709,7 +1709,8 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b
2ddfcf
 			break;
2ddfcf
 		}
2ddfcf
 		*c = '\0';
2ddfcf
-		if (sscanf(&path[hba_len], "host%d", &port) == 1)
2ddfcf
+		if ((sscanf(&path[hba_len], "ata%d", &port) == 1) ||
2ddfcf
+		   ((sscanf(&path[hba_len], "host%d", &port) == 1)))
2ddfcf
 			port -= host_base;
2ddfcf
 		else {
2ddfcf
 			if (verbose > 0) {
2ddfcf
@@ -1768,6 +1769,8 @@ static void print_found_intel_controllers(struct sys_dev *elem)
2ddfcf
 			fprintf(stderr, "SATA ");
2ddfcf
 		else if (elem->type == SYS_DEV_SAS)
2ddfcf
 			fprintf(stderr, "SAS ");
2ddfcf
+		else if (elem->type == SYS_DEV_NVME)
2ddfcf
+			fprintf(stderr, "NVMe ");
2ddfcf
 		fprintf(stderr, "RAID controller");
2ddfcf
 		if (elem->pci_id)
2ddfcf
 			fprintf(stderr, " at %s", elem->pci_id);
2ddfcf
@@ -1789,7 +1792,8 @@ static int ahci_get_port_count(const char *hba_path, int *port_count)
2ddfcf
 	for (ent = readdir(dir); ent; ent = readdir(dir)) {
2ddfcf
 		int host;
2ddfcf
 
2ddfcf
-		if (sscanf(ent->d_name, "host%d", &host) != 1)
2ddfcf
+		if ((sscanf(ent->d_name, "ata%d", &host) != 1) &&
2ddfcf
+		   ((sscanf(ent->d_name, "host%d", &host) != 1)))
2ddfcf
 			continue;
2ddfcf
 		if (*port_count == 0)
2ddfcf
 			host_base = host;
2ddfcf
@@ -1805,9 +1809,15 @@ static int ahci_get_port_count(const char *hba_path, int *port_count)
2ddfcf
 
2ddfcf
 static void print_imsm_capability(const struct imsm_orom *orom)
2ddfcf
 {
2ddfcf
-	printf("       Platform : Intel(R) Matrix Storage Manager\n");
2ddfcf
-	printf("        Version : %d.%d.%d.%d\n", orom->major_ver, orom->minor_ver,
2ddfcf
-	       orom->hotfix_ver, orom->build);
2ddfcf
+	printf("       Platform : Intel(R) ");
2ddfcf
+	if (orom->capabilities == 0 && orom->driver_features == 0)
2ddfcf
+		printf("Matrix Storage Manager\n");
2ddfcf
+	else
2ddfcf
+		printf("Rapid Storage Technology%s\n",
2ddfcf
+			imsm_orom_is_enterprise(orom) ? " enterprise" : "");
2ddfcf
+	if (orom->major_ver || orom->minor_ver || orom->hotfix_ver || orom->build)
2ddfcf
+		printf("        Version : %d.%d.%d.%d\n", orom->major_ver,
2ddfcf
+				orom->minor_ver, orom->hotfix_ver, orom->build);
2ddfcf
 	printf("    RAID Levels :%s%s%s%s%s\n",
2ddfcf
 	       imsm_orom_has_raid0(orom) ? " raid0" : "",
2ddfcf
 	       imsm_orom_has_raid1(orom) ? " raid1" : "",
2ddfcf
@@ -1836,16 +1846,18 @@ static void print_imsm_capability(const struct imsm_orom *orom)
2ddfcf
 	printf("      2TB disks :%s supported\n",
2ddfcf
 	       (orom->attr & IMSM_OROM_ATTR_2TB_DISK)?"":" not");
2ddfcf
 	printf("      Max Disks : %d\n", orom->tds);
2ddfcf
-	printf("    Max Volumes : %d per array, %d per controller\n",
2ddfcf
-	       orom->vpa, orom->vphba);
2ddfcf
+	printf("    Max Volumes : %d per array, %d per %s\n",
2ddfcf
+	       orom->vpa, orom->vphba,
2ddfcf
+	       imsm_orom_is_nvme(orom) ? "platform" : "controller");
2ddfcf
 	return;
2ddfcf
 }
2ddfcf
 
2ddfcf
 static void print_imsm_capability_export(const struct imsm_orom *orom)
2ddfcf
 {
2ddfcf
 	printf("MD_FIRMWARE_TYPE=imsm\n");
2ddfcf
-	printf("IMSM_VERSION=%d.%d.%d.%d\n",orom->major_ver, orom->minor_ver,
2ddfcf
-			orom->hotfix_ver, orom->build);
2ddfcf
+	if (orom->major_ver || orom->minor_ver || orom->hotfix_ver || orom->build)
2ddfcf
+		printf("IMSM_VERSION=%d.%d.%d.%d\n", orom->major_ver, orom->minor_ver,
2ddfcf
+				orom->hotfix_ver, orom->build);
2ddfcf
 	printf("IMSM_SUPPORTED_RAID_LEVELS=%s%s%s%s%s\n",
2ddfcf
 			imsm_orom_has_raid0(orom) ? "raid0 " : "",
2ddfcf
 			imsm_orom_has_raid1(orom) ? "raid1 " : "",
2ddfcf
@@ -1889,7 +1901,6 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
2ddfcf
 	 * platform capabilities.  If raid support is disabled in the BIOS the
2ddfcf
 	 * option-rom capability structure will not be available.
2ddfcf
 	 */
2ddfcf
-	const struct imsm_orom *orom;
2ddfcf
 	struct sys_dev *list, *hba;
2ddfcf
 	int host_base = 0;
2ddfcf
 	int port_count = 0;
2ddfcf
@@ -1922,15 +1933,42 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
2ddfcf
 		print_found_intel_controllers(list);
2ddfcf
 
2ddfcf
 	for (hba = list; hba; hba = hba->next) {
2ddfcf
-		if (controller_path && (compare_paths(hba->path,controller_path) != 0))
2ddfcf
+		if (controller_path && (compare_paths(hba->path, controller_path) != 0))
2ddfcf
 			continue;
2ddfcf
-		orom = find_imsm_capability(hba);
2ddfcf
-		if (!orom)
2ddfcf
+		if (!find_imsm_capability(hba)) {
2ddfcf
 			pr_err("imsm capabilities not found for controller: %s (type %s)\n",
2ddfcf
 				hba->path, get_sys_dev_type(hba->type));
2ddfcf
-		else {
2ddfcf
-			result = 0;
2ddfcf
-			print_imsm_capability(orom);
2ddfcf
+			continue;
2ddfcf
+		}
2ddfcf
+		result = 0;
2ddfcf
+	}
2ddfcf
+
2ddfcf
+	if (controller_path && result == 1) {
2ddfcf
+		pr_err("no active Intel(R) RAID controller found under %s\n",
2ddfcf
+				controller_path);
2ddfcf
+		return result;
2ddfcf
+	}
2ddfcf
+
2ddfcf
+	const struct orom_entry *oroms = get_oroms();
2ddfcf
+	int i;
2ddfcf
+
2ddfcf
+	for (i = 0; i < SYS_DEV_MAX && oroms[i].devid_list; i++) {
2ddfcf
+		print_imsm_capability(&oroms[i].orom);
2ddfcf
+
2ddfcf
+		if (imsm_orom_is_nvme(&oroms[i].orom)) {
2ddfcf
+			for (hba = list; hba; hba = hba->next) {
2ddfcf
+				if (hba->type == SYS_DEV_NVME)
2ddfcf
+					printf("    NVMe Device : %s\n", hba->path);
2ddfcf
+			}
2ddfcf
+			continue;
2ddfcf
+		}
2ddfcf
+
2ddfcf
+		struct devid_list *devid;
2ddfcf
+		for (devid = oroms[i].devid_list; devid; devid = devid->next) {
2ddfcf
+			hba = device_by_id(devid->devid);
2ddfcf
+			if (!hba)
2ddfcf
+				continue;
2ddfcf
+
2ddfcf
 			printf(" I/O Controller : %s (%s)\n",
2ddfcf
 				hba->path, get_sys_dev_type(hba->type));
2ddfcf
 			if (hba->type == SYS_DEV_SATA) {
2ddfcf
@@ -1943,18 +1981,14 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
2ddfcf
 				}
2ddfcf
 			}
2ddfcf
 		}
2ddfcf
+		printf("\n");
2ddfcf
 	}
2ddfcf
 
2ddfcf
-	if (controller_path && result == 1)
2ddfcf
-		pr_err("no active Intel(R) RAID "
2ddfcf
-				"controller found under %s\n",controller_path);
2ddfcf
-
2ddfcf
 	return result;
2ddfcf
 }
2ddfcf
 
2ddfcf
 static int export_detail_platform_imsm(int verbose, char *controller_path)
2ddfcf
 {
2ddfcf
-	const struct imsm_orom *orom;
2ddfcf
 	struct sys_dev *list, *hba;
2ddfcf
 	int result=1;
2ddfcf
 
2ddfcf
@@ -1969,17 +2003,18 @@ static int export_detail_platform_imsm(int verbose, char *controller_path)
2ddfcf
 	for (hba = list; hba; hba = hba->next) {
2ddfcf
 		if (controller_path && (compare_paths(hba->path,controller_path) != 0))
2ddfcf
 			continue;
2ddfcf
-		orom = find_imsm_capability(hba);
2ddfcf
-		if (!orom) {
2ddfcf
-			if (verbose > 0)
2ddfcf
-				pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n",hba->path);
2ddfcf
-		}
2ddfcf
-		else {
2ddfcf
-			print_imsm_capability_export(orom);
2ddfcf
+		if (!find_imsm_capability(hba) && verbose > 0)
2ddfcf
+			pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_IMSM_CAPABLE_DEVICE_UNDER_%s\n", hba->path);
2ddfcf
+		else
2ddfcf
 			result = 0;
2ddfcf
-		}
2ddfcf
 	}
2ddfcf
 
2ddfcf
+	const struct orom_entry *oroms = get_oroms();
2ddfcf
+	int i;
2ddfcf
+
2ddfcf
+	for (i = 0; i < SYS_DEV_MAX && oroms[i].devid_list; i++)
2ddfcf
+		print_imsm_capability_export(&oroms[i].orom);
2ddfcf
+
2ddfcf
 	return result;
2ddfcf
 }
2ddfcf
 
2ddfcf
-- 
2ddfcf
2.4.3
2ddfcf