]> git.ipfire.org Git - thirdparty/mdadm.git/blame_incremental - platform-intel.h
mdmonitor: use MAILFROM to set sendmail envelope sender address
[thirdparty/mdadm.git] / platform-intel.h
... / ...
CommitLineData
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 */
26struct imsm_orom {
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
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_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));
116
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)
128{
129 if (orom->rlc & bit)
130 return true;
131 return false;
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);
142 if (!fs)
143 return 0;
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)));
148}
149
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)) {
179 r -= 1;
180 }
181 return r;
182}
183
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,
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;
199}
200
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
206enum sys_dev_type {
207 SYS_DEV_UNKNOWN = 0,
208 SYS_DEV_SAS,
209 SYS_DEV_SATA,
210 SYS_DEV_NVME,
211 SYS_DEV_VMD,
212 SYS_DEV_SATA_VMD,
213 SYS_DEV_MAX
214};
215
216struct sys_dev {
217 enum sys_dev_type type;
218 char *path;
219 char *pci_id;
220 __u16 dev_id;
221 __u32 class;
222 struct sys_dev *next;
223};
224
225struct efi_guid {
226 __u8 b[16];
227};
228
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;
237 enum sys_dev_type type;
238 struct orom_entry *next;
239};
240
241extern struct orom_entry *orom_entries;
242
243static inline char *guid_str(char *buf, struct efi_guid guid)
244{
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]);
250 return buf;
251}
252
253char *get_nvme_multipath_dev_hw_path(const char *dev_path);
254char *diskfd_to_devpath(int fd, int dev_level, char *buf);
255int 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);
258struct sys_dev *find_driver_devices(const char *bus, const char *driver);
259struct sys_dev *find_intel_devices(void);
260const struct imsm_orom *find_imsm_capability(struct sys_dev *hba);
261const struct imsm_orom *find_imsm_orom(void);
262int disk_attached_to_hba(int fd, const char *hba_path);
263int devt_attached_to_hba(dev_t dev, const char *hba_path);
264char *devt_to_devpath(dev_t dev, int dev_level, char *buf);
265bool is_path_attached_to_hba(const char *disk_path, const char *hba_path);
266const struct orom_entry *get_orom_entry_by_device_id(__u16 dev_id);
267const struct imsm_orom *get_orom_by_device_id(__u16 device_id);
268struct sys_dev *device_by_id(__u16 device_id);
269struct sys_dev *device_by_id_and_path(__u16 device_id, const char *path);
270int is_multipath_nvme(int disk_fd);
271int imsm_is_nvme_namespace_supported(int disk_fd, int verbose);
272char *vmd_domain_to_controller(struct sys_dev *hba, char *buf);