scsi_devinfo.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. #include <linux/blkdev.h>
  2. #include <linux/init.h>
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/moduleparam.h>
  6. #include <linux/proc_fs.h>
  7. #include <linux/seq_file.h>
  8. #include <scsi/scsi_device.h>
  9. #include <scsi/scsi_devinfo.h>
  10. #include "scsi_priv.h"
  11. /*
  12. * scsi_dev_info_list: structure to hold black/white listed devices.
  13. */
  14. struct scsi_dev_info_list {
  15. struct list_head dev_info_list;
  16. char vendor[8];
  17. char model[16];
  18. unsigned flags;
  19. unsigned compatible; /* for use with scsi_static_device_list entries */
  20. };
  21. static const char spaces[] = " "; /* 16 of them */
  22. static unsigned scsi_default_dev_flags;
  23. static LIST_HEAD(scsi_dev_info_list);
  24. static char scsi_dev_flags[256];
  25. /*
  26. * scsi_static_device_list: deprecated list of devices that require
  27. * settings that differ from the default, includes black-listed (broken)
  28. * devices. The entries here are added to the tail of scsi_dev_info_list
  29. * via scsi_dev_info_list_init.
  30. *
  31. * Do not add to this list, use the command line or proc interface to add
  32. * to the scsi_dev_info_list. This table will eventually go away.
  33. */
  34. static struct {
  35. char *vendor;
  36. char *model;
  37. char *revision; /* revision known to be bad, unused */
  38. unsigned flags;
  39. } scsi_static_device_list[] __initdata = {
  40. /*
  41. * The following devices are known not to tolerate a lun != 0 scan
  42. * for one reason or another. Some will respond to all luns,
  43. * others will lock up.
  44. */
  45. {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN}, /* locks up */
  46. {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN}, /* locks up */
  47. {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN}, /* locks up */
  48. {"DENON", "DRD-25X", "V", BLIST_NOLUN}, /* locks up */
  49. {"HITACHI", "DK312C", "CM81", BLIST_NOLUN}, /* responds to all lun */
  50. {"HITACHI", "DK314C", "CR21", BLIST_NOLUN}, /* responds to all lun */
  51. {"IMS", "CDD521/10", "2.06", BLIST_NOLUN}, /* locks up */
  52. {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN}, /* locks up */
  53. {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN}, /* locks up */
  54. {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN}, /* locks up */
  55. {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN}, /* locks up */
  56. {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN}, /* locks up */
  57. {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN}, /* responds to all lun */
  58. {"MICROTEK", "ScanMakerIII", "2.30", BLIST_NOLUN}, /* responds to all lun */
  59. {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},/* locks up */
  60. {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN}, /* responds to all lun */
  61. {"RODIME", "RO3000S", "2.33", BLIST_NOLUN}, /* locks up */
  62. {"SUN", "SENA", NULL, BLIST_NOLUN}, /* responds to all luns */
  63. /*
  64. * The following causes a failed REQUEST SENSE on lun 1 for
  65. * aha152x controller, which causes SCSI code to reset bus.
  66. */
  67. {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},
  68. /*
  69. * The following causes a failed REQUEST SENSE on lun 1 for
  70. * aha152x controller, which causes SCSI code to reset bus.
  71. */
  72. {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
  73. {"SEAGATE", "ST296", "921", BLIST_NOLUN}, /* responds to all lun */
  74. {"SEAGATE", "ST1581", "6538", BLIST_NOLUN}, /* responds to all lun */
  75. {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
  76. {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
  77. {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
  78. {"SONY", "CD-ROM CDU-8012", NULL, BLIST_NOLUN},
  79. {"SONY", "SDT-5000", "3.17", BLIST_SELECT_NO_ATN},
  80. {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN}, /* locks up */
  81. {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN}, /* locks up */
  82. /*
  83. * The following causes a failed REQUEST SENSE on lun 1 for
  84. * seagate controller, which causes SCSI code to reset bus.
  85. */
  86. {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},
  87. {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN}, /* responds to all lun */
  88. /*
  89. * The following causes a failed REQUEST SENSE on lun 1 for
  90. * seagate controller, which causes SCSI code to reset bus.
  91. */
  92. {"HP", "C1750A", "3226", BLIST_NOLUN}, /* scanjet iic */
  93. {"HP", "C1790A", "", BLIST_NOLUN}, /* scanjet iip */
  94. {"HP", "C2500A", "", BLIST_NOLUN}, /* scanjet iicx */
  95. {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* locks up */
  96. {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN}, /* responds to all lun */
  97. {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN}, /* locks up */
  98. {"NEC", "D3856", "0009", BLIST_NOLUN},
  99. {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN}, /* locks up */
  100. {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN}, /* locks up */
  101. {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN}, /* locks up */
  102. {"RELISYS", "Scorpio", NULL, BLIST_NOLUN}, /* responds to all lun */
  103. {"SANKYO", "CP525", "6.64", BLIST_NOLUN}, /* causes failed REQ SENSE, extra reset */
  104. {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN},
  105. {"transtec", "T5008", "0001", BLIST_NOREPORTLUN },
  106. {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN}, /* locks up */
  107. {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* locks up */
  108. {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* locks up */
  109. {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* locks up */
  110. {"", "Scanner", "1.80", BLIST_NOLUN}, /* responds to all lun */
  111. /*
  112. * Other types of devices that have special flags.
  113. * Note that all USB devices should have the BLIST_INQUIRY_36 flag.
  114. */
  115. {"3PARdata", "VV", NULL, BLIST_REPORTLUN2},
  116. {"ADAPTEC", "AACRAID", NULL, BLIST_FORCELUN},
  117. {"ADAPTEC", "Adaptec 5400S", NULL, BLIST_FORCELUN},
  118. {"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN},
  119. {"BELKIN", "USB 2 HS-CF", "1.95", BLIST_FORCELUN | BLIST_INQUIRY_36},
  120. {"BROWNIE", "1600U3P", NULL, BLIST_NOREPORTLUN},
  121. {"CANON", "IPUBJD", NULL, BLIST_SPARSELUN},
  122. {"CBOX3", "USB Storage-SMC", "300A", BLIST_FORCELUN | BLIST_INQUIRY_36},
  123. {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN}, /* CMD RAID Controller */
  124. {"CNSI", "G7324", NULL, BLIST_SPARSELUN}, /* Chaparral G7324 RAID */
  125. {"CNSi", "G8324", NULL, BLIST_SPARSELUN}, /* Chaparral G8324 RAID */
  126. {"COMPAQ", "ARRAY CONTROLLER", NULL, BLIST_SPARSELUN | BLIST_LARGELUN |
  127. BLIST_MAX_512 | BLIST_REPORTLUN2}, /* Compaq RA4x00 */
  128. {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN | BLIST_MAX_512}, /* Compaq RA4x00 */
  129. {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN},
  130. {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
  131. {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
  132. {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
  133. {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
  134. {"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
  135. {"DELL", "PV660F", NULL, BLIST_SPARSELUN},
  136. {"DELL", "PV660F PSEUDO", NULL, BLIST_SPARSELUN},
  137. {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN}, /* Dell PV 530F */
  138. {"DELL", "PV530F", NULL, BLIST_SPARSELUN},
  139. {"DELL", "PERCRAID", NULL, BLIST_FORCELUN},
  140. {"DGC", "RAID", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, storage on LUN 0 */
  141. {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, no storage on LUN 0 */
  142. {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
  143. {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN},
  144. {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  145. {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
  146. {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
  147. {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
  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_REPORTLUN2 | BLIST_NOSTARTONADD},
  155. {"HP", "C1557A", NULL, BLIST_FORCELUN},
  156. {"HP", "C3323-300", "4269", BLIST_NOTQ},
  157. {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
  158. {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  159. {"IBM", "2105", NULL, BLIST_RETRY_HWERROR},
  160. {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
  161. {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
  162. {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
  163. {"INSITE", "I325VM", NULL, BLIST_KEY},
  164. {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  165. {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
  166. {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  167. {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  168. {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  169. {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN},
  170. {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
  171. {"MICROP", "4110", NULL, BLIST_NOTQ},
  172. {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
  173. {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
  174. {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  175. {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  176. {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  177. {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  178. {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  179. {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  180. {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  181. {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  182. {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  183. {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
  184. {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
  185. {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ}, /* Chokes on tagged INQUIRY */
  186. {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
  187. {"SGI", "RAID3", "*", BLIST_SPARSELUN},
  188. {"SGI", "RAID5", "*", BLIST_SPARSELUN},
  189. {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
  190. {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  191. {"IBM", "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. {"ST650211", "CF", NULL, BLIST_RETRY_HWERROR},
  196. {"SUN", "T300", "*", BLIST_SPARSELUN},
  197. {"SUN", "T4", "*", BLIST_SPARSELUN},
  198. {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
  199. {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
  200. {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
  201. {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
  202. {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
  203. {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
  204. {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
  205. {"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN},
  206. {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  207. {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
  208. {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
  209. { NULL, NULL, NULL, 0 },
  210. };
  211. /*
  212. * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
  213. * devinfo vendor and model strings.
  214. */
  215. static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
  216. char *from, int compatible)
  217. {
  218. size_t from_length;
  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. * scsi_dev_info_list_add: add one dev_info list entry.
  241. * @vendor: vendor string
  242. * @model: model (product) string
  243. * @strflags: integer string
  244. * @flag: if strflags NULL, use this flag value
  245. *
  246. * Description:
  247. * Create and add one dev_info entry for @vendor, @model, @strflags or
  248. * @flag. If @compatible, add to the tail of the list, do not space
  249. * pad, and set devinfo->compatible. The scsi_static_device_list entries
  250. * are added with @compatible 1 and @clfags NULL.
  251. *
  252. * Returns: 0 OK, -error on failure.
  253. **/
  254. static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
  255. char *strflags, int flags)
  256. {
  257. struct scsi_dev_info_list *devinfo;
  258. devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
  259. if (!devinfo) {
  260. printk(KERN_ERR "%s: no memory\n", __FUNCTION__);
  261. return -ENOMEM;
  262. }
  263. scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
  264. vendor, compatible);
  265. scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
  266. model, compatible);
  267. if (strflags)
  268. devinfo->flags = simple_strtoul(strflags, NULL, 0);
  269. else
  270. devinfo->flags = flags;
  271. devinfo->compatible = compatible;
  272. if (compatible)
  273. list_add_tail(&devinfo->dev_info_list, &scsi_dev_info_list);
  274. else
  275. list_add(&devinfo->dev_info_list, &scsi_dev_info_list);
  276. return 0;
  277. }
  278. /**
  279. * scsi_dev_info_list_add_str: parse dev_list and add to the
  280. * scsi_dev_info_list.
  281. * @dev_list: string of device flags to add
  282. *
  283. * Description:
  284. * Parse dev_list, and add entries to the scsi_dev_info_list.
  285. * dev_list is of the form "vendor:product:flag,vendor:product:flag".
  286. * dev_list is modified via strsep. Can be called for command line
  287. * addition, for proc or mabye a sysfs interface.
  288. *
  289. * Returns: 0 if OK, -error on failure.
  290. **/
  291. static int scsi_dev_info_list_add_str(char *dev_list)
  292. {
  293. char *vendor, *model, *strflags, *next;
  294. char *next_check;
  295. int res = 0;
  296. next = dev_list;
  297. if (next && next[0] == '"') {
  298. /*
  299. * Ignore both the leading and trailing quote.
  300. */
  301. next++;
  302. next_check = ",\"";
  303. } else {
  304. next_check = ",";
  305. }
  306. /*
  307. * For the leading and trailing '"' case, the for loop comes
  308. * through the last time with vendor[0] == '\0'.
  309. */
  310. for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
  311. && (res == 0); vendor = strsep(&next, ":")) {
  312. strflags = NULL;
  313. model = strsep(&next, ":");
  314. if (model)
  315. strflags = strsep(&next, next_check);
  316. if (!model || !strflags) {
  317. printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
  318. " '%s'\n", __FUNCTION__, vendor, model,
  319. strflags);
  320. res = -EINVAL;
  321. } else
  322. res = scsi_dev_info_list_add(0 /* compatible */, vendor,
  323. model, strflags, 0);
  324. }
  325. return res;
  326. }
  327. /**
  328. * get_device_flags - get device specific flags from the dynamic device
  329. * list. Called during scan time.
  330. * @vendor: vendor name
  331. * @model: model name
  332. *
  333. * Description:
  334. * Search the scsi_dev_info_list for an entry matching @vendor and
  335. * @model, if found, return the matching flags value, else return
  336. * the host or global default settings.
  337. **/
  338. int scsi_get_device_flags(struct scsi_device *sdev,
  339. const unsigned char *vendor,
  340. const unsigned char *model)
  341. {
  342. struct scsi_dev_info_list *devinfo;
  343. unsigned int bflags;
  344. bflags = sdev->sdev_bflags;
  345. if (!bflags)
  346. bflags = scsi_default_dev_flags;
  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. #ifdef CONFIG_SCSI_PROC_FS
  400. /*
  401. * proc_scsi_dev_info_read: dump the scsi_dev_info_list via
  402. * /proc/scsi/device_info
  403. */
  404. static int proc_scsi_devinfo_read(char *buffer, char **start,
  405. off_t offset, int length)
  406. {
  407. struct scsi_dev_info_list *devinfo;
  408. int size, len = 0;
  409. off_t begin = 0;
  410. off_t pos = 0;
  411. list_for_each_entry(devinfo, &scsi_dev_info_list, dev_info_list) {
  412. size = sprintf(buffer + len, "'%.8s' '%.16s' 0x%x\n",
  413. devinfo->vendor, devinfo->model, devinfo->flags);
  414. len += size;
  415. pos = begin + len;
  416. if (pos < offset) {
  417. len = 0;
  418. begin = pos;
  419. }
  420. if (pos > offset + length)
  421. goto stop_output;
  422. }
  423. stop_output:
  424. *start = buffer + (offset - begin); /* Start of wanted data */
  425. len -= (offset - begin); /* Start slop */
  426. if (len > length)
  427. len = length; /* Ending slop */
  428. return (len);
  429. }
  430. /*
  431. * proc_scsi_dev_info_write: allow additions to the scsi_dev_info_list via
  432. * /proc.
  433. *
  434. * Use: echo "vendor:model:flag" > /proc/scsi/device_info
  435. *
  436. * To add a black/white list entry for vendor and model with an integer
  437. * value of flag to the scsi device info list.
  438. */
  439. static int proc_scsi_devinfo_write(struct file *file, const char __user *buf,
  440. unsigned long length, void *data)
  441. {
  442. char *buffer;
  443. int err = length;
  444. if (!buf || length>PAGE_SIZE)
  445. return -EINVAL;
  446. if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
  447. return -ENOMEM;
  448. if (copy_from_user(buffer, buf, length)) {
  449. err =-EFAULT;
  450. goto out;
  451. }
  452. if (length < PAGE_SIZE)
  453. buffer[length] = '\0';
  454. else if (buffer[PAGE_SIZE-1]) {
  455. err = -EINVAL;
  456. goto out;
  457. }
  458. scsi_dev_info_list_add_str(buffer);
  459. out:
  460. free_page((unsigned long)buffer);
  461. return err;
  462. }
  463. #endif /* CONFIG_SCSI_PROC_FS */
  464. module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
  465. MODULE_PARM_DESC(dev_flags,
  466. "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
  467. " list entries for vendor and model with an integer value of flags"
  468. " to the scsi device info list");
  469. module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
  470. MODULE_PARM_DESC(default_dev_flags,
  471. "scsi default device flag integer value");
  472. /**
  473. * scsi_dev_info_list_delete: called from scsi.c:exit_scsi to remove
  474. * the scsi_dev_info_list.
  475. **/
  476. void scsi_exit_devinfo(void)
  477. {
  478. struct list_head *lh, *lh_next;
  479. struct scsi_dev_info_list *devinfo;
  480. #ifdef CONFIG_SCSI_PROC_FS
  481. remove_proc_entry("scsi/device_info", NULL);
  482. #endif
  483. list_for_each_safe(lh, lh_next, &scsi_dev_info_list) {
  484. devinfo = list_entry(lh, struct scsi_dev_info_list,
  485. dev_info_list);
  486. kfree(devinfo);
  487. }
  488. }
  489. /**
  490. * scsi_dev_list_init: set up the dynamic device list.
  491. * @dev_list: string of device flags to add
  492. *
  493. * Description:
  494. * Add command line @dev_list entries, then add
  495. * scsi_static_device_list entries to the scsi device info list.
  496. **/
  497. int __init scsi_init_devinfo(void)
  498. {
  499. #ifdef CONFIG_SCSI_PROC_FS
  500. struct proc_dir_entry *p;
  501. #endif
  502. int error, i;
  503. error = scsi_dev_info_list_add_str(scsi_dev_flags);
  504. if (error)
  505. return error;
  506. for (i = 0; scsi_static_device_list[i].vendor; i++) {
  507. error = scsi_dev_info_list_add(1 /* compatibile */,
  508. scsi_static_device_list[i].vendor,
  509. scsi_static_device_list[i].model,
  510. NULL,
  511. scsi_static_device_list[i].flags);
  512. if (error)
  513. goto out;
  514. }
  515. #ifdef CONFIG_SCSI_PROC_FS
  516. p = create_proc_entry("scsi/device_info", 0, NULL);
  517. if (!p) {
  518. error = -ENOMEM;
  519. goto out;
  520. }
  521. p->owner = THIS_MODULE;
  522. p->get_info = proc_scsi_devinfo_read;
  523. p->write_proc = proc_scsi_devinfo_write;
  524. #endif /* CONFIG_SCSI_PROC_FS */
  525. out:
  526. if (error)
  527. scsi_exit_devinfo();
  528. return error;
  529. }