scsi_devinfo.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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 <linux/slab.h>
  9. #include <scsi/scsi_device.h>
  10. #include <scsi/scsi_devinfo.h>
  11. #include "scsi_priv.h"
  12. /*
  13. * scsi_dev_info_list: structure to hold black/white listed devices.
  14. */
  15. struct scsi_dev_info_list {
  16. struct list_head dev_info_list;
  17. char vendor[8];
  18. char model[16];
  19. unsigned flags;
  20. unsigned compatible; /* for use with scsi_static_device_list entries */
  21. };
  22. struct scsi_dev_info_list_table {
  23. struct list_head node; /* our node for being on the master list */
  24. struct list_head scsi_dev_info_list; /* head of dev info list */
  25. const char *name; /* name of list for /proc (NULL for global) */
  26. int key; /* unique numeric identifier */
  27. };
  28. static const char spaces[] = " "; /* 16 of them */
  29. static unsigned 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. unsigned 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", "", BLIST_NOLUN}, /* scanjet iip */
  103. {"HP", "C2500A", "", 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},
  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. {"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}, /* Dell PV 650F, storage on LUN 0 */
  151. {"DGC", "DISK", NULL, BLIST_SPARSELUN}, /* Dell PV 650F, no storage on LUN 0 */
  152. {"EMC", "Invista", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  153. {"EMC", "SYMMETRIX", NULL, BLIST_SPARSELUN | BLIST_LARGELUN | BLIST_FORCELUN},
  154. {"EMULEX", "MD21/S2 ESDI", NULL, BLIST_SINGLELUN},
  155. {"easyRAID", "16P", NULL, BLIST_NOREPORTLUN},
  156. {"easyRAID", "X6P", NULL, BLIST_NOREPORTLUN},
  157. {"easyRAID", "F8", NULL, BLIST_NOREPORTLUN},
  158. {"FSC", "CentricStor", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  159. {"Generic", "USB SD Reader", "1.00", BLIST_FORCELUN | BLIST_INQUIRY_36},
  160. {"Generic", "USB Storage-SMC", "0180", BLIST_FORCELUN | BLIST_INQUIRY_36},
  161. {"Generic", "USB Storage-SMC", "0207", BLIST_FORCELUN | BLIST_INQUIRY_36},
  162. {"HITACHI", "DF400", "*", BLIST_REPORTLUN2},
  163. {"HITACHI", "DF500", "*", BLIST_REPORTLUN2},
  164. {"HITACHI", "DISK-SUBSYSTEM", "*", BLIST_REPORTLUN2},
  165. {"HITACHI", "HUS1530", "*", BLIST_NO_DIF},
  166. {"HITACHI", "OPEN-", "*", BLIST_REPORTLUN2},
  167. {"HITACHI", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  168. {"HITACHI", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  169. {"HITACHI", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  170. {"HITACHI", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  171. {"HITACHI", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  172. {"HP", "A6189A", NULL, BLIST_SPARSELUN | BLIST_LARGELUN}, /* HP VA7400 */
  173. {"HP", "OPEN-", "*", BLIST_REPORTLUN2}, /* HP XP Arrays */
  174. {"HP", "NetRAID-4M", NULL, BLIST_FORCELUN},
  175. {"HP", "HSV100", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
  176. {"HP", "C1557A", NULL, BLIST_FORCELUN},
  177. {"HP", "C3323-300", "4269", BLIST_NOTQ},
  178. {"HP", "C5713A", NULL, BLIST_NOREPORTLUN},
  179. {"HP", "DF400", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  180. {"HP", "DF500", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  181. {"HP", "DF600", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  182. {"HP", "OP-C-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  183. {"HP", "3380-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  184. {"HP", "3390-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  185. {"HP", "6586-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  186. {"HP", "6588-", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  187. {"IBM", "AuSaV1S2", NULL, BLIST_FORCELUN},
  188. {"IBM", "ProFibre 4000R", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  189. {"IBM", "2105", NULL, BLIST_RETRY_HWERROR},
  190. {"iomega", "jaz 1GB", "J.86", BLIST_NOTQ | BLIST_NOLUN},
  191. {"IOMEGA", "ZIP", NULL, BLIST_NOTQ | BLIST_NOLUN},
  192. {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
  193. {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
  194. {"INSITE", "I325VM", NULL, BLIST_KEY},
  195. {"Intel", "Multi-Flex", NULL, BLIST_NO_RSOC},
  196. {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  197. {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
  198. {"Marvell", "Console", NULL, BLIST_SKIP_VPD_PAGES},
  199. {"Marvell", "91xx Config", "1.01", BLIST_SKIP_VPD_PAGES},
  200. {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  201. {"MATSHITA", "DMC-LC5", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  202. {"MATSHITA", "DMC-LC40", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
  203. {"Medion", "Flash XL MMC/SD", "2.6D", BLIST_FORCELUN},
  204. {"MegaRAID", "LD", NULL, BLIST_FORCELUN},
  205. {"MICROP", "4110", NULL, BLIST_NOTQ},
  206. {"MSFT", "Virtual HD", NULL, BLIST_NO_RSOC},
  207. {"MYLEX", "DACARMRB", "*", BLIST_REPORTLUN2},
  208. {"nCipher", "Fastness Crypto", NULL, BLIST_FORCELUN},
  209. {"NAKAMICH", "MJ-4.8S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  210. {"NAKAMICH", "MJ-5.16S", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  211. {"NEC", "PD-1 ODX654P", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  212. {"NEC", "iStorage", NULL, BLIST_REPORTLUN2},
  213. {"NRC", "MBR-7", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  214. {"NRC", "MBR-7.4", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  215. {"PIONEER", "CD-ROM DRM-600", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  216. {"PIONEER", "CD-ROM DRM-602X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  217. {"PIONEER", "CD-ROM DRM-604X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  218. {"PIONEER", "CD-ROM DRM-624X", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
  219. {"Promise", "VTrak E610f", NULL, BLIST_SPARSELUN | BLIST_NO_RSOC},
  220. {"Promise", "", NULL, BLIST_SPARSELUN},
  221. {"QEMU", "QEMU CD-ROM", NULL, BLIST_SKIP_VPD_PAGES},
  222. {"QNAP", "iSCSI Storage", NULL, BLIST_MAX_1024},
  223. {"SYNOLOGY", "iSCSI Storage", NULL, BLIST_MAX_1024},
  224. {"QUANTUM", "XP34301", "1071", BLIST_NOTQ},
  225. {"REGAL", "CDC-4X", NULL, BLIST_MAX5LUN | BLIST_SINGLELUN},
  226. {"SanDisk", "ImageMate CF-SD1", NULL, BLIST_FORCELUN},
  227. {"SEAGATE", "ST34555N", "0930", BLIST_NOTQ}, /* Chokes on tagged INQUIRY */
  228. {"SEAGATE", "ST3390N", "9546", BLIST_NOTQ},
  229. {"SEAGATE", "ST900MM0006", NULL, BLIST_SKIP_VPD_PAGES},
  230. {"SGI", "RAID3", "*", BLIST_SPARSELUN},
  231. {"SGI", "RAID5", "*", BLIST_SPARSELUN},
  232. {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
  233. {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  234. {"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  235. {"SUN", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  236. {"DELL", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  237. {"STK", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  238. {"NETAPP", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  239. {"LSI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  240. {"ENGENIO", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
  241. {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
  242. {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
  243. {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */
  244. {"ST650211", "CF", NULL, BLIST_RETRY_HWERROR},
  245. {"SUN", "T300", "*", BLIST_SPARSELUN},
  246. {"SUN", "T4", "*", BLIST_SPARSELUN},
  247. {"TEXEL", "CD-ROM", "1.06", BLIST_BORKEN},
  248. {"Tornado-", "F4", "*", BLIST_NOREPORTLUN},
  249. {"TOSHIBA", "CDROM", NULL, BLIST_ISROM},
  250. {"TOSHIBA", "CD-ROM", NULL, BLIST_ISROM},
  251. {"Traxdata", "CDR4120", NULL, BLIST_NOLUN}, /* locks up */
  252. {"USB2.0", "SMARTMEDIA/XD", NULL, BLIST_FORCELUN | BLIST_INQUIRY_36},
  253. {"WangDAT", "Model 2600", "01.7", BLIST_SELECT_NO_ATN},
  254. {"WangDAT", "Model 3200", "02.2", BLIST_SELECT_NO_ATN},
  255. {"WangDAT", "Model 1300", "02.4", BLIST_SELECT_NO_ATN},
  256. {"WDC WD25", "00JB-00FUA0", NULL, BLIST_NOREPORTLUN},
  257. {"XYRATEX", "RS", "*", BLIST_SPARSELUN | BLIST_LARGELUN},
  258. {"Zzyzx", "RocketStor 500S", NULL, BLIST_SPARSELUN},
  259. {"Zzyzx", "RocketStor 2000", NULL, BLIST_SPARSELUN},
  260. { NULL, NULL, NULL, 0 },
  261. };
  262. static struct scsi_dev_info_list_table *scsi_devinfo_lookup_by_key(int key)
  263. {
  264. struct scsi_dev_info_list_table *devinfo_table;
  265. int found = 0;
  266. list_for_each_entry(devinfo_table, &scsi_dev_info_list, node)
  267. if (devinfo_table->key == key) {
  268. found = 1;
  269. break;
  270. }
  271. if (!found)
  272. return ERR_PTR(-EINVAL);
  273. return devinfo_table;
  274. }
  275. /*
  276. * scsi_strcpy_devinfo: called from scsi_dev_info_list_add to copy into
  277. * devinfo vendor and model strings.
  278. */
  279. static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
  280. char *from, int compatible)
  281. {
  282. size_t from_length;
  283. from_length = strlen(from);
  284. strncpy(to, from, min(to_length, from_length));
  285. if (from_length < to_length) {
  286. if (compatible) {
  287. /*
  288. * NUL terminate the string if it is short.
  289. */
  290. to[from_length] = '\0';
  291. } else {
  292. /*
  293. * space pad the string if it is short.
  294. */
  295. strncpy(&to[from_length], spaces,
  296. to_length - from_length);
  297. }
  298. }
  299. if (from_length > to_length)
  300. printk(KERN_WARNING "%s: %s string '%s' is too long\n",
  301. __func__, name, from);
  302. }
  303. /**
  304. * scsi_dev_info_list_add - add one dev_info list entry.
  305. * @compatible: if true, null terminate short strings. Otherwise space pad.
  306. * @vendor: vendor string
  307. * @model: model (product) string
  308. * @strflags: integer string
  309. * @flags: if strflags NULL, use this flag value
  310. *
  311. * Description:
  312. * Create and add one dev_info entry for @vendor, @model, @strflags or
  313. * @flag. If @compatible, add to the tail of the list, do not space
  314. * pad, and set devinfo->compatible. The scsi_static_device_list entries
  315. * are added with @compatible 1 and @clfags NULL.
  316. *
  317. * Returns: 0 OK, -error on failure.
  318. **/
  319. static int scsi_dev_info_list_add(int compatible, char *vendor, char *model,
  320. char *strflags, int flags)
  321. {
  322. return scsi_dev_info_list_add_keyed(compatible, vendor, model,
  323. strflags, flags,
  324. SCSI_DEVINFO_GLOBAL);
  325. }
  326. /**
  327. * scsi_dev_info_list_add_keyed - add one dev_info list entry.
  328. * @compatible: if true, null terminate short strings. Otherwise space pad.
  329. * @vendor: vendor string
  330. * @model: model (product) string
  331. * @strflags: integer string
  332. * @flags: if strflags NULL, use this flag value
  333. * @key: specify list to use
  334. *
  335. * Description:
  336. * Create and add one dev_info entry for @vendor, @model,
  337. * @strflags or @flag in list specified by @key. If @compatible,
  338. * add to the tail of the list, do not space pad, and set
  339. * devinfo->compatible. The scsi_static_device_list entries are
  340. * added with @compatible 1 and @clfags NULL.
  341. *
  342. * Returns: 0 OK, -error on failure.
  343. **/
  344. int scsi_dev_info_list_add_keyed(int compatible, char *vendor, char *model,
  345. char *strflags, int flags, int key)
  346. {
  347. struct scsi_dev_info_list *devinfo;
  348. struct scsi_dev_info_list_table *devinfo_table =
  349. scsi_devinfo_lookup_by_key(key);
  350. if (IS_ERR(devinfo_table))
  351. return PTR_ERR(devinfo_table);
  352. devinfo = kmalloc(sizeof(*devinfo), GFP_KERNEL);
  353. if (!devinfo) {
  354. printk(KERN_ERR "%s: no memory\n", __func__);
  355. return -ENOMEM;
  356. }
  357. scsi_strcpy_devinfo("vendor", devinfo->vendor, sizeof(devinfo->vendor),
  358. vendor, compatible);
  359. scsi_strcpy_devinfo("model", devinfo->model, sizeof(devinfo->model),
  360. model, compatible);
  361. if (strflags)
  362. devinfo->flags = simple_strtoul(strflags, NULL, 0);
  363. else
  364. devinfo->flags = flags;
  365. devinfo->compatible = compatible;
  366. if (compatible)
  367. list_add_tail(&devinfo->dev_info_list,
  368. &devinfo_table->scsi_dev_info_list);
  369. else
  370. list_add(&devinfo->dev_info_list,
  371. &devinfo_table->scsi_dev_info_list);
  372. return 0;
  373. }
  374. EXPORT_SYMBOL(scsi_dev_info_list_add_keyed);
  375. /**
  376. * scsi_dev_info_list_find - find a matching dev_info list entry.
  377. * @vendor: vendor string
  378. * @model: model (product) string
  379. * @key: specify list to use
  380. *
  381. * Description:
  382. * Finds the first dev_info entry matching @vendor, @model
  383. * in list specified by @key.
  384. *
  385. * Returns: pointer to matching entry, or ERR_PTR on failure.
  386. **/
  387. static struct scsi_dev_info_list *scsi_dev_info_list_find(const char *vendor,
  388. const char *model, int key)
  389. {
  390. struct scsi_dev_info_list *devinfo;
  391. struct scsi_dev_info_list_table *devinfo_table =
  392. scsi_devinfo_lookup_by_key(key);
  393. size_t vmax, mmax;
  394. const char *vskip, *mskip;
  395. if (IS_ERR(devinfo_table))
  396. return (struct scsi_dev_info_list *) devinfo_table;
  397. /* Prepare for "compatible" matches */
  398. /*
  399. * XXX why skip leading spaces? If an odd INQUIRY
  400. * value, that should have been part of the
  401. * scsi_static_device_list[] entry, such as " FOO"
  402. * rather than "FOO". Since this code is already
  403. * here, and we don't know what device it is
  404. * trying to work with, leave it as-is.
  405. */
  406. vmax = sizeof(devinfo->vendor);
  407. vskip = vendor;
  408. while (vmax > 0 && *vskip == ' ') {
  409. vmax--;
  410. vskip++;
  411. }
  412. /* Also skip trailing spaces */
  413. while (vmax > 0 && vskip[vmax - 1] == ' ')
  414. --vmax;
  415. mmax = sizeof(devinfo->model);
  416. mskip = model;
  417. while (mmax > 0 && *mskip == ' ') {
  418. mmax--;
  419. mskip++;
  420. }
  421. while (mmax > 0 && mskip[mmax - 1] == ' ')
  422. --mmax;
  423. list_for_each_entry(devinfo, &devinfo_table->scsi_dev_info_list,
  424. dev_info_list) {
  425. if (devinfo->compatible) {
  426. /*
  427. * Behave like the older version of get_device_flags.
  428. */
  429. if (memcmp(devinfo->vendor, vskip, vmax) ||
  430. (vmax < sizeof(devinfo->vendor) &&
  431. devinfo->vendor[vmax]))
  432. continue;
  433. if (memcmp(devinfo->model, mskip, mmax) ||
  434. (mmax < sizeof(devinfo->model) &&
  435. devinfo->model[mmax]))
  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_del_keyed - remove one dev_info list entry.
  450. * @vendor: vendor string
  451. * @model: model (product) string
  452. * @key: specify list to use
  453. *
  454. * Description:
  455. * Remove and destroy one dev_info entry for @vendor, @model
  456. * in list specified by @key.
  457. *
  458. * Returns: 0 OK, -error on failure.
  459. **/
  460. int scsi_dev_info_list_del_keyed(char *vendor, char *model, int key)
  461. {
  462. struct scsi_dev_info_list *found;
  463. found = scsi_dev_info_list_find(vendor, model, key);
  464. if (IS_ERR(found))
  465. return PTR_ERR(found);
  466. list_del(&found->dev_info_list);
  467. kfree(found);
  468. return 0;
  469. }
  470. EXPORT_SYMBOL(scsi_dev_info_list_del_keyed);
  471. /**
  472. * scsi_dev_info_list_add_str - parse dev_list and add to the scsi_dev_info_list.
  473. * @dev_list: string of device flags to add
  474. *
  475. * Description:
  476. * Parse dev_list, and add entries to the scsi_dev_info_list.
  477. * dev_list is of the form "vendor:product:flag,vendor:product:flag".
  478. * dev_list is modified via strsep. Can be called for command line
  479. * addition, for proc or mabye a sysfs interface.
  480. *
  481. * Returns: 0 if OK, -error on failure.
  482. **/
  483. static int scsi_dev_info_list_add_str(char *dev_list)
  484. {
  485. char *vendor, *model, *strflags, *next;
  486. char *next_check;
  487. int res = 0;
  488. next = dev_list;
  489. if (next && next[0] == '"') {
  490. /*
  491. * Ignore both the leading and trailing quote.
  492. */
  493. next++;
  494. next_check = ",\"";
  495. } else {
  496. next_check = ",";
  497. }
  498. /*
  499. * For the leading and trailing '"' case, the for loop comes
  500. * through the last time with vendor[0] == '\0'.
  501. */
  502. for (vendor = strsep(&next, ":"); vendor && (vendor[0] != '\0')
  503. && (res == 0); vendor = strsep(&next, ":")) {
  504. strflags = NULL;
  505. model = strsep(&next, ":");
  506. if (model)
  507. strflags = strsep(&next, next_check);
  508. if (!model || !strflags) {
  509. printk(KERN_ERR "%s: bad dev info string '%s' '%s'"
  510. " '%s'\n", __func__, vendor, model,
  511. strflags);
  512. res = -EINVAL;
  513. } else
  514. res = scsi_dev_info_list_add(0 /* compatible */, vendor,
  515. model, strflags, 0);
  516. }
  517. return res;
  518. }
  519. /**
  520. * get_device_flags - get device specific flags from the dynamic device list.
  521. * @sdev: &scsi_device to get flags for
  522. * @vendor: vendor name
  523. * @model: model name
  524. *
  525. * Description:
  526. * Search the global scsi_dev_info_list (specified by list zero)
  527. * for an entry matching @vendor and @model, if found, return the
  528. * matching flags value, else return the host or global default
  529. * settings. Called during scan time.
  530. **/
  531. int scsi_get_device_flags(struct scsi_device *sdev,
  532. const unsigned char *vendor,
  533. const unsigned char *model)
  534. {
  535. return scsi_get_device_flags_keyed(sdev, vendor, model,
  536. SCSI_DEVINFO_GLOBAL);
  537. }
  538. /**
  539. * scsi_get_device_flags_keyed - get device specific flags from the dynamic device list
  540. * @sdev: &scsi_device to get flags for
  541. * @vendor: vendor name
  542. * @model: model name
  543. * @key: list to look up
  544. *
  545. * Description:
  546. * Search the scsi_dev_info_list specified by @key for an entry
  547. * matching @vendor and @model, if found, return the matching
  548. * flags value, else return the host or global default settings.
  549. * Called during scan time.
  550. **/
  551. int scsi_get_device_flags_keyed(struct scsi_device *sdev,
  552. const unsigned char *vendor,
  553. const unsigned char *model,
  554. int key)
  555. {
  556. struct scsi_dev_info_list *devinfo;
  557. int err;
  558. devinfo = scsi_dev_info_list_find(vendor, model, key);
  559. if (!IS_ERR(devinfo))
  560. return devinfo->flags;
  561. err = PTR_ERR(devinfo);
  562. if (err != -ENOENT)
  563. return err;
  564. /* nothing found, return nothing */
  565. if (key != SCSI_DEVINFO_GLOBAL)
  566. return 0;
  567. /* except for the global list, where we have an exception */
  568. if (sdev->sdev_bflags)
  569. return sdev->sdev_bflags;
  570. return scsi_default_dev_flags;
  571. }
  572. EXPORT_SYMBOL(scsi_get_device_flags_keyed);
  573. #ifdef CONFIG_SCSI_PROC_FS
  574. struct double_list {
  575. struct list_head *top;
  576. struct list_head *bottom;
  577. };
  578. static int devinfo_seq_show(struct seq_file *m, void *v)
  579. {
  580. struct double_list *dl = v;
  581. struct scsi_dev_info_list_table *devinfo_table =
  582. list_entry(dl->top, struct scsi_dev_info_list_table, node);
  583. struct scsi_dev_info_list *devinfo =
  584. list_entry(dl->bottom, struct scsi_dev_info_list,
  585. dev_info_list);
  586. if (devinfo_table->scsi_dev_info_list.next == dl->bottom &&
  587. devinfo_table->name)
  588. seq_printf(m, "[%s]:\n", devinfo_table->name);
  589. seq_printf(m, "'%.8s' '%.16s' 0x%x\n",
  590. devinfo->vendor, devinfo->model, devinfo->flags);
  591. return 0;
  592. }
  593. static void *devinfo_seq_start(struct seq_file *m, loff_t *ppos)
  594. {
  595. struct double_list *dl = kmalloc(sizeof(*dl), GFP_KERNEL);
  596. loff_t pos = *ppos;
  597. if (!dl)
  598. return NULL;
  599. list_for_each(dl->top, &scsi_dev_info_list) {
  600. struct scsi_dev_info_list_table *devinfo_table =
  601. list_entry(dl->top, struct scsi_dev_info_list_table,
  602. node);
  603. list_for_each(dl->bottom, &devinfo_table->scsi_dev_info_list)
  604. if (pos-- == 0)
  605. return dl;
  606. }
  607. kfree(dl);
  608. return NULL;
  609. }
  610. static void *devinfo_seq_next(struct seq_file *m, void *v, loff_t *ppos)
  611. {
  612. struct double_list *dl = v;
  613. struct scsi_dev_info_list_table *devinfo_table =
  614. list_entry(dl->top, struct scsi_dev_info_list_table, node);
  615. ++*ppos;
  616. dl->bottom = dl->bottom->next;
  617. while (&devinfo_table->scsi_dev_info_list == dl->bottom) {
  618. dl->top = dl->top->next;
  619. if (dl->top == &scsi_dev_info_list) {
  620. kfree(dl);
  621. return NULL;
  622. }
  623. devinfo_table = list_entry(dl->top,
  624. struct scsi_dev_info_list_table,
  625. node);
  626. dl->bottom = devinfo_table->scsi_dev_info_list.next;
  627. }
  628. return dl;
  629. }
  630. static void devinfo_seq_stop(struct seq_file *m, void *v)
  631. {
  632. kfree(v);
  633. }
  634. static const struct seq_operations scsi_devinfo_seq_ops = {
  635. .start = devinfo_seq_start,
  636. .next = devinfo_seq_next,
  637. .stop = devinfo_seq_stop,
  638. .show = devinfo_seq_show,
  639. };
  640. static int proc_scsi_devinfo_open(struct inode *inode, struct file *file)
  641. {
  642. return seq_open(file, &scsi_devinfo_seq_ops);
  643. }
  644. /*
  645. * proc_scsi_dev_info_write - allow additions to scsi_dev_info_list via /proc.
  646. *
  647. * Description: Adds a black/white list entry for vendor and model with an
  648. * integer value of flag to the scsi device info list.
  649. * To use, echo "vendor:model:flag" > /proc/scsi/device_info
  650. */
  651. static ssize_t proc_scsi_devinfo_write(struct file *file,
  652. const char __user *buf,
  653. size_t length, loff_t *ppos)
  654. {
  655. char *buffer;
  656. ssize_t err = length;
  657. if (!buf || length>PAGE_SIZE)
  658. return -EINVAL;
  659. if (!(buffer = (char *) __get_free_page(GFP_KERNEL)))
  660. return -ENOMEM;
  661. if (copy_from_user(buffer, buf, length)) {
  662. err =-EFAULT;
  663. goto out;
  664. }
  665. if (length < PAGE_SIZE)
  666. buffer[length] = '\0';
  667. else if (buffer[PAGE_SIZE-1]) {
  668. err = -EINVAL;
  669. goto out;
  670. }
  671. scsi_dev_info_list_add_str(buffer);
  672. out:
  673. free_page((unsigned long)buffer);
  674. return err;
  675. }
  676. static const struct file_operations scsi_devinfo_proc_fops = {
  677. .owner = THIS_MODULE,
  678. .open = proc_scsi_devinfo_open,
  679. .read = seq_read,
  680. .write = proc_scsi_devinfo_write,
  681. .llseek = seq_lseek,
  682. .release = seq_release,
  683. };
  684. #endif /* CONFIG_SCSI_PROC_FS */
  685. module_param_string(dev_flags, scsi_dev_flags, sizeof(scsi_dev_flags), 0);
  686. MODULE_PARM_DESC(dev_flags,
  687. "Given scsi_dev_flags=vendor:model:flags[,v:m:f] add black/white"
  688. " list entries for vendor and model with an integer value of flags"
  689. " to the scsi device info list");
  690. module_param_named(default_dev_flags, scsi_default_dev_flags, int, S_IRUGO|S_IWUSR);
  691. MODULE_PARM_DESC(default_dev_flags,
  692. "scsi default device flag integer value");
  693. /**
  694. * scsi_exit_devinfo - remove /proc/scsi/device_info & the scsi_dev_info_list
  695. **/
  696. void scsi_exit_devinfo(void)
  697. {
  698. #ifdef CONFIG_SCSI_PROC_FS
  699. remove_proc_entry("scsi/device_info", NULL);
  700. #endif
  701. scsi_dev_info_remove_list(SCSI_DEVINFO_GLOBAL);
  702. }
  703. /**
  704. * scsi_dev_info_add_list - add a new devinfo list
  705. * @key: key of the list to add
  706. * @name: Name of the list to add (for /proc/scsi/device_info)
  707. *
  708. * Adds the requested list, returns zero on success, -EEXIST if the
  709. * key is already registered to a list, or other error on failure.
  710. */
  711. int scsi_dev_info_add_list(int key, const char *name)
  712. {
  713. struct scsi_dev_info_list_table *devinfo_table =
  714. scsi_devinfo_lookup_by_key(key);
  715. if (!IS_ERR(devinfo_table))
  716. /* list already exists */
  717. return -EEXIST;
  718. devinfo_table = kmalloc(sizeof(*devinfo_table), GFP_KERNEL);
  719. if (!devinfo_table)
  720. return -ENOMEM;
  721. INIT_LIST_HEAD(&devinfo_table->node);
  722. INIT_LIST_HEAD(&devinfo_table->scsi_dev_info_list);
  723. devinfo_table->name = name;
  724. devinfo_table->key = key;
  725. list_add_tail(&devinfo_table->node, &scsi_dev_info_list);
  726. return 0;
  727. }
  728. EXPORT_SYMBOL(scsi_dev_info_add_list);
  729. /**
  730. * scsi_dev_info_remove_list - destroy an added devinfo list
  731. * @key: key of the list to destroy
  732. *
  733. * Iterates over the entire list first, freeing all the values, then
  734. * frees the list itself. Returns 0 on success or -EINVAL if the key
  735. * can't be found.
  736. */
  737. int scsi_dev_info_remove_list(int key)
  738. {
  739. struct list_head *lh, *lh_next;
  740. struct scsi_dev_info_list_table *devinfo_table =
  741. scsi_devinfo_lookup_by_key(key);
  742. if (IS_ERR(devinfo_table))
  743. /* no such list */
  744. return -EINVAL;
  745. /* remove from the master list */
  746. list_del(&devinfo_table->node);
  747. list_for_each_safe(lh, lh_next, &devinfo_table->scsi_dev_info_list) {
  748. struct scsi_dev_info_list *devinfo;
  749. devinfo = list_entry(lh, struct scsi_dev_info_list,
  750. dev_info_list);
  751. kfree(devinfo);
  752. }
  753. kfree(devinfo_table);
  754. return 0;
  755. }
  756. EXPORT_SYMBOL(scsi_dev_info_remove_list);
  757. /**
  758. * scsi_init_devinfo - set up the dynamic device list.
  759. *
  760. * Description:
  761. * Add command line entries from scsi_dev_flags, then add
  762. * scsi_static_device_list entries to the scsi device info list.
  763. */
  764. int __init scsi_init_devinfo(void)
  765. {
  766. #ifdef CONFIG_SCSI_PROC_FS
  767. struct proc_dir_entry *p;
  768. #endif
  769. int error, i;
  770. error = scsi_dev_info_add_list(SCSI_DEVINFO_GLOBAL, NULL);
  771. if (error)
  772. return error;
  773. error = scsi_dev_info_list_add_str(scsi_dev_flags);
  774. if (error)
  775. goto out;
  776. for (i = 0; scsi_static_device_list[i].vendor; i++) {
  777. error = scsi_dev_info_list_add(1 /* compatibile */,
  778. scsi_static_device_list[i].vendor,
  779. scsi_static_device_list[i].model,
  780. NULL,
  781. scsi_static_device_list[i].flags);
  782. if (error)
  783. goto out;
  784. }
  785. #ifdef CONFIG_SCSI_PROC_FS
  786. p = proc_create("scsi/device_info", 0, NULL, &scsi_devinfo_proc_fops);
  787. if (!p) {
  788. error = -ENOMEM;
  789. goto out;
  790. }
  791. #endif /* CONFIG_SCSI_PROC_FS */
  792. out:
  793. if (error)
  794. scsi_exit_devinfo();
  795. return error;
  796. }