blob: abd7479ff45298fbf25bd6d2fb9579531b29f652 [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;
11struct scatterlist;
FUJITA Tomonorib58d9152006-11-16 19:24:10 +090012struct Scsi_Host;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013struct scsi_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15
16/* embedded in scsi_cmnd */
17struct 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
32struct scsi_cmnd {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 struct scsi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct list_head list; /* scsi_cmnd participates in queue lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 struct list_head eh_entry; /* entry for the host eh_cmd_q */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int eh_eflags; /* Used by error handlr */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 /*
c6295cd2005-04-03 14:59:11 -050039 * 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
Matthew Wilcox12a44162007-09-18 19:54:43 -060042 * 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).
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
46 unsigned long serial_number;
Matthew Wilcox12a44162007-09-18 19:54:43 -060047
James Bottomleyb21a4132005-08-05 21:45:40 -050048 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 int retries;
56 int allowed;
57 int timeout_per_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 unsigned char cmd_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 enum dma_data_direction sc_data_direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 unsigned short use_sg; /* Number of pieces of scatter-gather */
Jens Axboea8474ce2007-08-07 09:02:51 +020072 unsigned short __use_sg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74 unsigned underflow; /* Return error if less than
75 this amount is transferred */
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
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 */
82
83 int resid; /* Number of bytes requested to be
84 transferred less actual number
85 transferred (0 if not supported) */
86
87 struct request *request; /* The command we are
88 working on */
89
90#define SCSI_SENSE_BUFFERSIZE 96
FUJITA Tomonoride25deb2008-01-16 13:32:17 +090091 unsigned char *sense_buffer;
Matthew Wilcoxc67a8482006-01-17 11:54:24 -070092 /* obtained by REQUEST SENSE when
93 * CHECK CONDITION is received on original
94 * command (auto-sense) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
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 *);
99
100 /*
101 * The following fields can be written to by the host specific code.
102 * Everything else should be left alone.
103 */
104 struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
105
106 unsigned char *host_scribble; /* The host adapter is allowed to
Matthew Wilcoxc67a8482006-01-17 11:54:24 -0700107 * 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). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 int result; /* Status code from lower level driver */
115
116 unsigned char tag; /* SCSI-II queued command tag */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
Al Viroc53033f2005-10-21 03:22:08 -0400119extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900120extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121extern void scsi_put_command(struct scsi_cmnd *);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900122extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
123 struct device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124extern void scsi_finish_command(struct scsi_cmnd *cmd);
Luben Tuikov89f48c42006-05-15 20:57:18 +0900125extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Guennadi Liakhovetskicdb8c2a2006-04-02 21:57:43 +0200127extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
128 size_t *offset, size_t *len);
129extern void scsi_kunmap_atomic_sg(void *virt);
130
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900131extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
Jens Axboe0cde8d92007-10-16 11:12:37 +0200132extern void scsi_free_sgtable(struct scsi_cmnd *);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900133
FUJITA Tomonori824d7b52007-05-26 14:04:03 +0900134extern int scsi_dma_map(struct scsi_cmnd *cmd);
135extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
136
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)
140
141static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
142{
143 cmd->resid = resid;
144}
145
146static inline int scsi_get_resid(struct scsi_cmnd *cmd)
147{
148 return cmd->resid;
149}
150
151#define scsi_for_each_sg(cmd, sg, nseg, __i) \
Jens Axboec6132da2007-10-16 11:08:49 +0200152 for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
FUJITA Tomonori824d7b52007-05-26 14:04:03 +0900153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#endif /* _SCSI_SCSI_CMND_H */