You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scsi.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef _GPXE_SCSI_H
  2. #define _GPXE_SCSI_H
  3. #include <stdint.h>
  4. #include <gpxe/blockdev.h>
  5. /**
  6. * @defgroup scsiops SCSI operation codes
  7. * @{
  8. */
  9. #define SCSI_OPCODE_READ_16 0x88 /**< READ (16) */
  10. #define SCSI_OPCODE_WRITE_16 0x8a /**< WRITE (16) */
  11. #define SCSI_OPCODE_SERVICE_ACTION_IN 0x9e /**< SERVICE ACTION IN */
  12. #define SCSI_SERVICE_ACTION_READ_CAPACITY_16 0x10 /**< READ CAPACITY (16) */
  13. /** @} */
  14. /**
  15. * @defgroup scsiflags SCSI flags
  16. * @{
  17. */
  18. #define SCSI_FL_FUA_NV 0x02 /**< Force unit access to NVS */
  19. #define SCSI_FL_FUA 0x08 /**< Force unit access */
  20. #define SCSI_FL_DPO 0x10 /**< Disable cache page out */
  21. /** @} */
  22. /**
  23. * @defgroup scsicdbs SCSI command data blocks
  24. * @{
  25. */
  26. /** A SCSI "READ (16)" CDB */
  27. struct scsi_cdb_read_16 {
  28. /** Opcode (0x88) */
  29. uint8_t opcode;
  30. /** Flags */
  31. uint8_t flags;
  32. /** Start address
  33. *
  34. * This is a logical block number, in big-endian order.
  35. */
  36. uint64_t lba;
  37. /** Transfer length
  38. *
  39. * This is a logical block count, in big-endian order.
  40. */
  41. uint32_t len;
  42. /** Group number */
  43. uint8_t group;
  44. /** Control byte */
  45. uint8_t control;
  46. } __attribute__ (( packed ));
  47. /** A SCSI "WRITE (16)" CDB */
  48. struct scsi_cdb_write_16 {
  49. /** Opcode (0x8a) */
  50. uint8_t opcode;
  51. /** Flags */
  52. uint8_t flags;
  53. /** Start address
  54. *
  55. * This is a logical block number, in big-endian order.
  56. */
  57. uint64_t lba;
  58. /** Transfer length
  59. *
  60. * This is a logical block count, in big-endian order.
  61. */
  62. uint32_t len;
  63. /** Group number */
  64. uint8_t group;
  65. /** Control byte */
  66. uint8_t control;
  67. } __attribute__ (( packed ));
  68. /** A SCSI "READ CAPACITY (16)" CDB */
  69. struct scsi_cdb_read_capacity_16 {
  70. /** Opcode (0x9e) */
  71. uint8_t opcode;
  72. /** Service action */
  73. uint8_t service_action;
  74. /** Logical block address
  75. *
  76. * Applicable only if the PMI bit is set.
  77. */
  78. uint64_t lba;
  79. /** Transfer length
  80. *
  81. * This is the size of the data-in buffer, in bytes.
  82. */
  83. uint32_t len;
  84. /** Reserved */
  85. uint8_t reserved;
  86. /** Control byte */
  87. uint8_t control;
  88. } __attribute__ (( packed ));
  89. /** SCSI "READ CAPACITY (16)" parameter data */
  90. struct scsi_capacity_16 {
  91. /** Maximum logical block number */
  92. uint64_t lba;
  93. /** Block length in bytes */
  94. uint32_t blksize;
  95. /** Reserved */
  96. uint8_t reserved[20];
  97. } __attribute__ (( packed ));
  98. /** A SCSI Command Data Block */
  99. union scsi_cdb {
  100. struct scsi_cdb_read_16 read16;
  101. struct scsi_cdb_write_16 write16;
  102. struct scsi_cdb_read_capacity_16 readcap16;
  103. char bytes[16];
  104. };
  105. /** @} */
  106. /** A SCSI command */
  107. struct scsi_command {
  108. /** CDB for this command */
  109. union scsi_cdb cdb;
  110. /** Data-out buffer (may be NULL) */
  111. const void *data_out;
  112. /** Data-out buffer length
  113. *
  114. * Must be zero if @c data_out is NULL
  115. */
  116. size_t data_out_len;
  117. /** Data-in buffer (may be NULL) */
  118. void *data_in;
  119. /** Data-in buffer length
  120. *
  121. * Must be zero if @c data_in is NULL
  122. */
  123. size_t data_in_len;
  124. };
  125. /** A SCSI device */
  126. struct scsi_device {
  127. /** Block device interface */
  128. struct block_device blockdev;
  129. /** Logical unit number (LUN)
  130. *
  131. * This is a four-level LUN as specified by SAM-2, in
  132. * big-endian order.
  133. */
  134. uint64_t lun;
  135. /**
  136. * Issue SCSI command
  137. *
  138. * @v scsi SCSI device
  139. * @v command SCSI command
  140. * @ret rc Return status code
  141. */
  142. int ( * command ) ( struct scsi_device *scsi,
  143. struct scsi_command *command );
  144. };
  145. extern int init_scsidev ( struct scsi_device *scsi );
  146. #endif /* _GPXE_SCSI_H */