9b340d9913402f0df1d0245f7896f058a528f75e
[linux-2.6.git] / drivers / scsi / scsi_devinfo.c
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 __initdata 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 */
59         {"IMS", "CDD521/10", "2.06", BLIST_NOLUN},      /* locks up */
60         {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN},     /* locks up */
61         {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN},     /* locks up */
62         {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN},   /* locks up */
63         {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN},     /* locks up */
64         {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN},     /* locks up */
65         {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN},    /* responds to all lun */
66         {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},/* locks up */
67         {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN},    /* responds to all lun */
68         {"RODIME", "RO3000S", "2.33", BLIST_NOLUN},     /* locks up */
69         {"SUN", "SENA", NULL, BLIST_NOLUN},             /* responds to all luns */
70         /*
71          * The following causes a failed REQUEST SENSE on lun 1 for
72          * aha152x controller, which causes SCSI code to reset bus.
73          */
74         {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},
75         /*
76          * The following causes a failed REQUEST SENSE on lun 1 for
77          * aha152x controller, which causes SCSI code to reset bus.
78          */
79         {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
80         {"SEAGATE", "ST296", "921", BLIST_NOLUN},       /* responds to all lun */
81         {"SEAGATE", "ST1581", "6538", BLIST_NOLUN},     /* responds to all lun */
82         {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
83         {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
84         {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
85         {"SONY", "CD-ROM CDU-8012", NULL, BLIST_NOLUN},
86         {"SONY", "SDT-5000", "3.17", BLIST_SELECT_NO_ATN},
87         {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN},   /* locks up */
88         {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN},       /* locks up */
89         /*
90          * The following causes a failed REQUEST SENSE on lun 1 for
91          * seagate controller, which causes SCSI code to reset bus.
92          */
93         {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},
94         {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN},        /* responds to all lun */
95         /*
96          * The following causes a failed REQUEST SENSE on lun 1 for
97          * seagate controller, which causes SCSI code to reset bus.
98          */
99         {"HP", "C1750A", "3226", BLIST_NOLUN},          /* scanjet iic */
100         {"HP", "C1790A", "", BLIST_NOLUN},              /* scanjet iip */
101         {"HP", "C2500A", "", BLIST_NOLUN},              /* scanjet iicx */
102         {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* locks up */
103         {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN},      /* responds to all lun */
104         {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN},     /* locks up */
105         {"NEC", "D3856", "0009", BLIST_NOLUN},
106         {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN},    /* locks up */
107         {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN},    /* locks up */
108         {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN},    /* locks up */
109         {"RELISYS", "Scorpio", NULL, BLIST_NOLUN},      /* responds to all lun */
110         {"SANKYO", "CP525", "6.64", BLIST_NOLUN},       /* causes failed REQ SENSE, extra reset */
111         {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN},
112         {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN},      /* locks up */
113         {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN},      /* locks up */
114         {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN},     /* locks up */
115         {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN},    /* locks up */
116
117         /*
118          * Other types of devices that have special flags.
119          * Note that all USB devices should have the BLIST_INQUIRY_36 flag.
120          */
121         {"3PARdata", "VV", NULL, BLIST_REPORTLUN2},
122         {"ADAPTEC", "AACRAID", NULL, BLIST_FORCELUN},
123         {"ADAPTEC", "Adaptec 5400S", NULL, BLIST_FORCELUN},
124         {"CANON", "IPUBJD", NULL, BLIST_SPARSELUN},
125         {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN},     /* CMD RAID Controller */
126         {"CNSI", "G7324", NULL, BLIST_SPARSELUN},       /* Chaparral G7324 RAID */
127         {"CNSi", "G8324", NULL, BLIST_SPARSELUN},       /* Chaparral G8324 RAID */
128         {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN},
129         {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN},
130         {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
131         {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
132         {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
133         {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
134         {"DEC", "HSG80", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
135         {"DELL", "PV660F", NULL, BLIST_SPARSELUN},
136         {"DELL", "PV660F   PSEUDO", NULL, BLIST_SPARSELUN},
137         {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN},     /* Dell PV 530F */
138         {"DELL", "PV530F", NULL, BLIST_SPARSELUN},
139         {"DELL", "PERCRAID", NULL, BLIST_FORCELUN},
140         {"DGC", "RAID", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, storage on LUN 0 */
141         {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, no storage on LUN 0 */
142         {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
143         {"EMULEX", "MD21/S2     ESDI", NULL, BLIST_SINGLELUN},
144         {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
145         {"HITACHI", "DF400", "*", BLIST_SPARSELUN},
146         {"HITACHI", "DF500", "*", BLIST_SPARSELUN},
147         {"HITACHI", "DF600", "*", BLIST_SPARSELUN},
148         {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN},       /* HP VA7400 */
149         {"HP", "OPEN-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP XP Arrays */
150         {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
151         {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
152         {"HP", "C1557A", NULL, BLIST_FORCELUN},
153         {"HP", "C3323-300", "4269", BLIST_NOTQ},
154         {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
155         {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
156         {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
157         {"IOMEGA", "Io20S         *F", NULL, BLIST_KEY},
158         {"INSITE", "Floptical   F*8I", NULL, BLIST_KEY},
159         {"INSITE", "I325VM", NULL, BLIST_KEY},
160         {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
161         {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
162         {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
163         {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
164         {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
165         {"Medion", "Flash XL  MMC/SD", "2.6D", BLIST_FORCELUN},
166         {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
167         {"MICROP", "4110", NULL, BLIST_NOTQ},
168         {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
169         {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
170         {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
171         {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
172         {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
173         {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
174         {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
175         {"OTi", "CF CARD Reader", "2.00", BLIST_FORCELUN | BLIST_SINGLELUN},
176         {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
177         {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
178         {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
179         {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
180         {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ},    /* Chokes on tagged INQUIRY */
181         {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
182         {"SGI", "RAID3", "*", BLIST_SPARSELUN},
183         {"SGI", "RAID5", "*", BLIST_SPARSELUN},
184         {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
185         {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
186         {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
187         {"SONY", "TSL", NULL, BLIST_FORCELUN},          /* DDS3 & DDS4 autoloaders */
188         {"SUN", "T300", "*", BLIST_SPARSELUN},
189         {"SUN", "T4", "*", BLIST_SPARSELUN},
190         {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
191         {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
192         {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
193         {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
194         {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
195         {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
196         {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
197         {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
198         {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
199
200         /*
201          * USB multi card readers.
202          */
203         {"AFT", "CF  PRO-9XP", "9144", BLIST_FORCELUN | BLIST_INQUIRY_36},
204         {"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN | BLIST_INQUIRY_36},
205         {"BELKIN", "USB 2 HS-CF", "1.95",  BLIST_FORCELUN | BLIST_INQUIRY_36},
206         {"CBOX3", "USB Storage-SMC", "300A", BLIST_FORCELUN | BLIST_INQUIRY_36},
207         {"DMI", "MultiFlash", "3.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
208         {"eUSB", "Compact Flash", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
209         {"GENERIC", "Card Reader   CF", "v26F", BLIST_FORCELUN | BLIST_INQUIRY_36},
210         {"General", "USB Disk Drive","1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
211         {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
212         {"Generic", "USB Storage-SMC", "0090", BLIST_FORCELUN | BLIST_INQUIRY_36},
213         {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
214         {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
215         {"generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
216         {"IC", "USB Storage-CFC", "322E", BLIST_FORCELUN | BLIST_INQUIRY_36},
217         {"ICSI", "SD Card", "2.7C", BLIST_FORCELUN | BLIST_INQUIRY_36},
218         {"IOI", "Media Bay", "*", BLIST_FORCELUN | BLIST_INQUIRY_36},
219         {"Lexar", "Media Inc. SM/xD", "009E", BLIST_FORCELUN | BLIST_INQUIRY_36},
220         {"Lexar", "USB Storage-SMC", "I18A", BLIST_FORCELUN | BLIST_INQUIRY_36},
221         {"Medion", "Flash XL  MMC/SD", "2.6D", BLIST_FORCELUN | BLIST_INQUIRY_36},
222         {"OEI-USB", "CompactFlash", "1.01", BLIST_FORCELUN | BLIST_INQUIRY_36},
223         {"OEI-USB2", "CompactFlash", "2.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
224         {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
225         {"SMSC", "223 U HS-CF", "1.95", BLIST_FORCELUN | BLIST_INQUIRY_36},
226         {"SMSC", "USB 2 HS-CF", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
227         {"TwinMOS", "7-in-1 Card RWCF", "0100", BLIST_FORCELUN | BLIST_INQUIRY_36},
228         {"USB2.0", "CardReader CF RW", "0.0>", BLIST_FORCELUN | BLIST_INQUIRY_36},
229         {"USB2.0", "CardReader SM RW", "0814", BLIST_FORCELUN | BLIST_INQUIRY_36},
230         {"USB2.0", "CF  CardReader", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
231         {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
232         {"Y-E DATA", "CF Card Reader", "1.03", BLIST_FORCELUN | BLIST_INQUIRY_36},
233         {"Zynet", "USB Storage-SMC", "I03A", BLIST_FORCELUN | BLIST_INQUIRY_36},
234
235         { NULL, NULL, NULL, 0 },
236 };
237
238 /*
239  * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
240  * devinfo vendor and model strings.
241  */
242 static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
243                                 char *from, int compatible)
244 {
245         size_t from_length;
246
247         from_length = strlen(from);
248         strncpy(to, from, min(to_length, from_length));
249         if (from_length < to_length) {
250                 if (compatible) {
251                         /*
252                          * NUL terminate the string if it is short.
253                          */
254                         to[from_length] = '\0';
255                 } else {
256                         /* 
257                          * space pad the string if it is short. 
258                          */
259                         strncpy(&to[from_length], spaces,
260                                 to_length - from_length);
261                 }
262         }
263         if (from_length > to_length)
264                  printk(KERN_WARNING "%s: %s string '%s' is too long\n",
265                         __FUNCTION__, name, from);
266 }
267
268 /**
269  * scsi_dev_info_list_add: add one dev_info list entry.
270  * @vendor:     vendor string
271  * @model:      model (product) string
272  * @strflags:   integer string
273  * @flag:       if strflags NULL, use this flag value
274  *
275  * Description:
276  *      Create and add one dev_info entry for @vendor, @model, @strflags or
277  *      @flag. If @compatible, add to the tail of the list, do not space
278  *      pad, and set devinfo->compatible. The scsi_static_device_list entries
279  *      are added with @compatible 1 and @clfags NULL.
280  *
281  * Returns: 0 OK, -error on failure.
282  **/
283 static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
284                             char *strflags, int flags)
285 {
286         struct scsi_dev_info_list *devinfo;
287
288         devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
289         if (!devinfo) {
290                 printk(KERN_ERR "%s: no memory\n", __FUNCTION__);
291                 return -ENOMEM;
292         }
293
294         scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
295                             vendor, compatible);
296         scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
297                             model, compatible);
298
299         if (strflags)
300                 devinfo->flags = simple_strtoul(strflags, NULL, 0);
301         else
302                 devinfo->flags = flags;
303
304         devinfo->compatible = compatible;
305
306         if (compatible)
307                 list_add_tail(&devinfo->dev_info_list, &scsi_dev_info_list);
308         else
309                 list_add(&devinfo->dev_info_list, &scsi_dev_info_list);
310
311         return 0;
312 }
313
314 /**
315  * scsi_dev_info_list_add_str: parse dev_list and add to the
316  * scsi_dev_info_list.
317  * @dev_list:   string of device flags to add
318  *
319  * Description:
320  *      Parse dev_list, and add entries to the scsi_dev_info_list.
321  *      dev_list is of the form "vendor:product:flag,vendor:product:flag".
322  *      dev_list is modified via strsep. Can be called for command line
323  *      addition, for proc or mabye a sysfs interface.
324  *
325  * Returns: 0 if OK, -error on failure.
326  **/
327 static int scsi_dev_info_list_add_str(char *dev_list)
328 {
329         char *vendor, *model, *strflags, *next;
330         char *next_check;
331         int res = 0;
332
333         next = dev_list;
334         if (next && next[0] == '"') {
335                 /*
336                  * Ignore both the leading and trailing quote.
337                  */
338                 next++;
339                 next_check = ",\"";
340         } else {
341                 next_check = ",";
342         }
343
344         /*
345          * For the leading and trailing '"' case, the for loop comes
346          * through the last time with vendor[0] == '\0'.
347          */
348         for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
349              && (res == 0); vendor = strsep(&next, ":")) {
350                 strflags = NULL;
351                 model = strsep(&next, ":");
352                 if (model)
353                         strflags = strsep(&next, next_check);
354                 if (!model || !strflags) {
355                         printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
356                                " '%s'\n", __FUNCTION__, vendor, model,
357                                strflags);
358                         res = -EINVAL;
359                 } else
360                         res = scsi_dev_info_list_add(0 /* compatible */, vendor,
361                                                      model, strflags, 0);
362         }
363         return res;
364 }
365
366 /**
367  * get_device_flags - get device specific flags from the dynamic device
368  * list. Called during scan time.
369  * @vendor:     vendor name
370  * @model:      model name
371  *
372  * Description:
373  *     Search the scsi_dev_info_list for an entry matching @vendor and
374  *     @model, if found, return the matching flags value, else return
375  *     the host or global default settings.
376  **/
377 int scsi_get_device_flags(struct scsi_device *sdev, unsigned char *vendor,
378                           unsigned char *model)
379 {
380         struct scsi_dev_info_list *devinfo;
381         unsigned int bflags;
382
383         bflags = sdev->sdev_bflags;
384         if (!bflags)
385                 bflags = scsi_default_dev_flags;
386
387         list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
388                 if (devinfo->compatible) {
389                         /*
390                          * Behave like the older version of get_device_flags.
391                          */
392                         size_t max;
393                         /*
394                          * XXX why skip leading spaces? If an odd INQUIRY
395                          * value, that should have been part of the
396                          * scsi_static_device_list[] entry, such as "  FOO"
397                          * rather than "FOO". Since this code is already
398                          * here, and we don't know what device it is
399                          * trying to work with, leave it as-is.
400                          */
401                         max = 8;        /* max length of vendor */
402                         while ((max > 0) && *vendor == ' ') {
403                                 max--;
404                                 vendor++;
405                         }
406                         /*
407                          * XXX removing the following strlen() would be
408                          * good, using it means that for a an entry not in
409                          * the list, we scan every byte of every vendor
410                          * listed in scsi_static_device_list[], and never match
411                          * a single one (and still have to compare at
412                          * least the first byte of each vendor).
413                          */
414                         if (memcmp(devinfo->vendor, vendor,
415                                     min(max, strlen(devinfo->vendor))))
416                                 continue;
417                         /*
418                          * Skip spaces again.
419                          */
420                         max = 16;       /* max length of model */
421                         while ((max > 0) && *model == ' ') {
422                                 max--;
423                                 model++;
424                         }
425                         if (memcmp(devinfo->model, model,
426                                    min(max, strlen(devinfo->model))))
427                                 continue;
428                         return devinfo->flags;
429                 } else {
430                         if (!memcmp(devinfo->vendor, vendor,
431                                      sizeof(devinfo->vendor)) &&
432                              !memcmp(devinfo->model, model,
433                                       sizeof(devinfo->model)))
434                                 return devinfo->flags;
435                 }
436         }
437         return bflags;
438 }
439
440 #ifdef CONFIG_SCSI_PROC_FS
441 /* 
442  * proc_scsi_dev_info_read: dump the scsi_dev_info_list via
443  * /proc/scsi/device_info
444  */
445 static int proc_scsi_devinfo_read(char *buffer, char **start,
446                                   off_t offset, int length)
447 {
448         struct scsi_dev_info_list *devinfo;
449         int size, len = 0;
450         off_t begin = 0;
451         off_t pos = 0;
452
453         list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
454                 size = sprintf(buffer + len, "'%.8s' '%.16s' 0x%x\n",
455                         devinfo->vendor, devinfo->model, devinfo->flags);
456                 len += size;
457                 pos = begin + len;
458                 if (pos < offset) {
459                         len = 0;
460                         begin = pos;
461                 }
462                 if (pos > offset + length)
463                         goto stop_output;
464         }
465
466 stop_output:
467         *start = buffer + (offset - begin);     /* Start of wanted data */
468         len -= (offset - begin);        /* Start slop */
469         if (len > length)
470                 len = length;   /* Ending slop */
471         return (len);
472 }
473
474 /* 
475  * proc_scsi_dev_info_write: allow additions to the scsi_dev_info_list via
476  * /proc.
477  *
478  * Use: echo "vendor:model:flag" > /proc/scsi/device_info
479  *
480  * To add a black/white list entry for vendor and model with an integer
481  * value of flag to the scsi device info list.
482  */
483 static int proc_scsi_devinfo_write(struct file *file, const char __user *buf,
484                                    unsigned long length, void *data)
485 {
486         char *buffer;
487         int err = length;
488
489         if (!buf || length>PAGE_SIZE)
490                 return -EINVAL;
491         if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
492                 return -ENOMEM;
493         if (copy_from_user(buffer, buf, length)) {
494                 err =-EFAULT;
495                 goto out;
496         }
497
498         if (length < PAGE_SIZE)
499                 buffer[length] = '\0';
500         else if (buffer[PAGE_SIZE-1]) {
501                 err = -EINVAL;
502                 goto out;
503         }
504
505         scsi_dev_info_list_add_str(buffer);
506
507 out:
508         free_page((unsigned long)buffer);
509         return err;
510 }
511 #endif /* CONFIG_SCSI_PROC_FS */
512
513 module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
514 MODULE_PARM_DESC(dev_flags,
515          "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
516          " list entries for vendor and model with an integer value of flags"
517          " to the scsi device info list");
518
519 module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
520 MODULE_PARM_DESC(default_dev_flags,
521                  "scsi default device flag integer value");
522
523 /**
524  * scsi_dev_info_list_delete: called from scsi.c:exit_scsi to remove
525  *      the scsi_dev_info_list.
526  **/
527 void scsi_exit_devinfo(void)
528 {
529         struct list_head *lh, *lh_next;
530         struct scsi_dev_info_list *devinfo;
531
532 #ifdef CONFIG_SCSI_PROC_FS
533         remove_proc_entry("scsi/device_info", NULL);
534 #endif
535
536         list_for_each_safe(lh, lh_next, &scsi_dev_info_list) {
537                 devinfo = list_entry(lh, struct scsi_dev_info_list,
538                                      dev_info_list);
539                 kfree(devinfo);
540         }
541 }
542
543 /**
544  * scsi_dev_list_init: set up the dynamic device list.
545  * @dev_list:   string of device flags to add
546  *
547  * Description:
548  *      Add command line @dev_list entries, then add
549  *      scsi_static_device_list entries to the scsi device info list.
550  **/
551 int __init scsi_init_devinfo(void)
552 {
553 #ifdef CONFIG_SCSI_PROC_FS
554         struct proc_dir_entry *p;
555 #endif
556         int error, i;
557
558         error = scsi_dev_info_list_add_str(scsi_dev_flags);
559         if (error)
560                 return error;
561
562         for (i = 0; scsi_static_device_list[i].vendor; i++) {
563                 error = scsi_dev_info_list_add(1 /* compatibile */,
564                                 scsi_static_device_list[i].vendor,
565                                 scsi_static_device_list[i].model,
566                                 NULL,
567                                 scsi_static_device_list[i].flags);
568                 if (error)
569                         goto out;
570         }
571
572 #ifdef CONFIG_SCSI_PROC_FS
573         p = create_proc_entry("scsi/device_info", 0, NULL);
574         if (!p) {
575                 error = -ENOMEM;
576                 goto out;
577         }
578
579         p->owner = THIS_MODULE;
580         p->get_info = proc_scsi_devinfo_read;
581         p->write_proc = proc_scsi_devinfo_write;
582 #endif /* CONFIG_SCSI_PROC_FS */
583
584  out:
585         if (error)
586                 scsi_exit_devinfo();
587         return error;
588 }