]> git.ipfire.org Git - thirdparty/mdadm.git/blob - platform-intel.h
Create.c: fix uclibc build
[thirdparty/mdadm.git] / platform-intel.h
1 /*
2 * Intel(R) Matrix Storage Manager hardware and firmware support routines
3 *
4 * Copyright (C) 2008 Intel Corporation
5 *
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.
9 *
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
13 * more details.
14 *
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.
18 */
19 #include <asm/types.h>
20 #include <strings.h>
21
22 /* according to GUID format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
23 #define GUID_STR_MAX 37
24
25 /* The IMSM Capability (IMSM AHCI and ISCU OROM/EFI variable) Version Table definition */
26 struct imsm_orom {
27 __u8 signature[4];
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
41 * anywhere else
42 */
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.
82 */
83 __u32 attr;
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)
94 __u32 capabilities;
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_TPV (1 << 10)
110 } __attribute__((packed));
111
112 static inline int imsm_orom_has_raid0(const struct imsm_orom *orom)
113 {
114 return !!(orom->rlc & IMSM_OROM_RLC_RAID0);
115 }
116 static inline int imsm_orom_has_raid1(const struct imsm_orom *orom)
117 {
118 return !!(orom->rlc & IMSM_OROM_RLC_RAID1);
119 }
120 static inline int imsm_orom_has_raid1e(const struct imsm_orom *orom)
121 {
122 return !!(orom->rlc & IMSM_OROM_RLC_RAID1E);
123 }
124 static inline int imsm_orom_has_raid10(const struct imsm_orom *orom)
125 {
126 return !!(orom->rlc & IMSM_OROM_RLC_RAID10);
127 }
128 static inline int imsm_orom_has_raid5(const struct imsm_orom *orom)
129 {
130 return !!(orom->rlc & IMSM_OROM_RLC_RAID5);
131 }
132
133 /**
134 * imsm_orom_has_chunk - check if the orom supports the given chunk size
135 * @orom: orom pointer from find_imsm_orom
136 * @chunk: chunk size in kibibytes
137 */
138 static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
139 {
140 int fs = ffs(chunk);
141 if (!fs)
142 return 0;
143 fs--; /* bit num to bit index */
144 if (chunk & (chunk-1))
145 return 0; /* not a power of 2 */
146 return !!(orom->sss & (1 << (fs - 1)));
147 }
148
149 /**
150 * fls - find last (most-significant) bit set
151 * @x: the word to search
152 * The funciton is borrowed from Linux kernel code
153 * include/asm-generic/bitops/fls.h
154 */
155 static inline int fls(int x)
156 {
157 int r = 32;
158
159 if (!x)
160 return 0;
161 if (!(x & 0xffff0000u)) {
162 x <<= 16;
163 r -= 16;
164 }
165 if (!(x & 0xff000000u)) {
166 x <<= 8;
167 r -= 8;
168 }
169 if (!(x & 0xf0000000u)) {
170 x <<= 4;
171 r -= 4;
172 }
173 if (!(x & 0xc0000000u)) {
174 x <<= 2;
175 r -= 2;
176 }
177 if (!(x & 0x80000000u)) {
178 r -= 1;
179 }
180 return r;
181 }
182
183 static inline int imsm_orom_is_enterprise(const struct imsm_orom *orom)
184 {
185 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_EnterpriseSystem);
186 }
187
188 static inline int imsm_orom_is_nvme(const struct imsm_orom *orom)
189 {
190 return memcmp(orom->signature, IMSM_NVME_OROM_COMPAT_SIGNATURE,
191 sizeof(orom->signature)) == 0;
192 }
193
194 static inline int imsm_orom_is_vmd_without_efi(const struct imsm_orom *orom)
195 {
196 return memcmp(orom->signature, IMSM_VMD_OROM_COMPAT_SIGNATURE,
197 sizeof(orom->signature)) == 0;
198 }
199
200 static inline int imsm_orom_has_tpv_support(const struct imsm_orom *orom)
201 {
202 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_TPV);
203 }
204
205 enum sys_dev_type {
206 SYS_DEV_UNKNOWN = 0,
207 SYS_DEV_SAS,
208 SYS_DEV_SATA,
209 SYS_DEV_NVME,
210 SYS_DEV_VMD,
211 SYS_DEV_SATA_VMD,
212 SYS_DEV_MAX
213 };
214
215 struct sys_dev {
216 enum sys_dev_type type;
217 char *path;
218 char *pci_id;
219 __u16 dev_id;
220 __u32 class;
221 struct sys_dev *next;
222 };
223
224 struct efi_guid {
225 __u8 b[16];
226 };
227
228 struct devid_list {
229 __u16 devid;
230 struct devid_list *next;
231 };
232
233 struct orom_entry {
234 struct imsm_orom orom;
235 struct devid_list *devid_list;
236 enum sys_dev_type type;
237 struct orom_entry *next;
238 };
239
240 extern struct orom_entry *orom_entries;
241
242 static inline char *guid_str(char *buf, struct efi_guid guid)
243 {
244 snprintf(buf, GUID_STR_MAX, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
245 guid.b[3], guid.b[2], guid.b[1], guid.b[0],
246 guid.b[5], guid.b[4], guid.b[7], guid.b[6],
247 guid.b[8], guid.b[9], guid.b[10], guid.b[11],
248 guid.b[12], guid.b[13], guid.b[14], guid.b[15]);
249 return buf;
250 }
251
252 char *get_nvme_multipath_dev_hw_path(const char *dev_path);
253 char *diskfd_to_devpath(int fd, int dev_level, char *buf);
254 int devpath_to_char(const char *dev_path, const char *entry, char *buf,
255 int len, int verbose);
256 __u16 devpath_to_vendor(const char *dev_path);
257 struct sys_dev *find_driver_devices(const char *bus, const char *driver);
258 struct sys_dev *find_intel_devices(void);
259 const struct imsm_orom *find_imsm_capability(struct sys_dev *hba);
260 const struct imsm_orom *find_imsm_orom(void);
261 int disk_attached_to_hba(int fd, const char *hba_path);
262 int devt_attached_to_hba(dev_t dev, const char *hba_path);
263 char *devt_to_devpath(dev_t dev, int dev_level, char *buf);
264 int path_attached_to_hba(const char *disk_path, const char *hba_path);
265 const struct orom_entry *get_orom_entry_by_device_id(__u16 dev_id);
266 const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
267 struct sys_dev *device_by_id(__u16 device_id);
268 struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path);
269 int is_multipath_nvme(int disk_fd);
270 int imsm_is_nvme_namespace_supported(int disk_fd, int verbose);
271 char *vmd_domain_to_controller(struct sys_dev *hba, char *buf);