]>
Commit | Line | Data |
---|---|---|
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 | |
fc13853f | 22 | /* The IMSM Capability (IMSM AHCI and ISCU OROM/EFI variable) Version Table definition */ |
b390f610 DW |
23 | struct imsm_orom { |
24 | __u8 signature[4]; | |
25 | __u8 table_ver_major; /* Currently 2 (can change with future revs) */ | |
26 | __u8 table_ver_minor; /* Currently 2 (can change with future revs) */ | |
27 | __u16 major_ver; /* Example: 8 as in 8.6.0.1020 */ | |
28 | __u16 minor_ver; /* Example: 6 as in 8.6.0.1020 */ | |
29 | __u16 hotfix_ver; /* Example: 0 as in 8.6.0.1020 */ | |
30 | __u16 build; /* Example: 1020 as in 8.6.0.1020 */ | |
31 | __u8 len; /* number of bytes in this entire table */ | |
32 | __u8 checksum; /* checksum of all the bytes in this table */ | |
33 | __u16 rlc; /* RAID Level Capability */ | |
34 | /* we assume the cpu is x86 as the orom should not be found | |
35 | * anywhere else | |
36 | */ | |
37 | #define IMSM_OROM_RLC_RAID0 (1 << 0) | |
38 | #define IMSM_OROM_RLC_RAID1 (1 << 1) | |
39 | #define IMSM_OROM_RLC_RAID10 (1 << 2) | |
40 | #define IMSM_OROM_RLC_RAID1E (1 << 3) | |
41 | #define IMSM_OROM_RLC_RAID5 (1 << 4) | |
42 | #define IMSM_OROM_RLC_RAID_CNG (1 << 5) | |
43 | __u16 sss; /* Strip Size Supported */ | |
44 | #define IMSM_OROM_SSS_2kB (1 << 0) | |
45 | #define IMSM_OROM_SSS_4kB (1 << 1) | |
46 | #define IMSM_OROM_SSS_8kB (1 << 2) | |
47 | #define IMSM_OROM_SSS_16kB (1 << 3) | |
48 | #define IMSM_OROM_SSS_32kB (1 << 4) | |
49 | #define IMSM_OROM_SSS_64kB (1 << 5) | |
50 | #define IMSM_OROM_SSS_128kB (1 << 6) | |
51 | #define IMSM_OROM_SSS_256kB (1 << 7) | |
52 | #define IMSM_OROM_SSS_512kB (1 << 8) | |
53 | #define IMSM_OROM_SSS_1MB (1 << 9) | |
54 | #define IMSM_OROM_SSS_2MB (1 << 10) | |
55 | #define IMSM_OROM_SSS_4MB (1 << 11) | |
56 | #define IMSM_OROM_SSS_8MB (1 << 12) | |
57 | #define IMSM_OROM_SSS_16MB (1 << 13) | |
58 | #define IMSM_OROM_SSS_32MB (1 << 14) | |
59 | #define IMSM_OROM_SSS_64MB (1 << 15) | |
60 | __u16 dpa; /* Disks Per Array supported */ | |
fc13853f | 61 | #define IMSM_OROM_DISKS_PER_ARRAY 6 |
b390f610 | 62 | __u16 tds; /* Total Disks Supported */ |
fc13853f | 63 | #define IMSM_OROM_TOTAL_DISKS 6 |
b390f610 | 64 | __u8 vpa; /* # Volumes Per Array supported */ |
fc13853f | 65 | #define IMSM_OROM_VOLUMES_PER_ARRAY 2 |
b390f610 | 66 | __u8 vphba; /* # Volumes Per Host Bus Adapter supported */ |
fc13853f | 67 | #define IMSM_OROM_VOLUMES_PER_HBA 4 |
b390f610 DW |
68 | /* Attributes supported. This should map to the |
69 | * attributes in the MPB. Also, lower 16 bits | |
70 | * should match/duplicate RLC bits above. | |
71 | */ | |
72 | __u32 attr; | |
73 | #define IMSM_OROM_ATTR_RAID0 IMSM_OROM_RLC_RAID0 | |
74 | #define IMSM_OROM_ATTR_RAID1 IMSM_OROM_RLC_RAID1 | |
75 | #define IMSM_OROM_ATTR_RAID10 IMSM_OROM_RLC_RAID10 | |
76 | #define IMSM_OROM_ATTR_RAID1E IMSM_OROM_RLC_RAID1E | |
77 | #define IMSM_OROM_ATTR_RAID5 IMSM_OROM_RLC_RAID5 | |
78 | #define IMSM_OROM_ATTR_RAID_CNG IMSM_OROM_RLC_RAID_CNG | |
29cd0821 | 79 | #define IMSM_OROM_ATTR_2TB_DISK (1 << 26) |
b390f610 DW |
80 | #define IMSM_OROM_ATTR_2TB (1 << 29) |
81 | #define IMSM_OROM_ATTR_PM (1 << 30) | |
82 | #define IMSM_OROM_ATTR_ChecksumVerify (1 << 31) | |
2a7e6de2 LM |
83 | __u32 capabilities; |
84 | #define IMSM_OROM_CAPABILITIES_Ext_SATA (1 << 0) | |
85 | #define IMSM_OROM_CAPABILITIES_TurboMemory (1 << 1) | |
86 | #define IMSM_OROM_CAPABILITIES_HddPassword (1 << 2) | |
87 | #define IMSM_OROM_CAPABILITIES_DiskCoercion (1 << 3) | |
88 | __u32 driver_features; | |
89 | #define IMSM_OROM_CAPABILITIES_HDDUnlock (1 << 0) | |
90 | #define IMSM_OROM_CAPABILITIES_LEDLoc (1 << 1) | |
91 | #define IMSM_OROM_CAPABILITIES_EnterpriseSystem (1 << 2) | |
92 | #define IMSM_OROM_CAPABILITIES_Zpodd (1 << 3) | |
93 | #define IMSM_OROM_CAPABILITIES_LargeDramCache (1 << 4) | |
94 | #define IMSM_OROM_CAPABILITIES_Rohi (1 << 5) | |
95 | #define IMSM_OROM_CAPABILITIES_ReadPatrol (1 << 6) | |
96 | #define IMSM_OROM_CAPABILITIES_XorHw (1 << 7) | |
b390f610 DW |
97 | } __attribute__((packed)); |
98 | ||
88c32bb1 DW |
99 | static inline int imsm_orom_has_raid0(const struct imsm_orom *orom) |
100 | { | |
101 | return !!(orom->rlc & IMSM_OROM_RLC_RAID0); | |
102 | } | |
103 | static inline int imsm_orom_has_raid1(const struct imsm_orom *orom) | |
104 | { | |
105 | return !!(orom->rlc & IMSM_OROM_RLC_RAID1); | |
106 | } | |
107 | static inline int imsm_orom_has_raid1e(const struct imsm_orom *orom) | |
108 | { | |
109 | return !!(orom->rlc & IMSM_OROM_RLC_RAID1E); | |
110 | } | |
111 | static inline int imsm_orom_has_raid10(const struct imsm_orom *orom) | |
112 | { | |
113 | return !!(orom->rlc & IMSM_OROM_RLC_RAID10); | |
114 | } | |
115 | static inline int imsm_orom_has_raid5(const struct imsm_orom *orom) | |
116 | { | |
117 | return !!(orom->rlc & IMSM_OROM_RLC_RAID5); | |
118 | } | |
119 | ||
120 | /** | |
121 | * imsm_orom_has_chunk - check if the orom supports the given chunk size | |
122 | * @orom: orom pointer from find_imsm_orom | |
123 | * @chunk: chunk size in kibibytes | |
124 | */ | |
125 | static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk) | |
126 | { | |
127 | int fs = ffs(chunk); | |
88c32bb1 DW |
128 | if (!fs) |
129 | return 0; | |
130 | fs--; /* bit num to bit index */ | |
70eb8219 HCP |
131 | if (chunk & (chunk-1)) |
132 | return 0; /* not a power of 2 */ | |
133 | return !!(orom->sss & (1 << (fs - 1))); | |
88c32bb1 DW |
134 | } |
135 | ||
a8e5382a | 136 | |
0bd16cf2 DJ |
137 | /** |
138 | * fls - find last (most-significant) bit set | |
139 | * @x: the word to search | |
140 | * The funciton is borrowed from Linux kernel code | |
141 | * include/asm-generic/bitops/fls.h | |
142 | */ | |
143 | static inline int fls(int x) | |
144 | { | |
145 | int r = 32; | |
146 | ||
147 | if (!x) | |
148 | return 0; | |
149 | if (!(x & 0xffff0000u)) { | |
150 | x <<= 16; | |
151 | r -= 16; | |
152 | } | |
153 | if (!(x & 0xff000000u)) { | |
154 | x <<= 8; | |
155 | r -= 8; | |
156 | } | |
157 | if (!(x & 0xf0000000u)) { | |
158 | x <<= 4; | |
159 | r -= 4; | |
160 | } | |
161 | if (!(x & 0xc0000000u)) { | |
162 | x <<= 2; | |
163 | r -= 2; | |
164 | } | |
165 | if (!(x & 0x80000000u)) { | |
166 | x <<= 1; | |
167 | r -= 1; | |
168 | } | |
169 | return r; | |
170 | } | |
171 | ||
a8e5382a LM |
172 | enum sys_dev_type { |
173 | SYS_DEV_UNKNOWN = 0, | |
174 | SYS_DEV_SAS, | |
175 | SYS_DEV_SATA, | |
176 | SYS_DEV_MAX | |
177 | }; | |
178 | ||
b390f610 | 179 | struct sys_dev { |
a8e5382a | 180 | enum sys_dev_type type; |
b390f610 | 181 | char *path; |
a8e5382a | 182 | char *pci_id; |
9c747fa0 | 183 | __u16 dev_id; |
b390f610 DW |
184 | struct sys_dev *next; |
185 | }; | |
186 | ||
1a901471 LM |
187 | struct efi_guid { |
188 | __u8 b[16]; | |
189 | }; | |
190 | ||
191 | static inline char *guid_str(char *buf, struct efi_guid guid) | |
192 | { | |
193 | sprintf(buf, "%02x%02x%02x%02x-%02x%02x-%02x%02x-" | |
194 | "%02x%02x-%02x%02x%02x%02x%02x%02x", | |
195 | guid.b[3], guid.b[2], guid.b[1], guid.b[0], | |
196 | guid.b[5], guid.b[4], guid.b[7], guid.b[6], | |
197 | guid.b[8], guid.b[9], guid.b[10], guid.b[11], | |
198 | guid.b[12], guid.b[13], guid.b[14], guid.b[15]); | |
199 | return buf; | |
200 | } | |
201 | ||
a8e5382a | 202 | char *diskfd_to_devpath(int fd); |
b390f610 | 203 | struct sys_dev *find_driver_devices(const char *bus, const char *driver); |
a8e5382a | 204 | struct sys_dev *find_intel_devices(void); |
b390f610 | 205 | void free_sys_dev(struct sys_dev **list); |
fc13853f | 206 | const struct imsm_orom *find_imsm_capability(enum sys_dev_type hba_id); |
b390f610 | 207 | const struct imsm_orom *find_imsm_orom(void); |
25921536 DW |
208 | int disk_attached_to_hba(int fd, const char *hba_path); |
209 | char *devt_to_devpath(dev_t dev); | |
210 | int path_attached_to_hba(const char *disk_path, const char *hba_path); | |
a8e5382a LM |
211 | const char *get_sys_dev_type(enum sys_dev_type); |
212 |