scsi2sd.h 5.5 KB

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