Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

scsi.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #ifndef _GPXE_SCSI_H
  2. #define _GPXE_SCSI_H
  3. #include <stdint.h>
  4. #include <gpxe/blockdev.h>
  5. #include <gpxe/uaccess.h>
  6. /** @file
  7. *
  8. * SCSI devices
  9. *
  10. */
  11. /**
  12. * @defgroup scsiops SCSI operation codes
  13. * @{
  14. */
  15. #define SCSI_OPCODE_READ_16 0x88 /**< READ (16) */
  16. #define SCSI_OPCODE_WRITE_16 0x8a /**< WRITE (16) */
  17. #define SCSI_OPCODE_READ_CAPACITY_10 0x25 /**< READ CAPACITY (10) */
  18. #define SCSI_OPCODE_SERVICE_ACTION_IN 0x9e /**< SERVICE ACTION IN */
  19. #define SCSI_SERVICE_ACTION_READ_CAPACITY_16 0x10 /**< READ CAPACITY (16) */
  20. /** @} */
  21. /**
  22. * @defgroup scsiflags SCSI flags
  23. * @{
  24. */
  25. #define SCSI_FL_FUA_NV 0x02 /**< Force unit access to NVS */
  26. #define SCSI_FL_FUA 0x08 /**< Force unit access */
  27. #define SCSI_FL_DPO 0x10 /**< Disable cache page out */
  28. /** @} */
  29. /**
  30. * @defgroup scsicdbs SCSI command data blocks
  31. * @{
  32. */
  33. /** A SCSI "READ (16)" CDB */
  34. struct scsi_cdb_read_16 {
  35. /** Opcode (0x88) */
  36. uint8_t opcode;
  37. /** Flags */
  38. uint8_t flags;
  39. /** Start address
  40. *
  41. * This is a logical block number, in big-endian order.
  42. */
  43. uint64_t lba;
  44. /** Transfer length
  45. *
  46. * This is a logical block count, in big-endian order.
  47. */
  48. uint32_t len;
  49. /** Group number */
  50. uint8_t group;
  51. /** Control byte */
  52. uint8_t control;
  53. } __attribute__ (( packed ));
  54. /** A SCSI "WRITE (16)" CDB */
  55. struct scsi_cdb_write_16 {
  56. /** Opcode (0x8a) */
  57. uint8_t opcode;
  58. /** Flags */
  59. uint8_t flags;
  60. /** Start address
  61. *
  62. * This is a logical block number, in big-endian order.
  63. */
  64. uint64_t lba;
  65. /** Transfer length
  66. *
  67. * This is a logical block count, in big-endian order.
  68. */
  69. uint32_t len;
  70. /** Group number */
  71. uint8_t group;
  72. /** Control byte */
  73. uint8_t control;
  74. } __attribute__ (( packed ));
  75. /** A SCSI "READ CAPACITY (10)" CDB */
  76. struct scsi_cdb_read_capacity_10 {
  77. /** Opcode (0x25) */
  78. uint8_t opcode;
  79. /** Reserved */
  80. uint8_t reserved_a;
  81. /** Logical block address
  82. *
  83. * Applicable only if the PMI bit is set.
  84. */
  85. uint32_t lba;
  86. /** Reserved */
  87. uint8_t reserved_b[3];
  88. /** Control byte */
  89. uint8_t control;
  90. } __attribute__ (( packed ));
  91. /** SCSI "READ CAPACITY (10)" parameter data */
  92. struct scsi_capacity_10 {
  93. /** Maximum logical block number */
  94. uint32_t lba;
  95. /** Block length in bytes */
  96. uint32_t blksize;
  97. } __attribute__ (( packed ));
  98. /** A SCSI "READ CAPACITY (16)" CDB */
  99. struct scsi_cdb_read_capacity_16 {
  100. /** Opcode (0x9e) */
  101. uint8_t opcode;
  102. /** Service action */
  103. uint8_t service_action;
  104. /** Logical block address
  105. *
  106. * Applicable only if the PMI bit is set.
  107. */
  108. uint64_t lba;
  109. /** Transfer length
  110. *
  111. * This is the size of the data-in buffer, in bytes.
  112. */
  113. uint32_t len;
  114. /** Reserved */
  115. uint8_t reserved;
  116. /** Control byte */
  117. uint8_t control;
  118. } __attribute__ (( packed ));
  119. /** SCSI "READ CAPACITY (16)" parameter data */
  120. struct scsi_capacity_16 {
  121. /** Maximum logical block number */
  122. uint64_t lba;
  123. /** Block length in bytes */
  124. uint32_t blksize;
  125. /** Reserved */
  126. uint8_t reserved[20];
  127. } __attribute__ (( packed ));
  128. /** A SCSI Command Data Block */
  129. union scsi_cdb {
  130. struct scsi_cdb_read_16 read16;
  131. struct scsi_cdb_write_16 write16;
  132. struct scsi_cdb_read_capacity_10 readcap10;
  133. struct scsi_cdb_read_capacity_16 readcap16;
  134. unsigned char bytes[16];
  135. };
  136. /** printf() format for dumping a scsi_cdb */
  137. #define SCSI_CDB_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" \
  138. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
  139. /** printf() parameters for dumping a scsi_cdb */
  140. #define SCSI_CDB_DATA(cdb) \
  141. (cdb).bytes[0], (cdb).bytes[1], (cdb).bytes[2], (cdb).bytes[3], \
  142. (cdb).bytes[4], (cdb).bytes[5], (cdb).bytes[6], (cdb).bytes[7], \
  143. (cdb).bytes[8], (cdb).bytes[9], (cdb).bytes[10], (cdb).bytes[11], \
  144. (cdb).bytes[12], (cdb).bytes[13], (cdb).bytes[14], (cdb).bytes[15]
  145. /** @} */
  146. /** A SCSI command */
  147. struct scsi_command {
  148. /** CDB for this command */
  149. union scsi_cdb cdb;
  150. /** Data-out buffer (may be NULL) */
  151. userptr_t data_out;
  152. /** Data-out buffer length
  153. *
  154. * Must be zero if @c data_out is NULL
  155. */
  156. size_t data_out_len;
  157. /** Data-in buffer (may be NULL) */
  158. userptr_t data_in;
  159. /** Data-in buffer length
  160. *
  161. * Must be zero if @c data_in is NULL
  162. */
  163. size_t data_in_len;
  164. /** SCSI statua code */
  165. uint8_t status;
  166. /** SCSI sense response code */
  167. uint8_t sense_response;
  168. };
  169. /** A SCSI device */
  170. struct scsi_device {
  171. /** Block device interface */
  172. struct block_device blockdev;
  173. /** Logical unit number (LUN)
  174. *
  175. * This is a four-level LUN as specified by SAM-2, in
  176. * big-endian order.
  177. */
  178. uint64_t lun;
  179. /**
  180. * Issue SCSI command
  181. *
  182. * @v scsi SCSI device
  183. * @v command SCSI command
  184. * @ret rc Return status code
  185. *
  186. * Note that a successful return status code indicates only
  187. * that the SCSI command completed. The caller must check the
  188. * status field in the command structure to see if, for
  189. * example, the device returned CHECK CONDITION or some other
  190. * non-success status code.
  191. */
  192. int ( * command ) ( struct scsi_device *scsi,
  193. struct scsi_command *command );
  194. };
  195. extern int init_scsidev ( struct scsi_device *scsi );
  196. #endif /* _GPXE_SCSI_H */