[SCSI] drivers/scsi/st.c: add reference count and related fixes
[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>
7
8struct request;
9struct scatterlist;
10struct scsi_device;
11struct scsi_request;
12
13
14/* embedded in scsi_cmnd */
15struct scsi_pointer {
16 char *ptr; /* data pointer */
17 int this_residual; /* left in this buffer */
18 struct scatterlist *buffer; /* which buffer */
19 int buffers_residual; /* how many buffers left */
20
21 dma_addr_t dma_handle;
22
23 volatile int Status;
24 volatile int Message;
25 volatile int have_data_in;
26 volatile int sent_command;
27 volatile int phase;
28};
29
30struct scsi_cmnd {
31 int sc_magic;
32
33 struct scsi_device *device;
1da177e4
LT
34 struct scsi_request *sc_request;
35
36 struct list_head list; /* scsi_cmnd participates in queue lists */
37
38 struct list_head eh_entry; /* entry for the host eh_cmd_q */
1da177e4
LT
39 int eh_eflags; /* Used by error handlr */
40 void (*done) (struct scsi_cmnd *); /* Mid-level done function */
41
42 /*
c6295cdf
TH
43 * A SCSI Command is assigned a nonzero serial_number before passed
44 * to the driver's queue command function. The serial_number is
45 * cleared when scsi_done is entered indicating that the command
46 * has been completed. It currently doesn't have much use other
47 * than printk's. Some lldd's use this number for other purposes.
48 * It's almost certain that such usages are either incorrect or
49 * meaningless. Please kill all usages other than printk's. Also,
50 * as this number is always identical to ->pid, please convert
51 * printk's to use ->pid, so that we can kill this field.
1da177e4
LT
52 */
53 unsigned long serial_number;
1da177e4
LT
54
55 int retries;
56 int allowed;
57 int timeout_per_command;
58 int timeout_total;
59 int timeout;
60
1da177e4
LT
61 unsigned char cmd_len;
62 unsigned char old_cmd_len;
63 enum dma_data_direction sc_data_direction;
64 enum dma_data_direction sc_old_data_direction;
65
66 /* These elements define the operation we are about to perform */
67#define MAX_COMMAND_SIZE 16
68 unsigned char cmnd[MAX_COMMAND_SIZE];
69 unsigned request_bufflen; /* Actual request size */
70
71 struct timer_list eh_timeout; /* Used to time out the command. */
72 void *request_buffer; /* Actual requested buffer */
73
74 /* These elements define the operation we ultimately want to perform */
75 unsigned char data_cmnd[MAX_COMMAND_SIZE];
76 unsigned short old_use_sg; /* We save use_sg here when requesting
77 * sense info */
78 unsigned short use_sg; /* Number of pieces of scatter-gather */
79 unsigned short sglist_len; /* size of malloc'd scatter-gather list */
1da177e4
LT
80 unsigned bufflen; /* Size of data buffer */
81 void *buffer; /* Data buffer */
82
83 unsigned underflow; /* Return error if less than
84 this amount is transferred */
85 unsigned old_underflow; /* save underflow here when reusing the
86 * command for error handling */
87
88 unsigned transfersize; /* How much we are guaranteed to
89 transfer with each SCSI transfer
90 (ie, between disconnect /
91 reconnects. Probably == sector
92 size */
93
94 int resid; /* Number of bytes requested to be
95 transferred less actual number
96 transferred (0 if not supported) */
97
98 struct request *request; /* The command we are
99 working on */
100
101#define SCSI_SENSE_BUFFERSIZE 96
102 unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
103 * when CHECK CONDITION is
104 * received on original command
105 * (auto-sense) */
106
107 /* Low-level done function - can be used by low-level driver to point
108 * to completion function. Not used by mid/upper level code. */
109 void (*scsi_done) (struct scsi_cmnd *);
110
111 /*
112 * The following fields can be written to by the host specific code.
113 * Everything else should be left alone.
114 */
115 struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
116
117 unsigned char *host_scribble; /* The host adapter is allowed to
118 * call scsi_malloc and get some memory
119 * and hang it here. The host adapter
120 * is also expected to call scsi_free
121 * to release this memory. (The memory
122 * obtained by scsi_malloc is guaranteed
123 * to be at an address < 16Mb). */
124
125 int result; /* Status code from lower level driver */
126
127 unsigned char tag; /* SCSI-II queued command tag */
128 unsigned long pid; /* Process ID, starts at 0. Unique per host. */
129};
130
131/*
132 * These are the values that scsi_cmd->state can take.
133 */
134#define SCSI_STATE_TIMEOUT 0x1000
135#define SCSI_STATE_FINISHED 0x1001
136#define SCSI_STATE_FAILED 0x1002
137#define SCSI_STATE_QUEUED 0x1003
138#define SCSI_STATE_UNUSED 0x1006
139#define SCSI_STATE_DISCONNECTING 0x1008
140#define SCSI_STATE_INITIALIZING 0x1009
141#define SCSI_STATE_BHQUEUE 0x100a
142#define SCSI_STATE_MLQUEUE 0x100b
143
144
145extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, int);
146extern void scsi_put_command(struct scsi_cmnd *);
147extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
148extern void scsi_finish_command(struct scsi_cmnd *cmd);
149
150#endif /* _SCSI_SCSI_CMND_H */