scsi_cmnd.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. struct request;
  8. struct scatterlist;
  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. void (*done) (struct scsi_cmnd *); /* Mid-level done function */
  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 currently doesn't have much use other
  35. * than printk's. Some lldd's use this number for other purposes.
  36. * It's almost certain that such usages are either incorrect or
  37. * meaningless. Please kill all usages other than printk's. Also,
  38. * as this number is always identical to ->pid, please convert
  39. * printk's to use ->pid, so that we can kill this field.
  40. */
  41. unsigned long serial_number;
  42. /*
  43. * This is set to jiffies as it was when the command was first
  44. * allocated. It is used to time how long the command has
  45. * been outstanding
  46. */
  47. unsigned long jiffies_at_alloc;
  48. int retries;
  49. int allowed;
  50. int timeout_per_command;
  51. unsigned char cmd_len;
  52. enum dma_data_direction sc_data_direction;
  53. /* These elements define the operation we are about to perform */
  54. #define MAX_COMMAND_SIZE 16
  55. unsigned char cmnd[MAX_COMMAND_SIZE];
  56. unsigned request_bufflen; /* Actual request size */
  57. struct timer_list eh_timeout; /* Used to time out the command. */
  58. void *request_buffer; /* Actual requested buffer */
  59. /* These elements define the operation we ultimately want to perform */
  60. unsigned short use_sg; /* Number of pieces of scatter-gather */
  61. unsigned short sglist_len; /* size of malloc'd scatter-gather list */
  62. unsigned underflow; /* Return error if less than
  63. this amount is transferred */
  64. unsigned transfersize; /* How much we are guaranteed to
  65. transfer with each SCSI transfer
  66. (ie, between disconnect /
  67. reconnects. Probably == sector
  68. size */
  69. int resid; /* Number of bytes requested to be
  70. transferred less actual number
  71. transferred (0 if not supported) */
  72. struct request *request; /* The command we are
  73. working on */
  74. #define SCSI_SENSE_BUFFERSIZE 96
  75. unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE];
  76. /* obtained by REQUEST SENSE when
  77. * CHECK CONDITION is received on original
  78. * command (auto-sense) */
  79. /* Low-level done function - can be used by low-level driver to point
  80. * to completion function. Not used by mid/upper level code. */
  81. void (*scsi_done) (struct scsi_cmnd *);
  82. /*
  83. * The following fields can be written to by the host specific code.
  84. * Everything else should be left alone.
  85. */
  86. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  87. unsigned char *host_scribble; /* The host adapter is allowed to
  88. * call scsi_malloc and get some memory
  89. * and hang it here. The host adapter
  90. * is also expected to call scsi_free
  91. * to release this memory. (The memory
  92. * obtained by scsi_malloc is guaranteed
  93. * to be at an address < 16Mb). */
  94. int result; /* Status code from lower level driver */
  95. unsigned char tag; /* SCSI-II queued command tag */
  96. unsigned long pid; /* Process ID, starts at 0. Unique per host. */
  97. };
  98. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
  99. extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
  100. extern void scsi_put_command(struct scsi_cmnd *);
  101. extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
  102. struct device *);
  103. extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
  104. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  105. extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
  106. extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
  107. size_t *offset, size_t *len);
  108. extern void scsi_kunmap_atomic_sg(void *virt);
  109. extern struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *, gfp_t);
  110. extern void scsi_free_sgtable(struct scatterlist *, int);
  111. extern int scsi_dma_map(struct scsi_cmnd *cmd);
  112. extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
  113. #define scsi_sg_count(cmd) ((cmd)->use_sg)
  114. #define scsi_sglist(cmd) ((struct scatterlist *)(cmd)->request_buffer)
  115. #define scsi_bufflen(cmd) ((cmd)->request_bufflen)
  116. static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
  117. {
  118. cmd->resid = resid;
  119. }
  120. static inline int scsi_get_resid(struct scsi_cmnd *cmd)
  121. {
  122. return cmd->resid;
  123. }
  124. #define scsi_for_each_sg(cmd, sg, nseg, __i) \
  125. for (__i = 0, sg = scsi_sglist(cmd); __i < (nseg); __i++, (sg)++)
  126. #endif /* _SCSI_SCSI_CMND_H */