scsi2sd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef scsi2sd_h
  18. #define scsi2sd_h
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /* Common type definitions shared between the firmware and config tools
  23. The configuration data is now stored on the SD card, occupying the
  24. last 2 sectors.
  25. BoardConfig
  26. TargetConfig (disk 0)
  27. TargetConfig (disk 1)
  28. TargetConfig (disk 2)
  29. TargetConfig (disk 3)
  30. TargetConfig (disk 4)
  31. TargetConfig (disk 5)
  32. TargetConfig (disk 6)
  33. */
  34. #include "stdint.h"
  35. #define S2S_MAX_TARGETS 7
  36. #define S2S_CFG_SIZE (S2S_MAX_TARGETS * sizeof(S2S_TargetCfg) + sizeof(S2S_BoardCfg))
  37. typedef enum
  38. {
  39. S2S_CFG_TARGET_ID_BITS = 0x07,
  40. S2S_CFG_TARGET_ENABLED = 0x80
  41. } S2S_CFG_TARGET_FLAGS;
  42. typedef enum
  43. {
  44. S2S_CFG_ENABLE_UNIT_ATTENTION = 1,
  45. S2S_CFG_ENABLE_PARITY = 2,
  46. S2S_CFG_ENABLE_SCSI2 = 4,
  47. S2S_CFG_DISABLE_GLITCH = 8,
  48. S2S_CFG_ENABLE_CACHE = 16,
  49. S2S_CFG_ENABLE_DISCONNECT = 32,
  50. S2S_CFG_ENABLE_SEL_LATCH = 64,
  51. S2S_CFG_MAP_LUNS_TO_IDS = 128
  52. } S2S_CFG_FLAGS;
  53. typedef enum
  54. {
  55. S2S_CFG_ENABLE_TERMINATOR = 1
  56. } S2S_CFG_FLAGS6;
  57. typedef enum
  58. {
  59. S2S_CFG_FIXED,
  60. S2S_CFG_REMOVEABLE,
  61. S2S_CFG_OPTICAL,
  62. S2S_CFG_FLOPPY_14MB,
  63. S2S_CFG_MO,
  64. S2S_CFG_SEQUENTIAL
  65. } S2S_CFG_TYPE;
  66. typedef enum
  67. {
  68. S2S_CFG_QUIRKS_NONE,
  69. S2S_CFG_QUIRKS_APPLE,
  70. S2S_CFG_QUIRKS_OMTI
  71. } S2S_CFG_QUIRKS;
  72. typedef enum
  73. {
  74. S2S_CFG_SPEED_NoLimit,
  75. S2S_CFG_SPEED_ASYNC_15,
  76. S2S_CFG_SPEED_ASYNC_33,
  77. S2S_CFG_SPEED_ASYNC_50,
  78. S2S_CFG_SPEED_SYNC_5,
  79. S2S_CFG_SPEED_SYNC_10
  80. } S2S_CFG_SPEED;
  81. typedef struct __attribute__((packed))
  82. {
  83. // bits 7 -> 3 = S2S_CFG_TARGET_FLAGS
  84. // bits 2 -> 0 = target SCSI ID.
  85. uint8_t scsiId;
  86. uint8_t deviceType; // S2S_CFG_TYPE
  87. uint8_t flagsDEPRECATED; // S2S_CFG_FLAGS, removed in v4.5
  88. uint8_t deviceTypeModifier; // Used in INQUIRY response.
  89. uint32_t sdSectorStart;
  90. uint32_t scsiSectors;
  91. uint16_t bytesPerSector;
  92. // Max allowed by legacy IBM-PC bios is 6 bits (63)
  93. uint16_t sectorsPerTrack;
  94. // MS-Dos up to 7.10 will crash on >= 256 heads.
  95. uint16_t headsPerCylinder;
  96. char vendor[8];
  97. char prodId[16];
  98. char revision[4];
  99. char serial[16];
  100. uint16_t quirks; // S2S_CFG_QUIRKS
  101. uint8_t reserved[64]; // Pad out to 128 bytes for main section.
  102. } S2S_TargetCfg;
  103. typedef struct __attribute__((packed))
  104. {
  105. char magic[4]; // 'BCFG'
  106. uint8_t flags; // S2S_CFG_FLAGS
  107. uint8_t startupDelay; // Seconds.
  108. uint8_t selectionDelay; // milliseconds. 255 = auto
  109. uint8_t flags6; // S2S_CFG_FLAGS6
  110. uint8_t scsiSpeed;
  111. uint8_t reserved[119]; // Pad out to 128 bytes
  112. } S2S_BoardCfg;
  113. typedef enum
  114. {
  115. S2S_CMD_NONE, // Invalid
  116. // Command content:
  117. // uint8_t S2S_CFG_PING
  118. // Response:
  119. // S2S_CFG_STATUS
  120. S2S_CMD_PING,
  121. // Command content:
  122. // uint8_t S2S_CFG_WRITEFLASH
  123. // uint8_t[256] flashData
  124. // uint8_t flashArray
  125. // uint8_t flashRow
  126. // Response:
  127. // S2S_CFG_STATUS
  128. S2S_CMD_WRITEFLASH,
  129. // Command content:
  130. // uint8_t S2S_CFG_READFLASH
  131. // uint8_t flashArray
  132. // uint8_t flashRow
  133. // Response:
  134. // 256 bytes of flash
  135. S2S_CMD_READFLASH,
  136. // Command content:
  137. // uint8_t S2S_CFG_REBOOT
  138. // Response: None.
  139. S2S_CMD_REBOOT,
  140. // Command content:
  141. // uint8_t S2S_CFG_INFO
  142. // Response:
  143. // uint8_t[16] CSD
  144. // uint8_t[16] CID
  145. S2S_CMD_SDINFO,
  146. // Command content:
  147. // uint8_t S2S_CFG_SCSITEST
  148. // Response:
  149. // S2S_CFG_STATUS
  150. // uint8_t result code (0 = passed)
  151. S2S_CMD_SCSITEST,
  152. // Command content:
  153. // uint8_t S2S_CFG_DEVINFO
  154. // Response:
  155. // uint16_t protocol version (MSB)
  156. // uint16_t firmware version (MSB)
  157. // uint32_t SD capacity(MSB)
  158. S2S_CMD_DEVINFO,
  159. // Command content:
  160. // uint8_t S2S_CFG_SD_WRITE
  161. // uint32_t Sector Number (MSB)
  162. // uint8_t[512] data
  163. // Response:
  164. // S2S_CFG_STATUS
  165. S2S_CMD_SD_WRITE,
  166. // Command content:
  167. // uint8_t S2S_CFG_SD_READ
  168. // uint32_t Sector Number (MSB)
  169. // Response:
  170. // 512 bytes of data
  171. S2S_CMD_SD_READ,
  172. // Command content:
  173. // uint8_t S2S_CFG_DEBUG
  174. // Response:
  175. S2S_CMD_DEBUG,
  176. } S2S_COMMAND;
  177. typedef enum
  178. {
  179. S2S_CFG_STATUS_GOOD,
  180. S2S_CFG_STATUS_ERR,
  181. S2S_CFG_STATUS_BUSY
  182. } S2S_CFG_STATUS;
  183. #ifdef __cplusplus
  184. } // extern "C"
  185. #include <type_traits>
  186. static_assert(
  187. std::is_pod<S2S_TargetCfg>::value, "Misuse of TargetConfig struct"
  188. );
  189. static_assert(
  190. sizeof(S2S_TargetCfg) == 128,
  191. "TargetConfig struct size mismatch"
  192. );
  193. static_assert(
  194. std::is_pod<S2S_BoardCfg>::value, "Misuse of BoardConfig struct"
  195. );
  196. static_assert(
  197. sizeof(S2S_BoardCfg) == 128,
  198. "BoardConfig struct size mismatch"
  199. );
  200. #endif
  201. #endif