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
10 * Modified by Eric Youngdale eric@andante.org to
11 * add scatter-gather, multiple outstanding request, and other
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>
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
47 * Some defs, in case these are not defined elsewhere.
56 #define MAX_SCSI_DEVICE_CODE 14
57 extern const char *const scsi_device_types
[MAX_SCSI_DEVICE_CODE
];
60 #define SCSI_TIMEOUT (5*HZ)
62 #define SCSI_TIMEOUT (2*HZ)
66 * Used for debugging the new queueing code. We want to make sure
67 * that the lock state is consistent with design. Only do this in
68 * the user space simulator.
70 #define ASSERT_LOCK(_LOCK, _COUNT)
72 #if defined(__SMP__) && defined(CONFIG_USER_DEBUG)
74 #define ASSERT_LOCK(_LOCK,_COUNT) \
75 { if( (_LOCK)->lock != _COUNT ) \
76 panic("Lock count inconsistent %s %d\n", __FILE__, __LINE__); \
81 * Use these to separate status msg and our bytes
85 * status byte = set from target device
86 * msg_byte = return status from host adapter itself.
87 * host_byte = set by low-level driver to indicate status.
88 * driver_byte = set by mid-level.
90 #define status_byte(result) (((result) >> 1) & 0x1f)
91 #define msg_byte(result) (((result) >> 8) & 0xff)
92 #define host_byte(result) (((result) >> 16) & 0xff)
93 #define driver_byte(result) (((result) >> 24) & 0xff)
94 #define suggestion(result) (driver_byte(result) & SUGGEST_MASK)
96 #define sense_class(sense) (((sense) >> 4) & 0x7)
97 #define sense_error(sense) ((sense) & 0xf)
98 #define sense_valid(sense) ((sense) & 0x80);
100 #define NEEDS_RETRY 0x2001
101 #define SUCCESS 0x2002
102 #define FAILED 0x2003
103 #define QUEUED 0x2004
104 #define SOFT_ERROR 0x2005
105 #define ADD_TO_MLQUEUE 0x2006
108 * These are the values that scsi_cmd->state can take.
110 #define SCSI_STATE_TIMEOUT 0x1000
111 #define SCSI_STATE_FINISHED 0x1001
112 #define SCSI_STATE_FAILED 0x1002
113 #define SCSI_STATE_QUEUED 0x1003
114 #define SCSI_STATE_UNUSED 0x1006
115 #define SCSI_STATE_DISCONNECTING 0x1008
116 #define SCSI_STATE_INITIALIZING 0x1009
117 #define SCSI_STATE_BHQUEUE 0x100a
118 #define SCSI_STATE_MLQUEUE 0x100b
121 * These are the values that the owner field can take.
122 * They are used as an indication of who the command belongs to.
124 #define SCSI_OWNER_HIGHLEVEL 0x100
125 #define SCSI_OWNER_MIDLEVEL 0x101
126 #define SCSI_OWNER_LOWLEVEL 0x102
127 #define SCSI_OWNER_ERROR_HANDLER 0x103
128 #define SCSI_OWNER_BH_HANDLER 0x104
129 #define SCSI_OWNER_NOBODY 0x105
131 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
133 #define IDENTIFY_BASE 0x80
134 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
135 ((can_disconnect) ? 0x40 : 0) |\
140 * This defines the scsi logging feature. It is a means by which the
141 * user can select how much information they get about various goings on,
142 * and it can be really useful for fault tracing. The logging word is divided
143 * into 8 nibbles, each of which describes a loglevel. The division of things
144 * is somewhat arbitrary, and the division of the word could be changed if it
145 * were really needed for any reason. The numbers below are the only place where these
146 * are specified. For a first go-around, 3 bits is more than enough, since this
147 * gives 8 levels of logging (really 7, since 0 is always off). Cutting to 2 bits
148 * might be wise at some point.
151 #define SCSI_LOG_ERROR_SHIFT 0
152 #define SCSI_LOG_TIMEOUT_SHIFT 3
153 #define SCSI_LOG_SCAN_SHIFT 6
154 #define SCSI_LOG_MLQUEUE_SHIFT 9
155 #define SCSI_LOG_MLCOMPLETE_SHIFT 12
156 #define SCSI_LOG_LLQUEUE_SHIFT 15
157 #define SCSI_LOG_LLCOMPLETE_SHIFT 18
158 #define SCSI_LOG_HLQUEUE_SHIFT 21
159 #define SCSI_LOG_HLCOMPLETE_SHIFT 24
160 #define SCSI_LOG_IOCTL_SHIFT 27
162 #define SCSI_LOG_ERROR_BITS 3
163 #define SCSI_LOG_TIMEOUT_BITS 3
164 #define SCSI_LOG_SCAN_BITS 3
165 #define SCSI_LOG_MLQUEUE_BITS 3
166 #define SCSI_LOG_MLCOMPLETE_BITS 3
167 #define SCSI_LOG_LLQUEUE_BITS 3
168 #define SCSI_LOG_LLCOMPLETE_BITS 3
169 #define SCSI_LOG_HLQUEUE_BITS 3
170 #define SCSI_LOG_HLCOMPLETE_BITS 3
171 #define SCSI_LOG_IOCTL_BITS 3
173 #if CONFIG_SCSI_LOGGING
175 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) \
179 mask = (1 << (BITS)) - 1; \
180 if( ((scsi_logging_level >> (SHIFT)) & mask) > (LEVEL) ) \
186 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL) \
190 mask = ((1 << (BITS)) - 1) << SHIFT; \
191 scsi_logging_level = ((scsi_logging_level & ~mask) \
192 | ((LEVEL << SHIFT) & mask)); \
200 * With no logging enabled, stub these out so they don't do anything.
202 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL)
204 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
208 * These are the macros that are actually used throughout the code to
209 * log events. If logging isn't enabled, they are no-ops and will be
210 * completely absent from the user's code.
212 * The 'set' versions of the macros are really intended to only be called
213 * from the /proc filesystem, and in production kernels this will be about
214 * all that is ever used. It could be useful in a debugging environment to
215 * bump the logging level when certain strange events are detected, however.
217 #define SCSI_LOG_ERROR_RECOVERY(LEVEL,CMD) \
218 SCSI_CHECK_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL,CMD);
219 #define SCSI_LOG_TIMEOUT(LEVEL,CMD) \
220 SCSI_CHECK_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL,CMD);
221 #define SCSI_LOG_SCAN_BUS(LEVEL,CMD) \
222 SCSI_CHECK_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL,CMD);
223 #define SCSI_LOG_MLQUEUE(LEVEL,CMD) \
224 SCSI_CHECK_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL,CMD);
225 #define SCSI_LOG_MLCOMPLETE(LEVEL,CMD) \
226 SCSI_CHECK_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL,CMD);
227 #define SCSI_LOG_LLQUEUE(LEVEL,CMD) \
228 SCSI_CHECK_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL,CMD);
229 #define SCSI_LOG_LLCOMPLETE(LEVEL,CMD) \
230 SCSI_CHECK_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL,CMD);
231 #define SCSI_LOG_HLQUEUE(LEVEL,CMD) \
232 SCSI_CHECK_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL,CMD);
233 #define SCSI_LOG_HLCOMPLETE(LEVEL,CMD) \
234 SCSI_CHECK_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL,CMD);
235 #define SCSI_LOG_IOCTL(LEVEL,CMD) \
236 SCSI_CHECK_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL,CMD);
239 #define SCSI_SET_ERROR_RECOVERY_LOGGING(LEVEL) \
240 SCSI_SET_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL);
241 #define SCSI_SET_TIMEOUT_LOGGING(LEVEL) \
242 SCSI_SET_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL);
243 #define SCSI_SET_SCAN_BUS_LOGGING(LEVEL) \
244 SCSI_SET_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL);
245 #define SCSI_SET_MLQUEUE_LOGGING(LEVEL) \
246 SCSI_SET_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL);
247 #define SCSI_SET_MLCOMPLETE_LOGGING(LEVEL) \
248 SCSI_SET_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL);
249 #define SCSI_SET_LLQUEUE_LOGGING(LEVEL) \
250 SCSI_SET_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL);
251 #define SCSI_SET_LLCOMPLETE_LOGGING(LEVEL) \
252 SCSI_SET_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL);
253 #define SCSI_SET_HLQUEUE_LOGGING(LEVEL) \
254 SCSI_SET_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL);
255 #define SCSI_SET_HLCOMPLETE_LOGGING(LEVEL) \
256 SCSI_SET_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL);
257 #define SCSI_SET_IOCTL_LOGGING(LEVEL) \
258 SCSI_SET_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL);
261 * the return of the status word will be in the following format :
262 * The low byte is the status returned by the SCSI command,
263 * with vendor specific bits masked.
265 * The next byte is the message which followed the SCSI status.
266 * This allows a stos to be used, since the Intel is a little
269 * The final byte is a host return code, which is one of the following.
273 * status msg host code
275 * Our errors returned by OUR driver, NOT SCSI message. Or'd with
276 * SCSI message passed back to driver <IF any>.
280 #define DID_OK 0x00 /* NO error */
281 #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
282 #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
283 #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
284 #define DID_BAD_TARGET 0x04 /* BAD target. */
285 #define DID_ABORT 0x05 /* Told to abort for some other reason */
286 #define DID_PARITY 0x06 /* Parity error */
287 #define DID_ERROR 0x07 /* Internal error */
288 #define DID_RESET 0x08 /* Reset by somebody. */
289 #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
290 #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
291 #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
292 #define DRIVER_OK 0x00 /* Driver status */
295 * These indicate the error that occurred, and what is available.
298 #define DRIVER_BUSY 0x01
299 #define DRIVER_SOFT 0x02
300 #define DRIVER_MEDIA 0x03
301 #define DRIVER_ERROR 0x04
303 #define DRIVER_INVALID 0x05
304 #define DRIVER_TIMEOUT 0x06
305 #define DRIVER_HARD 0x07
306 #define DRIVER_SENSE 0x08
308 #define SUGGEST_RETRY 0x10
309 #define SUGGEST_ABORT 0x20
310 #define SUGGEST_REMAP 0x30
311 #define SUGGEST_DIE 0x40
312 #define SUGGEST_SENSE 0x80
313 #define SUGGEST_IS_OK 0xff
315 #define DRIVER_MASK 0x0f
316 #define SUGGEST_MASK 0xf0
318 #define MAX_COMMAND_SIZE 12
319 #define SCSI_SENSE_BUFFERSIZE 64
325 #define SCSI_UNKNOWN 0
332 * Every SCSI command starts with a one byte OP-code.
333 * The next byte's high three bits are the LUN of the
334 * device. Any multi-byte quantities are stored high byte
335 * first, and may have a 5 bit MSB in the same byte
340 * As the scsi do command functions are intelligent, and may need to
341 * redo a command, we need to keep track of the last command
342 * executed on each one.
345 #define WAS_RESET 0x01
346 #define WAS_TIMEDOUT 0x02
347 #define WAS_SENSE 0x04
348 #define IS_RESETTING 0x08
349 #define IS_ABORTING 0x10
350 #define ASKED_FOR_SENSE 0x20
351 #define SYNC_RESET 0x40
353 #if defined(__mc68000__) || defined(CONFIG_APUS)
354 #include <asm/pgtable.h>
355 #define CONTIGUOUS_BUFFERS(X,Y) \
356 (virt_to_phys((X)->b_data+(X)->b_size-1)+1==virt_to_phys((Y)->b_data))
358 #define CONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data)
363 * This is the crap from the old error handling code. We have it in a special
364 * place so that we can more easily delete it later on.
366 #include "scsi_obsolete.h"
369 * Add some typedefs so that we can prototyope a bunch of the functions.
371 typedef struct scsi_device Scsi_Device
;
372 typedef struct scsi_cmnd Scsi_Cmnd
;
373 typedef struct scsi_request Scsi_Request
;
375 #define SCSI_CMND_MAGIC 0xE25C23A5
376 #define SCSI_REQ_MAGIC 0x75F6D354
379 * Here is where we prototype most of the mid-layer.
383 * Initializes all SCSI devices. This scans all scsi busses.
386 extern unsigned int scsi_logging_level
; /* What do we log? */
387 extern unsigned int scsi_dma_free_sectors
; /* How much room do we have left */
388 extern unsigned int scsi_need_isa_buffer
; /* True if some devices need indirection
390 extern volatile int in_scan_scsis
;
391 extern const unsigned char scsi_command_size
[8];
395 * These are the error handling functions defined in scsi_error.c
397 extern void scsi_times_out(Scsi_Cmnd
* SCpnt
);
398 extern void scsi_add_timer(Scsi_Cmnd
* SCset
, int timeout
,
399 void (*complete
) (Scsi_Cmnd
*));
400 extern int scsi_delete_timer(Scsi_Cmnd
* SCset
);
401 extern void scsi_error_handler(void *host
);
402 extern int scsi_sense_valid(Scsi_Cmnd
*);
403 extern int scsi_decide_disposition(Scsi_Cmnd
* SCpnt
);
404 extern int scsi_block_when_processing_errors(Scsi_Device
*);
405 extern void scsi_sleep(int);
408 * Prototypes for functions in scsicam.c
410 extern int scsi_partsize(struct buffer_head
*bh
, unsigned long capacity
,
411 unsigned int *cyls
, unsigned int *hds
,
415 * Prototypes for functions in scsi_dma.c
417 void scsi_resize_dma_pool(void);
418 int scsi_init_minimal_dma_pool(void);
419 void *scsi_malloc(unsigned int);
420 int scsi_free(void *, unsigned int);
423 * Prototypes for functions in scsi_merge.c
425 extern void recount_segments(Scsi_Cmnd
* SCpnt
);
426 extern void initialize_merge_fn(Scsi_Device
* SDpnt
);
429 * Prototypes for functions in scsi_queue.c
431 extern int scsi_mlqueue_insert(Scsi_Cmnd
* cmd
, int reason
);
434 * Prototypes for functions in scsi_lib.c
436 extern int scsi_maybe_unblock_host(Scsi_Device
* SDpnt
);
437 extern Scsi_Cmnd
*scsi_end_request(Scsi_Cmnd
* SCpnt
, int uptodate
,
439 extern struct Scsi_Device_Template
*scsi_get_request_dev(struct request
*);
440 extern int scsi_init_cmd_errh(Scsi_Cmnd
* SCpnt
);
441 extern int scsi_insert_special_cmd(Scsi_Cmnd
* SCpnt
, int);
442 extern void scsi_io_completion(Scsi_Cmnd
* SCpnt
, int good_sectors
,
444 extern void scsi_queue_next_request(request_queue_t
* q
, Scsi_Cmnd
* SCpnt
);
445 extern void scsi_request_fn(request_queue_t
* q
);
446 extern int scsi_starvation_completion(Scsi_Device
* SDpnt
);
449 * Prototypes for functions in scsi.c
451 extern int scsi_dispatch_cmd(Scsi_Cmnd
* SCpnt
);
452 extern void scsi_bottom_half_handler(void);
453 extern void scsi_release_commandblocks(Scsi_Device
* SDpnt
);
454 extern void scsi_build_commandblocks(Scsi_Device
* SDpnt
);
455 extern void scsi_done(Scsi_Cmnd
* SCpnt
);
456 extern void scsi_finish_command(Scsi_Cmnd
*);
457 extern int scsi_retry_command(Scsi_Cmnd
*);
458 extern Scsi_Cmnd
*scsi_allocate_device(Scsi_Device
*, int, int);
459 extern void scsi_release_command(Scsi_Cmnd
*);
460 extern void scsi_do_cmd(Scsi_Cmnd
*, const void *cmnd
,
461 void *buffer
, unsigned bufflen
,
462 void (*done
) (struct scsi_cmnd
*),
463 int timeout
, int retries
);
464 extern void scsi_wait_cmd(Scsi_Cmnd
*, const void *cmnd
,
465 void *buffer
, unsigned bufflen
,
466 int timeout
, int retries
);
467 extern int scsi_dev_init(void);
470 * Newer request-based interfaces.
472 extern Scsi_Request
*scsi_allocate_request(Scsi_Device
*);
473 extern void scsi_release_request(Scsi_Request
*);
474 extern void scsi_wait_req(Scsi_Request
*, const void *cmnd
,
475 void *buffer
, unsigned bufflen
,
476 int timeout
, int retries
);
478 extern void scsi_do_req(Scsi_Request
*, const void *cmnd
,
479 void *buffer
, unsigned bufflen
,
480 void (*done
) (struct scsi_cmnd
*),
481 int timeout
, int retries
);
482 extern int scsi_insert_special_req(Scsi_Request
* SRpnt
, int);
483 extern void scsi_init_cmd_from_req(Scsi_Cmnd
*, Scsi_Request
*);
487 * Prototypes for functions/data in hosts.c
489 extern int max_scsi_hosts
;
492 * Prototypes for functions in scsi_proc.c
494 extern void proc_print_scsidevice(Scsi_Device
*, char *, int *, int);
495 extern struct proc_dir_entry
*proc_scsi
;
498 * Prototypes for functions in constants.c
500 extern void print_command(unsigned char *);
501 extern void print_sense(const char *, Scsi_Cmnd
*);
502 extern void print_req_sense(const char *, Scsi_Request
*);
503 extern void print_driverbyte(int scsiresult
);
504 extern void print_hostbyte(int scsiresult
);
505 extern void print_status (int status
);
508 * The scsi_device struct contains what we know about each given scsi
511 * FIXME(eric) - one of the great regrets that I have is that I failed to define
512 * these structure elements as something like sdev_foo instead of foo. This would
513 * make it so much easier to grep through sources and so forth. I propose that
514 * all new elements that get added to these structures follow this convention.
515 * As time goes on and as people have the stomach for it, it should be possible to
516 * go back and retrofit at least some of the elements here with with the prefix.
522 * This information is private to the scsi mid-layer. Wrapping it in a
523 * struct private is a way of marking it in a sort of C++ type of way.
525 struct scsi_device
*next
; /* Used for linked list */
526 struct scsi_device
*prev
; /* Used for linked list */
527 wait_queue_head_t scpnt_wait
; /* Used to wait if
529 struct Scsi_Host
*host
;
530 request_queue_t request_queue
;
531 atomic_t device_active
; /* commands checked out for device */
532 volatile unsigned short device_busy
; /* commands actually active on low-level */
533 int (*scsi_init_io_fn
) (Scsi_Cmnd
*); /* Used to initialize
535 Scsi_Cmnd
*device_queue
; /* queue of SCSI Command structures */
538 unsigned char id
, lun
, channel
;
540 unsigned int manufacturer
; /* Manufacturer of device, for using
541 * vendor-specific cmd's */
542 unsigned sector_size
; /* size in bytes */
544 int attached
; /* # of high level drivers attached to
546 int access_count
; /* Count of open channels/mounts */
548 void *hostdata
; /* available to low-level driver */
549 devfs_handle_t de
; /* directory for the device */
552 char vendor
[8], model
[16], rev
[4];
553 unsigned char current_tag
; /* current tag */
554 unsigned char sync_min_period
; /* Not less than this period */
555 unsigned char sync_max_offset
; /* Not greater than this offset */
556 unsigned char queue_depth
; /* How deep a queue to use */
559 unsigned writeable
:1;
560 unsigned removable
:1;
562 unsigned has_cmdblocks
:1;
563 unsigned changed
:1; /* Data invalid due to media change */
564 unsigned busy
:1; /* Used to prevent races */
565 unsigned lockable
:1; /* Able to prevent media removal */
566 unsigned borken
:1; /* Tell the Seagate driver to be
567 * painfully slow on this device */
568 unsigned tagged_supported
:1; /* Supports SCSI-II tagged queuing */
569 unsigned tagged_queue
:1; /* SCSI-II tagged queuing enabled */
570 unsigned disconnect
:1; /* can disconnect */
571 unsigned soft_reset
:1; /* Uses soft reset option */
572 unsigned sync
:1; /* Negotiate for sync transfers */
573 unsigned wide
:1; /* Negotiate for WIDE transfers */
574 unsigned single_lun
:1; /* Indicates we should only allow I/O to
575 * one of the luns for the device at a
577 unsigned was_reset
:1; /* There was a bus reset on the bus for
579 unsigned expecting_cc_ua
:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
580 * because we did a bus reset. */
581 unsigned device_blocked
:1; /* Device returned QUEUE_FULL. */
582 unsigned ten
:1; /* support ten byte read / write */
583 unsigned remap
:1; /* support remapping */
584 unsigned starved
:1; /* unable to process commands because
590 * The Scsi_Cmnd structure is used by scsi.c internally, and for communication
591 * with low level drivers that support multiple outstanding commands.
593 typedef struct scsi_pointer
{
594 char *ptr
; /* data pointer */
595 int this_residual
; /* left in this buffer */
596 struct scatterlist
*buffer
; /* which buffer */
597 int buffers_residual
; /* how many buffers left */
600 volatile int Message
;
601 volatile int have_data_in
;
602 volatile int sent_command
;
607 * This is essentially a slimmed down version of Scsi_Cmnd. The point of
608 * having this is that requests that are injected into the queue as result
609 * of things like ioctls and character devices shouldn't be using a
610 * Scsi_Cmnd until such a time that the command is actually at the head
611 * of the queue and being sent to the driver.
613 struct scsi_request
{
615 int sr_result
; /* Status code from lower level driver */
616 unsigned char sr_sense_buffer
[SCSI_SENSE_BUFFERSIZE
]; /* obtained by REQUEST SENSE
617 * when CHECK CONDITION is
618 * received on original command
621 struct Scsi_Host
*sr_host
;
622 Scsi_Device
*sr_device
;
623 Scsi_Cmnd
*sr_command
;
624 struct request sr_request
; /* A copy of the command we are
626 unsigned sr_bufflen
; /* Size of data buffer */
627 void *sr_buffer
; /* Data buffer */
629 unsigned char sr_data_direction
;
630 unsigned char sr_cmd_len
;
631 unsigned char sr_cmnd
[MAX_COMMAND_SIZE
];
632 void (*sr_done
) (struct scsi_cmnd
*); /* Mid-level done function */
633 int sr_timeout_per_command
;
634 unsigned short sr_use_sg
; /* Number of pieces of scatter-gather */
635 unsigned short sr_sglist_len
; /* size of malloc'd scatter-gather list */
636 unsigned sr_underflow
; /* Return error if less than
637 this amount is transfered */
641 * FIXME(eric) - one of the great regrets that I have is that I failed to define
642 * these structure elements as something like sc_foo instead of foo. This would
643 * make it so much easier to grep through sources and so forth. I propose that
644 * all new elements that get added to these structures follow this convention.
645 * As time goes on and as people have the stomach for it, it should be possible to
646 * go back and retrofit at least some of the elements here with with the prefix.
652 * This information is private to the scsi mid-layer. Wrapping it in a
653 * struct private is a way of marking it in a sort of C++ type of way.
655 struct Scsi_Host
*host
;
656 unsigned short state
;
657 unsigned short owner
;
659 Scsi_Request
*sc_request
;
660 struct scsi_cmnd
*next
;
661 struct scsi_cmnd
*reset_chain
;
663 int eh_state
; /* Used for state tracking in error handlr */
664 void (*done
) (struct scsi_cmnd
*); /* Mid-level done function */
666 A SCSI Command is assigned a nonzero serial_number when internal_cmnd
667 passes it to the driver's queue command function. The serial_number
668 is cleared when scsi_done is entered indicating that the command has
669 been completed. If a timeout occurs, the serial number at the moment
670 of timeout is copied into serial_number_at_timeout. By subsequently
671 comparing the serial_number and serial_number_at_timeout fields
672 during abort or reset processing, we can detect whether the command
673 has already completed. This also detects cases where the command has
674 completed and the SCSI Command structure has already being reused
675 for another command, so that we can avoid incorrectly aborting or
676 resetting the new command.
679 unsigned long serial_number
;
680 unsigned long serial_number_at_timeout
;
684 int timeout_per_command
;
689 * We handle the timeout differently if it happens when a reset,
690 * abort, etc are in process.
692 unsigned volatile char internal_timeout
;
693 struct scsi_cmnd
*bh_next
; /* To enumerate the commands waiting
698 unsigned char target
;
700 unsigned char channel
;
701 unsigned char cmd_len
;
702 unsigned char old_cmd_len
;
703 unsigned char sc_data_direction
;
704 unsigned char sc_old_data_direction
;
706 /* These elements define the operation we are about to perform */
707 unsigned char cmnd
[MAX_COMMAND_SIZE
];
708 unsigned request_bufflen
; /* Actual request size */
710 struct timer_list eh_timeout
; /* Used to time out the command. */
711 void *request_buffer
; /* Actual requested buffer */
713 /* These elements define the operation we ultimately want to perform */
714 unsigned char data_cmnd
[MAX_COMMAND_SIZE
];
715 unsigned short old_use_sg
; /* We save use_sg here when requesting
717 unsigned short use_sg
; /* Number of pieces of scatter-gather */
718 unsigned short sglist_len
; /* size of malloc'd scatter-gather list */
719 unsigned short abort_reason
; /* If the mid-level code requests an
720 * abort, this is the reason. */
721 unsigned bufflen
; /* Size of data buffer */
722 void *buffer
; /* Data buffer */
724 unsigned underflow
; /* Return error if less than
725 this amount is transfered */
727 unsigned transfersize
; /* How much we are guaranteed to
728 transfer with each SCSI transfer
729 (ie, between disconnect /
730 reconnects. Probably == sector
733 int resid
; /* Number of bytes requested to be
734 transferred less actual number
735 transferred (0 if not supported) */
737 struct request request
; /* A copy of the command we are
740 unsigned char sense_buffer
[SCSI_SENSE_BUFFERSIZE
]; /* obtained by REQUEST SENSE
741 * when CHECK CONDITION is
742 * received on original command
748 * Used to indicate that a command which has timed out also
749 * completed normally. Typically the completion function will
750 * do nothing but set this flag in this instance because the
751 * timeout handler is already running.
753 unsigned done_late
:1;
755 /* Low-level done function - can be used by low-level driver to point
756 * to completion function. Not used by mid/upper level code. */
757 void (*scsi_done
) (struct scsi_cmnd
*);
760 * The following fields can be written to by the host specific code.
761 * Everything else should be left alone.
764 Scsi_Pointer SCp
; /* Scratchpad used by some host adapters */
766 unsigned char *host_scribble
; /* The host adapter is allowed to
767 * call scsi_malloc and get some memory
768 * and hang it here. The host adapter
769 * is also expected to call scsi_free
770 * to release this memory. (The memory
771 * obtained by scsi_malloc is guaranteed
772 * to be at an address < 16Mb). */
774 int result
; /* Status code from lower level driver */
776 unsigned char tag
; /* SCSI-II queued command tag */
777 unsigned long pid
; /* Process ID, starts at 0 */
781 * Flag bit for the internal_timeout array
783 #define NORMAL_TIMEOUT 0
786 * Definitions and prototypes used for scsi mid-level queue.
788 #define SCSI_MLQUEUE_HOST_BUSY 0x1055
789 #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
791 #define SCSI_SLEEP(QUEUE, CONDITION) { \
793 DECLARE_WAITQUEUE(wait, current); \
794 add_wait_queue(QUEUE, &wait); \
796 set_current_state(TASK_UNINTERRUPTIBLE); \
798 if (in_interrupt()) \
799 panic("scsi: trying to call schedule() in interrupt" \
800 ", file %s, line %d.\n", __FILE__, __LINE__); \
806 remove_wait_queue(QUEUE, &wait);\
807 current->state = TASK_RUNNING; \
813 * Overrides for Emacs so that we follow Linus's tabbing style.
814 * Emacs will notice this stuff at the end of the file and automatically
815 * adjust the settings for this buffer only. This must remain at the end
817 * ---------------------------------------------------------------------------
820 * c-brace-imaginary-offset: 0
822 * c-argdecl-indent: 4
824 * c-continued-statement-offset: 4
825 * c-continued-brace-offset: 0
826 * indent-tabs-mode: nil