scsi_cmnd.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifndef _SCSI_SCSI_CMND_H
  2. #define _SCSI_SCSI_CMND_H
  3. #include <linux/dma-mapping.h>
  4. #include <linux/blkdev.h>
  5. #include <linux/list.h>
  6. #include <linux/types.h>
  7. #include <linux/timer.h>
  8. #include <linux/scatterlist.h>
  9. struct Scsi_Host;
  10. struct scsi_device;
  11. struct scsi_data_buffer {
  12. struct sg_table table;
  13. unsigned length;
  14. int resid;
  15. };
  16. /* embedded in scsi_cmnd */
  17. struct 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. dma_addr_t dma_handle;
  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. struct scsi_cmnd {
  30. struct scsi_device *device;
  31. struct list_head list; /* scsi_cmnd participates in queue lists */
  32. struct list_head eh_entry; /* entry for the host eh_cmd_q */
  33. int eh_eflags; /* Used by error handlr */
  34. /*
  35. * A SCSI Command is assigned a nonzero serial_number before passed
  36. * to the driver's queue command function. The serial_number is
  37. * cleared when scsi_done is entered indicating that the command
  38. * has been completed. It is a bug for LLDDs to use this number
  39. * for purposes other than printk (and even that is only useful
  40. * for debugging).
  41. */
  42. unsigned long serial_number;
  43. /*
  44. * This is set to jiffies as it was when the command was first
  45. * allocated. It is used to time how long the command has
  46. * been outstanding
  47. */
  48. unsigned long jiffies_at_alloc;
  49. int retries;
  50. int allowed;
  51. int timeout_per_command;
  52. unsigned char cmd_len;
  53. enum dma_data_direction sc_data_direction;
  54. /* These elements define the operation we are about to perform */
  55. #define MAX_COMMAND_SIZE 16
  56. unsigned char cmnd[MAX_COMMAND_SIZE];
  57. struct timer_list eh_timeout; /* Used to time out the command. */
  58. /* These elements define the operation we ultimately want to perform */
  59. struct scsi_data_buffer sdb;
  60. unsigned underflow; /* Return error if less than
  61. this amount is transferred */
  62. unsigned transfersize; /* How much we are guaranteed to
  63. transfer with each SCSI transfer
  64. (ie, between disconnect /
  65. reconnects. Probably == sector
  66. size */
  67. struct request *request; /* The command we are
  68. working on */
  69. #define SCSI_SENSE_BUFFERSIZE 96
  70. unsigned char *sense_buffer;
  71. /* obtained by REQUEST SENSE when
  72. * CHECK CONDITION is received on original
  73. * command (auto-sense) */
  74. /* Low-level done function - can be used by low-level driver to point
  75. * to completion function. Not used by mid/upper level code. */
  76. void (*scsi_done) (struct scsi_cmnd *);
  77. /*
  78. * The following fields can be written to by the host specific code.
  79. * Everything else should be left alone.
  80. */
  81. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  82. unsigned char *host_scribble; /* The host adapter is allowed to
  83. * call scsi_malloc and get some memory
  84. * and hang it here. The host adapter
  85. * is also expected to call scsi_free
  86. * to release this memory. (The memory
  87. * obtained by scsi_malloc is guaranteed
  88. * to be at an address < 16Mb). */
  89. int result; /* Status code from lower level driver */
  90. unsigned char tag; /* SCSI-II queued command tag */
  91. };
  92. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
  93. extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
  94. extern void scsi_put_command(struct scsi_cmnd *);
  95. extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
  96. struct device *);
  97. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  98. extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
  99. extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
  100. size_t *offset, size_t *len);
  101. extern void scsi_kunmap_atomic_sg(void *virt);
  102. extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask);
  103. extern void scsi_release_buffers(struct scsi_cmnd *cmd);
  104. extern int scsi_dma_map(struct scsi_cmnd *cmd);
  105. extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
  106. struct scsi_cmnd *scsi_allocate_command(gfp_t gfp_mask);
  107. void scsi_free_command(gfp_t gfp_mask, struct scsi_cmnd *cmd);
  108. static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
  109. {
  110. return cmd->sdb.table.nents;
  111. }
  112. static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd)
  113. {
  114. return cmd->sdb.table.sgl;
  115. }
  116. static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd)
  117. {
  118. return cmd->sdb.length;
  119. }
  120. static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
  121. {
  122. cmd->sdb.resid = resid;
  123. }
  124. static inline int scsi_get_resid(struct scsi_cmnd *cmd)
  125. {
  126. return cmd->sdb.resid;
  127. }
  128. #define scsi_for_each_sg(cmd, sg, nseg, __i) \
  129. for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
  130. static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd)
  131. {
  132. return blk_bidi_rq(cmd->request) &&
  133. (cmd->request->next_rq->special != NULL);
  134. }
  135. static inline struct scsi_data_buffer *scsi_in(struct scsi_cmnd *cmd)
  136. {
  137. return scsi_bidi_cmnd(cmd) ?
  138. cmd->request->next_rq->special : &cmd->sdb;
  139. }
  140. static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd)
  141. {
  142. return &cmd->sdb;
  143. }
  144. static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
  145. void *buf, int buflen)
  146. {
  147. return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
  148. buf, buflen);
  149. }
  150. static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd,
  151. void *buf, int buflen)
  152. {
  153. return sg_copy_to_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
  154. buf, buflen);
  155. }
  156. #endif /* _SCSI_SCSI_CMND_H */