scsi_cmnd.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. unsigned char cmd_len;
  56. unsigned char old_cmd_len;
  57. enum dma_data_direction sc_data_direction;
  58. enum dma_data_direction sc_old_data_direction;
  59. /* These elements define the operation we are about to perform */
  60. #define MAX_COMMAND_SIZE 16
  61. unsigned char cmnd[MAX_COMMAND_SIZE];
  62. unsigned request_bufflen; /* Actual request size */
  63. struct timer_list eh_timeout; /* Used to time out the command. */
  64. void *request_buffer; /* Actual requested buffer */
  65. /* These elements define the operation we ultimately want to perform */
  66. unsigned char data_cmnd[MAX_COMMAND_SIZE];
  67. unsigned short old_use_sg; /* We save use_sg here when requesting
  68. * sense info */
  69. unsigned short use_sg; /* Number of pieces of scatter-gather */
  70. unsigned short sglist_len; /* size of malloc'd scatter-gather list */
  71. unsigned short abort_reason; /* If the mid-level code requests an
  72. * abort, this is the reason. */
  73. unsigned bufflen; /* Size of data buffer */
  74. void *buffer; /* Data buffer */
  75. unsigned underflow; /* Return error if less than
  76. this amount is transferred */
  77. unsigned old_underflow; /* save underflow here when reusing the
  78. * command for error handling */
  79. unsigned transfersize; /* How much we are guaranteed to
  80. transfer with each SCSI transfer
  81. (ie, between disconnect /
  82. reconnects. Probably == sector
  83. size */
  84. int resid; /* Number of bytes requested to be
  85. transferred less actual number
  86. transferred (0 if not supported) */
  87. struct request *request; /* The command we are
  88. working on */
  89. #define SCSI_SENSE_BUFFERSIZE 96
  90. unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
  91. * when CHECK CONDITION is
  92. * received on original command
  93. * (auto-sense) */
  94. /* Low-level done function - can be used by low-level driver to point
  95. * to completion function. Not used by mid/upper level code. */
  96. void (*scsi_done) (struct scsi_cmnd *);
  97. /*
  98. * The following fields can be written to by the host specific code.
  99. * Everything else should be left alone.
  100. */
  101. struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
  102. unsigned char *host_scribble; /* The host adapter is allowed to
  103. * call scsi_malloc and get some memory
  104. * and hang it here. The host adapter
  105. * is also expected to call scsi_free
  106. * to release this memory. (The memory
  107. * obtained by scsi_malloc is guaranteed
  108. * to be at an address < 16Mb). */
  109. int result; /* Status code from lower level driver */
  110. unsigned char tag; /* SCSI-II queued command tag */
  111. unsigned long pid; /* Process ID, starts at 0. Unique per host. */
  112. };
  113. /*
  114. * These are the values that scsi_cmd->state can take.
  115. */
  116. #define SCSI_STATE_TIMEOUT 0x1000
  117. #define SCSI_STATE_FINISHED 0x1001
  118. #define SCSI_STATE_FAILED 0x1002
  119. #define SCSI_STATE_QUEUED 0x1003
  120. #define SCSI_STATE_UNUSED 0x1006
  121. #define SCSI_STATE_DISCONNECTING 0x1008
  122. #define SCSI_STATE_INITIALIZING 0x1009
  123. #define SCSI_STATE_BHQUEUE 0x100a
  124. #define SCSI_STATE_MLQUEUE 0x100b
  125. extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, int);
  126. extern void scsi_put_command(struct scsi_cmnd *);
  127. extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
  128. extern void scsi_finish_command(struct scsi_cmnd *cmd);
  129. #endif /* _SCSI_SCSI_CMND_H */