aboutsummaryrefslogtreecommitdiffstats
path: root/include/scsi/scsi_device.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/scsi/scsi_device.h
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/scsi/scsi_device.h')
-rw-r--r--include/scsi/scsi_device.h282
1 files changed, 282 insertions, 0 deletions
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
new file mode 100644
index 00000000000..07d974051b0
--- /dev/null
+++ b/include/scsi/scsi_device.h
@@ -0,0 +1,282 @@
1#ifndef _SCSI_SCSI_DEVICE_H
2#define _SCSI_SCSI_DEVICE_H
3
4#include <linux/device.h>
5#include <linux/list.h>
6#include <linux/spinlock.h>
7#include <asm/atomic.h>
8
9struct request_queue;
10struct scsi_cmnd;
11struct scsi_mode_data;
12
13
14/*
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().
18 */
19enum 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
32 * user request */
33 SDEV_BLOCK, /* Device blocked by scsi lld. No scsi
34 * commands from user or midlayer should be issued
35 * to the scsi lld. */
36};
37
38struct scsi_device {
39 struct Scsi_Host *host;
40 struct request_queue *request_queue;
41
42 /* the next two are protected by the host->host_lock */
43 struct list_head siblings; /* list of all devices on this host */
44 struct list_head same_target_siblings; /* just the devices sharing same target id */
45
46 volatile unsigned short device_busy; /* commands actually active on low-level */
47 spinlock_t sdev_lock; /* also the request queue_lock */
48 spinlock_t list_lock;
49 struct list_head cmd_list; /* queue of in use SCSI Command structures */
50 struct list_head starved_entry;
51 struct scsi_cmnd *current_cmnd; /* currently active command */
52 unsigned short queue_depth; /* How deep of a queue we want */
53 unsigned short last_queue_full_depth; /* These two are used by */
54 unsigned short last_queue_full_count; /* scsi_track_queue_full() */
55 unsigned long last_queue_full_time;/* don't let QUEUE_FULLs on the same
56 jiffie count on our counter, they
57 could all be from the same event. */
58
59 unsigned int id, lun, channel;
60
61 unsigned int manufacturer; /* Manufacturer of device, for using
62 * vendor-specific cmd's */
63 unsigned sector_size; /* size in bytes */
64
65 void *hostdata; /* available to low-level driver */
66 char devfs_name[256]; /* devfs junk */
67 char type;
68 char scsi_level;
69 char inq_periph_qual; /* PQ from INQUIRY data */
70 unsigned char inquiry_len; /* valid bytes in 'inquiry' */
71 unsigned char * inquiry; /* INQUIRY response data */
72 char * vendor; /* [back_compat] point into 'inquiry' ... */
73 char * model; /* ... after scan; point to static string */
74 char * rev; /* ... "nullnullnullnull" before scan */
75 unsigned char current_tag; /* current tag */
76 struct scsi_target *sdev_target; /* used only for single_lun */
77
78 unsigned int sdev_bflags; /* black/white flags as also found in
79 * scsi_devinfo.[hc]. For now used only to
80 * pass settings from slave_alloc to scsi
81 * core. */
82 unsigned writeable:1;
83 unsigned removable:1;
84 unsigned changed:1; /* Data invalid due to media change */
85 unsigned busy:1; /* Used to prevent races */
86 unsigned lockable:1; /* Able to prevent media removal */
87 unsigned locked:1; /* Media removal disabled */
88 unsigned borken:1; /* Tell the Seagate driver to be
89 * painfully slow on this device */
90 unsigned disconnect:1; /* can disconnect */
91 unsigned soft_reset:1; /* Uses soft reset option */
92 unsigned sdtr:1; /* Device supports SDTR messages */
93 unsigned wdtr:1; /* Device supports WDTR messages */
94 unsigned ppr:1; /* Device supports PPR messages */
95 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
96 unsigned simple_tags:1; /* simple queue tag messages are enabled */
97 unsigned ordered_tags:1;/* ordered queue tag messages are enabled */
98 unsigned single_lun:1; /* Indicates we should only allow I/O to
99 * one of the luns for the device at a
100 * time. */
101 unsigned was_reset:1; /* There was a bus reset on the bus for
102 * this device */
103 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
104 * because we did a bus reset. */
105 unsigned use_10_for_rw:1; /* first try 10-byte read / write */
106 unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
107 unsigned skip_ms_page_8:1; /* do not use MODE SENSE page 0x08 */
108 unsigned skip_ms_page_3f:1; /* do not use MODE SENSE page 0x3f */
109 unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
110 unsigned no_start_on_add:1; /* do not issue start on add */
111 unsigned allow_restart:1; /* issue START_UNIT in error handler */
112 unsigned no_uld_attach:1; /* disable connecting to upper level drivers */
113 unsigned select_no_atn:1;
114 unsigned fix_capacity:1; /* READ_CAPACITY is too high by 1 */
115 unsigned retry_hwerror:1; /* Retry HARDWARE_ERROR */
116
117 unsigned int device_blocked; /* Device returned QUEUE_FULL. */
118
119 unsigned int max_device_blocked; /* what device_blocked counts down from */
120#define SCSI_DEFAULT_DEVICE_BLOCKED 3
121
122 atomic_t iorequest_cnt;
123 atomic_t iodone_cnt;
124 atomic_t ioerr_cnt;
125
126 int timeout;
127
128 struct device sdev_gendev;
129 struct class_device sdev_classdev;
130
131 enum scsi_device_state sdev_state;
132 unsigned long sdev_data[0];
133} __attribute__((aligned(sizeof(unsigned long))));
134#define to_scsi_device(d) \
135 container_of(d, struct scsi_device, sdev_gendev)
136#define class_to_sdev(d) \
137 container_of(d, struct scsi_device, sdev_classdev)
138#define transport_class_to_sdev(class_dev) \
139 to_scsi_device(class_dev->dev)
140
141/*
142 * scsi_target: representation of a scsi target, for now, this is only
143 * used for single_lun devices. If no one has active IO to the target,
144 * starget_sdev_user is NULL, else it points to the active sdev.
145 */
146struct scsi_target {
147 struct scsi_device *starget_sdev_user;
148 struct list_head siblings;
149 struct list_head devices;
150 struct device dev;
151 unsigned int reap_ref; /* protected by the host lock */
152 unsigned int channel;
153 unsigned int id; /* target id ... replace
154 * scsi_device.id eventually */
155 unsigned long create:1; /* signal that it needs to be added */
156 unsigned long starget_data[0];
157} __attribute__((aligned(sizeof(unsigned long))));
158
159#define to_scsi_target(d) container_of(d, struct scsi_target, dev)
160static inline struct scsi_target *scsi_target(struct scsi_device *sdev)
161{
162 return to_scsi_target(sdev->sdev_gendev.parent);
163}
164#define transport_class_to_starget(class_dev) \
165 to_scsi_target(class_dev->dev)
166
167extern struct scsi_device *__scsi_add_device(struct Scsi_Host *,
168 uint, uint, uint, void *hostdata);
169#define scsi_add_device(host, channel, target, lun) \
170 __scsi_add_device(host, channel, target, lun, NULL)
171extern void scsi_remove_device(struct scsi_device *);
172extern int scsi_device_cancel(struct scsi_device *, int);
173
174extern int scsi_device_get(struct scsi_device *);
175extern void scsi_device_put(struct scsi_device *);
176extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
177 uint, uint, uint);
178extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
179 uint, uint, uint);
180extern struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *,
181 uint);
182extern struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *,
183 uint);
184extern void starget_for_each_device(struct scsi_target *, void *,
185 void (*fn)(struct scsi_device *, void *));
186
187/* only exposed to implement shost_for_each_device */
188extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
189 struct scsi_device *);
190
191/**
192 * shost_for_each_device - iterate over all devices of a host
193 * @sdev: iterator
194 * @host: host whiches devices we want to iterate over
195 *
196 * This traverses over each devices of @shost. The devices have
197 * a reference that must be released by scsi_host_put when breaking
198 * out of the loop.
199 */
200#define shost_for_each_device(sdev, shost) \
201 for ((sdev) = __scsi_iterate_devices((shost), NULL); \
202 (sdev); \
203 (sdev) = __scsi_iterate_devices((shost), (sdev)))
204
205/**
206 * __shost_for_each_device - iterate over all devices of a host (UNLOCKED)
207 * @sdev: iterator
208 * @host: host whiches devices we want to iterate over
209 *
210 * This traverses over each devices of @shost. It does _not_ take a
211 * reference on the scsi_device, thus it the whole loop must be protected
212 * by shost->host_lock.
213 *
214 * Note: The only reason why drivers would want to use this is because
215 * they're need to access the device list in irq context. Otherwise you
216 * really want to use shost_for_each_device instead.
217 */
218#define __shost_for_each_device(sdev, shost) \
219 list_for_each_entry((sdev), &((shost)->__devices), siblings)
220
221extern void scsi_adjust_queue_depth(struct scsi_device *, int, int);
222extern int scsi_track_queue_full(struct scsi_device *, int);
223
224extern int scsi_set_medium_removal(struct scsi_device *, char);
225
226extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
227 unsigned char *buffer, int len, int timeout,
228 int retries, struct scsi_mode_data *data);
229extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
230 int retries);
231extern int scsi_device_set_state(struct scsi_device *sdev,
232 enum scsi_device_state state);
233extern int scsi_device_quiesce(struct scsi_device *sdev);
234extern void scsi_device_resume(struct scsi_device *sdev);
235extern void scsi_target_quiesce(struct scsi_target *);
236extern void scsi_target_resume(struct scsi_target *);
237extern void scsi_scan_target(struct device *parent, unsigned int channel,
238 unsigned int id, unsigned int lun, int rescan);
239extern void scsi_target_reap(struct scsi_target *);
240extern void scsi_target_block(struct device *);
241extern void scsi_target_unblock(struct device *);
242extern void scsi_remove_target(struct device *);
243extern const char *scsi_device_state_name(enum scsi_device_state);
244extern int scsi_is_sdev_device(const struct device *);
245extern int scsi_is_target_device(const struct device *);
246static inline int scsi_device_online(struct scsi_device *sdev)
247{
248 return sdev->sdev_state != SDEV_OFFLINE;
249}
250
251/* accessor functions for the SCSI parameters */
252static inline int scsi_device_sync(struct scsi_device *sdev)
253{
254 return sdev->sdtr;
255}
256static inline int scsi_device_wide(struct scsi_device *sdev)
257{
258 return sdev->wdtr;
259}
260static inline int scsi_device_dt(struct scsi_device *sdev)
261{
262 return sdev->ppr;
263}
264static inline int scsi_device_dt_only(struct scsi_device *sdev)
265{
266 if (sdev->inquiry_len < 57)
267 return 0;
268 return (sdev->inquiry[56] & 0x0c) == 0x04;
269}
270static inline int scsi_device_ius(struct scsi_device *sdev)
271{
272 if (sdev->inquiry_len < 57)
273 return 0;
274 return sdev->inquiry[56] & 0x01;
275}
276static inline int scsi_device_qas(struct scsi_device *sdev)
277{
278 if (sdev->inquiry_len < 57)
279 return 0;
280 return sdev->inquiry[56] & 0x02;
281}
282#endif /* _SCSI_SCSI_DEVICE_H */