- pre4:
[davej-history.git] / drivers / scsi / scsi.h
blobe40d64ccb4ce098a5f7a7d2bcbdd2758b46531c7
1 /*
2 * scsi.h Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995, 1998, 1999 Eric Youngdale
4 * generic SCSI package header file by
5 * Initial versions: Drew Eckhardt
6 * Subsequent revisions: Eric Youngdale
8 * <drew@colorado.edu>
10 * Modified by Eric Youngdale eric@andante.org to
11 * add scatter-gather, multiple outstanding request, and other
12 * enhancements.
15 #ifndef _SCSI_H
16 #define _SCSI_H
18 #include <linux/config.h> /* for CONFIG_SCSI_LOGGING */
19 #include <linux/devfs_fs_kernel.h>
20 #include <linux/proc_fs.h>
23 * Some of the public constants are being moved to this file.
24 * We include it here so that what came from where is transparent.
26 #include <scsi/scsi.h>
28 #include <linux/random.h>
30 #include <asm/hardirq.h>
31 #include <asm/scatterlist.h>
32 #include <asm/io.h>
35 * These are the values that the SCpnt->sc_data_direction and
36 * SRpnt->sr_data_direction can take. These need to be set
37 * The SCSI_DATA_UNKNOWN value is essentially the default.
38 * In the event that the command creator didn't bother to
39 * set a value, you will see SCSI_DATA_UNKNOWN.
41 #define SCSI_DATA_UNKNOWN 0
42 #define SCSI_DATA_WRITE 1
43 #define SCSI_DATA_READ 2
44 #define SCSI_DATA_NONE 3
46 #ifdef CONFIG_PCI
47 #include <linux/pci.h>
48 #if ((SCSI_DATA_UNKNOWN == PCI_DMA_BIDIRECTIONAL) && (SCSI_DATA_WRITE == PCI_DMA_TODEVICE) && (SCSI_DATA_READ == PCI_DMA_FROMDEVICE) && (SCSI_DATA_NONE == PCI_DMA_NONE))
49 #define scsi_to_pci_dma_dir(scsi_dir) ((int)(scsi_dir))
50 #else
51 extern __inline__ int scsi_to_pci_dma_dir(unsigned char scsi_dir)
53 if (scsi_dir == SCSI_DATA_UNKNOWN)
54 return PCI_DMA_BIDIRECTIONAL;
55 if (scsi_dir == SCSI_DATA_WRITE)
56 return PCI_DMA_TODEVICE;
57 if (scsi_dir == SCSI_DATA_READ)
58 return PCI_DMA_FROMDEVICE;
59 return PCI_DMA_NONE;
61 #endif
62 #endif
64 #ifdef CONFIG_SBUS
65 #include <asm/sbus.h>
66 #if ((SCSI_DATA_UNKNOWN == SBUS_DMA_BIDIRECTIONAL) && (SCSI_DATA_WRITE == SBUS_DMA_TODEVICE) && (SCSI_DATA_READ == SBUS_DMA_FROMDEVICE) && (SCSI_DATA_NONE == SBUS_DMA_NONE))
67 #define scsi_to_sbus_dma_dir(scsi_dir) ((int)(scsi_dir))
68 #else
69 extern __inline__ int scsi_to_sbus_dma_dir(unsigned char scsi_dir)
71 if (scsi_dir == SCSI_DATA_UNKNOWN)
72 return SBUS_DMA_BIDIRECTIONAL;
73 if (scsi_dir == SCSI_DATA_WRITE)
74 return SBUS_DMA_TODEVICE;
75 if (scsi_dir == SCSI_DATA_READ)
76 return SBUS_DMA_FROMDEVICE;
77 return SBUS_DMA_NONE;
79 #endif
80 #endif
83 * Some defs, in case these are not defined elsewhere.
85 #ifndef TRUE
86 #define TRUE 1
87 #endif
88 #ifndef FALSE
89 #define FALSE 0
90 #endif
92 #define MAX_SCSI_DEVICE_CODE 14
93 extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE];
95 #ifdef DEBUG
96 #define SCSI_TIMEOUT (5*HZ)
97 #else
98 #define SCSI_TIMEOUT (2*HZ)
99 #endif
102 * Used for debugging the new queueing code. We want to make sure
103 * that the lock state is consistent with design. Only do this in
104 * the user space simulator.
106 #define ASSERT_LOCK(_LOCK, _COUNT)
108 #if defined(CONFIG_SMP) && defined(CONFIG_USER_DEBUG)
109 #undef ASSERT_LOCK
110 #define ASSERT_LOCK(_LOCK,_COUNT) \
111 { if( (_LOCK)->lock != _COUNT ) \
112 panic("Lock count inconsistent %s %d\n", __FILE__, __LINE__); \
114 #endif
117 * Use these to separate status msg and our bytes
119 * These are set by:
121 * status byte = set from target device
122 * msg_byte = return status from host adapter itself.
123 * host_byte = set by low-level driver to indicate status.
124 * driver_byte = set by mid-level.
126 #define status_byte(result) (((result) >> 1) & 0x1f)
127 #define msg_byte(result) (((result) >> 8) & 0xff)
128 #define host_byte(result) (((result) >> 16) & 0xff)
129 #define driver_byte(result) (((result) >> 24) & 0xff)
130 #define suggestion(result) (driver_byte(result) & SUGGEST_MASK)
132 #define sense_class(sense) (((sense) >> 4) & 0x7)
133 #define sense_error(sense) ((sense) & 0xf)
134 #define sense_valid(sense) ((sense) & 0x80);
136 #define NEEDS_RETRY 0x2001
137 #define SUCCESS 0x2002
138 #define FAILED 0x2003
139 #define QUEUED 0x2004
140 #define SOFT_ERROR 0x2005
141 #define ADD_TO_MLQUEUE 0x2006
144 * These are the values that scsi_cmd->state can take.
146 #define SCSI_STATE_TIMEOUT 0x1000
147 #define SCSI_STATE_FINISHED 0x1001
148 #define SCSI_STATE_FAILED 0x1002
149 #define SCSI_STATE_QUEUED 0x1003
150 #define SCSI_STATE_UNUSED 0x1006
151 #define SCSI_STATE_DISCONNECTING 0x1008
152 #define SCSI_STATE_INITIALIZING 0x1009
153 #define SCSI_STATE_BHQUEUE 0x100a
154 #define SCSI_STATE_MLQUEUE 0x100b
157 * These are the values that the owner field can take.
158 * They are used as an indication of who the command belongs to.
160 #define SCSI_OWNER_HIGHLEVEL 0x100
161 #define SCSI_OWNER_MIDLEVEL 0x101
162 #define SCSI_OWNER_LOWLEVEL 0x102
163 #define SCSI_OWNER_ERROR_HANDLER 0x103
164 #define SCSI_OWNER_BH_HANDLER 0x104
165 #define SCSI_OWNER_NOBODY 0x105
167 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
169 #define IDENTIFY_BASE 0x80
170 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
171 ((can_disconnect) ? 0x40 : 0) |\
172 ((lun) & 0x07))
176 * This defines the scsi logging feature. It is a means by which the
177 * user can select how much information they get about various goings on,
178 * and it can be really useful for fault tracing. The logging word is divided
179 * into 8 nibbles, each of which describes a loglevel. The division of things
180 * is somewhat arbitrary, and the division of the word could be changed if it
181 * were really needed for any reason. The numbers below are the only place where these
182 * are specified. For a first go-around, 3 bits is more than enough, since this
183 * gives 8 levels of logging (really 7, since 0 is always off). Cutting to 2 bits
184 * might be wise at some point.
187 #define SCSI_LOG_ERROR_SHIFT 0
188 #define SCSI_LOG_TIMEOUT_SHIFT 3
189 #define SCSI_LOG_SCAN_SHIFT 6
190 #define SCSI_LOG_MLQUEUE_SHIFT 9
191 #define SCSI_LOG_MLCOMPLETE_SHIFT 12
192 #define SCSI_LOG_LLQUEUE_SHIFT 15
193 #define SCSI_LOG_LLCOMPLETE_SHIFT 18
194 #define SCSI_LOG_HLQUEUE_SHIFT 21
195 #define SCSI_LOG_HLCOMPLETE_SHIFT 24
196 #define SCSI_LOG_IOCTL_SHIFT 27
198 #define SCSI_LOG_ERROR_BITS 3
199 #define SCSI_LOG_TIMEOUT_BITS 3
200 #define SCSI_LOG_SCAN_BITS 3
201 #define SCSI_LOG_MLQUEUE_BITS 3
202 #define SCSI_LOG_MLCOMPLETE_BITS 3
203 #define SCSI_LOG_LLQUEUE_BITS 3
204 #define SCSI_LOG_LLCOMPLETE_BITS 3
205 #define SCSI_LOG_HLQUEUE_BITS 3
206 #define SCSI_LOG_HLCOMPLETE_BITS 3
207 #define SCSI_LOG_IOCTL_BITS 3
209 #if CONFIG_SCSI_LOGGING
211 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) \
213 unsigned int mask; \
215 mask = (1 << (BITS)) - 1; \
216 if( ((scsi_logging_level >> (SHIFT)) & mask) > (LEVEL) ) \
218 (CMD); \
222 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL) \
224 unsigned int mask; \
226 mask = ((1 << (BITS)) - 1) << SHIFT; \
227 scsi_logging_level = ((scsi_logging_level & ~mask) \
228 | ((LEVEL << SHIFT) & mask)); \
233 #else
236 * With no logging enabled, stub these out so they don't do anything.
238 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL)
240 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
241 #endif
244 * These are the macros that are actually used throughout the code to
245 * log events. If logging isn't enabled, they are no-ops and will be
246 * completely absent from the user's code.
248 * The 'set' versions of the macros are really intended to only be called
249 * from the /proc filesystem, and in production kernels this will be about
250 * all that is ever used. It could be useful in a debugging environment to
251 * bump the logging level when certain strange events are detected, however.
253 #define SCSI_LOG_ERROR_RECOVERY(LEVEL,CMD) \
254 SCSI_CHECK_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL,CMD);
255 #define SCSI_LOG_TIMEOUT(LEVEL,CMD) \
256 SCSI_CHECK_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL,CMD);
257 #define SCSI_LOG_SCAN_BUS(LEVEL,CMD) \
258 SCSI_CHECK_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL,CMD);
259 #define SCSI_LOG_MLQUEUE(LEVEL,CMD) \
260 SCSI_CHECK_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL,CMD);
261 #define SCSI_LOG_MLCOMPLETE(LEVEL,CMD) \
262 SCSI_CHECK_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL,CMD);
263 #define SCSI_LOG_LLQUEUE(LEVEL,CMD) \
264 SCSI_CHECK_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL,CMD);
265 #define SCSI_LOG_LLCOMPLETE(LEVEL,CMD) \
266 SCSI_CHECK_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL,CMD);
267 #define SCSI_LOG_HLQUEUE(LEVEL,CMD) \
268 SCSI_CHECK_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL,CMD);
269 #define SCSI_LOG_HLCOMPLETE(LEVEL,CMD) \
270 SCSI_CHECK_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL,CMD);
271 #define SCSI_LOG_IOCTL(LEVEL,CMD) \
272 SCSI_CHECK_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL,CMD);
275 #define SCSI_SET_ERROR_RECOVERY_LOGGING(LEVEL) \
276 SCSI_SET_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL);
277 #define SCSI_SET_TIMEOUT_LOGGING(LEVEL) \
278 SCSI_SET_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL);
279 #define SCSI_SET_SCAN_BUS_LOGGING(LEVEL) \
280 SCSI_SET_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL);
281 #define SCSI_SET_MLQUEUE_LOGGING(LEVEL) \
282 SCSI_SET_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL);
283 #define SCSI_SET_MLCOMPLETE_LOGGING(LEVEL) \
284 SCSI_SET_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL);
285 #define SCSI_SET_LLQUEUE_LOGGING(LEVEL) \
286 SCSI_SET_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL);
287 #define SCSI_SET_LLCOMPLETE_LOGGING(LEVEL) \
288 SCSI_SET_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL);
289 #define SCSI_SET_HLQUEUE_LOGGING(LEVEL) \
290 SCSI_SET_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL);
291 #define SCSI_SET_HLCOMPLETE_LOGGING(LEVEL) \
292 SCSI_SET_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL);
293 #define SCSI_SET_IOCTL_LOGGING(LEVEL) \
294 SCSI_SET_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL);
297 * the return of the status word will be in the following format :
298 * The low byte is the status returned by the SCSI command,
299 * with vendor specific bits masked.
301 * The next byte is the message which followed the SCSI status.
302 * This allows a stos to be used, since the Intel is a little
303 * endian machine.
305 * The final byte is a host return code, which is one of the following.
307 * IE
308 * lsb msb
309 * status msg host code
311 * Our errors returned by OUR driver, NOT SCSI message. Or'd with
312 * SCSI message passed back to driver <IF any>.
316 #define DID_OK 0x00 /* NO error */
317 #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
318 #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
319 #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
320 #define DID_BAD_TARGET 0x04 /* BAD target. */
321 #define DID_ABORT 0x05 /* Told to abort for some other reason */
322 #define DID_PARITY 0x06 /* Parity error */
323 #define DID_ERROR 0x07 /* Internal error */
324 #define DID_RESET 0x08 /* Reset by somebody. */
325 #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
326 #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
327 #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
328 #define DRIVER_OK 0x00 /* Driver status */
331 * These indicate the error that occurred, and what is available.
334 #define DRIVER_BUSY 0x01
335 #define DRIVER_SOFT 0x02
336 #define DRIVER_MEDIA 0x03
337 #define DRIVER_ERROR 0x04
339 #define DRIVER_INVALID 0x05
340 #define DRIVER_TIMEOUT 0x06
341 #define DRIVER_HARD 0x07
342 #define DRIVER_SENSE 0x08
344 #define SUGGEST_RETRY 0x10
345 #define SUGGEST_ABORT 0x20
346 #define SUGGEST_REMAP 0x30
347 #define SUGGEST_DIE 0x40
348 #define SUGGEST_SENSE 0x80
349 #define SUGGEST_IS_OK 0xff
351 #define DRIVER_MASK 0x0f
352 #define SUGGEST_MASK 0xf0
354 #define MAX_COMMAND_SIZE 12
355 #define SCSI_SENSE_BUFFERSIZE 64
358 * SCSI command sets
361 #define SCSI_UNKNOWN 0
362 #define SCSI_1 1
363 #define SCSI_1_CCS 2
364 #define SCSI_2 3
365 #define SCSI_3 4
368 * Every SCSI command starts with a one byte OP-code.
369 * The next byte's high three bits are the LUN of the
370 * device. Any multi-byte quantities are stored high byte
371 * first, and may have a 5 bit MSB in the same byte
372 * as the LUN.
376 * As the scsi do command functions are intelligent, and may need to
377 * redo a command, we need to keep track of the last command
378 * executed on each one.
381 #define WAS_RESET 0x01
382 #define WAS_TIMEDOUT 0x02
383 #define WAS_SENSE 0x04
384 #define IS_RESETTING 0x08
385 #define IS_ABORTING 0x10
386 #define ASKED_FOR_SENSE 0x20
387 #define SYNC_RESET 0x40
389 #if defined(__mc68000__) || defined(CONFIG_APUS)
390 #include <asm/pgtable.h>
391 #define CONTIGUOUS_BUFFERS(X,Y) \
392 (virt_to_phys((X)->b_data+(X)->b_size-1)+1==virt_to_phys((Y)->b_data))
393 #else
394 #define CONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data)
395 #endif
399 * This is the crap from the old error handling code. We have it in a special
400 * place so that we can more easily delete it later on.
402 #include "scsi_obsolete.h"
405 * Add some typedefs so that we can prototyope a bunch of the functions.
407 typedef struct scsi_device Scsi_Device;
408 typedef struct scsi_cmnd Scsi_Cmnd;
409 typedef struct scsi_request Scsi_Request;
411 #define SCSI_CMND_MAGIC 0xE25C23A5
412 #define SCSI_REQ_MAGIC 0x75F6D354
415 * Here is where we prototype most of the mid-layer.
419 * Initializes all SCSI devices. This scans all scsi busses.
422 extern unsigned int scsi_logging_level; /* What do we log? */
423 extern unsigned int scsi_dma_free_sectors; /* How much room do we have left */
424 extern unsigned int scsi_need_isa_buffer; /* True if some devices need indirection
425 * buffers */
426 extern volatile int in_scan_scsis;
427 extern const unsigned char scsi_command_size[8];
431 * These are the error handling functions defined in scsi_error.c
433 extern void scsi_times_out(Scsi_Cmnd * SCpnt);
434 extern void scsi_add_timer(Scsi_Cmnd * SCset, int timeout,
435 void (*complete) (Scsi_Cmnd *));
436 extern int scsi_delete_timer(Scsi_Cmnd * SCset);
437 extern void scsi_error_handler(void *host);
438 extern int scsi_sense_valid(Scsi_Cmnd *);
439 extern int scsi_decide_disposition(Scsi_Cmnd * SCpnt);
440 extern int scsi_block_when_processing_errors(Scsi_Device *);
441 extern void scsi_sleep(int);
444 * Prototypes for functions in scsicam.c
446 extern int scsi_partsize(struct buffer_head *bh, unsigned long capacity,
447 unsigned int *cyls, unsigned int *hds,
448 unsigned int *secs);
451 * Prototypes for functions in scsi_dma.c
453 void scsi_resize_dma_pool(void);
454 int scsi_init_minimal_dma_pool(void);
455 void *scsi_malloc(unsigned int);
456 int scsi_free(void *, unsigned int);
459 * Prototypes for functions in scsi_merge.c
461 extern void recount_segments(Scsi_Cmnd * SCpnt);
462 extern void initialize_merge_fn(Scsi_Device * SDpnt);
465 * Prototypes for functions in scsi_queue.c
467 extern int scsi_mlqueue_insert(Scsi_Cmnd * cmd, int reason);
470 * Prototypes for functions in scsi_lib.c
472 extern int scsi_maybe_unblock_host(Scsi_Device * SDpnt);
473 extern Scsi_Cmnd *scsi_end_request(Scsi_Cmnd * SCpnt, int uptodate,
474 int sectors);
475 extern struct Scsi_Device_Template *scsi_get_request_dev(struct request *);
476 extern int scsi_init_cmd_errh(Scsi_Cmnd * SCpnt);
477 extern int scsi_insert_special_cmd(Scsi_Cmnd * SCpnt, int);
478 extern void scsi_io_completion(Scsi_Cmnd * SCpnt, int good_sectors,
479 int block_sectors);
480 extern void scsi_queue_next_request(request_queue_t * q, Scsi_Cmnd * SCpnt);
481 extern void scsi_request_fn(request_queue_t * q);
482 extern int scsi_starvation_completion(Scsi_Device * SDpnt);
485 * Prototypes for functions in scsi.c
487 extern int scsi_dispatch_cmd(Scsi_Cmnd * SCpnt);
488 extern void scsi_bottom_half_handler(void);
489 extern void scsi_release_commandblocks(Scsi_Device * SDpnt);
490 extern void scsi_build_commandblocks(Scsi_Device * SDpnt);
491 extern void scsi_done(Scsi_Cmnd * SCpnt);
492 extern void scsi_finish_command(Scsi_Cmnd *);
493 extern int scsi_retry_command(Scsi_Cmnd *);
494 extern Scsi_Cmnd *scsi_allocate_device(Scsi_Device *, int, int);
495 extern void scsi_release_command(Scsi_Cmnd *);
496 extern void scsi_do_cmd(Scsi_Cmnd *, const void *cmnd,
497 void *buffer, unsigned bufflen,
498 void (*done) (struct scsi_cmnd *),
499 int timeout, int retries);
500 extern int scsi_dev_init(void);
503 * Newer request-based interfaces.
505 extern Scsi_Request *scsi_allocate_request(Scsi_Device *);
506 extern void scsi_release_request(Scsi_Request *);
507 extern void scsi_wait_req(Scsi_Request *, const void *cmnd,
508 void *buffer, unsigned bufflen,
509 int timeout, int retries);
511 extern void scsi_do_req(Scsi_Request *, const void *cmnd,
512 void *buffer, unsigned bufflen,
513 void (*done) (struct scsi_cmnd *),
514 int timeout, int retries);
515 extern int scsi_insert_special_req(Scsi_Request * SRpnt, int);
516 extern void scsi_init_cmd_from_req(Scsi_Cmnd *, Scsi_Request *);
520 * Prototypes for functions/data in hosts.c
522 extern int max_scsi_hosts;
525 * Prototypes for functions in scsi_proc.c
527 extern void proc_print_scsidevice(Scsi_Device *, char *, int *, int);
528 extern struct proc_dir_entry *proc_scsi;
531 * Prototypes for functions in constants.c
533 extern void print_command(unsigned char *);
534 extern void print_sense(const char *, Scsi_Cmnd *);
535 extern void print_req_sense(const char *, Scsi_Request *);
536 extern void print_driverbyte(int scsiresult);
537 extern void print_hostbyte(int scsiresult);
538 extern void print_status (int status);
541 * The scsi_device struct contains what we know about each given scsi
542 * device.
544 * FIXME(eric) - one of the great regrets that I have is that I failed to define
545 * these structure elements as something like sdev_foo instead of foo. This would
546 * make it so much easier to grep through sources and so forth. I propose that
547 * all new elements that get added to these structures follow this convention.
548 * As time goes on and as people have the stomach for it, it should be possible to
549 * go back and retrofit at least some of the elements here with with the prefix.
552 struct scsi_device {
553 /* private: */
555 * This information is private to the scsi mid-layer. Wrapping it in a
556 * struct private is a way of marking it in a sort of C++ type of way.
558 struct scsi_device *next; /* Used for linked list */
559 struct scsi_device *prev; /* Used for linked list */
560 wait_queue_head_t scpnt_wait; /* Used to wait if
561 device is busy */
562 struct Scsi_Host *host;
563 request_queue_t request_queue;
564 atomic_t device_active; /* commands checked out for device */
565 volatile unsigned short device_busy; /* commands actually active on low-level */
566 int (*scsi_init_io_fn) (Scsi_Cmnd *); /* Used to initialize
567 new request */
568 Scsi_Cmnd *device_queue; /* queue of SCSI Command structures */
570 /* public: */
571 unsigned int id, lun, channel;
573 unsigned int manufacturer; /* Manufacturer of device, for using
574 * vendor-specific cmd's */
575 unsigned sector_size; /* size in bytes */
577 int attached; /* # of high level drivers attached to
578 * this */
579 int access_count; /* Count of open channels/mounts */
581 void *hostdata; /* available to low-level driver */
582 devfs_handle_t de; /* directory for the device */
583 char type;
584 char scsi_level;
585 char vendor[8], model[16], rev[4];
586 unsigned char current_tag; /* current tag */
587 unsigned char sync_min_period; /* Not less than this period */
588 unsigned char sync_max_offset; /* Not greater than this offset */
589 unsigned char queue_depth; /* How deep a queue to use */
591 unsigned online:1;
592 unsigned writeable:1;
593 unsigned removable:1;
594 unsigned random:1;
595 unsigned has_cmdblocks:1;
596 unsigned changed:1; /* Data invalid due to media change */
597 unsigned busy:1; /* Used to prevent races */
598 unsigned lockable:1; /* Able to prevent media removal */
599 unsigned borken:1; /* Tell the Seagate driver to be
600 * painfully slow on this device */
601 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
602 unsigned tagged_queue:1; /* SCSI-II tagged queuing enabled */
603 unsigned disconnect:1; /* can disconnect */
604 unsigned soft_reset:1; /* Uses soft reset option */
605 unsigned sync:1; /* Negotiate for sync transfers */
606 unsigned wide:1; /* Negotiate for WIDE transfers */
607 unsigned single_lun:1; /* Indicates we should only allow I/O to
608 * one of the luns for the device at a
609 * time. */
610 unsigned was_reset:1; /* There was a bus reset on the bus for
611 * this device */
612 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
613 * because we did a bus reset. */
614 unsigned device_blocked:1; /* Device returned QUEUE_FULL. */
615 unsigned ten:1; /* support ten byte read / write */
616 unsigned remap:1; /* support remapping */
617 unsigned starved:1; /* unable to process commands because
618 host busy */
623 * The Scsi_Cmnd structure is used by scsi.c internally, and for communication
624 * with low level drivers that support multiple outstanding commands.
626 typedef struct scsi_pointer {
627 char *ptr; /* data pointer */
628 int this_residual; /* left in this buffer */
629 struct scatterlist *buffer; /* which buffer */
630 int buffers_residual; /* how many buffers left */
632 volatile int Status;
633 volatile int Message;
634 volatile int have_data_in;
635 volatile int sent_command;
636 volatile int phase;
637 } Scsi_Pointer;
640 * This is essentially a slimmed down version of Scsi_Cmnd. The point of
641 * having this is that requests that are injected into the queue as result
642 * of things like ioctls and character devices shouldn't be using a
643 * Scsi_Cmnd until such a time that the command is actually at the head
644 * of the queue and being sent to the driver.
646 struct scsi_request {
647 int sr_magic;
648 int sr_result; /* Status code from lower level driver */
649 unsigned char sr_sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
650 * when CHECK CONDITION is
651 * received on original command
652 * (auto-sense) */
654 struct Scsi_Host *sr_host;
655 Scsi_Device *sr_device;
656 Scsi_Cmnd *sr_command;
657 struct request sr_request; /* A copy of the command we are
658 working on */
659 unsigned sr_bufflen; /* Size of data buffer */
660 void *sr_buffer; /* Data buffer */
661 int sr_allowed;
662 unsigned char sr_data_direction;
663 unsigned char sr_cmd_len;
664 unsigned char sr_cmnd[MAX_COMMAND_SIZE];
665 void (*sr_done) (struct scsi_cmnd *); /* Mid-level done function */
666 int sr_timeout_per_command;
667 unsigned short sr_use_sg; /* Number of pieces of scatter-gather */
668 unsigned short sr_sglist_len; /* size of malloc'd scatter-gather list */
669 unsigned sr_underflow; /* Return error if less than
670 this amount is transfered */
674 * FIXME(eric) - one of the great regrets that I have is that I failed to define
675 * these structure elements as something like sc_foo instead of foo. This would
676 * make it so much easier to grep through sources and so forth. I propose that
677 * all new elements that get added to these structures follow this convention.
678 * As time goes on and as people have the stomach for it, it should be possible to
679 * go back and retrofit at least some of the elements here with with the prefix.
681 struct scsi_cmnd {
682 int sc_magic;
683 /* private: */
685 * This information is private to the scsi mid-layer. Wrapping it in a
686 * struct private is a way of marking it in a sort of C++ type of way.
688 struct Scsi_Host *host;
689 unsigned short state;
690 unsigned short owner;
691 Scsi_Device *device;
692 Scsi_Request *sc_request;
693 struct scsi_cmnd *next;
694 struct scsi_cmnd *reset_chain;
696 int eh_state; /* Used for state tracking in error handlr */
697 void (*done) (struct scsi_cmnd *); /* Mid-level done function */
699 A SCSI Command is assigned a nonzero serial_number when internal_cmnd
700 passes it to the driver's queue command function. The serial_number
701 is cleared when scsi_done is entered indicating that the command has
702 been completed. If a timeout occurs, the serial number at the moment
703 of timeout is copied into serial_number_at_timeout. By subsequently
704 comparing the serial_number and serial_number_at_timeout fields
705 during abort or reset processing, we can detect whether the command
706 has already completed. This also detects cases where the command has
707 completed and the SCSI Command structure has already being reused
708 for another command, so that we can avoid incorrectly aborting or
709 resetting the new command.
712 unsigned long serial_number;
713 unsigned long serial_number_at_timeout;
715 int retries;
716 int allowed;
717 int timeout_per_command;
718 int timeout_total;
719 int timeout;
722 * We handle the timeout differently if it happens when a reset,
723 * abort, etc are in process.
725 unsigned volatile char internal_timeout;
726 struct scsi_cmnd *bh_next; /* To enumerate the commands waiting
727 to be processed. */
729 /* public: */
731 unsigned int target;
732 unsigned int lun;
733 unsigned int channel;
734 unsigned char cmd_len;
735 unsigned char old_cmd_len;
736 unsigned char sc_data_direction;
737 unsigned char sc_old_data_direction;
739 /* These elements define the operation we are about to perform */
740 unsigned char cmnd[MAX_COMMAND_SIZE];
741 unsigned request_bufflen; /* Actual request size */
743 struct timer_list eh_timeout; /* Used to time out the command. */
744 void *request_buffer; /* Actual requested buffer */
746 /* These elements define the operation we ultimately want to perform */
747 unsigned char data_cmnd[MAX_COMMAND_SIZE];
748 unsigned short old_use_sg; /* We save use_sg here when requesting
749 * sense info */
750 unsigned short use_sg; /* Number of pieces of scatter-gather */
751 unsigned short sglist_len; /* size of malloc'd scatter-gather list */
752 unsigned short abort_reason; /* If the mid-level code requests an
753 * abort, this is the reason. */
754 unsigned bufflen; /* Size of data buffer */
755 void *buffer; /* Data buffer */
757 unsigned underflow; /* Return error if less than
758 this amount is transfered */
759 unsigned old_underflow; /* save underflow here when reusing the
760 * command for error handling */
762 unsigned transfersize; /* How much we are guaranteed to
763 transfer with each SCSI transfer
764 (ie, between disconnect /
765 reconnects. Probably == sector
766 size */
768 int resid; /* Number of bytes requested to be
769 transferred less actual number
770 transferred (0 if not supported) */
772 struct request request; /* A copy of the command we are
773 working on */
775 unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
776 * when CHECK CONDITION is
777 * received on original command
778 * (auto-sense) */
780 unsigned flags;
783 * Used to indicate that a command which has timed out also
784 * completed normally. Typically the completion function will
785 * do nothing but set this flag in this instance because the
786 * timeout handler is already running.
788 unsigned done_late:1;
790 /* Low-level done function - can be used by low-level driver to point
791 * to completion function. Not used by mid/upper level code. */
792 void (*scsi_done) (struct scsi_cmnd *);
795 * The following fields can be written to by the host specific code.
796 * Everything else should be left alone.
799 Scsi_Pointer SCp; /* Scratchpad used by some host adapters */
801 unsigned char *host_scribble; /* The host adapter is allowed to
802 * call scsi_malloc and get some memory
803 * and hang it here. The host adapter
804 * is also expected to call scsi_free
805 * to release this memory. (The memory
806 * obtained by scsi_malloc is guaranteed
807 * to be at an address < 16Mb). */
809 int result; /* Status code from lower level driver */
811 unsigned char tag; /* SCSI-II queued command tag */
812 unsigned long pid; /* Process ID, starts at 0 */
816 * Flag bit for the internal_timeout array
818 #define NORMAL_TIMEOUT 0
821 * Definitions and prototypes used for scsi mid-level queue.
823 #define SCSI_MLQUEUE_HOST_BUSY 0x1055
824 #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
826 #define SCSI_SLEEP(QUEUE, CONDITION) { \
827 if (CONDITION) { \
828 DECLARE_WAITQUEUE(wait, current); \
829 add_wait_queue(QUEUE, &wait); \
830 for(;;) { \
831 set_current_state(TASK_UNINTERRUPTIBLE); \
832 if (CONDITION) { \
833 if (in_interrupt()) \
834 panic("scsi: trying to call schedule() in interrupt" \
835 ", file %s, line %d.\n", __FILE__, __LINE__); \
836 schedule(); \
838 else \
839 break; \
841 remove_wait_queue(QUEUE, &wait);\
842 current->state = TASK_RUNNING; \
843 }; }
845 #endif
848 * Overrides for Emacs so that we follow Linus's tabbing style.
849 * Emacs will notice this stuff at the end of the file and automatically
850 * adjust the settings for this buffer only. This must remain at the end
851 * of the file.
852 * ---------------------------------------------------------------------------
853 * Local variables:
854 * c-indent-level: 4
855 * c-brace-imaginary-offset: 0
856 * c-brace-offset: -4
857 * c-argdecl-indent: 4
858 * c-label-offset: -4
859 * c-continued-statement-offset: 4
860 * c-continued-brace-offset: 0
861 * indent-tabs-mode: nil
862 * tab-width: 8
863 * End: