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