diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/scsi |
Linux-2.6.12-rc2v2.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')
-rw-r--r-- | include/scsi/scsi.h | 412 | ||||
-rw-r--r-- | include/scsi/scsi_cmnd.h | 165 | ||||
-rw-r--r-- | include/scsi/scsi_dbg.h | 21 | ||||
-rw-r--r-- | include/scsi/scsi_device.h | 282 | ||||
-rw-r--r-- | include/scsi/scsi_devinfo.h | 31 | ||||
-rw-r--r-- | include/scsi/scsi_driver.h | 31 | ||||
-rw-r--r-- | include/scsi/scsi_eh.h | 63 | ||||
-rw-r--r-- | include/scsi/scsi_host.h | 642 | ||||
-rw-r--r-- | include/scsi/scsi_ioctl.h | 50 | ||||
-rw-r--r-- | include/scsi/scsi_request.h | 73 | ||||
-rw-r--r-- | include/scsi/scsi_tcq.h | 134 | ||||
-rw-r--r-- | include/scsi/scsi_transport.h | 48 | ||||
-rw-r--r-- | include/scsi/scsi_transport_fc.h | 442 | ||||
-rw-r--r-- | include/scsi/scsi_transport_iscsi.h | 178 | ||||
-rw-r--r-- | include/scsi/scsi_transport_spi.h | 135 | ||||
-rw-r--r-- | include/scsi/scsicam.h | 19 | ||||
-rw-r--r-- | include/scsi/sg.h | 326 |
17 files changed, 3052 insertions, 0 deletions
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h new file mode 100644 index 000000000000..1d54c063ae52 --- /dev/null +++ b/include/scsi/scsi.h | |||
@@ -0,0 +1,412 @@ | |||
1 | /* | ||
2 | * This header file contains public constants and structures used by | ||
3 | * the scsi code for linux. | ||
4 | * | ||
5 | * For documentation on the OPCODES, MESSAGES, and SENSE values, | ||
6 | * please consult the SCSI standard. | ||
7 | */ | ||
8 | #ifndef _SCSI_SCSI_H | ||
9 | #define _SCSI_SCSI_H | ||
10 | |||
11 | #include <linux/types.h> | ||
12 | |||
13 | /* | ||
14 | * The maximum sg list length SCSI can cope with | ||
15 | * (currently must be a power of 2 between 32 and 256) | ||
16 | */ | ||
17 | #define SCSI_MAX_PHYS_SEGMENTS MAX_PHYS_SEGMENTS | ||
18 | |||
19 | |||
20 | /* | ||
21 | * SCSI command lengths | ||
22 | */ | ||
23 | |||
24 | extern const unsigned char scsi_command_size[8]; | ||
25 | #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7] | ||
26 | |||
27 | /* | ||
28 | * SCSI device types | ||
29 | */ | ||
30 | |||
31 | #define MAX_SCSI_DEVICE_CODE 14 | ||
32 | extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE]; | ||
33 | |||
34 | /* | ||
35 | * SCSI opcodes | ||
36 | */ | ||
37 | |||
38 | #define TEST_UNIT_READY 0x00 | ||
39 | #define REZERO_UNIT 0x01 | ||
40 | #define REQUEST_SENSE 0x03 | ||
41 | #define FORMAT_UNIT 0x04 | ||
42 | #define READ_BLOCK_LIMITS 0x05 | ||
43 | #define REASSIGN_BLOCKS 0x07 | ||
44 | #define READ_6 0x08 | ||
45 | #define WRITE_6 0x0a | ||
46 | #define SEEK_6 0x0b | ||
47 | #define READ_REVERSE 0x0f | ||
48 | #define WRITE_FILEMARKS 0x10 | ||
49 | #define SPACE 0x11 | ||
50 | #define INQUIRY 0x12 | ||
51 | #define RECOVER_BUFFERED_DATA 0x14 | ||
52 | #define MODE_SELECT 0x15 | ||
53 | #define RESERVE 0x16 | ||
54 | #define RELEASE 0x17 | ||
55 | #define COPY 0x18 | ||
56 | #define ERASE 0x19 | ||
57 | #define MODE_SENSE 0x1a | ||
58 | #define START_STOP 0x1b | ||
59 | #define RECEIVE_DIAGNOSTIC 0x1c | ||
60 | #define SEND_DIAGNOSTIC 0x1d | ||
61 | #define ALLOW_MEDIUM_REMOVAL 0x1e | ||
62 | |||
63 | #define SET_WINDOW 0x24 | ||
64 | #define READ_CAPACITY 0x25 | ||
65 | #define READ_10 0x28 | ||
66 | #define WRITE_10 0x2a | ||
67 | #define SEEK_10 0x2b | ||
68 | #define WRITE_VERIFY 0x2e | ||
69 | #define VERIFY 0x2f | ||
70 | #define SEARCH_HIGH 0x30 | ||
71 | #define SEARCH_EQUAL 0x31 | ||
72 | #define SEARCH_LOW 0x32 | ||
73 | #define SET_LIMITS 0x33 | ||
74 | #define PRE_FETCH 0x34 | ||
75 | #define READ_POSITION 0x34 | ||
76 | #define SYNCHRONIZE_CACHE 0x35 | ||
77 | #define LOCK_UNLOCK_CACHE 0x36 | ||
78 | #define READ_DEFECT_DATA 0x37 | ||
79 | #define MEDIUM_SCAN 0x38 | ||
80 | #define COMPARE 0x39 | ||
81 | #define COPY_VERIFY 0x3a | ||
82 | #define WRITE_BUFFER 0x3b | ||
83 | #define READ_BUFFER 0x3c | ||
84 | #define UPDATE_BLOCK 0x3d | ||
85 | #define READ_LONG 0x3e | ||
86 | #define WRITE_LONG 0x3f | ||
87 | #define CHANGE_DEFINITION 0x40 | ||
88 | #define WRITE_SAME 0x41 | ||
89 | #define READ_TOC 0x43 | ||
90 | #define LOG_SELECT 0x4c | ||
91 | #define LOG_SENSE 0x4d | ||
92 | #define MODE_SELECT_10 0x55 | ||
93 | #define RESERVE_10 0x56 | ||
94 | #define RELEASE_10 0x57 | ||
95 | #define MODE_SENSE_10 0x5a | ||
96 | #define PERSISTENT_RESERVE_IN 0x5e | ||
97 | #define PERSISTENT_RESERVE_OUT 0x5f | ||
98 | #define REPORT_LUNS 0xa0 | ||
99 | #define MOVE_MEDIUM 0xa5 | ||
100 | #define READ_12 0xa8 | ||
101 | #define WRITE_12 0xaa | ||
102 | #define WRITE_VERIFY_12 0xae | ||
103 | #define SEARCH_HIGH_12 0xb0 | ||
104 | #define SEARCH_EQUAL_12 0xb1 | ||
105 | #define SEARCH_LOW_12 0xb2 | ||
106 | #define READ_ELEMENT_STATUS 0xb8 | ||
107 | #define SEND_VOLUME_TAG 0xb6 | ||
108 | #define WRITE_LONG_2 0xea | ||
109 | #define READ_16 0x88 | ||
110 | #define WRITE_16 0x8a | ||
111 | #define VERIFY_16 0x8f | ||
112 | #define SERVICE_ACTION_IN 0x9e | ||
113 | /* values for service action in */ | ||
114 | #define SAI_READ_CAPACITY_16 0x10 | ||
115 | |||
116 | |||
117 | /* | ||
118 | * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft | ||
119 | * T10/1561-D Revision 4 Draft dated 7th November 2002. | ||
120 | */ | ||
121 | #define SAM_STAT_GOOD 0x00 | ||
122 | #define SAM_STAT_CHECK_CONDITION 0x02 | ||
123 | #define SAM_STAT_CONDITION_MET 0x04 | ||
124 | #define SAM_STAT_BUSY 0x08 | ||
125 | #define SAM_STAT_INTERMEDIATE 0x10 | ||
126 | #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 | ||
127 | #define SAM_STAT_RESERVATION_CONFLICT 0x18 | ||
128 | #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ | ||
129 | #define SAM_STAT_TASK_SET_FULL 0x28 | ||
130 | #define SAM_STAT_ACA_ACTIVE 0x30 | ||
131 | #define SAM_STAT_TASK_ABORTED 0x40 | ||
132 | |||
133 | /** scsi_status_is_good - check the status return. | ||
134 | * | ||
135 | * @status: the status passed up from the driver (including host and | ||
136 | * driver components) | ||
137 | * | ||
138 | * This returns true for known good conditions that may be treated as | ||
139 | * command completed normally | ||
140 | */ | ||
141 | static inline int scsi_status_is_good(int status) | ||
142 | { | ||
143 | /* | ||
144 | * FIXME: bit0 is listed as reserved in SCSI-2, but is | ||
145 | * significant in SCSI-3. For now, we follow the SCSI-2 | ||
146 | * behaviour and ignore reserved bits. | ||
147 | */ | ||
148 | status &= 0xfe; | ||
149 | return ((status == SAM_STAT_GOOD) || | ||
150 | (status == SAM_STAT_INTERMEDIATE) || | ||
151 | (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) || | ||
152 | /* FIXME: this is obsolete in SAM-3 */ | ||
153 | (status == SAM_STAT_COMMAND_TERMINATED)); | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | * Status codes. These are deprecated as they are shifted 1 bit right | ||
158 | * from those found in the SCSI standards. This causes confusion for | ||
159 | * applications that are ported to several OSes. Prefer SAM Status codes | ||
160 | * above. | ||
161 | */ | ||
162 | |||
163 | #define GOOD 0x00 | ||
164 | #define CHECK_CONDITION 0x01 | ||
165 | #define CONDITION_GOOD 0x02 | ||
166 | #define BUSY 0x04 | ||
167 | #define INTERMEDIATE_GOOD 0x08 | ||
168 | #define INTERMEDIATE_C_GOOD 0x0a | ||
169 | #define RESERVATION_CONFLICT 0x0c | ||
170 | #define COMMAND_TERMINATED 0x11 | ||
171 | #define QUEUE_FULL 0x14 | ||
172 | #define ACA_ACTIVE 0x18 | ||
173 | #define TASK_ABORTED 0x20 | ||
174 | |||
175 | #define STATUS_MASK 0xfe | ||
176 | |||
177 | /* | ||
178 | * SENSE KEYS | ||
179 | */ | ||
180 | |||
181 | #define NO_SENSE 0x00 | ||
182 | #define RECOVERED_ERROR 0x01 | ||
183 | #define NOT_READY 0x02 | ||
184 | #define MEDIUM_ERROR 0x03 | ||
185 | #define HARDWARE_ERROR 0x04 | ||
186 | #define ILLEGAL_REQUEST 0x05 | ||
187 | #define UNIT_ATTENTION 0x06 | ||
188 | #define DATA_PROTECT 0x07 | ||
189 | #define BLANK_CHECK 0x08 | ||
190 | #define COPY_ABORTED 0x0a | ||
191 | #define ABORTED_COMMAND 0x0b | ||
192 | #define VOLUME_OVERFLOW 0x0d | ||
193 | #define MISCOMPARE 0x0e | ||
194 | |||
195 | |||
196 | /* | ||
197 | * DEVICE TYPES | ||
198 | */ | ||
199 | |||
200 | #define TYPE_DISK 0x00 | ||
201 | #define TYPE_TAPE 0x01 | ||
202 | #define TYPE_PRINTER 0x02 | ||
203 | #define TYPE_PROCESSOR 0x03 /* HP scanners use this */ | ||
204 | #define TYPE_WORM 0x04 /* Treated as ROM by our system */ | ||
205 | #define TYPE_ROM 0x05 | ||
206 | #define TYPE_SCANNER 0x06 | ||
207 | #define TYPE_MOD 0x07 /* Magneto-optical disk - | ||
208 | * - treated as TYPE_DISK */ | ||
209 | #define TYPE_MEDIUM_CHANGER 0x08 | ||
210 | #define TYPE_COMM 0x09 /* Communications device */ | ||
211 | #define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ | ||
212 | #define TYPE_RAID 0x0c | ||
213 | #define TYPE_NO_LUN 0x7f | ||
214 | |||
215 | /* | ||
216 | * standard mode-select header prepended to all mode-select commands | ||
217 | */ | ||
218 | |||
219 | struct ccs_modesel_head { | ||
220 | __u8 _r1; /* reserved */ | ||
221 | __u8 medium; /* device-specific medium type */ | ||
222 | __u8 _r2; /* reserved */ | ||
223 | __u8 block_desc_length; /* block descriptor length */ | ||
224 | __u8 density; /* device-specific density code */ | ||
225 | __u8 number_blocks_hi; /* number of blocks in this block desc */ | ||
226 | __u8 number_blocks_med; | ||
227 | __u8 number_blocks_lo; | ||
228 | __u8 _r3; | ||
229 | __u8 block_length_hi; /* block length for blocks in this desc */ | ||
230 | __u8 block_length_med; | ||
231 | __u8 block_length_lo; | ||
232 | }; | ||
233 | |||
234 | /* | ||
235 | * ScsiLun: 8 byte LUN. | ||
236 | */ | ||
237 | struct scsi_lun { | ||
238 | __u8 scsi_lun[8]; | ||
239 | }; | ||
240 | |||
241 | /* | ||
242 | * MESSAGE CODES | ||
243 | */ | ||
244 | |||
245 | #define COMMAND_COMPLETE 0x00 | ||
246 | #define EXTENDED_MESSAGE 0x01 | ||
247 | #define EXTENDED_MODIFY_DATA_POINTER 0x00 | ||
248 | #define EXTENDED_SDTR 0x01 | ||
249 | #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ | ||
250 | #define EXTENDED_WDTR 0x03 | ||
251 | #define EXTENDED_PPR 0x04 | ||
252 | #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05 | ||
253 | #define SAVE_POINTERS 0x02 | ||
254 | #define RESTORE_POINTERS 0x03 | ||
255 | #define DISCONNECT 0x04 | ||
256 | #define INITIATOR_ERROR 0x05 | ||
257 | #define ABORT_TASK_SET 0x06 | ||
258 | #define MESSAGE_REJECT 0x07 | ||
259 | #define NOP 0x08 | ||
260 | #define MSG_PARITY_ERROR 0x09 | ||
261 | #define LINKED_CMD_COMPLETE 0x0a | ||
262 | #define LINKED_FLG_CMD_COMPLETE 0x0b | ||
263 | #define TARGET_RESET 0x0c | ||
264 | #define ABORT_TASK 0x0d | ||
265 | #define CLEAR_TASK_SET 0x0e | ||
266 | #define INITIATE_RECOVERY 0x0f /* SCSI-II only */ | ||
267 | #define RELEASE_RECOVERY 0x10 /* SCSI-II only */ | ||
268 | #define CLEAR_ACA 0x16 | ||
269 | #define LOGICAL_UNIT_RESET 0x17 | ||
270 | #define SIMPLE_QUEUE_TAG 0x20 | ||
271 | #define HEAD_OF_QUEUE_TAG 0x21 | ||
272 | #define ORDERED_QUEUE_TAG 0x22 | ||
273 | #define IGNORE_WIDE_RESIDUE 0x23 | ||
274 | #define ACA 0x24 | ||
275 | #define QAS_REQUEST 0x55 | ||
276 | |||
277 | /* Old SCSI2 names, don't use in new code */ | ||
278 | #define BUS_DEVICE_RESET TARGET_RESET | ||
279 | #define ABORT ABORT_TASK_SET | ||
280 | |||
281 | /* | ||
282 | * Host byte codes | ||
283 | */ | ||
284 | |||
285 | #define DID_OK 0x00 /* NO error */ | ||
286 | #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ | ||
287 | #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ | ||
288 | #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ | ||
289 | #define DID_BAD_TARGET 0x04 /* BAD target. */ | ||
290 | #define DID_ABORT 0x05 /* Told to abort for some other reason */ | ||
291 | #define DID_PARITY 0x06 /* Parity error */ | ||
292 | #define DID_ERROR 0x07 /* Internal error */ | ||
293 | #define DID_RESET 0x08 /* Reset by somebody. */ | ||
294 | #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ | ||
295 | #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ | ||
296 | #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ | ||
297 | #define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */ | ||
298 | #define DRIVER_OK 0x00 /* Driver status */ | ||
299 | |||
300 | /* | ||
301 | * These indicate the error that occurred, and what is available. | ||
302 | */ | ||
303 | |||
304 | #define DRIVER_BUSY 0x01 | ||
305 | #define DRIVER_SOFT 0x02 | ||
306 | #define DRIVER_MEDIA 0x03 | ||
307 | #define DRIVER_ERROR 0x04 | ||
308 | |||
309 | #define DRIVER_INVALID 0x05 | ||
310 | #define DRIVER_TIMEOUT 0x06 | ||
311 | #define DRIVER_HARD 0x07 | ||
312 | #define DRIVER_SENSE 0x08 | ||
313 | |||
314 | #define SUGGEST_RETRY 0x10 | ||
315 | #define SUGGEST_ABORT 0x20 | ||
316 | #define SUGGEST_REMAP 0x30 | ||
317 | #define SUGGEST_DIE 0x40 | ||
318 | #define SUGGEST_SENSE 0x80 | ||
319 | #define SUGGEST_IS_OK 0xff | ||
320 | |||
321 | #define DRIVER_MASK 0x0f | ||
322 | #define SUGGEST_MASK 0xf0 | ||
323 | |||
324 | /* | ||
325 | * Internal return values. | ||
326 | */ | ||
327 | |||
328 | #define NEEDS_RETRY 0x2001 | ||
329 | #define SUCCESS 0x2002 | ||
330 | #define FAILED 0x2003 | ||
331 | #define QUEUED 0x2004 | ||
332 | #define SOFT_ERROR 0x2005 | ||
333 | #define ADD_TO_MLQUEUE 0x2006 | ||
334 | #define TIMEOUT_ERROR 0x2007 | ||
335 | |||
336 | /* | ||
337 | * Midlevel queue return values. | ||
338 | */ | ||
339 | #define SCSI_MLQUEUE_HOST_BUSY 0x1055 | ||
340 | #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056 | ||
341 | #define SCSI_MLQUEUE_EH_RETRY 0x1057 | ||
342 | |||
343 | /* | ||
344 | * Use these to separate status msg and our bytes | ||
345 | * | ||
346 | * These are set by: | ||
347 | * | ||
348 | * status byte = set from target device | ||
349 | * msg_byte = return status from host adapter itself. | ||
350 | * host_byte = set by low-level driver to indicate status. | ||
351 | * driver_byte = set by mid-level. | ||
352 | */ | ||
353 | #define status_byte(result) (((result) >> 1) & 0x7f) | ||
354 | #define msg_byte(result) (((result) >> 8) & 0xff) | ||
355 | #define host_byte(result) (((result) >> 16) & 0xff) | ||
356 | #define driver_byte(result) (((result) >> 24) & 0xff) | ||
357 | #define suggestion(result) (driver_byte(result) & SUGGEST_MASK) | ||
358 | |||
359 | #define sense_class(sense) (((sense) >> 4) & 0x7) | ||
360 | #define sense_error(sense) ((sense) & 0xf) | ||
361 | #define sense_valid(sense) ((sense) & 0x80); | ||
362 | |||
363 | |||
364 | #define IDENTIFY_BASE 0x80 | ||
365 | #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\ | ||
366 | ((can_disconnect) ? 0x40 : 0) |\ | ||
367 | ((lun) & 0x07)) | ||
368 | |||
369 | /* | ||
370 | * struct scsi_device::scsi_level values. For SCSI devices other than those | ||
371 | * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1) | ||
372 | * where "resp" is a byte array of the response to an INQUIRY. The scsi_level | ||
373 | * variable is visible to the user via sysfs. | ||
374 | */ | ||
375 | |||
376 | #define SCSI_UNKNOWN 0 | ||
377 | #define SCSI_1 1 | ||
378 | #define SCSI_1_CCS 2 | ||
379 | #define SCSI_2 3 | ||
380 | #define SCSI_3 4 /* SPC */ | ||
381 | #define SCSI_SPC_2 5 | ||
382 | #define SCSI_SPC_3 6 | ||
383 | |||
384 | /* | ||
385 | * INQ PERIPHERAL QUALIFIERS | ||
386 | */ | ||
387 | #define SCSI_INQ_PQ_CON 0x00 | ||
388 | #define SCSI_INQ_PQ_NOT_CON 0x01 | ||
389 | #define SCSI_INQ_PQ_NOT_CAP 0x03 | ||
390 | |||
391 | |||
392 | /* | ||
393 | * Here are some scsi specific ioctl commands which are sometimes useful. | ||
394 | * | ||
395 | * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395 | ||
396 | */ | ||
397 | |||
398 | /* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */ | ||
399 | #define SCSI_IOCTL_GET_IDLUN 0x5382 | ||
400 | |||
401 | /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */ | ||
402 | |||
403 | /* Used to obtain the host number of a device. */ | ||
404 | #define SCSI_IOCTL_PROBE_HOST 0x5385 | ||
405 | |||
406 | /* Used to obtain the bus number for a device */ | ||
407 | #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 | ||
408 | |||
409 | /* Used to obtain the PCI location of a device */ | ||
410 | #define SCSI_IOCTL_GET_PCI 0x5387 | ||
411 | |||
412 | #endif /* _SCSI_SCSI_H */ | ||
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h new file mode 100644 index 000000000000..9d9871c28abd --- /dev/null +++ b/include/scsi/scsi_cmnd.h | |||
@@ -0,0 +1,165 @@ | |||
1 | #ifndef _SCSI_SCSI_CMND_H | ||
2 | #define _SCSI_SCSI_CMND_H | ||
3 | |||
4 | #include <linux/dma-mapping.h> | ||
5 | #include <linux/list.h> | ||
6 | #include <linux/types.h> | ||
7 | |||
8 | struct request; | ||
9 | struct scatterlist; | ||
10 | struct scsi_device; | ||
11 | struct scsi_request; | ||
12 | |||
13 | |||
14 | /* embedded in scsi_cmnd */ | ||
15 | struct scsi_pointer { | ||
16 | char *ptr; /* data pointer */ | ||
17 | int this_residual; /* left in this buffer */ | ||
18 | struct scatterlist *buffer; /* which buffer */ | ||
19 | int buffers_residual; /* how many buffers left */ | ||
20 | |||
21 | dma_addr_t dma_handle; | ||
22 | |||
23 | volatile int Status; | ||
24 | volatile int Message; | ||
25 | volatile int have_data_in; | ||
26 | volatile int sent_command; | ||
27 | volatile int phase; | ||
28 | }; | ||
29 | |||
30 | struct scsi_cmnd { | ||
31 | int sc_magic; | ||
32 | |||
33 | struct scsi_device *device; | ||
34 | unsigned short state; | ||
35 | unsigned short owner; | ||
36 | struct scsi_request *sc_request; | ||
37 | |||
38 | struct list_head list; /* scsi_cmnd participates in queue lists */ | ||
39 | |||
40 | struct list_head eh_entry; /* entry for the host eh_cmd_q */ | ||
41 | int eh_state; /* Used for state tracking in error handlr */ | ||
42 | int eh_eflags; /* Used by error handlr */ | ||
43 | void (*done) (struct scsi_cmnd *); /* Mid-level done function */ | ||
44 | |||
45 | /* | ||
46 | * A SCSI Command is assigned a nonzero serial_number when internal_cmnd | ||
47 | * passes it to the driver's queue command function. The serial_number | ||
48 | * is cleared when scsi_done is entered indicating that the command has | ||
49 | * been completed. If a timeout occurs, the serial number at the moment | ||
50 | * of timeout is copied into serial_number_at_timeout. By subsequently | ||
51 | * comparing the serial_number and serial_number_at_timeout fields | ||
52 | * during abort or reset processing, we can detect whether the command | ||
53 | * has already completed. This also detects cases where the command has | ||
54 | * completed and the SCSI Command structure has already being reused | ||
55 | * for another command, so that we can avoid incorrectly aborting or | ||
56 | * resetting the new command. | ||
57 | * The serial number is only unique per host. | ||
58 | */ | ||
59 | unsigned long serial_number; | ||
60 | unsigned long serial_number_at_timeout; | ||
61 | |||
62 | int retries; | ||
63 | int allowed; | ||
64 | int timeout_per_command; | ||
65 | int timeout_total; | ||
66 | int timeout; | ||
67 | |||
68 | /* | ||
69 | * We handle the timeout differently if it happens when a reset, | ||
70 | * abort, etc are in process. | ||
71 | */ | ||
72 | unsigned volatile char internal_timeout; | ||
73 | |||
74 | unsigned char cmd_len; | ||
75 | unsigned char old_cmd_len; | ||
76 | enum dma_data_direction sc_data_direction; | ||
77 | enum dma_data_direction sc_old_data_direction; | ||
78 | |||
79 | /* These elements define the operation we are about to perform */ | ||
80 | #define MAX_COMMAND_SIZE 16 | ||
81 | unsigned char cmnd[MAX_COMMAND_SIZE]; | ||
82 | unsigned request_bufflen; /* Actual request size */ | ||
83 | |||
84 | struct timer_list eh_timeout; /* Used to time out the command. */ | ||
85 | void *request_buffer; /* Actual requested buffer */ | ||
86 | |||
87 | /* These elements define the operation we ultimately want to perform */ | ||
88 | unsigned char data_cmnd[MAX_COMMAND_SIZE]; | ||
89 | unsigned short old_use_sg; /* We save use_sg here when requesting | ||
90 | * sense info */ | ||
91 | unsigned short use_sg; /* Number of pieces of scatter-gather */ | ||
92 | unsigned short sglist_len; /* size of malloc'd scatter-gather list */ | ||
93 | unsigned short abort_reason; /* If the mid-level code requests an | ||
94 | * abort, this is the reason. */ | ||
95 | unsigned bufflen; /* Size of data buffer */ | ||
96 | void *buffer; /* Data buffer */ | ||
97 | |||
98 | unsigned underflow; /* Return error if less than | ||
99 | this amount is transferred */ | ||
100 | unsigned old_underflow; /* save underflow here when reusing the | ||
101 | * command for error handling */ | ||
102 | |||
103 | unsigned transfersize; /* How much we are guaranteed to | ||
104 | transfer with each SCSI transfer | ||
105 | (ie, between disconnect / | ||
106 | reconnects. Probably == sector | ||
107 | size */ | ||
108 | |||
109 | int resid; /* Number of bytes requested to be | ||
110 | transferred less actual number | ||
111 | transferred (0 if not supported) */ | ||
112 | |||
113 | struct request *request; /* The command we are | ||
114 | working on */ | ||
115 | |||
116 | #define SCSI_SENSE_BUFFERSIZE 96 | ||
117 | unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE | ||
118 | * when CHECK CONDITION is | ||
119 | * received on original command | ||
120 | * (auto-sense) */ | ||
121 | |||
122 | /* Low-level done function - can be used by low-level driver to point | ||
123 | * to completion function. Not used by mid/upper level code. */ | ||
124 | void (*scsi_done) (struct scsi_cmnd *); | ||
125 | |||
126 | /* | ||
127 | * The following fields can be written to by the host specific code. | ||
128 | * Everything else should be left alone. | ||
129 | */ | ||
130 | struct scsi_pointer SCp; /* Scratchpad used by some host adapters */ | ||
131 | |||
132 | unsigned char *host_scribble; /* The host adapter is allowed to | ||
133 | * call scsi_malloc and get some memory | ||
134 | * and hang it here. The host adapter | ||
135 | * is also expected to call scsi_free | ||
136 | * to release this memory. (The memory | ||
137 | * obtained by scsi_malloc is guaranteed | ||
138 | * to be at an address < 16Mb). */ | ||
139 | |||
140 | int result; /* Status code from lower level driver */ | ||
141 | |||
142 | unsigned char tag; /* SCSI-II queued command tag */ | ||
143 | unsigned long pid; /* Process ID, starts at 0. Unique per host. */ | ||
144 | }; | ||
145 | |||
146 | /* | ||
147 | * These are the values that scsi_cmd->state can take. | ||
148 | */ | ||
149 | #define SCSI_STATE_TIMEOUT 0x1000 | ||
150 | #define SCSI_STATE_FINISHED 0x1001 | ||
151 | #define SCSI_STATE_FAILED 0x1002 | ||
152 | #define SCSI_STATE_QUEUED 0x1003 | ||
153 | #define SCSI_STATE_UNUSED 0x1006 | ||
154 | #define SCSI_STATE_DISCONNECTING 0x1008 | ||
155 | #define SCSI_STATE_INITIALIZING 0x1009 | ||
156 | #define SCSI_STATE_BHQUEUE 0x100a | ||
157 | #define SCSI_STATE_MLQUEUE 0x100b | ||
158 | |||
159 | |||
160 | extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, int); | ||
161 | extern void scsi_put_command(struct scsi_cmnd *); | ||
162 | extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int); | ||
163 | extern void scsi_finish_command(struct scsi_cmnd *cmd); | ||
164 | |||
165 | #endif /* _SCSI_SCSI_CMND_H */ | ||
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h new file mode 100644 index 000000000000..12e90934a7a8 --- /dev/null +++ b/include/scsi/scsi_dbg.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef _SCSI_SCSI_DBG_H | ||
2 | #define _SCSI_SCSI_DBG_H | ||
3 | |||
4 | struct scsi_cmnd; | ||
5 | struct scsi_request; | ||
6 | |||
7 | extern void scsi_print_command(struct scsi_cmnd *); | ||
8 | extern void __scsi_print_command(unsigned char *); | ||
9 | extern void scsi_print_sense(const char *, struct scsi_cmnd *); | ||
10 | extern void scsi_print_req_sense(const char *, struct scsi_request *); | ||
11 | extern void __scsi_print_sense(const char *name, | ||
12 | const unsigned char *sense_buffer, | ||
13 | int sense_len); | ||
14 | extern void scsi_print_driverbyte(int); | ||
15 | extern void scsi_print_hostbyte(int); | ||
16 | extern void scsi_print_status(unsigned char); | ||
17 | extern int scsi_print_msg(const unsigned char *); | ||
18 | extern const char *scsi_sense_key_string(unsigned char); | ||
19 | extern const char *scsi_extd_sense_format(unsigned char, unsigned char); | ||
20 | |||
21 | #endif /* _SCSI_SCSI_DBG_H */ | ||
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h new file mode 100644 index 000000000000..07d974051b0c --- /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 | |||
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 | 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 | |||
38 | struct 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 | */ | ||
146 | struct 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) | ||
160 | static 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 | |||
167 | extern 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) | ||
171 | extern void scsi_remove_device(struct scsi_device *); | ||
172 | extern int scsi_device_cancel(struct scsi_device *, int); | ||
173 | |||
174 | extern int scsi_device_get(struct scsi_device *); | ||
175 | extern void scsi_device_put(struct scsi_device *); | ||
176 | extern struct scsi_device *scsi_device_lookup(struct Scsi_Host *, | ||
177 | uint, uint, uint); | ||
178 | extern struct scsi_device *__scsi_device_lookup(struct Scsi_Host *, | ||
179 | uint, uint, uint); | ||
180 | extern struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *, | ||
181 | uint); | ||
182 | extern struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *, | ||
183 | uint); | ||
184 | extern 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 */ | ||
188 | extern 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 | |||
221 | extern void scsi_adjust_queue_depth(struct scsi_device *, int, int); | ||
222 | extern int scsi_track_queue_full(struct scsi_device *, int); | ||
223 | |||
224 | extern int scsi_set_medium_removal(struct scsi_device *, char); | ||
225 | |||
226 | extern 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); | ||
229 | extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout, | ||
230 | int retries); | ||
231 | extern int scsi_device_set_state(struct scsi_device *sdev, | ||
232 | enum scsi_device_state state); | ||
233 | extern int scsi_device_quiesce(struct scsi_device *sdev); | ||
234 | extern void scsi_device_resume(struct scsi_device *sdev); | ||
235 | extern void scsi_target_quiesce(struct scsi_target *); | ||
236 | extern void scsi_target_resume(struct scsi_target *); | ||
237 | extern void scsi_scan_target(struct device *parent, unsigned int channel, | ||
238 | unsigned int id, unsigned int lun, int rescan); | ||
239 | extern void scsi_target_reap(struct scsi_target *); | ||
240 | extern void scsi_target_block(struct device *); | ||
241 | extern void scsi_target_unblock(struct device *); | ||
242 | extern void scsi_remove_target(struct device *); | ||
243 | extern const char *scsi_device_state_name(enum scsi_device_state); | ||
244 | extern int scsi_is_sdev_device(const struct device *); | ||
245 | extern int scsi_is_target_device(const struct device *); | ||
246 | static 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 */ | ||
252 | static inline int scsi_device_sync(struct scsi_device *sdev) | ||
253 | { | ||
254 | return sdev->sdtr; | ||
255 | } | ||
256 | static inline int scsi_device_wide(struct scsi_device *sdev) | ||
257 | { | ||
258 | return sdev->wdtr; | ||
259 | } | ||
260 | static inline int scsi_device_dt(struct scsi_device *sdev) | ||
261 | { | ||
262 | return sdev->ppr; | ||
263 | } | ||
264 | static 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 | } | ||
270 | static 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 | } | ||
276 | static 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 */ | ||
diff --git a/include/scsi/scsi_devinfo.h b/include/scsi/scsi_devinfo.h new file mode 100644 index 000000000000..174101b2069b --- /dev/null +++ b/include/scsi/scsi_devinfo.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef _SCSI_SCSI_DEVINFO_H | ||
2 | #define _SCSI_SCSI_DEVINFO_H | ||
3 | /* | ||
4 | * Flags for SCSI devices that need special treatment | ||
5 | */ | ||
6 | #define BLIST_NOLUN 0x001 /* Only scan LUN 0 */ | ||
7 | #define BLIST_FORCELUN 0x002 /* Known to have LUNs, force scanning, | ||
8 | deprecated: Use max_luns=N */ | ||
9 | #define BLIST_BORKEN 0x004 /* Flag for broken handshaking */ | ||
10 | #define BLIST_KEY 0x008 /* unlock by special command */ | ||
11 | #define BLIST_SINGLELUN 0x010 /* Do not use LUNs in parallel */ | ||
12 | #define BLIST_NOTQ 0x020 /* Buggy Tagged Command Queuing */ | ||
13 | #define BLIST_SPARSELUN 0x040 /* Non consecutive LUN numbering */ | ||
14 | #define BLIST_MAX5LUN 0x080 /* Avoid LUNS >= 5 */ | ||
15 | #define BLIST_ISROM 0x100 /* Treat as (removable) CD-ROM */ | ||
16 | #define BLIST_LARGELUN 0x200 /* LUNs past 7 on a SCSI-2 device */ | ||
17 | #define BLIST_INQUIRY_36 0x400 /* override additional length field */ | ||
18 | #define BLIST_INQUIRY_58 0x800 /* ... for broken inquiry responses */ | ||
19 | #define BLIST_NOSTARTONADD 0x1000 /* do not do automatic start on add */ | ||
20 | #define BLIST_MS_SKIP_PAGE_08 0x2000 /* do not send ms page 0x08 */ | ||
21 | #define BLIST_MS_SKIP_PAGE_3F 0x4000 /* do not send ms page 0x3f */ | ||
22 | #define BLIST_USE_10_BYTE_MS 0x8000 /* use 10 byte ms before 6 byte ms */ | ||
23 | #define BLIST_MS_192_BYTES_FOR_3F 0x10000 /* 192 byte ms page 0x3f request */ | ||
24 | #define BLIST_REPORTLUN2 0x20000 /* try REPORT_LUNS even for SCSI-2 devs | ||
25 | (if HBA supports more than 8 LUNs) */ | ||
26 | #define BLIST_NOREPORTLUN 0x40000 /* don't try REPORT_LUNS scan (SCSI-3 devs) */ | ||
27 | #define BLIST_NOT_LOCKABLE 0x80000 /* don't use PREVENT-ALLOW commands */ | ||
28 | #define BLIST_NO_ULD_ATTACH 0x100000 /* device is actually for RAID config */ | ||
29 | #define BLIST_SELECT_NO_ATN 0x200000 /* select without ATN */ | ||
30 | #define BLIST_RETRY_HWERROR 0x400000 /* retry HARDWARE_ERROR */ | ||
31 | #endif | ||
diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h new file mode 100644 index 000000000000..850dfa877fda --- /dev/null +++ b/include/scsi/scsi_driver.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef _SCSI_SCSI_DRIVER_H | ||
2 | #define _SCSI_SCSI_DRIVER_H | ||
3 | |||
4 | #include <linux/device.h> | ||
5 | |||
6 | struct module; | ||
7 | struct scsi_cmnd; | ||
8 | |||
9 | |||
10 | struct scsi_driver { | ||
11 | struct module *owner; | ||
12 | struct device_driver gendrv; | ||
13 | |||
14 | int (*init_command)(struct scsi_cmnd *); | ||
15 | void (*rescan)(struct device *); | ||
16 | int (*issue_flush)(struct device *, sector_t *); | ||
17 | int (*prepare_flush)(struct request_queue *, struct request *); | ||
18 | void (*end_flush)(struct request_queue *, struct request *); | ||
19 | }; | ||
20 | #define to_scsi_driver(drv) \ | ||
21 | container_of((drv), struct scsi_driver, gendrv) | ||
22 | |||
23 | extern int scsi_register_driver(struct device_driver *); | ||
24 | #define scsi_unregister_driver(drv) \ | ||
25 | driver_unregister(drv); | ||
26 | |||
27 | extern int scsi_register_interface(struct class_interface *); | ||
28 | #define scsi_unregister_interface(intf) \ | ||
29 | class_interface_unregister(intf) | ||
30 | |||
31 | #endif /* _SCSI_SCSI_DRIVER_H */ | ||
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h new file mode 100644 index 000000000000..80557f879e3e --- /dev/null +++ b/include/scsi/scsi_eh.h | |||
@@ -0,0 +1,63 @@ | |||
1 | #ifndef _SCSI_SCSI_EH_H | ||
2 | #define _SCSI_SCSI_EH_H | ||
3 | |||
4 | struct scsi_cmnd; | ||
5 | struct scsi_device; | ||
6 | struct scsi_request; | ||
7 | struct Scsi_Host; | ||
8 | |||
9 | /* | ||
10 | * This is a slightly modified SCSI sense "descriptor" format header. | ||
11 | * The addition is to allow the 0x70 and 0x71 response codes. The idea | ||
12 | * is to place the salient data from either "fixed" or "descriptor" sense | ||
13 | * format into one structure to ease application processing. | ||
14 | * | ||
15 | * The original sense buffer should be kept around for those cases | ||
16 | * in which more information is required (e.g. the LBA of a MEDIUM ERROR). | ||
17 | */ | ||
18 | struct scsi_sense_hdr { /* See SPC-3 section 4.5 */ | ||
19 | u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */ | ||
20 | u8 sense_key; | ||
21 | u8 asc; | ||
22 | u8 ascq; | ||
23 | u8 byte4; | ||
24 | u8 byte5; | ||
25 | u8 byte6; | ||
26 | u8 additional_length; /* always 0 for fixed sense format */ | ||
27 | }; | ||
28 | |||
29 | |||
30 | extern void scsi_add_timer(struct scsi_cmnd *, int, | ||
31 | void (*)(struct scsi_cmnd *)); | ||
32 | extern int scsi_delete_timer(struct scsi_cmnd *); | ||
33 | extern void scsi_report_bus_reset(struct Scsi_Host *, int); | ||
34 | extern void scsi_report_device_reset(struct Scsi_Host *, int, int); | ||
35 | extern int scsi_block_when_processing_errors(struct scsi_device *); | ||
36 | extern int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, | ||
37 | struct scsi_sense_hdr *sshdr); | ||
38 | extern int scsi_request_normalize_sense(struct scsi_request *sreq, | ||
39 | struct scsi_sense_hdr *sshdr); | ||
40 | extern int scsi_command_normalize_sense(struct scsi_cmnd *cmd, | ||
41 | struct scsi_sense_hdr *sshdr); | ||
42 | |||
43 | static inline int scsi_sense_is_deferred(struct scsi_sense_hdr *sshdr) | ||
44 | { | ||
45 | return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1)); | ||
46 | } | ||
47 | |||
48 | extern const u8 * scsi_sense_desc_find(const u8 * sense_buffer, int sb_len, | ||
49 | int desc_type); | ||
50 | |||
51 | extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len, | ||
52 | u64 * info_out); | ||
53 | |||
54 | /* | ||
55 | * Reset request from external source | ||
56 | */ | ||
57 | #define SCSI_TRY_RESET_DEVICE 1 | ||
58 | #define SCSI_TRY_RESET_BUS 2 | ||
59 | #define SCSI_TRY_RESET_HOST 3 | ||
60 | |||
61 | extern int scsi_reset_provider(struct scsi_device *, int); | ||
62 | |||
63 | #endif /* _SCSI_SCSI_EH_H */ | ||
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h new file mode 100644 index 000000000000..27f2c4e8943a --- /dev/null +++ b/include/scsi/scsi_host.h | |||
@@ -0,0 +1,642 @@ | |||
1 | #ifndef _SCSI_SCSI_HOST_H | ||
2 | #define _SCSI_SCSI_HOST_H | ||
3 | |||
4 | #include <linux/device.h> | ||
5 | #include <linux/list.h> | ||
6 | #include <linux/types.h> | ||
7 | #include <linux/workqueue.h> | ||
8 | |||
9 | struct block_device; | ||
10 | struct module; | ||
11 | struct scsi_cmnd; | ||
12 | struct scsi_device; | ||
13 | struct Scsi_Host; | ||
14 | struct scsi_host_cmd_pool; | ||
15 | struct scsi_transport_template; | ||
16 | |||
17 | |||
18 | /* | ||
19 | * The various choices mean: | ||
20 | * NONE: Self evident. Host adapter is not capable of scatter-gather. | ||
21 | * ALL: Means that the host adapter module can do scatter-gather, | ||
22 | * and that there is no limit to the size of the table to which | ||
23 | * we scatter/gather data. | ||
24 | * Anything else: Indicates the maximum number of chains that can be | ||
25 | * used in one scatter-gather request. | ||
26 | */ | ||
27 | #define SG_NONE 0 | ||
28 | #define SG_ALL 0xff | ||
29 | |||
30 | |||
31 | #define DISABLE_CLUSTERING 0 | ||
32 | #define ENABLE_CLUSTERING 1 | ||
33 | |||
34 | enum scsi_eh_timer_return { | ||
35 | EH_NOT_HANDLED, | ||
36 | EH_HANDLED, | ||
37 | EH_RESET_TIMER, | ||
38 | }; | ||
39 | |||
40 | |||
41 | struct scsi_host_template { | ||
42 | struct module *module; | ||
43 | const char *name; | ||
44 | |||
45 | /* | ||
46 | * Used to initialize old-style drivers. For new-style drivers | ||
47 | * just perform all work in your module initialization function. | ||
48 | * | ||
49 | * Status: OBSOLETE | ||
50 | */ | ||
51 | int (* detect)(struct scsi_host_template *); | ||
52 | |||
53 | /* | ||
54 | * Used as unload callback for hosts with old-style drivers. | ||
55 | * | ||
56 | * Status: OBSOLETE | ||
57 | */ | ||
58 | int (* release)(struct Scsi_Host *); | ||
59 | |||
60 | /* | ||
61 | * The info function will return whatever useful information the | ||
62 | * developer sees fit. If not provided, then the name field will | ||
63 | * be used instead. | ||
64 | * | ||
65 | * Status: OPTIONAL | ||
66 | */ | ||
67 | const char *(* info)(struct Scsi_Host *); | ||
68 | |||
69 | /* | ||
70 | * Ioctl interface | ||
71 | * | ||
72 | * Status: OPTIONAL | ||
73 | */ | ||
74 | int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg); | ||
75 | |||
76 | |||
77 | #ifdef CONFIG_COMPAT | ||
78 | /* | ||
79 | * Compat handler. Handle 32bit ABI. | ||
80 | * When unknown ioctl is passed return -ENOIOCTLCMD. | ||
81 | * | ||
82 | * Status: OPTIONAL | ||
83 | */ | ||
84 | int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg); | ||
85 | #endif | ||
86 | |||
87 | /* | ||
88 | * The queuecommand function is used to queue up a scsi | ||
89 | * command block to the LLDD. When the driver finished | ||
90 | * processing the command the done callback is invoked. | ||
91 | * | ||
92 | * If queuecommand returns 0, then the HBA has accepted the | ||
93 | * command. The done() function must be called on the command | ||
94 | * when the driver has finished with it. (you may call done on the | ||
95 | * command before queuecommand returns, but in this case you | ||
96 | * *must* return 0 from queuecommand). | ||
97 | * | ||
98 | * Queuecommand may also reject the command, in which case it may | ||
99 | * not touch the command and must not call done() for it. | ||
100 | * | ||
101 | * There are two possible rejection returns: | ||
102 | * | ||
103 | * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but | ||
104 | * allow commands to other devices serviced by this host. | ||
105 | * | ||
106 | * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this | ||
107 | * host temporarily. | ||
108 | * | ||
109 | * For compatibility, any other non-zero return is treated the | ||
110 | * same as SCSI_MLQUEUE_HOST_BUSY. | ||
111 | * | ||
112 | * NOTE: "temporarily" means either until the next command for# | ||
113 | * this device/host completes, or a period of time determined by | ||
114 | * I/O pressure in the system if there are no other outstanding | ||
115 | * commands. | ||
116 | * | ||
117 | * STATUS: REQUIRED | ||
118 | */ | ||
119 | int (* queuecommand)(struct scsi_cmnd *, | ||
120 | void (*done)(struct scsi_cmnd *)); | ||
121 | |||
122 | /* | ||
123 | * This is an error handling strategy routine. You don't need to | ||
124 | * define one of these if you don't want to - there is a default | ||
125 | * routine that is present that should work in most cases. For those | ||
126 | * driver authors that have the inclination and ability to write their | ||
127 | * own strategy routine, this is where it is specified. Note - the | ||
128 | * strategy routine is *ALWAYS* run in the context of the kernel eh | ||
129 | * thread. Thus you are guaranteed to *NOT* be in an interrupt | ||
130 | * handler when you execute this, and you are also guaranteed to | ||
131 | * *NOT* have any other commands being queued while you are in the | ||
132 | * strategy routine. When you return from this function, operations | ||
133 | * return to normal. | ||
134 | * | ||
135 | * See scsi_error.c scsi_unjam_host for additional comments about | ||
136 | * what this function should and should not be attempting to do. | ||
137 | * | ||
138 | * Status: REQUIRED (at least one of them) | ||
139 | */ | ||
140 | int (* eh_strategy_handler)(struct Scsi_Host *); | ||
141 | int (* eh_abort_handler)(struct scsi_cmnd *); | ||
142 | int (* eh_device_reset_handler)(struct scsi_cmnd *); | ||
143 | int (* eh_bus_reset_handler)(struct scsi_cmnd *); | ||
144 | int (* eh_host_reset_handler)(struct scsi_cmnd *); | ||
145 | |||
146 | /* | ||
147 | * This is an optional routine to notify the host that the scsi | ||
148 | * timer just fired. The returns tell the timer routine what to | ||
149 | * do about this: | ||
150 | * | ||
151 | * EH_HANDLED: I fixed the error, please complete the command | ||
152 | * EH_RESET_TIMER: I need more time, reset the timer and | ||
153 | * begin counting again | ||
154 | * EH_NOT_HANDLED Begin normal error recovery | ||
155 | * | ||
156 | * Status: OPTIONAL | ||
157 | */ | ||
158 | enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *); | ||
159 | |||
160 | /* | ||
161 | * Before the mid layer attempts to scan for a new device where none | ||
162 | * currently exists, it will call this entry in your driver. Should | ||
163 | * your driver need to allocate any structs or perform any other init | ||
164 | * items in order to send commands to a currently unused target/lun | ||
165 | * combo, then this is where you can perform those allocations. This | ||
166 | * is specifically so that drivers won't have to perform any kind of | ||
167 | * "is this a new device" checks in their queuecommand routine, | ||
168 | * thereby making the hot path a bit quicker. | ||
169 | * | ||
170 | * Return values: 0 on success, non-0 on failure | ||
171 | * | ||
172 | * Deallocation: If we didn't find any devices at this ID, you will | ||
173 | * get an immediate call to slave_destroy(). If we find something | ||
174 | * here then you will get a call to slave_configure(), then the | ||
175 | * device will be used for however long it is kept around, then when | ||
176 | * the device is removed from the system (or * possibly at reboot | ||
177 | * time), you will then get a call to slave_destroy(). This is | ||
178 | * assuming you implement slave_configure and slave_destroy. | ||
179 | * However, if you allocate memory and hang it off the device struct, | ||
180 | * then you must implement the slave_destroy() routine at a minimum | ||
181 | * in order to avoid leaking memory | ||
182 | * each time a device is tore down. | ||
183 | * | ||
184 | * Status: OPTIONAL | ||
185 | */ | ||
186 | int (* slave_alloc)(struct scsi_device *); | ||
187 | |||
188 | /* | ||
189 | * Once the device has responded to an INQUIRY and we know the | ||
190 | * device is online, we call into the low level driver with the | ||
191 | * struct scsi_device *. If the low level device driver implements | ||
192 | * this function, it *must* perform the task of setting the queue | ||
193 | * depth on the device. All other tasks are optional and depend | ||
194 | * on what the driver supports and various implementation details. | ||
195 | * | ||
196 | * Things currently recommended to be handled at this time include: | ||
197 | * | ||
198 | * 1. Setting the device queue depth. Proper setting of this is | ||
199 | * described in the comments for scsi_adjust_queue_depth. | ||
200 | * 2. Determining if the device supports the various synchronous | ||
201 | * negotiation protocols. The device struct will already have | ||
202 | * responded to INQUIRY and the results of the standard items | ||
203 | * will have been shoved into the various device flag bits, eg. | ||
204 | * device->sdtr will be true if the device supports SDTR messages. | ||
205 | * 3. Allocating command structs that the device will need. | ||
206 | * 4. Setting the default timeout on this device (if needed). | ||
207 | * 5. Anything else the low level driver might want to do on a device | ||
208 | * specific setup basis... | ||
209 | * 6. Return 0 on success, non-0 on error. The device will be marked | ||
210 | * as offline on error so that no access will occur. If you return | ||
211 | * non-0, your slave_destroy routine will never get called for this | ||
212 | * device, so don't leave any loose memory hanging around, clean | ||
213 | * up after yourself before returning non-0 | ||
214 | * | ||
215 | * Status: OPTIONAL | ||
216 | */ | ||
217 | int (* slave_configure)(struct scsi_device *); | ||
218 | |||
219 | /* | ||
220 | * Immediately prior to deallocating the device and after all activity | ||
221 | * has ceased the mid layer calls this point so that the low level | ||
222 | * driver may completely detach itself from the scsi device and vice | ||
223 | * versa. The low level driver is responsible for freeing any memory | ||
224 | * it allocated in the slave_alloc or slave_configure calls. | ||
225 | * | ||
226 | * Status: OPTIONAL | ||
227 | */ | ||
228 | void (* slave_destroy)(struct scsi_device *); | ||
229 | |||
230 | /* | ||
231 | * fill in this function to allow the queue depth of this host | ||
232 | * to be changeable (on a per device basis). returns either | ||
233 | * the current queue depth setting (may be different from what | ||
234 | * was passed in) or an error. An error should only be | ||
235 | * returned if the requested depth is legal but the driver was | ||
236 | * unable to set it. If the requested depth is illegal, the | ||
237 | * driver should set and return the closest legal queue depth. | ||
238 | * | ||
239 | */ | ||
240 | int (* change_queue_depth)(struct scsi_device *, int); | ||
241 | |||
242 | /* | ||
243 | * fill in this function to allow the changing of tag types | ||
244 | * (this also allows the enabling/disabling of tag command | ||
245 | * queueing). An error should only be returned if something | ||
246 | * went wrong in the driver while trying to set the tag type. | ||
247 | * If the driver doesn't support the requested tag type, then | ||
248 | * it should set the closest type it does support without | ||
249 | * returning an error. Returns the actual tag type set. | ||
250 | */ | ||
251 | int (* change_queue_type)(struct scsi_device *, int); | ||
252 | |||
253 | /* | ||
254 | * This function determines the bios parameters for a given | ||
255 | * harddisk. These tend to be numbers that are made up by | ||
256 | * the host adapter. Parameters: | ||
257 | * size, device, list (heads, sectors, cylinders) | ||
258 | * | ||
259 | * Status: OPTIONAL */ | ||
260 | int (* bios_param)(struct scsi_device *, struct block_device *, | ||
261 | sector_t, int []); | ||
262 | |||
263 | /* | ||
264 | * Can be used to export driver statistics and other infos to the | ||
265 | * world outside the kernel ie. userspace and it also provides an | ||
266 | * interface to feed the driver with information. | ||
267 | * | ||
268 | * Status: OBSOLETE | ||
269 | */ | ||
270 | int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int); | ||
271 | |||
272 | /* | ||
273 | * Name of proc directory | ||
274 | */ | ||
275 | char *proc_name; | ||
276 | |||
277 | /* | ||
278 | * Used to store the procfs directory if a driver implements the | ||
279 | * proc_info method. | ||
280 | */ | ||
281 | struct proc_dir_entry *proc_dir; | ||
282 | |||
283 | /* | ||
284 | * This determines if we will use a non-interrupt driven | ||
285 | * or an interrupt driven scheme, It is set to the maximum number | ||
286 | * of simultaneous commands a given host adapter will accept. | ||
287 | */ | ||
288 | int can_queue; | ||
289 | |||
290 | /* | ||
291 | * In many instances, especially where disconnect / reconnect are | ||
292 | * supported, our host also has an ID on the SCSI bus. If this is | ||
293 | * the case, then it must be reserved. Please set this_id to -1 if | ||
294 | * your setup is in single initiator mode, and the host lacks an | ||
295 | * ID. | ||
296 | */ | ||
297 | int this_id; | ||
298 | |||
299 | /* | ||
300 | * This determines the degree to which the host adapter is capable | ||
301 | * of scatter-gather. | ||
302 | */ | ||
303 | unsigned short sg_tablesize; | ||
304 | |||
305 | /* | ||
306 | * If the host adapter has limitations beside segment count | ||
307 | */ | ||
308 | unsigned short max_sectors; | ||
309 | |||
310 | /* | ||
311 | * dma scatter gather segment boundary limit. a segment crossing this | ||
312 | * boundary will be split in two. | ||
313 | */ | ||
314 | unsigned long dma_boundary; | ||
315 | |||
316 | /* | ||
317 | * This specifies "machine infinity" for host templates which don't | ||
318 | * limit the transfer size. Note this limit represents an absolute | ||
319 | * maximum, and may be over the transfer limits allowed for | ||
320 | * individual devices (e.g. 256 for SCSI-1) | ||
321 | */ | ||
322 | #define SCSI_DEFAULT_MAX_SECTORS 1024 | ||
323 | |||
324 | /* | ||
325 | * True if this host adapter can make good use of linked commands. | ||
326 | * This will allow more than one command to be queued to a given | ||
327 | * unit on a given host. Set this to the maximum number of command | ||
328 | * blocks to be provided for each device. Set this to 1 for one | ||
329 | * command block per lun, 2 for two, etc. Do not set this to 0. | ||
330 | * You should make sure that the host adapter will do the right thing | ||
331 | * before you try setting this above 1. | ||
332 | */ | ||
333 | short cmd_per_lun; | ||
334 | |||
335 | /* | ||
336 | * present contains counter indicating how many boards of this | ||
337 | * type were found when we did the scan. | ||
338 | */ | ||
339 | unsigned char present; | ||
340 | |||
341 | /* | ||
342 | * true if this host adapter uses unchecked DMA onto an ISA bus. | ||
343 | */ | ||
344 | unsigned unchecked_isa_dma:1; | ||
345 | |||
346 | /* | ||
347 | * true if this host adapter can make good use of clustering. | ||
348 | * I originally thought that if the tablesize was large that it | ||
349 | * was a waste of CPU cycles to prepare a cluster list, but | ||
350 | * it works out that the Buslogic is faster if you use a smaller | ||
351 | * number of segments (i.e. use clustering). I guess it is | ||
352 | * inefficient. | ||
353 | */ | ||
354 | unsigned use_clustering:1; | ||
355 | |||
356 | /* | ||
357 | * True for emulated SCSI host adapters (e.g. ATAPI) | ||
358 | */ | ||
359 | unsigned emulated:1; | ||
360 | |||
361 | /* | ||
362 | * True if the low-level driver performs its own reset-settle delays. | ||
363 | */ | ||
364 | unsigned skip_settle_delay:1; | ||
365 | |||
366 | /* | ||
367 | * ordered write support | ||
368 | */ | ||
369 | unsigned ordered_flush:1; | ||
370 | unsigned ordered_tag:1; | ||
371 | |||
372 | /* | ||
373 | * Countdown for host blocking with no commands outstanding | ||
374 | */ | ||
375 | unsigned int max_host_blocked; | ||
376 | |||
377 | /* | ||
378 | * Default value for the blocking. If the queue is empty, | ||
379 | * host_blocked counts down in the request_fn until it restarts | ||
380 | * host operations as zero is reached. | ||
381 | * | ||
382 | * FIXME: This should probably be a value in the template | ||
383 | */ | ||
384 | #define SCSI_DEFAULT_HOST_BLOCKED 7 | ||
385 | |||
386 | /* | ||
387 | * Pointer to the sysfs class properties for this host, NULL terminated. | ||
388 | */ | ||
389 | struct class_device_attribute **shost_attrs; | ||
390 | |||
391 | /* | ||
392 | * Pointer to the SCSI device properties for this host, NULL terminated. | ||
393 | */ | ||
394 | struct device_attribute **sdev_attrs; | ||
395 | |||
396 | /* | ||
397 | * List of hosts per template. | ||
398 | * | ||
399 | * This is only for use by scsi_module.c for legacy templates. | ||
400 | * For these access to it is synchronized implicitly by | ||
401 | * module_init/module_exit. | ||
402 | */ | ||
403 | struct list_head legacy_hosts; | ||
404 | }; | ||
405 | |||
406 | /* | ||
407 | * shost states | ||
408 | */ | ||
409 | enum { | ||
410 | SHOST_ADD, | ||
411 | SHOST_DEL, | ||
412 | SHOST_CANCEL, | ||
413 | SHOST_RECOVERY, | ||
414 | }; | ||
415 | |||
416 | struct Scsi_Host { | ||
417 | /* | ||
418 | * __devices is protected by the host_lock, but you should | ||
419 | * usually use scsi_device_lookup / shost_for_each_device | ||
420 | * to access it and don't care about locking yourself. | ||
421 | * In the rare case of beeing in irq context you can use | ||
422 | * their __ prefixed variants with the lock held. NEVER | ||
423 | * access this list directly from a driver. | ||
424 | */ | ||
425 | struct list_head __devices; | ||
426 | struct list_head __targets; | ||
427 | |||
428 | struct scsi_host_cmd_pool *cmd_pool; | ||
429 | spinlock_t free_list_lock; | ||
430 | struct list_head free_list; /* backup store of cmd structs */ | ||
431 | struct list_head starved_list; | ||
432 | |||
433 | spinlock_t default_lock; | ||
434 | spinlock_t *host_lock; | ||
435 | |||
436 | struct semaphore scan_mutex;/* serialize scanning activity */ | ||
437 | |||
438 | struct list_head eh_cmd_q; | ||
439 | struct task_struct * ehandler; /* Error recovery thread. */ | ||
440 | struct semaphore * eh_wait; /* The error recovery thread waits | ||
441 | on this. */ | ||
442 | struct completion * eh_notify; /* wait for eh to begin or end */ | ||
443 | struct semaphore * eh_action; /* Wait for specific actions on the | ||
444 | host. */ | ||
445 | unsigned int eh_active:1; /* Indicates the eh thread is awake and active if | ||
446 | this is true. */ | ||
447 | unsigned int eh_kill:1; /* set when killing the eh thread */ | ||
448 | wait_queue_head_t host_wait; | ||
449 | struct scsi_host_template *hostt; | ||
450 | struct scsi_transport_template *transportt; | ||
451 | volatile unsigned short host_busy; /* commands actually active on low-level */ | ||
452 | volatile unsigned short host_failed; /* commands that failed. */ | ||
453 | |||
454 | unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */ | ||
455 | int resetting; /* if set, it means that last_reset is a valid value */ | ||
456 | unsigned long last_reset; | ||
457 | |||
458 | /* | ||
459 | * These three parameters can be used to allow for wide scsi, | ||
460 | * and for host adapters that support multiple busses | ||
461 | * The first two should be set to 1 more than the actual max id | ||
462 | * or lun (i.e. 8 for normal systems). | ||
463 | */ | ||
464 | unsigned int max_id; | ||
465 | unsigned int max_lun; | ||
466 | unsigned int max_channel; | ||
467 | |||
468 | /* | ||
469 | * This is a unique identifier that must be assigned so that we | ||
470 | * have some way of identifying each detected host adapter properly | ||
471 | * and uniquely. For hosts that do not support more than one card | ||
472 | * in the system at one time, this does not need to be set. It is | ||
473 | * initialized to 0 in scsi_register. | ||
474 | */ | ||
475 | unsigned int unique_id; | ||
476 | |||
477 | /* | ||
478 | * The maximum length of SCSI commands that this host can accept. | ||
479 | * Probably 12 for most host adapters, but could be 16 for others. | ||
480 | * For drivers that don't set this field, a value of 12 is | ||
481 | * assumed. I am leaving this as a number rather than a bit | ||
482 | * because you never know what subsequent SCSI standards might do | ||
483 | * (i.e. could there be a 20 byte or a 24-byte command a few years | ||
484 | * down the road?). | ||
485 | */ | ||
486 | unsigned char max_cmd_len; | ||
487 | |||
488 | int this_id; | ||
489 | int can_queue; | ||
490 | short cmd_per_lun; | ||
491 | short unsigned int sg_tablesize; | ||
492 | short unsigned int max_sectors; | ||
493 | unsigned long dma_boundary; | ||
494 | /* | ||
495 | * Used to assign serial numbers to the cmds. | ||
496 | * Protected by the host lock. | ||
497 | */ | ||
498 | unsigned long cmd_serial_number, cmd_pid; | ||
499 | |||
500 | unsigned unchecked_isa_dma:1; | ||
501 | unsigned use_clustering:1; | ||
502 | unsigned use_blk_tcq:1; | ||
503 | |||
504 | /* | ||
505 | * Host has requested that no further requests come through for the | ||
506 | * time being. | ||
507 | */ | ||
508 | unsigned host_self_blocked:1; | ||
509 | |||
510 | /* | ||
511 | * Host uses correct SCSI ordering not PC ordering. The bit is | ||
512 | * set for the minority of drivers whose authors actually read | ||
513 | * the spec ;) | ||
514 | */ | ||
515 | unsigned reverse_ordering:1; | ||
516 | |||
517 | /* | ||
518 | * ordered write support | ||
519 | */ | ||
520 | unsigned ordered_flush:1; | ||
521 | unsigned ordered_tag:1; | ||
522 | |||
523 | /* | ||
524 | * Optional work queue to be utilized by the transport | ||
525 | */ | ||
526 | char work_q_name[KOBJ_NAME_LEN]; | ||
527 | struct workqueue_struct *work_q; | ||
528 | |||
529 | /* | ||
530 | * Host has rejected a command because it was busy. | ||
531 | */ | ||
532 | unsigned int host_blocked; | ||
533 | |||
534 | /* | ||
535 | * Value host_blocked counts down from | ||
536 | */ | ||
537 | unsigned int max_host_blocked; | ||
538 | |||
539 | /* legacy crap */ | ||
540 | unsigned long base; | ||
541 | unsigned long io_port; | ||
542 | unsigned char n_io_port; | ||
543 | unsigned char dma_channel; | ||
544 | unsigned int irq; | ||
545 | |||
546 | |||
547 | unsigned long shost_state; | ||
548 | |||
549 | /* ldm bits */ | ||
550 | struct device shost_gendev; | ||
551 | struct class_device shost_classdev; | ||
552 | |||
553 | /* | ||
554 | * List of hosts per template. | ||
555 | * | ||
556 | * This is only for use by scsi_module.c for legacy templates. | ||
557 | * For these access to it is synchronized implicitly by | ||
558 | * module_init/module_exit. | ||
559 | */ | ||
560 | struct list_head sht_legacy_list; | ||
561 | |||
562 | /* | ||
563 | * Points to the transport data (if any) which is allocated | ||
564 | * separately | ||
565 | */ | ||
566 | void *shost_data; | ||
567 | |||
568 | /* | ||
569 | * We should ensure that this is aligned, both for better performance | ||
570 | * and also because some compilers (m68k) don't automatically force | ||
571 | * alignment to a long boundary. | ||
572 | */ | ||
573 | unsigned long hostdata[0] /* Used for storage of host specific stuff */ | ||
574 | __attribute__ ((aligned (sizeof(unsigned long)))); | ||
575 | }; | ||
576 | |||
577 | #define class_to_shost(d) \ | ||
578 | container_of(d, struct Scsi_Host, shost_classdev) | ||
579 | |||
580 | int scsi_is_host_device(const struct device *); | ||
581 | |||
582 | static inline struct Scsi_Host *dev_to_shost(struct device *dev) | ||
583 | { | ||
584 | while (!scsi_is_host_device(dev)) { | ||
585 | if (!dev->parent) | ||
586 | return NULL; | ||
587 | dev = dev->parent; | ||
588 | } | ||
589 | return container_of(dev, struct Scsi_Host, shost_gendev); | ||
590 | } | ||
591 | |||
592 | extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *); | ||
593 | extern void scsi_flush_work(struct Scsi_Host *); | ||
594 | |||
595 | extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int); | ||
596 | extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *); | ||
597 | extern void scsi_scan_host(struct Scsi_Host *); | ||
598 | extern void scsi_scan_single_target(struct Scsi_Host *, unsigned int, | ||
599 | unsigned int); | ||
600 | extern void scsi_rescan_device(struct device *); | ||
601 | extern void scsi_remove_host(struct Scsi_Host *); | ||
602 | extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *); | ||
603 | extern void scsi_host_put(struct Scsi_Host *t); | ||
604 | extern struct Scsi_Host *scsi_host_lookup(unsigned short); | ||
605 | |||
606 | extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *); | ||
607 | |||
608 | static inline void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock) | ||
609 | { | ||
610 | shost->host_lock = lock; | ||
611 | } | ||
612 | |||
613 | static inline void scsi_set_device(struct Scsi_Host *shost, | ||
614 | struct device *dev) | ||
615 | { | ||
616 | shost->shost_gendev.parent = dev; | ||
617 | } | ||
618 | |||
619 | static inline struct device *scsi_get_device(struct Scsi_Host *shost) | ||
620 | { | ||
621 | return shost->shost_gendev.parent; | ||
622 | } | ||
623 | |||
624 | extern void scsi_unblock_requests(struct Scsi_Host *); | ||
625 | extern void scsi_block_requests(struct Scsi_Host *); | ||
626 | |||
627 | struct class_container; | ||
628 | /* | ||
629 | * These two functions are used to allocate and free a pseudo device | ||
630 | * which will connect to the host adapter itself rather than any | ||
631 | * physical device. You must deallocate when you are done with the | ||
632 | * thing. This physical pseudo-device isn't real and won't be available | ||
633 | * from any high-level drivers. | ||
634 | */ | ||
635 | extern void scsi_free_host_dev(struct scsi_device *); | ||
636 | extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *); | ||
637 | |||
638 | /* legacy interfaces */ | ||
639 | extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int); | ||
640 | extern void scsi_unregister(struct Scsi_Host *); | ||
641 | |||
642 | #endif /* _SCSI_SCSI_HOST_H */ | ||
diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h new file mode 100644 index 000000000000..d4be4d92d586 --- /dev/null +++ b/include/scsi/scsi_ioctl.h | |||
@@ -0,0 +1,50 @@ | |||
1 | #ifndef _SCSI_IOCTL_H | ||
2 | #define _SCSI_IOCTL_H | ||
3 | |||
4 | #define SCSI_IOCTL_SEND_COMMAND 1 | ||
5 | #define SCSI_IOCTL_TEST_UNIT_READY 2 | ||
6 | #define SCSI_IOCTL_BENCHMARK_COMMAND 3 | ||
7 | #define SCSI_IOCTL_SYNC 4 /* Request synchronous parameters */ | ||
8 | #define SCSI_IOCTL_START_UNIT 5 | ||
9 | #define SCSI_IOCTL_STOP_UNIT 6 | ||
10 | /* The door lock/unlock constants are compatible with Sun constants for | ||
11 | the cdrom */ | ||
12 | #define SCSI_IOCTL_DOORLOCK 0x5380 /* lock the eject mechanism */ | ||
13 | #define SCSI_IOCTL_DOORUNLOCK 0x5381 /* unlock the mechanism */ | ||
14 | |||
15 | #define SCSI_REMOVAL_PREVENT 1 | ||
16 | #define SCSI_REMOVAL_ALLOW 0 | ||
17 | |||
18 | #ifdef __KERNEL__ | ||
19 | |||
20 | struct scsi_device; | ||
21 | |||
22 | /* | ||
23 | * Structures used for scsi_ioctl et al. | ||
24 | */ | ||
25 | |||
26 | typedef struct scsi_ioctl_command { | ||
27 | unsigned int inlen; | ||
28 | unsigned int outlen; | ||
29 | unsigned char data[0]; | ||
30 | } Scsi_Ioctl_Command; | ||
31 | |||
32 | typedef struct scsi_idlun { | ||
33 | __u32 dev_id; | ||
34 | __u32 host_unique_id; | ||
35 | } Scsi_Idlun; | ||
36 | |||
37 | /* Fibre Channel WWN, port_id struct */ | ||
38 | typedef struct scsi_fctargaddress { | ||
39 | __u32 host_port_id; | ||
40 | unsigned char host_wwn[8]; // include NULL term. | ||
41 | } Scsi_FCTargAddress; | ||
42 | |||
43 | extern int scsi_ioctl(struct scsi_device *, int, void __user *); | ||
44 | extern int scsi_ioctl_send_command(struct scsi_device *, | ||
45 | struct scsi_ioctl_command __user *); | ||
46 | extern int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd, | ||
47 | void __user *arg, struct file *filp); | ||
48 | |||
49 | #endif /* __KERNEL__ */ | ||
50 | #endif /* _SCSI_IOCTL_H */ | ||
diff --git a/include/scsi/scsi_request.h b/include/scsi/scsi_request.h new file mode 100644 index 000000000000..98719407d554 --- /dev/null +++ b/include/scsi/scsi_request.h | |||
@@ -0,0 +1,73 @@ | |||
1 | #ifndef _SCSI_SCSI_REQUEST_H | ||
2 | #define _SCSI_SCSI_REQUEST_H | ||
3 | |||
4 | #include <scsi/scsi_cmnd.h> | ||
5 | |||
6 | struct request; | ||
7 | struct scsi_cmnd; | ||
8 | struct scsi_device; | ||
9 | struct Scsi_Host; | ||
10 | |||
11 | |||
12 | /* | ||
13 | * This is essentially a slimmed down version of Scsi_Cmnd. The point of | ||
14 | * having this is that requests that are injected into the queue as result | ||
15 | * of things like ioctls and character devices shouldn't be using a | ||
16 | * Scsi_Cmnd until such a time that the command is actually at the head | ||
17 | * of the queue and being sent to the driver. | ||
18 | */ | ||
19 | struct scsi_request { | ||
20 | int sr_magic; | ||
21 | int sr_result; /* Status code from lower level driver */ | ||
22 | unsigned char sr_sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE | ||
23 | * when CHECK CONDITION is | ||
24 | * received on original command | ||
25 | * (auto-sense) */ | ||
26 | |||
27 | struct Scsi_Host *sr_host; | ||
28 | struct scsi_device *sr_device; | ||
29 | struct scsi_cmnd *sr_command; | ||
30 | struct request *sr_request; /* A copy of the command we are | ||
31 | working on */ | ||
32 | unsigned sr_bufflen; /* Size of data buffer */ | ||
33 | void *sr_buffer; /* Data buffer */ | ||
34 | int sr_allowed; | ||
35 | enum dma_data_direction sr_data_direction; | ||
36 | unsigned char sr_cmd_len; | ||
37 | unsigned char sr_cmnd[MAX_COMMAND_SIZE]; | ||
38 | void (*sr_done) (struct scsi_cmnd *); /* Mid-level done function */ | ||
39 | int sr_timeout_per_command; | ||
40 | unsigned short sr_use_sg; /* Number of pieces of scatter-gather */ | ||
41 | unsigned short sr_sglist_len; /* size of malloc'd scatter-gather list */ | ||
42 | unsigned sr_underflow; /* Return error if less than | ||
43 | this amount is transferred */ | ||
44 | void *upper_private_data; /* reserved for owner (usually upper | ||
45 | level driver) of this request */ | ||
46 | }; | ||
47 | |||
48 | extern struct scsi_request *scsi_allocate_request(struct scsi_device *, int); | ||
49 | extern void scsi_release_request(struct scsi_request *); | ||
50 | extern void scsi_wait_req(struct scsi_request *, const void *cmnd, | ||
51 | void *buffer, unsigned bufflen, | ||
52 | int timeout, int retries); | ||
53 | extern void scsi_do_req(struct scsi_request *, const void *cmnd, | ||
54 | void *buffer, unsigned bufflen, | ||
55 | void (*done) (struct scsi_cmnd *), | ||
56 | int timeout, int retries); | ||
57 | |||
58 | struct scsi_mode_data { | ||
59 | __u32 length; | ||
60 | __u16 block_descriptor_length; | ||
61 | __u8 medium_type; | ||
62 | __u8 device_specific; | ||
63 | __u8 header_length; | ||
64 | __u8 longlba:1; | ||
65 | }; | ||
66 | |||
67 | extern int __scsi_mode_sense(struct scsi_request *SRpnt, int dbd, | ||
68 | int modepage, unsigned char *buffer, int len, | ||
69 | int timeout, int retries, | ||
70 | struct scsi_mode_data *data); | ||
71 | |||
72 | |||
73 | #endif /* _SCSI_SCSI_REQUEST_H */ | ||
diff --git a/include/scsi/scsi_tcq.h b/include/scsi/scsi_tcq.h new file mode 100644 index 000000000000..e47e36a4ef49 --- /dev/null +++ b/include/scsi/scsi_tcq.h | |||
@@ -0,0 +1,134 @@ | |||
1 | #ifndef _SCSI_SCSI_TCQ_H | ||
2 | #define _SCSI_SCSI_TCQ_H | ||
3 | |||
4 | #include <linux/blkdev.h> | ||
5 | #include <scsi/scsi_cmnd.h> | ||
6 | #include <scsi/scsi_device.h> | ||
7 | |||
8 | |||
9 | #define MSG_SIMPLE_TAG 0x20 | ||
10 | #define MSG_HEAD_TAG 0x21 | ||
11 | #define MSG_ORDERED_TAG 0x22 | ||
12 | |||
13 | #define SCSI_NO_TAG (-1) /* identify no tag in use */ | ||
14 | |||
15 | |||
16 | |||
17 | /** | ||
18 | * scsi_get_tag_type - get the type of tag the device supports | ||
19 | * @sdev: the scsi device | ||
20 | * | ||
21 | * Notes: | ||
22 | * If the drive only supports simple tags, returns MSG_SIMPLE_TAG | ||
23 | * if it supports all tag types, returns MSG_ORDERED_TAG. | ||
24 | */ | ||
25 | static inline int scsi_get_tag_type(struct scsi_device *sdev) | ||
26 | { | ||
27 | if (!sdev->tagged_supported) | ||
28 | return 0; | ||
29 | if (sdev->ordered_tags) | ||
30 | return MSG_ORDERED_TAG; | ||
31 | if (sdev->simple_tags) | ||
32 | return MSG_SIMPLE_TAG; | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag) | ||
37 | { | ||
38 | switch (tag) { | ||
39 | case MSG_ORDERED_TAG: | ||
40 | sdev->ordered_tags = 1; | ||
41 | /* fall through */ | ||
42 | case MSG_SIMPLE_TAG: | ||
43 | sdev->simple_tags = 1; | ||
44 | break; | ||
45 | case 0: | ||
46 | /* fall through */ | ||
47 | default: | ||
48 | sdev->ordered_tags = 0; | ||
49 | sdev->simple_tags = 0; | ||
50 | break; | ||
51 | } | ||
52 | } | ||
53 | /** | ||
54 | * scsi_activate_tcq - turn on tag command queueing | ||
55 | * @SDpnt: device to turn on TCQ for | ||
56 | * @depth: queue depth | ||
57 | * | ||
58 | * Notes: | ||
59 | * Eventually, I hope depth would be the maximum depth | ||
60 | * the device could cope with and the real queue depth | ||
61 | * would be adjustable from 0 to depth. | ||
62 | **/ | ||
63 | static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth) | ||
64 | { | ||
65 | if (!sdev->tagged_supported) | ||
66 | return; | ||
67 | |||
68 | if (!blk_queue_tagged(sdev->request_queue)) | ||
69 | blk_queue_init_tags(sdev->request_queue, depth, NULL); | ||
70 | |||
71 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * scsi_deactivate_tcq - turn off tag command queueing | ||
76 | * @SDpnt: device to turn off TCQ for | ||
77 | **/ | ||
78 | static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth) | ||
79 | { | ||
80 | if (blk_queue_tagged(sdev->request_queue)) | ||
81 | blk_queue_free_tags(sdev->request_queue); | ||
82 | scsi_adjust_queue_depth(sdev, 0, depth); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * scsi_populate_tag_msg - place a tag message in a buffer | ||
87 | * @SCpnt: pointer to the Scsi_Cmnd for the tag | ||
88 | * @msg: pointer to the area to place the tag | ||
89 | * | ||
90 | * Notes: | ||
91 | * designed to create the correct type of tag message for the | ||
92 | * particular request. Returns the size of the tag message. | ||
93 | * May return 0 if TCQ is disabled for this device. | ||
94 | **/ | ||
95 | static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg) | ||
96 | { | ||
97 | struct request *req = cmd->request; | ||
98 | struct scsi_device *sdev = cmd->device; | ||
99 | |||
100 | if (blk_rq_tagged(req)) { | ||
101 | if (sdev->ordered_tags && req->flags & REQ_HARDBARRIER) | ||
102 | *msg++ = MSG_ORDERED_TAG; | ||
103 | else | ||
104 | *msg++ = MSG_SIMPLE_TAG; | ||
105 | *msg++ = req->tag; | ||
106 | return 2; | ||
107 | } | ||
108 | |||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * scsi_find_tag - find a tagged command by device | ||
114 | * @SDpnt: pointer to the ScSI device | ||
115 | * @tag: the tag number | ||
116 | * | ||
117 | * Notes: | ||
118 | * Only works with tags allocated by the generic blk layer. | ||
119 | **/ | ||
120 | static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag) | ||
121 | { | ||
122 | |||
123 | struct request *req; | ||
124 | |||
125 | if (tag != SCSI_NO_TAG) { | ||
126 | req = blk_queue_find_tag(sdev->request_queue, tag); | ||
127 | return req ? (struct scsi_cmnd *)req->special : NULL; | ||
128 | } | ||
129 | |||
130 | /* single command, look in space */ | ||
131 | return sdev->current_cmnd; | ||
132 | } | ||
133 | |||
134 | #endif /* _SCSI_SCSI_TCQ_H */ | ||
diff --git a/include/scsi/scsi_transport.h b/include/scsi/scsi_transport.h new file mode 100644 index 000000000000..2dcee7a84752 --- /dev/null +++ b/include/scsi/scsi_transport.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | * Transport specific attributes. | ||
3 | * | ||
4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | #ifndef SCSI_TRANSPORT_H | ||
21 | #define SCSI_TRANSPORT_H | ||
22 | |||
23 | #include <linux/transport_class.h> | ||
24 | |||
25 | struct scsi_transport_template { | ||
26 | /* the attribute containers */ | ||
27 | struct transport_container host_attrs; | ||
28 | struct transport_container target_attrs; | ||
29 | struct transport_container device_attrs; | ||
30 | |||
31 | /* The size of the specific transport attribute structure (a | ||
32 | * space of this size will be left at the end of the | ||
33 | * scsi_* structure */ | ||
34 | int device_size; | ||
35 | int target_size; | ||
36 | int host_size; | ||
37 | |||
38 | /* | ||
39 | * True if the transport wants to use a host-based work-queue | ||
40 | */ | ||
41 | unsigned int create_work_queue : 1; | ||
42 | }; | ||
43 | |||
44 | #define transport_class_to_shost(tc) \ | ||
45 | dev_to_shost((tc)->dev) | ||
46 | |||
47 | |||
48 | #endif /* SCSI_TRANSPORT_H */ | ||
diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h new file mode 100644 index 000000000000..70ad16315a16 --- /dev/null +++ b/include/scsi/scsi_transport_fc.h | |||
@@ -0,0 +1,442 @@ | |||
1 | /* | ||
2 | * FiberChannel transport specific attributes exported to sysfs. | ||
3 | * | ||
4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | * ======== | ||
21 | * | ||
22 | * Copyright (C) 2004-2005 James Smart, Emulex Corporation | ||
23 | * Rewrite for host, target, device, and remote port attributes, | ||
24 | * statistics, and service functions... | ||
25 | * | ||
26 | */ | ||
27 | #ifndef SCSI_TRANSPORT_FC_H | ||
28 | #define SCSI_TRANSPORT_FC_H | ||
29 | |||
30 | #include <linux/config.h> | ||
31 | |||
32 | struct scsi_transport_template; | ||
33 | |||
34 | |||
35 | /* | ||
36 | * FC Port definitions - Following FC HBAAPI guidelines | ||
37 | * | ||
38 | * Note: Not all binary values for the different fields match HBAAPI. | ||
39 | * Instead, we use densely packed ordinal values or enums. | ||
40 | * We get away with this as we never present the actual binary values | ||
41 | * externally. For sysfs, we always present the string that describes | ||
42 | * the value. Thus, an admin doesn't need a magic HBAAPI decoder ring | ||
43 | * to understand the values. The HBAAPI user-space library is free to | ||
44 | * convert the strings into the HBAAPI-specified binary values. | ||
45 | * | ||
46 | * Note: Not all HBAAPI-defined values are contained in the definitions | ||
47 | * below. Those not appropriate to an fc_host (e.g. FCP initiator) have | ||
48 | * been removed. | ||
49 | */ | ||
50 | |||
51 | /* | ||
52 | * fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c | ||
53 | * (for the ascii descriptions). | ||
54 | */ | ||
55 | enum fc_port_type { | ||
56 | FC_PORTTYPE_UNKNOWN, | ||
57 | FC_PORTTYPE_OTHER, | ||
58 | FC_PORTTYPE_NOTPRESENT, | ||
59 | FC_PORTTYPE_NPORT, /* Attached to FPort */ | ||
60 | FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */ | ||
61 | FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */ | ||
62 | FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */ | ||
63 | }; | ||
64 | |||
65 | /* | ||
66 | * fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c | ||
67 | * (for the ascii descriptions). | ||
68 | */ | ||
69 | enum fc_port_state { | ||
70 | FC_PORTSTATE_UNKNOWN, | ||
71 | FC_PORTSTATE_NOTPRESENT, | ||
72 | FC_PORTSTATE_ONLINE, | ||
73 | FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */ | ||
74 | FC_PORTSTATE_BLOCKED, | ||
75 | FC_PORTSTATE_BYPASSED, | ||
76 | FC_PORTSTATE_DIAGNOSTICS, | ||
77 | FC_PORTSTATE_LINKDOWN, | ||
78 | FC_PORTSTATE_ERROR, | ||
79 | FC_PORTSTATE_LOOPBACK, | ||
80 | }; | ||
81 | |||
82 | |||
83 | /* | ||
84 | * FC Classes of Service | ||
85 | * Note: values are not enumerated, as they can be "or'd" together | ||
86 | * for reporting (e.g. report supported_classes). If you alter this list, | ||
87 | * you also need to alter scsi_transport_fc.c (for the ascii descriptions). | ||
88 | */ | ||
89 | #define FC_COS_UNSPECIFIED 0 | ||
90 | #define FC_COS_CLASS1 2 | ||
91 | #define FC_COS_CLASS2 4 | ||
92 | #define FC_COS_CLASS3 8 | ||
93 | #define FC_COS_CLASS4 0x10 | ||
94 | #define FC_COS_CLASS6 0x40 | ||
95 | |||
96 | /* | ||
97 | * FC Port Speeds | ||
98 | * Note: values are not enumerated, as they can be "or'd" together | ||
99 | * for reporting (e.g. report supported_speeds). If you alter this list, | ||
100 | * you also need to alter scsi_transport_fc.c (for the ascii descriptions). | ||
101 | */ | ||
102 | #define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver | ||
103 | incapable of reporting */ | ||
104 | #define FC_PORTSPEED_1GBIT 1 | ||
105 | #define FC_PORTSPEED_2GBIT 2 | ||
106 | #define FC_PORTSPEED_10GBIT 4 | ||
107 | #define FC_PORTSPEED_4GBIT 8 | ||
108 | #define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */ | ||
109 | |||
110 | /* | ||
111 | * fc_tgtid_binding_type: If you alter this, you also need to alter | ||
112 | * scsi_transport_fc.c (for the ascii descriptions). | ||
113 | */ | ||
114 | enum fc_tgtid_binding_type { | ||
115 | FC_TGTID_BIND_NONE, | ||
116 | FC_TGTID_BIND_BY_WWPN, | ||
117 | FC_TGTID_BIND_BY_WWNN, | ||
118 | FC_TGTID_BIND_BY_ID, | ||
119 | }; | ||
120 | |||
121 | /* | ||
122 | * FC Remote Port Roles | ||
123 | * Note: values are not enumerated, as they can be "or'd" together | ||
124 | * for reporting (e.g. report roles). If you alter this list, | ||
125 | * you also need to alter scsi_transport_fc.c (for the ascii descriptions). | ||
126 | */ | ||
127 | #define FC_RPORT_ROLE_UNKNOWN 0x00 | ||
128 | #define FC_RPORT_ROLE_FCP_TARGET 0x01 | ||
129 | #define FC_RPORT_ROLE_FCP_INITIATOR 0x02 | ||
130 | #define FC_RPORT_ROLE_IP_PORT 0x04 | ||
131 | |||
132 | |||
133 | /* | ||
134 | * fc_rport_identifiers: This set of data contains all elements | ||
135 | * to uniquely identify a remote FC port. The driver uses this data | ||
136 | * to report the existence of a remote FC port in the topology. Internally, | ||
137 | * the transport uses this data for attributes and to manage consistent | ||
138 | * target id bindings. | ||
139 | */ | ||
140 | struct fc_rport_identifiers { | ||
141 | u64 node_name; | ||
142 | u64 port_name; | ||
143 | u32 port_id; | ||
144 | u32 roles; | ||
145 | }; | ||
146 | |||
147 | /* Macro for use in defining Remote Port attributes */ | ||
148 | #define FC_RPORT_ATTR(_name,_mode,_show,_store) \ | ||
149 | struct class_device_attribute class_device_attr_rport_##_name = \ | ||
150 | __ATTR(_name,_mode,_show,_store) | ||
151 | |||
152 | |||
153 | /* | ||
154 | * FC Remote Port Attributes | ||
155 | * | ||
156 | * This structure exists for each remote FC port that a LLDD notifies | ||
157 | * the subsystem of. A remote FC port may or may not be a SCSI Target, | ||
158 | * also be a SCSI initiator, IP endpoint, etc. As such, the remote | ||
159 | * port is considered a separate entity, independent of "role" (such | ||
160 | * as scsi target). | ||
161 | * | ||
162 | * -- | ||
163 | * | ||
164 | * Attributes are based on HBAAPI V2.0 definitions. Only those | ||
165 | * attributes that are determinable by the local port (aka Host) | ||
166 | * are contained. | ||
167 | * | ||
168 | * Fixed attributes are not expected to change. The driver is | ||
169 | * expected to set these values after successfully calling | ||
170 | * fc_remote_port_add(). The transport fully manages all get functions | ||
171 | * w/o driver interaction. | ||
172 | * | ||
173 | * Dynamic attributes are expected to change. The driver participates | ||
174 | * in all get/set operations via functions provided by the driver. | ||
175 | * | ||
176 | * Private attributes are transport-managed values. They are fully | ||
177 | * managed by the transport w/o driver interaction. | ||
178 | */ | ||
179 | |||
180 | struct fc_rport { /* aka fc_starget_attrs */ | ||
181 | /* Fixed Attributes */ | ||
182 | u32 maxframe_size; | ||
183 | u32 supported_classes; | ||
184 | |||
185 | /* Dynamic Attributes */ | ||
186 | u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */ | ||
187 | |||
188 | /* Private (Transport-managed) Attributes */ | ||
189 | u64 node_name; | ||
190 | u64 port_name; | ||
191 | u32 port_id; | ||
192 | u32 roles; | ||
193 | enum fc_port_state port_state; /* Will only be ONLINE or UNKNOWN */ | ||
194 | u32 scsi_target_id; | ||
195 | |||
196 | /* exported data */ | ||
197 | void *dd_data; /* Used for driver-specific storage */ | ||
198 | |||
199 | /* internal data */ | ||
200 | unsigned int channel; | ||
201 | u32 number; | ||
202 | struct list_head peers; | ||
203 | struct device dev; | ||
204 | struct work_struct dev_loss_work; | ||
205 | struct work_struct scan_work; | ||
206 | } __attribute__((aligned(sizeof(unsigned long)))); | ||
207 | |||
208 | #define dev_to_rport(d) \ | ||
209 | container_of(d, struct fc_rport, dev) | ||
210 | #define transport_class_to_rport(classdev) \ | ||
211 | dev_to_rport(classdev->dev) | ||
212 | #define rport_to_shost(r) \ | ||
213 | dev_to_shost(r->dev.parent) | ||
214 | |||
215 | /* | ||
216 | * FC SCSI Target Attributes | ||
217 | * | ||
218 | * The SCSI Target is considered an extention of a remote port (as | ||
219 | * a remote port can be more than a SCSI Target). Within the scsi | ||
220 | * subsystem, we leave the Target as a separate entity. Doing so | ||
221 | * provides backward compatibility with prior FC transport api's, | ||
222 | * and lets remote ports be handled entirely within the FC transport | ||
223 | * and independently from the scsi subsystem. The drawback is that | ||
224 | * some data will be duplicated. | ||
225 | */ | ||
226 | |||
227 | struct fc_starget_attrs { /* aka fc_target_attrs */ | ||
228 | /* Dynamic Attributes */ | ||
229 | u64 node_name; | ||
230 | u64 port_name; | ||
231 | u32 port_id; | ||
232 | }; | ||
233 | |||
234 | #define fc_starget_node_name(x) \ | ||
235 | (((struct fc_starget_attrs *)&(x)->starget_data)->node_name) | ||
236 | #define fc_starget_port_name(x) \ | ||
237 | (((struct fc_starget_attrs *)&(x)->starget_data)->port_name) | ||
238 | #define fc_starget_port_id(x) \ | ||
239 | (((struct fc_starget_attrs *)&(x)->starget_data)->port_id) | ||
240 | |||
241 | #define starget_to_rport(s) \ | ||
242 | scsi_is_fc_rport(s->dev.parent) ? dev_to_rport(s->dev.parent) : NULL | ||
243 | |||
244 | |||
245 | /* | ||
246 | * FC Local Port (Host) Statistics | ||
247 | */ | ||
248 | |||
249 | /* FC Statistics - Following FC HBAAPI v2.0 guidelines */ | ||
250 | struct fc_host_statistics { | ||
251 | /* port statistics */ | ||
252 | u64 seconds_since_last_reset; | ||
253 | u64 tx_frames; | ||
254 | u64 tx_words; | ||
255 | u64 rx_frames; | ||
256 | u64 rx_words; | ||
257 | u64 lip_count; | ||
258 | u64 nos_count; | ||
259 | u64 error_frames; | ||
260 | u64 dumped_frames; | ||
261 | u64 link_failure_count; | ||
262 | u64 loss_of_sync_count; | ||
263 | u64 loss_of_signal_count; | ||
264 | u64 prim_seq_protocol_err_count; | ||
265 | u64 invalid_tx_word_count; | ||
266 | u64 invalid_crc_count; | ||
267 | |||
268 | /* fc4 statistics (only FCP supported currently) */ | ||
269 | u64 fcp_input_requests; | ||
270 | u64 fcp_output_requests; | ||
271 | u64 fcp_control_requests; | ||
272 | u64 fcp_input_megabytes; | ||
273 | u64 fcp_output_megabytes; | ||
274 | }; | ||
275 | |||
276 | |||
277 | /* | ||
278 | * FC Local Port (Host) Attributes | ||
279 | * | ||
280 | * Attributes are based on HBAAPI V2.0 definitions. | ||
281 | * Note: OSDeviceName is determined by user-space library | ||
282 | * | ||
283 | * Fixed attributes are not expected to change. The driver is | ||
284 | * expected to set these values after successfully calling scsi_add_host(). | ||
285 | * The transport fully manages all get functions w/o driver interaction. | ||
286 | * | ||
287 | * Dynamic attributes are expected to change. The driver participates | ||
288 | * in all get/set operations via functions provided by the driver. | ||
289 | * | ||
290 | * Private attributes are transport-managed values. They are fully | ||
291 | * managed by the transport w/o driver interaction. | ||
292 | */ | ||
293 | |||
294 | #define FC_FC4_LIST_SIZE 32 | ||
295 | #define FC_SYMBOLIC_NAME_SIZE 256 | ||
296 | #define FC_VERSION_STRING_SIZE 64 | ||
297 | #define FC_SERIAL_NUMBER_SIZE 80 | ||
298 | |||
299 | struct fc_host_attrs { | ||
300 | /* Fixed Attributes */ | ||
301 | u64 node_name; | ||
302 | u64 port_name; | ||
303 | u32 supported_classes; | ||
304 | u8 supported_fc4s[FC_FC4_LIST_SIZE]; | ||
305 | char symbolic_name[FC_SYMBOLIC_NAME_SIZE]; | ||
306 | u32 supported_speeds; | ||
307 | u32 maxframe_size; | ||
308 | char serial_number[FC_SERIAL_NUMBER_SIZE]; | ||
309 | |||
310 | /* Dynamic Attributes */ | ||
311 | u32 port_id; | ||
312 | enum fc_port_type port_type; | ||
313 | enum fc_port_state port_state; | ||
314 | u8 active_fc4s[FC_FC4_LIST_SIZE]; | ||
315 | u32 speed; | ||
316 | u64 fabric_name; | ||
317 | |||
318 | /* Private (Transport-managed) Attributes */ | ||
319 | enum fc_tgtid_binding_type tgtid_bind_type; | ||
320 | |||
321 | /* internal data */ | ||
322 | struct list_head rports; | ||
323 | struct list_head rport_bindings; | ||
324 | u32 next_rport_number; | ||
325 | u32 next_target_id; | ||
326 | }; | ||
327 | |||
328 | #define fc_host_node_name(x) \ | ||
329 | (((struct fc_host_attrs *)(x)->shost_data)->node_name) | ||
330 | #define fc_host_port_name(x) \ | ||
331 | (((struct fc_host_attrs *)(x)->shost_data)->port_name) | ||
332 | #define fc_host_supported_classes(x) \ | ||
333 | (((struct fc_host_attrs *)(x)->shost_data)->supported_classes) | ||
334 | #define fc_host_supported_fc4s(x) \ | ||
335 | (((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s) | ||
336 | #define fc_host_symbolic_name(x) \ | ||
337 | (((struct fc_host_attrs *)(x)->shost_data)->symbolic_name) | ||
338 | #define fc_host_supported_speeds(x) \ | ||
339 | (((struct fc_host_attrs *)(x)->shost_data)->supported_speeds) | ||
340 | #define fc_host_maxframe_size(x) \ | ||
341 | (((struct fc_host_attrs *)(x)->shost_data)->maxframe_size) | ||
342 | #define fc_host_serial_number(x) \ | ||
343 | (((struct fc_host_attrs *)(x)->shost_data)->serial_number) | ||
344 | #define fc_host_port_id(x) \ | ||
345 | (((struct fc_host_attrs *)(x)->shost_data)->port_id) | ||
346 | #define fc_host_port_type(x) \ | ||
347 | (((struct fc_host_attrs *)(x)->shost_data)->port_type) | ||
348 | #define fc_host_port_state(x) \ | ||
349 | (((struct fc_host_attrs *)(x)->shost_data)->port_state) | ||
350 | #define fc_host_active_fc4s(x) \ | ||
351 | (((struct fc_host_attrs *)(x)->shost_data)->active_fc4s) | ||
352 | #define fc_host_speed(x) \ | ||
353 | (((struct fc_host_attrs *)(x)->shost_data)->speed) | ||
354 | #define fc_host_fabric_name(x) \ | ||
355 | (((struct fc_host_attrs *)(x)->shost_data)->fabric_name) | ||
356 | #define fc_host_tgtid_bind_type(x) \ | ||
357 | (((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type) | ||
358 | #define fc_host_rports(x) \ | ||
359 | (((struct fc_host_attrs *)(x)->shost_data)->rports) | ||
360 | #define fc_host_rport_bindings(x) \ | ||
361 | (((struct fc_host_attrs *)(x)->shost_data)->rport_bindings) | ||
362 | #define fc_host_next_rport_number(x) \ | ||
363 | (((struct fc_host_attrs *)(x)->shost_data)->next_rport_number) | ||
364 | #define fc_host_next_target_id(x) \ | ||
365 | (((struct fc_host_attrs *)(x)->shost_data)->next_target_id) | ||
366 | |||
367 | |||
368 | /* The functions by which the transport class and the driver communicate */ | ||
369 | struct fc_function_template { | ||
370 | void (*get_rport_dev_loss_tmo)(struct fc_rport *); | ||
371 | void (*set_rport_dev_loss_tmo)(struct fc_rport *, u32); | ||
372 | |||
373 | void (*get_starget_node_name)(struct scsi_target *); | ||
374 | void (*get_starget_port_name)(struct scsi_target *); | ||
375 | void (*get_starget_port_id)(struct scsi_target *); | ||
376 | |||
377 | void (*get_host_port_id)(struct Scsi_Host *); | ||
378 | void (*get_host_port_type)(struct Scsi_Host *); | ||
379 | void (*get_host_port_state)(struct Scsi_Host *); | ||
380 | void (*get_host_active_fc4s)(struct Scsi_Host *); | ||
381 | void (*get_host_speed)(struct Scsi_Host *); | ||
382 | void (*get_host_fabric_name)(struct Scsi_Host *); | ||
383 | |||
384 | struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *); | ||
385 | void (*reset_fc_host_stats)(struct Scsi_Host *); | ||
386 | |||
387 | /* allocation lengths for host-specific data */ | ||
388 | u32 dd_fcrport_size; | ||
389 | |||
390 | /* | ||
391 | * The driver sets these to tell the transport class it | ||
392 | * wants the attributes displayed in sysfs. If the show_ flag | ||
393 | * is not set, the attribute will be private to the transport | ||
394 | * class | ||
395 | */ | ||
396 | |||
397 | /* remote port fixed attributes */ | ||
398 | unsigned long show_rport_maxframe_size:1; | ||
399 | unsigned long show_rport_supported_classes:1; | ||
400 | unsigned long show_rport_dev_loss_tmo:1; | ||
401 | |||
402 | /* | ||
403 | * target dynamic attributes | ||
404 | * These should all be "1" if the driver uses the remote port | ||
405 | * add/delete functions (so attributes reflect rport values). | ||
406 | */ | ||
407 | unsigned long show_starget_node_name:1; | ||
408 | unsigned long show_starget_port_name:1; | ||
409 | unsigned long show_starget_port_id:1; | ||
410 | |||
411 | /* host fixed attributes */ | ||
412 | unsigned long show_host_node_name:1; | ||
413 | unsigned long show_host_port_name:1; | ||
414 | unsigned long show_host_supported_classes:1; | ||
415 | unsigned long show_host_supported_fc4s:1; | ||
416 | unsigned long show_host_symbolic_name:1; | ||
417 | unsigned long show_host_supported_speeds:1; | ||
418 | unsigned long show_host_maxframe_size:1; | ||
419 | unsigned long show_host_serial_number:1; | ||
420 | /* host dynamic attributes */ | ||
421 | unsigned long show_host_port_id:1; | ||
422 | unsigned long show_host_port_type:1; | ||
423 | unsigned long show_host_port_state:1; | ||
424 | unsigned long show_host_active_fc4s:1; | ||
425 | unsigned long show_host_speed:1; | ||
426 | unsigned long show_host_fabric_name:1; | ||
427 | }; | ||
428 | |||
429 | |||
430 | struct scsi_transport_template *fc_attach_transport( | ||
431 | struct fc_function_template *); | ||
432 | void fc_release_transport(struct scsi_transport_template *); | ||
433 | void fc_remove_host(struct Scsi_Host *); | ||
434 | struct fc_rport *fc_remote_port_add(struct Scsi_Host *shost, | ||
435 | int channel, struct fc_rport_identifiers *ids); | ||
436 | void fc_remote_port_delete(struct fc_rport *rport); | ||
437 | void fc_remote_port_rolechg(struct fc_rport *rport, u32 roles); | ||
438 | int fc_remote_port_block(struct fc_rport *rport); | ||
439 | void fc_remote_port_unblock(struct fc_rport *rport); | ||
440 | int scsi_is_fc_rport(const struct device *); | ||
441 | |||
442 | #endif /* SCSI_TRANSPORT_FC_H */ | ||
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h new file mode 100644 index 000000000000..1b26a6c0aa2a --- /dev/null +++ b/include/scsi/scsi_transport_iscsi.h | |||
@@ -0,0 +1,178 @@ | |||
1 | /* | ||
2 | * iSCSI transport class definitions | ||
3 | * | ||
4 | * Copyright (C) IBM Corporation, 2004 | ||
5 | * Copyright (C) Mike Christie, 2004 | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | */ | ||
21 | #ifndef SCSI_TRANSPORT_ISCSI_H | ||
22 | #define SCSI_TRANSPORT_ISCSI_H | ||
23 | |||
24 | #include <linux/config.h> | ||
25 | #include <linux/in6.h> | ||
26 | #include <linux/in.h> | ||
27 | |||
28 | struct scsi_transport_template; | ||
29 | |||
30 | struct iscsi_class_session { | ||
31 | uint8_t isid[6]; | ||
32 | uint16_t tsih; | ||
33 | int header_digest; /* 1 CRC32, 0 None */ | ||
34 | int data_digest; /* 1 CRC32, 0 None */ | ||
35 | uint16_t tpgt; | ||
36 | union { | ||
37 | struct in6_addr sin6_addr; | ||
38 | struct in_addr sin_addr; | ||
39 | } u; | ||
40 | sa_family_t addr_type; /* must be AF_INET or AF_INET6 */ | ||
41 | uint16_t port; /* must be in network byte order */ | ||
42 | int initial_r2t; /* 1 Yes, 0 No */ | ||
43 | int immediate_data; /* 1 Yes, 0 No */ | ||
44 | uint32_t max_recv_data_segment_len; | ||
45 | uint32_t max_burst_len; | ||
46 | uint32_t first_burst_len; | ||
47 | uint16_t def_time2wait; | ||
48 | uint16_t def_time2retain; | ||
49 | uint16_t max_outstanding_r2t; | ||
50 | int data_pdu_in_order; /* 1 Yes, 0 No */ | ||
51 | int data_sequence_in_order; /* 1 Yes, 0 No */ | ||
52 | int erl; | ||
53 | }; | ||
54 | |||
55 | /* | ||
56 | * accessor macros | ||
57 | */ | ||
58 | #define iscsi_isid(x) \ | ||
59 | (((struct iscsi_class_session *)&(x)->starget_data)->isid) | ||
60 | #define iscsi_tsih(x) \ | ||
61 | (((struct iscsi_class_session *)&(x)->starget_data)->tsih) | ||
62 | #define iscsi_header_digest(x) \ | ||
63 | (((struct iscsi_class_session *)&(x)->starget_data)->header_digest) | ||
64 | #define iscsi_data_digest(x) \ | ||
65 | (((struct iscsi_class_session *)&(x)->starget_data)->data_digest) | ||
66 | #define iscsi_port(x) \ | ||
67 | (((struct iscsi_class_session *)&(x)->starget_data)->port) | ||
68 | #define iscsi_addr_type(x) \ | ||
69 | (((struct iscsi_class_session *)&(x)->starget_data)->addr_type) | ||
70 | #define iscsi_sin_addr(x) \ | ||
71 | (((struct iscsi_class_session *)&(x)->starget_data)->u.sin_addr) | ||
72 | #define iscsi_sin6_addr(x) \ | ||
73 | (((struct iscsi_class_session *)&(x)->starget_data)->u.sin6_addr) | ||
74 | #define iscsi_tpgt(x) \ | ||
75 | (((struct iscsi_class_session *)&(x)->starget_data)->tpgt) | ||
76 | #define iscsi_initial_r2t(x) \ | ||
77 | (((struct iscsi_class_session *)&(x)->starget_data)->initial_r2t) | ||
78 | #define iscsi_immediate_data(x) \ | ||
79 | (((struct iscsi_class_session *)&(x)->starget_data)->immediate_data) | ||
80 | #define iscsi_max_recv_data_segment_len(x) \ | ||
81 | (((struct iscsi_class_session *)&(x)->starget_data)->max_recv_data_segment_len) | ||
82 | #define iscsi_max_burst_len(x) \ | ||
83 | (((struct iscsi_class_session *)&(x)->starget_data)->max_burst_len) | ||
84 | #define iscsi_first_burst_len(x) \ | ||
85 | (((struct iscsi_class_session *)&(x)->starget_data)->first_burst_len) | ||
86 | #define iscsi_def_time2wait(x) \ | ||
87 | (((struct iscsi_class_session *)&(x)->starget_data)->def_time2wait) | ||
88 | #define iscsi_def_time2retain(x) \ | ||
89 | (((struct iscsi_class_session *)&(x)->starget_data)->def_time2retain) | ||
90 | #define iscsi_max_outstanding_r2t(x) \ | ||
91 | (((struct iscsi_class_session *)&(x)->starget_data)->max_outstanding_r2t) | ||
92 | #define iscsi_data_pdu_in_order(x) \ | ||
93 | (((struct iscsi_class_session *)&(x)->starget_data)->data_pdu_in_order) | ||
94 | #define iscsi_data_sequence_in_order(x) \ | ||
95 | (((struct iscsi_class_session *)&(x)->starget_data)->data_sequence_in_order) | ||
96 | #define iscsi_erl(x) \ | ||
97 | (((struct iscsi_class_session *)&(x)->starget_data)->erl) | ||
98 | |||
99 | /* | ||
100 | * The functions by which the transport class and the driver communicate | ||
101 | */ | ||
102 | struct iscsi_function_template { | ||
103 | /* | ||
104 | * target attrs | ||
105 | */ | ||
106 | void (*get_isid)(struct scsi_target *); | ||
107 | void (*get_tsih)(struct scsi_target *); | ||
108 | void (*get_header_digest)(struct scsi_target *); | ||
109 | void (*get_data_digest)(struct scsi_target *); | ||
110 | void (*get_port)(struct scsi_target *); | ||
111 | void (*get_tpgt)(struct scsi_target *); | ||
112 | /* | ||
113 | * In get_ip_address the lld must set the address and | ||
114 | * the address type | ||
115 | */ | ||
116 | void (*get_ip_address)(struct scsi_target *); | ||
117 | /* | ||
118 | * The lld should snprintf the name or alias to the buffer | ||
119 | */ | ||
120 | ssize_t (*get_target_name)(struct scsi_target *, char *, ssize_t); | ||
121 | ssize_t (*get_target_alias)(struct scsi_target *, char *, ssize_t); | ||
122 | void (*get_initial_r2t)(struct scsi_target *); | ||
123 | void (*get_immediate_data)(struct scsi_target *); | ||
124 | void (*get_max_recv_data_segment_len)(struct scsi_target *); | ||
125 | void (*get_max_burst_len)(struct scsi_target *); | ||
126 | void (*get_first_burst_len)(struct scsi_target *); | ||
127 | void (*get_def_time2wait)(struct scsi_target *); | ||
128 | void (*get_def_time2retain)(struct scsi_target *); | ||
129 | void (*get_max_outstanding_r2t)(struct scsi_target *); | ||
130 | void (*get_data_pdu_in_order)(struct scsi_target *); | ||
131 | void (*get_data_sequence_in_order)(struct scsi_target *); | ||
132 | void (*get_erl)(struct scsi_target *); | ||
133 | |||
134 | /* | ||
135 | * host atts | ||
136 | */ | ||
137 | |||
138 | /* | ||
139 | * The lld should snprintf the name or alias to the buffer | ||
140 | */ | ||
141 | ssize_t (*get_initiator_alias)(struct Scsi_Host *, char *, ssize_t); | ||
142 | ssize_t (*get_initiator_name)(struct Scsi_Host *, char *, ssize_t); | ||
143 | /* | ||
144 | * The driver sets these to tell the transport class it | ||
145 | * wants the attributes displayed in sysfs. If the show_ flag | ||
146 | * is not set, the attribute will be private to the transport | ||
147 | * class. We could probably just test if a get_ fn was set | ||
148 | * since we only use the values for sysfs but this is how | ||
149 | * fc does it too. | ||
150 | */ | ||
151 | unsigned long show_isid:1; | ||
152 | unsigned long show_tsih:1; | ||
153 | unsigned long show_header_digest:1; | ||
154 | unsigned long show_data_digest:1; | ||
155 | unsigned long show_port:1; | ||
156 | unsigned long show_tpgt:1; | ||
157 | unsigned long show_ip_address:1; | ||
158 | unsigned long show_target_name:1; | ||
159 | unsigned long show_target_alias:1; | ||
160 | unsigned long show_initial_r2t:1; | ||
161 | unsigned long show_immediate_data:1; | ||
162 | unsigned long show_max_recv_data_segment_len:1; | ||
163 | unsigned long show_max_burst_len:1; | ||
164 | unsigned long show_first_burst_len:1; | ||
165 | unsigned long show_def_time2wait:1; | ||
166 | unsigned long show_def_time2retain:1; | ||
167 | unsigned long show_max_outstanding_r2t:1; | ||
168 | unsigned long show_data_pdu_in_order:1; | ||
169 | unsigned long show_data_sequence_in_order:1; | ||
170 | unsigned long show_erl:1; | ||
171 | unsigned long show_initiator_name:1; | ||
172 | unsigned long show_initiator_alias:1; | ||
173 | }; | ||
174 | |||
175 | struct scsi_transport_template *iscsi_attach_transport(struct iscsi_function_template *); | ||
176 | void iscsi_release_transport(struct scsi_transport_template *); | ||
177 | |||
178 | #endif | ||
diff --git a/include/scsi/scsi_transport_spi.h b/include/scsi/scsi_transport_spi.h new file mode 100644 index 000000000000..6dcf497bf46d --- /dev/null +++ b/include/scsi/scsi_transport_spi.h | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Parallel SCSI (SPI) transport specific attributes exported to sysfs. | ||
3 | * | ||
4 | * Copyright (c) 2003 Silicon Graphics, Inc. All rights reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | #ifndef SCSI_TRANSPORT_SPI_H | ||
21 | #define SCSI_TRANSPORT_SPI_H | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #include <linux/transport_class.h> | ||
25 | |||
26 | struct scsi_transport_template; | ||
27 | |||
28 | struct spi_transport_attrs { | ||
29 | int period; /* value in the PPR/SDTR command */ | ||
30 | int offset; | ||
31 | unsigned int width:1; /* 0 - narrow, 1 - wide */ | ||
32 | unsigned int iu:1; /* Information Units enabled */ | ||
33 | unsigned int dt:1; /* DT clocking enabled */ | ||
34 | unsigned int qas:1; /* Quick Arbitration and Selection enabled */ | ||
35 | unsigned int wr_flow:1; /* Write Flow control enabled */ | ||
36 | unsigned int rd_strm:1; /* Read streaming enabled */ | ||
37 | unsigned int rti:1; /* Retain Training Information */ | ||
38 | unsigned int pcomp_en:1;/* Precompensation enabled */ | ||
39 | unsigned int initial_dv:1; /* DV done to this target yet */ | ||
40 | unsigned long flags; /* flags field for drivers to use */ | ||
41 | /* Device Properties fields */ | ||
42 | unsigned int support_sync:1; /* synchronous support */ | ||
43 | unsigned int support_wide:1; /* wide support */ | ||
44 | unsigned int support_dt:1; /* allows DT phases */ | ||
45 | unsigned int support_dt_only; /* disallows ST phases */ | ||
46 | unsigned int support_ius; /* support Information Units */ | ||
47 | unsigned int support_qas; /* supports quick arbitration and selection */ | ||
48 | /* Private Fields */ | ||
49 | unsigned int dv_pending:1; /* Internal flag */ | ||
50 | struct semaphore dv_sem; /* semaphore to serialise dv */ | ||
51 | }; | ||
52 | |||
53 | enum spi_signal_type { | ||
54 | SPI_SIGNAL_UNKNOWN = 1, | ||
55 | SPI_SIGNAL_SE, | ||
56 | SPI_SIGNAL_LVD, | ||
57 | SPI_SIGNAL_HVD, | ||
58 | }; | ||
59 | |||
60 | struct spi_host_attrs { | ||
61 | enum spi_signal_type signalling; | ||
62 | }; | ||
63 | |||
64 | /* accessor functions */ | ||
65 | #define spi_period(x) (((struct spi_transport_attrs *)&(x)->starget_data)->period) | ||
66 | #define spi_offset(x) (((struct spi_transport_attrs *)&(x)->starget_data)->offset) | ||
67 | #define spi_width(x) (((struct spi_transport_attrs *)&(x)->starget_data)->width) | ||
68 | #define spi_iu(x) (((struct spi_transport_attrs *)&(x)->starget_data)->iu) | ||
69 | #define spi_dt(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dt) | ||
70 | #define spi_qas(x) (((struct spi_transport_attrs *)&(x)->starget_data)->qas) | ||
71 | #define spi_wr_flow(x) (((struct spi_transport_attrs *)&(x)->starget_data)->wr_flow) | ||
72 | #define spi_rd_strm(x) (((struct spi_transport_attrs *)&(x)->starget_data)->rd_strm) | ||
73 | #define spi_rti(x) (((struct spi_transport_attrs *)&(x)->starget_data)->rti) | ||
74 | #define spi_pcomp_en(x) (((struct spi_transport_attrs *)&(x)->starget_data)->pcomp_en) | ||
75 | #define spi_initial_dv(x) (((struct spi_transport_attrs *)&(x)->starget_data)->initial_dv) | ||
76 | |||
77 | #define spi_support_sync(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_sync) | ||
78 | #define spi_support_wide(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_wide) | ||
79 | #define spi_support_dt(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_dt) | ||
80 | #define spi_support_dt_only(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_dt_only) | ||
81 | #define spi_support_ius(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_ius) | ||
82 | #define spi_support_qas(x) (((struct spi_transport_attrs *)&(x)->starget_data)->support_qas) | ||
83 | |||
84 | #define spi_flags(x) (((struct spi_transport_attrs *)&(x)->starget_data)->flags) | ||
85 | #define spi_signalling(h) (((struct spi_host_attrs *)(h)->shost_data)->signalling) | ||
86 | |||
87 | |||
88 | |||
89 | /* The functions by which the transport class and the driver communicate */ | ||
90 | struct spi_function_template { | ||
91 | void (*get_period)(struct scsi_target *); | ||
92 | void (*set_period)(struct scsi_target *, int); | ||
93 | void (*get_offset)(struct scsi_target *); | ||
94 | void (*set_offset)(struct scsi_target *, int); | ||
95 | void (*get_width)(struct scsi_target *); | ||
96 | void (*set_width)(struct scsi_target *, int); | ||
97 | void (*get_iu)(struct scsi_target *); | ||
98 | void (*set_iu)(struct scsi_target *, int); | ||
99 | void (*get_dt)(struct scsi_target *); | ||
100 | void (*set_dt)(struct scsi_target *, int); | ||
101 | void (*get_qas)(struct scsi_target *); | ||
102 | void (*set_qas)(struct scsi_target *, int); | ||
103 | void (*get_wr_flow)(struct scsi_target *); | ||
104 | void (*set_wr_flow)(struct scsi_target *, int); | ||
105 | void (*get_rd_strm)(struct scsi_target *); | ||
106 | void (*set_rd_strm)(struct scsi_target *, int); | ||
107 | void (*get_rti)(struct scsi_target *); | ||
108 | void (*set_rti)(struct scsi_target *, int); | ||
109 | void (*get_pcomp_en)(struct scsi_target *); | ||
110 | void (*set_pcomp_en)(struct scsi_target *, int); | ||
111 | void (*get_signalling)(struct Scsi_Host *); | ||
112 | void (*set_signalling)(struct Scsi_Host *, enum spi_signal_type); | ||
113 | /* The driver sets these to tell the transport class it | ||
114 | * wants the attributes displayed in sysfs. If the show_ flag | ||
115 | * is not set, the attribute will be private to the transport | ||
116 | * class */ | ||
117 | unsigned long show_period:1; | ||
118 | unsigned long show_offset:1; | ||
119 | unsigned long show_width:1; | ||
120 | unsigned long show_iu:1; | ||
121 | unsigned long show_dt:1; | ||
122 | unsigned long show_qas:1; | ||
123 | unsigned long show_wr_flow:1; | ||
124 | unsigned long show_rd_strm:1; | ||
125 | unsigned long show_rti:1; | ||
126 | unsigned long show_pcomp_en:1; | ||
127 | }; | ||
128 | |||
129 | struct scsi_transport_template *spi_attach_transport(struct spi_function_template *); | ||
130 | void spi_release_transport(struct scsi_transport_template *); | ||
131 | void spi_schedule_dv_device(struct scsi_device *); | ||
132 | void spi_dv_device(struct scsi_device *); | ||
133 | void spi_display_xfer_agreement(struct scsi_target *); | ||
134 | |||
135 | #endif /* SCSI_TRANSPORT_SPI_H */ | ||
diff --git a/include/scsi/scsicam.h b/include/scsi/scsicam.h new file mode 100644 index 000000000000..24ede474752e --- /dev/null +++ b/include/scsi/scsicam.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * scsicam.h - SCSI CAM support functions, use for HDIO_GETGEO, etc. | ||
3 | * | ||
4 | * Copyright 1993, 1994 Drew Eckhardt | ||
5 | * Visionary Computing | ||
6 | * (Unix and Linux consulting and custom programming) | ||
7 | * drew@Colorado.EDU | ||
8 | * +1 (303) 786-7975 | ||
9 | * | ||
10 | * For more information, please consult the SCSI-CAM draft. | ||
11 | */ | ||
12 | |||
13 | #ifndef SCSICAM_H | ||
14 | #define SCSICAM_H | ||
15 | extern int scsicam_bios_param (struct block_device *bdev, sector_t capacity, int *ip); | ||
16 | extern int scsi_partsize(unsigned char *buf, unsigned long capacity, | ||
17 | unsigned int *cyls, unsigned int *hds, unsigned int *secs); | ||
18 | extern unsigned char *scsi_bios_ptable(struct block_device *bdev); | ||
19 | #endif /* def SCSICAM_H */ | ||
diff --git a/include/scsi/sg.h b/include/scsi/sg.h new file mode 100644 index 000000000000..0a487fe26d4f --- /dev/null +++ b/include/scsi/sg.h | |||
@@ -0,0 +1,326 @@ | |||
1 | #ifndef _SCSI_GENERIC_H | ||
2 | #define _SCSI_GENERIC_H | ||
3 | |||
4 | #include <linux/compiler.h> | ||
5 | |||
6 | /* | ||
7 | History: | ||
8 | Started: Aug 9 by Lawrence Foard (entropy@world.std.com), to allow user | ||
9 | process control of SCSI devices. | ||
10 | Development Sponsored by Killy Corp. NY NY | ||
11 | Original driver (sg.h): | ||
12 | * Copyright (C) 1992 Lawrence Foard | ||
13 | Version 2 and 3 extensions to driver: | ||
14 | * Copyright (C) 1998 - 2003 Douglas Gilbert | ||
15 | |||
16 | Version: 3.5.29 (20030529) | ||
17 | This version is for 2.5 series kernels. | ||
18 | |||
19 | Changes since 3.5.28 (20030308) | ||
20 | - fix bug introduced in version 3.1.24 (last segment of sgat list) | ||
21 | Changes since 3.5.27 (20020812) | ||
22 | - remove procfs entries: hosts, host_hdr + host_strs (now in sysfs) | ||
23 | - add sysfs sg driver params: def_reserved_size, allow_dio, version | ||
24 | - new boot option: "sg_allow_dio" and module parameter: "allow_dio" | ||
25 | - multiple internal changes due to scsi subsystem rework | ||
26 | Changes since 3.5.26 (20020708) | ||
27 | - re-add direct IO using Kai Makisara's work | ||
28 | - re-tab to 8, start using C99-isms | ||
29 | - simplify memory management | ||
30 | Changes since 3.5.25 (20020504) | ||
31 | - driverfs additions | ||
32 | - copy_to/from_user() fixes [William Stinson] | ||
33 | - disable kiobufs support | ||
34 | |||
35 | For a full changelog see http://www.torque.net/sg | ||
36 | |||
37 | Map of SG verions to the Linux kernels in which they appear: | ||
38 | ---------- ---------------------------------- | ||
39 | original all kernels < 2.2.6 | ||
40 | 2.1.40 2.2.20 | ||
41 | 3.0.x optional version 3 sg driver for 2.2 series | ||
42 | 3.1.17++ 2.4.0++ | ||
43 | 3.5.23++ 2.5.0++ | ||
44 | |||
45 | Major new features in SG 3.x driver (cf SG 2.x drivers) | ||
46 | - SG_IO ioctl() combines function if write() and read() | ||
47 | - new interface (sg_io_hdr_t) but still supports old interface | ||
48 | - scatter/gather in user space, direct IO, and mmap supported | ||
49 | |||
50 | The normal action of this driver is to use the adapter (HBA) driver to DMA | ||
51 | data into kernel buffers and then use the CPU to copy the data into the | ||
52 | user space (vice versa for writes). That is called "indirect" IO due to | ||
53 | the double handling of data. There are two methods offered to remove the | ||
54 | redundant copy: 1) direct IO which uses the kernel kiobuf mechanism and | ||
55 | 2) using the mmap() system call to map the reserve buffer (this driver has | ||
56 | one reserve buffer per fd) into the user space. Both have their advantages. | ||
57 | In terms of absolute speed mmap() is faster. If speed is not a concern, | ||
58 | indirect IO should be fine. Read the documentation for more information. | ||
59 | |||
60 | ** N.B. To use direct IO 'echo 1 > /proc/scsi/sg/allow_dio' may be | ||
61 | needed. That pseudo file's content is defaulted to 0. ** | ||
62 | |||
63 | Historical note: this SCSI pass-through driver has been known as "sg" for | ||
64 | a decade. In broader kernel discussions "sg" is used to refer to scatter | ||
65 | gather techniques. The context should clarify which "sg" is referred to. | ||
66 | |||
67 | Documentation | ||
68 | ============= | ||
69 | A web site for the SG device driver can be found at: | ||
70 | http://www.torque.net/sg [alternatively check the MAINTAINERS file] | ||
71 | The documentation for the sg version 3 driver can be found at: | ||
72 | http://www.torque.net/sg/p/sg_v3_ho.html | ||
73 | This is a rendering from DocBook source [change the extension to "sgml" | ||
74 | or "xml"]. There are renderings in "ps", "pdf", "rtf" and "txt" (soon). | ||
75 | |||
76 | The older, version 2 documents discuss the original sg interface in detail: | ||
77 | http://www.torque.net/sg/p/scsi-generic.txt | ||
78 | http://www.torque.net/sg/p/scsi-generic_long.txt | ||
79 | A version of this document (potentially out of date) may also be found in | ||
80 | the kernel source tree, probably at: | ||
81 | Documentation/scsi/scsi-generic.txt . | ||
82 | |||
83 | Utility and test programs are available at the sg web site. They are | ||
84 | bundled as sg_utils (for the lk 2.2 series) and sg3_utils (for the | ||
85 | lk 2.4 series). | ||
86 | |||
87 | There is a HOWTO on the Linux SCSI subsystem in the lk 2.4 series at: | ||
88 | http://www.linuxdoc.org/HOWTO/SCSI-2.4-HOWTO | ||
89 | */ | ||
90 | |||
91 | |||
92 | /* New interface introduced in the 3.x SG drivers follows */ | ||
93 | |||
94 | typedef struct sg_iovec /* same structure as used by readv() Linux system */ | ||
95 | { /* call. It defines one scatter-gather element. */ | ||
96 | void __user *iov_base; /* Starting address */ | ||
97 | size_t iov_len; /* Length in bytes */ | ||
98 | } sg_iovec_t; | ||
99 | |||
100 | |||
101 | typedef struct sg_io_hdr | ||
102 | { | ||
103 | int interface_id; /* [i] 'S' for SCSI generic (required) */ | ||
104 | int dxfer_direction; /* [i] data transfer direction */ | ||
105 | unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ | ||
106 | unsigned char mx_sb_len; /* [i] max length to write to sbp */ | ||
107 | unsigned short iovec_count; /* [i] 0 implies no scatter gather */ | ||
108 | unsigned int dxfer_len; /* [i] byte count of data transfer */ | ||
109 | void __user *dxferp; /* [i], [*io] points to data transfer memory | ||
110 | or scatter gather list */ | ||
111 | unsigned char __user *cmdp; /* [i], [*i] points to command to perform */ | ||
112 | void __user *sbp; /* [i], [*o] points to sense_buffer memory */ | ||
113 | unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ | ||
114 | unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */ | ||
115 | int pack_id; /* [i->o] unused internally (normally) */ | ||
116 | void __user * usr_ptr; /* [i->o] unused internally */ | ||
117 | unsigned char status; /* [o] scsi status */ | ||
118 | unsigned char masked_status;/* [o] shifted, masked scsi status */ | ||
119 | unsigned char msg_status; /* [o] messaging level data (optional) */ | ||
120 | unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ | ||
121 | unsigned short host_status; /* [o] errors from host adapter */ | ||
122 | unsigned short driver_status;/* [o] errors from software driver */ | ||
123 | int resid; /* [o] dxfer_len - actual_transferred */ | ||
124 | unsigned int duration; /* [o] time taken by cmd (unit: millisec) */ | ||
125 | unsigned int info; /* [o] auxiliary information */ | ||
126 | } sg_io_hdr_t; /* 64 bytes long (on i386) */ | ||
127 | |||
128 | #define SG_INTERFACE_ID_ORIG 'S' | ||
129 | |||
130 | /* Use negative values to flag difference from original sg_header structure */ | ||
131 | #define SG_DXFER_NONE (-1) /* e.g. a SCSI Test Unit Ready command */ | ||
132 | #define SG_DXFER_TO_DEV (-2) /* e.g. a SCSI WRITE command */ | ||
133 | #define SG_DXFER_FROM_DEV (-3) /* e.g. a SCSI READ command */ | ||
134 | #define SG_DXFER_TO_FROM_DEV (-4) /* treated like SG_DXFER_FROM_DEV with the | ||
135 | additional property than during indirect | ||
136 | IO the user buffer is copied into the | ||
137 | kernel buffers before the transfer */ | ||
138 | #define SG_DXFER_UNKNOWN (-5) /* Unknown data direction */ | ||
139 | |||
140 | /* following flag values can be "or"-ed together */ | ||
141 | #define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */ | ||
142 | #define SG_FLAG_UNUSED_LUN_INHIBIT 2 /* default is overwrite lun in SCSI */ | ||
143 | /* command block (when <= SCSI_2) */ | ||
144 | #define SG_FLAG_MMAP_IO 4 /* request memory mapped IO */ | ||
145 | #define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */ | ||
146 | /* user space (debug indirect IO) */ | ||
147 | |||
148 | /* following 'info' values are "or"-ed together */ | ||
149 | #define SG_INFO_OK_MASK 0x1 | ||
150 | #define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */ | ||
151 | #define SG_INFO_CHECK 0x1 /* something abnormal happened */ | ||
152 | |||
153 | #define SG_INFO_DIRECT_IO_MASK 0x6 | ||
154 | #define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */ | ||
155 | #define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ | ||
156 | #define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */ | ||
157 | |||
158 | |||
159 | typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ | ||
160 | int host_no; /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */ | ||
161 | int channel; | ||
162 | int scsi_id; /* scsi id of target device */ | ||
163 | int lun; | ||
164 | int scsi_type; /* TYPE_... defined in scsi/scsi.h */ | ||
165 | short h_cmd_per_lun;/* host (adapter) maximum commands per lun */ | ||
166 | short d_queue_depth;/* device (or adapter) maximum queue length */ | ||
167 | int unused[2]; /* probably find a good use, set 0 for now */ | ||
168 | } sg_scsi_id_t; /* 32 bytes long on i386 */ | ||
169 | |||
170 | typedef struct sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */ | ||
171 | char req_state; /* 0 -> not used, 1 -> written, 2 -> ready to read */ | ||
172 | char orphan; /* 0 -> normal request, 1 -> from interruped SG_IO */ | ||
173 | char sg_io_owned; /* 0 -> complete with read(), 1 -> owned by SG_IO */ | ||
174 | char problem; /* 0 -> no problem detected, 1 -> error to report */ | ||
175 | int pack_id; /* pack_id associated with request */ | ||
176 | void __user *usr_ptr; /* user provided pointer (in new interface) */ | ||
177 | unsigned int duration; /* millisecs elapsed since written (req_state==1) | ||
178 | or request duration (req_state==2) */ | ||
179 | int unused; | ||
180 | } sg_req_info_t; /* 20 bytes long on i386 */ | ||
181 | |||
182 | |||
183 | /* IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow. | ||
184 | [Those that only apply to the SG 2.x drivers are at the end of the file.] | ||
185 | (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) */ | ||
186 | |||
187 | #define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */ | ||
188 | |||
189 | /* Used to configure SCSI command transformation layer for ATAPI devices */ | ||
190 | /* Only supported by the ide-scsi driver */ | ||
191 | #define SG_SET_TRANSFORM 0x2204 /* N.B. 3rd arg is not pointer but value: */ | ||
192 | /* 3rd arg = 0 to disable transform, 1 to enable it */ | ||
193 | #define SG_GET_TRANSFORM 0x2205 | ||
194 | |||
195 | #define SG_SET_RESERVED_SIZE 0x2275 /* request a new reserved buffer size */ | ||
196 | #define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */ | ||
197 | |||
198 | /* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */ | ||
199 | #define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */ | ||
200 | /* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */ | ||
201 | |||
202 | /* Override host setting and always DMA using low memory ( <16MB on i386) */ | ||
203 | #define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */ | ||
204 | #define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */ | ||
205 | |||
206 | /* When SG_SET_FORCE_PACK_ID set to 1, pack_id is input to read() which | ||
207 | tries to fetch a packet with a matching pack_id, waits, or returns EAGAIN. | ||
208 | If pack_id is -1 then read oldest waiting. When ...FORCE_PACK_ID set to 0 | ||
209 | then pack_id ignored by read() and oldest readable fetched. */ | ||
210 | #define SG_SET_FORCE_PACK_ID 0x227b | ||
211 | #define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id (or -1) */ | ||
212 | |||
213 | #define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */ | ||
214 | |||
215 | /* Yields max scatter gather tablesize allowed by current host adapter */ | ||
216 | #define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */ | ||
217 | |||
218 | #define SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */ | ||
219 | |||
220 | /* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ | ||
221 | #define SG_SCSI_RESET 0x2284 | ||
222 | /* Associated values that can be given to SG_SCSI_RESET follow */ | ||
223 | #define SG_SCSI_RESET_NOTHING 0 | ||
224 | #define SG_SCSI_RESET_DEVICE 1 | ||
225 | #define SG_SCSI_RESET_BUS 2 | ||
226 | #define SG_SCSI_RESET_HOST 3 | ||
227 | |||
228 | /* synchronous SCSI command ioctl, (only in version 3 interface) */ | ||
229 | #define SG_IO 0x2285 /* similar effect as write() followed by read() */ | ||
230 | |||
231 | #define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */ | ||
232 | |||
233 | /* How to treat EINTR during SG_IO ioctl(), only in SG 3.x series */ | ||
234 | #define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */ | ||
235 | #define SG_GET_KEEP_ORPHAN 0x2288 | ||
236 | |||
237 | /* yields scsi midlevel's access_count for this SCSI device */ | ||
238 | #define SG_GET_ACCESS_COUNT 0x2289 | ||
239 | |||
240 | |||
241 | #define SG_SCATTER_SZ (8 * 4096) /* PAGE_SIZE not available to user */ | ||
242 | /* Largest size (in bytes) a single scatter-gather list element can have. | ||
243 | The value must be a power of 2 and <= (PAGE_SIZE * 32) [131072 bytes on | ||
244 | i386]. The minimum value is PAGE_SIZE. If scatter-gather not supported | ||
245 | by adapter then this value is the largest data block that can be | ||
246 | read/written by a single scsi command. The user can find the value of | ||
247 | PAGE_SIZE by calling getpagesize() defined in unistd.h . */ | ||
248 | |||
249 | #define SG_DEFAULT_RETRIES 0 | ||
250 | |||
251 | /* Defaults, commented if they differ from original sg driver */ | ||
252 | #define SG_DEF_FORCE_LOW_DMA 0 /* was 1 -> memory below 16MB on i386 */ | ||
253 | #define SG_DEF_FORCE_PACK_ID 0 | ||
254 | #define SG_DEF_KEEP_ORPHAN 0 | ||
255 | #define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */ | ||
256 | |||
257 | /* maximum outstanding requests, write() yields EDOM if exceeded */ | ||
258 | #define SG_MAX_QUEUE 16 | ||
259 | |||
260 | #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */ | ||
261 | |||
262 | /* Alternate style type names, "..._t" variants preferred */ | ||
263 | typedef struct sg_io_hdr Sg_io_hdr; | ||
264 | typedef struct sg_io_vec Sg_io_vec; | ||
265 | typedef struct sg_scsi_id Sg_scsi_id; | ||
266 | typedef struct sg_req_info Sg_req_info; | ||
267 | |||
268 | |||
269 | /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ | ||
270 | /* The older SG interface based on the 'sg_header' structure follows. */ | ||
271 | /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ | ||
272 | |||
273 | #define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */ | ||
274 | |||
275 | struct sg_header | ||
276 | { | ||
277 | int pack_len; /* [o] reply_len (ie useless), ignored as input */ | ||
278 | int reply_len; /* [i] max length of expected reply (inc. sg_header) */ | ||
279 | int pack_id; /* [io] id number of packet (use ints >= 0) */ | ||
280 | int result; /* [o] 0==ok, else (+ve) Unix errno (best ignored) */ | ||
281 | unsigned int twelve_byte:1; | ||
282 | /* [i] Force 12 byte command length for group 6 & 7 commands */ | ||
283 | unsigned int target_status:5; /* [o] scsi status from target */ | ||
284 | unsigned int host_status:8; /* [o] host status (see "DID" codes) */ | ||
285 | unsigned int driver_status:8; /* [o] driver status+suggestion */ | ||
286 | unsigned int other_flags:10; /* unused */ | ||
287 | unsigned char sense_buffer[SG_MAX_SENSE]; /* [o] Output in 3 cases: | ||
288 | when target_status is CHECK_CONDITION or | ||
289 | when target_status is COMMAND_TERMINATED or | ||
290 | when (driver_status & DRIVER_SENSE) is true. */ | ||
291 | }; /* This structure is 36 bytes long on i386 */ | ||
292 | |||
293 | |||
294 | /* IOCTLs: The following are not required (or ignored) when the sg_io_hdr_t | ||
295 | interface is used. They are kept for backward compatibility with | ||
296 | the original and version 2 drivers. */ | ||
297 | |||
298 | #define SG_SET_TIMEOUT 0x2201 /* unit: jiffies (10ms on i386) */ | ||
299 | #define SG_GET_TIMEOUT 0x2202 /* yield timeout as _return_ value */ | ||
300 | |||
301 | /* Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q. | ||
302 | Each time a sg_io_hdr_t object is seen on this file descriptor, this | ||
303 | command queuing flag is set on (overriding the previous setting). */ | ||
304 | #define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on) */ | ||
305 | #define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1 */ | ||
306 | |||
307 | /* Turn on/off error sense trace (1 and 0 respectively, default is off). | ||
308 | Try using: "# cat /proc/scsi/sg/debug" instead in the v3 driver */ | ||
309 | #define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */ | ||
310 | |||
311 | #define SG_NEXT_CMD_LEN 0x2283 /* override SCSI command length with given | ||
312 | number on the next write() on this file descriptor */ | ||
313 | |||
314 | |||
315 | /* Defaults, commented if they differ from original sg driver */ | ||
316 | #ifdef __KERNEL__ | ||
317 | #define SG_DEFAULT_TIMEOUT_USER (60*USER_HZ) /* HZ == 'jiffies in 1 second' */ | ||
318 | #else | ||
319 | #define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */ | ||
320 | #endif | ||
321 | |||
322 | #define SG_DEF_COMMAND_Q 0 /* command queuing is always on when | ||
323 | the new interface is used */ | ||
324 | #define SG_DEF_UNDERRUN_FLAG 0 | ||
325 | |||
326 | #endif | ||