vserver 1.9.5.x5
[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 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         {"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN},
125         {"BELKIN", "USB 2 HS-CF", "1.95",  BLIST_FORCELUN | BLIST_INQUIRY_36},
126         {"CANON", "IPUBJD", NULL, BLIST_SPARSELUN},
127         {"CBOX3", "USB Storage-SMC", "300A", BLIST_FORCELUN | BLIST_INQUIRY_36},
128         {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN},     /* CMD RAID Controller */
129         {"CNSI", "G7324", NULL, BLIST_SPARSELUN},       /* Chaparral G7324 RAID */
130         {"CNSi", "G8324", NULL, BLIST_SPARSELUN},       /* Chaparral G8324 RAID */
131         {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN},
132         {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN},
133         {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
134         {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
135         {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
136         {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
137         {"DEC", "HSG80", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
138         {"DELL", "PV660F", NULL, BLIST_SPARSELUN},
139         {"DELL", "PV660F   PSEUDO", NULL, BLIST_SPARSELUN},
140         {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN},     /* Dell PV 530F */
141         {"DELL", "PV530F", NULL, BLIST_SPARSELUN},
142         {"DELL", "PERCRAID", NULL, BLIST_FORCELUN},
143         {"DGC", "RAID", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, storage on LUN 0 */
144         {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, no storage on LUN 0 */
145         {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
146         {"EMULEX", "MD21/S2     ESDI", NULL, BLIST_SINGLELUN},
147         {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
148         {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
149         {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
150         {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
151         {"HITACHI", "DF400", "*", BLIST_SPARSELUN},
152         {"HITACHI", "DF500", "*", BLIST_SPARSELUN},
153         {"HITACHI", "DF600", "*", BLIST_SPARSELUN},
154         {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN},       /* HP VA7400 */
155         {"HP", "OPEN-", "*", BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP XP Arrays */
156         {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
157         {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
158         {"HP", "C1557A", NULL, BLIST_FORCELUN},
159         {"HP", "C3323-300", "4269", BLIST_NOTQ},
160         {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
161         {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
162         {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
163         {"IOMEGA", "Io20S         *F", NULL, BLIST_KEY},
164         {"INSITE", "Floptical   F*8I", NULL, BLIST_KEY},
165         {"INSITE", "I325VM", NULL, BLIST_KEY},
166         {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
167         {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
168         {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
169         {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
170         {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
171         {"Medion", "Flash XL  MMC/SD", "2.6D", BLIST_FORCELUN},
172         {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
173         {"MICROP", "4110", NULL, BLIST_NOTQ},
174         {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
175         {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
176         {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
177         {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
178         {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
179         {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
180         {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
181         {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
182         {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
183         {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
184         {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
185         {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
186         {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ},    /* Chokes on tagged INQUIRY */
187         {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
188         {"SGI", "RAID3", "*", BLIST_SPARSELUN},
189         {"SGI", "RAID5", "*", BLIST_SPARSELUN},
190         {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
191         {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
192         {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
193         {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
194         {"SONY", "TSL", NULL, BLIST_FORCELUN},          /* DDS3 & DDS4 autoloaders */
195         {"SUN", "T300", "*", BLIST_SPARSELUN},
196         {"SUN", "T4", "*", BLIST_SPARSELUN},
197         {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
198         {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
199         {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
200         {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
201         {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
202         {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
203         {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
204         {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
205         {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
206         {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
207         { NULL, NULL, NULL, 0 },
208 };
209
210 /*
211  * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
212  * devinfo vendor and model strings.
213  */
214 static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
215                                 char *from, int compatible)
216 {
217         size_t from_length;
218
219         from_length = strlen(from);
220         strncpy(to, from, min(to_length, from_length));
221         if (from_length < to_length) {
222                 if (compatible) {
223                         /*
224                          * NUL terminate the string if it is short.
225                          */
226                         to[from_length] = '\0';
227                 } else {
228                         /* 
229                          * space pad the string if it is short. 
230                          */
231                         strncpy(&to[from_length], spaces,
232                                 to_length - from_length);
233                 }
234         }
235         if (from_length > to_length)
236                  printk(KERN_WARNING "%s: %s string '%s' is too long\n",
237                         __FUNCTION__, name, from);
238 }
239
240 /**
241  * scsi_dev_info_list_add: add one dev_info list entry.
242  * @vendor:     vendor string
243  * @model:      model (product) string
244  * @strflags:   integer string
245  * @flag:       if strflags NULL, use this flag value
246  *
247  * Description:
248  *      Create and add one dev_info entry for @vendor, @model, @strflags or
249  *      @flag. If @compatible, add to the tail of the list, do not space
250  *      pad, and set devinfo->compatible. The scsi_static_device_list entries
251  *      are added with @compatible 1 and @clfags NULL.
252  *
253  * Returns: 0 OK, -error on failure.
254  **/
255 static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
256                             char *strflags, int flags)
257 {
258         struct scsi_dev_info_list *devinfo;
259
260         devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
261         if (!devinfo) {
262                 printk(KERN_ERR "%s: no memory\n", __FUNCTION__);
263                 return -ENOMEM;
264         }
265
266         scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
267                             vendor, compatible);
268         scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
269                             model, compatible);
270
271         if (strflags)
272                 devinfo->flags = simple_strtoul(strflags, NULL, 0);
273         else
274                 devinfo->flags = flags;
275
276         devinfo->compatible = compatible;
277
278         if (compatible)
279                 list_add_tail(&devinfo->dev_info_list, &scsi_dev_info_list);
280         else
281                 list_add(&devinfo->dev_info_list, &scsi_dev_info_list);
282
283         return 0;
284 }
285
286 /**
287  * scsi_dev_info_list_add_str: parse dev_list and add to the
288  * scsi_dev_info_list.
289  * @dev_list:   string of device flags to add
290  *
291  * Description:
292  *      Parse dev_list, and add entries to the scsi_dev_info_list.
293  *      dev_list is of the form "vendor:product:flag,vendor:product:flag".
294  *      dev_list is modified via strsep. Can be called for command line
295  *      addition, for proc or mabye a sysfs interface.
296  *
297  * Returns: 0 if OK, -error on failure.
298  **/
299 static int scsi_dev_info_list_add_str(char *dev_list)
300 {
301         char *vendor, *model, *strflags, *next;
302         char *next_check;
303         int res = 0;
304
305         next = dev_list;
306         if (next && next[0] == '"') {
307                 /*
308                  * Ignore both the leading and trailing quote.
309                  */
310                 next++;
311                 next_check = ",\"";
312         } else {
313                 next_check = ",";
314         }
315
316         /*
317          * For the leading and trailing '"' case, the for loop comes
318          * through the last time with vendor[0] == '\0'.
319          */
320         for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
321              && (res == 0); vendor = strsep(&next, ":")) {
322                 strflags = NULL;
323                 model = strsep(&next, ":");
324                 if (model)
325                         strflags = strsep(&next, next_check);
326                 if (!model || !strflags) {
327                         printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
328                                " '%s'\n", __FUNCTION__, vendor, model,
329                                strflags);
330                         res = -EINVAL;
331                 } else
332                         res = scsi_dev_info_list_add(0 /* compatible */, vendor,
333                                                      model, strflags, 0);
334         }
335         return res;
336 }
337
338 /**
339  * get_device_flags - get device specific flags from the dynamic device
340  * list. Called during scan time.
341  * @vendor:     vendor name
342  * @model:      model name
343  *
344  * Description:
345  *     Search the scsi_dev_info_list for an entry matching @vendor and
346  *     @model, if found, return the matching flags value, else return
347  *     the host or global default settings.
348  **/
349 int scsi_get_device_flags(struct scsi_device *sdev, unsigned char *vendor,
350                           unsigned char *model)
351 {
352         struct scsi_dev_info_list *devinfo;
353         unsigned int bflags;
354
355         bflags = sdev->sdev_bflags;
356         if (!bflags)
357                 bflags = scsi_default_dev_flags;
358
359         list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
360                 if (devinfo->compatible) {
361                         /*
362                          * Behave like the older version of get_device_flags.
363                          */
364                         size_t max;
365                         /*
366                          * XXX why skip leading spaces? If an odd INQUIRY
367                          * value, that should have been part of the
368                          * scsi_static_device_list[] entry, such as "  FOO"
369                          * rather than "FOO". Since this code is already
370                          * here, and we don't know what device it is
371                          * trying to work with, leave it as-is.
372                          */
373                         max = 8;        /* max length of vendor */
374                         while ((max > 0) && *vendor == ' ') {
375                                 max--;
376                                 vendor++;
377                         }
378                         /*
379                          * XXX removing the following strlen() would be
380                          * good, using it means that for a an entry not in
381                          * the list, we scan every byte of every vendor
382                          * listed in scsi_static_device_list[], and never match
383                          * a single one (and still have to compare at
384                          * least the first byte of each vendor).
385                          */
386                         if (memcmp(devinfo->vendor, vendor,
387                                     min(max, strlen(devinfo->vendor))))
388                                 continue;
389                         /*
390                          * Skip spaces again.
391                          */
392                         max = 16;       /* max length of model */
393                         while ((max > 0) && *model == ' ') {
394                                 max--;
395                                 model++;
396                         }
397                         if (memcmp(devinfo->model, model,
398                                    min(max, strlen(devinfo->model))))
399                                 continue;
400                         return devinfo->flags;
401                 } else {
402                         if (!memcmp(devinfo->vendor, vendor,
403                                      sizeof(devinfo->vendor)) &&
404                              !memcmp(devinfo->model, model,
405                                       sizeof(devinfo->model)))
406                                 return devinfo->flags;
407                 }
408         }
409         return bflags;
410 }
411
412 #ifdef CONFIG_SCSI_PROC_FS
413 /* 
414  * proc_scsi_dev_info_read: dump the scsi_dev_info_list via
415  * /proc/scsi/device_info
416  */
417 static int proc_scsi_devinfo_read(char *buffer, char **start,
418                                   off_t offset, int length)
419 {
420         struct scsi_dev_info_list *devinfo;
421         int size, len = 0;
422         off_t begin = 0;
423         off_t pos = 0;
424
425         list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
426                 size = sprintf(buffer + len, "'%.8s' '%.16s' 0x%x\n",
427                         devinfo->vendor, devinfo->model, devinfo->flags);
428                 len += size;
429                 pos = begin + len;
430                 if (pos < offset) {
431                         len = 0;
432                         begin = pos;
433                 }
434                 if (pos > offset + length)
435                         goto stop_output;
436         }
437
438 stop_output:
439         *start = buffer + (offset - begin);     /* Start of wanted data */
440         len -= (offset - begin);        /* Start slop */
441         if (len > length)
442                 len = length;   /* Ending slop */
443         return (len);
444 }
445
446 /* 
447  * proc_scsi_dev_info_write: allow additions to the scsi_dev_info_list via
448  * /proc.
449  *
450  * Use: echo "vendor:model:flag" > /proc/scsi/device_info
451  *
452  * To add a black/white list entry for vendor and model with an integer
453  * value of flag to the scsi device info list.
454  */
455 static int proc_scsi_devinfo_write(struct file *file, const char __user *buf,
456                                    unsigned long length, void *data)
457 {
458         char *buffer;
459         int err = length;
460
461         if (!buf || length>PAGE_SIZE)
462                 return -EINVAL;
463         if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
464                 return -ENOMEM;
465         if (copy_from_user(buffer, buf, length)) {
466                 err =-EFAULT;
467                 goto out;
468         }
469
470         if (length < PAGE_SIZE)
471                 buffer[length] = '\0';
472         else if (buffer[PAGE_SIZE-1]) {
473                 err = -EINVAL;
474                 goto out;
475         }
476
477         scsi_dev_info_list_add_str(buffer);
478
479 out:
480         free_page((unsigned long)buffer);
481         return err;
482 }
483 #endif /* CONFIG_SCSI_PROC_FS */
484
485 module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
486 MODULE_PARM_DESC(dev_flags,
487          "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
488          " list entries for vendor and model with an integer value of flags"
489          " to the scsi device info list");
490
491 module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
492 MODULE_PARM_DESC(default_dev_flags,
493                  "scsi default device flag integer value");
494
495 /**
496  * scsi_dev_info_list_delete: called from scsi.c:exit_scsi to remove
497  *      the scsi_dev_info_list.
498  **/
499 void scsi_exit_devinfo(void)
500 {
501         struct list_head *lh, *lh_next;
502         struct scsi_dev_info_list *devinfo;
503
504 #ifdef CONFIG_SCSI_PROC_FS
505         remove_proc_entry("scsi/device_info", NULL);
506 #endif
507
508         list_for_each_safe(lh, lh_next, &scsi_dev_info_list) {
509                 devinfo = list_entry(lh, struct scsi_dev_info_list,
510                                      dev_info_list);
511                 kfree(devinfo);
512         }
513 }
514
515 /**
516  * scsi_dev_list_init: set up the dynamic device list.
517  * @dev_list:   string of device flags to add
518  *
519  * Description:
520  *      Add command line @dev_list entries, then add
521  *      scsi_static_device_list entries to the scsi device info list.
522  **/
523 int __init scsi_init_devinfo(void)
524 {
525 #ifdef CONFIG_SCSI_PROC_FS
526         struct proc_dir_entry *p;
527 #endif
528         int error, i;
529
530         error = scsi_dev_info_list_add_str(scsi_dev_flags);
531         if (error)
532                 return error;
533
534         for (i = 0; scsi_static_device_list[i].vendor; i++) {
535                 error = scsi_dev_info_list_add(1 /* compatibile */,
536                                 scsi_static_device_list[i].vendor,
537                                 scsi_static_device_list[i].model,
538                                 NULL,
539                                 scsi_static_device_list[i].flags);
540                 if (error)
541                         goto out;
542         }
543
544 #ifdef CONFIG_SCSI_PROC_FS
545         p = create_proc_entry("scsi/device_info", 0, NULL);
546         if (!p) {
547                 error = -ENOMEM;
548                 goto out;
549         }
550
551         p->owner = THIS_MODULE;
552         p->get_info = proc_scsi_devinfo_read;
553         p->write_proc = proc_scsi_devinfo_write;
554 #endif /* CONFIG_SCSI_PROC_FS */
555
556  out:
557         if (error)
558                 scsi_exit_devinfo();
559         return error;
560 }