blob: 19c44f0781fd7d478858c2295d232f6f5ebe7f4c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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 */
19struct 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
28static const char spaces[] = " "; /* 16 of them */
29static unsigned scsi_default_dev_flags;
30static LIST_HEAD(scsi_dev_info_list);
31static 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 */
42static 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 */
Brian Kingf2536cb2006-04-26 13:48:11 -050059 {"IBM", "2104-DU3", NULL, BLIST_NOLUN}, /* locks up */
60 {"IBM", "2104-TU3", NULL, BLIST_NOLUN}, /* locks up */
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 {"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},
James Bottomley1c536312005-09-12 09:15:14 -0500115 {"transtec", "T5008", "0001", BLIST_NOREPORTLUN },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 {"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 */
Dave Jones0d7323c2005-08-08 19:01:43 -0400120 {"", "Scanner", "1.80", BLIST_NOLUN}, /* responds to all lun */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
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},
Matthew Wilcox80dc3e02007-07-05 08:57:50 -0600131 {"BROWNIE", "1200U3P", NULL, BLIST_NOREPORTLUN},
Matthew Wilcox98acfc72006-03-01 12:04:46 -0700132 {"BROWNIE", "1600U3P", NULL, BLIST_NOREPORTLUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 {"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 */
James Bottomley4d7db042006-03-31 20:07:45 -0600138 {"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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 {"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},
James Bottomley507caac2005-08-09 12:57:11 -0500146 {"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 {"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 */
Mike Christie3441afc2006-09-30 20:42:28 -0400154 {"EMC", "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
156 {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN},
157 {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
158 {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
159 {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
160 {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
161 {"HITACHI", "DF400", "*", BLIST_SPARSELUN},
162 {"HITACHI", "DF500", "*", BLIST_SPARSELUN},
163 {"HITACHI", "DF600", "*", BLIST_SPARSELUN},
Kurt Garloff13f7e5a2006-04-03 15:20:08 +0200164 {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN},
165 {"HITACHI", "OPEN-E", "*", BLIST_ATTACH_PQ3 | BLIST_SPARSELUN | BLIST_LARGELUN},
Mike Christief70cfa92006-09-30 20:42:31 -0400166 {"HITACHI", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
167 {"HITACHI", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
168 {"HITACHI", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
169 {"HITACHI", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
170 {"HITACHI", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */
Hannes Reinecke9ba08832006-06-22 09:19:51 +0200172 {"HP", "OPEN-", "*", BLIST_REPORTLUN2}, /* HP XP Arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
174 {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
175 {"HP", "C1557A", NULL, BLIST_FORCELUN},
176 {"HP", "C3323-300", "4269", BLIST_NOTQ},
Thomas Bogendoerferc3d83362006-05-16 06:38:29 +0200177 {"HP", "C5713A", NULL, BLIST_NOREPORTLUN},
Mike Christief70cfa92006-09-30 20:42:31 -0400178 {"HP", "DF400", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
179 {"HP", "DF500", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
180 {"HP", "DF600", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
181 {"HP", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
182 {"HP", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
183 {"HP", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
184 {"HP", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
185 {"HP", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
187 {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
188 {"IBM", "2105", NULL, BLIST_RETRY_HWERROR},
189 {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
190 {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
191 {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
192 {"INSITE", "I325VM", NULL, BLIST_KEY},
193 {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
194 {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
195 {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
196 {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
197 {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
198 {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN},
199 {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
200 {"MICROP", "4110", NULL, BLIST_NOTQ},
201 {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
202 {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
203 {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
204 {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
205 {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
Mike Christie12427d92006-09-30 20:42:30 -0400206 {"NEC", "iStorage", NULL, BLIST_REPORTLUN2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
208 {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
209 {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
210 {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
211 {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
Karl Magnus Kolstoef4fd20b2005-10-17 10:05:42 +0200212 {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
Ed Line0b2e592007-05-09 20:50:33 -0800213 {"Promise", "", NULL, BLIST_SPARSELUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
215 {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
216 {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ}, /* Chokes on tagged INQUIRY */
217 {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
218 {"SGI", "RAID3", "*", BLIST_SPARSELUN},
219 {"SGI", "RAID5", "*", BLIST_SPARSELUN},
220 {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
221 {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
Anton Blanchard48690402005-09-06 18:08:14 +1000222 {"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
224 {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
225 {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */
226 {"ST650211", "CF", NULL, BLIST_RETRY_HWERROR},
227 {"SUN", "T300", "*", BLIST_SPARSELUN},
228 {"SUN", "T4", "*", BLIST_SPARSELUN},
229 {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
Mike Christie5f619c52006-09-30 20:42:29 -0400230 {"Tornado-", "F4", "*", BLIST_NOREPORTLUN},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
232 {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
233 {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
234 {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
235 {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
236 {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
237 {"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN},
238 {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
239 {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
240 {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
241 { NULL, NULL, NULL, 0 },
242};
243
244/*
245 * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
246 * devinfo vendor and model strings.
247 */
248static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
249 char *from, int compatible)
250{
251 size_t from_length;
252
253 from_length = strlen(from);
254 strncpy(to, from, min(to_length, from_length));
255 if (from_length < to_length) {
256 if (compatible) {
257 /*
258 * NUL terminate the string if it is short.
259 */
260 to[from_length] = '\0';
261 } else {
262 /*
263 * space pad the string if it is short.
264 */
265 strncpy(&to[from_length], spaces,
266 to_length - from_length);
267 }
268 }
269 if (from_length > to_length)
270 printk(KERN_WARNING "%s: %s string '%s' is too long\n",
271 __FUNCTION__, name, from);
272}
273
274/**
275 * scsi_dev_info_list_add: add one dev_info list entry.
276 * @vendor: vendor string
277 * @model: model (product) string
278 * @strflags: integer string
279 * @flag: if strflags NULL, use this flag value
280 *
281 * Description:
282 * Create and add one dev_info entry for @vendor, @model, @strflags or
283 * @flag. If @compatible, add to the tail of the list, do not space
284 * pad, and set devinfo->compatible. The scsi_static_device_list entries
285 * are added with @compatible 1 and @clfags NULL.
286 *
287 * Returns: 0 OK, -error on failure.
288 **/
289static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
290 char *strflags, int flags)
291{
292 struct scsi_dev_info_list *devinfo;
293
294 devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
295 if (!devinfo) {
296 printk(KERN_ERR "%s: no memory\n", __FUNCTION__);
297 return -ENOMEM;
298 }
299
300 scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
301 vendor, compatible);
302 scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
303 model, compatible);
304
305 if (strflags)
306 devinfo->flags = simple_strtoul(strflags, NULL, 0);
307 else
308 devinfo->flags = flags;
309
310 devinfo->compatible = compatible;
311
312 if (compatible)
313 list_add_tail(&devinfo->dev_info_list, &scsi_dev_info_list);
314 else
315 list_add(&devinfo->dev_info_list, &scsi_dev_info_list);
316
317 return 0;
318}
319
320/**
321 * scsi_dev_info_list_add_str: parse dev_list and add to the
322 * scsi_dev_info_list.
323 * @dev_list: string of device flags to add
324 *
325 * Description:
326 * Parse dev_list, and add entries to the scsi_dev_info_list.
327 * dev_list is of the form "vendor:product:flag,vendor:product:flag".
328 * dev_list is modified via strsep. Can be called for command line
329 * addition, for proc or mabye a sysfs interface.
330 *
331 * Returns: 0 if OK, -error on failure.
332 **/
333static int scsi_dev_info_list_add_str(char *dev_list)
334{
335 char *vendor, *model, *strflags, *next;
336 char *next_check;
337 int res = 0;
338
339 next = dev_list;
340 if (next && next[0] == '"') {
341 /*
342 * Ignore both the leading and trailing quote.
343 */
344 next++;
345 next_check = ",\"";
346 } else {
347 next_check = ",";
348 }
349
350 /*
351 * For the leading and trailing '"' case, the for loop comes
352 * through the last time with vendor[0] == '\0'.
353 */
354 for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
355 && (res == 0); vendor = strsep(&next, ":")) {
356 strflags = NULL;
357 model = strsep(&next, ":");
358 if (model)
359 strflags = strsep(&next, next_check);
360 if (!model || !strflags) {
361 printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
362 " '%s'\n", __FUNCTION__, vendor, model,
363 strflags);
364 res = -EINVAL;
365 } else
366 res = scsi_dev_info_list_add(0 /* compatible */, vendor,
367 model, strflags, 0);
368 }
369 return res;
370}
371
372/**
373 * get_device_flags - get device specific flags from the dynamic device
374 * list. Called during scan time.
375 * @vendor: vendor name
376 * @model: model name
377 *
378 * Description:
379 * Search the scsi_dev_info_list for an entry matching @vendor and
380 * @model, if found, return the matching flags value, else return
381 * the host or global default settings.
382 **/
James Bottomley7f23e142005-12-01 12:50:13 -0600383int scsi_get_device_flags(struct scsi_device *sdev,
384 const unsigned char *vendor,
385 const unsigned char *model)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 struct scsi_dev_info_list *devinfo;
388 unsigned int bflags;
389
390 bflags = sdev->sdev_bflags;
391 if (!bflags)
392 bflags = scsi_default_dev_flags;
393
394 list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
395 if (devinfo->compatible) {
396 /*
397 * Behave like the older version of get_device_flags.
398 */
399 size_t max;
400 /*
401 * XXX why skip leading spaces? If an odd INQUIRY
402 * value, that should have been part of the
403 * scsi_static_device_list[] entry, such as " FOO"
404 * rather than "FOO". Since this code is already
405 * here, and we don't know what device it is
406 * trying to work with, leave it as-is.
407 */
408 max = 8; /* max length of vendor */
409 while ((max > 0) && *vendor == ' ') {
410 max--;
411 vendor++;
412 }
413 /*
414 * XXX removing the following strlen() would be
415 * good, using it means that for a an entry not in
416 * the list, we scan every byte of every vendor
417 * listed in scsi_static_device_list[], and never match
418 * a single one (and still have to compare at
419 * least the first byte of each vendor).
420 */
421 if (memcmp(devinfo->vendor, vendor,
422 min(max, strlen(devinfo->vendor))))
423 continue;
424 /*
425 * Skip spaces again.
426 */
427 max = 16; /* max length of model */
428 while ((max > 0) && *model == ' ') {
429 max--;
430 model++;
431 }
432 if (memcmp(devinfo->model, model,
433 min(max, strlen(devinfo->model))))
434 continue;
435 return devinfo->flags;
436 } else {
437 if (!memcmp(devinfo->vendor, vendor,
438 sizeof(devinfo->vendor)) &&
439 !memcmp(devinfo->model, model,
440 sizeof(devinfo->model)))
441 return devinfo->flags;
442 }
443 }
444 return bflags;
445}
446
447#ifdef CONFIG_SCSI_PROC_FS
448/*
449 * proc_scsi_dev_info_read: dump the scsi_dev_info_list via
450 * /proc/scsi/device_info
451 */
452static int proc_scsi_devinfo_read(char *buffer, char **start,
453 off_t offset, int length)
454{
455 struct scsi_dev_info_list *devinfo;
456 int size, len = 0;
457 off_t begin = 0;
458 off_t pos = 0;
459
460 list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
461 size = sprintf(buffer + len, "'%.8s' '%.16s' 0x%x\n",
462 devinfo->vendor, devinfo->model, devinfo->flags);
463 len += size;
464 pos = begin + len;
465 if (pos < offset) {
466 len = 0;
467 begin = pos;
468 }
469 if (pos > offset + length)
470 goto stop_output;
471 }
472
473stop_output:
474 *start = buffer + (offset - begin); /* Start of wanted data */
475 len -= (offset - begin); /* Start slop */
476 if (len > length)
477 len = length; /* Ending slop */
478 return (len);
479}
480
481/*
482 * proc_scsi_dev_info_write: allow additions to the scsi_dev_info_list via
483 * /proc.
484 *
485 * Use: echo "vendor:model:flag" > /proc/scsi/device_info
486 *
487 * To add a black/white list entry for vendor and model with an integer
488 * value of flag to the scsi device info list.
489 */
490static int proc_scsi_devinfo_write(struct file *file, const char __user *buf,
491 unsigned long length, void *data)
492{
493 char *buffer;
494 int err = length;
495
496 if (!buf || length>PAGE_SIZE)
497 return -EINVAL;
498 if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
499 return -ENOMEM;
500 if (copy_from_user(buffer, buf, length)) {
501 err =-EFAULT;
502 goto out;
503 }
504
505 if (length < PAGE_SIZE)
506 buffer[length] = '\0';
507 else if (buffer[PAGE_SIZE-1]) {
508 err = -EINVAL;
509 goto out;
510 }
511
512 scsi_dev_info_list_add_str(buffer);
513
514out:
515 free_page((unsigned long)buffer);
516 return err;
517}
518#endif /* CONFIG_SCSI_PROC_FS */
519
520module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
521MODULE_PARM_DESC(dev_flags,
522 "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
523 " list entries for vendor and model with an integer value of flags"
524 " to the scsi device info list");
525
526module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
527MODULE_PARM_DESC(default_dev_flags,
528 "scsi default device flag integer value");
529
530/**
531 * scsi_dev_info_list_delete: called from scsi.c:exit_scsi to remove
532 * the scsi_dev_info_list.
533 **/
534void scsi_exit_devinfo(void)
535{
536 struct list_head *lh, *lh_next;
537 struct scsi_dev_info_list *devinfo;
538
539#ifdef CONFIG_SCSI_PROC_FS
540 remove_proc_entry("scsi/device_info", NULL);
541#endif
542
543 list_for_each_safe(lh, lh_next, &scsi_dev_info_list) {
544 devinfo = list_entry(lh, struct scsi_dev_info_list,
545 dev_info_list);
546 kfree(devinfo);
547 }
548}
549
550/**
551 * scsi_dev_list_init: set up the dynamic device list.
552 * @dev_list: string of device flags to add
553 *
554 * Description:
555 * Add command line @dev_list entries, then add
556 * scsi_static_device_list entries to the scsi device info list.
557 **/
558int __init scsi_init_devinfo(void)
559{
560#ifdef CONFIG_SCSI_PROC_FS
561 struct proc_dir_entry *p;
562#endif
563 int error, i;
564
565 error = scsi_dev_info_list_add_str(scsi_dev_flags);
566 if (error)
567 return error;
568
569 for (i = 0; scsi_static_device_list[i].vendor; i++) {
570 error = scsi_dev_info_list_add(1 /* compatibile */,
571 scsi_static_device_list[i].vendor,
572 scsi_static_device_list[i].model,
573 NULL,
574 scsi_static_device_list[i].flags);
575 if (error)
576 goto out;
577 }
578
579#ifdef CONFIG_SCSI_PROC_FS
580 p = create_proc_entry("scsi/device_info", 0, NULL);
581 if (!p) {
582 error = -ENOMEM;
583 goto out;
584 }
585
586 p->owner = THIS_MODULE;
587 p->get_info = proc_scsi_devinfo_read;
588 p->write_proc = proc_scsi_devinfo_write;
589#endif /* CONFIG_SCSI_PROC_FS */
590
591 out:
592 if (error)
593 scsi_exit_devinfo();
594 return error;
595}