]> git.ipfire.org Git - thirdparty/mdadm.git/blob - platform-intel.h
Correctly abort level change when reshape_array fails.
[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 /* The IMSM OROM Version Table definition */
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 */
61 __u16 tds; /* Total Disks Supported */
62 __u8 vpa; /* # Volumes Per Array supported */
63 __u8 vphba; /* # Volumes Per Host Bus Adapter supported */
64 /* Attributes supported. This should map to the
65 * attributes in the MPB. Also, lower 16 bits
66 * should match/duplicate RLC bits above.
67 */
68 __u32 attr;
69 #define IMSM_OROM_ATTR_RAID0 IMSM_OROM_RLC_RAID0
70 #define IMSM_OROM_ATTR_RAID1 IMSM_OROM_RLC_RAID1
71 #define IMSM_OROM_ATTR_RAID10 IMSM_OROM_RLC_RAID10
72 #define IMSM_OROM_ATTR_RAID1E IMSM_OROM_RLC_RAID1E
73 #define IMSM_OROM_ATTR_RAID5 IMSM_OROM_RLC_RAID5
74 #define IMSM_OROM_ATTR_RAID_CNG IMSM_OROM_RLC_RAID_CNG
75 #define IMSM_OROM_ATTR_2TB (1 << 29)
76 #define IMSM_OROM_ATTR_PM (1 << 30)
77 #define IMSM_OROM_ATTR_ChecksumVerify (1 << 31)
78 __u32 reserved1;
79 __u32 reserved2;
80 } __attribute__((packed));
81
82 static inline int imsm_orom_has_raid0(const struct imsm_orom *orom)
83 {
84 return !!(orom->rlc & IMSM_OROM_RLC_RAID0);
85 }
86 static inline int imsm_orom_has_raid1(const struct imsm_orom *orom)
87 {
88 return !!(orom->rlc & IMSM_OROM_RLC_RAID1);
89 }
90 static inline int imsm_orom_has_raid1e(const struct imsm_orom *orom)
91 {
92 return !!(orom->rlc & IMSM_OROM_RLC_RAID1E);
93 }
94 static inline int imsm_orom_has_raid10(const struct imsm_orom *orom)
95 {
96 return !!(orom->rlc & IMSM_OROM_RLC_RAID10);
97 }
98 static inline int imsm_orom_has_raid5(const struct imsm_orom *orom)
99 {
100 return !!(orom->rlc & IMSM_OROM_RLC_RAID5);
101 }
102
103 /**
104 * imsm_orom_has_chunk - check if the orom supports the given chunk size
105 * @orom: orom pointer from find_imsm_orom
106 * @chunk: chunk size in kibibytes
107 */
108 static inline int imsm_orom_has_chunk(const struct imsm_orom *orom, int chunk)
109 {
110 int fs = ffs(chunk);
111
112 if (!fs)
113 return 0;
114 fs--; /* bit num to bit index */
115 return !!(orom->sss & (1 << (fs - 1)));
116 }
117
118 /**
119 * fls - find last (most-significant) bit set
120 * @x: the word to search
121 * The funciton is borrowed from Linux kernel code
122 * include/asm-generic/bitops/fls.h
123 */
124 static inline int fls(int x)
125 {
126 int r = 32;
127
128 if (!x)
129 return 0;
130 if (!(x & 0xffff0000u)) {
131 x <<= 16;
132 r -= 16;
133 }
134 if (!(x & 0xff000000u)) {
135 x <<= 8;
136 r -= 8;
137 }
138 if (!(x & 0xf0000000u)) {
139 x <<= 4;
140 r -= 4;
141 }
142 if (!(x & 0xc0000000u)) {
143 x <<= 2;
144 r -= 2;
145 }
146 if (!(x & 0x80000000u)) {
147 x <<= 1;
148 r -= 1;
149 }
150 return r;
151 }
152
153 /**
154 * imsm_orom_default_chunk - return the largest chunk size supported via orom
155 * @orom: orom pointer from find_imsm_orom
156 */
157 static inline int imsm_orom_default_chunk(const struct imsm_orom *orom)
158 {
159 int fs = fls(orom->sss);
160
161 if (!fs)
162 return 0;
163
164 return min(512, (1 << fs));
165 }
166
167 struct sys_dev {
168 char *path;
169 struct sys_dev *next;
170 };
171
172 struct sys_dev *find_driver_devices(const char *bus, const char *driver);
173 __u16 devpath_to_vendor(const char *dev_path);
174 void free_sys_dev(struct sys_dev **list);
175 const struct imsm_orom *find_imsm_orom(void);
176 int disk_attached_to_hba(int fd, const char *hba_path);
177 char *devt_to_devpath(dev_t dev);
178 int path_attached_to_hba(const char *disk_path, const char *hba_path);