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);
194 show_shost_mode(unsigned int mode, char *buf)
198 if (mode & MODE_INITIATOR)
199 len = sprintf(buf, "%s", "Initiator");
201 if (mode & MODE_TARGET)
202 len += sprintf(buf + len, "%s%s", len ? ", " : "", "Target");
204 len += sprintf(buf + len, "\n");
209 static ssize_t show_shost_supported_mode(struct class_device *class_dev, char *buf)
211 struct Scsi_Host *shost = class_to_shost(class_dev);
212 unsigned int supported_mode = shost->hostt->supported_mode;
214 if (supported_mode == MODE_UNKNOWN)
215 /* by default this should be initiator */
216 supported_mode = MODE_INITIATOR;
218 return show_shost_mode(supported_mode, buf);
221 static CLASS_DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
223 static ssize_t show_shost_active_mode(struct class_device *class_dev, char *buf)
225 struct Scsi_Host *shost = class_to_shost(class_dev);
227 if (shost->active_mode == MODE_UNKNOWN)
228 return snprintf(buf, 20, "unknown\n");
230 return show_shost_mode(shost->active_mode, buf);
233 static CLASS_DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
235 shost_rd_attr(unique_id, "%u\n");
236 shost_rd_attr(host_busy, "%hu\n");
237 shost_rd_attr(cmd_per_lun, "%hd\n");
238 shost_rd_attr(can_queue, "%hd\n");
239 shost_rd_attr(sg_tablesize, "%hu\n");
240 shost_rd_attr(unchecked_isa_dma, "%d\n");
241 shost_rd_attr2(proc_name, hostt->proc_name, "%s\n");
243 static struct class_device_attribute *scsi_sysfs_shost_attrs[] = {
244 &class_device_attr_unique_id,
245 &class_device_attr_host_busy,
246 &class_device_attr_cmd_per_lun,
247 &class_device_attr_can_queue,
248 &class_device_attr_sg_tablesize,
249 &class_device_attr_unchecked_isa_dma,
250 &class_device_attr_proc_name,
251 &class_device_attr_scan,
252 &class_device_attr_state,
253 &class_device_attr_supported_mode,
254 &class_device_attr_active_mode,
258 static void scsi_device_cls_release(struct class_device *class_dev)
260 struct scsi_device *sdev;
262 sdev = class_to_sdev(class_dev);
263 put_device(&sdev->sdev_gendev);
266 static void scsi_device_dev_release_usercontext(struct work_struct *work)
268 struct scsi_device *sdev;
269 struct device *parent;
270 struct scsi_target *starget;
273 sdev = container_of(work, struct scsi_device, ew.work);
275 parent = sdev->sdev_gendev.parent;
276 starget = to_scsi_target(parent);
278 spin_lock_irqsave(sdev->host->host_lock, flags);
280 list_del(&sdev->siblings);
281 list_del(&sdev->same_target_siblings);
282 list_del(&sdev->starved_entry);
283 spin_unlock_irqrestore(sdev->host->host_lock, flags);
285 if (sdev->request_queue) {
286 sdev->request_queue->queuedata = NULL;
287 /* user context needed to free queue */
288 scsi_free_queue(sdev->request_queue);
289 /* temporary expedient, try to catch use of queue lock
290 * after free of sdev */
291 sdev->request_queue = NULL;
294 scsi_target_reap(scsi_target(sdev));
296 kfree(sdev->inquiry);
303 static void scsi_device_dev_release(struct device *dev)
305 struct scsi_device *sdp = to_scsi_device(dev);
306 execute_in_process_context(scsi_device_dev_release_usercontext,
310 static struct class sdev_class = {
311 .name = "scsi_device",
312 .release = scsi_device_cls_release,
315 /* all probing is done in the individual ->probe routines */
316 static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
318 struct scsi_device *sdp = to_scsi_device(dev);
319 if (sdp->no_uld_attach)
321 return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
324 static int scsi_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
326 struct scsi_device *sdev = to_scsi_device(dev);
328 add_uevent_var(env, "MODALIAS=" SCSI_DEVICE_MODALIAS_FMT, sdev->type);
332 static int scsi_bus_suspend(struct device * dev, pm_message_t state)
334 struct device_driver *drv = dev->driver;
335 struct scsi_device *sdev = to_scsi_device(dev);
338 err = scsi_device_quiesce(sdev);
342 if (drv && drv->suspend) {
343 err = drv->suspend(dev, state);
351 static int scsi_bus_resume(struct device * dev)
353 struct device_driver *drv = dev->driver;
354 struct scsi_device *sdev = to_scsi_device(dev);
357 if (drv && drv->resume)
358 err = drv->resume(dev);
360 scsi_device_resume(sdev);
365 struct bus_type scsi_bus_type = {
367 .match = scsi_bus_match,
368 .uevent = scsi_bus_uevent,
369 .suspend = scsi_bus_suspend,
370 .resume = scsi_bus_resume,
373 int scsi_sysfs_register(void)
377 error = bus_register(&scsi_bus_type);
379 error = class_register(&sdev_class);
381 bus_unregister(&scsi_bus_type);
387 void scsi_sysfs_unregister(void)
389 class_unregister(&sdev_class);
390 bus_unregister(&scsi_bus_type);
394 * sdev_show_function: macro to create an attr function that can be used to
395 * show a non-bit field.
397 #define sdev_show_function(field, format_string) \
399 sdev_show_##field (struct device *dev, struct device_attribute *attr, char *buf) \
401 struct scsi_device *sdev; \
402 sdev = to_scsi_device(dev); \
403 return snprintf (buf, 20, format_string, sdev->field); \
407 * sdev_rd_attr: macro to create a function and attribute variable for a
410 #define sdev_rd_attr(field, format_string) \
411 sdev_show_function(field, format_string) \
412 static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
416 * sdev_rd_attr: create a function and attribute variable for a
419 #define sdev_rw_attr(field, format_string) \
420 sdev_show_function(field, format_string) \
423 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
425 struct scsi_device *sdev; \
426 sdev = to_scsi_device(dev); \
427 snscanf (buf, 20, format_string, &sdev->field); \
430 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
432 /* Currently we don't export bit fields, but we might in future,
433 * so leave this code in */
436 * sdev_rd_attr: create a function and attribute variable for a
437 * read/write bit field.
439 #define sdev_rw_attr_bit(field) \
440 sdev_show_function(field, "%d\n") \
443 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
446 struct scsi_device *sdev; \
447 ret = scsi_sdev_check_buf_bit(buf); \
449 sdev = to_scsi_device(dev); \
455 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
458 * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
459 * else return -EINVAL.
461 static int scsi_sdev_check_buf_bit(const char *buf)
463 if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) {
466 else if (buf[0] == '0')
475 * Create the actual show/store functions and data structures.
477 sdev_rd_attr (device_blocked, "%d\n");
478 sdev_rd_attr (queue_depth, "%d\n");
479 sdev_rd_attr (type, "%d\n");
480 sdev_rd_attr (scsi_level, "%d\n");
481 sdev_rd_attr (vendor, "%.8s\n");
482 sdev_rd_attr (model, "%.16s\n");
483 sdev_rd_attr (rev, "%.4s\n");
486 sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
488 struct scsi_device *sdev;
489 sdev = to_scsi_device(dev);
490 return snprintf (buf, 20, "%d\n", sdev->timeout / HZ);
494 sdev_store_timeout (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
496 struct scsi_device *sdev;
498 sdev = to_scsi_device(dev);
499 sscanf (buf, "%d\n", &timeout);
500 sdev->timeout = timeout * HZ;
503 static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
506 store_rescan_field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
508 scsi_rescan_device(dev);
511 static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
513 static void sdev_store_delete_callback(struct device *dev)
515 scsi_remove_device(to_scsi_device(dev));
518 static ssize_t sdev_store_delete(struct device *dev, struct device_attribute *attr, const char *buf,
523 /* An attribute cannot be unregistered by one of its own methods,
524 * so we have to use this roundabout approach.
526 rc = device_schedule_callback(dev, sdev_store_delete_callback);
531 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
534 store_state_field(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
537 struct scsi_device *sdev = to_scsi_device(dev);
538 enum scsi_device_state state = 0;
540 for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
541 const int len = strlen(sdev_states[i].name);
542 if (strncmp(sdev_states[i].name, buf, len) == 0 &&
544 state = sdev_states[i].value;
551 if (scsi_device_set_state(sdev, state))
557 show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
559 struct scsi_device *sdev = to_scsi_device(dev);
560 const char *name = scsi_device_state_name(sdev->sdev_state);
565 return snprintf(buf, 20, "%s\n", name);
568 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
571 show_queue_type_field(struct device *dev, struct device_attribute *attr, char *buf)
573 struct scsi_device *sdev = to_scsi_device(dev);
574 const char *name = "none";
576 if (sdev->ordered_tags)
578 else if (sdev->simple_tags)
581 return snprintf(buf, 20, "%s\n", name);
584 static DEVICE_ATTR(queue_type, S_IRUGO, show_queue_type_field, NULL);
587 show_iostat_counterbits(struct device *dev, struct device_attribute *attr, char *buf)
589 return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8);
592 static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL);
594 #define show_sdev_iostat(field) \
596 show_iostat_##field(struct device *dev, struct device_attribute *attr, char *buf) \
598 struct scsi_device *sdev = to_scsi_device(dev); \
599 unsigned long long count = atomic_read(&sdev->field); \
600 return snprintf(buf, 20, "0x%llx\n", count); \
602 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
604 show_sdev_iostat(iorequest_cnt);
605 show_sdev_iostat(iodone_cnt);
606 show_sdev_iostat(ioerr_cnt);
609 sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
611 struct scsi_device *sdev;
612 sdev = to_scsi_device(dev);
613 return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
615 static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
617 /* Default template for device attributes. May NOT be modified */
618 static struct attribute *scsi_sdev_attrs[] = {
619 &dev_attr_device_blocked.attr,
621 &dev_attr_scsi_level.attr,
622 &dev_attr_vendor.attr,
623 &dev_attr_model.attr,
625 &dev_attr_rescan.attr,
626 &dev_attr_delete.attr,
627 &dev_attr_state.attr,
628 &dev_attr_timeout.attr,
629 &dev_attr_iocounterbits.attr,
630 &dev_attr_iorequest_cnt.attr,
631 &dev_attr_iodone_cnt.attr,
632 &dev_attr_ioerr_cnt.attr,
633 &dev_attr_modalias.attr,
637 static struct attribute_group scsi_sdev_attr_group = {
638 .attrs = scsi_sdev_attrs,
641 static struct attribute_group *scsi_sdev_attr_groups[] = {
642 &scsi_sdev_attr_group,
646 static ssize_t sdev_store_queue_depth_rw(struct device *dev, struct device_attribute *attr, const char *buf,
650 struct scsi_device *sdev = to_scsi_device(dev);
651 struct scsi_host_template *sht = sdev->host->hostt;
653 if (!sht->change_queue_depth)
656 depth = simple_strtoul(buf, NULL, 0);
661 retval = sht->change_queue_depth(sdev, depth);
668 static struct device_attribute sdev_attr_queue_depth_rw =
669 __ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
670 sdev_store_queue_depth_rw);
672 static ssize_t sdev_store_queue_type_rw(struct device *dev, struct device_attribute *attr, const char *buf,
675 struct scsi_device *sdev = to_scsi_device(dev);
676 struct scsi_host_template *sht = sdev->host->hostt;
677 int tag_type = 0, retval;
678 int prev_tag_type = scsi_get_tag_type(sdev);
680 if (!sdev->tagged_supported || !sht->change_queue_type)
683 if (strncmp(buf, "ordered", 7) == 0)
684 tag_type = MSG_ORDERED_TAG;
685 else if (strncmp(buf, "simple", 6) == 0)
686 tag_type = MSG_SIMPLE_TAG;
687 else if (strncmp(buf, "none", 4) != 0)
690 if (tag_type == prev_tag_type)
693 retval = sht->change_queue_type(sdev, tag_type);
700 static struct device_attribute sdev_attr_queue_type_rw =
701 __ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
702 sdev_store_queue_type_rw);
705 * scsi_sysfs_add_sdev - add scsi device to sysfs
706 * @sdev: scsi_device to add
709 * 0 on Success / non-zero on Failure
711 int scsi_sysfs_add_sdev(struct scsi_device *sdev)
714 struct request_queue *rq = sdev->request_queue;
716 if ((error = scsi_device_set_state(sdev, SDEV_RUNNING)) != 0)
719 error = device_add(&sdev->sdev_gendev);
721 put_device(sdev->sdev_gendev.parent);
722 printk(KERN_INFO "error 1\n");
725 error = class_device_add(&sdev->sdev_classdev);
727 printk(KERN_INFO "error 2\n");
731 /* take a reference for the sdev_classdev; this is
732 * released by the sdev_class .release */
733 get_device(&sdev->sdev_gendev);
735 /* create queue files, which may be writable, depending on the host */
736 if (sdev->host->hostt->change_queue_depth)
737 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_depth_rw);
739 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_depth);
741 __scsi_remove_device(sdev);
744 if (sdev->host->hostt->change_queue_type)
745 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_type_rw);
747 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_type);
749 __scsi_remove_device(sdev);
753 error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL);
756 sdev_printk(KERN_INFO, sdev,
757 "Failed to register bsg queue, errno=%d\n", error);
759 /* we're treating error on bsg register as non-fatal, so pretend
760 * nothing went wrong */
763 /* add additional host specific attributes */
764 if (sdev->host->hostt->sdev_attrs) {
765 for (i = 0; sdev->host->hostt->sdev_attrs[i]; i++) {
766 error = device_create_file(&sdev->sdev_gendev,
767 sdev->host->hostt->sdev_attrs[i]);
769 __scsi_remove_device(sdev);
775 transport_add_device(&sdev->sdev_gendev);
780 scsi_device_set_state(sdev, SDEV_CANCEL);
782 device_del(&sdev->sdev_gendev);
783 transport_destroy_device(&sdev->sdev_gendev);
784 put_device(&sdev->sdev_gendev);
789 void __scsi_remove_device(struct scsi_device *sdev)
791 struct device *dev = &sdev->sdev_gendev;
793 if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
796 bsg_unregister_queue(sdev->request_queue);
797 class_device_unregister(&sdev->sdev_classdev);
798 transport_remove_device(dev);
800 scsi_device_set_state(sdev, SDEV_DEL);
801 if (sdev->host->hostt->slave_destroy)
802 sdev->host->hostt->slave_destroy(sdev);
803 transport_destroy_device(dev);
808 * scsi_remove_device - unregister a device from the scsi bus
809 * @sdev: scsi_device to unregister
811 void scsi_remove_device(struct scsi_device *sdev)
813 struct Scsi_Host *shost = sdev->host;
815 mutex_lock(&shost->scan_mutex);
816 __scsi_remove_device(sdev);
817 mutex_unlock(&shost->scan_mutex);
819 EXPORT_SYMBOL(scsi_remove_device);
821 static void __scsi_remove_target(struct scsi_target *starget)
823 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
825 struct scsi_device *sdev;
827 spin_lock_irqsave(shost->host_lock, flags);
830 list_for_each_entry(sdev, &shost->__devices, siblings) {
831 if (sdev->channel != starget->channel ||
832 sdev->id != starget->id ||
833 sdev->sdev_state == SDEV_DEL)
835 spin_unlock_irqrestore(shost->host_lock, flags);
836 scsi_remove_device(sdev);
837 spin_lock_irqsave(shost->host_lock, flags);
840 spin_unlock_irqrestore(shost->host_lock, flags);
841 scsi_target_reap(starget);
844 static int __remove_child (struct device * dev, void * data)
846 if (scsi_is_target_device(dev))
847 __scsi_remove_target(to_scsi_target(dev));
852 * scsi_remove_target - try to remove a target and all its devices
853 * @dev: generic starget or parent of generic stargets to be removed
855 * Note: This is slightly racy. It is possible that if the user
856 * requests the addition of another device then the target won't be
859 void scsi_remove_target(struct device *dev)
863 if (scsi_is_target_device(dev)) {
864 __scsi_remove_target(to_scsi_target(dev));
868 rdev = get_device(dev);
869 device_for_each_child(dev, NULL, __remove_child);
872 EXPORT_SYMBOL(scsi_remove_target);
874 int scsi_register_driver(struct device_driver *drv)
876 drv->bus = &scsi_bus_type;
878 return driver_register(drv);
880 EXPORT_SYMBOL(scsi_register_driver);
882 int scsi_register_interface(struct class_interface *intf)
884 intf->class = &sdev_class;
886 return class_interface_register(intf);
888 EXPORT_SYMBOL(scsi_register_interface);
891 static struct class_device_attribute *class_attr_overridden(
892 struct class_device_attribute **attrs,
893 struct class_device_attribute *attr)
899 for (i = 0; attrs[i]; i++)
900 if (!strcmp(attrs[i]->attr.name, attr->attr.name))
905 static int class_attr_add(struct class_device *classdev,
906 struct class_device_attribute *attr)
908 struct class_device_attribute *base_attr;
911 * Spare the caller from having to copy things it's not interested in.
913 base_attr = class_attr_overridden(scsi_sysfs_shost_attrs, attr);
915 /* extend permissions */
916 attr->attr.mode |= base_attr->attr.mode;
918 /* override null show/store with default */
920 attr->show = base_attr->show;
922 attr->store = base_attr->store;
925 return class_device_create_file(classdev, attr);
929 * scsi_sysfs_add_host - add scsi host to subsystem
930 * @shost: scsi host struct to add to subsystem
931 * @dev: parent struct device pointer
933 int scsi_sysfs_add_host(struct Scsi_Host *shost)
937 if (shost->hostt->shost_attrs) {
938 for (i = 0; shost->hostt->shost_attrs[i]; i++) {
939 error = class_attr_add(&shost->shost_classdev,
940 shost->hostt->shost_attrs[i]);
946 for (i = 0; scsi_sysfs_shost_attrs[i]; i++) {
947 if (!class_attr_overridden(shost->hostt->shost_attrs,
948 scsi_sysfs_shost_attrs[i])) {
949 error = class_device_create_file(&shost->shost_classdev,
950 scsi_sysfs_shost_attrs[i]);
956 transport_register_device(&shost->shost_gendev);
960 static struct device_type scsi_dev_type = {
961 .name = "scsi_device",
962 .release = scsi_device_dev_release,
963 .groups = scsi_sdev_attr_groups,
966 void scsi_sysfs_device_initialize(struct scsi_device *sdev)
969 struct Scsi_Host *shost = sdev->host;
970 struct scsi_target *starget = sdev->sdev_target;
972 device_initialize(&sdev->sdev_gendev);
973 sdev->sdev_gendev.bus = &scsi_bus_type;
974 sdev->sdev_gendev.type = &scsi_dev_type;
975 sprintf(sdev->sdev_gendev.bus_id,"%d:%d:%d:%d",
976 sdev->host->host_no, sdev->channel, sdev->id,
979 class_device_initialize(&sdev->sdev_classdev);
980 sdev->sdev_classdev.dev = &sdev->sdev_gendev;
981 sdev->sdev_classdev.class = &sdev_class;
982 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
983 "%d:%d:%d:%d", sdev->host->host_no,
984 sdev->channel, sdev->id, sdev->lun);
985 sdev->scsi_level = starget->scsi_level;
986 transport_setup_device(&sdev->sdev_gendev);
987 spin_lock_irqsave(shost->host_lock, flags);
988 list_add_tail(&sdev->same_target_siblings, &starget->devices);
989 list_add_tail(&sdev->siblings, &shost->__devices);
990 spin_unlock_irqrestore(shost->host_lock, flags);
993 int scsi_is_sdev_device(const struct device *dev)
995 return dev->type == &scsi_dev_type;
997 EXPORT_SYMBOL(scsi_is_sdev_device);
999 /* A blank transport template that is used in drivers that don't
1000 * yet implement Transport Attributes */
1001 struct scsi_transport_template blank_transport_template = { { { {NULL, }, }, }, };