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
16
17
18
19enum scsi_device_state {
20 SDEV_CREATED = 1,
21
22 SDEV_RUNNING,
23
24 SDEV_CANCEL,
25
26 SDEV_DEL,
27
28 SDEV_QUIESCE,
29
30
31 SDEV_OFFLINE,
32
33};
34
35struct scsi_device {
36 struct Scsi_Host *host;
37 struct request_queue *request_queue;
38
39
40 struct list_head siblings;
41 struct list_head same_target_siblings;
42
43 volatile unsigned short device_busy;
44 spinlock_t sdev_lock;
45 spinlock_t list_lock;
46 struct list_head cmd_list;
47 struct list_head starved_entry;
48 struct scsi_cmnd *current_cmnd;
49 unsigned short queue_depth;
50 unsigned short last_queue_full_depth;
51 unsigned short last_queue_full_count;
52 unsigned long last_queue_full_time;
53
54
55
56 unsigned int id, lun, channel;
57
58 unsigned int manufacturer;
59
60 unsigned sector_size;
61
62 void *hostdata;
63 char devfs_name[256];
64 char type;
65 char scsi_level;
66 char inq_periph_qual;
67 unsigned char inquiry_len;
68 unsigned char * inquiry;
69 char * vendor;
70 char * model;
71 char * rev;
72 unsigned char current_tag;
73 struct scsi_target *sdev_target;
74
75 unsigned int sdev_bflags;
76
77
78
79 unsigned writeable:1;
80 unsigned removable:1;
81 unsigned changed:1;
82 unsigned busy:1;
83 unsigned lockable:1;
84 unsigned locked:1;
85 unsigned borken:1;
86
87 unsigned disconnect:1;
88 unsigned soft_reset:1;
89 unsigned sdtr:1;
90 unsigned wdtr:1;
91 unsigned ppr:1;
92 unsigned tagged_supported:1;
93 unsigned simple_tags:1;
94 unsigned ordered_tags:1;
95 unsigned single_lun:1;
96
97
98 unsigned was_reset:1;
99
100 unsigned expecting_cc_ua:1;
101
102 unsigned use_10_for_rw:1;
103 unsigned use_10_for_ms:1;
104 unsigned skip_ms_page_8:1;
105 unsigned skip_ms_page_3f:1;
106 unsigned use_192_bytes_for_3f:1;
107 unsigned no_start_on_add:1;
108 unsigned allow_restart:1;
109
110 unsigned int device_blocked;
111
112 unsigned int max_device_blocked;
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
132extern struct scsi_device *scsi_add_device(struct Scsi_Host *,
133 uint, uint, uint);
134extern void scsi_remove_device(struct scsi_device *);
135extern int scsi_device_cancel(struct scsi_device *, int);
136
137extern int scsi_device_get(struct scsi_device *);
138extern void scsi_device_put(struct scsi_device *);
139extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *,
140 uint, uint, uint);
141extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *,
142 uint, uint, uint);
143
144
145extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
146 struct scsi_device *);
147
148
149
150
151
152
153
154
155
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
164
165
166
167
168
169
170
171
172
173
174
175#define __shost_for_each_device(sdev, shost) \
176 list_for_each_entry((sdev), &((shost)->__devices), siblings)
177
178extern void scsi_adjust_queue_depth(struct scsi_device *, int, int);
179extern int scsi_track_queue_full(struct scsi_device *, int);
180
181extern int scsi_set_medium_removal(struct scsi_device *, char);
182
183extern 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);
186extern int scsi_device_set_state(struct scsi_device *sdev,
187 enum scsi_device_state state);
188extern int scsi_device_quiesce(struct scsi_device *sdev);
189extern void scsi_device_resume(struct scsi_device *sdev);
190extern const char *scsi_device_state_name(enum scsi_device_state);
191static int inline scsi_device_online(struct scsi_device *sdev)
192{
193 return sdev->sdev_state != SDEV_OFFLINE;
194}
195#endif
196