patch-2_6_7-vs1_9_1_12
[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);
134 extern void scsi_remove_device(struct scsi_device *);
135 extern int scsi_device_cancel(struct scsi_device *, int);
136
137 extern int scsi_device_get(struct scsi_device *);
138 extern void scsi_device_put(struct scsi_device *);
139 extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
140                                               uint, uint, uint);
141 extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
142                                                 uint, uint, uint);
143
144 /* only exposed to implement shost_for_each_device */
145 extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
146                                                   struct scsi_device *);
147
148 /**
149  * shost_for_each_device  -  iterate over all devices of a host
150  * @sdev:       iterator
151  * @host:       host whiches devices we want to iterate over
152  *
153  * This traverses over each devices of @shost.  The devices have
154  * a reference that must be released by scsi_host_put when breaking
155  * out of the loop.
156  */
157 #define shost_for_each_device(sdev, shost) \
158         for ((sdev) = __scsi_iterate_devices((shost), NULL); \
159              (sdev); \
160              (sdev) = __scsi_iterate_devices((shost), (sdev)))
161
162 /**
163  * __shost_for_each_device  -  iterate over all devices of a host (UNLOCKED)
164  * @sdev:       iterator
165  * @host:       host whiches devices we want to iterate over
166  *
167  * This traverses over each devices of @shost.  It does _not_ take a
168  * reference on the scsi_device, thus it the whole loop must be protected
169  * by shost->host_lock.
170  *
171  * Note:  The only reason why drivers would want to use this is because
172  * they're need to access the device list in irq context.  Otherwise you
173  * really want to use shost_for_each_device instead.
174  */
175 #define __shost_for_each_device(sdev, shost) \
176         list_for_each_entry((sdev), &((shost)->__devices), siblings)
177
178 extern void scsi_adjust_queue_depth(struct scsi_device *, int, int);
179 extern int scsi_track_queue_full(struct scsi_device *, int);
180
181 extern int scsi_set_medium_removal(struct scsi_device *, char);
182
183 extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
184                            unsigned char *buffer, int len, int timeout,
185                            int retries, struct scsi_mode_data *data);
186 extern int scsi_device_set_state(struct scsi_device *sdev,
187                                  enum scsi_device_state state);
188 extern int scsi_device_quiesce(struct scsi_device *sdev);
189 extern void scsi_device_resume(struct scsi_device *sdev);
190 extern const char *scsi_device_state_name(enum scsi_device_state);
191 static int inline scsi_device_online(struct scsi_device *sdev)
192 {
193         return sdev->sdev_state != SDEV_OFFLINE;
194 }
195 #endif /* _SCSI_SCSI_DEVICE_H */