fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / include / scsi / scsi_cmnd.h
blob3f47e522a1ec3bedf6c85b9d30145c7208a626b5
1 #ifndef _SCSI_SCSI_CMND_H
2 #define _SCSI_SCSI_CMND_H
4 #include <linux/dma-mapping.h>
5 #include <linux/list.h>
6 #include <linux/types.h>
7 #include <linux/timer.h>
8 #include <linux/scatterlist.h>
10 struct request;
11 struct scatterlist;
12 struct Scsi_Host;
13 struct scsi_device;
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 */
23 dma_addr_t dma_handle;
25 volatile int Status;
26 volatile int Message;
27 volatile int have_data_in;
28 volatile int sent_command;
29 volatile int phase;
32 struct scsi_cmnd {
33 struct scsi_device *device;
34 struct list_head list; /* scsi_cmnd participates in queue lists */
35 struct list_head eh_entry; /* entry for the host eh_cmd_q */
36 int eh_eflags; /* Used by error handlr */
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
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).
46 unsigned long serial_number;
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
53 unsigned long jiffies_at_alloc;
55 int retries;
56 int allowed;
57 int timeout_per_command;
59 unsigned char cmd_len;
60 enum dma_data_direction sc_data_direction;
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 */
67 struct timer_list eh_timeout; /* Used to time out the command. */
68 void *request_buffer; /* Actual requested buffer */
70 /* These elements define the operation we ultimately want to perform */
71 unsigned short use_sg; /* Number of pieces of scatter-gather */
72 unsigned short __use_sg;
74 unsigned underflow; /* Return error if less than
75 this amount is transferred */
77 unsigned transfersize; /* How much we are guaranteed to
78 transfer with each SCSI transfer
79 (ie, between disconnect /
80 reconnects. Probably == sector
81 size */
83 int resid; /* Number of bytes requested to be
84 transferred less actual number
85 transferred (0 if not supported) */
87 struct request *request; /* The command we are
88 working on */
90 #define SCSI_SENSE_BUFFERSIZE 96
91 unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
92 /* obtained by REQUEST SENSE when
93 * CHECK CONDITION is received on original
94 * command (auto-sense) */
96 /* Low-level done function - can be used by low-level driver to point
97 * to completion function. Not used by mid/upper level code. */
98 void (*scsi_done) (struct scsi_cmnd *);
101 * The following fields can be written to by the host specific code.
102 * Everything else should be left alone.
104 struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
106 unsigned char *host_scribble; /* The host adapter is allowed to
107 * call scsi_malloc and get some memory
108 * and hang it here. The host adapter
109 * is also expected to call scsi_free
110 * to release this memory. (The memory
111 * obtained by scsi_malloc is guaranteed
112 * to be at an address < 16Mb). */
114 int result; /* Status code from lower level driver */
116 unsigned char tag; /* SCSI-II queued command tag */
119 extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
120 extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
121 extern void scsi_put_command(struct scsi_cmnd *);
122 extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
123 struct device *);
124 extern void scsi_finish_command(struct scsi_cmnd *cmd);
125 extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
127 extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
128 size_t *offset, size_t *len);
129 extern void scsi_kunmap_atomic_sg(void *virt);
131 extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
132 extern void scsi_free_sgtable(struct scsi_cmnd *);
134 extern int scsi_dma_map(struct scsi_cmnd *cmd);
135 extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
137 #define scsi_sg_count(cmd) ((cmd)->use_sg)
138 #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer)
139 #define scsi_bufflen(cmd) ((cmd)->request_bufflen)
141 static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
143 cmd->resid = resid;
146 static inline int scsi_get_resid(struct scsi_cmnd *cmd)
148 return cmd->resid;
151 #define scsi_for_each_sg(cmd, sg, nseg, __i) \
152 for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
154 #endif /* _SCSI_SCSI_CMND_H */