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