scsi_cmnd.h 4.6 KB

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