/scsipi/scsi_spc.h

http://rtems-atapi.googlecode.com/ · C++ Header · 564 lines · 326 code · 58 blank · 180 comment · 0 complexity · 3374823be4ecb2e90acebf6cf7d9bab3 MD5 · raw file

  1. /* $NetBSD: scsi_spc.h,v 1.4 2008/04/28 20:23:57 martin Exp $ */
  2. /*-
  3. * Copyright (c) 2005 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Jason R. Thorpe.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  22. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*
  31. * SCSI Primary Commands (SPC) --
  32. * Commands for all device types
  33. */
  34. /*
  35. * Largely written by Julian Elischer (julian@tfs.com)
  36. * for TRW Financial Systems.
  37. *
  38. * TRW Financial Systems, in accordance with their agreement with Carnegie
  39. * Mellon University, makes this software available to CMU to distribute
  40. * or use in any manner that they see fit as long as this message is kept with
  41. * the software. For this reason TFS also grants any other persons or
  42. * organisations permission to use or modify this software.
  43. *
  44. * TFS supplies this software to be publicly redistributed
  45. * on the understanding that TFS is not responsible for the correct
  46. * functioning of this software in any circumstances.
  47. *
  48. * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  49. */
  50. #ifndef _DEV_SCSIPI_SCSI_SPC_H_
  51. #define _DEV_SCSIPI_SCSI_SPC_H_
  52. /*
  53. * EXTENDED COPY
  54. */
  55. /*
  56. * INQUIRY
  57. */
  58. /*
  59. * LOG SELECT
  60. */
  61. /*
  62. * LOG SENSE
  63. */
  64. /*
  65. * MODE SELECT
  66. */
  67. #define SCSI_MODE_SELECT_6 0x15
  68. struct scsi_mode_select_6 {
  69. uint8_t opcode;
  70. uint8_t byte2;
  71. #define SMS_SP 0x01 /* save page */
  72. #define SMS_PF 0x10 /* page format (0 = SCSI-1, 1 = SCSI-2) */
  73. uint8_t reserved[2];
  74. uint8_t length;
  75. uint8_t control;
  76. };
  77. #define SCSI_MODE_SELECT_10 0x55
  78. struct scsi_mode_select_10 {
  79. uint8_t opcode;
  80. uint8_t byte2; /* see MODE SELECT (6) */
  81. uint8_t reserved[5];
  82. uint8_t length[2];
  83. uint8_t control;
  84. };
  85. /*
  86. * MODE SENSE
  87. */
  88. #define SCSI_MODE_SENSE_6 0x1a
  89. struct scsi_mode_sense_6 {
  90. uint8_t opcode;
  91. uint8_t byte2;
  92. #define SMS_DBD 0x08 /* disable block descriptors */
  93. uint8_t page;
  94. #define SMS_PAGE_MASK 0x3f
  95. #define SMS_PCTRL_MASK 0xc0
  96. #define SMS_PCTRL_CURRENT 0x00
  97. #define SMS_PCTRL_CHANGEABLE 0x40
  98. #define SMS_PCTRL_DEFAULT 0x80
  99. #define SMS_PCTRL_SAVED 0xc0
  100. uint8_t reserved;
  101. uint8_t length;
  102. uint8_t control;
  103. };
  104. #define SCSI_MODE_SENSE_10 0x5a
  105. struct scsi_mode_sense_10 {
  106. uint8_t opcode;
  107. uint8_t byte2; /* see MODE SENSE (6) */
  108. #define SMS_LLBAA 0x10
  109. uint8_t page; /* See MODE SENSE (6) */
  110. uint8_t reserved[4];
  111. uint8_t length[2];
  112. uint8_t control;
  113. };
  114. /*
  115. * Page code usage:
  116. * 0x00 Vendor-specific (does not require page format)
  117. * 0x01 - 0x1f Device-type-specific pages
  118. * 0x20 - 0x3e Vendor-specific (page format required)
  119. * 0x3f Return all mode pages
  120. */
  121. #define SMS_PAGE_ALL_PAGES 0x3f
  122. /*
  123. * Mode parameters are returned in the following format:
  124. *
  125. * Mode parameter header
  126. * Block descriptor(s) [zero or more]
  127. * Page(s) [zero or more, variable-length]
  128. */
  129. struct scsi_mode_parameter_header_6 {
  130. uint8_t data_length;
  131. uint8_t medium_type;
  132. uint8_t dev_spec;
  133. uint8_t blk_desc_len; /* unused on ATAPI */
  134. };
  135. struct scsi_mode_parameter_header_10 {
  136. uint8_t data_length[2];
  137. uint8_t medium_type;
  138. uint8_t dev_spec;
  139. uint8_t byte5;
  140. #define SMPH_LONGLBA 0x01
  141. uint8_t reserved;
  142. uint8_t blk_desc_len[2];
  143. };
  144. struct scsi_general_block_descriptor {
  145. uint8_t density;
  146. uint8_t nblocks[3];
  147. uint8_t reserved;
  148. uint8_t blklen[3];
  149. };
  150. struct scsi_da_block_descriptor {
  151. uint8_t nblocks[4];
  152. uint8_t density;
  153. uint8_t blklen[3];
  154. };
  155. struct scsi_longlba_block_descriptor {
  156. uint8_t nblocks[8];
  157. uint8_t density;
  158. uint8_t reserved[3];
  159. uint8_t blklen[4];
  160. };
  161. /*
  162. * Header common to all mode parameter pages.
  163. */
  164. struct scsi_mode_page_header {
  165. uint8_t pg_code;
  166. #define PGCODE_MASK 0x3f /* page code mask */
  167. #define PGCODE_PS 0x80 /* page is saveable */
  168. uint8_t pg_length; /* page length (not including header) */
  169. };
  170. /*
  171. * Control mode page
  172. */
  173. #define SCSI_CONTROL_MODE_PAGE 0x0a
  174. struct scsi_control_mode_page {
  175. uint8_t pg_code; /* 0x0a */
  176. uint8_t pg_length; /* 0x0a */
  177. uint8_t byte3;
  178. #define SCMP_RLEC 0x01 /* report log exception condition */
  179. #define SCMP_GLTSD 0x02 /* global logging target save disable */
  180. #define SCMP_TST_mask 0x7 /* task set type */
  181. #define SCMP_TST_shift 5
  182. #define SCMP_TST_ALL_INIT 0 /* per LU for all initiators */
  183. #define SCMP_TST_PER_INIT 1 /* per initiator per LU */
  184. uint8_t queue_params;
  185. #define SCMP_DQue 0x01 /* disable queueing */
  186. #define SCMP_QErr_mask 0x3 /* queue error management */
  187. #define SCMP_QErr_shift 1
  188. #define SCMP_QAM_mask 0xf /* queue algorithm modifier */
  189. #define SCMP_QAM_shift 4
  190. #define SCMP_QAM_RESTRICTED 0x0 /* restricted reordering allowed */
  191. #define SCMP_QAM_UNRESTRICTED 0x1 /* unrestricted reordering allowed */
  192. /* 0x2 - 0x7 Reserved */
  193. /* 0x8 - 0xf Vendor-specific */
  194. uint8_t byte5;
  195. #define SCMP_EAERP 0x01
  196. #define SCMP_UAAERP 0x02
  197. #define SCMP_RAERP 0x04
  198. #define SCMP_SWP 0x08
  199. #define SCMP_RAC 0x40
  200. #define SCMP_TAS 0x80
  201. uint8_t byte6;
  202. #define SCMP_AM_mask 0x7 /* autload mode */
  203. #define SCMP_AM_FULL 0
  204. #define SCMP_AM_AUXMEM 1
  205. #define SCMP_AM_NOLOAD 2
  206. uint8_t rahp[2]; /* ready aer holdoff period */
  207. uint8_t btp[2]; /* busy timeout period */
  208. uint8_t estct[2]; /* extended self-test completion time */
  209. };
  210. /*
  211. * Disconnect-reconnect page
  212. */
  213. #define SCSI_DISCONNECT_RECONNECT_PAGE 0x02
  214. struct scsi_disconnect_reconnect_page {
  215. uint8_t pg_code; /* 0x02 */
  216. uint8_t pg_length; /* 0x0e */
  217. uint8_t buffer_full_ratio;
  218. uint8_t buffer_empty_ratio;
  219. uint8_t bus_inactivity_limit[2];
  220. uint8_t disconnect_time_limit[2];
  221. uint8_t connect_time_limit[2];
  222. uint8_t maximum_burst_size[2];
  223. uint8_t flags;
  224. #define SDRP_DTDC_mask 0x7 /* data transfer disconnect control */
  225. #define SDRP_DImm 0x08
  226. #define SDRP_FA_mask 0x7
  227. #define SDRP_FA_shift 4
  228. #define SDRP_EMDP 0x80
  229. uint8_t reserved;
  230. uint8_t first_burst_size[2];
  231. };
  232. /*
  233. * Informational exceptions control page
  234. */
  235. #define SCSI_INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE 0x1c
  236. struct scsi_informational_exceptions_control_page {
  237. uint8_t pg_code; /* 0x1c */
  238. uint8_t pg_length; /* 0x0a */
  239. uint8_t byte3;
  240. #define SIECP_LogErr 0x01
  241. #define SIECP_TEST 0x04
  242. #define SIECP_DExcpt 0x08
  243. #define SIECP_EWasc 0x10
  244. #define SIECP_EBF 0x20
  245. #define SIECP_PERF 0x80
  246. uint8_t byte4;
  247. #define SIECP_MRIE_mask 0xf /* method of reporting
  248. informational exceptions */
  249. #define SIECP_MRIE_NO_REPORTING 0x00
  250. #define SIECP_MRIE_ASYNC_EVENT 0x01
  251. #define SIECP_MRIE_UNIT_ATN 0x02
  252. #define SIECP_MRIE_COND_RECOV_ERR 0x03
  253. #define SIECP_MRIE_UNCOND_RECOV_ERR 0x04
  254. #define SIECP_MRIE_NO_SENSE 0x05
  255. #define SIECP_MRIE_ON_REQUEST 0x06
  256. /* 0x07 - 0x0b reserved */
  257. /* 0x0c - 0x0f Vendor-specific */
  258. uint8_t interval_timer[2];
  259. uint8_t report_count[2];
  260. };
  261. /*
  262. * Power condition page
  263. */
  264. #define SCSI_POWER_CONDITION_PAGE 0x1a
  265. struct scsi_power_condition_page {
  266. uint8_t pg_code; /* 0x1a */
  267. uint8_t pg_length; /* 0x0a */
  268. uint8_t reserved;
  269. uint8_t byte4;
  270. #define SPCP_STANDBY 0x01
  271. #define SPCP_IDLE 0x02
  272. uint8_t idle_timer[2]; /* 100ms increments */
  273. uint8_t standby_timer[2]; /* 100ms increments */
  274. };
  275. /*
  276. * Protocol specific LUN page
  277. */
  278. #define SCSI_PROTOCOL_SPECIFIC_LUN_PAGE 0x18
  279. struct scsi_protocol_specific_lun_page {
  280. uint8_t pg_code; /* 0x18 */
  281. uint8_t pg_length; /* variable */
  282. uint8_t byte3;
  283. #define SPSLP_PROTOCOL_mask 0xf
  284. #define SPSLP_PROTOCOL_FCP 0x00 /* Fibre Channel */
  285. #define SPSLP_PROTOCOL_SPI 0x01 /* parallel SCSI */
  286. #define SPSLP_PROTOCOL_SSA 0x02 /* SSA-S2P or SSA-S3P */
  287. #define SPSLP_PROTOCOL_SBP2 0x03 /* IEEE 1394 */
  288. #define SPSLP_PROTOCOL_SRP 0x04 /* SCSI RDMA */
  289. #define SPSLP_PROTOCOL_ISCSI 0x05 /* iSCSI */
  290. /* protocol specific mode parameters follow */
  291. };
  292. /*
  293. * Protocol specific port page
  294. */
  295. #define SCSI_PROTOCOL_SPECIFIC_PORT_PAGE 0x19
  296. struct scsi_protocol_specific_port_page {
  297. uint8_t pg_code; /* 0x18 */
  298. uint8_t pg_length; /* variable */
  299. uint8_t byte3; /* see SCSI PROTOCOL SPECIFIC LUN PAGE */
  300. /* protocol specific mode parameters follow */
  301. };
  302. /*
  303. * PERSISTENT RESERVE IN
  304. */
  305. /*
  306. * PERSISTENT RESERVE OUT
  307. */
  308. /*
  309. * PREVENT ALLOW MEDIUM REMOVAL
  310. */
  311. #define SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
  312. struct scsi_prevent_allow_medium_removal {
  313. uint8_t opcode;
  314. uint8_t byte2;
  315. uint8_t reserved[2];
  316. uint8_t how;
  317. #define SPAMR_ALLOW 0x00
  318. #define SPAMR_PREVENT_DT 0x01
  319. #define SPAMR_PREVENT_MC 0x02
  320. #define SPAMR_PREVENT_ALL 0x03
  321. uint8_t control;
  322. };
  323. /*
  324. * READ BUFFER
  325. */
  326. /*
  327. * RECEIVE COPY RESULTS
  328. */
  329. /*
  330. * RECEIVE DIAGNOSTIC RESULTS
  331. */
  332. /*
  333. * RESERVE / RELEASE
  334. */
  335. #define SCSI_RESERVE_6 0x16
  336. #define SCSI_RELEASE_6 0x17
  337. struct scsi_reserve_release_6 {
  338. uint8_t opcode;
  339. uint8_t byte2;
  340. uint8_t obsolete;
  341. uint8_t reserved[2];
  342. uint8_t control;
  343. };
  344. #define SCSI_RESERVE_10 0x56
  345. #define SCSI_RELEASE_10 0x57
  346. struct scsi_reserve_release_10 {
  347. uint8_t opcode;
  348. uint8_t byte2;
  349. #define SR_LongID 0x02
  350. #define SR_3rdPty 0x10
  351. uint8_t obsolete;
  352. uint8_t thirdpartyid;
  353. uint8_t reserved[3];
  354. uint8_t paramlen[2];
  355. uint8_t control;
  356. };
  357. struct scsi_reserve_release_10_idparam {
  358. uint8_t thirdpartyid[8];
  359. };
  360. /*
  361. * REPORT DEVICE IDENTIFIER
  362. */
  363. /*
  364. * REPORT LUNS
  365. */
  366. /*
  367. * REQUEST SENSE
  368. */
  369. #define SCSI_REQUEST_SENSE 0x03
  370. struct scsi_request_sense {
  371. uint8_t opcode;
  372. uint8_t byte2;
  373. uint8_t reserved[2];
  374. uint8_t length;
  375. uint8_t control;
  376. };
  377. struct scsi_sense_data {
  378. /* 1*/ uint8_t response_code;
  379. #define SSD_RCODE(x) ((x) & 0x7f)
  380. #define SSD_RCODE_CURRENT 0x70
  381. #define SSD_RCODE_DEFERRED 0x71
  382. #define SSD_RCODE_VALID 0x80
  383. /* 2*/ uint8_t segment; /* obsolete */
  384. /* 3*/ uint8_t flags;
  385. #define SSD_SENSE_KEY(x) ((x) & 0x0f)
  386. #define SSD_ILI 0x20
  387. #define SSD_EOM 0x40
  388. #define SSD_FILEMARK 0x80
  389. /* 7*/ uint8_t info[4];
  390. /* 8*/ uint8_t extra_len;
  391. /*12*/ uint8_t csi[4];
  392. /*13*/ uint8_t asc;
  393. /*14*/ uint8_t ascq;
  394. /*15*/ uint8_t fru;
  395. union {
  396. uint8_t sks_bytes[3];
  397. /* ILLEGAL REQUEST */
  398. struct {
  399. uint8_t byte0;
  400. #define SSD_SKS_FP_BIT(x) ((x) & 0x7)
  401. #define SSD_SKS_FP_BPV 0x08
  402. #define SSK_SKS_FP_CD 0x40 /* 1=command, 0=data */
  403. uint8_t val[2];
  404. } field_pointer;
  405. /* RECOVERED ERROR, HARDWARE ERROR, MEDIUM ERROR */
  406. struct {
  407. uint8_t byte0;
  408. uint8_t val[2];
  409. } actual_retry_count;
  410. /* NOT READY, NO SENSE */
  411. struct {
  412. uint8_t byte0;
  413. uint8_t val[2];
  414. } progress_indication;
  415. /* COPY ABORTED */
  416. struct {
  417. uint8_t byte0;
  418. #define SSD_SKS_SP_BIT(x) ((x) & 0x7)
  419. #define SSD_SKS_SP_BPV 0x08
  420. #define SSD_SKS_SP_SD 0x20 /* 0=param list, 1=segment desc */
  421. uint8_t val[2];
  422. } segment_pointer;
  423. /*18*/ } sks;
  424. #define SSD_SKSV 0x80 /* byte0 of sks field */
  425. /*32*/ uint8_t extra_bytes[14]; /* really variable length */
  426. };
  427. /*
  428. * Sense bytes described by the extra_len field start at csi[], and can
  429. * only continue up to the end of the 32-byte sense structure that we
  430. * have defined (which might be too short for some cases).
  431. */
  432. #define SSD_ADD_BYTES_LIM(sp) \
  433. ((((int)(sp)->extra_len) < (int)sizeof(struct scsi_sense_data) - 8) ? \
  434. (sp)->extra_len : sizeof(struct scsi_sense_data) - 8)
  435. #define SKEY_NO_SENSE 0x00
  436. #define SKEY_RECOVERED_ERROR 0x01
  437. #define SKEY_NOT_READY 0x02
  438. #define SKEY_MEDIUM_ERROR 0x03
  439. #define SKEY_HARDWARE_ERROR 0x04
  440. #define SKEY_ILLEGAL_REQUEST 0x05
  441. #define SKEY_UNIT_ATTENTION 0x06
  442. #define SKEY_DATA_PROTECT 0x07
  443. #define SKEY_BLANK_CHECK 0x08
  444. #define SKEY_VENDOR_SPECIFIC 0x09
  445. #define SKEY_COPY_ABORTED 0x0a
  446. #define SKEY_ABORTED_COMMAND 0x0b
  447. #define SKEY_EQUAL 0x0c /* obsolete */
  448. #define SKEY_VOLUME_OVERFLOW 0x0d
  449. #define SKEY_MISCOMPARE 0x0e
  450. /* 0x0f reserved */
  451. /* XXX This is not described in SPC-2. */
  452. struct scsi_sense_data_unextended {
  453. uint8_t response_code;
  454. uint8_t block[3];
  455. };
  456. /*
  457. * SEND DIAGNOSTIC
  458. */
  459. #define SCSI_SEND_DIAGNOSTIC 0x1d
  460. struct scsi_send_diagnostic {
  461. uint8_t opcode;
  462. uint8_t byte2;
  463. #define SSD_UnitOffL 0x01
  464. #define SSD_DevOffL 0x02
  465. #define SSD_SelfTest 0x04 /* standard self-test */
  466. #define SSD_PF 0x10 /* results in page format */
  467. #define SSD_CODE(x) ((x) << 5)
  468. /*
  469. * Codes:
  470. *
  471. * 0 This value shall be used when the SelfTest bit is
  472. * set to one or if the SEND DIAGNOSTIC command is not
  473. * invoking one of the other self-test functions such
  474. * as enclosure services or the Translate Address page.
  475. *
  476. * 1 Background short self-test. Parameter length is 0.
  477. *
  478. * 2 Background extended self-test. Parameter length is 0.
  479. *
  480. * 4 Abort background self-test. Parameter length is 0.
  481. *
  482. * 5 Foreground short self-test. Parameter length is 0.
  483. *
  484. * 6 Foreground extended self-test. Parameter length is 0.
  485. */
  486. uint8_t reserved;
  487. uint8_t paramlen[2];
  488. uint8_t control;
  489. };
  490. /*
  491. * SET DEVICE IDENTIFIER
  492. */
  493. /*
  494. * TEST UNIT READY
  495. */
  496. #define SCSI_TEST_UNIT_READY 0x00
  497. struct scsi_test_unit_ready {
  498. uint8_t opcode;
  499. uint8_t byte2;
  500. uint8_t reserved[3];
  501. uint8_t control;
  502. };
  503. /*
  504. * WRITE BUFFER
  505. */
  506. #endif /* _DEV_SCSIPI_SCSI_SPC_H_ */