blob: 09d44f91dbdbd745f292ca863df47a7e8402b12e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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>
Tim Schmielau4e57b682005-10-30 15:03:48 -08007#include <linux/timer.h>
Jens Axboec6132da2007-10-16 11:08:49 +02008#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10struct request;
FUJITA Tomonorib58d9152006-11-16 19:24:10 +090011struct Scsi_Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -070012struct scsi_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 struct scsi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 struct list_head list; /* scsi_cmnd participates in queue lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct list_head eh_entry; /* entry for the host eh_cmd_q */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 int eh_eflags; /* Used by error handlr */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 /*
c6295cd2005-04-03 14:59:11 -050038 * 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
Matthew Wilcox12a44162007-09-18 19:54:43 -060041 * 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).
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 */
45 unsigned long serial_number;
Matthew Wilcox12a44162007-09-18 19:54:43 -060046
James Bottomleyb21a4132005-08-05 21:45:40 -050047 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 int retries;
55 int allowed;
56 int timeout_per_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned char cmd_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 enum dma_data_direction sc_data_direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
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 */
Jens Axboe5ed79592007-11-15 09:13:11 +010070 struct sg_table sg_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 unsigned short use_sg; /* Number of pieces of scatter-gather */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 unsigned underflow; /* Return error if less than
74 this amount is transferred */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
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
FUJITA Tomonoride25deb2008-01-16 13:32:17 +090090 unsigned char *sense_buffer;
Matthew Wilcoxc67a8482006-01-17 11:54:24 -070091 /* obtained by REQUEST SENSE when
92 * CHECK CONDITION is received on original
93 * command (auto-sense) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
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
Matthew Wilcoxc67a8482006-01-17 11:54:24 -0700106 * 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). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 int result; /* Status code from lower level driver */
114
115 unsigned char tag; /* SCSI-II queued command tag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
117
Al Viroc53033f2005-10-21 03:22:08 -0400118extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900119extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120extern void scsi_put_command(struct scsi_cmnd *);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900121extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
122 struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123extern void scsi_finish_command(struct scsi_cmnd *cmd);
Luben Tuikov89f48c42006-05-15 20:57:18 +0900124extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Guennadi Liakhovetskicdb8c2a2006-04-02 21:57:43 +0200126extern 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
Boaz Harroshbb52d822007-12-13 16:14:27 -0800130extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask);
131extern void scsi_release_buffers(struct scsi_cmnd *cmd);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900132
FUJITA Tomonori824d7b52007-05-26 14:04:03 +0900133extern 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)
Jens Axboe5ed79592007-11-15 09:13:11 +0100137#define scsi_sglist(cmd) ((cmd)->sg_table.sgl)
FUJITA Tomonori824d7b52007-05-26 14:04:03 +0900138#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) \
Jens Axboec6132da2007-10-16 11:08:49 +0200151 for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
FUJITA Tomonori824d7b52007-05-26 14:04:03 +0900152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif /* _SCSI_SCSI_CMND_H */