4 * SCSI sysfs interface routines.
6 * Created to pull SCSI mid layer sysfs routines into one file.
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/blkdev.h>
12 #include <linux/device.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>
21 #include "scsi_priv.h"
22 #include "scsi_logging.h"
25 enum scsi_device_state value;
28 { SDEV_CREATED, "created" },
29 { SDEV_RUNNING, "running" },
30 { SDEV_CANCEL, "cancel" },
31 { SDEV_DEL, "deleted" },
32 { SDEV_QUIESCE, "quiesce" },
33 { SDEV_OFFLINE, "offline" },
34 { SDEV_BLOCK, "blocked" },
37 const char *scsi_device_state_name(enum scsi_device_state state)
42 for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
43 if (sdev_states[i].value == state) {
44 name = sdev_states[i].name;
52 enum scsi_host_state value;
55 { SHOST_CREATED, "created" },
56 { SHOST_RUNNING, "running" },
57 { SHOST_CANCEL, "cancel" },
58 { SHOST_DEL, "deleted" },
59 { SHOST_RECOVERY, "recovery" },
60 { SHOST_CANCEL_RECOVERY, "cancel/recovery" },
61 { SHOST_DEL_RECOVERY, "deleted/recovery", },
63 const char *scsi_host_state_name(enum scsi_host_state state)
68 for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
69 if (shost_states[i].value == state) {
70 name = shost_states[i].name;
77 static int check_set(unsigned int *val, char *src)
81 if (strncmp(src, "-", 20) == 0) {
82 *val = SCAN_WILD_CARD;
85 * Doesn't check for int overflow
87 *val = simple_strtoul(src, &last, 0);
94 static int scsi_scan(struct Scsi_Host *shost, const char *str)
96 char s1[15], s2[15], s3[15], junk;
97 unsigned int channel, id, lun;
100 res = sscanf(str, "%10s %10s %10s %c", s1, s2, s3, &junk);
103 if (check_set(&channel, s1))
105 if (check_set(&id, s2))
107 if (check_set(&lun, s3))
109 if (shost->transportt->user_scan)
110 res = shost->transportt->user_scan(shost, channel, id, lun);
112 res = scsi_scan_host_selected(shost, channel, id, lun, 1);
117 * shost_show_function: macro to create an attr function that can be used to
118 * show a non-bit field.
120 #define shost_show_function(name, field, format_string) \
122 show_##name (struct class_device *class_dev, char *buf) \
124 struct Scsi_Host *shost = class_to_shost(class_dev); \
125 return snprintf (buf, 20, format_string, shost->field); \
129 * shost_rd_attr: macro to create a function and attribute variable for a
132 #define shost_rd_attr2(name, field, format_string) \
133 shost_show_function(name, field, format_string) \
134 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
136 #define shost_rd_attr(field, format_string) \
137 shost_rd_attr2(field, field, format_string)
140 * Create the actual show/store functions and data structures.
143 static ssize_t store_scan(struct class_device *class_dev, const char *buf,
146 struct Scsi_Host *shost = class_to_shost(class_dev);
149 res = scsi_scan(shost, buf);
154 static CLASS_DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
157 store_shost_state(struct class_device *class_dev, const char *buf, size_t count)
160 struct Scsi_Host *shost = class_to_shost(class_dev);
161 enum scsi_host_state state = 0;
163 for (i = 0; i < ARRAY_SIZE(shost_states); i++) {
164 const int len = strlen(shost_states[i].name);
165 if (strncmp(shost_states[i].name, buf, len) == 0 &&
167 state = shost_states[i].value;
174 if (scsi_host_set_state(shost, state))
180 show_shost_state(struct class_device *class_dev, char *buf)
182 struct Scsi_Host *shost = class_to_shost(class_dev);
183 const char *name = scsi_host_state_name(shost->shost_state);
188 return snprintf(buf, 20, "%s\n", name);
191 static CLASS_DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_shost_state, store_shost_state);
193 shost_rd_attr(unique_id, "%u\n");
194 shost_rd_attr(host_busy, "%hu\n");
195 shost_rd_attr(cmd_per_lun, "%hd\n");
196 shost_rd_attr(can_queue, "%hd\n");
197 shost_rd_attr(sg_tablesize, "%hu\n");
198 shost_rd_attr(unchecked_isa_dma, "%d\n");
199 shost_rd_attr2(proc_name, hostt->proc_name, "%s\n");
201 static struct class_device_attribute *scsi_sysfs_shost_attrs[] = {
202 &class_device_attr_unique_id,
203 &class_device_attr_host_busy,
204 &class_device_attr_cmd_per_lun,
205 &class_device_attr_can_queue,
206 &class_device_attr_sg_tablesize,
207 &class_device_attr_unchecked_isa_dma,
208 &class_device_attr_proc_name,
209 &class_device_attr_scan,
210 &class_device_attr_state,
214 static void scsi_device_cls_release(struct class_device *class_dev)
216 struct scsi_device *sdev;
218 sdev = class_to_sdev(class_dev);
219 put_device(&sdev->sdev_gendev);
222 static void scsi_device_dev_release_usercontext(struct work_struct *work)
224 struct scsi_device *sdev;
225 struct device *parent;
226 struct scsi_target *starget;
229 sdev = container_of(work, struct scsi_device, ew.work);
231 parent = sdev->sdev_gendev.parent;
232 starget = to_scsi_target(parent);
234 spin_lock_irqsave(sdev->host->host_lock, flags);
236 list_del(&sdev->siblings);
237 list_del(&sdev->same_target_siblings);
238 list_del(&sdev->starved_entry);
239 spin_unlock_irqrestore(sdev->host->host_lock, flags);
241 if (sdev->request_queue) {
242 sdev->request_queue->queuedata = NULL;
243 /* user context needed to free queue */
244 scsi_free_queue(sdev->request_queue);
245 /* temporary expedient, try to catch use of queue lock
246 * after free of sdev */
247 sdev->request_queue = NULL;
250 scsi_target_reap(scsi_target(sdev));
252 kfree(sdev->inquiry);
259 static void scsi_device_dev_release(struct device *dev)
261 struct scsi_device *sdp = to_scsi_device(dev);
262 execute_in_process_context(scsi_device_dev_release_usercontext,
266 static struct class sdev_class = {
267 .name = "scsi_device",
268 .release = scsi_device_cls_release,
271 /* all probing is done in the individual ->probe routines */
272 static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
274 struct scsi_device *sdp = to_scsi_device(dev);
275 if (sdp->no_uld_attach)
277 return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
280 static int scsi_bus_uevent(struct device *dev, char **envp, int num_envp,
281 char *buffer, int buffer_size)
283 struct scsi_device *sdev = to_scsi_device(dev);
287 add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
288 "MODALIAS=" SCSI_DEVICE_MODALIAS_FMT, sdev->type);
293 static int scsi_bus_suspend(struct device * dev, pm_message_t state)
295 struct device_driver *drv = dev->driver;
296 struct scsi_device *sdev = to_scsi_device(dev);
299 err = scsi_device_quiesce(sdev);
303 if (drv && drv->suspend) {
304 err = drv->suspend(dev, state);
312 static int scsi_bus_resume(struct device * dev)
314 struct device_driver *drv = dev->driver;
315 struct scsi_device *sdev = to_scsi_device(dev);
318 if (drv && drv->resume)
319 err = drv->resume(dev);
321 scsi_device_resume(sdev);
326 struct bus_type scsi_bus_type = {
328 .match = scsi_bus_match,
329 .uevent = scsi_bus_uevent,
330 .suspend = scsi_bus_suspend,
331 .resume = scsi_bus_resume,
334 int scsi_sysfs_register(void)
338 error = bus_register(&scsi_bus_type);
340 error = class_register(&sdev_class);
342 bus_unregister(&scsi_bus_type);
348 void scsi_sysfs_unregister(void)
350 class_unregister(&sdev_class);
351 bus_unregister(&scsi_bus_type);
355 * sdev_show_function: macro to create an attr function that can be used to
356 * show a non-bit field.
358 #define sdev_show_function(field, format_string) \
360 sdev_show_##field (struct device *dev, struct device_attribute *attr, char *buf) \
362 struct scsi_device *sdev; \
363 sdev = to_scsi_device(dev); \
364 return snprintf (buf, 20, format_string, sdev->field); \
368 * sdev_rd_attr: macro to create a function and attribute variable for a
371 #define sdev_rd_attr(field, format_string) \
372 sdev_show_function(field, format_string) \
373 static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
377 * sdev_rd_attr: create a function and attribute variable for a
380 #define sdev_rw_attr(field, format_string) \
381 sdev_show_function(field, format_string) \
384 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
386 struct scsi_device *sdev; \
387 sdev = to_scsi_device(dev); \
388 snscanf (buf, 20, format_string, &sdev->field); \
391 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
393 /* Currently we don't export bit fields, but we might in future,
394 * so leave this code in */
397 * sdev_rd_attr: create a function and attribute variable for a
398 * read/write bit field.
400 #define sdev_rw_attr_bit(field) \
401 sdev_show_function(field, "%d\n") \
404 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
407 struct scsi_device *sdev; \
408 ret = scsi_sdev_check_buf_bit(buf); \
410 sdev = to_scsi_device(dev); \
416 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
419 * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
420 * else return -EINVAL.
422 static int scsi_sdev_check_buf_bit(const char *buf)
424 if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) {
427 else if (buf[0] == '0')
436 * Create the actual show/store functions and data structures.
438 sdev_rd_attr (device_blocked, "%d\n");
439 sdev_rd_attr (queue_depth, "%d\n");
440 sdev_rd_attr (type, "%d\n");
441 sdev_rd_attr (scsi_level, "%d\n");
442 sdev_rd_attr (vendor, "%.8s\n");
443 sdev_rd_attr (model, "%.16s\n");
444 sdev_rd_attr (rev, "%.4s\n");
447 sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
449 struct scsi_device *sdev;
450 sdev = to_scsi_device(dev);
451 return snprintf (buf, 20, "%d\n", sdev->timeout / HZ);
455 sdev_store_timeout (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
457 struct scsi_device *sdev;
459 sdev = to_scsi_device(dev);
460 sscanf (buf, "%d\n", &timeout);
461 sdev->timeout = timeout * HZ;
464 static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
467 store_rescan_field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
469 scsi_rescan_device(dev);
472 static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
474 static void sdev_store_delete_callback(struct device *dev)
476 scsi_remove_device(to_scsi_device(dev));
479 static ssize_t sdev_store_delete(struct device *dev, struct device_attribute *attr, const char *buf,
484 /* An attribute cannot be unregistered by one of its own methods,
485 * so we have to use this roundabout approach.
487 rc = device_schedule_callback(dev, sdev_store_delete_callback);
492 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
495 store_state_field(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
498 struct scsi_device *sdev = to_scsi_device(dev);
499 enum scsi_device_state state = 0;
501 for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
502 const int len = strlen(sdev_states[i].name);
503 if (strncmp(sdev_states[i].name, buf, len) == 0 &&
505 state = sdev_states[i].value;
512 if (scsi_device_set_state(sdev, state))
518 show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
520 struct scsi_device *sdev = to_scsi_device(dev);
521 const char *name = scsi_device_state_name(sdev->sdev_state);
526 return snprintf(buf, 20, "%s\n", name);
529 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
532 show_queue_type_field(struct device *dev, struct device_attribute *attr, char *buf)
534 struct scsi_device *sdev = to_scsi_device(dev);
535 const char *name = "none";
537 if (sdev->ordered_tags)
539 else if (sdev->simple_tags)
542 return snprintf(buf, 20, "%s\n", name);
545 static DEVICE_ATTR(queue_type, S_IRUGO, show_queue_type_field, NULL);
548 show_iostat_counterbits(struct device *dev, struct device_attribute *attr, char *buf)
550 return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8);
553 static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL);
555 #define show_sdev_iostat(field) \
557 show_iostat_##field(struct device *dev, struct device_attribute *attr, char *buf) \
559 struct scsi_device *sdev = to_scsi_device(dev); \
560 unsigned long long count = atomic_read(&sdev->field); \
561 return snprintf(buf, 20, "0x%llx\n", count); \
563 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
565 show_sdev_iostat(iorequest_cnt);
566 show_sdev_iostat(iodone_cnt);
567 show_sdev_iostat(ioerr_cnt);
570 sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
572 struct scsi_device *sdev;
573 sdev = to_scsi_device(dev);
574 return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
576 static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
578 /* Default template for device attributes. May NOT be modified */
579 static struct device_attribute *scsi_sysfs_sdev_attrs[] = {
580 &dev_attr_device_blocked,
581 &dev_attr_queue_depth,
582 &dev_attr_queue_type,
584 &dev_attr_scsi_level,
592 &dev_attr_iocounterbits,
593 &dev_attr_iorequest_cnt,
594 &dev_attr_iodone_cnt,
600 static ssize_t sdev_store_queue_depth_rw(struct device *dev, struct device_attribute *attr, const char *buf,
604 struct scsi_device *sdev = to_scsi_device(dev);
605 struct scsi_host_template *sht = sdev->host->hostt;
607 if (!sht->change_queue_depth)
610 depth = simple_strtoul(buf, NULL, 0);
615 retval = sht->change_queue_depth(sdev, depth);
622 static struct device_attribute sdev_attr_queue_depth_rw =
623 __ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
624 sdev_store_queue_depth_rw);
626 static ssize_t sdev_store_queue_type_rw(struct device *dev, struct device_attribute *attr, const char *buf,
629 struct scsi_device *sdev = to_scsi_device(dev);
630 struct scsi_host_template *sht = sdev->host->hostt;
631 int tag_type = 0, retval;
632 int prev_tag_type = scsi_get_tag_type(sdev);
634 if (!sdev->tagged_supported || !sht->change_queue_type)
637 if (strncmp(buf, "ordered", 7) == 0)
638 tag_type = MSG_ORDERED_TAG;
639 else if (strncmp(buf, "simple", 6) == 0)
640 tag_type = MSG_SIMPLE_TAG;
641 else if (strncmp(buf, "none", 4) != 0)
644 if (tag_type == prev_tag_type)
647 retval = sht->change_queue_type(sdev, tag_type);
654 static struct device_attribute sdev_attr_queue_type_rw =
655 __ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
656 sdev_store_queue_type_rw);
658 static struct device_attribute *attr_changed_internally(
659 struct Scsi_Host *shost,
660 struct device_attribute * attr)
662 if (!strcmp("queue_depth", attr->attr.name)
663 && shost->hostt->change_queue_depth)
664 return &sdev_attr_queue_depth_rw;
665 else if (!strcmp("queue_type", attr->attr.name)
666 && shost->hostt->change_queue_type)
667 return &sdev_attr_queue_type_rw;
672 static struct device_attribute *attr_overridden(
673 struct device_attribute **attrs,
674 struct device_attribute *attr)
680 for (i = 0; attrs[i]; i++)
681 if (!strcmp(attrs[i]->attr.name, attr->attr.name))
686 static int attr_add(struct device *dev, struct device_attribute *attr)
688 struct device_attribute *base_attr;
691 * Spare the caller from having to copy things it's not interested in.
693 base_attr = attr_overridden(scsi_sysfs_sdev_attrs, attr);
695 /* extend permissions */
696 attr->attr.mode |= base_attr->attr.mode;
698 /* override null show/store with default */
700 attr->show = base_attr->show;
702 attr->store = base_attr->store;
705 return device_create_file(dev, attr);
709 * scsi_sysfs_add_sdev - add scsi device to sysfs
710 * @sdev: scsi_device to add
713 * 0 on Success / non-zero on Failure
715 int scsi_sysfs_add_sdev(struct scsi_device *sdev)
719 if ((error = scsi_device_set_state(sdev, SDEV_RUNNING)) != 0)
722 error = device_add(&sdev->sdev_gendev);
724 put_device(sdev->sdev_gendev.parent);
725 printk(KERN_INFO "error 1\n");
728 error = class_device_add(&sdev->sdev_classdev);
730 printk(KERN_INFO "error 2\n");
734 /* take a reference for the sdev_classdev; this is
735 * released by the sdev_class .release */
736 get_device(&sdev->sdev_gendev);
737 if (sdev->host->hostt->sdev_attrs) {
738 for (i = 0; sdev->host->hostt->sdev_attrs[i]; i++) {
739 error = attr_add(&sdev->sdev_gendev,
740 sdev->host->hostt->sdev_attrs[i]);
742 __scsi_remove_device(sdev);
748 for (i = 0; scsi_sysfs_sdev_attrs[i]; i++) {
749 if (!attr_overridden(sdev->host->hostt->sdev_attrs,
750 scsi_sysfs_sdev_attrs[i])) {
751 struct device_attribute * attr =
752 attr_changed_internally(sdev->host,
753 scsi_sysfs_sdev_attrs[i]);
754 error = device_create_file(&sdev->sdev_gendev, attr);
756 __scsi_remove_device(sdev);
762 transport_add_device(&sdev->sdev_gendev);
767 scsi_device_set_state(sdev, SDEV_CANCEL);
769 device_del(&sdev->sdev_gendev);
770 transport_destroy_device(&sdev->sdev_gendev);
771 put_device(&sdev->sdev_gendev);
776 void __scsi_remove_device(struct scsi_device *sdev)
778 struct device *dev = &sdev->sdev_gendev;
780 if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
783 class_device_unregister(&sdev->sdev_classdev);
784 transport_remove_device(dev);
786 scsi_device_set_state(sdev, SDEV_DEL);
787 if (sdev->host->hostt->slave_destroy)
788 sdev->host->hostt->slave_destroy(sdev);
789 transport_destroy_device(dev);
794 * scsi_remove_device - unregister a device from the scsi bus
795 * @sdev: scsi_device to unregister
797 void scsi_remove_device(struct scsi_device *sdev)
799 struct Scsi_Host *shost = sdev->host;
801 mutex_lock(&shost->scan_mutex);
802 __scsi_remove_device(sdev);
803 mutex_unlock(&shost->scan_mutex);
805 EXPORT_SYMBOL(scsi_remove_device);
807 static void __scsi_remove_target(struct scsi_target *starget)
809 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
811 struct scsi_device *sdev;
813 spin_lock_irqsave(shost->host_lock, flags);
816 list_for_each_entry(sdev, &shost->__devices, siblings) {
817 if (sdev->channel != starget->channel ||
818 sdev->id != starget->id ||
819 sdev->sdev_state == SDEV_DEL)
821 spin_unlock_irqrestore(shost->host_lock, flags);
822 scsi_remove_device(sdev);
823 spin_lock_irqsave(shost->host_lock, flags);
826 spin_unlock_irqrestore(shost->host_lock, flags);
827 scsi_target_reap(starget);
830 static int __remove_child (struct device * dev, void * data)
832 if (scsi_is_target_device(dev))
833 __scsi_remove_target(to_scsi_target(dev));
838 * scsi_remove_target - try to remove a target and all its devices
839 * @dev: generic starget or parent of generic stargets to be removed
841 * Note: This is slightly racy. It is possible that if the user
842 * requests the addition of another device then the target won't be
845 void scsi_remove_target(struct device *dev)
849 if (scsi_is_target_device(dev)) {
850 __scsi_remove_target(to_scsi_target(dev));
854 rdev = get_device(dev);
855 device_for_each_child(dev, NULL, __remove_child);
858 EXPORT_SYMBOL(scsi_remove_target);
860 int scsi_register_driver(struct device_driver *drv)
862 drv->bus = &scsi_bus_type;
864 return driver_register(drv);
866 EXPORT_SYMBOL(scsi_register_driver);
868 int scsi_register_interface(struct class_interface *intf)
870 intf->class = &sdev_class;
872 return class_interface_register(intf);
874 EXPORT_SYMBOL(scsi_register_interface);
877 static struct class_device_attribute *class_attr_overridden(
878 struct class_device_attribute **attrs,
879 struct class_device_attribute *attr)
885 for (i = 0; attrs[i]; i++)
886 if (!strcmp(attrs[i]->attr.name, attr->attr.name))
891 static int class_attr_add(struct class_device *classdev,
892 struct class_device_attribute *attr)
894 struct class_device_attribute *base_attr;
897 * Spare the caller from having to copy things it's not interested in.
899 base_attr = class_attr_overridden(scsi_sysfs_shost_attrs, attr);
901 /* extend permissions */
902 attr->attr.mode |= base_attr->attr.mode;
904 /* override null show/store with default */
906 attr->show = base_attr->show;
908 attr->store = base_attr->store;
911 return class_device_create_file(classdev, attr);
915 * scsi_sysfs_add_host - add scsi host to subsystem
916 * @shost: scsi host struct to add to subsystem
917 * @dev: parent struct device pointer
919 int scsi_sysfs_add_host(struct Scsi_Host *shost)
923 if (shost->hostt->shost_attrs) {
924 for (i = 0; shost->hostt->shost_attrs[i]; i++) {
925 error = class_attr_add(&shost->shost_classdev,
926 shost->hostt->shost_attrs[i]);
932 for (i = 0; scsi_sysfs_shost_attrs[i]; i++) {
933 if (!class_attr_overridden(shost->hostt->shost_attrs,
934 scsi_sysfs_shost_attrs[i])) {
935 error = class_device_create_file(&shost->shost_classdev,
936 scsi_sysfs_shost_attrs[i]);
942 transport_register_device(&shost->shost_gendev);
946 void scsi_sysfs_device_initialize(struct scsi_device *sdev)
949 struct Scsi_Host *shost = sdev->host;
950 struct scsi_target *starget = sdev->sdev_target;
952 device_initialize(&sdev->sdev_gendev);
953 sdev->sdev_gendev.bus = &scsi_bus_type;
954 sdev->sdev_gendev.release = scsi_device_dev_release;
955 sprintf(sdev->sdev_gendev.bus_id,"%d:%d:%d:%d",
956 sdev->host->host_no, sdev->channel, sdev->id,
959 class_device_initialize(&sdev->sdev_classdev);
960 sdev->sdev_classdev.dev = &sdev->sdev_gendev;
961 sdev->sdev_classdev.class = &sdev_class;
962 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
963 "%d:%d:%d:%d", sdev->host->host_no,
964 sdev->channel, sdev->id, sdev->lun);
965 sdev->scsi_level = starget->scsi_level;
966 transport_setup_device(&sdev->sdev_gendev);
967 spin_lock_irqsave(shost->host_lock, flags);
968 list_add_tail(&sdev->same_target_siblings, &starget->devices);
969 list_add_tail(&sdev->siblings, &shost->__devices);
970 spin_unlock_irqrestore(shost->host_lock, flags);
973 int scsi_is_sdev_device(const struct device *dev)
975 return dev->release == scsi_device_dev_release;
977 EXPORT_SYMBOL(scsi_is_sdev_device);
979 /* A blank transport template that is used in drivers that don't
980 * yet implement Transport Attributes */
981 struct scsi_transport_template blank_transport_template = { { { {NULL, }, }, }, };