scsi2sd.h 5.4 KB

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