| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 7 | #include <linux/timer.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  | 
|  | 9 | struct request; | 
|  | 10 | struct scatterlist; | 
| FUJITA Tomonori | b58d915 | 2006-11-16 19:24:10 +0900 | [diff] [blame] | 11 | struct Scsi_Host; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | struct scsi_device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
|  | 14 |  | 
|  | 15 | /* embedded in scsi_cmnd */ | 
|  | 16 | struct 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 |  | 
|  | 31 | struct scsi_cmnd { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | struct scsi_device *device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct list_head list;  /* scsi_cmnd participates in queue lists */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct list_head eh_entry; /* entry for the host eh_cmd_q */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | int eh_eflags;		/* Used by error handlr */ | 
|  | 36 | void (*done) (struct scsi_cmnd *);	/* Mid-level done function */ | 
|  | 37 |  | 
|  | 38 | /* | 
|  | c6295cd | 2005-04-03 14:59:11 -0500 | [diff] [blame] | 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 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | */ | 
|  | 49 | unsigned long serial_number; | 
| James Bottomley | b21a413 | 2005-08-05 21:45:40 -0500 | [diff] [blame] | 50 | /* | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
|  | 57 | int retries; | 
|  | 58 | int allowed; | 
|  | 59 | int timeout_per_command; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | unsigned char cmd_len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | enum dma_data_direction sc_data_direction; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 |  | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | unsigned short use_sg;	/* Number of pieces of scatter-gather */ | 
|  | 74 | unsigned short sglist_len;	/* size of malloc'd scatter-gather list */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 |  | 
|  | 76 | unsigned underflow;	/* Return error if less than | 
|  | 77 | this amount is transferred */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
|  | 79 | unsigned transfersize;	/* How much we are guaranteed to | 
|  | 80 | transfer with each SCSI transfer | 
|  | 81 | (ie, between disconnect / | 
|  | 82 | reconnects.   Probably == sector | 
|  | 83 | size */ | 
|  | 84 |  | 
|  | 85 | int resid;		/* Number of bytes requested to be | 
|  | 86 | transferred less actual number | 
|  | 87 | transferred (0 if not supported) */ | 
|  | 88 |  | 
|  | 89 | struct request *request;	/* The command we are | 
|  | 90 | working on */ | 
|  | 91 |  | 
|  | 92 | #define SCSI_SENSE_BUFFERSIZE 	96 | 
| Matthew Wilcox | c67a848 | 2006-01-17 11:54:24 -0700 | [diff] [blame] | 93 | unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; | 
|  | 94 | /* obtained by REQUEST SENSE when | 
|  | 95 | * CHECK CONDITION is received on original | 
|  | 96 | * command (auto-sense) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 |  | 
|  | 98 | /* Low-level done function - can be used by low-level driver to point | 
|  | 99 | *        to completion function.  Not used by mid/upper level code. */ | 
|  | 100 | void (*scsi_done) (struct scsi_cmnd *); | 
|  | 101 |  | 
|  | 102 | /* | 
|  | 103 | * The following fields can be written to by the host specific code. | 
|  | 104 | * Everything else should be left alone. | 
|  | 105 | */ | 
|  | 106 | struct scsi_pointer SCp;	/* Scratchpad used by some host adapters */ | 
|  | 107 |  | 
|  | 108 | unsigned char *host_scribble;	/* The host adapter is allowed to | 
| Matthew Wilcox | c67a848 | 2006-01-17 11:54:24 -0700 | [diff] [blame] | 109 | * call scsi_malloc and get some memory | 
|  | 110 | * and hang it here.  The host adapter | 
|  | 111 | * is also expected to call scsi_free | 
|  | 112 | * to release this memory.  (The memory | 
|  | 113 | * obtained by scsi_malloc is guaranteed | 
|  | 114 | * to be at an address < 16Mb). */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | int result;		/* Status code from lower level driver */ | 
|  | 117 |  | 
|  | 118 | unsigned char tag;	/* SCSI-II queued command tag */ | 
|  | 119 | unsigned long pid;	/* Process ID, starts at 0. Unique per host. */ | 
|  | 120 | }; | 
|  | 121 |  | 
| Al Viro | c53033f | 2005-10-21 03:22:08 -0400 | [diff] [blame] | 122 | extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t); | 
| FUJITA Tomonori | b58d915 | 2006-11-16 19:24:10 +0900 | [diff] [blame] | 123 | extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | extern void scsi_put_command(struct scsi_cmnd *); | 
| FUJITA Tomonori | b58d915 | 2006-11-16 19:24:10 +0900 | [diff] [blame] | 125 | extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *, | 
|  | 126 | struct device *); | 
| Luben Tuikov | 03aba2f | 2006-06-23 09:39:09 -0700 | [diff] [blame] | 127 | extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | extern void scsi_finish_command(struct scsi_cmnd *cmd); | 
| Luben Tuikov | 89f48c4 | 2006-05-15 20:57:18 +0900 | [diff] [blame] | 129 | extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 |  | 
| Guennadi Liakhovetski | cdb8c2a | 2006-04-02 21:57:43 +0200 | [diff] [blame] | 131 | extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count, | 
|  | 132 | size_t *offset, size_t *len); | 
|  | 133 | extern void scsi_kunmap_atomic_sg(void *virt); | 
|  | 134 |  | 
| FUJITA Tomonori | b58d915 | 2006-11-16 19:24:10 +0900 | [diff] [blame] | 135 | extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t); | 
|  | 136 | extern void scsi_free_sgtable(struct scatterlist *, int); | 
|  | 137 |  | 
| FUJITA Tomonori | 824d7b5 | 2007-05-26 14:04:03 +0900 | [diff] [blame] | 138 | extern int scsi_dma_map(struct scsi_cmnd *cmd); | 
|  | 139 | extern void scsi_dma_unmap(struct scsi_cmnd *cmd); | 
|  | 140 |  | 
|  | 141 | #define scsi_sg_count(cmd) ((cmd)->use_sg) | 
|  | 142 | #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer) | 
|  | 143 | #define scsi_bufflen(cmd) ((cmd)->request_bufflen) | 
|  | 144 |  | 
|  | 145 | static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) | 
|  | 146 | { | 
|  | 147 | cmd->resid = resid; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | static inline int scsi_get_resid(struct scsi_cmnd *cmd) | 
|  | 151 | { | 
|  | 152 | return cmd->resid; | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | #define scsi_for_each_sg(cmd, sg, nseg, __i)			\ | 
|  | 156 | for (__i = 0, sg = scsi_sglist(cmd); __i < (nseg); __i++, (sg)++) | 
|  | 157 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | #endif /* _SCSI_SCSI_CMND_H */ |