scsi_cmnd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef _SCSI_SCSI_CMND_H
  2. #define _SCSI_SCSI_CMND_H
  3. #include <linux/dma-mapping.h>
  4. #include <linux/list.h>
  5. #include <linux/types.h>
  6. #include <linux/timer.h>
  7. #include <linux/scatterlist.h>
  8. struct request;
  9. struct scatterlist;
  10. struct Scsi_Host;
  11. struct scsi_device;
  12. /* embedded in scsi_cmnd */
  13. struct scsi_pointer {
  14. char *ptr; /* data pointer */
  15. int this_residual; /* left in this buffer */
  16. struct scatterlist *buffer; /* which buffer */
  17. int buffers_residual; /* how many buffers left */
  18. dma_addr_t dma_handle;
  19. volatile int Status;
  20. volatile int Message;
  21. volatile int have_data_in;
  22. volatile int sent_command;
  23. volatile int phase;
  24. };
  25. struct scsi_cmnd {
  26. struct scsi_device *device;
  27. struct list_head list; /* scsi_cmnd participates in queue lists */
  28. struct list_head eh_entry; /* entry for the host eh_cmd_q */
  29. int eh_eflags; /* Used by error handlr */
  30. /*
  31. * A SCSI Command is assigned a nonzero serial_number before passed
  32. * to the driver's queue command function. The serial_number is
  33. * cleared when scsi_done is entered indicating that the command
  34. * has been completed. It is a bug for LLDDs to use this number
  35. * for purposes other than printk (and even that is only useful
  36. * for debugging).
  37. */
  38. unsigned long serial_number;
  39. /*
  40. * This is set to jiffies as it was when the command was first
  41. * allocated. It is used to time how long the command has
  42. * been outstanding
  43. */
  44. unsigned long jiffies_at_alloc;
  45. int retries;
  46. int allowed;
  47. int timeout_per_command;
  48. unsigned char cmd_len;
  49. enum dma_data_direction sc_data_direction;
  50. /* These elements define the operation we are about to perform */
  51. #define MAX_COMMAND_SIZE 16
  52. unsigned char cmnd[MAX_COMMAND_SIZE];
  53. unsigned request_bufflen; /* Actual request size */
  54. struct timer_list eh_timeout; /* Used to time out the command. */
  55. void *request_buffer; /* Actual requested buffer */
  56. /* These elements define the operation we ultimately want to perform */
  57. unsigned short use_sg; /* Number of pieces of scatter-gather */
  58. unsigned short __use_sg;
  59. unsigned underflow; /* Return error if less than
  60. this amount is transferred */
  61. unsigned transfersize; /* How much we are guaranteed to
  62. transfer with each SCSI transfer
  63. (ie, between disconnect /
  64. reconnects. Probably == sector
  65. size */
  66. int resid; /* Number of bytes requested to be
  67. transferred less actual number
  68. transferred (0 if not supported) */
  69. struct request *request; /* The command we are
  70. working on */
  71. #define SCSI_SENSE_BUFFERSIZE 96
  72. unsigned char *sense_buffer;
  73. /* obtained by REQUEST SENSE when
  74. * CHECK CONDITION is received on original
  75. * command (auto-sense) */
  76. /* Low-level done function - can be used by low-level driver to point
  77. * to completion function. Not used by mid/upper level code. */
  78. void (*scsi_done) (struct scsi_cmnd *);
  79. /*
  80. * The following fields can be written to by the host specific code.
  81. * Everything else should be left alone.
  82. */
  83. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  84. unsigned char *host_scribble; /* The host adapter is allowed to
  85. * call scsi_malloc and get some memory
  86. * and hang it here. The host adapter
  87. * is also expected to call scsi_free
  88. * to release this memory. (The memory
  89. * obtained by scsi_malloc is guaranteed
  90. * to be at an address < 16Mb). */
  91. int result; /* Status code from lower level driver */
  92. unsigned char tag; /* SCSI-II queued command tag */
  93. };
  94. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
  95. extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
  96. extern void scsi_put_command(struct scsi_cmnd *);
  97. extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
  98. struct device *);
  99. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  100. extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
  101. extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
  102. size_t *offset, size_t *len);
  103. extern void scsi_kunmap_atomic_sg(void *virt);
  104. extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
  105. extern void scsi_free_sgtable(struct scsi_cmnd *);
  106. extern int scsi_dma_map(struct scsi_cmnd *cmd);
  107. extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
  108. #define scsi_sg_count(cmd) ((cmd)->use_sg)
  109. #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer)
  110. #define scsi_bufflen(cmd) ((cmd)->request_bufflen)
  111. static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
  112. {
  113. cmd->resid = resid;
  114. }
  115. static inline int scsi_get_resid(struct scsi_cmnd *cmd)
  116. {
  117. return cmd->resid;
  118. }
  119. #define scsi_for_each_sg(cmd, sg, nseg, __i) \
  120. for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
  121. #endif /* _SCSI_SCSI_CMND_H */