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>
20 #include "scsi_priv.h"
21 #include "scsi_logging.h"
24 enum scsi_device_state value
;
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_BLOCK
, "blocked" },
36 const char *scsi_device_state_name(enum scsi_device_state state
)
41 for (i
= 0; i
< ARRAY_SIZE(sdev_states
); i
++) {
42 if (sdev_states
[i
].value
== state
) {
43 name
= sdev_states
[i
].name
;
51 enum scsi_host_state value
;
54 { SHOST_CREATED
, "created" },
55 { SHOST_RUNNING
, "running" },
56 { SHOST_CANCEL
, "cancel" },
57 { SHOST_DEL
, "deleted" },
58 { SHOST_RECOVERY
, "recovery" },
59 { SHOST_CANCEL_RECOVERY
, "cancel/recovery" },
60 { SHOST_DEL_RECOVERY
, "deleted/recovery", },
62 const char *scsi_host_state_name(enum scsi_host_state state
)
67 for (i
= 0; i
< ARRAY_SIZE(shost_states
); i
++) {
68 if (shost_states
[i
].value
== state
) {
69 name
= shost_states
[i
].name
;
76 static int check_set(unsigned int *val
, char *src
)
80 if (strncmp(src
, "-", 20) == 0) {
81 *val
= SCAN_WILD_CARD
;
84 * Doesn't check for int overflow
86 *val
= simple_strtoul(src
, &last
, 0);
93 static int scsi_scan(struct Scsi_Host
*shost
, const char *str
)
95 char s1
[15], s2
[15], s3
[15], junk
;
96 unsigned int channel
, id
, lun
;
99 res
= sscanf(str
, "%10s %10s %10s %c", s1
, s2
, s3
, &junk
);
102 if (check_set(&channel
, s1
))
104 if (check_set(&id
, s2
))
106 if (check_set(&lun
, s3
))
108 if (shost
->transportt
->user_scan
)
109 res
= shost
->transportt
->user_scan(shost
, channel
, id
, lun
);
111 res
= scsi_scan_host_selected(shost
, channel
, id
, lun
, 1);
116 * shost_show_function: macro to create an attr function that can be used to
117 * show a non-bit field.
119 #define shost_show_function(name, field, format_string) \
121 show_##name (struct class_device *class_dev, char *buf) \
123 struct Scsi_Host *shost = class_to_shost(class_dev); \
124 return snprintf (buf, 20, format_string, shost->field); \
128 * shost_rd_attr: macro to create a function and attribute variable for a
131 #define shost_rd_attr2(name, field, format_string) \
132 shost_show_function(name, field, format_string) \
133 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
135 #define shost_rd_attr(field, format_string) \
136 shost_rd_attr2(field, field, format_string)
139 * Create the actual show/store functions and data structures.
142 static ssize_t
store_scan(struct class_device
*class_dev
, const char *buf
,
145 struct Scsi_Host
*shost
= class_to_shost(class_dev
);
148 res
= scsi_scan(shost
, buf
);
153 static CLASS_DEVICE_ATTR(scan
, S_IWUSR
, NULL
, store_scan
);
156 store_shost_state(struct class_device
*class_dev
, const char *buf
, size_t count
)
159 struct Scsi_Host
*shost
= class_to_shost(class_dev
);
160 enum scsi_host_state state
= 0;
162 for (i
= 0; i
< ARRAY_SIZE(shost_states
); i
++) {
163 const int len
= strlen(shost_states
[i
].name
);
164 if (strncmp(shost_states
[i
].name
, buf
, len
) == 0 &&
166 state
= shost_states
[i
].value
;
173 if (scsi_host_set_state(shost
, state
))
179 show_shost_state(struct class_device
*class_dev
, char *buf
)
181 struct Scsi_Host
*shost
= class_to_shost(class_dev
);
182 const char *name
= scsi_host_state_name(shost
->shost_state
);
187 return snprintf(buf
, 20, "%s\n", name
);
190 static CLASS_DEVICE_ATTR(state
, S_IRUGO
| S_IWUSR
, show_shost_state
, store_shost_state
);
192 shost_rd_attr(unique_id
, "%u\n");
193 shost_rd_attr(host_busy
, "%hu\n");
194 shost_rd_attr(cmd_per_lun
, "%hd\n");
195 shost_rd_attr(can_queue
, "%hd\n");
196 shost_rd_attr(sg_tablesize
, "%hu\n");
197 shost_rd_attr(unchecked_isa_dma
, "%d\n");
198 shost_rd_attr2(proc_name
, hostt
->proc_name
, "%s\n");
200 static struct class_device_attribute
*scsi_sysfs_shost_attrs
[] = {
201 &class_device_attr_unique_id
,
202 &class_device_attr_host_busy
,
203 &class_device_attr_cmd_per_lun
,
204 &class_device_attr_can_queue
,
205 &class_device_attr_sg_tablesize
,
206 &class_device_attr_unchecked_isa_dma
,
207 &class_device_attr_proc_name
,
208 &class_device_attr_scan
,
209 &class_device_attr_state
,
213 static void scsi_device_cls_release(struct class_device
*class_dev
)
215 struct scsi_device
*sdev
;
217 sdev
= class_to_sdev(class_dev
);
218 put_device(&sdev
->sdev_gendev
);
221 static void scsi_device_dev_release_usercontext(struct work_struct
*work
)
223 struct scsi_device
*sdev
;
224 struct device
*parent
;
225 struct scsi_target
*starget
;
228 sdev
= container_of(work
, struct scsi_device
, ew
.work
);
230 parent
= sdev
->sdev_gendev
.parent
;
231 starget
= to_scsi_target(parent
);
233 spin_lock_irqsave(sdev
->host
->host_lock
, flags
);
235 list_del(&sdev
->siblings
);
236 list_del(&sdev
->same_target_siblings
);
237 list_del(&sdev
->starved_entry
);
238 spin_unlock_irqrestore(sdev
->host
->host_lock
, flags
);
240 if (sdev
->request_queue
) {
241 sdev
->request_queue
->queuedata
= NULL
;
242 /* user context needed to free queue */
243 scsi_free_queue(sdev
->request_queue
);
244 /* temporary expedient, try to catch use of queue lock
245 * after free of sdev */
246 sdev
->request_queue
= NULL
;
249 scsi_target_reap(scsi_target(sdev
));
251 kfree(sdev
->inquiry
);
258 static void scsi_device_dev_release(struct device
*dev
)
260 struct scsi_device
*sdp
= to_scsi_device(dev
);
261 execute_in_process_context(scsi_device_dev_release_usercontext
,
265 static struct class sdev_class
= {
266 .name
= "scsi_device",
267 .release
= scsi_device_cls_release
,
270 /* all probing is done in the individual ->probe routines */
271 static int scsi_bus_match(struct device
*dev
, struct device_driver
*gendrv
)
273 struct scsi_device
*sdp
= to_scsi_device(dev
);
274 if (sdp
->no_uld_attach
)
276 return (sdp
->inq_periph_qual
== SCSI_INQ_PQ_CON
)? 1: 0;
279 static int scsi_bus_suspend(struct device
* dev
, pm_message_t state
)
281 struct scsi_device
*sdev
= to_scsi_device(dev
);
282 struct scsi_host_template
*sht
= sdev
->host
->hostt
;
285 err
= scsi_device_quiesce(sdev
);
290 err
= sht
->suspend(sdev
, state
);
295 static int scsi_bus_resume(struct device
* dev
)
297 struct scsi_device
*sdev
= to_scsi_device(dev
);
298 struct scsi_host_template
*sht
= sdev
->host
->hostt
;
302 err
= sht
->resume(sdev
);
304 scsi_device_resume(sdev
);
308 struct bus_type scsi_bus_type
= {
310 .match
= scsi_bus_match
,
311 .suspend
= scsi_bus_suspend
,
312 .resume
= scsi_bus_resume
,
315 int scsi_sysfs_register(void)
319 error
= bus_register(&scsi_bus_type
);
321 error
= class_register(&sdev_class
);
323 bus_unregister(&scsi_bus_type
);
329 void scsi_sysfs_unregister(void)
331 class_unregister(&sdev_class
);
332 bus_unregister(&scsi_bus_type
);
336 * sdev_show_function: macro to create an attr function that can be used to
337 * show a non-bit field.
339 #define sdev_show_function(field, format_string) \
341 sdev_show_##field (struct device *dev, struct device_attribute *attr, char *buf) \
343 struct scsi_device *sdev; \
344 sdev = to_scsi_device(dev); \
345 return snprintf (buf, 20, format_string, sdev->field); \
349 * sdev_rd_attr: macro to create a function and attribute variable for a
352 #define sdev_rd_attr(field, format_string) \
353 sdev_show_function(field, format_string) \
354 static DEVICE_ATTR(field, S_IRUGO, sdev_show_##field, NULL);
358 * sdev_rd_attr: create a function and attribute variable for a
361 #define sdev_rw_attr(field, format_string) \
362 sdev_show_function(field, format_string) \
365 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
367 struct scsi_device *sdev; \
368 sdev = to_scsi_device(dev); \
369 snscanf (buf, 20, format_string, &sdev->field); \
372 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
374 /* Currently we don't export bit fields, but we might in future,
375 * so leave this code in */
378 * sdev_rd_attr: create a function and attribute variable for a
379 * read/write bit field.
381 #define sdev_rw_attr_bit(field) \
382 sdev_show_function(field, "%d\n") \
385 sdev_store_##field (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
388 struct scsi_device *sdev; \
389 ret = scsi_sdev_check_buf_bit(buf); \
391 sdev = to_scsi_device(dev); \
397 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, sdev_store_##field);
400 * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
401 * else return -EINVAL.
403 static int scsi_sdev_check_buf_bit(const char *buf
)
405 if ((buf
[1] == '\0') || ((buf
[1] == '\n') && (buf
[2] == '\0'))) {
408 else if (buf
[0] == '0')
417 * Create the actual show/store functions and data structures.
419 sdev_rd_attr (device_blocked
, "%d\n");
420 sdev_rd_attr (queue_depth
, "%d\n");
421 sdev_rd_attr (type
, "%d\n");
422 sdev_rd_attr (scsi_level
, "%d\n");
423 sdev_rd_attr (vendor
, "%.8s\n");
424 sdev_rd_attr (model
, "%.16s\n");
425 sdev_rd_attr (rev
, "%.4s\n");
428 sdev_show_timeout (struct device
*dev
, struct device_attribute
*attr
, char *buf
)
430 struct scsi_device
*sdev
;
431 sdev
= to_scsi_device(dev
);
432 return snprintf (buf
, 20, "%d\n", sdev
->timeout
/ HZ
);
436 sdev_store_timeout (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
438 struct scsi_device
*sdev
;
440 sdev
= to_scsi_device(dev
);
441 sscanf (buf
, "%d\n", &timeout
);
442 sdev
->timeout
= timeout
* HZ
;
445 static DEVICE_ATTR(timeout
, S_IRUGO
| S_IWUSR
, sdev_show_timeout
, sdev_store_timeout
);
448 store_rescan_field (struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
450 scsi_rescan_device(dev
);
453 static DEVICE_ATTR(rescan
, S_IWUSR
, NULL
, store_rescan_field
);
455 static ssize_t
sdev_store_delete(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
458 scsi_remove_device(to_scsi_device(dev
));
461 static DEVICE_ATTR(delete, S_IWUSR
, NULL
, sdev_store_delete
);
464 store_state_field(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
467 struct scsi_device
*sdev
= to_scsi_device(dev
);
468 enum scsi_device_state state
= 0;
470 for (i
= 0; i
< ARRAY_SIZE(sdev_states
); i
++) {
471 const int len
= strlen(sdev_states
[i
].name
);
472 if (strncmp(sdev_states
[i
].name
, buf
, len
) == 0 &&
474 state
= sdev_states
[i
].value
;
481 if (scsi_device_set_state(sdev
, state
))
487 show_state_field(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
489 struct scsi_device
*sdev
= to_scsi_device(dev
);
490 const char *name
= scsi_device_state_name(sdev
->sdev_state
);
495 return snprintf(buf
, 20, "%s\n", name
);
498 static DEVICE_ATTR(state
, S_IRUGO
| S_IWUSR
, show_state_field
, store_state_field
);
501 show_queue_type_field(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
503 struct scsi_device
*sdev
= to_scsi_device(dev
);
504 const char *name
= "none";
506 if (sdev
->ordered_tags
)
508 else if (sdev
->simple_tags
)
511 return snprintf(buf
, 20, "%s\n", name
);
514 static DEVICE_ATTR(queue_type
, S_IRUGO
, show_queue_type_field
, NULL
);
517 show_iostat_counterbits(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
519 return snprintf(buf
, 20, "%d\n", (int)sizeof(atomic_t
) * 8);
522 static DEVICE_ATTR(iocounterbits
, S_IRUGO
, show_iostat_counterbits
, NULL
);
524 #define show_sdev_iostat(field) \
526 show_iostat_##field(struct device *dev, struct device_attribute *attr, char *buf) \
528 struct scsi_device *sdev = to_scsi_device(dev); \
529 unsigned long long count = atomic_read(&sdev->field); \
530 return snprintf(buf, 20, "0x%llx\n", count); \
532 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
534 show_sdev_iostat(iorequest_cnt
);
535 show_sdev_iostat(iodone_cnt
);
536 show_sdev_iostat(ioerr_cnt
);
539 /* Default template for device attributes. May NOT be modified */
540 static struct device_attribute
*scsi_sysfs_sdev_attrs
[] = {
541 &dev_attr_device_blocked
,
542 &dev_attr_queue_depth
,
543 &dev_attr_queue_type
,
545 &dev_attr_scsi_level
,
553 &dev_attr_iocounterbits
,
554 &dev_attr_iorequest_cnt
,
555 &dev_attr_iodone_cnt
,
560 static ssize_t
sdev_store_queue_depth_rw(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
564 struct scsi_device
*sdev
= to_scsi_device(dev
);
565 struct scsi_host_template
*sht
= sdev
->host
->hostt
;
567 if (!sht
->change_queue_depth
)
570 depth
= simple_strtoul(buf
, NULL
, 0);
575 retval
= sht
->change_queue_depth(sdev
, depth
);
582 static struct device_attribute sdev_attr_queue_depth_rw
=
583 __ATTR(queue_depth
, S_IRUGO
| S_IWUSR
, sdev_show_queue_depth
,
584 sdev_store_queue_depth_rw
);
586 static ssize_t
sdev_store_queue_type_rw(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
589 struct scsi_device
*sdev
= to_scsi_device(dev
);
590 struct scsi_host_template
*sht
= sdev
->host
->hostt
;
591 int tag_type
= 0, retval
;
592 int prev_tag_type
= scsi_get_tag_type(sdev
);
594 if (!sdev
->tagged_supported
|| !sht
->change_queue_type
)
597 if (strncmp(buf
, "ordered", 7) == 0)
598 tag_type
= MSG_ORDERED_TAG
;
599 else if (strncmp(buf
, "simple", 6) == 0)
600 tag_type
= MSG_SIMPLE_TAG
;
601 else if (strncmp(buf
, "none", 4) != 0)
604 if (tag_type
== prev_tag_type
)
607 retval
= sht
->change_queue_type(sdev
, tag_type
);
614 static struct device_attribute sdev_attr_queue_type_rw
=
615 __ATTR(queue_type
, S_IRUGO
| S_IWUSR
, show_queue_type_field
,
616 sdev_store_queue_type_rw
);
618 static struct device_attribute
*attr_changed_internally(
619 struct Scsi_Host
*shost
,
620 struct device_attribute
* attr
)
622 if (!strcmp("queue_depth", attr
->attr
.name
)
623 && shost
->hostt
->change_queue_depth
)
624 return &sdev_attr_queue_depth_rw
;
625 else if (!strcmp("queue_type", attr
->attr
.name
)
626 && shost
->hostt
->change_queue_type
)
627 return &sdev_attr_queue_type_rw
;
632 static struct device_attribute
*attr_overridden(
633 struct device_attribute
**attrs
,
634 struct device_attribute
*attr
)
640 for (i
= 0; attrs
[i
]; i
++)
641 if (!strcmp(attrs
[i
]->attr
.name
, attr
->attr
.name
))
646 static int attr_add(struct device
*dev
, struct device_attribute
*attr
)
648 struct device_attribute
*base_attr
;
651 * Spare the caller from having to copy things it's not interested in.
653 base_attr
= attr_overridden(scsi_sysfs_sdev_attrs
, attr
);
655 /* extend permissions */
656 attr
->attr
.mode
|= base_attr
->attr
.mode
;
658 /* override null show/store with default */
660 attr
->show
= base_attr
->show
;
662 attr
->store
= base_attr
->store
;
665 return device_create_file(dev
, attr
);
669 * scsi_sysfs_add_sdev - add scsi device to sysfs
670 * @sdev: scsi_device to add
673 * 0 on Success / non-zero on Failure
675 int scsi_sysfs_add_sdev(struct scsi_device
*sdev
)
679 if ((error
= scsi_device_set_state(sdev
, SDEV_RUNNING
)) != 0)
682 error
= device_add(&sdev
->sdev_gendev
);
684 put_device(sdev
->sdev_gendev
.parent
);
685 printk(KERN_INFO
"error 1\n");
688 error
= class_device_add(&sdev
->sdev_classdev
);
690 printk(KERN_INFO
"error 2\n");
694 /* take a reference for the sdev_classdev; this is
695 * released by the sdev_class .release */
696 get_device(&sdev
->sdev_gendev
);
697 if (sdev
->host
->hostt
->sdev_attrs
) {
698 for (i
= 0; sdev
->host
->hostt
->sdev_attrs
[i
]; i
++) {
699 error
= attr_add(&sdev
->sdev_gendev
,
700 sdev
->host
->hostt
->sdev_attrs
[i
]);
702 __scsi_remove_device(sdev
);
708 for (i
= 0; scsi_sysfs_sdev_attrs
[i
]; i
++) {
709 if (!attr_overridden(sdev
->host
->hostt
->sdev_attrs
,
710 scsi_sysfs_sdev_attrs
[i
])) {
711 struct device_attribute
* attr
=
712 attr_changed_internally(sdev
->host
,
713 scsi_sysfs_sdev_attrs
[i
]);
714 error
= device_create_file(&sdev
->sdev_gendev
, attr
);
716 __scsi_remove_device(sdev
);
722 transport_add_device(&sdev
->sdev_gendev
);
727 scsi_device_set_state(sdev
, SDEV_CANCEL
);
729 device_del(&sdev
->sdev_gendev
);
730 transport_destroy_device(&sdev
->sdev_gendev
);
731 put_device(&sdev
->sdev_gendev
);
736 void __scsi_remove_device(struct scsi_device
*sdev
)
738 struct device
*dev
= &sdev
->sdev_gendev
;
740 if (scsi_device_set_state(sdev
, SDEV_CANCEL
) != 0)
743 class_device_unregister(&sdev
->sdev_classdev
);
744 transport_remove_device(dev
);
746 scsi_device_set_state(sdev
, SDEV_DEL
);
747 if (sdev
->host
->hostt
->slave_destroy
)
748 sdev
->host
->hostt
->slave_destroy(sdev
);
749 transport_destroy_device(dev
);
754 * scsi_remove_device - unregister a device from the scsi bus
755 * @sdev: scsi_device to unregister
757 void scsi_remove_device(struct scsi_device
*sdev
)
759 struct Scsi_Host
*shost
= sdev
->host
;
761 mutex_lock(&shost
->scan_mutex
);
762 __scsi_remove_device(sdev
);
763 mutex_unlock(&shost
->scan_mutex
);
765 EXPORT_SYMBOL(scsi_remove_device
);
767 void __scsi_remove_target(struct scsi_target
*starget
)
769 struct Scsi_Host
*shost
= dev_to_shost(starget
->dev
.parent
);
771 struct scsi_device
*sdev
;
773 spin_lock_irqsave(shost
->host_lock
, flags
);
776 list_for_each_entry(sdev
, &shost
->__devices
, siblings
) {
777 if (sdev
->channel
!= starget
->channel
||
778 sdev
->id
!= starget
->id
||
779 sdev
->sdev_state
== SDEV_DEL
)
781 spin_unlock_irqrestore(shost
->host_lock
, flags
);
782 scsi_remove_device(sdev
);
783 spin_lock_irqsave(shost
->host_lock
, flags
);
786 spin_unlock_irqrestore(shost
->host_lock
, flags
);
787 scsi_target_reap(starget
);
790 static int __remove_child (struct device
* dev
, void * data
)
792 if (scsi_is_target_device(dev
))
793 __scsi_remove_target(to_scsi_target(dev
));
798 * scsi_remove_target - try to remove a target and all its devices
799 * @dev: generic starget or parent of generic stargets to be removed
801 * Note: This is slightly racy. It is possible that if the user
802 * requests the addition of another device then the target won't be
805 void scsi_remove_target(struct device
*dev
)
809 if (scsi_is_target_device(dev
)) {
810 __scsi_remove_target(to_scsi_target(dev
));
814 rdev
= get_device(dev
);
815 device_for_each_child(dev
, NULL
, __remove_child
);
818 EXPORT_SYMBOL(scsi_remove_target
);
820 int scsi_register_driver(struct device_driver
*drv
)
822 drv
->bus
= &scsi_bus_type
;
824 return driver_register(drv
);
826 EXPORT_SYMBOL(scsi_register_driver
);
828 int scsi_register_interface(struct class_interface
*intf
)
830 intf
->class = &sdev_class
;
832 return class_interface_register(intf
);
834 EXPORT_SYMBOL(scsi_register_interface
);
837 static struct class_device_attribute
*class_attr_overridden(
838 struct class_device_attribute
**attrs
,
839 struct class_device_attribute
*attr
)
845 for (i
= 0; attrs
[i
]; i
++)
846 if (!strcmp(attrs
[i
]->attr
.name
, attr
->attr
.name
))
851 static int class_attr_add(struct class_device
*classdev
,
852 struct class_device_attribute
*attr
)
854 struct class_device_attribute
*base_attr
;
857 * Spare the caller from having to copy things it's not interested in.
859 base_attr
= class_attr_overridden(scsi_sysfs_shost_attrs
, attr
);
861 /* extend permissions */
862 attr
->attr
.mode
|= base_attr
->attr
.mode
;
864 /* override null show/store with default */
866 attr
->show
= base_attr
->show
;
868 attr
->store
= base_attr
->store
;
871 return class_device_create_file(classdev
, attr
);
875 * scsi_sysfs_add_host - add scsi host to subsystem
876 * @shost: scsi host struct to add to subsystem
877 * @dev: parent struct device pointer
879 int scsi_sysfs_add_host(struct Scsi_Host
*shost
)
883 if (shost
->hostt
->shost_attrs
) {
884 for (i
= 0; shost
->hostt
->shost_attrs
[i
]; i
++) {
885 error
= class_attr_add(&shost
->shost_classdev
,
886 shost
->hostt
->shost_attrs
[i
]);
892 for (i
= 0; scsi_sysfs_shost_attrs
[i
]; i
++) {
893 if (!class_attr_overridden(shost
->hostt
->shost_attrs
,
894 scsi_sysfs_shost_attrs
[i
])) {
895 error
= class_device_create_file(&shost
->shost_classdev
,
896 scsi_sysfs_shost_attrs
[i
]);
902 transport_register_device(&shost
->shost_gendev
);
906 void scsi_sysfs_device_initialize(struct scsi_device
*sdev
)
909 struct Scsi_Host
*shost
= sdev
->host
;
910 struct scsi_target
*starget
= sdev
->sdev_target
;
912 device_initialize(&sdev
->sdev_gendev
);
913 sdev
->sdev_gendev
.bus
= &scsi_bus_type
;
914 sdev
->sdev_gendev
.release
= scsi_device_dev_release
;
915 sprintf(sdev
->sdev_gendev
.bus_id
,"%d:%d:%d:%d",
916 sdev
->host
->host_no
, sdev
->channel
, sdev
->id
,
919 class_device_initialize(&sdev
->sdev_classdev
);
920 sdev
->sdev_classdev
.dev
= &sdev
->sdev_gendev
;
921 sdev
->sdev_classdev
.class = &sdev_class
;
922 snprintf(sdev
->sdev_classdev
.class_id
, BUS_ID_SIZE
,
923 "%d:%d:%d:%d", sdev
->host
->host_no
,
924 sdev
->channel
, sdev
->id
, sdev
->lun
);
925 sdev
->scsi_level
= SCSI_2
;
926 transport_setup_device(&sdev
->sdev_gendev
);
927 spin_lock_irqsave(shost
->host_lock
, flags
);
928 list_add_tail(&sdev
->same_target_siblings
, &starget
->devices
);
929 list_add_tail(&sdev
->siblings
, &shost
->__devices
);
930 spin_unlock_irqrestore(shost
->host_lock
, flags
);
933 int scsi_is_sdev_device(const struct device
*dev
)
935 return dev
->release
== scsi_device_dev_release
;
937 EXPORT_SYMBOL(scsi_is_sdev_device
);
939 /* A blank transport template that is used in drivers that don't
940 * yet implement Transport Attributes */
941 struct scsi_transport_template blank_transport_template
= { { { {NULL
, }, }, }, };