scsi_sysfs.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. /*
  2. * scsi_sysfs.c
  3. *
  4. * SCSI sysfs interface routines.
  5. *
  6. * Created to pull SCSI mid layer sysfs routines into one file.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <linux/init.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/device.h>
  13. #include <linux/pm_runtime.h>
  14. #include <scsi/scsi.h>
  15. #include <scsi/scsi_device.h>
  16. #include <scsi/scsi_host.h>
  17. #include <scsi/scsi_tcq.h>
  18. #include <scsi/scsi_transport.h>
  19. #include <scsi/scsi_driver.h>
  20. #include "scsi_priv.h"
  21. #include "scsi_logging.h"
  22. static struct device_type scsi_dev_type;
  23. static const struct {
  24. enum scsi_device_state value;
  25. char *name;
  26. } sdev_states[] = {
  27. { SDEV_CREATED, "created" },
  28. { SDEV_RUNNING, "running" },
  29. { SDEV_CANCEL, "cancel" },
  30. { SDEV_DEL, "deleted" },
  31. { SDEV_QUIESCE, "quiesce" },
  32. { SDEV_OFFLINE, "offline" },
  33. { SDEV_TRANSPORT_OFFLINE, "transport-offline" },
  34. { SDEV_BLOCK, "blocked" },
  35. { SDEV_CREATED_BLOCK, "created-blocked" },
  36. };
  37. const char *scsi_device_state_name(enum scsi_device_state state)
  38. {
  39. int i;
  40. char *name = NULL;
  41. for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
  42. if (sdev_states[i].value == state) {
  43. name = sdev_states[i].name;
  44. break;
  45. }
  46. }
  47. return name;
  48. }
  49. static const struct {
  50. enum scsi_host_state value;
  51. char *name;
  52. } shost_states[] = {
  53. { SHOST_CREATED, "created" },
  54. { SHOST_RUNNING, "running" },
  55. { SHOST_CANCEL, "cancel" },
  56. { SHOST_DEL, "deleted" },
  57. { SHOST_RECOVERY, "recovery" },
  58. { SHOST_CANCEL_RECOVERY, "cancel/recovery" },
  59. { SHOST_DEL_RECOVERY, "deleted/recovery", },
  60. };
  61. const char *scsi_host_state_name(enum scsi_host_state state)
  62. {
  63. int i;
  64. char *name = NULL;
  65. for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
  66. if (shost_states[i].value == state) {
  67. name = shost_states[i].name;
  68. break;
  69. }
  70. }
  71. return name;
  72. }
  73. static int check_set(unsigned long long *val, char *src)
  74. {
  75. char *last;
  76. if (strncmp(src, "-", 20) == 0) {
  77. *val = SCAN_WILD_CARD;
  78. } else {
  79. /*
  80. * Doesn't check for int overflow
  81. */
  82. *val = simple_strtoull(src, &last, 0);
  83. if (*last != '\0')
  84. return 1;
  85. }
  86. return 0;
  87. }
  88. static int scsi_scan(struct Scsi_Host *shost, const char *str)
  89. {
  90. char s1[15], s2[15], s3[17], junk;
  91. unsigned long long channel, id, lun;
  92. int res;
  93. res = sscanf(str, "%10s %10s %16s %c", s1, s2, s3, &junk);
  94. if (res != 3)
  95. return -EINVAL;
  96. if (check_set(&channel, s1))
  97. return -EINVAL;
  98. if (check_set(&id, s2))
  99. return -EINVAL;
  100. if (check_set(&lun, s3))
  101. return -EINVAL;
  102. if (shost->transportt->user_scan)
  103. res = shost->transportt->user_scan(shost, channel, id, lun);
  104. else
  105. res = scsi_scan_host_selected(shost, channel, id, lun, 1);
  106. return res;
  107. }
  108. /*
  109. * shost_show_function: macro to create an attr function that can be used to
  110. * show a non-bit field.
  111. */
  112. #define shost_show_function(name, field, format_string) \
  113. static ssize_t \
  114. show_##name (struct device *dev, struct device_attribute *attr, \
  115. char *buf) \
  116. { \
  117. struct Scsi_Host *shost = class_to_shost(dev); \
  118. return snprintf (buf, 20, format_string, shost->field); \
  119. }
  120. /*
  121. * shost_rd_attr: macro to create a function and attribute variable for a
  122. * read only field.
  123. */
  124. #define shost_rd_attr2(name, field, format_string) \
  125. shost_show_function(name, field, format_string) \
  126. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
  127. #define shost_rd_attr(field, format_string) \
  128. shost_rd_attr2(field, field, format_string)
  129. /*
  130. * Create the actual show/store functions and data structures.
  131. */
  132. static ssize_t
  133. store_scan(struct device *dev, struct device_attribute *attr,
  134. const char *buf, size_t count)
  135. {
  136. struct Scsi_Host *shost = class_to_shost(dev);
  137. int res;
  138. res = scsi_scan(shost, buf);
  139. if (res == 0)
  140. res = count;
  141. return res;
  142. };
  143. static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
  144. static ssize_t
  145. store_shost_state(struct device *dev, struct device_attribute *attr,
  146. const char *buf, size_t count)
  147. {
  148. int i;
  149. struct Scsi_Host *shost = class_to_shost(dev);
  150. enum scsi_host_state state = 0;
  151. for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
  152. const int len = strlen(shost_states[i].name);
  153. if (strncmp(shost_states[i].name, buf, len) == 0 &&
  154. buf[len] == '\n') {
  155. state = shost_states[i].value;
  156. break;
  157. }
  158. }
  159. if (!state)
  160. return -EINVAL;
  161. if (scsi_host_set_state(shost, state))
  162. return -EINVAL;
  163. return count;
  164. }
  165. static ssize_t
  166. show_shost_state(struct device *dev, struct device_attribute *attr, char *buf)
  167. {
  168. struct Scsi_Host *shost = class_to_shost(dev);
  169. const char *name = scsi_host_state_name(shost->shost_state);
  170. if (!name)
  171. return -EINVAL;
  172. return snprintf(buf, 20, "%s\n", name);
  173. }
  174. /* DEVICE_ATTR(state) clashes with dev_attr_state for sdev */
  175. struct device_attribute dev_attr_hstate =
  176. __ATTR(state, S_IRUGO | S_IWUSR, show_shost_state, store_shost_state);
  177. static ssize_t
  178. show_shost_mode(unsigned int mode, char *buf)
  179. {
  180. ssize_t len = 0;
  181. if (mode & MODE_INITIATOR)
  182. len = sprintf(buf, "%s", "Initiator");
  183. if (mode & MODE_TARGET)
  184. len += sprintf(buf + len, "%s%s", len ? ", " : "", "Target");
  185. len += sprintf(buf + len, "\n");
  186. return len;
  187. }
  188. static ssize_t
  189. show_shost_supported_mode(struct device *dev, struct device_attribute *attr,
  190. char *buf)
  191. {
  192. struct Scsi_Host *shost = class_to_shost(dev);
  193. unsigned int supported_mode = shost->hostt->supported_mode;
  194. if (supported_mode == MODE_UNKNOWN)
  195. /* by default this should be initiator */
  196. supported_mode = MODE_INITIATOR;
  197. return show_shost_mode(supported_mode, buf);
  198. }
  199. static DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
  200. static ssize_t
  201. show_shost_active_mode(struct device *dev,
  202. struct device_attribute *attr, char *buf)
  203. {
  204. struct Scsi_Host *shost = class_to_shost(dev);
  205. if (shost->active_mode == MODE_UNKNOWN)
  206. return snprintf(buf, 20, "unknown\n");
  207. else
  208. return show_shost_mode(shost->active_mode, buf);
  209. }
  210. static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
  211. static int check_reset_type(const char *str)
  212. {
  213. if (sysfs_streq(str, "adapter"))
  214. return SCSI_ADAPTER_RESET;
  215. else if (sysfs_streq(str, "firmware"))
  216. return SCSI_FIRMWARE_RESET;
  217. else
  218. return 0;
  219. }
  220. static ssize_t
  221. store_host_reset(struct device *dev, struct device_attribute *attr,
  222. const char *buf, size_t count)
  223. {
  224. struct Scsi_Host *shost = class_to_shost(dev);
  225. struct scsi_host_template *sht = shost->hostt;
  226. int ret = -EINVAL;
  227. int type;
  228. type = check_reset_type(buf);
  229. if (!type)
  230. goto exit_store_host_reset;
  231. if (sht->host_reset)
  232. ret = sht->host_reset(shost, type);
  233. exit_store_host_reset:
  234. if (ret == 0)
  235. ret = count;
  236. return ret;
  237. }
  238. static DEVICE_ATTR(host_reset, S_IWUSR, NULL, store_host_reset);
  239. static ssize_t
  240. show_shost_eh_deadline(struct device *dev,
  241. struct device_attribute *attr, char *buf)
  242. {
  243. struct Scsi_Host *shost = class_to_shost(dev);
  244. if (shost->eh_deadline == -1)
  245. return snprintf(buf, strlen("off") + 2, "off\n");
  246. return sprintf(buf, "%u\n", shost->eh_deadline / HZ);
  247. }
  248. static ssize_t
  249. store_shost_eh_deadline(struct device *dev, struct device_attribute *attr,
  250. const char *buf, size_t count)
  251. {
  252. struct Scsi_Host *shost = class_to_shost(dev);
  253. int ret = -EINVAL;
  254. unsigned long deadline, flags;
  255. if (shost->transportt &&
  256. (shost->transportt->eh_strategy_handler ||
  257. !shost->hostt->eh_host_reset_handler))
  258. return ret;
  259. if (!strncmp(buf, "off", strlen("off")))
  260. deadline = -1;
  261. else {
  262. ret = kstrtoul(buf, 10, &deadline);
  263. if (ret)
  264. return ret;
  265. if (deadline * HZ > UINT_MAX)
  266. return -EINVAL;
  267. }
  268. spin_lock_irqsave(shost->host_lock, flags);
  269. if (scsi_host_in_recovery(shost))
  270. ret = -EBUSY;
  271. else {
  272. if (deadline == -1)
  273. shost->eh_deadline = -1;
  274. else
  275. shost->eh_deadline = deadline * HZ;
  276. ret = count;
  277. }
  278. spin_unlock_irqrestore(shost->host_lock, flags);
  279. return ret;
  280. }
  281. static DEVICE_ATTR(eh_deadline, S_IRUGO | S_IWUSR, show_shost_eh_deadline, store_shost_eh_deadline);
  282. shost_rd_attr(use_blk_mq, "%d\n");
  283. shost_rd_attr(unique_id, "%u\n");
  284. shost_rd_attr(cmd_per_lun, "%hd\n");
  285. shost_rd_attr(can_queue, "%hd\n");
  286. shost_rd_attr(sg_tablesize, "%hu\n");
  287. shost_rd_attr(sg_prot_tablesize, "%hu\n");
  288. shost_rd_attr(unchecked_isa_dma, "%d\n");
  289. shost_rd_attr(prot_capabilities, "%u\n");
  290. shost_rd_attr(prot_guard_type, "%hd\n");
  291. shost_rd_attr2(proc_name, hostt->proc_name, "%s\n");
  292. static ssize_t
  293. show_host_busy(struct device *dev, struct device_attribute *attr, char *buf)
  294. {
  295. struct Scsi_Host *shost = class_to_shost(dev);
  296. return snprintf(buf, 20, "%d\n", atomic_read(&shost->host_busy));
  297. }
  298. static DEVICE_ATTR(host_busy, S_IRUGO, show_host_busy, NULL);
  299. static struct attribute *scsi_sysfs_shost_attrs[] = {
  300. &dev_attr_use_blk_mq.attr,
  301. &dev_attr_unique_id.attr,
  302. &dev_attr_host_busy.attr,
  303. &dev_attr_cmd_per_lun.attr,
  304. &dev_attr_can_queue.attr,
  305. &dev_attr_sg_tablesize.attr,
  306. &dev_attr_sg_prot_tablesize.attr,
  307. &dev_attr_unchecked_isa_dma.attr,
  308. &dev_attr_proc_name.attr,
  309. &dev_attr_scan.attr,
  310. &dev_attr_hstate.attr,
  311. &dev_attr_supported_mode.attr,
  312. &dev_attr_active_mode.attr,
  313. &dev_attr_prot_capabilities.attr,
  314. &dev_attr_prot_guard_type.attr,
  315. &dev_attr_host_reset.attr,
  316. &dev_attr_eh_deadline.attr,
  317. NULL
  318. };
  319. struct attribute_group scsi_shost_attr_group = {
  320. .attrs = scsi_sysfs_shost_attrs,
  321. };
  322. const struct attribute_group *scsi_sysfs_shost_attr_groups[] = {
  323. &scsi_shost_attr_group,
  324. NULL
  325. };
  326. static void scsi_device_cls_release(struct device *class_dev)
  327. {
  328. struct scsi_device *sdev;
  329. sdev = class_to_sdev(class_dev);
  330. put_device(&sdev->sdev_gendev);
  331. }
  332. static void scsi_device_dev_release_usercontext(struct work_struct *work)
  333. {
  334. struct scsi_device *sdev;
  335. struct device *parent;
  336. struct list_head *this, *tmp;
  337. unsigned long flags;
  338. sdev = container_of(work, struct scsi_device, ew.work);
  339. parent = sdev->sdev_gendev.parent;
  340. spin_lock_irqsave(sdev->host->host_lock, flags);
  341. list_del(&sdev->siblings);
  342. list_del(&sdev->same_target_siblings);
  343. list_del(&sdev->starved_entry);
  344. spin_unlock_irqrestore(sdev->host->host_lock, flags);
  345. cancel_work_sync(&sdev->event_work);
  346. list_for_each_safe(this, tmp, &sdev->event_list) {
  347. struct scsi_event *evt;
  348. evt = list_entry(this, struct scsi_event, node);
  349. list_del(&evt->node);
  350. kfree(evt);
  351. }
  352. blk_put_queue(sdev->request_queue);
  353. /* NULL queue means the device can't be used */
  354. sdev->request_queue = NULL;
  355. kfree(sdev->vpd_pg83);
  356. kfree(sdev->vpd_pg80);
  357. kfree(sdev->inquiry);
  358. kfree(sdev);
  359. if (parent)
  360. put_device(parent);
  361. }
  362. static void scsi_device_dev_release(struct device *dev)
  363. {
  364. struct scsi_device *sdp = to_scsi_device(dev);
  365. execute_in_process_context(scsi_device_dev_release_usercontext,
  366. &sdp->ew);
  367. }
  368. static struct class sdev_class = {
  369. .name = "scsi_device",
  370. .dev_release = scsi_device_cls_release,
  371. };
  372. /* all probing is done in the individual ->probe routines */
  373. static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
  374. {
  375. struct scsi_device *sdp;
  376. if (dev->type != &scsi_dev_type)
  377. return 0;
  378. sdp = to_scsi_device(dev);
  379. if (sdp->no_uld_attach)
  380. return 0;
  381. return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
  382. }
  383. static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
  384. {
  385. struct scsi_device *sdev;
  386. if (dev->type != &scsi_dev_type)
  387. return 0;
  388. sdev = to_scsi_device(dev);
  389. add_uevent_var(env, "MODALIAS=" SCSI_DEVICE_MODALIAS_FMT, sdev->type);
  390. return 0;
  391. }
  392. struct bus_type scsi_bus_type = {
  393. .name = "scsi",
  394. .match = scsi_bus_match,
  395. .uevent = scsi_bus_uevent,
  396. #ifdef CONFIG_PM
  397. .pm = &scsi_bus_pm_ops,
  398. #endif
  399. };
  400. EXPORT_SYMBOL_GPL(scsi_bus_type);
  401. int scsi_sysfs_register(void)
  402. {
  403. int error;
  404. error = bus_register(&scsi_bus_type);
  405. if (!error) {
  406. error = class_register(&sdev_class);
  407. if (error)
  408. bus_unregister(&scsi_bus_type);
  409. }
  410. return error;
  411. }
  412. void scsi_sysfs_unregister(void)
  413. {
  414. class_unregister(&sdev_class);
  415. bus_unregister(&scsi_bus_type);
  416. }
  417. /*
  418. * sdev_show_function: macro to create an attr function that can be used to
  419. * show a non-bit field.
  420. */
  421. #define sdev_show_function(field, format_string) \
  422. static ssize_t \
  423. sdev_show_##field (struct device *dev, struct device_attribute *attr, \
  424. char *buf) \
  425. { \
  426. struct scsi_device *sdev; \
  427. sdev = to_scsi_device(dev); \
  428. return snprintf (buf, 20, format_string, sdev->field); \
  429. } \
  430. /*
  431. * sdev_rd_attr: macro to create a function and attribute variable for a
  432. * read only field.
  433. */
  434. #define sdev_rd_attr(field, format_string) \
  435. sdev_show_function(field, format_string) \
  436. static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
  437. /*
  438. * sdev_rw_attr: create a function and attribute variable for a
  439. * read/write field.
  440. */
  441. #define sdev_rw_attr(field, format_string) \
  442. sdev_show_function(field, format_string) \
  443. \
  444. static ssize_t \
  445. sdev_store_##field (struct device *dev, struct device_attribute *attr, \
  446. const char *buf, size_t count) \
  447. { \
  448. struct scsi_device *sdev; \
  449. sdev = to_scsi_device(dev); \
  450. sscanf (buf, format_string, &sdev->field); \
  451. return count; \
  452. } \
  453. static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
  454. /* Currently we don't export bit fields, but we might in future,
  455. * so leave this code in */
  456. #if 0
  457. /*
  458. * sdev_rd_attr: create a function and attribute variable for a
  459. * read/write bit field.
  460. */
  461. #define sdev_rw_attr_bit(field) \
  462. sdev_show_function(field, "%d\n") \
  463. \
  464. static ssize_t \
  465. sdev_store_##field (struct device *dev, struct device_attribute *attr, \
  466. const char *buf, size_t count) \
  467. { \
  468. int ret; \
  469. struct scsi_device *sdev; \
  470. ret = scsi_sdev_check_buf_bit(buf); \
  471. if (ret >= 0) { \
  472. sdev = to_scsi_device(dev); \
  473. sdev->field = ret; \
  474. ret = count; \
  475. } \
  476. return ret; \
  477. } \
  478. static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
  479. /*
  480. * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
  481. * else return -EINVAL.
  482. */
  483. static int scsi_sdev_check_buf_bit(const char *buf)
  484. {
  485. if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) {
  486. if (buf[0] == '1')
  487. return 1;
  488. else if (buf[0] == '0')
  489. return 0;
  490. else
  491. return -EINVAL;
  492. } else
  493. return -EINVAL;
  494. }
  495. #endif
  496. /*
  497. * Create the actual show/store functions and data structures.
  498. */
  499. sdev_rd_attr (type, "%d\n");
  500. sdev_rd_attr (scsi_level, "%d\n");
  501. sdev_rd_attr (vendor, "%.8s\n");
  502. sdev_rd_attr (model, "%.16s\n");
  503. sdev_rd_attr (rev, "%.4s\n");
  504. static ssize_t
  505. sdev_show_device_busy(struct device *dev, struct device_attribute *attr,
  506. char *buf)
  507. {
  508. struct scsi_device *sdev = to_scsi_device(dev);
  509. return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_busy));
  510. }
  511. static DEVICE_ATTR(device_busy, S_IRUGO, sdev_show_device_busy, NULL);
  512. static ssize_t
  513. sdev_show_device_blocked(struct device *dev, struct device_attribute *attr,
  514. char *buf)
  515. {
  516. struct scsi_device *sdev = to_scsi_device(dev);
  517. return snprintf(buf, 20, "%d\n", atomic_read(&sdev->device_blocked));
  518. }
  519. static DEVICE_ATTR(device_blocked, S_IRUGO, sdev_show_device_blocked, NULL);
  520. /*
  521. * TODO: can we make these symlinks to the block layer ones?
  522. */
  523. static ssize_t
  524. sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
  525. {
  526. struct scsi_device *sdev;
  527. sdev = to_scsi_device(dev);
  528. return snprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ);
  529. }
  530. static ssize_t
  531. sdev_store_timeout (struct device *dev, struct device_attribute *attr,
  532. const char *buf, size_t count)
  533. {
  534. struct scsi_device *sdev;
  535. int timeout;
  536. sdev = to_scsi_device(dev);
  537. sscanf (buf, "%d\n", &timeout);
  538. blk_queue_rq_timeout(sdev->request_queue, timeout * HZ);
  539. return count;
  540. }
  541. static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
  542. static ssize_t
  543. sdev_show_eh_timeout(struct device *dev, struct device_attribute *attr, char *buf)
  544. {
  545. struct scsi_device *sdev;
  546. sdev = to_scsi_device(dev);
  547. return snprintf(buf, 20, "%u\n", sdev->eh_timeout / HZ);
  548. }
  549. static ssize_t
  550. sdev_store_eh_timeout(struct device *dev, struct device_attribute *attr,
  551. const char *buf, size_t count)
  552. {
  553. struct scsi_device *sdev;
  554. unsigned int eh_timeout;
  555. int err;
  556. if (!capable(CAP_SYS_ADMIN))
  557. return -EACCES;
  558. sdev = to_scsi_device(dev);
  559. err = kstrtouint(buf, 10, &eh_timeout);
  560. if (err)
  561. return err;
  562. sdev->eh_timeout = eh_timeout * HZ;
  563. return count;
  564. }
  565. static DEVICE_ATTR(eh_timeout, S_IRUGO | S_IWUSR, sdev_show_eh_timeout, sdev_store_eh_timeout);
  566. static ssize_t
  567. store_rescan_field (struct device *dev, struct device_attribute *attr,
  568. const char *buf, size_t count)
  569. {
  570. scsi_rescan_device(dev);
  571. return count;
  572. }
  573. static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
  574. static ssize_t
  575. sdev_store_delete(struct device *dev, struct device_attribute *attr,
  576. const char *buf, size_t count)
  577. {
  578. if (device_remove_file_self(dev, attr))
  579. scsi_remove_device(to_scsi_device(dev));
  580. return count;
  581. };
  582. static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
  583. static ssize_t
  584. store_state_field(struct device *dev, struct device_attribute *attr,
  585. const char *buf, size_t count)
  586. {
  587. int i;
  588. struct scsi_device *sdev = to_scsi_device(dev);
  589. enum scsi_device_state state = 0;
  590. for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
  591. const int len = strlen(sdev_states[i].name);
  592. if (strncmp(sdev_states[i].name, buf, len) == 0 &&
  593. buf[len] == '\n') {
  594. state = sdev_states[i].value;
  595. break;
  596. }
  597. }
  598. if (!state)
  599. return -EINVAL;
  600. if (scsi_device_set_state(sdev, state))
  601. return -EINVAL;
  602. return count;
  603. }
  604. static ssize_t
  605. show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
  606. {
  607. struct scsi_device *sdev = to_scsi_device(dev);
  608. const char *name = scsi_device_state_name(sdev->sdev_state);
  609. if (!name)
  610. return -EINVAL;
  611. return snprintf(buf, 20, "%s\n", name);
  612. }
  613. static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
  614. static ssize_t
  615. show_queue_type_field(struct device *dev, struct device_attribute *attr,
  616. char *buf)
  617. {
  618. struct scsi_device *sdev = to_scsi_device(dev);
  619. const char *name = "none";
  620. if (sdev->simple_tags)
  621. name = "simple";
  622. return snprintf(buf, 20, "%s\n", name);
  623. }
  624. static ssize_t
  625. store_queue_type_field(struct device *dev, struct device_attribute *attr,
  626. const char *buf, size_t count)
  627. {
  628. struct scsi_device *sdev = to_scsi_device(dev);
  629. struct scsi_host_template *sht = sdev->host->hostt;
  630. int tag_type = 0, retval;
  631. int prev_tag_type = scsi_get_tag_type(sdev);
  632. if (!sdev->tagged_supported || !sht->change_queue_type)
  633. return -EINVAL;
  634. /*
  635. * We're never issueing order tags these days, but allow the value
  636. * for backwards compatibility.
  637. */
  638. if (strncmp(buf, "ordered", 7) == 0 ||
  639. strncmp(buf, "simple", 6) == 0)
  640. tag_type = MSG_SIMPLE_TAG;
  641. else if (strncmp(buf, "none", 4) != 0)
  642. return -EINVAL;
  643. if (tag_type == prev_tag_type)
  644. return count;
  645. retval = sht->change_queue_type(sdev, tag_type);
  646. if (retval < 0)
  647. return retval;
  648. return count;
  649. }
  650. static DEVICE_ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
  651. store_queue_type_field);
  652. #define sdev_vpd_pg_attr(_page) \
  653. static ssize_t \
  654. show_vpd_##_page(struct file *filp, struct kobject *kobj, \
  655. struct bin_attribute *bin_attr, \
  656. char *buf, loff_t off, size_t count) \
  657. { \
  658. struct device *dev = container_of(kobj, struct device, kobj); \
  659. struct scsi_device *sdev = to_scsi_device(dev); \
  660. if (!sdev->vpd_##_page) \
  661. return -EINVAL; \
  662. return memory_read_from_buffer(buf, count, &off, \
  663. sdev->vpd_##_page, \
  664. sdev->vpd_##_page##_len); \
  665. } \
  666. static struct bin_attribute dev_attr_vpd_##_page = { \
  667. .attr = {.name = __stringify(vpd_##_page), .mode = S_IRUGO }, \
  668. .size = 0, \
  669. .read = show_vpd_##_page, \
  670. };
  671. sdev_vpd_pg_attr(pg83);
  672. sdev_vpd_pg_attr(pg80);
  673. static ssize_t
  674. show_iostat_counterbits(struct device *dev, struct device_attribute *attr,
  675. char *buf)
  676. {
  677. return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8);
  678. }
  679. static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL);
  680. #define show_sdev_iostat(field) \
  681. static ssize_t \
  682. show_iostat_##field(struct device *dev, struct device_attribute *attr, \
  683. char *buf) \
  684. { \
  685. struct scsi_device *sdev = to_scsi_device(dev); \
  686. unsigned long long count = atomic_read(&sdev->field); \
  687. return snprintf(buf, 20, "0x%llx\n", count); \
  688. } \
  689. static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
  690. show_sdev_iostat(iorequest_cnt);
  691. show_sdev_iostat(iodone_cnt);
  692. show_sdev_iostat(ioerr_cnt);
  693. static ssize_t
  694. sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
  695. {
  696. struct scsi_device *sdev;
  697. sdev = to_scsi_device(dev);
  698. return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
  699. }
  700. static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
  701. #define DECLARE_EVT_SHOW(name, Cap_name) \
  702. static ssize_t \
  703. sdev_show_evt_##name(struct device *dev, struct device_attribute *attr, \
  704. char *buf) \
  705. { \
  706. struct scsi_device *sdev = to_scsi_device(dev); \
  707. int val = test_bit(SDEV_EVT_##Cap_name, sdev->supported_events);\
  708. return snprintf(buf, 20, "%d\n", val); \
  709. }
  710. #define DECLARE_EVT_STORE(name, Cap_name) \
  711. static ssize_t \
  712. sdev_store_evt_##name(struct device *dev, struct device_attribute *attr,\
  713. const char *buf, size_t count) \
  714. { \
  715. struct scsi_device *sdev = to_scsi_device(dev); \
  716. int val = simple_strtoul(buf, NULL, 0); \
  717. if (val == 0) \
  718. clear_bit(SDEV_EVT_##Cap_name, sdev->supported_events); \
  719. else if (val == 1) \
  720. set_bit(SDEV_EVT_##Cap_name, sdev->supported_events); \
  721. else \
  722. return -EINVAL; \
  723. return count; \
  724. }
  725. #define DECLARE_EVT(name, Cap_name) \
  726. DECLARE_EVT_SHOW(name, Cap_name) \
  727. DECLARE_EVT_STORE(name, Cap_name) \
  728. static DEVICE_ATTR(evt_##name, S_IRUGO, sdev_show_evt_##name, \
  729. sdev_store_evt_##name);
  730. #define REF_EVT(name) &dev_attr_evt_##name.attr
  731. DECLARE_EVT(media_change, MEDIA_CHANGE)
  732. DECLARE_EVT(inquiry_change_reported, INQUIRY_CHANGE_REPORTED)
  733. DECLARE_EVT(capacity_change_reported, CAPACITY_CHANGE_REPORTED)
  734. DECLARE_EVT(soft_threshold_reached, SOFT_THRESHOLD_REACHED_REPORTED)
  735. DECLARE_EVT(mode_parameter_change_reported, MODE_PARAMETER_CHANGE_REPORTED)
  736. DECLARE_EVT(lun_change_reported, LUN_CHANGE_REPORTED)
  737. static ssize_t
  738. sdev_store_queue_depth(struct device *dev, struct device_attribute *attr,
  739. const char *buf, size_t count)
  740. {
  741. int depth, retval;
  742. struct scsi_device *sdev = to_scsi_device(dev);
  743. struct scsi_host_template *sht = sdev->host->hostt;
  744. if (!sht->change_queue_depth)
  745. return -EINVAL;
  746. depth = simple_strtoul(buf, NULL, 0);
  747. if (depth < 1 || depth > sht->can_queue)
  748. return -EINVAL;
  749. retval = sht->change_queue_depth(sdev, depth);
  750. if (retval < 0)
  751. return retval;
  752. sdev->max_queue_depth = sdev->queue_depth;
  753. return count;
  754. }
  755. sdev_show_function(queue_depth, "%d\n");
  756. static DEVICE_ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
  757. sdev_store_queue_depth);
  758. static ssize_t
  759. sdev_show_queue_ramp_up_period(struct device *dev,
  760. struct device_attribute *attr,
  761. char *buf)
  762. {
  763. struct scsi_device *sdev;
  764. sdev = to_scsi_device(dev);
  765. return snprintf(buf, 20, "%u\n",
  766. jiffies_to_msecs(sdev->queue_ramp_up_period));
  767. }
  768. static ssize_t
  769. sdev_store_queue_ramp_up_period(struct device *dev,
  770. struct device_attribute *attr,
  771. const char *buf, size_t count)
  772. {
  773. struct scsi_device *sdev = to_scsi_device(dev);
  774. unsigned int period;
  775. if (kstrtouint(buf, 10, &period))
  776. return -EINVAL;
  777. sdev->queue_ramp_up_period = msecs_to_jiffies(period);
  778. return period;
  779. }
  780. static DEVICE_ATTR(queue_ramp_up_period, S_IRUGO | S_IWUSR,
  781. sdev_show_queue_ramp_up_period,
  782. sdev_store_queue_ramp_up_period);
  783. static umode_t scsi_sdev_attr_is_visible(struct kobject *kobj,
  784. struct attribute *attr, int i)
  785. {
  786. struct device *dev = container_of(kobj, struct device, kobj);
  787. struct scsi_device *sdev = to_scsi_device(dev);
  788. if (attr == &dev_attr_queue_depth.attr &&
  789. !sdev->host->hostt->change_queue_depth)
  790. return S_IRUGO;
  791. if (attr == &dev_attr_queue_ramp_up_period.attr &&
  792. !sdev->host->hostt->change_queue_depth)
  793. return 0;
  794. if (attr == &dev_attr_queue_type.attr &&
  795. !sdev->host->hostt->change_queue_type)
  796. return S_IRUGO;
  797. return attr->mode;
  798. }
  799. /* Default template for device attributes. May NOT be modified */
  800. static struct attribute *scsi_sdev_attrs[] = {
  801. &dev_attr_device_blocked.attr,
  802. &dev_attr_type.attr,
  803. &dev_attr_scsi_level.attr,
  804. &dev_attr_device_busy.attr,
  805. &dev_attr_vendor.attr,
  806. &dev_attr_model.attr,
  807. &dev_attr_rev.attr,
  808. &dev_attr_rescan.attr,
  809. &dev_attr_delete.attr,
  810. &dev_attr_state.attr,
  811. &dev_attr_timeout.attr,
  812. &dev_attr_eh_timeout.attr,
  813. &dev_attr_iocounterbits.attr,
  814. &dev_attr_iorequest_cnt.attr,
  815. &dev_attr_iodone_cnt.attr,
  816. &dev_attr_ioerr_cnt.attr,
  817. &dev_attr_modalias.attr,
  818. &dev_attr_queue_depth.attr,
  819. &dev_attr_queue_type.attr,
  820. &dev_attr_queue_ramp_up_period.attr,
  821. REF_EVT(media_change),
  822. REF_EVT(inquiry_change_reported),
  823. REF_EVT(capacity_change_reported),
  824. REF_EVT(soft_threshold_reached),
  825. REF_EVT(mode_parameter_change_reported),
  826. REF_EVT(lun_change_reported),
  827. NULL
  828. };
  829. static struct bin_attribute *scsi_sdev_bin_attrs[] = {
  830. &dev_attr_vpd_pg83,
  831. &dev_attr_vpd_pg80,
  832. NULL
  833. };
  834. static struct attribute_group scsi_sdev_attr_group = {
  835. .attrs = scsi_sdev_attrs,
  836. .bin_attrs = scsi_sdev_bin_attrs,
  837. .is_visible = scsi_sdev_attr_is_visible,
  838. };
  839. static const struct attribute_group *scsi_sdev_attr_groups[] = {
  840. &scsi_sdev_attr_group,
  841. NULL
  842. };
  843. static int scsi_target_add(struct scsi_target *starget)
  844. {
  845. int error;
  846. if (starget->state != STARGET_CREATED)
  847. return 0;
  848. error = device_add(&starget->dev);
  849. if (error) {
  850. dev_err(&starget->dev, "target device_add failed, error %d\n", error);
  851. return error;
  852. }
  853. transport_add_device(&starget->dev);
  854. starget->state = STARGET_RUNNING;
  855. pm_runtime_set_active(&starget->dev);
  856. pm_runtime_enable(&starget->dev);
  857. device_enable_async_suspend(&starget->dev);
  858. return 0;
  859. }
  860. /**
  861. * scsi_sysfs_add_sdev - add scsi device to sysfs
  862. * @sdev: scsi_device to add
  863. *
  864. * Return value:
  865. * 0 on Success / non-zero on Failure
  866. **/
  867. int scsi_sysfs_add_sdev(struct scsi_device *sdev)
  868. {
  869. int error, i;
  870. struct request_queue *rq = sdev->request_queue;
  871. struct scsi_target *starget = sdev->sdev_target;
  872. error = scsi_device_set_state(sdev, SDEV_RUNNING);
  873. if (error)
  874. return error;
  875. error = scsi_target_add(starget);
  876. if (error)
  877. return error;
  878. transport_configure_device(&starget->dev);
  879. device_enable_async_suspend(&sdev->sdev_gendev);
  880. scsi_autopm_get_target(starget);
  881. pm_runtime_set_active(&sdev->sdev_gendev);
  882. pm_runtime_forbid(&sdev->sdev_gendev);
  883. pm_runtime_enable(&sdev->sdev_gendev);
  884. scsi_autopm_put_target(starget);
  885. scsi_autopm_get_device(sdev);
  886. error = device_add(&sdev->sdev_gendev);
  887. if (error) {
  888. sdev_printk(KERN_INFO, sdev,
  889. "failed to add device: %d\n", error);
  890. return error;
  891. }
  892. device_enable_async_suspend(&sdev->sdev_dev);
  893. error = device_add(&sdev->sdev_dev);
  894. if (error) {
  895. sdev_printk(KERN_INFO, sdev,
  896. "failed to add class device: %d\n", error);
  897. device_del(&sdev->sdev_gendev);
  898. return error;
  899. }
  900. transport_add_device(&sdev->sdev_gendev);
  901. sdev->is_visible = 1;
  902. error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL, NULL);
  903. if (error)
  904. /* we're treating error on bsg register as non-fatal,
  905. * so pretend nothing went wrong */
  906. sdev_printk(KERN_INFO, sdev,
  907. "Failed to register bsg queue, errno=%d\n", error);
  908. /* add additional host specific attributes */
  909. if (sdev->host->hostt->sdev_attrs) {
  910. for (i = 0; sdev->host->hostt->sdev_attrs[i]; i++) {
  911. error = device_create_file(&sdev->sdev_gendev,
  912. sdev->host->hostt->sdev_attrs[i]);
  913. if (error)
  914. return error;
  915. }
  916. }
  917. scsi_autopm_put_device(sdev);
  918. return error;
  919. }
  920. void __scsi_remove_device(struct scsi_device *sdev)
  921. {
  922. struct device *dev = &sdev->sdev_gendev;
  923. if (sdev->is_visible) {
  924. if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
  925. return;
  926. bsg_unregister_queue(sdev->request_queue);
  927. device_unregister(&sdev->sdev_dev);
  928. transport_remove_device(dev);
  929. device_del(dev);
  930. } else
  931. put_device(&sdev->sdev_dev);
  932. /*
  933. * Stop accepting new requests and wait until all queuecommand() and
  934. * scsi_run_queue() invocations have finished before tearing down the
  935. * device.
  936. */
  937. scsi_device_set_state(sdev, SDEV_DEL);
  938. blk_cleanup_queue(sdev->request_queue);
  939. cancel_work_sync(&sdev->requeue_work);
  940. if (sdev->host->hostt->slave_destroy)
  941. sdev->host->hostt->slave_destroy(sdev);
  942. transport_destroy_device(dev);
  943. /*
  944. * Paired with the kref_get() in scsi_sysfs_initialize(). We have
  945. * remoed sysfs visibility from the device, so make the target
  946. * invisible if this was the last device underneath it.
  947. */
  948. scsi_target_reap(scsi_target(sdev));
  949. put_device(dev);
  950. }
  951. /**
  952. * scsi_remove_device - unregister a device from the scsi bus
  953. * @sdev: scsi_device to unregister
  954. **/
  955. void scsi_remove_device(struct scsi_device *sdev)
  956. {
  957. struct Scsi_Host *shost = sdev->host;
  958. mutex_lock(&shost->scan_mutex);
  959. __scsi_remove_device(sdev);
  960. mutex_unlock(&shost->scan_mutex);
  961. }
  962. EXPORT_SYMBOL(scsi_remove_device);
  963. static void __scsi_remove_target(struct scsi_target *starget)
  964. {
  965. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  966. unsigned long flags;
  967. struct scsi_device *sdev;
  968. spin_lock_irqsave(shost->host_lock, flags);
  969. restart:
  970. list_for_each_entry(sdev, &shost->__devices, siblings) {
  971. if (sdev->channel != starget->channel ||
  972. sdev->id != starget->id ||
  973. scsi_device_get(sdev))
  974. continue;
  975. spin_unlock_irqrestore(shost->host_lock, flags);
  976. scsi_remove_device(sdev);
  977. scsi_device_put(sdev);
  978. spin_lock_irqsave(shost->host_lock, flags);
  979. goto restart;
  980. }
  981. spin_unlock_irqrestore(shost->host_lock, flags);
  982. }
  983. /**
  984. * scsi_remove_target - try to remove a target and all its devices
  985. * @dev: generic starget or parent of generic stargets to be removed
  986. *
  987. * Note: This is slightly racy. It is possible that if the user
  988. * requests the addition of another device then the target won't be
  989. * removed.
  990. */
  991. void scsi_remove_target(struct device *dev)
  992. {
  993. struct Scsi_Host *shost = dev_to_shost(dev->parent);
  994. struct scsi_target *starget, *last = NULL;
  995. unsigned long flags;
  996. /* remove targets being careful to lookup next entry before
  997. * deleting the last
  998. */
  999. spin_lock_irqsave(shost->host_lock, flags);
  1000. list_for_each_entry(starget, &shost->__targets, siblings) {
  1001. if (starget->state == STARGET_DEL)
  1002. continue;
  1003. if (starget->dev.parent == dev || &starget->dev == dev) {
  1004. /* assuming new targets arrive at the end */
  1005. kref_get(&starget->reap_ref);
  1006. spin_unlock_irqrestore(shost->host_lock, flags);
  1007. if (last)
  1008. scsi_target_reap(last);
  1009. last = starget;
  1010. __scsi_remove_target(starget);
  1011. spin_lock_irqsave(shost->host_lock, flags);
  1012. }
  1013. }
  1014. spin_unlock_irqrestore(shost->host_lock, flags);
  1015. if (last)
  1016. scsi_target_reap(last);
  1017. }
  1018. EXPORT_SYMBOL(scsi_remove_target);
  1019. int scsi_register_driver(struct device_driver *drv)
  1020. {
  1021. drv->bus = &scsi_bus_type;
  1022. return driver_register(drv);
  1023. }
  1024. EXPORT_SYMBOL(scsi_register_driver);
  1025. int scsi_register_interface(struct class_interface *intf)
  1026. {
  1027. intf->class = &sdev_class;
  1028. return class_interface_register(intf);
  1029. }
  1030. EXPORT_SYMBOL(scsi_register_interface);
  1031. /**
  1032. * scsi_sysfs_add_host - add scsi host to subsystem
  1033. * @shost: scsi host struct to add to subsystem
  1034. **/
  1035. int scsi_sysfs_add_host(struct Scsi_Host *shost)
  1036. {
  1037. int error, i;
  1038. /* add host specific attributes */
  1039. if (shost->hostt->shost_attrs) {
  1040. for (i = 0; shost->hostt->shost_attrs[i]; i++) {
  1041. error = device_create_file(&shost->shost_dev,
  1042. shost->hostt->shost_attrs[i]);
  1043. if (error)
  1044. return error;
  1045. }
  1046. }
  1047. transport_register_device(&shost->shost_gendev);
  1048. transport_configure_device(&shost->shost_gendev);
  1049. return 0;
  1050. }
  1051. static struct device_type scsi_dev_type = {
  1052. .name = "scsi_device",
  1053. .release = scsi_device_dev_release,
  1054. .groups = scsi_sdev_attr_groups,
  1055. };
  1056. void scsi_sysfs_device_initialize(struct scsi_device *sdev)
  1057. {
  1058. unsigned long flags;
  1059. struct Scsi_Host *shost = sdev->host;
  1060. struct scsi_target *starget = sdev->sdev_target;
  1061. device_initialize(&sdev->sdev_gendev);
  1062. sdev->sdev_gendev.bus = &scsi_bus_type;
  1063. sdev->sdev_gendev.type = &scsi_dev_type;
  1064. dev_set_name(&sdev->sdev_gendev, "%d:%d:%d:%llu",
  1065. sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
  1066. device_initialize(&sdev->sdev_dev);
  1067. sdev->sdev_dev.parent = get_device(&sdev->sdev_gendev);
  1068. sdev->sdev_dev.class = &sdev_class;
  1069. dev_set_name(&sdev->sdev_dev, "%d:%d:%d:%llu",
  1070. sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
  1071. /*
  1072. * Get a default scsi_level from the target (derived from sibling
  1073. * devices). This is the best we can do for guessing how to set
  1074. * sdev->lun_in_cdb for the initial INQUIRY command. For LUN 0 the
  1075. * setting doesn't matter, because all the bits are zero anyway.
  1076. * But it does matter for higher LUNs.
  1077. */
  1078. sdev->scsi_level = starget->scsi_level;
  1079. if (sdev->scsi_level <= SCSI_2 &&
  1080. sdev->scsi_level != SCSI_UNKNOWN &&
  1081. !shost->no_scsi2_lun_in_cdb)
  1082. sdev->lun_in_cdb = 1;
  1083. transport_setup_device(&sdev->sdev_gendev);
  1084. spin_lock_irqsave(shost->host_lock, flags);
  1085. list_add_tail(&sdev->same_target_siblings, &starget->devices);
  1086. list_add_tail(&sdev->siblings, &shost->__devices);
  1087. spin_unlock_irqrestore(shost->host_lock, flags);
  1088. /*
  1089. * device can now only be removed via __scsi_remove_device() so hold
  1090. * the target. Target will be held in CREATED state until something
  1091. * beneath it becomes visible (in which case it moves to RUNNING)
  1092. */
  1093. kref_get(&starget->reap_ref);
  1094. }
  1095. int scsi_is_sdev_device(const struct device *dev)
  1096. {
  1097. return dev->type == &scsi_dev_type;
  1098. }
  1099. EXPORT_SYMBOL(scsi_is_sdev_device);
  1100. /* A blank transport template that is used in drivers that don't
  1101. * yet implement Transport Attributes */
  1102. struct scsi_transport_template blank_transport_template = { { { {NULL, }, }, }, };