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