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.

spc_protocol.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /**
  2. * \file
  3. *
  4. * \brief SCSI Primary Commands
  5. *
  6. * This file contains definitions of some of the commands found in the
  7. * SPC-2 standard.
  8. *
  9. * Copyright (c) 2009-2015 Atmel Corporation. All rights reserved.
  10. *
  11. * \asf_license_start
  12. *
  13. * \page License
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. *
  25. * 3. The name of Atmel may not be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * 4. This software may only be redistributed and used in connection with an
  29. * Atmel microcontroller product.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  32. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  34. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  35. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  40. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. * \asf_license_stop
  44. *
  45. */
  46. /*
  47. * Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
  48. */
  49. #ifndef _SPC_PROTOCOL_H_
  50. #define _SPC_PROTOCOL_H_
  51. /**
  52. * \ingroup usb_msc_protocol
  53. * \defgroup usb_spc_protocol SCSI Primary Commands protocol definitions
  54. *
  55. * @{
  56. */
  57. //! \name SCSI commands defined by SPC-2
  58. //@{
  59. #define SPC_TEST_UNIT_READY 0x00
  60. #define SPC_REQUEST_SENSE 0x03
  61. #define SPC_INQUIRY 0x12
  62. #define SPC_MODE_SELECT6 0x15
  63. #define SPC_MODE_SENSE6 0x1A
  64. #define SPC_SEND_DIAGNOSTIC 0x1D
  65. #define SPC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
  66. #define SPC_MODE_SENSE10 0x5A
  67. #define SPC_REPORT_LUNS 0xA0
  68. //@}
  69. //! \brief May be set in byte 0 of the INQUIRY CDB
  70. //@{
  71. //! Enable Vital Product Data
  72. #define SCSI_INQ_REQ_EVPD 0x01
  73. //! Command Support Data specified by the PAGE OR OPERATION CODE field
  74. #define SCSI_INQ_REQ_CMDT 0x02
  75. //@}
  76. COMPILER_PACK_SET(1)
  77. /**
  78. * \brief SCSI Standard Inquiry data structure
  79. */
  80. struct scsi_inquiry_data {
  81. uint8_t pq_pdt; //!< Peripheral Qual / Peripheral Dev Type
  82. #define SCSI_INQ_PQ_CONNECTED 0x00 //!< Peripheral connected
  83. #define SCSI_INQ_PQ_NOT_CONN 0x20 //!< Peripheral not connected
  84. #define SCSI_INQ_PQ_NOT_SUPP 0x60 //!< Peripheral not supported
  85. #define SCSI_INQ_DT_DIR_ACCESS 0x00 //!< Direct Access (SBC)
  86. #define SCSI_INQ_DT_SEQ_ACCESS 0x01 //!< Sequential Access
  87. #define SCSI_INQ_DT_PRINTER 0x02 //!< Printer
  88. #define SCSI_INQ_DT_PROCESSOR 0x03 //!< Processor device
  89. #define SCSI_INQ_DT_WRITE_ONCE 0x04 //!< Write-once device
  90. #define SCSI_INQ_DT_CD_DVD 0x05 //!< CD/DVD device
  91. #define SCSI_INQ_DT_OPTICAL 0x07 //!< Optical Memory
  92. #define SCSI_INQ_DT_MC 0x08 //!< Medium Changer
  93. #define SCSI_INQ_DT_ARRAY 0x0C //!< Storage Array Controller
  94. #define SCSI_INQ_DT_ENCLOSURE 0x0D //!< Enclosure Services
  95. #define SCSI_INQ_DT_RBC 0x0E //!< Simplified Direct Access
  96. #define SCSI_INQ_DT_OCRW 0x0F //!< Optical card reader/writer
  97. #define SCSI_INQ_DT_BCC 0x10 //!< Bridge Controller Commands
  98. #define SCSI_INQ_DT_OSD 0x11 //!< Object-based Storage
  99. #define SCSI_INQ_DT_NONE 0x1F //!< No Peripheral
  100. uint8_t flags1; //!< Flags (byte 1)
  101. #define SCSI_INQ_RMB 0x80 //!< Removable Medium
  102. uint8_t version; //!< Version
  103. #define SCSI_INQ_VER_NONE 0x00 //!< No standards conformance
  104. #define SCSI_INQ_VER_SPC 0x03 //!< SCSI Primary Commands (link to SBC)
  105. #define SCSI_INQ_VER_SPC2 0x04 //!< SCSI Primary Commands - 2 (link to SBC-2)
  106. #define SCSI_INQ_VER_SPC3 0x05 //!< SCSI Primary Commands - 3 (link to SBC-2)
  107. #define SCSI_INQ_VER_SPC4 0x06 //!< SCSI Primary Commands - 4 (link to SBC-3)
  108. uint8_t flags3; //!< Flags (byte 3)
  109. #define SCSI_INQ_NORMACA 0x20 //!< Normal ACA Supported
  110. #define SCSI_INQ_HISUP 0x10 //!< Hierarchal LUN addressing
  111. #define SCSI_INQ_RSP_SPC2 0x02 //!< SPC-2 / SPC-3 response format
  112. uint8_t addl_len; //!< Additional Length (n-4)
  113. #define SCSI_INQ_ADDL_LEN(tot) ((tot)-5) //!< Total length is \a tot
  114. uint8_t flags5; //!< Flags (byte 5)
  115. #define SCSI_INQ_SCCS 0x80
  116. uint8_t flags6; //!< Flags (byte 6)
  117. #define SCSI_INQ_BQUE 0x80
  118. #define SCSI_INQ_ENCSERV 0x40
  119. #define SCSI_INQ_MULTIP 0x10
  120. #define SCSI_INQ_MCHGR 0x08
  121. #define SCSI_INQ_ADDR16 0x01
  122. uint8_t flags7; //!< Flags (byte 7)
  123. #define SCSI_INQ_WBUS16 0x20
  124. #define SCSI_INQ_SYNC 0x10
  125. #define SCSI_INQ_LINKED 0x08
  126. #define SCSI_INQ_CMDQUE 0x02
  127. uint8_t vendor_id[8]; //!< T10 Vendor Identification
  128. uint8_t product_id[16]; //!< Product Identification
  129. uint8_t product_rev[4]; //!< Product Revision Level
  130. };
  131. /**
  132. * \brief SCSI Standard Request sense data structure
  133. */
  134. struct scsi_request_sense_data {
  135. /* 1st byte: REQUEST SENSE response flags*/
  136. uint8_t valid_reponse_code;
  137. #define SCSI_SENSE_VALID 0x80 //!< Indicates the INFORMATION field contains valid information
  138. #define SCSI_SENSE_RESPONSE_CODE_MASK 0x7F
  139. #define SCSI_SENSE_CURRENT 0x70 //!< Response code 70h (current errors)
  140. #define SCSI_SENSE_DEFERRED 0x71
  141. /* 2nd byte */
  142. uint8_t obsolete;
  143. /* 3rd byte */
  144. uint8_t sense_flag_key;
  145. #define SCSI_SENSE_FILEMARK 0x80 //!< Indicates that the current command has read a filemark or setmark.
  146. #define SCSI_SENSE_EOM 0x40 //!< Indicates that an end-of-medium condition exists.
  147. #define SCSI_SENSE_ILI 0x20 //!< Indicates that the requested logical block length did not match the logical block length of the data on the medium.
  148. #define SCSI_SENSE_RESERVED 0x10 //!< Reserved
  149. #define SCSI_SENSE_KEY(x) (x&0x0F) //!< Sense Key
  150. /* 4th to 7th bytes - INFORMATION field */
  151. uint8_t information[4];
  152. /* 8th byte - ADDITIONAL SENSE LENGTH field */
  153. uint8_t AddSenseLen;
  154. #define SCSI_SENSE_ADDL_LEN(total_len) ((total_len) - 8)
  155. /* 9th to 12th byte - COMMAND-SPECIFIC INFORMATION field */
  156. uint8_t CmdSpecINFO[4];
  157. /* 13th byte - ADDITIONAL SENSE CODE field */
  158. uint8_t AddSenseCode;
  159. /* 14th byte - ADDITIONAL SENSE CODE QUALIFIER field */
  160. uint8_t AddSnsCodeQlfr;
  161. /* 15th byte - FIELD REPLACEABLE UNIT CODE field */
  162. uint8_t FldReplUnitCode;
  163. /* 16th byte */
  164. uint8_t SenseKeySpec[3];
  165. #define SCSI_SENSE_SKSV 0x80 //!< Indicates the SENSE-KEY SPECIFIC field contains valid information
  166. };
  167. COMPILER_PACK_RESET()
  168. /* Vital Product Data page codes */
  169. enum scsi_vpd_page_code {
  170. SCSI_VPD_SUPPORTED_PAGES = 0x00,
  171. SCSI_VPD_UNIT_SERIAL_NUMBER = 0x80,
  172. SCSI_VPD_DEVICE_IDENTIFICATION = 0x83,
  173. };
  174. #define SCSI_VPD_HEADER_SIZE 4
  175. /* Constants associated with the Device Identification VPD page */
  176. #define SCSI_VPD_ID_HEADER_SIZE 4
  177. #define SCSI_VPD_CODE_SET_BINARY 1
  178. #define SCSI_VPD_CODE_SET_ASCII 2
  179. #define SCSI_VPD_CODE_SET_UTF8 3
  180. #define SCSI_VPD_ID_TYPE_T10 1
  181. /* Sense keys */
  182. enum scsi_sense_key {
  183. SCSI_SK_NO_SENSE = 0x0,
  184. SCSI_SK_RECOVERED_ERROR = 0x1,
  185. SCSI_SK_NOT_READY = 0x2,
  186. SCSI_SK_MEDIUM_ERROR = 0x3,
  187. SCSI_SK_HARDWARE_ERROR = 0x4,
  188. SCSI_SK_ILLEGAL_REQUEST = 0x5,
  189. SCSI_SK_UNIT_ATTENTION = 0x6,
  190. SCSI_SK_DATA_PROTECT = 0x7,
  191. SCSI_SK_BLANK_CHECK = 0x8,
  192. SCSI_SK_VENDOR_SPECIFIC = 0x9,
  193. SCSI_SK_COPY_ABORTED = 0xA,
  194. SCSI_SK_ABORTED_COMMAND = 0xB,
  195. SCSI_SK_VOLUME_OVERFLOW = 0xD,
  196. SCSI_SK_MISCOMPARE = 0xE,
  197. };
  198. /* Additional Sense Code / Additional Sense Code Qualifier pairs */
  199. enum scsi_asc_ascq {
  200. SCSI_ASC_NO_ADDITIONAL_SENSE_INFO = 0x0000,
  201. SCSI_ASC_LU_NOT_READY_REBUILD_IN_PROGRESS = 0x0405,
  202. SCSI_ASC_WRITE_ERROR = 0x0C00,
  203. SCSI_ASC_UNRECOVERED_READ_ERROR = 0x1100,
  204. SCSI_ASC_INVALID_COMMAND_OPERATION_CODE = 0x2000,
  205. SCSI_ASC_INVALID_FIELD_IN_CDB = 0x2400,
  206. SCSI_ASC_WRITE_PROTECTED = 0x2700,
  207. SCSI_ASC_NOT_READY_TO_READY_CHANGE = 0x2800,
  208. SCSI_ASC_MEDIUM_NOT_PRESENT = 0x3A00,
  209. SCSI_ASC_INTERNAL_TARGET_FAILURE = 0x4400,
  210. };
  211. /**
  212. * \brief SPC-2 Mode parameter
  213. * This subclause describes the block descriptors and the pages
  214. * used with MODE SELECT and MODE SENSE commands
  215. * that are applicable to all SCSI devices.
  216. */
  217. enum scsi_spc_mode {
  218. SCSI_MS_MODE_VENDOR_SPEC = 0x00,
  219. SCSI_MS_MODE_INFEXP = 0x1C, // Informational exceptions control page
  220. SCSI_MS_MODE_ALL = 0x3F,
  221. };
  222. /**
  223. * \brief SPC-2 Informational exceptions control page
  224. * See chapter 8.3.8
  225. */
  226. struct spc_control_page_info_execpt {
  227. uint8_t page_code;
  228. uint8_t page_length;
  229. #define SPC_MP_INFEXP_PAGE_LENGTH 0x0A
  230. uint8_t flags1;
  231. #define SPC_MP_INFEXP_PERF (1<<7) //!< Initiator Control
  232. #define SPC_MP_INFEXP_EBF (1<<5) //!< Caching Analysis Permitted
  233. #define SPC_MP_INFEXP_EWASC (1<<4) //!< Discontinuity
  234. #define SPC_MP_INFEXP_DEXCPT (1<<3) //!< Size enable
  235. #define SPC_MP_INFEXP_TEST (1<<2) //!< Writeback Cache Enable
  236. #define SPC_MP_INFEXP_LOGERR (1<<0) //!< Log errors bit
  237. uint8_t mrie;
  238. #define SPC_MP_INFEXP_MRIE_NO_REPORT 0x00
  239. #define SPC_MP_INFEXP_MRIE_ASYNC_EVENT 0x01
  240. #define SPC_MP_INFEXP_MRIE_GEN_UNIT 0x02
  241. #define SPC_MP_INFEXP_MRIE_COND_RECOV_ERROR 0x03
  242. #define SPC_MP_INFEXP_MRIE_UNCOND_RECOV_ERROR 0x04
  243. #define SPC_MP_INFEXP_MRIE_NO_SENSE 0x05
  244. #define SPC_MP_INFEXP_MRIE_ONLY_REPORT 0x06
  245. be32_t interval_timer;
  246. be32_t report_count;
  247. };
  248. enum scsi_spc_mode_sense_pc {
  249. SCSI_MS_SENSE_PC_CURRENT = 0,
  250. SCSI_MS_SENSE_PC_CHANGEABLE = 1,
  251. SCSI_MS_SENSE_PC_DEFAULT = 2,
  252. SCSI_MS_SENSE_PC_SAVED = 3,
  253. };
  254. static inline bool scsi_mode_sense_dbd_is_set(const uint8_t * cdb)
  255. {
  256. return (cdb[1] >> 3) & 1;
  257. }
  258. static inline uint8_t scsi_mode_sense_get_page_code(const uint8_t * cdb)
  259. {
  260. return cdb[2] & 0x3F;
  261. }
  262. static inline uint8_t scsi_mode_sense_get_pc(const uint8_t * cdb)
  263. {
  264. return cdb[2] >> 6;
  265. }
  266. /**
  267. * \brief SCSI Mode Parameter Header used by MODE SELECT(6) and MODE
  268. * SENSE(6)
  269. */
  270. struct scsi_mode_param_header6 {
  271. uint8_t mode_data_length; //!< Number of bytes after this
  272. uint8_t medium_type; //!< Medium Type
  273. uint8_t device_specific_parameter; //!< Defined by command set
  274. uint8_t block_descriptor_length; //!< Length of block descriptors
  275. };
  276. /**
  277. * \brief SCSI Mode Parameter Header used by MODE SELECT(10) and MODE
  278. * SENSE(10)
  279. */
  280. struct scsi_mode_param_header10 {
  281. be16_t mode_data_length; //!< Number of bytes after this
  282. uint8_t medium_type; //!< Medium Type
  283. uint8_t device_specific_parameter; //!< Defined by command set
  284. uint8_t flags4; //!< LONGLBA in bit 0
  285. uint8_t reserved;
  286. be16_t block_descriptor_length; //!< Length of block descriptors
  287. };
  288. /**
  289. * \brief SCSI Page_0 Mode Page header (SPF not set)
  290. */
  291. struct scsi_mode_page_0_header {
  292. uint8_t page_code;
  293. #define SCSI_PAGE_CODE_PS (1 << 7) //!< Parameters Saveable
  294. #define SCSI_PAGE_CODE_SPF (1 << 6) //!< SubPage Format
  295. uint8_t page_length; //!< Number of bytes after this
  296. #define SCSI_MS_PAGE_LEN(total) ((total) - 2)
  297. };
  298. //@}
  299. #endif // SPC_PROTOCOL_H_