My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UHS_SCSI.h 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* Copyright (C) 2015-2016 Andrew J. Kroll
  2. and
  3. Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. Contact information
  16. -------------------
  17. Circuits At Home, LTD
  18. Web : https://www.circuitsathome.com
  19. e-mail : support@circuitsathome.com
  20. */
  21. #ifndef UHS_SCSI_H
  22. #define UHS_SCSI_H
  23. /*
  24. * Reference documents from T10 (https://www.t10.org)
  25. * SCSI Primary Commands - 3 (SPC-3)
  26. * SCSI Block Commands - 2 (SBC-2)
  27. * Multi-Media Commands - 5 (MMC-5)
  28. */
  29. /* Group 1 commands (CDB's here are should all be 6-bytes) */
  30. #define SCSI_CMD_TEST_UNIT_READY 0x00U
  31. #define SCSI_CMD_REQUEST_SENSE 0x03U
  32. #define SCSI_CMD_FORMAT_UNIT 0x04U
  33. #define SCSI_CMD_READ_6 0x08U
  34. #define SCSI_CMD_WRITE_6 0x0AU
  35. #define SCSI_CMD_INQUIRY 0x12U
  36. #define SCSI_CMD_MODE_SELECT_6 0x15U
  37. #define SCSI_CMD_MODE_SENSE_6 0x1AU
  38. #define SCSI_CMD_START_STOP_UNIT 0x1BU
  39. #define SCSI_CMD_PREVENT_REMOVAL 0x1EU
  40. /* Group 2 Commands (CDB's here are 10-bytes) */
  41. #define SCSI_CMD_READ_FORMAT_CAPACITIES 0x23U
  42. #define SCSI_CMD_READ_CAPACITY_10 0x25U
  43. #define SCSI_CMD_READ_10 0x28U
  44. #define SCSI_CMD_WRITE_10 0x2AU
  45. #define SCSI_CMD_SEEK_10 0x2BU
  46. #define SCSI_CMD_ERASE_10 0x2CU
  47. #define SCSI_CMD_WRITE_AND_VERIFY_10 0x2EU
  48. #define SCSI_CMD_VERIFY_10 0x2FU
  49. #define SCSI_CMD_SYNCHRONIZE_CACHE 0x35U
  50. #define SCSI_CMD_WRITE_BUFFER 0x3BU
  51. #define SCSI_CMD_READ_BUFFER 0x3CU
  52. #define SCSI_CMD_READ_SUBCHANNEL 0x42U
  53. #define SCSI_CMD_READ_TOC 0x43U
  54. #define SCSI_CMD_READ_HEADER 0x44U
  55. #define SCSI_CMD_PLAY_AUDIO_10 0x45U
  56. #define SCSI_CMD_GET_CONFIGURATION 0x46U
  57. #define SCSI_CMD_PLAY_AUDIO_MSF 0x47U
  58. #define SCSI_CMD_PLAY_AUDIO_TI 0x48U
  59. #define SCSI_CMD_PLAY_TRACK_REL_10 0x49U
  60. #define SCSI_CMD_GET_EVENT_STATUS 0x4AU
  61. #define SCSI_CMD_PAUSE_RESUME 0x4BU
  62. #define SCSI_CMD_READ_DISC_INFORMATION 0x51U
  63. #define SCSI_CMD_READ_TRACK_INFORMATION 0x52U
  64. #define SCSI_CMD_RESERVE_TRACK 0x53U
  65. #define SCSI_CMD_SEND_OPC_INFORMATION 0x54U
  66. #define SCSI_CMD_MODE_SELECT_10 0x55U
  67. #define SCSI_CMD_REPAIR_TRACK 0x58U
  68. #define SCSI_CMD_MODE_SENSE_10 0x5AU
  69. #define SCSI_CMD_CLOSE_TRACK_SESSION 0x5BU
  70. #define SCSI_CMD_READ_BUFFER_CAPACITY 0x5CU
  71. #define SCSI_CMD_SEND_CUE_SHEET 0x5DU
  72. /* Group 5 Commands (CDB's here are 12-bytes) */
  73. #define SCSI_CMD_REPORT_LUNS 0xA0U
  74. #define SCSI_CMD_BLANK 0xA1U
  75. #define SCSI_CMD_SECURITY_PROTOCOL_IN 0xA2U
  76. #define SCSI_CMD_SEND_KEY 0xA3U
  77. #define SCSI_CMD_REPORT_KEY 0xA4U
  78. #define SCSI_CMD_PLAY_AUDIO_12 0xA5U
  79. #define SCSI_CMD_LOAD_UNLOAD 0xA6U
  80. #define SCSI_CMD_SET_READ_AHEAD 0xA7U
  81. #define SCSI_CMD_READ_12 0xA8U
  82. #define SCSI_CMD_PLAY_TRACK_REL_12 0xA9U
  83. #define SCSI_CMD_WRITE_12 0xAAU
  84. #define SCSI_CMD_READ_MEDIA_SERIAL_12 0xABU
  85. #define SCSI_CMD_GET_PERFORMANCE 0xACU
  86. #define SCSI_CMD_READ_DVD_STRUCTURE 0xADU
  87. #define SCSI_CMD_SECURITY_PROTOCOL_OUT 0xB5U
  88. #define SCSI_CMD_SET_STREAMING 0xB6U
  89. #define SCSI_CMD_READ_MSF 0xB9U
  90. #define SCSI_CMD_SET_SPEED 0xBBU
  91. #define SCSI_CMD_MECHANISM_STATUS 0xBDU
  92. #define SCSI_CMD_READ_CD 0xBEU
  93. #define SCSI_CMD_SEND_DISC_STRUCTURE 0xBFU
  94. /* Vendor-unique Commands, included for completeness */
  95. #define SCSI_CMD_CD_PLAYBACK_STATUS 0xC4U /* SONY unique */
  96. #define SCSI_CMD_PLAYBACK_CONTROL 0xC9U /* SONY unique */
  97. #define SCSI_CMD_READ_CDDA 0xD8U /* Vendor unique */
  98. #define SCSI_CMD_READ_CDXA 0xDBU /* Vendor unique */
  99. #define SCSI_CMD_READ_ALL_SUBCODES 0xDFU /* Vendor unique */
  100. /* SCSI error codes */
  101. #define SCSI_S_NOT_READY 0x02U
  102. #define SCSI_S_MEDIUM_ERROR 0x03U
  103. #define SCSI_S_ILLEGAL_REQUEST 0x05U
  104. #define SCSI_S_UNIT_ATTENTION 0x06U
  105. #define SCSI_ASC_LBA_OUT_OF_RANGE 0x21U
  106. #define SCSI_ASC_MEDIA_CHANGED 0x28U
  107. #define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3AU
  108. struct SCSI_Capacity {
  109. uint8_t data[8];
  110. //uint32_t dwBlockAddress;
  111. //uint32_t dwBlockLength;
  112. } __attribute__((packed));
  113. struct SCSI_CDB_BASE {
  114. uint8_t Opcode;
  115. unsigned unused : 5;
  116. unsigned LUN : 3;
  117. uint8_t info[12];
  118. } __attribute__((packed));
  119. typedef SCSI_CDB_BASE SCSI_CDB_BASE_t;
  120. struct SCSI_CDB6 {
  121. uint8_t Opcode;
  122. unsigned LBAMSB : 5;
  123. unsigned LUN : 3;
  124. uint8_t LBAHB;
  125. uint8_t LBALB;
  126. uint8_t AllocationLength;
  127. uint8_t Control;
  128. public:
  129. SCSI_CDB6(uint8_t _Opcode, uint8_t _LUN, uint32_t LBA, uint8_t _AllocationLength, uint8_t _Control) :
  130. Opcode(_Opcode), LBAMSB(UHS_UINT8_BYTE2(LBA) & 0x1F), LUN(_LUN), LBAHB(UHS_UINT8_BYTE1(LBA)), LBALB(UHS_UINT8_BYTE0(LBA)),
  131. AllocationLength(_AllocationLength), Control(_Control) {
  132. }
  133. SCSI_CDB6(uint8_t _Opcode, uint8_t _LUN, uint8_t _AllocationLength, uint8_t _Control) :
  134. Opcode(_Opcode), LBAMSB(0), LUN(_LUN), LBAHB(0), LBALB(0),
  135. AllocationLength(_AllocationLength), Control(_Control) {
  136. }
  137. } __attribute__((packed));
  138. typedef SCSI_CDB6 SCSI_CDB6_t;
  139. struct SCSI_CDB10 {
  140. uint8_t Opcode;
  141. unsigned Service_Action : 5;
  142. unsigned LUN : 3;
  143. uint8_t LBA_L_M_MB;
  144. uint8_t LBA_L_M_LB;
  145. uint8_t LBA_L_L_MB;
  146. uint8_t LBA_L_L_LB;
  147. uint8_t Misc2;
  148. uint8_t ALC_MB;
  149. uint8_t ALC_LB;
  150. uint8_t Control;
  151. public:
  152. SCSI_CDB10(uint8_t _Opcode, uint8_t _LUN) :
  153. Opcode(_Opcode), Service_Action(0), LUN(_LUN),
  154. LBA_L_M_MB(0), LBA_L_M_LB(0), LBA_L_L_MB(0), LBA_L_L_LB(0),
  155. Misc2(0), ALC_MB(0), ALC_LB(0), Control(0) {
  156. }
  157. SCSI_CDB10(uint8_t _Opcode, uint8_t _LUN, uint16_t xflen, uint32_t _LBA) :
  158. Opcode(_Opcode), Service_Action(0), LUN(_LUN),
  159. LBA_L_M_MB(UHS_UINT8_BYTE3(_LBA)), LBA_L_M_LB(UHS_UINT8_BYTE2(_LBA)), LBA_L_L_MB(UHS_UINT8_BYTE1(_LBA)), LBA_L_L_LB(UHS_UINT8_BYTE0(_LBA)),
  160. Misc2(0), ALC_MB(UHS_UINT8_BYTE1(xflen)), ALC_LB(UHS_UINT8_BYTE0(xflen)), Control(0) {
  161. }
  162. } __attribute__((packed));
  163. typedef SCSI_CDB10 SCSI_CDB10_t;
  164. struct SCSI_CDB12 {
  165. uint8_t Opcode;
  166. unsigned Service_Action : 5;
  167. unsigned Misc : 3;
  168. uint8_t LBA_L_M_LB;
  169. uint8_t LBA_L_L_MB;
  170. uint8_t LBA_L_L_LB;
  171. uint8_t ALC_M_LB;
  172. uint8_t ALC_L_MB;
  173. uint8_t ALC_L_LB;
  174. uint8_t Control;
  175. } __attribute__((packed));
  176. typedef SCSI_CDB12 SCSI_CDB12_t;
  177. struct SCSI_CDB_LBA32_16 {
  178. uint8_t Opcode;
  179. unsigned Service_Action : 5;
  180. unsigned Misc : 3;
  181. uint8_t LBA_L_M_MB;
  182. uint8_t LBA_L_M_LB;
  183. uint8_t LBA_L_L_MB;
  184. uint8_t LBA_L_L_LB;
  185. uint8_t A_M_M_MB;
  186. uint8_t A_M_M_LB;
  187. uint8_t A_M_L_MB;
  188. uint8_t A_M_L_LB;
  189. uint8_t ALC_M_MB;
  190. uint8_t ALC_M_LB;
  191. uint8_t ALC_L_MB;
  192. uint8_t ALC_L_LB;
  193. uint8_t Misc2;
  194. uint8_t Control;
  195. } __attribute__((packed));
  196. struct SCSI_CDB_LBA64_16 {
  197. uint8_t Opcode;
  198. uint8_t Misc;
  199. uint8_t LBA_M_M_MB;
  200. uint8_t LBA_M_M_LB;
  201. uint8_t LBA_M_L_MB;
  202. uint8_t LBA_M_L_LB;
  203. uint8_t LBA_L_M_MB;
  204. uint8_t LBA_L_M_LB;
  205. uint8_t LBA_L_L_MB;
  206. uint8_t LBA_L_L_LB;
  207. uint8_t ALC_M_MB;
  208. uint8_t ALC_M_LB;
  209. uint8_t ALC_L_MB;
  210. uint8_t ALC_L_LB;
  211. uint8_t Misc2;
  212. uint8_t Control;
  213. } __attribute__((packed));
  214. struct SCSI_Inquiry_Response {
  215. uint8_t DeviceType : 5;
  216. uint8_t PeripheralQualifier : 3;
  217. unsigned Reserved : 7;
  218. unsigned Removable : 1;
  219. uint8_t Version;
  220. unsigned ResponseDataFormat : 4;
  221. unsigned HISUP : 1;
  222. unsigned NormACA : 1;
  223. unsigned TrmTsk : 1;
  224. unsigned AERC : 1;
  225. uint8_t AdditionalLength;
  226. unsigned PROTECT : 1;
  227. unsigned Res : 2;
  228. unsigned ThreePC : 1;
  229. unsigned TPGS : 2;
  230. unsigned ACC : 1;
  231. unsigned SCCS : 1;
  232. unsigned ADDR16 : 1;
  233. unsigned R1 : 1;
  234. unsigned R2 : 1;
  235. unsigned MCHNGR : 1;
  236. unsigned MULTIP : 1;
  237. unsigned VS : 1;
  238. unsigned ENCSERV : 1;
  239. unsigned BQUE : 1;
  240. unsigned SoftReset : 1;
  241. unsigned CmdQue : 1;
  242. unsigned Reserved4 : 1;
  243. unsigned Linked : 1;
  244. unsigned Sync : 1;
  245. unsigned WideBus16Bit : 1;
  246. unsigned WideBus32Bit : 1;
  247. unsigned RelAddr : 1;
  248. uint8_t VendorID[8];
  249. uint8_t ProductID[16];
  250. uint8_t RevisionID[4];
  251. } __attribute__((packed));
  252. struct SCSI_Request_Sense_Response {
  253. uint8_t bResponseCode;
  254. uint8_t bSegmentNumber;
  255. uint8_t bmSenseKey : 4;
  256. uint8_t bmReserved : 1;
  257. uint8_t bmILI : 1;
  258. uint8_t bmEOM : 1;
  259. uint8_t bmFileMark : 1;
  260. uint8_t Information[4];
  261. uint8_t bAdditionalLength;
  262. uint8_t CmdSpecificInformation[4];
  263. uint8_t bAdditionalSenseCode;
  264. uint8_t bAdditionalSenseQualifier;
  265. uint8_t bFieldReplaceableUnitCode;
  266. uint8_t SenseKeySpecific[3];
  267. } __attribute__((packed));
  268. #endif /* UHS_SCSI_H */