scsi_devinfo.c 28 KB

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