vserver 1.9.3
[linux-2.6.git] / include / scsi / scsi_device.h
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
9 struct request_queue;
10 struct scsi_cmnd;
11 struct 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  */
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
32                                  * user request */
33 };
34
35 struct scsi_device {
36         struct Scsi_Host *host;
37         struct request_queue *request_queue;
38
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 */
42
43         volatile unsigned short device_busy;    /* commands actually active on low-level */
44         spinlock_t sdev_lock;           /* also the request queue_lock */
45         spinlock_t list_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. */
55
56         unsigned int id, lun, channel;
57
58         unsigned int manufacturer;      /* Manufacturer of device, for using 
59                                          * vendor-specific cmd's */
60         unsigned sector_size;   /* size in bytes */
61
62         void *hostdata;         /* available to low-level driver */
63         char devfs_name[256];   /* devfs junk */
64         char type;
65         char scsi_level;
66         char inq_periph_qual;   /* PQ from INQUIRY data */      
67         unsigned char inquiry_len;      /* valid bytes in 'inquiry' */
68         unsigned char * inquiry;        /* INQUIRY response data */
69         char * vendor;          /* [back_compat] point into 'inquiry' ... */
70         char * model;           /* ... after scan; point to static string */
71         char * rev;             /* ... "nullnullnullnull" before scan */
72         unsigned char current_tag;      /* current tag */
73         struct scsi_target      *sdev_target;   /* used only for single_lun */
74
75         unsigned int    sdev_bflags; /* black/white flags as also found in
76                                  * scsi_devinfo.[hc]. For now used only to
77                                  * pass settings from slave_alloc to scsi
78                                  * core. */
79         unsigned writeable:1;
80         unsigned removable:1;
81         unsigned changed:1;     /* Data invalid due to media change */
82         unsigned busy:1;        /* Used to prevent races */
83         unsigned lockable:1;    /* Able to prevent media removal */
84         unsigned locked:1;      /* Media removal disabled */
85         unsigned borken:1;      /* Tell the Seagate driver to be 
86                                  * painfully slow on this device */
87         unsigned disconnect:1;  /* can disconnect */
88         unsigned soft_reset:1;  /* Uses soft reset option */
89         unsigned sdtr:1;        /* Device supports SDTR messages */
90         unsigned wdtr:1;        /* Device supports WDTR messages */
91         unsigned ppr:1;         /* Device supports PPR messages */
92         unsigned tagged_supported:1;    /* Supports SCSI-II tagged queuing */
93         unsigned simple_tags:1; /* simple queue tag messages are enabled */
94         unsigned ordered_tags:1;/* ordered queue tag messages are enabled */
95         unsigned single_lun:1;  /* Indicates we should only allow I/O to
96                                  * one of the luns for the device at a 
97                                  * time. */
98         unsigned was_reset:1;   /* There was a bus reset on the bus for 
99                                  * this device */
100         unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
101                                      * because we did a bus reset. */
102         unsigned use_10_for_rw:1; /* first try 10-byte read / write */
103         unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
104         unsigned skip_ms_page_8:1;      /* do not use MODE SENSE page 0x08 */
105         unsigned skip_ms_page_3f:1;     /* do not use MODE SENSE page 0x3f */
106         unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
107         unsigned no_start_on_add:1;     /* do not issue start on add */
108         unsigned allow_restart:1; /* issue START_UNIT in error handler */
109
110         unsigned int device_blocked;    /* Device returned QUEUE_FULL. */
111
112         unsigned int max_device_blocked; /* what device_blocked counts down from  */
113 #define SCSI_DEFAULT_DEVICE_BLOCKED     3
114
115         int timeout;
116
117         struct device           sdev_gendev;
118         struct class_device     sdev_classdev;
119
120         struct class_device     transport_classdev;
121
122         enum scsi_device_state sdev_state;
123         unsigned long           transport_data[0];
124 } __attribute__((aligned(sizeof(unsigned long))));
125 #define to_scsi_device(d)       \
126         container_of(d, struct scsi_device, sdev_gendev)
127 #define class_to_sdev(d)        \
128         container_of(d, struct scsi_device, sdev_classdev)
129 #define transport_class_to_sdev(class_dev) \
130         container_of(class_dev, struct scsi_device, transport_classdev)
131
132 extern struct scsi_device *__scsi_add_device(struct Scsi_Host *,
133                 uint, uint, uint, void *hostdata);
134 #define scsi_add_device(host, channel, target, lun) \
135         __scsi_add_device(host, channel, target, lun, NULL)
136 extern void scsi_remove_device(struct scsi_device *);
137 extern int scsi_device_cancel(struct scsi_device *, int);
138
139 extern int scsi_device_get(struct scsi_device *);
140 extern void scsi_device_put(struct scsi_device *);
141 extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
142                                               uint, uint, uint);
143 extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
144                                                 uint, uint, uint);
145
146 /* only exposed to implement shost_for_each_device */
147 extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
148                                                   struct scsi_device *);
149
150 /**
151  * shost_for_each_device  -  iterate over all devices of a host
152  * @sdev:       iterator
153  * @host:       host whiches devices we want to iterate over
154  *
155  * This traverses over each devices of @shost.  The devices have
156  * a reference that must be released by scsi_host_put when breaking
157  * out of the loop.
158  */
159 #define shost_for_each_device(sdev, shost) \
160         for ((sdev) = __scsi_iterate_devices((shost), NULL); \
161              (sdev); \
162              (sdev) = __scsi_iterate_devices((shost), (sdev)))
163
164 /**
165  * __shost_for_each_device  -  iterate over all devices of a host (UNLOCKED)
166  * @sdev:       iterator
167  * @host:       host whiches devices we want to iterate over
168  *
169  * This traverses over each devices of @shost.  It does _not_ take a
170  * reference on the scsi_device, thus it the whole loop must be protected
171  * by shost->host_lock.
172  *
173  * Note:  The only reason why drivers would want to use this is because
174  * they're need to access the device list in irq context.  Otherwise you
175  * really want to use shost_for_each_device instead.
176  */
177 #define __shost_for_each_device(sdev, shost) \
178         list_for_each_entry((sdev), &((shost)->__devices), siblings)
179
180 extern void scsi_adjust_queue_depth(struct scsi_device *, int, int);
181 extern int scsi_track_queue_full(struct scsi_device *, int);
182
183 extern int scsi_set_medium_removal(struct scsi_device *, char);
184
185 extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
186                            unsigned char *buffer, int len, int timeout,
187                            int retries, struct scsi_mode_data *data);
188 extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
189                                 int retries);
190 extern int scsi_device_set_state(struct scsi_device *sdev,
191                                  enum scsi_device_state state);
192 extern int scsi_device_quiesce(struct scsi_device *sdev);
193 extern void scsi_device_resume(struct scsi_device *sdev);
194 extern const char *scsi_device_state_name(enum scsi_device_state);
195 static inline int scsi_device_online(struct scsi_device *sdev)
196 {
197         return sdev->sdev_state != SDEV_OFFLINE;
198 }
199
200 /* accessor functions for the SCSI parameters */
201 static inline int scsi_device_sync(struct scsi_device *sdev)
202 {
203         return sdev->sdtr;
204 }
205 static inline int scsi_device_wide(struct scsi_device *sdev)
206 {
207         return sdev->wdtr;
208 }
209 static inline int scsi_device_dt(struct scsi_device *sdev)
210 {
211         return sdev->ppr;
212 }
213 static inline int scsi_device_dt_only(struct scsi_device *sdev)
214 {
215         if (sdev->inquiry_len < 57)
216                 return 0;
217         return (sdev->inquiry[56] & 0x0c) == 0x04;
218 }
219 static inline int scsi_device_ius(struct scsi_device *sdev)
220 {
221         if (sdev->inquiry_len < 57)
222                 return 0;
223         return sdev->inquiry[56] & 0x01;
224 }
225 static inline int scsi_device_qas(struct scsi_device *sdev)
226 {
227         if (sdev->inquiry_len < 57)
228                 return 0;
229         return sdev->inquiry[56] & 0x02;
230 }
231 #endif /* _SCSI_SCSI_DEVICE_H */