scsi_cmnd.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. struct request;
  7. struct scatterlist;
  8. struct scsi_device;
  9. struct scsi_request;
  10. /* embedded in scsi_cmnd */
  11. struct scsi_pointer {
  12. char *ptr; /* data pointer */
  13. int this_residual; /* left in this buffer */
  14. struct scatterlist *buffer; /* which buffer */
  15. int buffers_residual; /* how many buffers left */
  16. dma_addr_t dma_handle;
  17. volatile int Status;
  18. volatile int Message;
  19. volatile int have_data_in;
  20. volatile int sent_command;
  21. volatile int phase;
  22. };
  23. struct scsi_cmnd {
  24. int sc_magic;
  25. struct scsi_device *device;
  26. unsigned short state;
  27. unsigned short owner;
  28. struct scsi_request *sc_request;
  29. struct list_head list; /* scsi_cmnd participates in queue lists */
  30. struct list_head eh_entry; /* entry for the host eh_cmd_q */
  31. int eh_state; /* Used for state tracking in error handlr */
  32. int eh_eflags; /* Used by error handlr */
  33. void (*done) (struct scsi_cmnd *); /* Mid-level done function */
  34. /*
  35. * A SCSI Command is assigned a nonzero serial_number when internal_cmnd
  36. * passes it to the driver's queue command function. The serial_number
  37. * is cleared when scsi_done is entered indicating that the command has
  38. * been completed. If a timeout occurs, the serial number at the moment
  39. * of timeout is copied into serial_number_at_timeout. By subsequently
  40. * comparing the serial_number and serial_number_at_timeout fields
  41. * during abort or reset processing, we can detect whether the command
  42. * has already completed. This also detects cases where the command has
  43. * completed and the SCSI Command structure has already being reused
  44. * for another command, so that we can avoid incorrectly aborting or
  45. * resetting the new command.
  46. * The serial number is only unique per host.
  47. */
  48. unsigned long serial_number;
  49. unsigned long serial_number_at_timeout;
  50. int retries;
  51. int allowed;
  52. int timeout_per_command;
  53. int timeout_total;
  54. int timeout;
  55. /*
  56. * We handle the timeout differently if it happens when a reset,
  57. * abort, etc are in process.
  58. */
  59. unsigned volatile char internal_timeout;
  60. unsigned char cmd_len;
  61. unsigned char old_cmd_len;
  62. enum dma_data_direction sc_data_direction;
  63. enum dma_data_direction sc_old_data_direction;
  64. /* These elements define the operation we are about to perform */
  65. #define MAX_COMMAND_SIZE 16
  66. unsigned char cmnd[MAX_COMMAND_SIZE];
  67. unsigned request_bufflen; /* Actual request size */
  68. struct timer_list eh_timeout; /* Used to time out the command. */
  69. void *request_buffer; /* Actual requested buffer */
  70. /* These elements define the operation we ultimately want to perform */
  71. unsigned char data_cmnd[MAX_COMMAND_SIZE];
  72. unsigned short old_use_sg; /* We save use_sg here when requesting
  73. * sense info */
  74. unsigned short use_sg; /* Number of pieces of scatter-gather */
  75. unsigned short sglist_len; /* size of malloc'd scatter-gather list */
  76. unsigned short abort_reason; /* If the mid-level code requests an
  77. * abort, this is the reason. */
  78. unsigned bufflen; /* Size of data buffer */
  79. void *buffer; /* Data buffer */
  80. unsigned underflow; /* Return error if less than
  81. this amount is transferred */
  82. unsigned old_underflow; /* save underflow here when reusing the
  83. * command for error handling */
  84. unsigned transfersize; /* How much we are guaranteed to
  85. transfer with each SCSI transfer
  86. (ie, between disconnect /
  87. reconnects. Probably == sector
  88. size */
  89. int resid; /* Number of bytes requested to be
  90. transferred less actual number
  91. transferred (0 if not supported) */
  92. struct request *request; /* The command we are
  93. working on */
  94. #define SCSI_SENSE_BUFFERSIZE 96
  95. unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
  96. * when CHECK CONDITION is
  97. * received on original command
  98. * (auto-sense) */
  99. /* Low-level done function - can be used by low-level driver to point
  100. * to completion function. Not used by mid/upper level code. */
  101. void (*scsi_done) (struct scsi_cmnd *);
  102. /*
  103. * The following fields can be written to by the host specific code.
  104. * Everything else should be left alone.
  105. */
  106. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  107. unsigned char *host_scribble; /* The host adapter is allowed to
  108. * call scsi_malloc and get some memory
  109. * and hang it here. The host adapter
  110. * is also expected to call scsi_free
  111. * to release this memory. (The memory
  112. * obtained by scsi_malloc is guaranteed
  113. * to be at an address < 16Mb). */
  114. int result; /* Status code from lower level driver */
  115. unsigned char tag; /* SCSI-II queued command tag */
  116. unsigned long pid; /* Process ID, starts at 0. Unique per host. */
  117. };
  118. /*
  119. * These are the values that scsi_cmd->state can take.
  120. */
  121. #define SCSI_STATE_TIMEOUT 0x1000
  122. #define SCSI_STATE_FINISHED 0x1001
  123. #define SCSI_STATE_FAILED 0x1002
  124. #define SCSI_STATE_QUEUED 0x1003
  125. #define SCSI_STATE_UNUSED 0x1006
  126. #define SCSI_STATE_DISCONNECTING 0x1008
  127. #define SCSI_STATE_INITIALIZING 0x1009
  128. #define SCSI_STATE_BHQUEUE 0x100a
  129. #define SCSI_STATE_MLQUEUE 0x100b
  130. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, int);
  131. extern void scsi_put_command(struct scsi_cmnd *);
  132. extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
  133. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  134. #endif /* _SCSI_SCSI_CMND_H */