scsi_devinfo.c 28 KB

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