scsi_devinfo.c 21 KB

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