/drivers/scsi/scsi_devinfo.c

http://github.com/mirrors/linux · C · 880 lines · 598 code · 86 blank · 196 comment · 76 complexity · cf5947b0a80889c0c9bbee7af7ef3e4f MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0
  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. #include <linux/slab.h>
  10. #include <scsi/scsi_device.h>
  11. #include <scsi/scsi_devinfo.h>
  12. #include "scsi_priv.h"
  13. /*
  14. * scsi_dev_info_list: structure to hold black/white listed devices.
  15. */
  16. struct scsi_dev_info_list {
  17. struct list_head dev_info_list;
  18. char vendor[8];
  19. char model[16];
  20. blist_flags_t flags;
  21. unsigned compatible; /* for use with scsi_static_device_list entries */
  22. };
  23. struct scsi_dev_info_list_table {
  24. struct list_head node; /* our node for being on the master list */
  25. struct list_head scsi_dev_info_list; /* head of dev info list */
  26. const char *name; /* name of list for /proc (NULL for global) */
  27. int key; /* unique numeric identifier */
  28. };
  29. static blist_flags_t scsi_default_dev_flags;
  30. static LIST_HEAD(scsi_dev_info_list);
  31. static char scsi_dev_flags[256];
  32. /*
  33. * scsi_static_device_list: deprecated list of devices that require
  34. * settings that differ from the default, includes black-listed (broken)
  35. * devices. The entries here are added to the tail of scsi_dev_info_list
  36. * via scsi_dev_info_list_init.
  37. *
  38. * Do not add to this list, use the command line or proc interface to add
  39. * to the scsi_dev_info_list. This table will eventually go away.
  40. */
  41. static struct {
  42. char *vendor;
  43. char *model;
  44. char *revision; /* revision known to be bad, unused */
  45. blist_flags_t flags;
  46. } scsi_static_device_list[] __initdata = {
  47. /*
  48. * The following devices are known not to tolerate a lun != 0 scan
  49. * for one reason or another. Some will respond to all luns,
  50. * others will lock up.
  51. */
  52. {"Aashima", "IMAGERY 2400SP", "1.03", BLIST_NOLUN}, /* locks up */
  53. {"CHINON", "CD-ROM CDS-431", "H42", BLIST_NOLUN}, /* locks up */
  54. {"CHINON", "CD-ROM CDS-535", "Q14", BLIST_NOLUN}, /* locks up */
  55. {"DENON", "DRD-25X", "V", BLIST_NOLUN}, /* locks up */
  56. {"HITACHI", "DK312C", "CM81", BLIST_NOLUN}, /* responds to all lun */
  57. {"HITACHI", "DK314C", "CR21", BLIST_NOLUN}, /* responds to all lun */
  58. {"IBM", "2104-DU3", NULL, BLIST_NOLUN}, /* locks up */
  59. {"IBM", "2104-TU3", NULL, BLIST_NOLUN}, /* locks up */
  60. {"IMS", "CDD521/10", "2.06", BLIST_NOLUN}, /* locks up */
  61. {"MAXTOR", "XT-3280", "PR02", BLIST_NOLUN}, /* locks up */
  62. {"MAXTOR", "XT-4380S", "B3C", BLIST_NOLUN}, /* locks up */
  63. {"MAXTOR", "MXT-1240S", "I1.2", BLIST_NOLUN}, /* locks up */
  64. {"MAXTOR", "XT-4170S", "B5A", BLIST_NOLUN}, /* locks up */
  65. {"MAXTOR", "XT-8760S", "B7B", BLIST_NOLUN}, /* locks up */
  66. {"MEDIAVIS", "RENO CD-ROMX2A", "2.03", BLIST_NOLUN}, /* responds to all lun */
  67. {"MICROTEK", "ScanMakerIII", "2.30", BLIST_NOLUN}, /* responds to all lun */
  68. {"NEC", "CD-ROM DRIVE:841", "1.0", BLIST_NOLUN},/* locks up */
  69. {"PHILIPS", "PCA80SC", "V4-2", BLIST_NOLUN}, /* responds to all lun */
  70. {"RODIME", "RO3000S", "2.33", BLIST_NOLUN}, /* locks up */
  71. {"SUN", "SENA", NULL, BLIST_NOLUN}, /* responds to all luns */
  72. /*
  73. * The following causes a failed REQUEST SENSE on lun 1 for
  74. * aha152x controller, which causes SCSI code to reset bus.
  75. */
  76. {"SANYO", "CRD-250S", "1.20", BLIST_NOLUN},
  77. /*
  78. * The following causes a failed REQUEST SENSE on lun 1 for
  79. * aha152x controller, which causes SCSI code to reset bus.
  80. */
  81. {"SEAGATE", "ST157N", "\004|j", BLIST_NOLUN},
  82. {"SEAGATE", "ST296", "921", BLIST_NOLUN}, /* responds to all lun */
  83. {"SEAGATE", "ST1581", "6538", BLIST_NOLUN}, /* responds to all lun */
  84. {"SONY", "CD-ROM CDU-541", "4.3d", BLIST_NOLUN},
  85. {"SONY", "CD-ROM CDU-55S", "1.0i", BLIST_NOLUN},
  86. {"SONY", "CD-ROM CDU-561", "1.7x", BLIST_NOLUN},
  87. {"SONY", "CD-ROM CDU-8012", NULL, BLIST_NOLUN},
  88. {"SONY", "SDT-5000", "3.17", BLIST_SELECT_NO_ATN},
  89. {"TANDBERG", "TDC 3600", "U07", BLIST_NOLUN}, /* locks up */
  90. {"TEAC", "CD-R55S", "1.0H", BLIST_NOLUN}, /* locks up */
  91. /*
  92. * The following causes a failed REQUEST SENSE on lun 1 for
  93. * seagate controller, which causes SCSI code to reset bus.
  94. */
  95. {"TEAC", "CD-ROM", "1.06", BLIST_NOLUN},
  96. {"TEAC", "MT-2ST/45S2-27", "RV M", BLIST_NOLUN}, /* responds to all lun */
  97. /*
  98. * The following causes a failed REQUEST SENSE on lun 1 for
  99. * seagate controller, which causes SCSI code to reset bus.
  100. */
  101. {"HP", "C1750A", "3226", BLIST_NOLUN}, /* scanjet iic */
  102. {"HP", "C1790A", NULL, BLIST_NOLUN}, /* scanjet iip */
  103. {"HP", "C2500A", NULL, BLIST_NOLUN}, /* scanjet iicx */
  104. {"MEDIAVIS", "CDR-H93MV", "1.31", BLIST_NOLUN}, /* locks up */
  105. {"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN}, /* responds to all lun */
  106. {"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN}, /* locks up */
  107. {"NEC", "D3856", "0009", BLIST_NOLUN},
  108. {"QUANTUM", "LPS525S", "3110", BLIST_NOLUN}, /* locks up */
  109. {"QUANTUM", "PD1225S", "3110", BLIST_NOLUN}, /* locks up */
  110. {"QUANTUM", "FIREBALL ST4.3S", "0F0C", BLIST_NOLUN}, /* locks up */
  111. {"RELISYS", "Scorpio", NULL, BLIST_NOLUN}, /* responds to all lun */
  112. {"SANKYO", "CP525", "6.64", BLIST_NOLUN}, /* causes failed REQ SENSE, extra reset */
  113. {"TEXEL", "CD-ROM", "1.06", BLIST_NOLUN | BLIST_BORKEN},
  114. {"transtec", "T5008", "0001", BLIST_NOREPORTLUN },
  115. {"YAMAHA", "CDR100", "1.00", BLIST_NOLUN}, /* locks up */
  116. {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* locks up */
  117. {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* locks up */
  118. {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* locks up */
  119. {"", "Scanner", "1.80", BLIST_NOLUN}, /* responds to all lun */
  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. {"AIX", "VDASD", NULL, BLIST_TRY_VPD_PAGES},
  128. {"AFT PRO", "-IX CF", "0.0>", BLIST_FORCELUN},
  129. {"BELKIN", "USB 2 HS-CF", "1.95", BLIST_FORCELUN | BLIST_INQUIRY_36},
  130. {"BROWNIE", "1200U3P", NULL, BLIST_NOREPORTLUN},
  131. {"BROWNIE", "1600U3P", NULL, BLIST_NOREPORTLUN},
  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 */
  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 */
  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},
  145. {"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
  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}, /* EMC CLARiiON, storage on LUN 0 */
  152. {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* EMC CLARiiON, no storage on LUN 0 */
  153. {"EMC", "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  154. {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN |
  155. BLIST_REPORTLUN2 | BLIST_RETRY_ITF},
  156. {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN},
  157. {"easyRAID", "16P", NULL, BLIST_NOREPORTLUN},
  158. {"easyRAID", "X6P", NULL, BLIST_NOREPORTLUN},
  159. {"easyRAID", "F8", NULL, BLIST_NOREPORTLUN},
  160. {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  161. {"FUJITSU", "ETERNUS_DXM", "*", BLIST_RETRY_ASC_C1},
  162. {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
  163. {"Generic", "USB Storage-SMC", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36}, /* FW: 0180 and 0207 */
  164. {"HITACHI", "DF400", "*", BLIST_REPORTLUN2},
  165. {"HITACHI", "DF500", "*", BLIST_REPORTLUN2},
  166. {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_REPORTLUN2},
  167. {"HITACHI", "HUS1530", "*", BLIST_NO_DIF},
  168. {"HITACHI", "OPEN-", "*", BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES},
  169. {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */
  170. {"HP", "OPEN-", "*", BLIST_REPORTLUN2 | BLIST_TRY_VPD_PAGES}, /* HP XP Arrays */
  171. {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
  172. {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
  173. {"HP", "C1557A", NULL, BLIST_FORCELUN},
  174. {"HP", "C3323-300", "4269", BLIST_NOTQ},
  175. {"HP", "C5713A", NULL, BLIST_NOREPORTLUN},
  176. {"HP", "DISK-SUBSYSTEM", "*", BLIST_REPORTLUN2},
  177. {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
  178. {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  179. {"IBM", "2105", NULL, BLIST_RETRY_HWERROR},
  180. {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
  181. {"IOMEGA", "ZIP", NULL, BLIST_NOTQ | BLIST_NOLUN},
  182. {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
  183. {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
  184. {"INSITE", "I325VM", NULL, BLIST_KEY},
  185. {"Intel", "Multi-Flex", NULL, BLIST_NO_RSOC},
  186. {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  187. {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
  188. {"Marvell", "Console", NULL, BLIST_SKIP_VPD_PAGES},
  189. {"Marvell", "91xx Config", "1.01", BLIST_SKIP_VPD_PAGES},
  190. {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  191. {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  192. {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  193. {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN},
  194. {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
  195. {"MICROP", "4110", NULL, BLIST_NOTQ},
  196. {"MSFT", "Virtual HD", NULL, BLIST_MAX_1024 | BLIST_NO_RSOC},
  197. {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
  198. {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
  199. {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  200. {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  201. {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  202. {"NEC", "iStorage", NULL, BLIST_REPORTLUN2},
  203. {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  204. {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  205. {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  206. {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  207. {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  208. {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  209. {"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC},
  210. {"Promise", "", NULL, BLIST_SPARSELUN},
  211. {"QEMU", "QEMU CD-ROM", NULL, BLIST_SKIP_VPD_PAGES},
  212. {"QNAP", "iSCSI Storage", NULL, BLIST_MAX_1024},
  213. {"SYNOLOGY", "iSCSI Storage", NULL, BLIST_MAX_1024},
  214. {"QUANTUM", "XP34301", "1071", BLIST_NOTQ},
  215. {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
  216. {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
  217. {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ}, /* Chokes on tagged INQUIRY */
  218. {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
  219. {"SEAGATE", "ST900MM0006", NULL, BLIST_SKIP_VPD_PAGES},
  220. {"SGI", "RAID3", "*", BLIST_SPARSELUN},
  221. {"SGI", "RAID5", "*", BLIST_SPARSELUN},
  222. {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
  223. {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  224. {"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  225. {"SUN", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  226. {"DELL", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  227. {"STK", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  228. {"NETAPP", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  229. {"LSI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  230. {"ENGENIO", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  231. {"LENOVO", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  232. {"SanDisk", "Cruzer Blade", NULL, BLIST_TRY_VPD_PAGES |
  233. BLIST_INQUIRY_36},
  234. {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
  235. {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
  236. {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */
  237. {"ST650211", "CF", NULL, BLIST_RETRY_HWERROR},
  238. {"SUN", "T300", "*", BLIST_SPARSELUN},
  239. {"SUN", "T4", "*", BLIST_SPARSELUN},
  240. {"Tornado-", "F4", "*", BLIST_NOREPORTLUN},
  241. {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
  242. {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
  243. {"Traxdata", "CDR4120", NULL, BLIST_NOLUN}, /* locks up */
  244. {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
  245. {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
  246. {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
  247. {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
  248. {"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN},
  249. {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  250. {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
  251. {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
  252. { NULL, NULL, NULL, 0 },
  253. };
  254. static struct scsi_dev_info_list_table *scsi_devinfo_lookup_by_key(int key)
  255. {
  256. struct scsi_dev_info_list_table *devinfo_table;
  257. int found = 0;
  258. list_for_each_entry(devinfo_table, &scsi_dev_info_list, node)
  259. if (devinfo_table->key == key) {
  260. found = 1;
  261. break;
  262. }
  263. if (!found)
  264. return ERR_PTR(-EINVAL);
  265. return devinfo_table;
  266. }
  267. /*
  268. * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
  269. * devinfo vendor and model strings.
  270. */
  271. static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
  272. char *from, int compatible)
  273. {
  274. size_t from_length;
  275. from_length = strlen(from);
  276. /* This zero-pads the destination */
  277. strncpy(to, from, to_length);
  278. if (from_length < to_length && !compatible) {
  279. /*
  280. * space pad the string if it is short.
  281. */
  282. memset(&to[from_length], ' ', to_length - from_length);
  283. }
  284. if (from_length > to_length)
  285. printk(KERN_WARNING "%s: %s string '%s' is too long\n",
  286. __func__, name, from);
  287. }
  288. /**
  289. * scsi_dev_info_list_add - add one dev_info list entry.
  290. * @compatible: if true, null terminate short strings. Otherwise space pad.
  291. * @vendor: vendor string
  292. * @model: model (product) string
  293. * @strflags: integer string
  294. * @flags: if strflags NULL, use this flag value
  295. *
  296. * Description:
  297. * Create and add one dev_info entry for @vendor, @model, @strflags or
  298. * @flag. If @compatible, add to the tail of the list, do not space
  299. * pad, and set devinfo->compatible. The scsi_static_device_list entries
  300. * are added with @compatible 1 and @clfags NULL.
  301. *
  302. * Returns: 0 OK, -error on failure.
  303. **/
  304. static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
  305. char *strflags, blist_flags_t flags)
  306. {
  307. return scsi_dev_info_list_add_keyed(compatible, vendor, model,
  308. strflags, flags,
  309. SCSI_DEVINFO_GLOBAL);
  310. }
  311. /**
  312. * scsi_dev_info_list_add_keyed - add one dev_info list entry.
  313. * @compatible: if true, null terminate short strings. Otherwise space pad.
  314. * @vendor: vendor string
  315. * @model: model (product) string
  316. * @strflags: integer string
  317. * @flags: if strflags NULL, use this flag value
  318. * @key: specify list to use
  319. *
  320. * Description:
  321. * Create and add one dev_info entry for @vendor, @model,
  322. * @strflags or @flag in list specified by @key. If @compatible,
  323. * add to the tail of the list, do not space pad, and set
  324. * devinfo->compatible. The scsi_static_device_list entries are
  325. * added with @compatible 1 and @clfags NULL.
  326. *
  327. * Returns: 0 OK, -error on failure.
  328. **/
  329. int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
  330. char *strflags, blist_flags_t flags,
  331. enum scsi_devinfo_key key)
  332. {
  333. struct scsi_dev_info_list *devinfo;
  334. struct scsi_dev_info_list_table *devinfo_table =
  335. scsi_devinfo_lookup_by_key(key);
  336. if (IS_ERR(devinfo_table))
  337. return PTR_ERR(devinfo_table);
  338. devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
  339. if (!devinfo) {
  340. printk(KERN_ERR "%s: no memory\n", __func__);
  341. return -ENOMEM;
  342. }
  343. scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
  344. vendor, compatible);
  345. scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
  346. model, compatible);
  347. if (strflags) {
  348. unsigned long long val;
  349. int ret = kstrtoull(strflags, 0, &val);
  350. if (ret != 0) {
  351. kfree(devinfo);
  352. return ret;
  353. }
  354. flags = (__force blist_flags_t)val;
  355. }
  356. if (flags & __BLIST_UNUSED_MASK) {
  357. pr_err("scsi_devinfo (%s:%s): unsupported flags 0x%llx",
  358. vendor, model, flags & __BLIST_UNUSED_MASK);
  359. kfree(devinfo);
  360. return -EINVAL;
  361. }
  362. devinfo->flags = flags;
  363. devinfo->compatible = compatible;
  364. if (compatible)
  365. list_add_tail(&devinfo->dev_info_list,
  366. &devinfo_table->scsi_dev_info_list);
  367. else
  368. list_add(&devinfo->dev_info_list,
  369. &devinfo_table->scsi_dev_info_list);
  370. return 0;
  371. }
  372. EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
  373. /**
  374. * scsi_dev_info_list_find - find a matching dev_info list entry.
  375. * @vendor: full vendor string
  376. * @model: full model (product) string
  377. * @key: specify list to use
  378. *
  379. * Description:
  380. * Finds the first dev_info entry matching @vendor, @model
  381. * in list specified by @key.
  382. *
  383. * Returns: pointer to matching entry, or ERR_PTR on failure.
  384. **/
  385. static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
  386. const char *model, enum scsi_devinfo_key key)
  387. {
  388. struct scsi_dev_info_list *devinfo;
  389. struct scsi_dev_info_list_table *devinfo_table =
  390. scsi_devinfo_lookup_by_key(key);
  391. size_t vmax, mmax, mlen;
  392. const char *vskip, *mskip;
  393. if (IS_ERR(devinfo_table))
  394. return (struct scsi_dev_info_list *) devinfo_table;
  395. /* Prepare for "compatible" matches */
  396. /*
  397. * XXX why skip leading spaces? If an odd INQUIRY
  398. * value, that should have been part of the
  399. * scsi_static_device_list[] entry, such as " FOO"
  400. * rather than "FOO". Since this code is already
  401. * here, and we don't know what device it is
  402. * trying to work with, leave it as-is.
  403. */
  404. vmax = sizeof(devinfo->vendor);
  405. vskip = vendor;
  406. while (vmax > 0 && *vskip == ' ') {
  407. vmax--;
  408. vskip++;
  409. }
  410. /* Also skip trailing spaces */
  411. while (vmax > 0 && vskip[vmax - 1] == ' ')
  412. --vmax;
  413. mmax = sizeof(devinfo->model);
  414. mskip = model;
  415. while (mmax > 0 && *mskip == ' ') {
  416. mmax--;
  417. mskip++;
  418. }
  419. while (mmax > 0 && mskip[mmax - 1] == ' ')
  420. --mmax;
  421. list_for_each_entry(devinfo, &devinfo_table->scsi_dev_info_list,
  422. dev_info_list) {
  423. if (devinfo->compatible) {
  424. /*
  425. * vendor strings must be an exact match
  426. */
  427. if (vmax != strnlen(devinfo->vendor,
  428. sizeof(devinfo->vendor)) ||
  429. memcmp(devinfo->vendor, vskip, vmax))
  430. continue;
  431. /*
  432. * @model specifies the full string, and
  433. * must be larger or equal to devinfo->model
  434. */
  435. mlen = strnlen(devinfo->model, sizeof(devinfo->model));
  436. if (mmax < mlen || memcmp(devinfo->model, mskip, mlen))
  437. continue;
  438. return devinfo;
  439. } else {
  440. if (!memcmp(devinfo->vendor, vendor,
  441. sizeof(devinfo->vendor)) &&
  442. !memcmp(devinfo->model, model,
  443. sizeof(devinfo->model)))
  444. return devinfo;
  445. }
  446. }
  447. return ERR_PTR(-ENOENT);
  448. }
  449. /**
  450. * scsi_dev_info_list_del_keyed - remove one dev_info list entry.
  451. * @vendor: vendor string
  452. * @model: model (product) string
  453. * @key: specify list to use
  454. *
  455. * Description:
  456. * Remove and destroy one dev_info entry for @vendor, @model
  457. * in list specified by @key.
  458. *
  459. * Returns: 0 OK, -error on failure.
  460. **/
  461. int scsi_dev_info_list_del_keyed(char *vendor, char *model,
  462. enum scsi_devinfo_key key)
  463. {
  464. struct scsi_dev_info_list *found;
  465. found = scsi_dev_info_list_find(vendor, model, key);
  466. if (IS_ERR(found))
  467. return PTR_ERR(found);
  468. list_del(&found->dev_info_list);
  469. kfree(found);
  470. return 0;
  471. }
  472. EXPORT_SYMBOL(scsi_dev_info_list_del_keyed);
  473. /**
  474. * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list.
  475. * @dev_list: string of device flags to add
  476. *
  477. * Description:
  478. * Parse dev_list, and add entries to the scsi_dev_info_list.
  479. * dev_list is of the form "vendor:product:flag,vendor:product:flag".
  480. * dev_list is modified via strsep. Can be called for command line
  481. * addition, for proc or mabye a sysfs interface.
  482. *
  483. * Returns: 0 if OK, -error on failure.
  484. **/
  485. static int scsi_dev_info_list_add_str(char *dev_list)
  486. {
  487. char *vendor, *model, *strflags, *next;
  488. char *next_check;
  489. int res = 0;
  490. next = dev_list;
  491. if (next && next[0] == '"') {
  492. /*
  493. * Ignore both the leading and trailing quote.
  494. */
  495. next++;
  496. next_check = ",\"";
  497. } else {
  498. next_check = ",";
  499. }
  500. /*
  501. * For the leading and trailing '"' case, the for loop comes
  502. * through the last time with vendor[0] == '\0'.
  503. */
  504. for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
  505. && (res == 0); vendor = strsep(&next, ":")) {
  506. strflags = NULL;
  507. model = strsep(&next, ":");
  508. if (model)
  509. strflags = strsep(&next, next_check);
  510. if (!model || !strflags) {
  511. printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
  512. " '%s'\n", __func__, vendor, model,
  513. strflags);
  514. res = -EINVAL;
  515. } else
  516. res = scsi_dev_info_list_add(0 /* compatible */, vendor,
  517. model, strflags, 0);
  518. }
  519. return res;
  520. }
  521. /**
  522. * get_device_flags - get device specific flags from the dynamic device list.
  523. * @sdev: &scsi_device to get flags for
  524. * @vendor: vendor name
  525. * @model: model name
  526. *
  527. * Description:
  528. * Search the global scsi_dev_info_list (specified by list zero)
  529. * for an entry matching @vendor and @model, if found, return the
  530. * matching flags value, else return the host or global default
  531. * settings. Called during scan time.
  532. **/
  533. blist_flags_t scsi_get_device_flags(struct scsi_device *sdev,
  534. const unsigned char *vendor,
  535. const unsigned char *model)
  536. {
  537. return scsi_get_device_flags_keyed(sdev, vendor, model,
  538. SCSI_DEVINFO_GLOBAL);
  539. }
  540. /**
  541. * scsi_get_device_flags_keyed - get device specific flags from the dynamic device list
  542. * @sdev: &scsi_device to get flags for
  543. * @vendor: vendor name
  544. * @model: model name
  545. * @key: list to look up
  546. *
  547. * Description:
  548. * Search the scsi_dev_info_list specified by @key for an entry
  549. * matching @vendor and @model, if found, return the matching
  550. * flags value, else return the host or global default settings.
  551. * Called during scan time.
  552. **/
  553. blist_flags_t scsi_get_device_flags_keyed(struct scsi_device *sdev,
  554. const unsigned char *vendor,
  555. const unsigned char *model,
  556. enum scsi_devinfo_key key)
  557. {
  558. struct scsi_dev_info_list *devinfo;
  559. devinfo = scsi_dev_info_list_find(vendor, model, key);
  560. if (!IS_ERR(devinfo))
  561. return devinfo->flags;
  562. /* key or device not found: return nothing */
  563. if (key != SCSI_DEVINFO_GLOBAL)
  564. return 0;
  565. /* except for the global list, where we have an exception */
  566. if (sdev->sdev_bflags)
  567. return sdev->sdev_bflags;
  568. return scsi_default_dev_flags;
  569. }
  570. EXPORT_SYMBOL(scsi_get_device_flags_keyed);
  571. #ifdef CONFIG_SCSI_PROC_FS
  572. struct double_list {
  573. struct list_head *top;
  574. struct list_head *bottom;
  575. };
  576. static int devinfo_seq_show(struct seq_file *m, void *v)
  577. {
  578. struct double_list *dl = v;
  579. struct scsi_dev_info_list_table *devinfo_table =
  580. list_entry(dl->top, struct scsi_dev_info_list_table, node);
  581. struct scsi_dev_info_list *devinfo =
  582. list_entry(dl->bottom, struct scsi_dev_info_list,
  583. dev_info_list);
  584. if (devinfo_table->scsi_dev_info_list.next == dl->bottom &&
  585. devinfo_table->name)
  586. seq_printf(m, "[%s]:\n", devinfo_table->name);
  587. seq_printf(m, "'%.8s' '%.16s' 0x%llx\n",
  588. devinfo->vendor, devinfo->model, devinfo->flags);
  589. return 0;
  590. }
  591. static void *devinfo_seq_start(struct seq_file *m, loff_t *ppos)
  592. {
  593. struct double_list *dl = kmalloc(sizeof(*dl), GFP_KERNEL);
  594. loff_t pos = *ppos;
  595. if (!dl)
  596. return NULL;
  597. list_for_each(dl->top, &scsi_dev_info_list) {
  598. struct scsi_dev_info_list_table *devinfo_table =
  599. list_entry(dl->top, struct scsi_dev_info_list_table,
  600. node);
  601. list_for_each(dl->bottom, &devinfo_table->scsi_dev_info_list)
  602. if (pos-- == 0)
  603. return dl;
  604. }
  605. kfree(dl);
  606. return NULL;
  607. }
  608. static void *devinfo_seq_next(struct seq_file *m, void *v, loff_t *ppos)
  609. {
  610. struct double_list *dl = v;
  611. struct scsi_dev_info_list_table *devinfo_table =
  612. list_entry(dl->top, struct scsi_dev_info_list_table, node);
  613. ++*ppos;
  614. dl->bottom = dl->bottom->next;
  615. while (&devinfo_table->scsi_dev_info_list == dl->bottom) {
  616. dl->top = dl->top->next;
  617. if (dl->top == &scsi_dev_info_list) {
  618. kfree(dl);
  619. return NULL;
  620. }
  621. devinfo_table = list_entry(dl->top,
  622. struct scsi_dev_info_list_table,
  623. node);
  624. dl->bottom = devinfo_table->scsi_dev_info_list.next;
  625. }
  626. return dl;
  627. }
  628. static void devinfo_seq_stop(struct seq_file *m, void *v)
  629. {
  630. kfree(v);
  631. }
  632. static const struct seq_operations scsi_devinfo_seq_ops = {
  633. .start = devinfo_seq_start,
  634. .next = devinfo_seq_next,
  635. .stop = devinfo_seq_stop,
  636. .show = devinfo_seq_show,
  637. };
  638. static int proc_scsi_devinfo_open(struct inode *inode, struct file *file)
  639. {
  640. return seq_open(file, &scsi_devinfo_seq_ops);
  641. }
  642. /*
  643. * proc_scsi_dev_info_write - allow additions to scsi_dev_info_list via /proc.
  644. *
  645. * Description: Adds a black/white list entry for vendor and model with an
  646. * integer value of flag to the scsi device info list.
  647. * To use, echo "vendor:model:flag" > /proc/scsi/device_info
  648. */
  649. static ssize_t proc_scsi_devinfo_write(struct file *file,
  650. const char __user *buf,
  651. size_t length, loff_t *ppos)
  652. {
  653. char *buffer;
  654. ssize_t err = length;
  655. if (!buf || length>PAGE_SIZE)
  656. return -EINVAL;
  657. if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
  658. return -ENOMEM;
  659. if (copy_from_user(buffer, buf, length)) {
  660. err =-EFAULT;
  661. goto out;
  662. }
  663. if (length < PAGE_SIZE)
  664. buffer[length] = '\0';
  665. else if (buffer[PAGE_SIZE-1]) {
  666. err = -EINVAL;
  667. goto out;
  668. }
  669. scsi_dev_info_list_add_str(buffer);
  670. out:
  671. free_page((unsigned long)buffer);
  672. return err;
  673. }
  674. static const struct proc_ops scsi_devinfo_proc_ops = {
  675. .proc_open = proc_scsi_devinfo_open,
  676. .proc_read = seq_read,
  677. .proc_write = proc_scsi_devinfo_write,
  678. .proc_lseek = seq_lseek,
  679. .proc_release = seq_release,
  680. };
  681. #endif /* CONFIG_SCSI_PROC_FS */
  682. module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
  683. MODULE_PARM_DESC(dev_flags,
  684. "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
  685. " list entries for vendor and model with an integer value of flags"
  686. " to the scsi device info list");
  687. module_param_named(default_dev_flags, scsi_default_dev_flags, ullong, 0644);
  688. MODULE_PARM_DESC(default_dev_flags,
  689. "scsi default device flag uint64_t value");
  690. /**
  691. * scsi_exit_devinfo - remove /proc/scsi/device_info & the scsi_dev_info_list
  692. **/
  693. void scsi_exit_devinfo(void)
  694. {
  695. #ifdef CONFIG_SCSI_PROC_FS
  696. remove_proc_entry("scsi/device_info", NULL);
  697. #endif
  698. scsi_dev_info_remove_list(SCSI_DEVINFO_GLOBAL);
  699. }
  700. /**
  701. * scsi_dev_info_add_list - add a new devinfo list
  702. * @key: key of the list to add
  703. * @name: Name of the list to add (for /proc/scsi/device_info)
  704. *
  705. * Adds the requested list, returns zero on success, -EEXIST if the
  706. * key is already registered to a list, or other error on failure.
  707. */
  708. int scsi_dev_info_add_list(enum scsi_devinfo_key key, const char *name)
  709. {
  710. struct scsi_dev_info_list_table *devinfo_table =
  711. scsi_devinfo_lookup_by_key(key);
  712. if (!IS_ERR(devinfo_table))
  713. /* list already exists */
  714. return -EEXIST;
  715. devinfo_table = kmalloc(sizeof(*devinfo_table), GFP_KERNEL);
  716. if (!devinfo_table)
  717. return -ENOMEM;
  718. INIT_LIST_HEAD(&devinfo_table->node);
  719. INIT_LIST_HEAD(&devinfo_table->scsi_dev_info_list);
  720. devinfo_table->name = name;
  721. devinfo_table->key = key;
  722. list_add_tail(&devinfo_table->node, &scsi_dev_info_list);
  723. return 0;
  724. }
  725. EXPORT_SYMBOL(scsi_dev_info_add_list);
  726. /**
  727. * scsi_dev_info_remove_list - destroy an added devinfo list
  728. * @key: key of the list to destroy
  729. *
  730. * Iterates over the entire list first, freeing all the values, then
  731. * frees the list itself. Returns 0 on success or -EINVAL if the key
  732. * can't be found.
  733. */
  734. int scsi_dev_info_remove_list(enum scsi_devinfo_key key)
  735. {
  736. struct list_head *lh, *lh_next;
  737. struct scsi_dev_info_list_table *devinfo_table =
  738. scsi_devinfo_lookup_by_key(key);
  739. if (IS_ERR(devinfo_table))
  740. /* no such list */
  741. return -EINVAL;
  742. /* remove from the master list */
  743. list_del(&devinfo_table->node);
  744. list_for_each_safe(lh, lh_next, &devinfo_table->scsi_dev_info_list) {
  745. struct scsi_dev_info_list *devinfo;
  746. devinfo = list_entry(lh, struct scsi_dev_info_list,
  747. dev_info_list);
  748. kfree(devinfo);
  749. }
  750. kfree(devinfo_table);
  751. return 0;
  752. }
  753. EXPORT_SYMBOL(scsi_dev_info_remove_list);
  754. /**
  755. * scsi_init_devinfo - set up the dynamic device list.
  756. *
  757. * Description:
  758. * Add command line entries from scsi_dev_flags, then add
  759. * scsi_static_device_list entries to the scsi device info list.
  760. */
  761. int __init scsi_init_devinfo(void)
  762. {
  763. #ifdef CONFIG_SCSI_PROC_FS
  764. struct proc_dir_entry *p;
  765. #endif
  766. int error, i;
  767. error = scsi_dev_info_add_list(SCSI_DEVINFO_GLOBAL, NULL);
  768. if (error)
  769. return error;
  770. error = scsi_dev_info_list_add_str(scsi_dev_flags);
  771. if (error)
  772. goto out;
  773. for (i = 0; scsi_static_device_list[i].vendor; i++) {
  774. error = scsi_dev_info_list_add(1 /* compatibile */,
  775. scsi_static_device_list[i].vendor,
  776. scsi_static_device_list[i].model,
  777. NULL,
  778. scsi_static_device_list[i].flags);
  779. if (error)
  780. goto out;
  781. }
  782. #ifdef CONFIG_SCSI_PROC_FS
  783. p = proc_create("scsi/device_info", 0, NULL, &scsi_devinfo_proc_ops);
  784. if (!p) {
  785. error = -ENOMEM;
  786. goto out;
  787. }
  788. #endif /* CONFIG_SCSI_PROC_FS */
  789. out:
  790. if (error)
  791. scsi_exit_devinfo();
  792. return error;
  793. }