scsi2sd.h 5.4 KB

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