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);
213 if (shost->hostt->supported_mode == MODE_UNKNOWN)
214 return snprintf(buf, 20, "unknown\n");
216 return show_shost_mode(shost->hostt->supported_mode, buf);
219 static CLASS_DEVICE_ATTR(supported_mode, S_IRUGO | S_IWUSR, show_shost_supported_mode, NULL);
221 static ssize_t show_shost_active_mode(struct class_device *class_dev, char *buf)
223 struct Scsi_Host *shost = class_to_shost(class_dev);
225 if (shost->active_mode == MODE_UNKNOWN)
226 return snprintf(buf, 20, "unknown\n");
228 return show_shost_mode(shost->active_mode, buf);
231 static CLASS_DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL);
233 shost_rd_attr(unique_id, "%u\n");
234 shost_rd_attr(host_busy, "%hu\n");
235 shost_rd_attr(cmd_per_lun, "%hd\n");
236 shost_rd_attr(can_queue, "%hd\n");
237 shost_rd_attr(sg_tablesize, "%hu\n");
238 shost_rd_attr(unchecked_isa_dma, "%d\n");
239 shost_rd_attr2(proc_name, hostt->proc_name, "%s\n");
241 static struct class_device_attribute *scsi_sysfs_shost_attrs[] = {
242 &class_device_attr_unique_id,
243 &class_device_attr_host_busy,
244 &class_device_attr_cmd_per_lun,
245 &class_device_attr_can_queue,
246 &class_device_attr_sg_tablesize,
247 &class_device_attr_unchecked_isa_dma,
248 &class_device_attr_proc_name,
249 &class_device_attr_scan,
250 &class_device_attr_state,
251 &class_device_attr_supported_mode,
252 &class_device_attr_active_mode,
256 static void scsi_device_cls_release(struct class_device *class_dev)
258 struct scsi_device *sdev;
260 sdev = class_to_sdev(class_dev);
261 put_device(&sdev->sdev_gendev);
264 static void scsi_device_dev_release_usercontext(struct work_struct *work)
266 struct scsi_device *sdev;
267 struct device *parent;
268 struct scsi_target *starget;
271 sdev = container_of(work, struct scsi_device, ew.work);
273 parent = sdev->sdev_gendev.parent;
274 starget = to_scsi_target(parent);
276 spin_lock_irqsave(sdev->host->host_lock, flags);
278 list_del(&sdev->siblings);
279 list_del(&sdev->same_target_siblings);
280 list_del(&sdev->starved_entry);
281 spin_unlock_irqrestore(sdev->host->host_lock, flags);
283 if (sdev->request_queue) {
284 sdev->request_queue->queuedata = NULL;
285 /* user context needed to free queue */
286 scsi_free_queue(sdev->request_queue);
287 /* temporary expedient, try to catch use of queue lock
288 * after free of sdev */
289 sdev->request_queue = NULL;
292 scsi_target_reap(scsi_target(sdev));
294 kfree(sdev->inquiry);
301 static void scsi_device_dev_release(struct device *dev)
303 struct scsi_device *sdp = to_scsi_device(dev);
304 execute_in_process_context(scsi_device_dev_release_usercontext,
308 static struct class sdev_class = {
309 .name = "scsi_device",
310 .release = scsi_device_cls_release,
313 /* all probing is done in the individual ->probe routines */
314 static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
316 struct scsi_device *sdp = to_scsi_device(dev);
317 if (sdp->no_uld_attach)
319 return (sdp->inq_periph_qual == SCSI_INQ_PQ_CON)? 1: 0;
322 static int scsi_bus_uevent(struct device *dev, char **envp, int num_envp,
323 char *buffer, int buffer_size)
325 struct scsi_device *sdev = to_scsi_device(dev);
329 add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
330 "MODALIAS=" SCSI_DEVICE_MODALIAS_FMT, sdev->type);
335 static int scsi_bus_suspend(struct device * dev, pm_message_t state)
337 struct device_driver *drv = dev->driver;
338 struct scsi_device *sdev = to_scsi_device(dev);
341 err = scsi_device_quiesce(sdev);
345 if (drv && drv->suspend) {
346 err = drv->suspend(dev, state);
354 static int scsi_bus_resume(struct device * dev)
356 struct device_driver *drv = dev->driver;
357 struct scsi_device *sdev = to_scsi_device(dev);
360 if (drv && drv->resume)
361 err = drv->resume(dev);
363 scsi_device_resume(sdev);
368 struct bus_type scsi_bus_type = {
370 .match = scsi_bus_match,
371 .uevent = scsi_bus_uevent,
372 .suspend = scsi_bus_suspend,
373 .resume = scsi_bus_resume,
376 int scsi_sysfs_register(void)
380 error = bus_register(&scsi_bus_type);
382 error = class_register(&sdev_class);
384 bus_unregister(&scsi_bus_type);
390 void scsi_sysfs_unregister(void)
392 class_unregister(&sdev_class);
393 bus_unregister(&scsi_bus_type);
397 * sdev_show_function: macro to create an attr function that can be used to
398 * show a non-bit field.
400 #define sdev_show_function(field, format_string) \
402 sdev_show_##field (struct device *dev, struct device_attribute *attr, char *buf) \
404 struct scsi_device *sdev; \
405 sdev = to_scsi_device(dev); \
406 return snprintf (buf, 20, format_string, sdev->field); \
410 * sdev_rd_attr: macro to create a function and attribute variable for a
413 #define sdev_rd_attr(field, format_string) \
414 sdev_show_function(field, format_string) \
415 static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
419 * sdev_rd_attr: create a function and attribute variable for a
422 #define sdev_rw_attr(field, format_string) \
423 sdev_show_function(field, format_string) \
426 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
428 struct scsi_device *sdev; \
429 sdev = to_scsi_device(dev); \
430 snscanf (buf, 20, format_string, &sdev->field); \
433 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
435 /* Currently we don't export bit fields, but we might in future,
436 * so leave this code in */
439 * sdev_rd_attr: create a function and attribute variable for a
440 * read/write bit field.
442 #define sdev_rw_attr_bit(field) \
443 sdev_show_function(field, "%d\n") \
446 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
449 struct scsi_device *sdev; \
450 ret = scsi_sdev_check_buf_bit(buf); \
452 sdev = to_scsi_device(dev); \
458 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
461 * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
462 * else return -EINVAL.
464 static int scsi_sdev_check_buf_bit(const char *buf)
466 if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) {
469 else if (buf[0] == '0')
478 * Create the actual show/store functions and data structures.
480 sdev_rd_attr (device_blocked, "%d\n");
481 sdev_rd_attr (queue_depth, "%d\n");
482 sdev_rd_attr (type, "%d\n");
483 sdev_rd_attr (scsi_level, "%d\n");
484 sdev_rd_attr (vendor, "%.8s\n");
485 sdev_rd_attr (model, "%.16s\n");
486 sdev_rd_attr (rev, "%.4s\n");
489 sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
491 struct scsi_device *sdev;
492 sdev = to_scsi_device(dev);
493 return snprintf (buf, 20, "%d\n", sdev->timeout / HZ);
497 sdev_store_timeout (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
499 struct scsi_device *sdev;
501 sdev = to_scsi_device(dev);
502 sscanf (buf, "%d\n", &timeout);
503 sdev->timeout = timeout * HZ;
506 static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
509 store_rescan_field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
511 scsi_rescan_device(dev);
514 static DEVICE_ATTR(rescan, S_IWUSR, NULL, store_rescan_field);
516 static void sdev_store_delete_callback(struct device *dev)
518 scsi_remove_device(to_scsi_device(dev));
521 static ssize_t sdev_store_delete(struct device *dev, struct device_attribute *attr, const char *buf,
526 /* An attribute cannot be unregistered by one of its own methods,
527 * so we have to use this roundabout approach.
529 rc = device_schedule_callback(dev, sdev_store_delete_callback);
534 static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
537 store_state_field(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
540 struct scsi_device *sdev = to_scsi_device(dev);
541 enum scsi_device_state state = 0;
543 for (i = 0; i < ARRAY_SIZE(sdev_states); i++) {
544 const int len = strlen(sdev_states[i].name);
545 if (strncmp(sdev_states[i].name, buf, len) == 0 &&
547 state = sdev_states[i].value;
554 if (scsi_device_set_state(sdev, state))
560 show_state_field(struct device *dev, struct device_attribute *attr, char *buf)
562 struct scsi_device *sdev = to_scsi_device(dev);
563 const char *name = scsi_device_state_name(sdev->sdev_state);
568 return snprintf(buf, 20, "%s\n", name);
571 static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_state_field, store_state_field);
574 show_queue_type_field(struct device *dev, struct device_attribute *attr, char *buf)
576 struct scsi_device *sdev = to_scsi_device(dev);
577 const char *name = "none";
579 if (sdev->ordered_tags)
581 else if (sdev->simple_tags)
584 return snprintf(buf, 20, "%s\n", name);
587 static DEVICE_ATTR(queue_type, S_IRUGO, show_queue_type_field, NULL);
590 show_iostat_counterbits(struct device *dev, struct device_attribute *attr, char *buf)
592 return snprintf(buf, 20, "%d\n", (int)sizeof(atomic_t) * 8);
595 static DEVICE_ATTR(iocounterbits, S_IRUGO, show_iostat_counterbits, NULL);
597 #define show_sdev_iostat(field) \
599 show_iostat_##field(struct device *dev, struct device_attribute *attr, char *buf) \
601 struct scsi_device *sdev = to_scsi_device(dev); \
602 unsigned long long count = atomic_read(&sdev->field); \
603 return snprintf(buf, 20, "0x%llx\n", count); \
605 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
607 show_sdev_iostat(iorequest_cnt);
608 show_sdev_iostat(iodone_cnt);
609 show_sdev_iostat(ioerr_cnt);
612 sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
614 struct scsi_device *sdev;
615 sdev = to_scsi_device(dev);
616 return snprintf (buf, 20, SCSI_DEVICE_MODALIAS_FMT "\n", sdev->type);
618 static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
620 /* Default template for device attributes. May NOT be modified */
621 static struct attribute *scsi_sdev_attrs[] = {
622 &dev_attr_device_blocked.attr,
624 &dev_attr_scsi_level.attr,
625 &dev_attr_vendor.attr,
626 &dev_attr_model.attr,
628 &dev_attr_rescan.attr,
629 &dev_attr_delete.attr,
630 &dev_attr_state.attr,
631 &dev_attr_timeout.attr,
632 &dev_attr_iocounterbits.attr,
633 &dev_attr_iorequest_cnt.attr,
634 &dev_attr_iodone_cnt.attr,
635 &dev_attr_ioerr_cnt.attr,
636 &dev_attr_modalias.attr,
640 static struct attribute_group scsi_sdev_attr_group = {
641 .attrs = scsi_sdev_attrs,
644 static struct attribute_group *scsi_sdev_attr_groups[] = {
645 &scsi_sdev_attr_group,
649 static ssize_t sdev_store_queue_depth_rw(struct device *dev, struct device_attribute *attr, const char *buf,
653 struct scsi_device *sdev = to_scsi_device(dev);
654 struct scsi_host_template *sht = sdev->host->hostt;
656 if (!sht->change_queue_depth)
659 depth = simple_strtoul(buf, NULL, 0);
664 retval = sht->change_queue_depth(sdev, depth);
671 static struct device_attribute sdev_attr_queue_depth_rw =
672 __ATTR(queue_depth, S_IRUGO | S_IWUSR, sdev_show_queue_depth,
673 sdev_store_queue_depth_rw);
675 static ssize_t sdev_store_queue_type_rw(struct device *dev, struct device_attribute *attr, const char *buf,
678 struct scsi_device *sdev = to_scsi_device(dev);
679 struct scsi_host_template *sht = sdev->host->hostt;
680 int tag_type = 0, retval;
681 int prev_tag_type = scsi_get_tag_type(sdev);
683 if (!sdev->tagged_supported || !sht->change_queue_type)
686 if (strncmp(buf, "ordered", 7) == 0)
687 tag_type = MSG_ORDERED_TAG;
688 else if (strncmp(buf, "simple", 6) == 0)
689 tag_type = MSG_SIMPLE_TAG;
690 else if (strncmp(buf, "none", 4) != 0)
693 if (tag_type == prev_tag_type)
696 retval = sht->change_queue_type(sdev, tag_type);
703 static struct device_attribute sdev_attr_queue_type_rw =
704 __ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
705 sdev_store_queue_type_rw);
708 * scsi_sysfs_add_sdev - add scsi device to sysfs
709 * @sdev: scsi_device to add
712 * 0 on Success / non-zero on Failure
714 int scsi_sysfs_add_sdev(struct scsi_device *sdev)
717 struct request_queue *rq = sdev->request_queue;
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);
738 /* create queue files, which may be writable, depending on the host */
739 if (sdev->host->hostt->change_queue_depth)
740 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_depth_rw);
742 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_depth);
744 __scsi_remove_device(sdev);
747 if (sdev->host->hostt->change_queue_type)
748 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_type_rw);
750 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_type);
752 __scsi_remove_device(sdev);
756 error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL);
759 sdev_printk(KERN_INFO, sdev,
760 "Failed to register bsg queue, errno=%d\n", error);
762 /* we're treating error on bsg register as non-fatal, so pretend
763 * nothing went wrong */
766 /* add additional host specific attributes */
767 if (sdev->host->hostt->sdev_attrs) {
768 for (i = 0; sdev->host->hostt->sdev_attrs[i]; i++) {
769 error = device_create_file(&sdev->sdev_gendev,
770 sdev->host->hostt->sdev_attrs[i]);
772 __scsi_remove_device(sdev);
778 transport_add_device(&sdev->sdev_gendev);
783 scsi_device_set_state(sdev, SDEV_CANCEL);
785 device_del(&sdev->sdev_gendev);
786 transport_destroy_device(&sdev->sdev_gendev);
787 put_device(&sdev->sdev_gendev);
792 void __scsi_remove_device(struct scsi_device *sdev)
794 struct device *dev = &sdev->sdev_gendev;
796 if (scsi_device_set_state(sdev, SDEV_CANCEL) != 0)
799 bsg_unregister_queue(sdev->request_queue);
800 class_device_unregister(&sdev->sdev_classdev);
801 transport_remove_device(dev);
803 scsi_device_set_state(sdev, SDEV_DEL);
804 if (sdev->host->hostt->slave_destroy)
805 sdev->host->hostt->slave_destroy(sdev);
806 transport_destroy_device(dev);
811 * scsi_remove_device - unregister a device from the scsi bus
812 * @sdev: scsi_device to unregister
814 void scsi_remove_device(struct scsi_device *sdev)
816 struct Scsi_Host *shost = sdev->host;
818 mutex_lock(&shost->scan_mutex);
819 __scsi_remove_device(sdev);
820 mutex_unlock(&shost->scan_mutex);
822 EXPORT_SYMBOL(scsi_remove_device);
824 static void __scsi_remove_target(struct scsi_target *starget)
826 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
828 struct scsi_device *sdev;
830 spin_lock_irqsave(shost->host_lock, flags);
833 list_for_each_entry(sdev, &shost->__devices, siblings) {
834 if (sdev->channel != starget->channel ||
835 sdev->id != starget->id ||
836 sdev->sdev_state == SDEV_DEL)
838 spin_unlock_irqrestore(shost->host_lock, flags);
839 scsi_remove_device(sdev);
840 spin_lock_irqsave(shost->host_lock, flags);
843 spin_unlock_irqrestore(shost->host_lock, flags);
844 scsi_target_reap(starget);
847 static int __remove_child (struct device * dev, void * data)
849 if (scsi_is_target_device(dev))
850 __scsi_remove_target(to_scsi_target(dev));
855 * scsi_remove_target - try to remove a target and all its devices
856 * @dev: generic starget or parent of generic stargets to be removed
858 * Note: This is slightly racy. It is possible that if the user
859 * requests the addition of another device then the target won't be
862 void scsi_remove_target(struct device *dev)
866 if (scsi_is_target_device(dev)) {
867 __scsi_remove_target(to_scsi_target(dev));
871 rdev = get_device(dev);
872 device_for_each_child(dev, NULL, __remove_child);
875 EXPORT_SYMBOL(scsi_remove_target);
877 int scsi_register_driver(struct device_driver *drv)
879 drv->bus = &scsi_bus_type;
881 return driver_register(drv);
883 EXPORT_SYMBOL(scsi_register_driver);
885 int scsi_register_interface(struct class_interface *intf)
887 intf->class = &sdev_class;
889 return class_interface_register(intf);
891 EXPORT_SYMBOL(scsi_register_interface);
894 static struct class_device_attribute *class_attr_overridden(
895 struct class_device_attribute **attrs,
896 struct class_device_attribute *attr)
902 for (i = 0; attrs[i]; i++)
903 if (!strcmp(attrs[i]->attr.name, attr->attr.name))
908 static int class_attr_add(struct class_device *classdev,
909 struct class_device_attribute *attr)
911 struct class_device_attribute *base_attr;
914 * Spare the caller from having to copy things it's not interested in.
916 base_attr = class_attr_overridden(scsi_sysfs_shost_attrs, attr);
918 /* extend permissions */
919 attr->attr.mode |= base_attr->attr.mode;
921 /* override null show/store with default */
923 attr->show = base_attr->show;
925 attr->store = base_attr->store;
928 return class_device_create_file(classdev, attr);
932 * scsi_sysfs_add_host - add scsi host to subsystem
933 * @shost: scsi host struct to add to subsystem
934 * @dev: parent struct device pointer
936 int scsi_sysfs_add_host(struct Scsi_Host *shost)
940 if (shost->hostt->shost_attrs) {
941 for (i = 0; shost->hostt->shost_attrs[i]; i++) {
942 error = class_attr_add(&shost->shost_classdev,
943 shost->hostt->shost_attrs[i]);
949 for (i = 0; scsi_sysfs_shost_attrs[i]; i++) {
950 if (!class_attr_overridden(shost->hostt->shost_attrs,
951 scsi_sysfs_shost_attrs[i])) {
952 error = class_device_create_file(&shost->shost_classdev,
953 scsi_sysfs_shost_attrs[i]);
959 transport_register_device(&shost->shost_gendev);
963 static struct device_type scsi_dev_type = {
964 .name = "scsi_device",
965 .release = scsi_device_dev_release,
966 .groups = scsi_sdev_attr_groups,
969 void scsi_sysfs_device_initialize(struct scsi_device *sdev)
972 struct Scsi_Host *shost = sdev->host;
973 struct scsi_target *starget = sdev->sdev_target;
975 device_initialize(&sdev->sdev_gendev);
976 sdev->sdev_gendev.bus = &scsi_bus_type;
977 sdev->sdev_gendev.type = &scsi_dev_type;
978 sprintf(sdev->sdev_gendev.bus_id,"%d:%d:%d:%d",
979 sdev->host->host_no, sdev->channel, sdev->id,
982 class_device_initialize(&sdev->sdev_classdev);
983 sdev->sdev_classdev.dev = &sdev->sdev_gendev;
984 sdev->sdev_classdev.class = &sdev_class;
985 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
986 "%d:%d:%d:%d", sdev->host->host_no,
987 sdev->channel, sdev->id, sdev->lun);
988 sdev->scsi_level = starget->scsi_level;
989 transport_setup_device(&sdev->sdev_gendev);
990 spin_lock_irqsave(shost->host_lock, flags);
991 list_add_tail(&sdev->same_target_siblings, &starget->devices);
992 list_add_tail(&sdev->siblings, &shost->__devices);
993 spin_unlock_irqrestore(shost->host_lock, flags);
996 int scsi_is_sdev_device(const struct device *dev)
998 return dev->release == scsi_device_dev_release;
1000 EXPORT_SYMBOL(scsi_is_sdev_device);
1002 /* A blank transport template that is used in drivers that don't
1003 * yet implement Transport Attributes */
1004 struct scsi_transport_template blank_transport_template = { { { {NULL, }, }, }, };