Blame SOURCES/mdadm-3.3.2-imsm-add-support-for-NVMe-devices.patch

2ddfcf
From 614902f64e856b4cffc26687fac74412c4a6d91c Mon Sep 17 00:00:00 2001
2ddfcf
From: Pawel Baldysiak <pawel.baldysiak@intel.com>
2ddfcf
Date: Wed, 19 Nov 2014 13:53:28 +0100
2ddfcf
Subject: [PATCH] imsm: add support for NVMe devices
2ddfcf
2ddfcf
Recognize Intel(R) NVMe devices as IMSM-capable.
2ddfcf
2ddfcf
Signed-off-by: Pawel Baldysiak <pawel.baldysiak@intel.com>
2ddfcf
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
2ddfcf
Signed-off-by: NeilBrown <neilb@suse.de>
2ddfcf
---
2ddfcf
 platform-intel.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
2ddfcf
 platform-intel.h |  5 +++++
2ddfcf
 super-intel.c    | 11 +++++++----
2ddfcf
 3 files changed, 56 insertions(+), 6 deletions(-)
2ddfcf
2ddfcf
diff --git a/platform-intel.c b/platform-intel.c
2ddfcf
index c5a0aa4..ae72827 100644
2ddfcf
--- a/platform-intel.c
2ddfcf
+++ b/platform-intel.c
2ddfcf
@@ -65,6 +65,8 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
2ddfcf
 		type = SYS_DEV_SAS;
2ddfcf
 	else if (strcmp(driver, "ahci") == 0)
2ddfcf
 		type = SYS_DEV_SATA;
2ddfcf
+	else if (strcmp(driver, "nvme") == 0)
2ddfcf
+		type = SYS_DEV_NVME;
2ddfcf
 	else
2ddfcf
 		type = SYS_DEV_UNKNOWN;
2ddfcf
 
2ddfcf
@@ -174,7 +176,7 @@ static __u16 devpath_to_vendor(const char *dev_path)
2ddfcf
 
2ddfcf
 struct sys_dev *find_intel_devices(void)
2ddfcf
 {
2ddfcf
-	struct sys_dev *ahci, *isci;
2ddfcf
+	struct sys_dev *ahci, *isci, *nvme;
2ddfcf
 
2ddfcf
 	if (valid_time > time(0) - 10)
2ddfcf
 		return intel_devices;
2ddfcf
@@ -184,14 +186,24 @@ struct sys_dev *find_intel_devices(void)
2ddfcf
 
2ddfcf
 	isci = find_driver_devices("pci", "isci");
2ddfcf
 	ahci = find_driver_devices("pci", "ahci");
2ddfcf
+	nvme = find_driver_devices("pci", "nvme");
2ddfcf
 
2ddfcf
-	if (!ahci) {
2ddfcf
+	if (!isci && !ahci) {
2ddfcf
+		ahci = nvme;
2ddfcf
+	} else if (!ahci) {
2ddfcf
 		ahci = isci;
2ddfcf
+		struct sys_dev *elem = ahci;
2ddfcf
+		while (elem->next)
2ddfcf
+			elem = elem->next;
2ddfcf
+		elem->next = nvme;
2ddfcf
 	} else {
2ddfcf
 		struct sys_dev *elem = ahci;
2ddfcf
 		while (elem->next)
2ddfcf
 			elem = elem->next;
2ddfcf
 		elem->next = isci;
2ddfcf
+		while (elem->next)
2ddfcf
+			elem = elem->next;
2ddfcf
+		elem->next = nvme;
2ddfcf
 	}
2ddfcf
 	intel_devices = ahci;
2ddfcf
 	valid_time = time(0);
2ddfcf
@@ -497,6 +509,33 @@ const struct imsm_orom *find_imsm_efi(struct sys_dev *hba)
2ddfcf
 	return ret;
2ddfcf
 }
2ddfcf
 
2ddfcf
+const struct imsm_orom *find_imsm_nvme(struct sys_dev *hba)
2ddfcf
+{
2ddfcf
+	static const struct imsm_orom *nvme_orom;
2ddfcf
+
2ddfcf
+	if (hba->type != SYS_DEV_NVME)
2ddfcf
+		return NULL;
2ddfcf
+
2ddfcf
+	if (!nvme_orom) {
2ddfcf
+		struct imsm_orom nvme_orom_compat = {
2ddfcf
+			.signature = IMSM_NVME_OROM_COMPAT_SIGNATURE,
2ddfcf
+			.rlc = IMSM_OROM_RLC_RAID0 | IMSM_OROM_RLC_RAID1 |
2ddfcf
+						IMSM_OROM_RLC_RAID10 | IMSM_OROM_RLC_RAID5,
2ddfcf
+			.sss = IMSM_OROM_SSS_4kB | IMSM_OROM_SSS_8kB |
2ddfcf
+						IMSM_OROM_SSS_16kB | IMSM_OROM_SSS_32kB |
2ddfcf
+						IMSM_OROM_SSS_64kB | IMSM_OROM_SSS_128kB,
2ddfcf
+			.dpa = IMSM_OROM_DISKS_PER_ARRAY_NVME,
2ddfcf
+			.tds = IMSM_OROM_TOTAL_DISKS_NVME,
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
+		};
2ddfcf
+		nvme_orom = add_orom(&nvme_orom_compat);
2ddfcf
+	}
2ddfcf
+	add_orom_device_id(nvme_orom, hba->dev_id);
2ddfcf
+	return nvme_orom;
2ddfcf
+}
2ddfcf
+
2ddfcf
 const struct imsm_orom *find_imsm_capability(struct sys_dev *hba)
2ddfcf
 {
2ddfcf
 	const struct imsm_orom *cap = get_orom_by_device_id(hba->dev_id);
2ddfcf
@@ -504,10 +543,13 @@ const struct imsm_orom *find_imsm_capability(struct sys_dev *hba)
2ddfcf
 	if (cap)
2ddfcf
 		return cap;
2ddfcf
 
2ddfcf
+	if (hba->type == SYS_DEV_NVME)
2ddfcf
+		return find_imsm_nvme(hba);
2ddfcf
 	if ((cap = find_imsm_efi(hba)) != NULL)
2ddfcf
 		return cap;
2ddfcf
 	if ((cap = find_imsm_hba_orom(hba)) != NULL)
2ddfcf
 		return cap;
2ddfcf
+
2ddfcf
 	return NULL;
2ddfcf
 }
2ddfcf
 
2ddfcf
diff --git a/platform-intel.h b/platform-intel.h
2ddfcf
index e41f386..6b4ebd8 100644
2ddfcf
--- a/platform-intel.h
2ddfcf
+++ b/platform-intel.h
2ddfcf
@@ -23,6 +23,7 @@
2ddfcf
 struct imsm_orom {
2ddfcf
 	__u8 signature[4];
2ddfcf
 	#define IMSM_OROM_SIGNATURE "$VER"
2ddfcf
+	#define IMSM_NVME_OROM_COMPAT_SIGNATURE "$NVM"
2ddfcf
 	__u8 table_ver_major; /* Currently 2 (can change with future revs) */
2ddfcf
 	__u8 table_ver_minor; /* Currently 2 (can change with future revs) */
2ddfcf
 	__u16 major_ver; /* Example: 8 as in 8.6.0.1020 */
2ddfcf
@@ -60,12 +61,15 @@ struct imsm_orom {
2ddfcf
 	#define IMSM_OROM_SSS_64MB (1 << 15)
2ddfcf
 	__u16 dpa; /* Disks Per Array supported */
2ddfcf
 	#define IMSM_OROM_DISKS_PER_ARRAY 6
2ddfcf
+	#define IMSM_OROM_DISKS_PER_ARRAY_NVME 12
2ddfcf
 	__u16 tds; /* Total Disks Supported */
2ddfcf
 	#define IMSM_OROM_TOTAL_DISKS 6
2ddfcf
+	#define IMSM_OROM_TOTAL_DISKS_NVME 12
2ddfcf
 	__u8 vpa; /* # Volumes Per Array supported */
2ddfcf
 	#define IMSM_OROM_VOLUMES_PER_ARRAY 2
2ddfcf
 	__u8 vphba; /* # Volumes Per Host Bus Adapter supported */
2ddfcf
 	#define IMSM_OROM_VOLUMES_PER_HBA 4
2ddfcf
+	#define IMSM_OROM_VOLUMES_PER_HBA_NVME 4
2ddfcf
 	/* Attributes supported. This should map to the
2ddfcf
 	 * attributes in the MPB. Also, lower 16 bits
2ddfcf
 	 * should match/duplicate RLC bits above.
2ddfcf
@@ -173,6 +177,7 @@ enum sys_dev_type {
2ddfcf
 	SYS_DEV_UNKNOWN = 0,
2ddfcf
 	SYS_DEV_SAS,
2ddfcf
 	SYS_DEV_SATA,
2ddfcf
+	SYS_DEV_NVME,
2ddfcf
 	SYS_DEV_MAX
2ddfcf
 };
2ddfcf
 
2ddfcf
diff --git a/super-intel.c b/super-intel.c
2ddfcf
index dabf011..d2ee1c6 100644
2ddfcf
--- a/super-intel.c
2ddfcf
+++ b/super-intel.c
2ddfcf
@@ -509,7 +509,8 @@ struct imsm_update_add_remove_disk {
2ddfcf
 static const char *_sys_dev_type[] = {
2ddfcf
 	[SYS_DEV_UNKNOWN] = "Unknown",
2ddfcf
 	[SYS_DEV_SAS] = "SAS",
2ddfcf
-	[SYS_DEV_SATA] = "SATA"
2ddfcf
+	[SYS_DEV_SATA] = "SATA",
2ddfcf
+	[SYS_DEV_NVME] = "NVMe"
2ddfcf
 };
2ddfcf
 
2ddfcf
 const char *get_sys_dev_type(enum sys_dev_type type)
2ddfcf
@@ -559,7 +560,7 @@ static int attach_hba_to_super(struct intel_super *super, struct sys_dev *device
2ddfcf
 
2ddfcf
 	hba = super->hba;
2ddfcf
 	/* Intel metadata allows for all disks attached to the same type HBA.
2ddfcf
-	 * Do not sypport odf HBA types mixing
2ddfcf
+	 * Do not support HBA types mixing
2ddfcf
 	 */
2ddfcf
 	if (device->type != hba->type)
2ddfcf
 		return 2;
2ddfcf
@@ -3841,9 +3842,9 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de
2ddfcf
 				"    but the container is assigned to Intel(R) "
2ddfcf
 				"%s RAID controller (",
2ddfcf
 				devname,
2ddfcf
-				hba_name->path,
2ddfcf
+				get_sys_dev_type(hba_name->type),
2ddfcf
 				hba_name->pci_id ? : "Err!",
2ddfcf
-				get_sys_dev_type(hba_name->type));
2ddfcf
+				get_sys_dev_type(super->hba->type));
2ddfcf
 
2ddfcf
 			while (hba) {
2ddfcf
 				fprintf(stderr, "%s", hba->pci_id ? : "Err!");
2ddfcf
@@ -3860,6 +3861,7 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de
2ddfcf
 	super->orom = find_imsm_capability(hba_name);
2ddfcf
 	if (!super->orom)
2ddfcf
 		return 3;
2ddfcf
+
2ddfcf
 	return 0;
2ddfcf
 }
2ddfcf
 
2ddfcf
@@ -5916,6 +5918,7 @@ validate_geometry_imsm_orom(struct intel_super *super, int level, int layout,
2ddfcf
 		pr_vrb(": platform does not support a volume size over 2TB\n");
2ddfcf
 		return 0;
2ddfcf
 	}
2ddfcf
+
2ddfcf
 	return 1;
2ddfcf
 }
2ddfcf
 
2ddfcf
-- 
2ddfcf
2.4.3
2ddfcf