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