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 6.0KB

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