Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | #include <linux/blkdev.h> | |
3 | #include <linux/init.h> | |
4 | #include <linux/kernel.h> | |
5 | #include <linux/module.h> | |
6 | #include <linux/moduleparam.h> | |
7 | #include <linux/proc_fs.h> | |
8 | #include <linux/seq_file.h> | |
9 | ||
10 | #include <scsi/scsi_device.h> | |
11 | #include <scsi/scsi_devinfo.h> | |
12 | ||
13 | #include "scsi_priv.h" | |
14 | ||
15 | ||
16 | /* | |
17 | * scsi_dev_info_list: structure to hold black/white listed devices. | |
18 | */ | |
19 | struct scsi_dev_info_list { | |
20 | struct list_head dev_info_list; | |
21 | char vendor[8]; | |
22 | char model[16]; | |
23 | unsigned flags; | |
24 | unsigned compatible; /* for use with scsi_static_device_list entries */ | |
25 | }; | |
26 | ||
27 | ||
28 | static const char spaces[] = " "; /* 16 of them */ | |
29 | static unsigned scsi_default_dev_flags; | |
30 | static LIST_HEAD(scsi_dev_info_list); | |
31 | static char scsi_dev_flags[256]; | |
32 | ||
33 | /* | |
34 | * scsi_static_device_list: deprecated list of devices that require | |
35 | * settings that differ from the default, includes black-listed (broken) | |
36 | * devices. The entries here are added to the tail of scsi_dev_info_list | |
37 | * via scsi_dev_info_list_init. | |
38 | * | |
39 | * Do not add to this list, use the command line or proc interface to add | |
40 | * to the scsi_dev_info_list. This table will eventually go away. | |
41 | */ | |
42 | static struct { | |
43 | char *vendor; | |
44 | char *model; | |
45 | char *revision; /* revision known to be bad, unused */ | |
46 | unsigned flags; | |
47 | } scsi_static_device_list[] __initdata = { | |
48 | /* | |
49 | * The following devices are known not to tolerate a lun != 0 scan | |
50 | * for one reason or another. Some will respond to all luns, | |
51 | * others will lock up. | |
52 | */ | |
53 | {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN}, /* locks up */ | |
54 | {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN}, /* locks up */ | |
55 | {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN}, /* locks up */ | |
56 | {"DENON", "DRD-25X", "V", BLIST_NOLUN}, /* locks up */ | |
57 | {"HITACHI", "DK312C", "CM81", BLIST_NOLUN}, /* responds to all lun */ | |
58 | {"HITACHI", "DK314C", "CR21", BLIST_NOLUN}, /* responds to all lun */ | |
f2536cbd BK |
59 | {"IBM", "2104-DU3", NULL, BLIST_NOLUN}, /* locks up */ |
60 | {"IBM", "2104-TU3", NULL, BLIST_NOLUN}, /* locks up */ | |
1da177e4 LT |
61 | {"IMS", "CDD521/10", "2.06", BLIST_NOLUN}, /* locks up */ |
62 | {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN}, /* locks up */ | |
63 | {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN}, /* locks up */ | |
64 | {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN}, /* locks up */ | |
65 | {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN}, /* locks up */ | |
66 | {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN}, /* locks up */ | |
67 | {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN}, /* responds to all lun */ | |
68 | {"MICROTEK", "ScanMakerIII", "2.30", BLIST_NOLUN}, /* responds to all lun */ | |
69 | {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},/* locks up */ | |
70 | {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN}, /* responds to all lun */ | |
71 | {"RODIME", "RO3000S", "2.33", BLIST_NOLUN}, /* locks up */ | |
72 | {"SUN", "SENA", NULL, BLIST_NOLUN}, /* responds to all luns */ | |
73 | /* | |
74 | * The following causes a failed REQUEST SENSE on lun 1 for | |
75 | * aha152x controller, which causes SCSI code to reset bus. | |
76 | */ | |
77 | {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN}, | |
78 | /* | |
79 | * The following causes a failed REQUEST SENSE on lun 1 for | |
80 | * aha152x controller, which causes SCSI code to reset bus. | |
81 | */ | |
82 | {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN}, | |
83 | {"SEAGATE", "ST296", "921", BLIST_NOLUN}, /* responds to all lun */ | |
84 | {"SEAGATE", "ST1581", "6538", BLIST_NOLUN}, /* responds to all lun */ | |
85 | {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN}, | |
86 | {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN}, | |
87 | {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN}, | |
88 | {"SONY", "CD-ROM CDU-8012", NULL, BLIST_NOLUN}, | |
89 | {"SONY", "SDT-5000", "3.17", BLIST_SELECT_NO_ATN}, | |
90 | {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN}, /* locks up */ | |
91 | {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN}, /* locks up */ | |
92 | /* | |
93 | * The following causes a failed REQUEST SENSE on lun 1 for | |
94 | * seagate controller, which causes SCSI code to reset bus. | |
95 | */ | |
96 | {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN}, | |
97 | {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN}, /* responds to all lun */ | |
98 | /* | |
99 | * The following causes a failed REQUEST SENSE on lun 1 for | |
100 | * seagate controller, which causes SCSI code to reset bus. | |
101 | */ | |
102 | {"HP", "C1750A", "3226", BLIST_NOLUN}, /* scanjet iic */ | |
103 | {"HP", "C1790A", "", BLIST_NOLUN}, /* scanjet iip */ | |
104 | {"HP", "C2500A", "", BLIST_NOLUN}, /* scanjet iicx */ | |
105 | {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* locks up */ | |
106 | {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN}, /* responds to all lun */ | |
107 | {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN}, /* locks up */ | |
108 | {"NEC", "D3856", "0009", BLIST_NOLUN}, | |
109 | {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN}, /* locks up */ | |
110 | {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN}, /* locks up */ | |
111 | {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN}, /* locks up */ | |
112 | {"RELISYS", "Scorpio", NULL, BLIST_NOLUN}, /* responds to all lun */ | |
113 | {"SANKYO", "CP525", "6.64", BLIST_NOLUN}, /* causes failed REQ SENSE, extra reset */ | |
114 | {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN}, | |
1c536315 | 115 | {"transtec", "T5008", "0001", BLIST_NOREPORTLUN }, |
1da177e4 LT |
116 | {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN}, /* locks up */ |
117 | {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* locks up */ | |
118 | {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* locks up */ | |
119 | {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* locks up */ | |
0d7323c8 | 120 | {"", "Scanner", "1.80", BLIST_NOLUN}, /* responds to all lun */ |
1da177e4 LT |
121 | |
122 | /* | |
123 | * Other types of devices that have special flags. | |
124 | * Note that all USB devices should have the BLIST_INQUIRY_36 flag. | |
125 | */ | |
126 | {"3PARdata", "VV", NULL, BLIST_REPORTLUN2}, | |
127 | {"ADAPTEC", "AACRAID", NULL, BLIST_FORCELUN}, | |
128 | {"ADAPTEC", "Adaptec 5400S", NULL, BLIST_FORCELUN}, | |
129 | {"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN}, | |
130 | {"BELKIN", "USB 2 HS-CF", "1.95", BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
80dc3e06 | 131 | {"BROWNIE", "1200U3P", NULL, BLIST_NOREPORTLUN}, |
98acfc7e | 132 | {"BROWNIE", "1600U3P", NULL, BLIST_NOREPORTLUN}, |
1da177e4 LT |
133 | {"CANON", "IPUBJD", NULL, BLIST_SPARSELUN}, |
134 | {"CBOX3", "USB Storage-SMC", "300A", BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
135 | {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN}, /* CMD RAID Controller */ | |
136 | {"CNSI", "G7324", NULL, BLIST_SPARSELUN}, /* Chaparral G7324 RAID */ | |
137 | {"CNSi", "G8324", NULL, BLIST_SPARSELUN}, /* Chaparral G8324 RAID */ | |
4d7db04a JB |
138 | {"COMPAQ", "ARRAY CONTROLLER", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | |
139 | BLIST_MAX_512 | BLIST_REPORTLUN2}, /* Compaq RA4x00 */ | |
140 | {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN | BLIST_MAX_512}, /* Compaq RA4x00 */ | |
1da177e4 LT |
141 | {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN}, |
142 | {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, | |
143 | {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, | |
144 | {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD}, | |
145 | {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN}, | |
507caac7 | 146 | {"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD}, |
1da177e4 LT |
147 | {"DELL", "PV660F", NULL, BLIST_SPARSELUN}, |
148 | {"DELL", "PV660F PSEUDO", NULL, BLIST_SPARSELUN}, | |
149 | {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN}, /* Dell PV 530F */ | |
150 | {"DELL", "PV530F", NULL, BLIST_SPARSELUN}, | |
151 | {"DELL", "PERCRAID", NULL, BLIST_FORCELUN}, | |
152 | {"DGC", "RAID", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, storage on LUN 0 */ | |
153 | {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, no storage on LUN 0 */ | |
3441afc6 | 154 | {"EMC", "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, |
1da177e4 LT |
155 | {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN}, |
156 | {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN}, | |
80b1c7bd | 157 | {"easyRAID", "16P", NULL, BLIST_NOREPORTLUN}, |
158 | {"easyRAID", "X6P", NULL, BLIST_NOREPORTLUN}, | |
159 | {"easyRAID", "F8", NULL, BLIST_NOREPORTLUN}, | |
1da177e4 LT |
160 | {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, |
161 | {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
162 | {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
163 | {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
164 | {"HITACHI", "DF400", "*", BLIST_SPARSELUN}, | |
165 | {"HITACHI", "DF500", "*", BLIST_SPARSELUN}, | |
166 | {"HITACHI", "DF600", "*", BLIST_SPARSELUN}, | |
13f7e5ac KG |
167 | {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN}, |
168 | {"HITACHI", "OPEN-E", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN}, | |
f70cfa9b MC |
169 | {"HITACHI", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, |
170 | {"HITACHI", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
171 | {"HITACHI", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
172 | {"HITACHI", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
173 | {"HITACHI", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
1da177e4 | 174 | {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */ |
9ba0883c | 175 | {"HP", "OPEN-", "*", BLIST_REPORTLUN2}, /* HP XP Arrays */ |
1da177e4 LT |
176 | {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN}, |
177 | {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD}, | |
178 | {"HP", "C1557A", NULL, BLIST_FORCELUN}, | |
179 | {"HP", "C3323-300", "4269", BLIST_NOTQ}, | |
c3d83368 | 180 | {"HP", "C5713A", NULL, BLIST_NOREPORTLUN}, |
f70cfa9b MC |
181 | {"HP", "DF400", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, |
182 | {"HP", "DF500", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
183 | {"HP", "DF600", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
184 | {"HP", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
185 | {"HP", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
186 | {"HP", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
187 | {"HP", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
188 | {"HP", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
1da177e4 LT |
189 | {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN}, |
190 | {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
191 | {"IBM", "2105", NULL, BLIST_RETRY_HWERROR}, | |
192 | {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN}, | |
193 | {"IOMEGA", "Io20S *F", NULL, BLIST_KEY}, | |
194 | {"INSITE", "Floptical F*8I", NULL, BLIST_KEY}, | |
195 | {"INSITE", "I325VM", NULL, BLIST_KEY}, | |
196 | {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36}, | |
197 | {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN}, | |
198 | {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
199 | {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36}, | |
200 | {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36}, | |
201 | {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN}, | |
202 | {"MegaRAID", "LD", NULL, BLIST_FORCELUN}, | |
203 | {"MICROP", "4110", NULL, BLIST_NOTQ}, | |
204 | {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2}, | |
205 | {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN}, | |
206 | {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
207 | {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
208 | {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
12427d99 | 209 | {"NEC", "iStorage", NULL, BLIST_REPORTLUN2}, |
1da177e4 LT |
210 | {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, |
211 | {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
212 | {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
213 | {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
214 | {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, | |
f4fd20bf | 215 | {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, |
e0b2e597 | 216 | {"Promise", "", NULL, BLIST_SPARSELUN}, |
2ffb45c6 | 217 | {"QUANTUM", "XP34301", "1071", BLIST_NOTQ}, |
1da177e4 LT |
218 | {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN}, |
219 | {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN}, | |
220 | {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ}, /* Chokes on tagged INQUIRY */ | |
221 | {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ}, | |
222 | {"SGI", "RAID3", "*", BLIST_SPARSELUN}, | |
223 | {"SGI", "RAID5", "*", BLIST_SPARSELUN}, | |
224 | {"SGI", "TP9100", "*", BLIST_REPORTLUN2}, | |
225 | {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH}, | |
48690405 | 226 | {"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH}, |
debf4777 | 227 | {"SUN", "Universal Xport", "*", BLIST_NO_ULD_ATTACH}, |
1da177e4 LT |
228 | {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36}, |
229 | {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN}, | |
230 | {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */ | |
231 | {"ST650211", "CF", NULL, BLIST_RETRY_HWERROR}, | |
232 | {"SUN", "T300", "*", BLIST_SPARSELUN}, | |
233 | {"SUN", "T4", "*", BLIST_SPARSELUN}, | |
234 | {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN}, | |
5f619c5b | 235 | {"Tornado-", "F4", "*", BLIST_NOREPORTLUN}, |
1da177e4 LT |
236 | {"TOSHIBA", "CDROM", NULL, BLIST_ISROM}, |
237 | {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM}, | |
238 | {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36}, | |
239 | {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN}, | |
240 | {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN}, | |
241 | {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN}, | |
242 | {"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN}, | |
243 | {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, | |
244 | {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN}, | |
245 | {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN}, | |
246 | { NULL, NULL, NULL, 0 }, | |
247 | }; | |
248 | ||
249 | /* | |
250 | * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into | |
251 | * devinfo vendor and model strings. | |
252 | */ | |
253 | static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length, | |
254 | char *from, int compatible) | |
255 | { | |
256 | size_t from_length; | |
257 | ||
258 | from_length = strlen(from); | |
259 | strncpy(to, from, min(to_length, from_length)); | |
260 | if (from_length < to_length) { | |
261 | if (compatible) { | |
262 | /* | |
263 | * NUL terminate the string if it is short. | |
264 | */ | |
265 | to[from_length] = '\0'; | |
266 | } else { | |
267 | /* | |
268 | * space pad the string if it is short. | |
269 | */ | |
270 | strncpy(&to[from_length], spaces, | |
271 | to_length - from_length); | |
272 | } | |
273 | } | |
274 | if (from_length > to_length) | |
275 | printk(KERN_WARNING "%s: %s string '%s' is too long\n", | |
cadbd4a5 | 276 | __func__, name, from); |
1da177e4 LT |
277 | } |
278 | ||
279 | /** | |
eb44820c RL |
280 | * scsi_dev_info_list_add - add one dev_info list entry. |
281 | * @compatible: if true, null terminate short strings. Otherwise space pad. | |
1da177e4 LT |
282 | * @vendor: vendor string |
283 | * @model: model (product) string | |
284 | * @strflags: integer string | |
eb44820c | 285 | * @flags: if strflags NULL, use this flag value |
1da177e4 LT |
286 | * |
287 | * Description: | |
288 | * Create and add one dev_info entry for @vendor, @model, @strflags or | |
289 | * @flag. If @compatible, add to the tail of the list, do not space | |
290 | * pad, and set devinfo->compatible. The scsi_static_device_list entries | |
291 | * are added with @compatible 1 and @clfags NULL. | |
292 | * | |
293 | * Returns: 0 OK, -error on failure. | |
294 | **/ | |
295 | static int scsi_dev_info_list_add(int compatible, char *vendor, char *model, | |
296 | char *strflags, int flags) | |
297 | { | |
298 | struct scsi_dev_info_list *devinfo; | |
299 | ||
300 | devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL); | |
301 | if (!devinfo) { | |
cadbd4a5 | 302 | printk(KERN_ERR "%s: no memory\n", __func__); |
1da177e4 LT |
303 | return -ENOMEM; |
304 | } | |
305 | ||
306 | scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor), | |
307 | vendor, compatible); | |
308 | scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model), | |
309 | model, compatible); | |
310 | ||
311 | if (strflags) | |
312 | devinfo->flags = simple_strtoul(strflags, NULL, 0); | |
313 | else | |
314 | devinfo->flags = flags; | |
315 | ||
316 | devinfo->compatible = compatible; | |
317 | ||
318 | if (compatible) | |
319 | list_add_tail(&devinfo->dev_info_list, &scsi_dev_info_list); | |
320 | else | |
321 | list_add(&devinfo->dev_info_list, &scsi_dev_info_list); | |
322 | ||
323 | return 0; | |
324 | } | |
325 | ||
326 | /** | |
eb44820c | 327 | * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list. |
1da177e4 LT |
328 | * @dev_list: string of device flags to add |
329 | * | |
330 | * Description: | |
331 | * Parse dev_list, and add entries to the scsi_dev_info_list. | |
332 | * dev_list is of the form "vendor:product:flag,vendor:product:flag". | |
333 | * dev_list is modified via strsep. Can be called for command line | |
334 | * addition, for proc or mabye a sysfs interface. | |
335 | * | |
336 | * Returns: 0 if OK, -error on failure. | |
337 | **/ | |
338 | static int scsi_dev_info_list_add_str(char *dev_list) | |
339 | { | |
340 | char *vendor, *model, *strflags, *next; | |
341 | char *next_check; | |
342 | int res = 0; | |
343 | ||
344 | next = dev_list; | |
345 | if (next && next[0] == '"') { | |
346 | /* | |
347 | * Ignore both the leading and trailing quote. | |
348 | */ | |
349 | next++; | |
350 | next_check = ",\""; | |
351 | } else { | |
352 | next_check = ","; | |
353 | } | |
354 | ||
355 | /* | |
356 | * For the leading and trailing '"' case, the for loop comes | |
357 | * through the last time with vendor[0] == '\0'. | |
358 | */ | |
359 | for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0') | |
360 | && (res == 0); vendor = strsep(&next, ":")) { | |
361 | strflags = NULL; | |
362 | model = strsep(&next, ":"); | |
363 | if (model) | |
364 | strflags = strsep(&next, next_check); | |
365 | if (!model || !strflags) { | |
366 | printk(KERN_ERR "%s: bad dev info string '%s' '%s'" | |
cadbd4a5 | 367 | " '%s'\n", __func__, vendor, model, |
1da177e4 LT |
368 | strflags); |
369 | res = -EINVAL; | |
370 | } else | |
371 | res = scsi_dev_info_list_add(0 /* compatible */, vendor, | |
372 | model, strflags, 0); | |
373 | } | |
374 | return res; | |
375 | } | |
376 | ||
377 | /** | |
eb44820c RL |
378 | * get_device_flags - get device specific flags from the dynamic device list. |
379 | * @sdev: &scsi_device to get flags for | |
1da177e4 LT |
380 | * @vendor: vendor name |
381 | * @model: model name | |
382 | * | |
383 | * Description: | |
384 | * Search the scsi_dev_info_list for an entry matching @vendor and | |
385 | * @model, if found, return the matching flags value, else return | |
eb44820c | 386 | * the host or global default settings. Called during scan time. |
1da177e4 | 387 | **/ |
7f23e146 JB |
388 | int scsi_get_device_flags(struct scsi_device *sdev, |
389 | const unsigned char *vendor, | |
390 | const unsigned char *model) | |
1da177e4 LT |
391 | { |
392 | struct scsi_dev_info_list *devinfo; | |
393 | unsigned int bflags; | |
394 | ||
395 | bflags = sdev->sdev_bflags; | |
396 | if (!bflags) | |
397 | bflags = scsi_default_dev_flags; | |
398 | ||
399 | list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) { | |
400 | if (devinfo->compatible) { | |
401 | /* | |
402 | * Behave like the older version of get_device_flags. | |
403 | */ | |
404 | size_t max; | |
405 | /* | |
406 | * XXX why skip leading spaces? If an odd INQUIRY | |
407 | * value, that should have been part of the | |
408 | * scsi_static_device_list[] entry, such as " FOO" | |
409 | * rather than "FOO". Since this code is already | |
410 | * here, and we don't know what device it is | |
411 | * trying to work with, leave it as-is. | |
412 | */ | |
413 | max = 8; /* max length of vendor */ | |
414 | while ((max > 0) && *vendor == ' ') { | |
415 | max--; | |
416 | vendor++; | |
417 | } | |
418 | /* | |
419 | * XXX removing the following strlen() would be | |
420 | * good, using it means that for a an entry not in | |
421 | * the list, we scan every byte of every vendor | |
422 | * listed in scsi_static_device_list[], and never match | |
423 | * a single one (and still have to compare at | |
424 | * least the first byte of each vendor). | |
425 | */ | |
426 | if (memcmp(devinfo->vendor, vendor, | |
427 | min(max, strlen(devinfo->vendor)))) | |
428 | continue; | |
429 | /* | |
430 | * Skip spaces again. | |
431 | */ | |
432 | max = 16; /* max length of model */ | |
433 | while ((max > 0) && *model == ' ') { | |
434 | max--; | |
435 | model++; | |
436 | } | |
437 | if (memcmp(devinfo->model, model, | |
438 | min(max, strlen(devinfo->model)))) | |
439 | continue; | |
440 | return devinfo->flags; | |
441 | } else { | |
442 | if (!memcmp(devinfo->vendor, vendor, | |
443 | sizeof(devinfo->vendor)) && | |
444 | !memcmp(devinfo->model, model, | |
445 | sizeof(devinfo->model))) | |
446 | return devinfo->flags; | |
447 | } | |
448 | } | |
449 | return bflags; | |
450 | } | |
451 | ||
452 | #ifdef CONFIG_SCSI_PROC_FS | |
352ced8e | 453 | static int devinfo_seq_show(struct seq_file *m, void *v) |
1da177e4 | 454 | { |
352ced8e AD |
455 | struct scsi_dev_info_list *devinfo = |
456 | list_entry(v, struct scsi_dev_info_list, dev_info_list); | |
1da177e4 | 457 | |
352ced8e | 458 | seq_printf(m, "'%.8s' '%.16s' 0x%x\n", |
1da177e4 | 459 | devinfo->vendor, devinfo->model, devinfo->flags); |
352ced8e AD |
460 | return 0; |
461 | } | |
462 | ||
463 | static void * devinfo_seq_start(struct seq_file *m, loff_t *pos) | |
464 | { | |
465 | return seq_list_start(&scsi_dev_info_list, *pos); | |
466 | } | |
1da177e4 | 467 | |
352ced8e AD |
468 | static void * devinfo_seq_next(struct seq_file *m, void *v, loff_t *pos) |
469 | { | |
470 | return seq_list_next(v, &scsi_dev_info_list, pos); | |
471 | } | |
472 | ||
473 | static void devinfo_seq_stop(struct seq_file *m, void *v) | |
474 | { | |
475 | } | |
476 | ||
477 | static const struct seq_operations scsi_devinfo_seq_ops = { | |
478 | .start = devinfo_seq_start, | |
479 | .next = devinfo_seq_next, | |
480 | .stop = devinfo_seq_stop, | |
481 | .show = devinfo_seq_show, | |
482 | }; | |
483 | ||
484 | static int proc_scsi_devinfo_open(struct inode *inode, struct file *file) | |
485 | { | |
486 | return seq_open(file, &scsi_devinfo_seq_ops); | |
1da177e4 LT |
487 | } |
488 | ||
489 | /* | |
eb44820c | 490 | * proc_scsi_dev_info_write - allow additions to scsi_dev_info_list via /proc. |
1da177e4 | 491 | * |
eb44820c RL |
492 | * Description: Adds a black/white list entry for vendor and model with an |
493 | * integer value of flag to the scsi device info list. | |
494 | * To use, echo "vendor:model:flag" > /proc/scsi/device_info | |
1da177e4 | 495 | */ |
352ced8e AD |
496 | static ssize_t proc_scsi_devinfo_write(struct file *file, |
497 | const char __user *buf, | |
498 | size_t length, loff_t *ppos) | |
1da177e4 LT |
499 | { |
500 | char *buffer; | |
352ced8e | 501 | ssize_t err = length; |
1da177e4 LT |
502 | |
503 | if (!buf || length>PAGE_SIZE) | |
504 | return -EINVAL; | |
505 | if (!(buffer = (char *) __get_free_page(GFP_KERNEL))) | |
506 | return -ENOMEM; | |
507 | if (copy_from_user(buffer, buf, length)) { | |
508 | err =-EFAULT; | |
509 | goto out; | |
510 | } | |
511 | ||
512 | if (length < PAGE_SIZE) | |
513 | buffer[length] = '\0'; | |
514 | else if (buffer[PAGE_SIZE-1]) { | |
515 | err = -EINVAL; | |
516 | goto out; | |
517 | } | |
518 | ||
519 | scsi_dev_info_list_add_str(buffer); | |
520 | ||
521 | out: | |
522 | free_page((unsigned long)buffer); | |
523 | return err; | |
524 | } | |
352ced8e AD |
525 | |
526 | static const struct file_operations scsi_devinfo_proc_fops = { | |
527 | .owner = THIS_MODULE, | |
528 | .open = proc_scsi_devinfo_open, | |
529 | .read = seq_read, | |
530 | .write = proc_scsi_devinfo_write, | |
531 | .llseek = seq_lseek, | |
532 | .release = seq_release, | |
533 | }; | |
1da177e4 LT |
534 | #endif /* CONFIG_SCSI_PROC_FS */ |
535 | ||
536 | module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0); | |
537 | MODULE_PARM_DESC(dev_flags, | |
538 | "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white" | |
539 | " list entries for vendor and model with an integer value of flags" | |
540 | " to the scsi device info list"); | |
541 | ||
542 | module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR); | |
543 | MODULE_PARM_DESC(default_dev_flags, | |
544 | "scsi default device flag integer value"); | |
545 | ||
546 | /** | |
eb44820c | 547 | * scsi_dev_info_list_delete - called from scsi.c:exit_scsi to remove the scsi_dev_info_list. |
1da177e4 LT |
548 | **/ |
549 | void scsi_exit_devinfo(void) | |
550 | { | |
551 | struct list_head *lh, *lh_next; | |
552 | struct scsi_dev_info_list *devinfo; | |
553 | ||
554 | #ifdef CONFIG_SCSI_PROC_FS | |
555 | remove_proc_entry("scsi/device_info", NULL); | |
556 | #endif | |
557 | ||
558 | list_for_each_safe(lh, lh_next, &scsi_dev_info_list) { | |
559 | devinfo = list_entry(lh, struct scsi_dev_info_list, | |
560 | dev_info_list); | |
561 | kfree(devinfo); | |
562 | } | |
563 | } | |
564 | ||
565 | /** | |
c93ff979 | 566 | * scsi_init_devinfo - set up the dynamic device list. |
1da177e4 LT |
567 | * |
568 | * Description: | |
eb44820c | 569 | * Add command line entries from scsi_dev_flags, then add |
1da177e4 | 570 | * scsi_static_device_list entries to the scsi device info list. |
eb44820c | 571 | */ |
1da177e4 LT |
572 | int __init scsi_init_devinfo(void) |
573 | { | |
574 | #ifdef CONFIG_SCSI_PROC_FS | |
575 | struct proc_dir_entry *p; | |
576 | #endif | |
577 | int error, i; | |
578 | ||
579 | error = scsi_dev_info_list_add_str(scsi_dev_flags); | |
580 | if (error) | |
581 | return error; | |
582 | ||
583 | for (i = 0; scsi_static_device_list[i].vendor; i++) { | |
584 | error = scsi_dev_info_list_add(1 /* compatibile */, | |
585 | scsi_static_device_list[i].vendor, | |
586 | scsi_static_device_list[i].model, | |
587 | NULL, | |
588 | scsi_static_device_list[i].flags); | |
589 | if (error) | |
590 | goto out; | |
591 | } | |
592 | ||
593 | #ifdef CONFIG_SCSI_PROC_FS | |
352ced8e | 594 | p = proc_create("scsi/device_info", 0, NULL, &scsi_devinfo_proc_fops); |
1da177e4 LT |
595 | if (!p) { |
596 | error = -ENOMEM; | |
597 | goto out; | |
598 | } | |
1da177e4 LT |
599 | #endif /* CONFIG_SCSI_PROC_FS */ |
600 | ||
601 | out: | |
602 | if (error) | |
603 | scsi_exit_devinfo(); | |
604 | return error; | |
605 | } |