1 #ifndef _SCSI_SCSI_DEVICE_H
2 #define _SCSI_SCSI_DEVICE_H
4 #include <linux/device.h>
5 #include <linux/list.h>
6 #include <linux/spinlock.h>
7 #include <asm/atomic.h>
11 struct scsi_mode_data;
15 * sdev state: If you alter this, you also need to alter scsi_sysfs.c
16 * (for the ascii descriptions) and the state model enforcer:
17 * scsi_lib:scsi_device_set_state().
19 enum scsi_device_state {
20 SDEV_CREATED = 1, /* device created but not added to sysfs
21 * Only internal commands allowed (for inq) */
22 SDEV_RUNNING, /* device properly configured
23 * All commands allowed */
24 SDEV_CANCEL, /* beginning to delete device
25 * Only error handler commands allowed */
26 SDEV_DEL, /* device deleted
27 * no commands allowed */
28 SDEV_QUIESCE, /* Device quiescent. No block commands
29 * will be accepted, only specials (which
30 * originate in the mid-layer) */
31 SDEV_OFFLINE, /* Device offlined (by error handling or
36 struct Scsi_Host *host;
37 struct request_queue *request_queue;
39 /* the next two are protected by the host->host_lock */
40 struct list_head siblings; /* list of all devices on this host */
41 struct list_head same_target_siblings; /* just the devices sharing same target id */
43 volatile unsigned short device_busy; /* commands actually active on low-level */
44 spinlock_t sdev_lock; /* also the request queue_lock */
46 struct list_head cmd_list; /* queue of in use SCSI Command structures */
47 struct list_head starved_entry;
48 struct scsi_cmnd *current_cmnd; /* currently active command */
49 unsigned short queue_depth; /* How deep of a queue we want */
50 unsigned short last_queue_full_depth; /* These two are used by */
51 unsigned short last_queue_full_count; /* scsi_track_queue_full() */
52 unsigned long last_queue_full_time;/* don't let QUEUE_FULLs on the same
53 jiffie count on our counter, they
54 could all be from the same event. */
56 unsigned int id, lun, channel;
58 unsigned int manufacturer; /* Manufacturer of device, for using
59 * vendor-specific cmd's */
60 unsigned sector_size; /* size in bytes */
62 void *hostdata; /* available to low-level driver */
63 char devfs_name[256]; /* devfs junk */
66 unsigned char inquiry_len; /* valid bytes in 'inquiry' */
67 unsigned char * inquiry; /* INQUIRY response data */
68 char * vendor; /* [back_compat] point into 'inquiry' ... */
69 char * model; /* ... after scan; point to static string */
70 char * rev; /* ... "nullnullnullnull" before scan */
71 unsigned char current_tag; /* current tag */
72 struct scsi_target *sdev_target; /* used only for single_lun */
74 unsigned int sdev_bflags; /* black/white flags as also found in
75 * scsi_devinfo.[hc]. For now used only to
76 * pass settings from slave_alloc to scsi
80 unsigned changed:1; /* Data invalid due to media change */
81 unsigned busy:1; /* Used to prevent races */
82 unsigned lockable:1; /* Able to prevent media removal */
83 unsigned locked:1; /* Media removal disabled */
84 unsigned borken:1; /* Tell the Seagate driver to be
85 * painfully slow on this device */
86 unsigned disconnect:1; /* can disconnect */
87 unsigned soft_reset:1; /* Uses soft reset option */
88 unsigned sdtr:1; /* Device supports SDTR messages */
89 unsigned wdtr:1; /* Device supports WDTR messages */
90 unsigned ppr:1; /* Device supports PPR messages */
91 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
92 unsigned simple_tags:1; /* simple queue tag messages are enabled */
93 unsigned ordered_tags:1;/* ordered queue tag messages are enabled */
94 unsigned single_lun:1; /* Indicates we should only allow I/O to
95 * one of the luns for the device at a
97 unsigned was_reset:1; /* There was a bus reset on the bus for
99 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
100 * because we did a bus reset. */
101 unsigned use_10_for_rw:1; /* first try 10-byte read / write */
102 unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
103 unsigned skip_ms_page_8:1; /* do not use MODE SENSE page 0x08 */
104 unsigned skip_ms_page_3f:1; /* do not use MODE SENSE page 0x3f */
105 unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
106 unsigned no_start_on_add:1; /* do not issue start on add */
107 unsigned allow_restart:1; /* issue START_UNIT in error handler */
109 unsigned int device_blocked; /* Device returned QUEUE_FULL. */
111 unsigned int max_device_blocked; /* what device_blocked counts down from */
112 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
114 struct device sdev_gendev;
115 struct class_device sdev_classdev;
117 struct class_device transport_classdev;
119 enum scsi_device_state sdev_state;
120 unsigned long transport_data[0];
121 } __attribute__((aligned(sizeof(unsigned long))));
122 #define to_scsi_device(d) \
123 container_of(d, struct scsi_device, sdev_gendev)
124 #define class_to_sdev(d) \
125 container_of(d, struct scsi_device, sdev_classdev)
126 #define transport_class_to_sdev(class_dev) \
127 container_of(class_dev, struct scsi_device, transport_classdev)
129 extern struct scsi_device *scsi_add_device(struct Scsi_Host *,
131 extern void scsi_remove_device(struct scsi_device *);
132 extern int scsi_device_cancel(struct scsi_device *, int);
134 extern int scsi_device_get(struct scsi_device *);
135 extern void scsi_device_put(struct scsi_device *);
136 extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
138 extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
141 /* only exposed to implement shost_for_each_device */
142 extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
143 struct scsi_device *);
146 * shost_for_each_device - iterate over all devices of a host
148 * @host: host whiches devices we want to iterate over
150 * This traverses over each devices of @shost. The devices have
151 * a reference that must be released by scsi_host_put when breaking
154 #define shost_for_each_device(sdev, shost) \
155 for ((sdev) = __scsi_iterate_devices((shost), NULL); \
157 (sdev) = __scsi_iterate_devices((shost), (sdev)))
160 * __shost_for_each_device - iterate over all devices of a host (UNLOCKED)
162 * @host: host whiches devices we want to iterate over
164 * This traverses over each devices of @shost. It does _not_ take a
165 * reference on the scsi_device, thus it the whole loop must be protected
166 * by shost->host_lock.
168 * Note: The only reason why drivers would want to use this is because
169 * they're need to access the device list in irq context. Otherwise you
170 * really want to use shost_for_each_device instead.
172 #define __shost_for_each_device(sdev, shost) \
173 list_for_each_entry((sdev), &((shost)->__devices), siblings)
175 extern void scsi_adjust_queue_depth(struct scsi_device *, int, int);
176 extern int scsi_track_queue_full(struct scsi_device *, int);
178 extern int scsi_set_medium_removal(struct scsi_device *, char);
180 extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
181 unsigned char *buffer, int len, int timeout,
182 int retries, struct scsi_mode_data *data);
183 extern int scsi_device_set_state(struct scsi_device *sdev,
184 enum scsi_device_state state);
185 extern int scsi_device_quiesce(struct scsi_device *sdev);
186 extern void scsi_device_resume(struct scsi_device *sdev);
187 extern const char *scsi_device_state_name(enum scsi_device_state);
188 static int inline scsi_device_online(struct scsi_device *sdev)
190 return sdev->sdev_state != SDEV_OFFLINE;
192 #endif /* _SCSI_SCSI_DEVICE_H */