]> git.ipfire.org Git - thirdparty/mdadm.git/blame - platform-intel.h
Wait for mdmon when it is stared via systemd
[thirdparty/mdadm.git] / platform-intel.h
CommitLineData
b390f610
DW
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>
88c32bb1 20#include <strings.h>
b390f610 21
5ccd457b
KT
22/* according to GUID format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
23#define GUID_STR_MAX 37
24
fc13853f 25/* The IMSM Capability (IMSM AHCI and ISCU OROM/EFI variable) Version Table definition */
b390f610
DW
26struct imsm_orom {
27 __u8 signature[4];
6b781d33 28 #define IMSM_OROM_SIGNATURE "$VER"
614902f6 29 #define IMSM_NVME_OROM_COMPAT_SIGNATURE "$NVM"
8d1114be 30 #define IMSM_VMD_OROM_COMPAT_SIGNATURE "$VMD"
b390f610
DW
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 */
fc13853f 67 #define IMSM_OROM_DISKS_PER_ARRAY 6
614902f6 68 #define IMSM_OROM_DISKS_PER_ARRAY_NVME 12
b390f610 69 __u16 tds; /* Total Disks Supported */
fc13853f 70 #define IMSM_OROM_TOTAL_DISKS 6
614902f6 71 #define IMSM_OROM_TOTAL_DISKS_NVME 12
8d1114be 72 #define IMSM_OROM_TOTAL_DISKS_VMD 48
b390f610 73 __u8 vpa; /* # Volumes Per Array supported */
fc13853f 74 #define IMSM_OROM_VOLUMES_PER_ARRAY 2
b390f610 75 __u8 vphba; /* # Volumes Per Host Bus Adapter supported */
fc13853f 76 #define IMSM_OROM_VOLUMES_PER_HBA 4
614902f6 77 #define IMSM_OROM_VOLUMES_PER_HBA_NVME 4
8d1114be 78 #define IMSM_OROM_VOLUMES_PER_HBA_VMD 24
b390f610
DW
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
29cd0821 90 #define IMSM_OROM_ATTR_2TB_DISK (1 << 26)
b390f610
DW
91 #define IMSM_OROM_ATTR_2TB (1 << 29)
92 #define IMSM_OROM_ATTR_PM (1 << 30)
93 #define IMSM_OROM_ATTR_ChecksumVerify (1 << 31)
2a7e6de2
LM
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)
32716c51
PB
108 #define IMSM_OROM_CAPABILITIES_SKUMode ((1 << 8)|(1 << 9))
109 #define IMSM_OROM_CAPABILITIES_TPV (1 << 10)
b390f610
DW
110} __attribute__((packed));
111
191e6ddb
MK
112/* IMSM metadata requirements for each level */
113struct imsm_level_ops {
114 int level;
115 bool (*is_level_supported)(const struct imsm_orom *);
116 bool (*is_raiddisks_count_supported)(const int);
117 char *name;
118};
119
120extern struct imsm_level_ops imsm_level_ops[];
121
122static inline bool imsm_rlc_has_bit(const struct imsm_orom *orom, const unsigned short bit)
88c32bb1 123{
191e6ddb
MK
124 if (orom->rlc & bit)
125 return true;
126 return false;
88c32bb1
DW
127}
128
129/**
130 * imsm_orom_has_chunk - check if the orom supports the given chunk size
131 * @orom: orom pointer from find_imsm_orom
132 * @chunk: chunk size in kibibytes
133 */
134static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
135{
136 int fs = ffs(chunk);
88c32bb1
DW
137 if (!fs)
138 return 0;
139 fs--; /* bit num to bit index */
70eb8219
HCP
140 if (chunk & (chunk-1))
141 return 0; /* not a power of 2 */
142 return !!(orom->sss & (1 << (fs - 1)));
88c32bb1
DW
143}
144
0bd16cf2
DJ
145/**
146 * fls - find last (most-significant) bit set
147 * @x: the word to search
148 * The funciton is borrowed from Linux kernel code
149 * include/asm-generic/bitops/fls.h
150 */
151static inline int fls(int x)
152{
153 int r = 32;
154
155 if (!x)
156 return 0;
157 if (!(x & 0xffff0000u)) {
158 x <<= 16;
159 r -= 16;
160 }
161 if (!(x & 0xff000000u)) {
162 x <<= 8;
163 r -= 8;
164 }
165 if (!(x & 0xf0000000u)) {
166 x <<= 4;
167 r -= 4;
168 }
169 if (!(x & 0xc0000000u)) {
170 x <<= 2;
171 r -= 2;
172 }
173 if (!(x & 0x80000000u)) {
0bd16cf2
DJ
174 r -= 1;
175 }
176 return r;
177}
178
0858eccf
AP
179static inline int imsm_orom_is_enterprise(const struct imsm_orom *orom)
180{
181 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_EnterpriseSystem);
182}
183
184static inline int imsm_orom_is_nvme(const struct imsm_orom *orom)
185{
186 return memcmp(orom->signature, IMSM_NVME_OROM_COMPAT_SIGNATURE,
8d1114be
MG
187 sizeof(orom->signature)) == 0;
188}
189
190static inline int imsm_orom_is_vmd_without_efi(const struct imsm_orom *orom)
191{
192 return memcmp(orom->signature, IMSM_VMD_OROM_COMPAT_SIGNATURE,
193 sizeof(orom->signature)) == 0;
0858eccf
AP
194}
195
32716c51
PB
196static inline int imsm_orom_has_tpv_support(const struct imsm_orom *orom)
197{
198 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_TPV);
199}
200
a8e5382a
LM
201enum sys_dev_type {
202 SYS_DEV_UNKNOWN = 0,
203 SYS_DEV_SAS,
204 SYS_DEV_SATA,
614902f6 205 SYS_DEV_NVME,
60f0f54d 206 SYS_DEV_VMD,
75350d87 207 SYS_DEV_SATA_VMD,
a8e5382a
LM
208 SYS_DEV_MAX
209};
210
b390f610 211struct sys_dev {
a8e5382a 212 enum sys_dev_type type;
b390f610 213 char *path;
a8e5382a 214 char *pci_id;
9c747fa0 215 __u16 dev_id;
6b781d33 216 __u32 class;
b390f610
DW
217 struct sys_dev *next;
218};
219
1a901471
LM
220struct efi_guid {
221 __u8 b[16];
222};
223
0858eccf
AP
224struct devid_list {
225 __u16 devid;
226 struct devid_list *next;
227};
228
229struct orom_entry {
230 struct imsm_orom orom;
231 struct devid_list *devid_list;
60f0f54d 232 enum sys_dev_type type;
5e1d6128 233 struct orom_entry *next;
0858eccf
AP
234};
235
5e1d6128
AP
236extern struct orom_entry *orom_entries;
237
1a901471
LM
238static inline char *guid_str(char *buf, struct efi_guid guid)
239{
5ccd457b 240 snprintf(buf, GUID_STR_MAX, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1a901471
LM
241 guid.b[3], guid.b[2], guid.b[1], guid.b[0],
242 guid.b[5], guid.b[4], guid.b[7], guid.b[6],
243 guid.b[8], guid.b[9], guid.b[10], guid.b[11],
244 guid.b[12], guid.b[13], guid.b[14], guid.b[15]);
245 return buf;
246}
247
d835518b 248char *get_nvme_multipath_dev_hw_path(const char *dev_path);
7c798f87 249char *diskfd_to_devpath(int fd, int dev_level, char *buf);
fcebeb77
MT
250int devpath_to_char(const char *dev_path, const char *entry, char *buf,
251 int len, int verbose);
60f0f54d 252__u16 devpath_to_vendor(const char *dev_path);
b390f610 253struct sys_dev *find_driver_devices(const char *bus, const char *driver);
a8e5382a 254struct sys_dev *find_intel_devices(void);
6b781d33 255const struct imsm_orom *find_imsm_capability(struct sys_dev *hba);
b390f610 256const struct imsm_orom *find_imsm_orom(void);
25921536 257int disk_attached_to_hba(int fd, const char *hba_path);
0c21b485 258int devt_attached_to_hba(dev_t dev, const char *hba_path);
7c798f87 259char *devt_to_devpath(dev_t dev, int dev_level, char *buf);
25921536 260int path_attached_to_hba(const char *disk_path, const char *hba_path);
72a45777 261const struct orom_entry *get_orom_entry_by_device_id(__u16 dev_id);
6b781d33 262const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
0858eccf 263struct sys_dev *device_by_id(__u16 device_id);
d3c11416 264struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path);
d835518b 265int is_multipath_nvme(int disk_fd);
8662f92d 266int imsm_is_nvme_namespace_supported(int disk_fd, int verbose);
60f0f54d 267char *vmd_domain_to_controller(struct sys_dev *hba, char *buf);