Import 2.3.18pre1
[davej-history.git] / drivers / scsi / scsi.h
blob31661b3f0390732936771ff292de5f74ff56eb9d
1 /*
2 * scsi.h Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995 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@aib.com 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 */
21 * Some of the public constants are being moved to this file.
22 * We include it here so that what came from where is transparent.
24 #include <scsi/scsi.h>
26 #include <linux/random.h>
28 #include <asm/hardirq.h>
29 #include <asm/scatterlist.h>
30 #include <asm/io.h>
33 * Some defs, in case these are not defined elsewhere.
35 #ifndef TRUE
36 #define TRUE 1
37 #endif
38 #ifndef FALSE
39 #define FALSE 0
40 #endif
42 #define MAX_SCSI_DEVICE_CODE 14
43 extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE];
45 #ifdef DEBUG
46 #define SCSI_TIMEOUT (5*HZ)
47 #else
48 #define SCSI_TIMEOUT (2*HZ)
49 #endif
52 * Use these to separate status msg and our bytes
54 * These are set by:
56 * status byte = set from target device
57 * msg_byte = return status from host adapter itself.
58 * host_byte = set by low-level driver to indicate status.
59 * driver_byte = set by mid-level.
61 #define status_byte(result) (((result) >> 1) & 0x1f)
62 #define msg_byte(result) (((result) >> 8) & 0xff)
63 #define host_byte(result) (((result) >> 16) & 0xff)
64 #define driver_byte(result) (((result) >> 24) & 0xff)
65 #define suggestion(result) (driver_byte(result) & SUGGEST_MASK)
67 #define sense_class(sense) (((sense) >> 4) & 0x7)
68 #define sense_error(sense) ((sense) & 0xf)
69 #define sense_valid(sense) ((sense) & 0x80);
71 #define NEEDS_RETRY 0x2001
72 #define SUCCESS 0x2002
73 #define FAILED 0x2003
74 #define QUEUED 0x2004
75 #define SOFT_ERROR 0x2005
76 #define ADD_TO_MLQUEUE 0x2006
79 * These are the values that scsi_cmd->state can take.
81 #define SCSI_STATE_TIMEOUT 0x1000
82 #define SCSI_STATE_FINISHED 0x1001
83 #define SCSI_STATE_FAILED 0x1002
84 #define SCSI_STATE_QUEUED 0x1003
85 #define SCSI_STATE_UNUSED 0x1006
86 #define SCSI_STATE_DISCONNECTING 0x1008
87 #define SCSI_STATE_INITIALIZING 0x1009
88 #define SCSI_STATE_BHQUEUE 0x100a
89 #define SCSI_STATE_MLQUEUE 0x100b
92 * These are the values that the owner field can take.
93 * They are used as an indication of who the command belongs to.
95 #define SCSI_OWNER_HIGHLEVEL 0x100
96 #define SCSI_OWNER_MIDLEVEL 0x101
97 #define SCSI_OWNER_LOWLEVEL 0x102
98 #define SCSI_OWNER_ERROR_HANDLER 0x103
99 #define SCSI_OWNER_BH_HANDLER 0x104
100 #define SCSI_OWNER_NOBODY 0x105
102 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
104 #define IDENTIFY_BASE 0x80
105 #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
106 ((can_disconnect) ? 0x40 : 0) |\
107 ((lun) & 0x07))
111 * This defines the scsi logging feature. It is a means by which the
112 * user can select how much information they get about various goings on,
113 * and it can be really useful for fault tracing. The logging word is divided
114 * into 8 nibbles, each of which describes a loglevel. The division of things
115 * is somewhat arbitrary, and the division of the word could be changed if it
116 * were really needed for any reason. The numbers below are the only place where these
117 * are specified. For a first go-around, 3 bits is more than enough, since this
118 * gives 8 levels of logging (really 7, since 0 is always off). Cutting to 2 bits
119 * might be wise at some point.
122 #define SCSI_LOG_ERROR_SHIFT 0
123 #define SCSI_LOG_TIMEOUT_SHIFT 3
124 #define SCSI_LOG_SCAN_SHIFT 6
125 #define SCSI_LOG_MLQUEUE_SHIFT 9
126 #define SCSI_LOG_MLCOMPLETE_SHIFT 12
127 #define SCSI_LOG_LLQUEUE_SHIFT 15
128 #define SCSI_LOG_LLCOMPLETE_SHIFT 18
129 #define SCSI_LOG_HLQUEUE_SHIFT 21
130 #define SCSI_LOG_HLCOMPLETE_SHIFT 24
131 #define SCSI_LOG_IOCTL_SHIFT 27
133 #define SCSI_LOG_ERROR_BITS 3
134 #define SCSI_LOG_TIMEOUT_BITS 3
135 #define SCSI_LOG_SCAN_BITS 3
136 #define SCSI_LOG_MLQUEUE_BITS 3
137 #define SCSI_LOG_MLCOMPLETE_BITS 3
138 #define SCSI_LOG_LLQUEUE_BITS 3
139 #define SCSI_LOG_LLCOMPLETE_BITS 3
140 #define SCSI_LOG_HLQUEUE_BITS 3
141 #define SCSI_LOG_HLCOMPLETE_BITS 3
142 #define SCSI_LOG_IOCTL_BITS 3
144 #if CONFIG_SCSI_LOGGING
146 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) \
148 unsigned int mask; \
150 mask = (1 << (BITS)) - 1; \
151 if( ((scsi_logging_level >> (SHIFT)) & mask) > (LEVEL) ) \
153 (CMD); \
157 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL) \
159 unsigned int mask; \
161 mask = ((1 << (BITS)) - 1) << SHIFT; \
162 scsi_logging_level = ((scsi_logging_level & ~mask) \
163 | ((LEVEL << SHIFT) & mask)); \
168 #else
171 * With no logging enabled, stub these out so they don't do anything.
173 #define SCSI_SET_LOGGING(SHIFT, BITS, LEVEL)
175 #define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
176 #endif
179 * These are the macros that are actually used throughout the code to
180 * log events. If logging isn't enabled, they are no-ops and will be
181 * completely absent from the user's code.
183 * The 'set' versions of the macros are really intended to only be called
184 * from the /proc filesystem, and in production kernels this will be about
185 * all that is ever used. It could be useful in a debugging environment to
186 * bump the logging level when certain strange events are detected, however.
188 #define SCSI_LOG_ERROR_RECOVERY(LEVEL,CMD) \
189 SCSI_CHECK_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL,CMD);
190 #define SCSI_LOG_TIMEOUT(LEVEL,CMD) \
191 SCSI_CHECK_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL,CMD);
192 #define SCSI_LOG_SCAN_BUS(LEVEL,CMD) \
193 SCSI_CHECK_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL,CMD);
194 #define SCSI_LOG_MLQUEUE(LEVEL,CMD) \
195 SCSI_CHECK_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL,CMD);
196 #define SCSI_LOG_MLCOMPLETE(LEVEL,CMD) \
197 SCSI_CHECK_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL,CMD);
198 #define SCSI_LOG_LLQUEUE(LEVEL,CMD) \
199 SCSI_CHECK_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL,CMD);
200 #define SCSI_LOG_LLCOMPLETE(LEVEL,CMD) \
201 SCSI_CHECK_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL,CMD);
202 #define SCSI_LOG_HLQUEUE(LEVEL,CMD) \
203 SCSI_CHECK_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL,CMD);
204 #define SCSI_LOG_HLCOMPLETE(LEVEL,CMD) \
205 SCSI_CHECK_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL,CMD);
206 #define SCSI_LOG_IOCTL(LEVEL,CMD) \
207 SCSI_CHECK_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL,CMD);
210 #define SCSI_SET_ERROR_RECOVERY_LOGGING(LEVEL) \
211 SCSI_SET_LOGGING(SCSI_LOG_ERROR_SHIFT, SCSI_LOG_ERROR_BITS, LEVEL);
212 #define SCSI_SET_TIMEOUT_LOGGING(LEVEL) \
213 SCSI_SET_LOGGING(SCSI_LOG_TIMEOUT_SHIFT, SCSI_LOG_TIMEOUT_BITS, LEVEL);
214 #define SCSI_SET_SCAN_BUS_LOGGING(LEVEL) \
215 SCSI_SET_LOGGING(SCSI_LOG_SCAN_SHIFT, SCSI_LOG_SCAN_BITS, LEVEL);
216 #define SCSI_SET_MLQUEUE_LOGGING(LEVEL) \
217 SCSI_SET_LOGGING(SCSI_LOG_MLQUEUE_SHIFT, SCSI_LOG_MLQUEUE_BITS, LEVEL);
218 #define SCSI_SET_MLCOMPLETE_LOGGING(LEVEL) \
219 SCSI_SET_LOGGING(SCSI_LOG_MLCOMPLETE_SHIFT, SCSI_LOG_MLCOMPLETE_BITS, LEVEL);
220 #define SCSI_SET_LLQUEUE_LOGGING(LEVEL) \
221 SCSI_SET_LOGGING(SCSI_LOG_LLQUEUE_SHIFT, SCSI_LOG_LLQUEUE_BITS, LEVEL);
222 #define SCSI_SET_LLCOMPLETE_LOGGING(LEVEL) \
223 SCSI_SET_LOGGING(SCSI_LOG_LLCOMPLETE_SHIFT, SCSI_LOG_LLCOMPLETE_BITS, LEVEL);
224 #define SCSI_SET_HLQUEUE_LOGGING(LEVEL) \
225 SCSI_SET_LOGGING(SCSI_LOG_HLQUEUE_SHIFT, SCSI_LOG_HLQUEUE_BITS, LEVEL);
226 #define SCSI_SET_HLCOMPLETE_LOGGING(LEVEL) \
227 SCSI_SET_LOGGING(SCSI_LOG_HLCOMPLETE_SHIFT, SCSI_LOG_HLCOMPLETE_BITS, LEVEL);
228 #define SCSI_SET_IOCTL_LOGGING(LEVEL) \
229 SCSI_SET_LOGGING(SCSI_LOG_IOCTL_SHIFT, SCSI_LOG_IOCTL_BITS, LEVEL);
232 * the return of the status word will be in the following format :
233 * The low byte is the status returned by the SCSI command,
234 * with vendor specific bits masked.
236 * The next byte is the message which followed the SCSI status.
237 * This allows a stos to be used, since the Intel is a little
238 * endian machine.
240 * The final byte is a host return code, which is one of the following.
242 * IE
243 * lsb msb
244 * status msg host code
246 * Our errors returned by OUR driver, NOT SCSI message. Or'd with
247 * SCSI message passed back to driver <IF any>.
251 #define DID_OK 0x00 /* NO error */
252 #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
253 #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
254 #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
255 #define DID_BAD_TARGET 0x04 /* BAD target. */
256 #define DID_ABORT 0x05 /* Told to abort for some other reason */
257 #define DID_PARITY 0x06 /* Parity error */
258 #define DID_ERROR 0x07 /* Internal error */
259 #define DID_RESET 0x08 /* Reset by somebody. */
260 #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
261 #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
262 #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
263 #define DRIVER_OK 0x00 /* Driver status */
266 * These indicate the error that occurred, and what is available.
269 #define DRIVER_BUSY 0x01
270 #define DRIVER_SOFT 0x02
271 #define DRIVER_MEDIA 0x03
272 #define DRIVER_ERROR 0x04
274 #define DRIVER_INVALID 0x05
275 #define DRIVER_TIMEOUT 0x06
276 #define DRIVER_HARD 0x07
277 #define DRIVER_SENSE 0x08
279 #define SUGGEST_RETRY 0x10
280 #define SUGGEST_ABORT 0x20
281 #define SUGGEST_REMAP 0x30
282 #define SUGGEST_DIE 0x40
283 #define SUGGEST_SENSE 0x80
284 #define SUGGEST_IS_OK 0xff
286 #define DRIVER_MASK 0x0f
287 #define SUGGEST_MASK 0xf0
289 #define MAX_COMMAND_SIZE 12
292 * SCSI command sets
295 #define SCSI_UNKNOWN 0
296 #define SCSI_1 1
297 #define SCSI_1_CCS 2
298 #define SCSI_2 3
299 #define SCSI_3 4
302 * Every SCSI command starts with a one byte OP-code.
303 * The next byte's high three bits are the LUN of the
304 * device. Any multi-byte quantities are stored high byte
305 * first, and may have a 5 bit MSB in the same byte
306 * as the LUN.
310 * As the scsi do command functions are intelligent, and may need to
311 * redo a command, we need to keep track of the last command
312 * executed on each one.
315 #define WAS_RESET 0x01
316 #define WAS_TIMEDOUT 0x02
317 #define WAS_SENSE 0x04
318 #define IS_RESETTING 0x08
319 #define IS_ABORTING 0x10
320 #define ASKED_FOR_SENSE 0x20
321 #define SYNC_RESET 0x40
323 #if defined(__mc68000__) || defined(CONFIG_APUS)
324 #include <asm/pgtable.h>
325 #define CONTIGUOUS_BUFFERS(X,Y) \
326 (virt_to_phys((X)->b_data+(X)->b_size-1)+1==virt_to_phys((Y)->b_data))
327 #else
328 #define CONTIGUOUS_BUFFERS(X,Y) ((X->b_data+X->b_size) == Y->b_data)
329 #endif
333 * This is the crap from the old error handling code. We have it in a special
334 * place so that we can more easily delete it later on.
336 #include "scsi_obsolete.h"
339 * Add some typedefs so that we can prototyope a bunch of the functions.
341 typedef struct scsi_device Scsi_Device;
342 typedef struct scsi_cmnd Scsi_Cmnd;
345 * Here is where we prototype most of the mid-layer.
349 * Initializes all SCSI devices. This scans all scsi busses.
352 extern int scsi_dev_init(void);
356 void *scsi_malloc(unsigned int);
357 int scsi_free(void *, unsigned int);
358 extern unsigned int scsi_logging_level; /* What do we log? */
359 extern unsigned int scsi_dma_free_sectors; /* How much room do we have left */
360 extern unsigned int scsi_need_isa_buffer; /* True if some devices need indirection
361 * buffers */
362 extern void scsi_make_blocked_list(void);
363 extern volatile int in_scan_scsis;
364 extern const unsigned char scsi_command_size[8];
367 * These are the error handling functions defined in scsi_error.c
369 extern void scsi_add_timer(Scsi_Cmnd * SCset, int timeout,
370 void (*complete) (Scsi_Cmnd *));
371 extern void scsi_done(Scsi_Cmnd * SCpnt);
372 extern int scsi_delete_timer(Scsi_Cmnd * SCset);
373 extern void scsi_error_handler(void *host);
374 extern int scsi_retry_command(Scsi_Cmnd *);
375 extern void scsi_finish_command(Scsi_Cmnd *);
376 extern int scsi_sense_valid(Scsi_Cmnd *);
377 extern int scsi_decide_disposition(Scsi_Cmnd * SCpnt);
378 extern int scsi_block_when_processing_errors(Scsi_Device *);
379 extern void scsi_sleep(int);
382 * scsi_abort aborts the current command that is executing on host host.
383 * The error code, if non zero is returned in the host byte, otherwise
384 * DID_ABORT is returned in the hostbyte.
387 extern void scsi_do_cmd(Scsi_Cmnd *, const void *cmnd,
388 void *buffer, unsigned bufflen,
389 void (*done) (struct scsi_cmnd *),
390 int timeout, int retries);
393 extern Scsi_Cmnd *scsi_allocate_device(struct request **, Scsi_Device *, int);
395 extern Scsi_Cmnd *scsi_request_queueable(struct request *, Scsi_Device *);
397 extern void scsi_release_command(Scsi_Cmnd *);
399 extern int max_scsi_hosts;
401 extern void proc_print_scsidevice(Scsi_Device *, char *, int *, int);
403 extern void print_command(unsigned char *);
404 extern void print_sense(const char *, Scsi_Cmnd *);
405 extern void print_driverbyte(int scsiresult);
406 extern void print_hostbyte(int scsiresult);
409 * The scsi_device struct contains what we know about each given scsi
410 * device.
413 struct scsi_device {
414 /* private: */
416 * This information is private to the scsi mid-layer. Wrapping it in a
417 * struct private is a way of marking it in a sort of C++ type of way.
419 struct scsi_device *next; /* Used for linked list */
420 struct scsi_device *prev; /* Used for linked list */
421 wait_queue_head_t device_wait; /* Used to wait if
422 device is busy */
423 struct Scsi_Host *host;
424 volatile unsigned short device_busy; /* commands actually active on low-level */
425 void (*scsi_request_fn) (void); /* Used to jumpstart things after an
426 * ioctl */
427 Scsi_Cmnd *device_queue; /* queue of SCSI Command structures */
429 /* public: */
430 unsigned char id, lun, channel;
432 unsigned int manufacturer; /* Manufacturer of device, for using
433 * vendor-specific cmd's */
434 int attached; /* # of high level drivers attached to
435 * this */
436 int access_count; /* Count of open channels/mounts */
438 void *hostdata; /* available to low-level driver */
439 char type;
440 char scsi_level;
441 char vendor[8], model[16], rev[4];
442 unsigned char current_tag; /* current tag */
443 unsigned char sync_min_period; /* Not less than this period */
444 unsigned char sync_max_offset; /* Not greater than this offset */
445 unsigned char queue_depth; /* How deep a queue to use */
447 unsigned online:1;
448 unsigned writeable:1;
449 unsigned removable:1;
450 unsigned random:1;
451 unsigned has_cmdblocks:1;
452 unsigned changed:1; /* Data invalid due to media change */
453 unsigned busy:1; /* Used to prevent races */
454 unsigned lockable:1; /* Able to prevent media removal */
455 unsigned borken:1; /* Tell the Seagate driver to be
456 * painfully slow on this device */
457 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
458 unsigned tagged_queue:1; /* SCSI-II tagged queuing enabled */
459 unsigned disconnect:1; /* can disconnect */
460 unsigned soft_reset:1; /* Uses soft reset option */
461 unsigned sync:1; /* Negotiate for sync transfers */
462 unsigned wide:1; /* Negotiate for WIDE transfers */
463 unsigned single_lun:1; /* Indicates we should only allow I/O to
464 * one of the luns for the device at a
465 * time. */
466 unsigned was_reset:1; /* There was a bus reset on the bus for
467 * this device */
468 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
469 * because we did a bus reset. */
470 unsigned device_blocked:1; /* Device returned QUEUE_FULL. */
475 * The Scsi_Cmnd structure is used by scsi.c internally, and for communication
476 * with low level drivers that support multiple outstanding commands.
478 typedef struct scsi_pointer {
479 char *ptr; /* data pointer */
480 int this_residual; /* left in this buffer */
481 struct scatterlist *buffer; /* which buffer */
482 int buffers_residual; /* how many buffers left */
484 volatile int Status;
485 volatile int Message;
486 volatile int have_data_in;
487 volatile int sent_command;
488 volatile int phase;
489 } Scsi_Pointer;
492 struct scsi_cmnd {
493 /* private: */
495 * This information is private to the scsi mid-layer. Wrapping it in a
496 * struct private is a way of marking it in a sort of C++ type of way.
498 struct Scsi_Host *host;
499 unsigned short state;
500 unsigned short owner;
501 Scsi_Device *device;
502 struct scsi_cmnd *next;
503 struct scsi_cmnd *reset_chain;
505 int eh_state; /* Used for state tracking in error handlr */
506 void (*done) (struct scsi_cmnd *); /* Mid-level done function */
508 A SCSI Command is assigned a nonzero serial_number when internal_cmnd
509 passes it to the driver's queue command function. The serial_number
510 is cleared when scsi_done is entered indicating that the command has
511 been completed. If a timeout occurs, the serial number at the moment
512 of timeout is copied into serial_number_at_timeout. By subsequently
513 comparing the serial_number and serial_number_at_timeout fields
514 during abort or reset processing, we can detect whether the command
515 has already completed. This also detects cases where the command has
516 completed and the SCSI Command structure has already being reused
517 for another command, so that we can avoid incorrectly aborting or
518 resetting the new command.
521 unsigned long serial_number;
522 unsigned long serial_number_at_timeout;
524 int retries;
525 int allowed;
526 int timeout_per_command;
527 int timeout_total;
528 int timeout;
531 * We handle the timeout differently if it happens when a reset,
532 * abort, etc are in process.
534 unsigned volatile char internal_timeout;
535 struct scsi_cmnd *bh_next; /* To enumerate the commands waiting
536 to be processed. */
538 /* public: */
540 unsigned char target;
541 unsigned char lun;
542 unsigned char channel;
543 unsigned char cmd_len;
544 unsigned char old_cmd_len;
546 /* These elements define the operation we are about to perform */
547 unsigned char cmnd[12];
548 unsigned request_bufflen; /* Actual request size */
550 struct timer_list eh_timeout; /* Used to time out the command. */
551 void *request_buffer; /* Actual requested buffer */
553 /* These elements define the operation we ultimately want to perform */
554 unsigned char data_cmnd[12];
555 unsigned short old_use_sg; /* We save use_sg here when requesting
556 * sense info */
557 unsigned short use_sg; /* Number of pieces of scatter-gather */
558 unsigned short sglist_len; /* size of malloc'd scatter-gather list */
559 unsigned short abort_reason; /* If the mid-level code requests an
560 * abort, this is the reason. */
561 unsigned bufflen; /* Size of data buffer */
562 void *buffer; /* Data buffer */
564 unsigned underflow; /* Return error if less than
565 this amount is transfered */
567 unsigned transfersize; /* How much we are guaranteed to
568 transfer with each SCSI transfer
569 (ie, between disconnect /
570 reconnects. Probably == sector
571 size */
574 struct request request; /* A copy of the command we are
575 working on */
577 unsigned char sense_buffer[16]; /* Sense for this command,
578 needed */
580 unsigned flags;
583 * These two flags are used to track commands that are in the
584 * mid-level queue. The idea is that a command can be there for
585 * one of two reasons - either the host is busy or the device is
586 * busy. Thus when a command on the host finishes, we only try
587 * and requeue commands that we might expect to be queueable.
589 unsigned host_wait:1;
590 unsigned device_wait:1;
592 /* These variables are for the cdrom only. Once we have variable size
593 * buffers in the buffer cache, they will go away. */
594 int this_count;
595 /* End of special cdrom variables */
597 /* Low-level done function - can be used by low-level driver to point
598 * to completion function. Not used by mid/upper level code. */
599 void (*scsi_done) (struct scsi_cmnd *);
602 * The following fields can be written to by the host specific code.
603 * Everything else should be left alone.
606 Scsi_Pointer SCp; /* Scratchpad used by some host adapters */
608 unsigned char *host_scribble; /* The host adapter is allowed to
609 * call scsi_malloc and get some memory
610 * and hang it here. The host adapter
611 * is also expected to call scsi_free
612 * to release this memory. (The memory
613 * obtained by scsi_malloc is guaranteed
614 * to be at an address < 16Mb). */
616 int result; /* Status code from lower level driver */
618 unsigned char tag; /* SCSI-II queued command tag */
619 unsigned long pid; /* Process ID, starts at 0 */
624 * Definitions and prototypes used for scsi mid-level queue.
626 #define SCSI_MLQUEUE_HOST_BUSY 0x1055
627 #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
629 extern int scsi_mlqueue_insert(Scsi_Cmnd * cmd, int reason);
630 extern int scsi_mlqueue_finish(struct Scsi_Host *host, Scsi_Device * device);
633 #if defined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR)
634 #include "hosts.h"
636 static Scsi_Cmnd *end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors)
638 struct request *req;
639 struct buffer_head *bh;
641 req = &SCpnt->request;
642 req->errors = 0;
643 if (!uptodate) {
644 printk(DEVICE_NAME " I/O error: dev %s, sector %lu\n",
645 kdevname(req->rq_dev), req->sector);
647 do {
648 if ((bh = req->bh) != NULL) {
649 req->bh = bh->b_reqnext;
650 req->nr_sectors -= bh->b_size >> 9;
651 req->sector += bh->b_size >> 9;
652 bh->b_reqnext = NULL;
653 bh->b_end_io(bh, uptodate);
654 sectors -= bh->b_size >> 9;
655 if ((bh = req->bh) != NULL) {
656 req->current_nr_sectors = bh->b_size >> 9;
657 if (req->nr_sectors < req->current_nr_sectors) {
658 req->nr_sectors = req->current_nr_sectors;
659 printk("end_scsi_request: buffer-list destroyed\n");
663 } while (sectors && bh);
664 if (req->bh) {
665 req->buffer = bh->b_data;
666 return SCpnt;
668 DEVICE_OFF(req->rq_dev);
669 if (req->sem != NULL) {
670 up(req->sem);
672 add_blkdev_randomness(MAJOR(req->rq_dev));
674 if (SCpnt->host->block) {
675 struct Scsi_Host *next;
677 for (next = SCpnt->host->block; next != SCpnt->host;
678 next = next->block)
679 wake_up(&next->host_wait);
681 wake_up(&wait_for_request);
682 wake_up(&SCpnt->device->device_wait);
683 scsi_release_command(SCpnt);
684 return NULL;
688 /* This is just like INIT_REQUEST, but we need to be aware of the fact
689 * that an interrupt may start another request, so we run this with interrupts
690 * turned off
692 #if MAJOR_NR == SCSI_DISK0_MAJOR
693 #define CHECK_INITREQ_SD_MAJOR(major) SCSI_DISK_MAJOR(major)
694 #else
695 #define CHECK_INITREQ_SD_MAJOR(major) ((major) == MAJOR_NR)
696 #endif
698 #define INIT_SCSI_REQUEST \
699 if (!CURRENT) { \
700 CLEAR_INTR; \
701 return; \
703 if (!CHECK_INITREQ_SD_MAJOR(MAJOR(CURRENT->rq_dev)))\
704 panic(DEVICE_NAME ": request list destroyed"); \
705 if (CURRENT->bh) { \
706 if (!buffer_locked(CURRENT->bh)) \
707 panic(DEVICE_NAME ": block not locked"); \
709 #endif
711 #define SCSI_SLEEP(QUEUE, CONDITION) { \
712 if (CONDITION) { \
713 DECLARE_WAITQUEUE(wait, current); \
714 add_wait_queue(QUEUE, &wait); \
715 for(;;) { \
716 set_current_state(TASK_UNINTERRUPTIBLE); \
717 if (CONDITION) { \
718 if (in_interrupt()) \
719 panic("scsi: trying to call schedule() in interrupt" \
720 ", file %s, line %d.\n", __FILE__, __LINE__); \
721 schedule(); \
723 else \
724 break; \
726 remove_wait_queue(QUEUE, &wait);\
727 current->state = TASK_RUNNING; \
728 }; }
730 #endif
733 * Overrides for Emacs so that we follow Linus's tabbing style.
734 * Emacs will notice this stuff at the end of the file and automatically
735 * adjust the settings for this buffer only. This must remain at the end
736 * of the file.
737 * ---------------------------------------------------------------------------
738 * Local variables:
739 * c-indent-level: 4
740 * c-brace-imaginary-offset: 0
741 * c-brace-offset: -4
742 * c-argdecl-indent: 4
743 * c-label-offset: -4
744 * c-continued-statement-offset: 4
745 * c-continued-brace-offset: 0
746 * indent-tabs-mode: nil
747 * tab-width: 8
748 * End: