]> git.ipfire.org Git - thirdparty/mdadm.git/blame - platform-intel.h
mdmonitor: use MAILFROM to set sendmail envelope sender address
[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 26struct imsm_orom {
a83ecaf1 27 __u8 signature[4] __attribute__((nonstring));
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 108 #define IMSM_OROM_CAPABILITIES_SKUMode ((1 << 8)|(1 << 9))
f70e08be
BK
109 #define IMSM_OROM_CAPABILITIES_SKUMode_LOW ((1 << 8) | (1 << 9))
110 #define IMSM_OROM_CAPABILITIES_SKUMode_LOW_SHIFT 8
32716c51 111 #define IMSM_OROM_CAPABILITIES_TPV (1 << 10)
f70e08be
BK
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)
b390f610
DW
115} __attribute__((packed));
116
191e6ddb
MK
117/* IMSM metadata requirements for each level */
118struct imsm_level_ops {
119 int level;
120 bool (*is_level_supported)(const struct imsm_orom *);
121 bool (*is_raiddisks_count_supported)(const int);
122 char *name;
123};
124
125extern struct imsm_level_ops imsm_level_ops[];
126
127static inline bool imsm_rlc_has_bit(const struct imsm_orom *orom, const unsigned short bit)
88c32bb1 128{
191e6ddb
MK
129 if (orom->rlc & bit)
130 return true;
131 return false;
88c32bb1
DW
132}
133
134/**
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
138 */
139static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
140{
141 int fs = ffs(chunk);
88c32bb1
DW
142 if (!fs)
143 return 0;
144 fs--; /* bit num to bit index */
70eb8219
HCP
145 if (chunk & (chunk-1))
146 return 0; /* not a power of 2 */
147 return !!(orom->sss & (1 << (fs - 1)));
88c32bb1
DW
148}
149
0bd16cf2
DJ
150/**
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
155 */
156static inline int fls(int x)
157{
158 int r = 32;
159
160 if (!x)
161 return 0;
162 if (!(x & 0xffff0000u)) {
163 x <<= 16;
164 r -= 16;
165 }
166 if (!(x & 0xff000000u)) {
167 x <<= 8;
168 r -= 8;
169 }
170 if (!(x & 0xf0000000u)) {
171 x <<= 4;
172 r -= 4;
173 }
174 if (!(x & 0xc0000000u)) {
175 x <<= 2;
176 r -= 2;
177 }
178 if (!(x & 0x80000000u)) {
0bd16cf2
DJ
179 r -= 1;
180 }
181 return r;
182}
183
0858eccf
AP
184static inline int imsm_orom_is_enterprise(const struct imsm_orom *orom)
185{
186 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_EnterpriseSystem);
187}
188
189static inline int imsm_orom_is_nvme(const struct imsm_orom *orom)
190{
191 return memcmp(orom->signature, IMSM_NVME_OROM_COMPAT_SIGNATURE,
8d1114be
MG
192 sizeof(orom->signature)) == 0;
193}
194
195static inline int imsm_orom_is_vmd_without_efi(const struct imsm_orom *orom)
196{
197 return memcmp(orom->signature, IMSM_VMD_OROM_COMPAT_SIGNATURE,
198 sizeof(orom->signature)) == 0;
0858eccf
AP
199}
200
32716c51
PB
201static inline int imsm_orom_has_tpv_support(const struct imsm_orom *orom)
202{
203 return !!(orom->driver_features & IMSM_OROM_CAPABILITIES_TPV);
204}
205
a8e5382a
LM
206enum sys_dev_type {
207 SYS_DEV_UNKNOWN = 0,
208 SYS_DEV_SAS,
209 SYS_DEV_SATA,
614902f6 210 SYS_DEV_NVME,
60f0f54d 211 SYS_DEV_VMD,
75350d87 212 SYS_DEV_SATA_VMD,
a8e5382a
LM
213 SYS_DEV_MAX
214};
215
b390f610 216struct sys_dev {
a8e5382a 217 enum sys_dev_type type;
b390f610 218 char *path;
a8e5382a 219 char *pci_id;
9c747fa0 220 __u16 dev_id;
6b781d33 221 __u32 class;
b390f610
DW
222 struct sys_dev *next;
223};
224
1a901471
LM
225struct efi_guid {
226 __u8 b[16];
227};
228
0858eccf
AP
229struct devid_list {
230 __u16 devid;
231 struct devid_list *next;
232};
233
234struct orom_entry {
235 struct imsm_orom orom;
236 struct devid_list *devid_list;
60f0f54d 237 enum sys_dev_type type;
5e1d6128 238 struct orom_entry *next;
0858eccf
AP
239};
240
5e1d6128
AP
241extern struct orom_entry *orom_entries;
242
1a901471
LM
243static inline char *guid_str(char *buf, struct efi_guid guid)
244{
5ccd457b 245 snprintf(buf, GUID_STR_MAX, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1a901471
LM
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]);
250 return buf;
251}
252
d835518b 253char *get_nvme_multipath_dev_hw_path(const char *dev_path);
7c798f87 254char *diskfd_to_devpath(int fd, int dev_level, char *buf);
fcebeb77
MT
255int devpath_to_char(const char *dev_path, const char *entry, char *buf,
256 int len, int verbose);
60f0f54d 257__u16 devpath_to_vendor(const char *dev_path);
b390f610 258struct sys_dev *find_driver_devices(const char *bus, const char *driver);
a8e5382a 259struct sys_dev *find_intel_devices(void);
6b781d33 260const struct imsm_orom *find_imsm_capability(struct sys_dev *hba);
b390f610 261const struct imsm_orom *find_imsm_orom(void);
25921536 262int disk_attached_to_hba(int fd, const char *hba_path);
0c21b485 263int devt_attached_to_hba(dev_t dev, const char *hba_path);
7c798f87 264char *devt_to_devpath(dev_t dev, int dev_level, char *buf);
a6392b41 265bool is_path_attached_to_hba(const char *disk_path, const char *hba_path);
72a45777 266const struct orom_entry *get_orom_entry_by_device_id(__u16 dev_id);
6b781d33 267const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
0858eccf 268struct sys_dev *device_by_id(__u16 device_id);
d3c11416 269struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path);
d835518b 270int is_multipath_nvme(int disk_fd);
8662f92d 271int imsm_is_nvme_namespace_supported(int disk_fd, int verbose);
60f0f54d 272char *vmd_domain_to_controller(struct sys_dev *hba, char *buf);