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