scsi2sd.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. //
  18. // This work incorporates work from the following
  19. // Copyright (c) 2023 joshua stein <jcs@jcs.org>
  20. #ifndef scsi2sd_h
  21. #define scsi2sd_h
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Common type definitions shared between the firmware and config tools
  26. The configuration data is now stored on the SD card, occupying the
  27. last 2 sectors.
  28. BoardConfig
  29. TargetConfig (disk 0)
  30. TargetConfig (disk 1)
  31. TargetConfig (disk 2)
  32. TargetConfig (disk 3)
  33. TargetConfig (disk 4)
  34. TargetConfig (disk 5)
  35. TargetConfig (disk 6)
  36. */
  37. #include "stdint.h"
  38. #define S2S_MAX_TARGETS 8
  39. #define S2S_CFG_SIZE (S2S_MAX_TARGETS * sizeof(S2S_TargetCfg) + sizeof(S2S_BoardCfg))
  40. typedef enum
  41. {
  42. S2S_CFG_TARGET_ID_BITS = 0x07,
  43. S2S_CFG_TARGET_ENABLED = 0x80
  44. } S2S_CFG_TARGET_FLAGS;
  45. typedef enum
  46. {
  47. S2S_CFG_ENABLE_UNIT_ATTENTION = 1,
  48. S2S_CFG_ENABLE_PARITY = 2,
  49. S2S_CFG_ENABLE_SCSI2 = 4,
  50. S2S_CFG_DISABLE_GLITCH = 8,
  51. S2S_CFG_ENABLE_CACHE = 16,
  52. S2S_CFG_ENABLE_DISCONNECT = 32,
  53. S2S_CFG_ENABLE_SEL_LATCH = 64,
  54. S2S_CFG_MAP_LUNS_TO_IDS = 128
  55. } S2S_CFG_FLAGS;
  56. typedef enum
  57. {
  58. S2S_CFG_ENABLE_TERMINATOR = 1
  59. //S2S_CFG_ENABLE_BLIND_WRITES = 2, // Obosolete
  60. } S2S_CFG_FLAGS6;
  61. typedef enum
  62. {
  63. S2S_CFG_FIXED,
  64. S2S_CFG_REMOVEABLE,
  65. S2S_CFG_OPTICAL,
  66. S2S_CFG_FLOPPY_14MB,
  67. S2S_CFG_MO,
  68. S2S_CFG_SEQUENTIAL,
  69. S2S_CFG_NETWORK,
  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_EMU = 9
  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. uint8_t reserved[64]; // Pad out to 128 bytes for main section.
  111. } S2S_TargetCfg;
  112. typedef struct __attribute__((packed))
  113. {
  114. char magic[4]; // 'BCFG'
  115. uint8_t flags; // S2S_CFG_FLAGS
  116. uint8_t startupDelay; // Seconds.
  117. uint8_t selectionDelay; // milliseconds. 255 = auto
  118. uint8_t flags6; // S2S_CFG_FLAGS6
  119. uint8_t scsiSpeed;
  120. char wifiMACAddress[6];
  121. char wifiSSID[32];
  122. char wifiPassword[63];
  123. uint8_t reserved[18]; // Pad out to 128 bytes
  124. } S2S_BoardCfg;
  125. typedef enum
  126. {
  127. S2S_CMD_NONE, // Invalid
  128. // Command content:
  129. // uint8_t S2S_CFG_PING
  130. // Response:
  131. // S2S_CFG_STATUS
  132. S2S_CMD_PING,
  133. // Command content:
  134. // uint8_t S2S_CFG_WRITEFLASH
  135. // uint8_t[256] flashData
  136. // uint8_t flashArray
  137. // uint8_t flashRow
  138. // Response:
  139. // S2S_CFG_STATUS
  140. S2S_CMD_WRITEFLASH,
  141. // Command content:
  142. // uint8_t S2S_CFG_READFLASH
  143. // uint8_t flashArray
  144. // uint8_t flashRow
  145. // Response:
  146. // 256 bytes of flash
  147. S2S_CMD_READFLASH,
  148. // Command content:
  149. // uint8_t S2S_CFG_REBOOT
  150. // Response: None.
  151. S2S_CMD_REBOOT,
  152. // Command content:
  153. // uint8_t S2S_CFG_INFO
  154. // Response:
  155. // uint8_t[16] CSD
  156. // uint8_t[16] CID
  157. S2S_CMD_SDINFO,
  158. // Command content:
  159. // uint8_t S2S_CFG_SCSITEST
  160. // Response:
  161. // S2S_CFG_STATUS
  162. // uint8_t result code (0 = passed)
  163. S2S_CMD_SCSITEST,
  164. // Command content:
  165. // uint8_t S2S_CFG_DEVINFO
  166. // Response:
  167. // uint16_t protocol version (MSB)
  168. // uint16_t firmware version (MSB)
  169. // uint32_t SD capacity(MSB)
  170. S2S_CMD_DEVINFO,
  171. // Command content:
  172. // uint8_t S2S_CFG_SD_WRITE
  173. // uint32_t Sector Number (MSB)
  174. // uint8_t[512] data
  175. // Response:
  176. // S2S_CFG_STATUS
  177. S2S_CMD_SD_WRITE,
  178. // Command content:
  179. // uint8_t S2S_CFG_SD_READ
  180. // uint32_t Sector Number (MSB)
  181. // Response:
  182. // 512 bytes of data
  183. S2S_CMD_SD_READ,
  184. // Command content:
  185. // uint8_t S2S_CFG_DEBUG
  186. // Response:
  187. S2S_CMD_DEBUG,
  188. } S2S_COMMAND;
  189. typedef enum
  190. {
  191. S2S_CFG_STATUS_GOOD,
  192. S2S_CFG_STATUS_ERR,
  193. S2S_CFG_STATUS_BUSY
  194. } S2S_CFG_STATUS;
  195. #ifdef __cplusplus
  196. } // extern "C"
  197. #include <type_traits>
  198. static_assert(
  199. std::is_pod<S2S_TargetCfg>::value, "Misuse of TargetConfig struct"
  200. );
  201. static_assert(
  202. sizeof(S2S_TargetCfg) == 128,
  203. "TargetConfig struct size mismatch"
  204. );
  205. static_assert(
  206. std::is_pod<S2S_BoardCfg>::value, "Misuse of BoardConfig struct"
  207. );
  208. static_assert(
  209. sizeof(S2S_BoardCfg) == 128,
  210. "BoardConfig struct size mismatch"
  211. );
  212. #endif
  213. #endif