scsi_cmnd.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 sglist_len; /* size of malloc'd scatter-gather list */
  59. unsigned short __use_sg;
  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. int resid; /* Number of bytes requested to be
  68. transferred less actual number
  69. transferred (0 if not supported) */
  70. struct request *request; /* The command we are
  71. working on */
  72. #define SCSI_SENSE_BUFFERSIZE 96
  73. unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
  74. /* obtained by REQUEST SENSE when
  75. * CHECK CONDITION is received on original
  76. * command (auto-sense) */
  77. /* Low-level done function - can be used by low-level driver to point
  78. * to completion function. Not used by mid/upper level code. */
  79. void (*scsi_done) (struct scsi_cmnd *);
  80. /*
  81. * The following fields can be written to by the host specific code.
  82. * Everything else should be left alone.
  83. */
  84. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  85. unsigned char *host_scribble; /* The host adapter is allowed to
  86. * call scsi_malloc and get some memory
  87. * and hang it here. The host adapter
  88. * is also expected to call scsi_free
  89. * to release this memory. (The memory
  90. * obtained by scsi_malloc is guaranteed
  91. * to be at an address < 16Mb). */
  92. int result; /* Status code from lower level driver */
  93. unsigned char tag; /* SCSI-II queued command tag */
  94. };
  95. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
  96. extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
  97. extern void scsi_put_command(struct scsi_cmnd *);
  98. extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
  99. struct device *);
  100. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  101. extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
  102. extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
  103. size_t *offset, size_t *len);
  104. extern void scsi_kunmap_atomic_sg(void *virt);
  105. extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
  106. extern void scsi_free_sgtable(struct scsi_cmnd *);
  107. extern int scsi_dma_map(struct scsi_cmnd *cmd);
  108. extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
  109. #define scsi_sg_count(cmd) ((cmd)->use_sg)
  110. #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer)
  111. #define scsi_bufflen(cmd) ((cmd)->request_bufflen)
  112. static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
  113. {
  114. cmd->resid = resid;
  115. }
  116. static inline int scsi_get_resid(struct scsi_cmnd *cmd)
  117. {
  118. return cmd->resid;
  119. }
  120. #define scsi_for_each_sg(cmd, sg, nseg, __i) \
  121. for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
  122. #endif /* _SCSI_SCSI_CMND_H */