2 * Intel(R) Matrix Storage Manager hardware and firmware support routines
4 * Copyright (C) 2008 Intel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <asm/types.h>
22 /* according to GUID format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
23 #define GUID_STR_MAX 37
25 /* The IMSM Capability (IMSM AHCI and ISCU OROM/EFI variable) Version Table definition */
27 __u8 signature
[4] __attribute__((nonstring
));
28 #define IMSM_OROM_SIGNATURE "$VER"
29 #define IMSM_NVME_OROM_COMPAT_SIGNATURE "$NVM"
30 #define IMSM_VMD_OROM_COMPAT_SIGNATURE "$VMD"
31 __u8 table_ver_major
; /* Currently 2 (can change with future revs) */
32 __u8 table_ver_minor
; /* Currently 2 (can change with future revs) */
33 __u16 major_ver
; /* Example: 8 as in 8.6.0.1020 */
34 __u16 minor_ver
; /* Example: 6 as in 8.6.0.1020 */
35 __u16 hotfix_ver
; /* Example: 0 as in 8.6.0.1020 */
36 __u16 build
; /* Example: 1020 as in 8.6.0.1020 */
37 __u8 len
; /* number of bytes in this entire table */
38 __u8 checksum
; /* checksum of all the bytes in this table */
39 __u16 rlc
; /* RAID Level Capability */
40 /* we assume the cpu is x86 as the orom should not be found
43 #define IMSM_OROM_RLC_RAID0 (1 << 0)
44 #define IMSM_OROM_RLC_RAID1 (1 << 1)
45 #define IMSM_OROM_RLC_RAID10 (1 << 2)
46 #define IMSM_OROM_RLC_RAID1E (1 << 3)
47 #define IMSM_OROM_RLC_RAID5 (1 << 4)
48 #define IMSM_OROM_RLC_RAID_CNG (1 << 5)
49 __u16 sss
; /* Strip Size Supported */
50 #define IMSM_OROM_SSS_2kB (1 << 0)
51 #define IMSM_OROM_SSS_4kB (1 << 1)
52 #define IMSM_OROM_SSS_8kB (1 << 2)
53 #define IMSM_OROM_SSS_16kB (1 << 3)
54 #define IMSM_OROM_SSS_32kB (1 << 4)
55 #define IMSM_OROM_SSS_64kB (1 << 5)
56 #define IMSM_OROM_SSS_128kB (1 << 6)
57 #define IMSM_OROM_SSS_256kB (1 << 7)
58 #define IMSM_OROM_SSS_512kB (1 << 8)
59 #define IMSM_OROM_SSS_1MB (1 << 9)
60 #define IMSM_OROM_SSS_2MB (1 << 10)
61 #define IMSM_OROM_SSS_4MB (1 << 11)
62 #define IMSM_OROM_SSS_8MB (1 << 12)
63 #define IMSM_OROM_SSS_16MB (1 << 13)
64 #define IMSM_OROM_SSS_32MB (1 << 14)
65 #define IMSM_OROM_SSS_64MB (1 << 15)
66 __u16 dpa
; /* Disks Per Array supported */
67 #define IMSM_OROM_DISKS_PER_ARRAY 6
68 #define IMSM_OROM_DISKS_PER_ARRAY_NVME 12
69 __u16 tds
; /* Total Disks Supported */
70 #define IMSM_OROM_TOTAL_DISKS 6
71 #define IMSM_OROM_TOTAL_DISKS_NVME 12
72 #define IMSM_OROM_TOTAL_DISKS_VMD 48
73 __u8 vpa
; /* # Volumes Per Array supported */
74 #define IMSM_OROM_VOLUMES_PER_ARRAY 2
75 __u8 vphba
; /* # Volumes Per Host Bus Adapter supported */
76 #define IMSM_OROM_VOLUMES_PER_HBA 4
77 #define IMSM_OROM_VOLUMES_PER_HBA_NVME 4
78 #define IMSM_OROM_VOLUMES_PER_HBA_VMD 24
79 /* Attributes supported. This should map to the
80 * attributes in the MPB. Also, lower 16 bits
81 * should match/duplicate RLC bits above.
84 #define IMSM_OROM_ATTR_RAID0 IMSM_OROM_RLC_RAID0
85 #define IMSM_OROM_ATTR_RAID1 IMSM_OROM_RLC_RAID1
86 #define IMSM_OROM_ATTR_RAID10 IMSM_OROM_RLC_RAID10
87 #define IMSM_OROM_ATTR_RAID1E IMSM_OROM_RLC_RAID1E
88 #define IMSM_OROM_ATTR_RAID5 IMSM_OROM_RLC_RAID5
89 #define IMSM_OROM_ATTR_RAID_CNG IMSM_OROM_RLC_RAID_CNG
90 #define IMSM_OROM_ATTR_2TB_DISK (1 << 26)
91 #define IMSM_OROM_ATTR_2TB (1 << 29)
92 #define IMSM_OROM_ATTR_PM (1 << 30)
93 #define IMSM_OROM_ATTR_ChecksumVerify (1 << 31)
95 #define IMSM_OROM_CAPABILITIES_Ext_SATA (1 << 0)
96 #define IMSM_OROM_CAPABILITIES_TurboMemory (1 << 1)
97 #define IMSM_OROM_CAPABILITIES_HddPassword (1 << 2)
98 #define IMSM_OROM_CAPABILITIES_DiskCoercion (1 << 3)
99 __u32 driver_features
;
100 #define IMSM_OROM_CAPABILITIES_HDDUnlock (1 << 0)
101 #define IMSM_OROM_CAPABILITIES_LEDLoc (1 << 1)
102 #define IMSM_OROM_CAPABILITIES_EnterpriseSystem (1 << 2)
103 #define IMSM_OROM_CAPABILITIES_Zpodd (1 << 3)
104 #define IMSM_OROM_CAPABILITIES_LargeDramCache (1 << 4)
105 #define IMSM_OROM_CAPABILITIES_Rohi (1 << 5)
106 #define IMSM_OROM_CAPABILITIES_ReadPatrol (1 << 6)
107 #define IMSM_OROM_CAPABILITIES_XorHw (1 << 7)
108 #define IMSM_OROM_CAPABILITIES_SKUMode ((1 << 8)|(1 << 9))
109 #define IMSM_OROM_CAPABILITIES_SKUMode_LOW ((1 << 8) | (1 << 9))
110 #define IMSM_OROM_CAPABILITIES_SKUMode_LOW_SHIFT 8
111 #define IMSM_OROM_CAPABILITIES_TPV (1 << 10)
112 #define IMSM_OROM_CAPABILITIES_SKUMode_HIGH ((1 << 11) | (1 << 12))
113 #define IMSM_OROM_CAPABILITIES_SKUMode_HIGH_SHIFT 9
114 #define IMSM_OROM_CAPABILITIES_SKUMode_NON_PRODUCTION (1 << 13)
115 } __attribute__((packed
));
117 /* IMSM metadata requirements for each level */
118 struct imsm_level_ops
{
120 bool (*is_level_supported
)(const struct imsm_orom
*);
121 bool (*is_raiddisks_count_supported
)(const int);
125 extern struct imsm_level_ops imsm_level_ops
[];
127 static inline bool imsm_rlc_has_bit(const struct imsm_orom
*orom
, const unsigned short bit
)
135 * imsm_orom_has_chunk - check if the orom supports the given chunk size
136 * @orom: orom pointer from find_imsm_orom
137 * @chunk: chunk size in kibibytes
139 static inline int imsm_orom_has_chunk(const struct imsm_orom
*orom
, int chunk
)
144 fs
--; /* bit num to bit index */
145 if (chunk
& (chunk
-1))
146 return 0; /* not a power of 2 */
147 return !!(orom
->sss
& (1 << (fs
- 1)));
151 * fls - find last (most-significant) bit set
152 * @x: the word to search
153 * The funciton is borrowed from Linux kernel code
154 * include/asm-generic/bitops/fls.h
156 static inline int fls(int x
)
162 if (!(x
& 0xffff0000u
)) {
166 if (!(x
& 0xff000000u
)) {
170 if (!(x
& 0xf0000000u
)) {
174 if (!(x
& 0xc0000000u
)) {
178 if (!(x
& 0x80000000u
)) {
184 static inline int imsm_orom_is_enterprise(const struct imsm_orom
*orom
)
186 return !!(orom
->driver_features
& IMSM_OROM_CAPABILITIES_EnterpriseSystem
);
189 static inline int imsm_orom_is_nvme(const struct imsm_orom
*orom
)
191 return memcmp(orom
->signature
, IMSM_NVME_OROM_COMPAT_SIGNATURE
,
192 sizeof(orom
->signature
)) == 0;
195 static inline int imsm_orom_is_vmd_without_efi(const struct imsm_orom
*orom
)
197 return memcmp(orom
->signature
, IMSM_VMD_OROM_COMPAT_SIGNATURE
,
198 sizeof(orom
->signature
)) == 0;
201 static inline int imsm_orom_has_tpv_support(const struct imsm_orom
*orom
)
203 return !!(orom
->driver_features
& IMSM_OROM_CAPABILITIES_TPV
);
217 enum sys_dev_type type
;
222 struct sys_dev
*next
;
231 struct devid_list
*next
;
235 struct imsm_orom orom
;
236 struct devid_list
*devid_list
;
237 enum sys_dev_type type
;
238 struct orom_entry
*next
;
241 extern struct orom_entry
*orom_entries
;
243 static inline char *guid_str(char *buf
, struct efi_guid guid
)
245 snprintf(buf
, GUID_STR_MAX
, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
246 guid
.b
[3], guid
.b
[2], guid
.b
[1], guid
.b
[0],
247 guid
.b
[5], guid
.b
[4], guid
.b
[7], guid
.b
[6],
248 guid
.b
[8], guid
.b
[9], guid
.b
[10], guid
.b
[11],
249 guid
.b
[12], guid
.b
[13], guid
.b
[14], guid
.b
[15]);
253 char *get_nvme_multipath_dev_hw_path(const char *dev_path
);
254 char *diskfd_to_devpath(int fd
, int dev_level
, char *buf
);
255 int devpath_to_char(const char *dev_path
, const char *entry
, char *buf
,
256 int len
, int verbose
);
257 __u16
devpath_to_vendor(const char *dev_path
);
258 struct sys_dev
*find_driver_devices(const char *bus
, const char *driver
);
259 struct sys_dev
*find_intel_devices(void);
260 const struct imsm_orom
*find_imsm_capability(struct sys_dev
*hba
);
261 const struct imsm_orom
*find_imsm_orom(void);
262 int disk_attached_to_hba(int fd
, const char *hba_path
);
263 int devt_attached_to_hba(dev_t dev
, const char *hba_path
);
264 char *devt_to_devpath(dev_t dev
, int dev_level
, char *buf
);
265 bool is_path_attached_to_hba(const char *disk_path
, const char *hba_path
);
266 const struct orom_entry
*get_orom_entry_by_device_id(__u16 dev_id
);
267 const struct imsm_orom
*get_orom_by_device_id(__u16 device_id
);
268 struct sys_dev
*device_by_id(__u16 device_id
);
269 struct sys_dev
*device_by_id_and_path(__u16 device_id
, const char *path
);
270 int is_multipath_nvme(int disk_fd
);
271 int imsm_is_nvme_namespace_supported(int disk_fd
, int verbose
);
272 char *vmd_domain_to_controller(struct sys_dev
*hba
, char *buf
);