scsi2sd.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 8
  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_ENABLE_BLIND_WRITES = 2, // Obsolete
  57. } S2S_CFG_FLAGS6;
  58. typedef enum
  59. {
  60. S2S_CFG_FIXED,
  61. S2S_CFG_REMOVEABLE,
  62. S2S_CFG_OPTICAL,
  63. S2S_CFG_FLOPPY_14MB,
  64. S2S_CFG_MO,
  65. S2S_CFG_SEQUENTIAL,
  66. S2S_CFG_NETWORK,
  67. } S2S_CFG_TYPE;
  68. typedef enum
  69. {
  70. S2S_CFG_QUIRKS_NONE = 0,
  71. S2S_CFG_QUIRKS_APPLE = 1,
  72. S2S_CFG_QUIRKS_OMTI = 2,
  73. S2S_CFG_QUIRKS_XEBEC = 4,
  74. S2S_CFG_QUIRKS_VMS = 8,
  75. } S2S_CFG_QUIRKS;
  76. typedef enum
  77. {
  78. S2S_CFG_SPEED_NoLimit,
  79. S2S_CFG_SPEED_ASYNC_15,
  80. S2S_CFG_SPEED_ASYNC_33,
  81. S2S_CFG_SPEED_ASYNC_50,
  82. S2S_CFG_SPEED_SYNC_5,
  83. S2S_CFG_SPEED_SYNC_10,
  84. S2S_CFG_SPEED_TURBO
  85. } S2S_CFG_SPEED;
  86. typedef struct __attribute__((packed))
  87. {
  88. // bits 7 -> 3 = S2S_CFG_TARGET_FLAGS
  89. // bits 2 -> 0 = target SCSI ID.
  90. uint8_t scsiId;
  91. uint8_t deviceType; // S2S_CFG_TYPE
  92. uint8_t flagsDEPRECATED; // S2S_CFG_FLAGS, removed in v4.5
  93. uint8_t deviceTypeModifier; // Used in INQUIRY response.
  94. uint32_t sdSectorStart;
  95. uint32_t scsiSectors;
  96. uint16_t bytesPerSector;
  97. // Max allowed by legacy IBM-PC bios is 6 bits (63)
  98. uint16_t sectorsPerTrack;
  99. // MS-Dos up to 7.10 will crash on >= 256 heads.
  100. uint16_t headsPerCylinder;
  101. char vendor[8];
  102. char prodId[16];
  103. char revision[4];
  104. char serial[16];
  105. uint16_t quirks; // S2S_CFG_QUIRKS
  106. uint8_t reserved[64]; // Pad out to 128 bytes for main section.
  107. } S2S_TargetCfg;
  108. typedef struct __attribute__((packed))
  109. {
  110. char magic[4]; // 'BCFG'
  111. uint8_t flags; // S2S_CFG_FLAGS
  112. uint8_t startupDelay; // Seconds.
  113. uint8_t selectionDelay; // milliseconds. 255 = auto
  114. uint8_t flags6; // S2S_CFG_FLAGS6
  115. uint8_t scsiSpeed;
  116. char wifiMACAddress[6];
  117. char wifiSSID[32];
  118. char wifiPassword[63];
  119. uint8_t reserved[18]; // Pad out to 128 bytes
  120. } S2S_BoardCfg;
  121. typedef enum
  122. {
  123. S2S_CMD_NONE, // Invalid
  124. // Command content:
  125. // uint8_t S2S_CFG_PING
  126. // Response:
  127. // S2S_CFG_STATUS
  128. S2S_CMD_PING,
  129. // Command content:
  130. // uint8_t S2S_CFG_WRITEFLASH
  131. // uint8_t[256] flashData
  132. // uint8_t flashArray
  133. // uint8_t flashRow
  134. // Response:
  135. // S2S_CFG_STATUS
  136. S2S_CMD_WRITEFLASH,
  137. // Command content:
  138. // uint8_t S2S_CFG_READFLASH
  139. // uint8_t flashArray
  140. // uint8_t flashRow
  141. // Response:
  142. // 256 bytes of flash
  143. S2S_CMD_READFLASH,
  144. // Command content:
  145. // uint8_t S2S_CFG_REBOOT
  146. // Response: None.
  147. S2S_CMD_REBOOT,
  148. // Command content:
  149. // uint8_t S2S_CFG_INFO
  150. // Response:
  151. // uint8_t[16] CSD
  152. // uint8_t[16] CID
  153. S2S_CMD_SDINFO,
  154. // Command content:
  155. // uint8_t S2S_CFG_SCSITEST
  156. // Response:
  157. // S2S_CFG_STATUS
  158. // uint8_t result code (0 = passed)
  159. S2S_CMD_SCSITEST,
  160. // Command content:
  161. // uint8_t S2S_CFG_DEVINFO
  162. // Response:
  163. // uint16_t protocol version (MSB)
  164. // uint16_t firmware version (MSB)
  165. // uint32_t SD capacity(MSB)
  166. S2S_CMD_DEVINFO,
  167. // Command content:
  168. // uint8_t S2S_CFG_SD_WRITE
  169. // uint32_t Sector Number (MSB)
  170. // uint8_t[512] data
  171. // Response:
  172. // S2S_CFG_STATUS
  173. S2S_CMD_SD_WRITE,
  174. // Command content:
  175. // uint8_t S2S_CFG_SD_READ
  176. // uint32_t Sector Number (MSB)
  177. // Response:
  178. // 512 bytes of data
  179. S2S_CMD_SD_READ,
  180. // Command content:
  181. // uint8_t S2S_CFG_DEBUG
  182. // Response:
  183. S2S_CMD_DEBUG,
  184. } S2S_COMMAND;
  185. typedef enum
  186. {
  187. S2S_CFG_STATUS_GOOD,
  188. S2S_CFG_STATUS_ERR,
  189. S2S_CFG_STATUS_BUSY
  190. } S2S_CFG_STATUS;
  191. #ifdef __cplusplus
  192. } // extern "C"
  193. #include <type_traits>
  194. static_assert(
  195. std::is_pod<S2S_TargetCfg>::value, "Misuse of TargetConfig struct"
  196. );
  197. static_assert(
  198. sizeof(S2S_TargetCfg) == 128,
  199. "TargetConfig struct size mismatch"
  200. );
  201. static_assert(
  202. std::is_pod<S2S_BoardCfg>::value, "Misuse of BoardConfig struct"
  203. );
  204. static_assert(
  205. sizeof(S2S_BoardCfg) == 128,
  206. "BoardConfig struct size mismatch"
  207. );
  208. #endif
  209. #endif