blob: d6948d0e8cdb47d2347f2f2e9c9b991e7788b804 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9struct request;
10struct scatterlist;
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 */
36 void (*done) (struct scsi_cmnd *); /* Mid-level done function */
37
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
42 * has been completed. It currently doesn't have much use other
43 * than printk's. Some lldd's use this number for other purposes.
44 * It's almost certain that such usages are either incorrect or
45 * meaningless. Please kill all usages other than printk's. Also,
46 * as this number is always identical to ->pid, please convert
47 * printk's to use ->pid, so that we can kill this field.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49 unsigned long serial_number;
James Bottomleyb21a4132005-08-05 21:45:40 -050050 /*
51 * This is set to jiffies as it was when the command was first
52 * allocated. It is used to time how long the command has
53 * been outstanding
54 */
55 unsigned long jiffies_at_alloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 int retries;
58 int allowed;
59 int timeout_per_command;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 unsigned char cmd_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 enum dma_data_direction sc_data_direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 /* These elements define the operation we are about to perform */
65#define MAX_COMMAND_SIZE 16
66 unsigned char cmnd[MAX_COMMAND_SIZE];
67 unsigned request_bufflen; /* Actual request size */
68
69 struct timer_list eh_timeout; /* Used to time out the command. */
70 void *request_buffer; /* Actual requested buffer */
71
72 /* These elements define the operation we ultimately want to perform */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 unsigned short use_sg; /* Number of pieces of scatter-gather */
74 unsigned short sglist_len; /* size of malloc'd scatter-gather list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
FUJITA Tomonorib58d9152006-11-16 19:24:10 +090076 /* offset in cmd we are at (for multi-transfer tgt cmds) */
77 unsigned offset;
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 unsigned underflow; /* Return error if less than
80 this amount is transferred */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 unsigned transfersize; /* How much we are guaranteed to
83 transfer with each SCSI transfer
84 (ie, between disconnect /
85 reconnects. Probably == sector
86 size */
87
88 int resid; /* Number of bytes requested to be
89 transferred less actual number
90 transferred (0 if not supported) */
91
92 struct request *request; /* The command we are
93 working on */
94
95#define SCSI_SENSE_BUFFERSIZE 96
Matthew Wilcoxc67a8482006-01-17 11:54:24 -070096 unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
97 /* obtained by REQUEST SENSE when
98 * CHECK CONDITION is received on original
99 * command (auto-sense) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 /* Low-level done function - can be used by low-level driver to point
102 * to completion function. Not used by mid/upper level code. */
103 void (*scsi_done) (struct scsi_cmnd *);
104
105 /*
106 * The following fields can be written to by the host specific code.
107 * Everything else should be left alone.
108 */
109 struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
110
111 unsigned char *host_scribble; /* The host adapter is allowed to
Matthew Wilcoxc67a8482006-01-17 11:54:24 -0700112 * call scsi_malloc and get some memory
113 * and hang it here. The host adapter
114 * is also expected to call scsi_free
115 * to release this memory. (The memory
116 * obtained by scsi_malloc is guaranteed
117 * to be at an address < 16Mb). */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 int result; /* Status code from lower level driver */
120
121 unsigned char tag; /* SCSI-II queued command tag */
122 unsigned long pid; /* Process ID, starts at 0. Unique per host. */
123};
124
Al Viroc53033f2005-10-21 03:22:08 -0400125extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900126extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127extern void scsi_put_command(struct scsi_cmnd *);
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900128extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
129 struct device *);
Luben Tuikov03aba2f2006-06-23 09:39:09 -0700130extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131extern void scsi_finish_command(struct scsi_cmnd *cmd);
Luben Tuikov89f48c42006-05-15 20:57:18 +0900132extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Guennadi Liakhovetskicdb8c2a2006-04-02 21:57:43 +0200134extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
135 size_t *offset, size_t *len);
136extern void scsi_kunmap_atomic_sg(void *virt);
137
FUJITA Tomonorib58d9152006-11-16 19:24:10 +0900138extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
139extern void scsi_free_sgtable(struct scatterlist *, int);
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif /* _SCSI_SCSI_CMND_H */