Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
4e57b681 | 7 | #include <linux/timer.h> |
c6132da1 | 8 | #include <linux/scatterlist.h> |
1da177e4 LT |
9 | |
10 | struct request; | |
11 | struct scatterlist; | |
b58d9154 | 12 | struct Scsi_Host; |
1da177e4 | 13 | struct scsi_device; |
1da177e4 LT |
14 | |
15 | ||
16 | /* embedded in scsi_cmnd */ | |
17 | struct scsi_pointer { | |
18 | char *ptr; /* data pointer */ | |
19 | int this_residual; /* left in this buffer */ | |
20 | struct scatterlist *buffer; /* which buffer */ | |
21 | int buffers_residual; /* how many buffers left */ | |
22 | ||
23 | dma_addr_t dma_handle; | |
24 | ||
25 | volatile int Status; | |
26 | volatile int Message; | |
27 | volatile int have_data_in; | |
28 | volatile int sent_command; | |
29 | volatile int phase; | |
30 | }; | |
31 | ||
32 | struct scsi_cmnd { | |
1da177e4 | 33 | struct scsi_device *device; |
1da177e4 | 34 | struct list_head list; /* scsi_cmnd participates in queue lists */ |
1da177e4 | 35 | struct list_head eh_entry; /* entry for the host eh_cmd_q */ |
1da177e4 | 36 | int eh_eflags; /* Used by error handlr */ |
1da177e4 LT |
37 | |
38 | /* | |
c6295cdf | 39 | * A SCSI Command is assigned a nonzero serial_number before passed |
40 | * to the driver's queue command function. The serial_number is | |
41 | * cleared when scsi_done is entered indicating that the command | |
12a44162 MW |
42 | * has been completed. It is a bug for LLDDs to use this number |
43 | * for purposes other than printk (and even that is only useful | |
44 | * for debugging). | |
1da177e4 LT |
45 | */ |
46 | unsigned long serial_number; | |
12a44162 | 47 | |
b21a4138 JB |
48 | /* |
49 | * This is set to jiffies as it was when the command was first | |
50 | * allocated. It is used to time how long the command has | |
51 | * been outstanding | |
52 | */ | |
53 | unsigned long jiffies_at_alloc; | |
1da177e4 LT |
54 | |
55 | int retries; | |
56 | int allowed; | |
57 | int timeout_per_command; | |
1da177e4 | 58 | |
1da177e4 | 59 | unsigned char cmd_len; |
1da177e4 | 60 | enum dma_data_direction sc_data_direction; |
1da177e4 LT |
61 | |
62 | /* These elements define the operation we are about to perform */ | |
63 | #define MAX_COMMAND_SIZE 16 | |
64 | unsigned char cmnd[MAX_COMMAND_SIZE]; | |
65 | unsigned request_bufflen; /* Actual request size */ | |
66 | ||
67 | struct timer_list eh_timeout; /* Used to time out the command. */ | |
68 | void *request_buffer; /* Actual requested buffer */ | |
69 | ||
70 | /* These elements define the operation we ultimately want to perform */ | |
1da177e4 LT |
71 | unsigned short use_sg; /* Number of pieces of scatter-gather */ |
72 | unsigned short sglist_len; /* size of malloc'd scatter-gather list */ | |
a8474ce2 | 73 | unsigned short __use_sg; |
1da177e4 LT |
74 | |
75 | unsigned underflow; /* Return error if less than | |
76 | this amount is transferred */ | |
1da177e4 LT |
77 | |
78 | unsigned transfersize; /* How much we are guaranteed to | |
79 | transfer with each SCSI transfer | |
80 | (ie, between disconnect / | |
81 | reconnects. Probably == sector | |
82 | size */ | |
83 | ||
84 | int resid; /* Number of bytes requested to be | |
85 | transferred less actual number | |
86 | transferred (0 if not supported) */ | |
87 | ||
88 | struct request *request; /* The command we are | |
89 | working on */ | |
90 | ||
91 | #define SCSI_SENSE_BUFFERSIZE 96 | |
c67a848c MW |
92 | unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; |
93 | /* obtained by REQUEST SENSE when | |
94 | * CHECK CONDITION is received on original | |
95 | * command (auto-sense) */ | |
1da177e4 LT |
96 | |
97 | /* Low-level done function - can be used by low-level driver to point | |
98 | * to completion function. Not used by mid/upper level code. */ | |
99 | void (*scsi_done) (struct scsi_cmnd *); | |
100 | ||
101 | /* | |
102 | * The following fields can be written to by the host specific code. | |
103 | * Everything else should be left alone. | |
104 | */ | |
105 | struct scsi_pointer SCp; /* Scratchpad used by some host adapters */ | |
106 | ||
107 | unsigned char *host_scribble; /* The host adapter is allowed to | |
c67a848c MW |
108 | * call scsi_malloc and get some memory |
109 | * and hang it here. The host adapter | |
110 | * is also expected to call scsi_free | |
111 | * to release this memory. (The memory | |
112 | * obtained by scsi_malloc is guaranteed | |
113 | * to be at an address < 16Mb). */ | |
1da177e4 LT |
114 | |
115 | int result; /* Status code from lower level driver */ | |
116 | ||
117 | unsigned char tag; /* SCSI-II queued command tag */ | |
1da177e4 LT |
118 | }; |
119 | ||
c53033f6 | 120 | extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t); |
b58d9154 | 121 | extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t); |
1da177e4 | 122 | extern void scsi_put_command(struct scsi_cmnd *); |
b58d9154 FT |
123 | extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *, |
124 | struct device *); | |
1da177e4 | 125 | extern void scsi_finish_command(struct scsi_cmnd *cmd); |
89f48c4d | 126 | extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd); |
1da177e4 | 127 | |
cdb8c2a6 GL |
128 | extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, |
129 | size_t *offset, size_t *len); | |
130 | extern void scsi_kunmap_atomic_sg(void *virt); | |
131 | ||
b58d9154 | 132 | extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t); |
0cde8d95 | 133 | extern void scsi_free_sgtable(struct scsi_cmnd *); |
b58d9154 | 134 | |
824d7b57 FT |
135 | extern int scsi_dma_map(struct scsi_cmnd *cmd); |
136 | extern void scsi_dma_unmap(struct scsi_cmnd *cmd); | |
137 | ||
138 | #define scsi_sg_count(cmd) ((cmd)->use_sg) | |
139 | #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer) | |
140 | #define scsi_bufflen(cmd) ((cmd)->request_bufflen) | |
141 | ||
142 | static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) | |
143 | { | |
144 | cmd->resid = resid; | |
145 | } | |
146 | ||
147 | static inline int scsi_get_resid(struct scsi_cmnd *cmd) | |
148 | { | |
149 | return cmd->resid; | |
150 | } | |
151 | ||
152 | #define scsi_for_each_sg(cmd, sg, nseg, __i) \ | |
c6132da1 | 153 | for_each_sg(scsi_sglist(cmd), sg, nseg, __i) |
824d7b57 | 154 | |
1da177e4 | 155 | #endif /* _SCSI_SCSI_CMND_H */ |