Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / include / scsi / scsi_cmnd.h
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 #include <linux/timer.h>
8
9 struct request;
10 struct scatterlist;
11 struct scsi_device;
12 struct scsi_request;
13
14
15 /* embedded in scsi_cmnd */
16 struct scsi_pointer {
17         char *ptr;              /* data pointer */
18         int this_residual;      /* left in this buffer */
19         struct scatterlist *buffer;     /* which buffer */
20         int buffers_residual;   /* how many buffers left */
21
22         dma_addr_t dma_handle;
23
24         volatile int Status;
25         volatile int Message;
26         volatile int have_data_in;
27         volatile int sent_command;
28         volatile int phase;
29 };
30
31 struct scsi_cmnd {
32         int     sc_magic;
33
34         struct scsi_device *device;
35         struct scsi_request *sc_request;
36
37         struct list_head list;  /* scsi_cmnd participates in queue lists */
38
39         struct list_head eh_entry; /* entry for the host eh_cmd_q */
40         int eh_eflags;          /* Used by error handlr */
41         void (*done) (struct scsi_cmnd *);      /* Mid-level done function */
42
43         /*
44          * A SCSI Command is assigned a nonzero serial_number before passed
45          * to the driver's queue command function.  The serial_number is
46          * cleared when scsi_done is entered indicating that the command
47          * has been completed.  It currently doesn't have much use other
48          * than printk's.  Some lldd's use this number for other purposes.
49          * It's almost certain that such usages are either incorrect or
50          * meaningless.  Please kill all usages other than printk's.  Also,
51          * as this number is always identical to ->pid, please convert
52          * printk's to use ->pid, so that we can kill this field.
53          */
54         unsigned long serial_number;
55         /*
56          * This is set to jiffies as it was when the command was first
57          * allocated.  It is used to time how long the command has
58          * been outstanding
59          */
60         unsigned long jiffies_at_alloc;
61
62         int retries;
63         int allowed;
64         int timeout_per_command;
65
66         unsigned char cmd_len;
67         unsigned char old_cmd_len;
68         enum dma_data_direction sc_data_direction;
69         enum dma_data_direction sc_old_data_direction;
70
71         /* These elements define the operation we are about to perform */
72 #define MAX_COMMAND_SIZE        16
73         unsigned char cmnd[MAX_COMMAND_SIZE];
74         unsigned request_bufflen;       /* Actual request size */
75
76         struct timer_list eh_timeout;   /* Used to time out the command. */
77         void *request_buffer;           /* Actual requested buffer */
78
79         /* These elements define the operation we ultimately want to perform */
80         unsigned char data_cmnd[MAX_COMMAND_SIZE];
81         unsigned short old_use_sg;      /* We save  use_sg here when requesting
82                                          * sense info */
83         unsigned short use_sg;  /* Number of pieces of scatter-gather */
84         unsigned short sglist_len;      /* size of malloc'd scatter-gather list */
85         unsigned bufflen;       /* Size of data buffer */
86         void *buffer;           /* Data buffer */
87
88         unsigned underflow;     /* Return error if less than
89                                    this amount is transferred */
90         unsigned old_underflow; /* save underflow here when reusing the
91                                  * command for error handling */
92
93         unsigned transfersize;  /* How much we are guaranteed to
94                                    transfer with each SCSI transfer
95                                    (ie, between disconnect / 
96                                    reconnects.   Probably == sector
97                                    size */
98
99         int resid;              /* Number of bytes requested to be
100                                    transferred less actual number
101                                    transferred (0 if not supported) */
102
103         struct request *request;        /* The command we are
104                                            working on */
105
106 #define SCSI_SENSE_BUFFERSIZE   96
107         unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
108                                 /* obtained by REQUEST SENSE when
109                                  * CHECK CONDITION is received on original
110                                  * command (auto-sense) */
111
112         /* Low-level done function - can be used by low-level driver to point
113          *        to completion function.  Not used by mid/upper level code. */
114         void (*scsi_done) (struct scsi_cmnd *);
115
116         /*
117          * The following fields can be written to by the host specific code. 
118          * Everything else should be left alone. 
119          */
120         struct scsi_pointer SCp;        /* Scratchpad used by some host adapters */
121
122         unsigned char *host_scribble;   /* The host adapter is allowed to
123                                          * call scsi_malloc and get some memory
124                                          * and hang it here.  The host adapter
125                                          * is also expected to call scsi_free
126                                          * to release this memory.  (The memory
127                                          * obtained by scsi_malloc is guaranteed
128                                          * to be at an address < 16Mb). */
129
130         int result;             /* Status code from lower level driver */
131
132         unsigned char tag;      /* SCSI-II queued command tag */
133         unsigned long pid;      /* Process ID, starts at 0. Unique per host. */
134 };
135
136 /*
137  * These are the values that scsi_cmd->state can take.
138  */
139 #define SCSI_STATE_TIMEOUT         0x1000
140 #define SCSI_STATE_FINISHED        0x1001
141 #define SCSI_STATE_FAILED          0x1002
142 #define SCSI_STATE_QUEUED          0x1003
143 #define SCSI_STATE_UNUSED          0x1006
144 #define SCSI_STATE_DISCONNECTING   0x1008
145 #define SCSI_STATE_INITIALIZING    0x1009
146 #define SCSI_STATE_BHQUEUE         0x100a
147 #define SCSI_STATE_MLQUEUE         0x100b
148
149
150 extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
151 extern void scsi_put_command(struct scsi_cmnd *);
152 extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
153 extern void scsi_finish_command(struct scsi_cmnd *cmd);
154
155 #endif /* _SCSI_SCSI_CMND_H */