scsi_disk.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /* $OpenBSD: scsi_disk.h,v 1.35 2015/06/07 19:13:27 krw Exp $ */
  2. /* $NetBSD: scsi_disk.h,v 1.10 1996/07/05 16:19:05 christos Exp $ */
  3. /*
  4. * SCSI interface description
  5. */
  6. /*
  7. * Some lines of this file come from a file of the name "scsi.h"
  8. * distributed by OSF as part of mach2.5,
  9. * so the following disclaimer has been kept.
  10. *
  11. * Copyright 1990 by Open Software Foundation,
  12. * Grenoble, FRANCE
  13. *
  14. * All Rights Reserved
  15. *
  16. * Permission to use, copy, modify, and distribute this software and
  17. * its documentation for any purpose and without fee is hereby granted,
  18. * provided that the above copyright notice appears in all copies and
  19. * that both the copyright notice and this permission notice appear in
  20. * supporting documentation, and that the name of OSF or Open Software
  21. * Foundation not be used in advertising or publicity pertaining to
  22. * distribution of the software without specific, written prior
  23. * permission.
  24. *
  25. * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
  26. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  27. * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
  28. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  29. * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
  30. * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  31. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  32. */
  33. /*
  34. * Largely written by Julian Elischer (julian@tfs.com)
  35. * for TRW Financial Systems.
  36. *
  37. * TRW Financial Systems, in accordance with their agreement with Carnegie
  38. * Mellon University, makes this software available to CMU to distribute
  39. * or use in any manner that they see fit as long as this message is kept with
  40. * the software. For this reason TFS also grants any other persons or
  41. * organisations permission to use or modify this software.
  42. *
  43. * TFS supplies this software to be publicly redistributed
  44. * on the understanding that TFS is not responsible for the correct
  45. * functioning of this software in any circumstances.
  46. *
  47. * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  48. */
  49. /*
  50. * SCSI command format
  51. */
  52. #ifndef _SCSI_SCSI_DISK_H
  53. #define _SCSI_SCSI_DISK_H 1
  54. /*
  55. * XXX Is this also used by ATAPI?
  56. */
  57. #define FORMAT_UNIT 0x04
  58. struct scsi_format_unit {
  59. u_int8_t opcode;
  60. u_int8_t flags;
  61. #define SFU_DLF_MASK 0x07
  62. #define SFU_CMPLST 0x08
  63. #define SFU_FMTDATA 0x10
  64. u_int8_t vendor_specific;
  65. u_int8_t interleave[2];
  66. u_int8_t control;
  67. };
  68. /*
  69. * If the FmtData bit is set, a FORMAT UNIT parameter list is transferred
  70. * to the target during the DATA OUT phase. The parameter list includes
  71. *
  72. * Defect list header
  73. * Initialization pattern descriptor (if any)
  74. * Defect descriptor(s) (if any)
  75. */
  76. struct scsi_format_unit_defect_list_header {
  77. u_int8_t reserved;
  78. u_int8_t flags;
  79. #define DLH_VS 0x01 /* vendor specific */
  80. #define DLH_IMMED 0x02 /* immediate return */
  81. #define DLH_DSP 0x04 /* disable saving parameters */
  82. #define DLH_IP 0x08 /* initialization pattern */
  83. #define DLH_STPF 0x10 /* stop format */
  84. #define DLH_DCRT 0x20 /* disable certification */
  85. #define DLH_DPRY 0x40 /* disable primary */
  86. #define DLH_FOV 0x80 /* format options valid */
  87. u_int8_t defect_lst_len[2];
  88. };
  89. /*
  90. * See Table 117 of the SCSI-2 specification for a description of
  91. * the IP modifier.
  92. */
  93. struct scsi_initialization_pattern_descriptor {
  94. u_int8_t ip_modifier;
  95. u_int8_t pattern_type;
  96. #define IP_TYPE_DEFAULT 0x01
  97. #define IP_TYPE_REPEAT 0x01
  98. /* 0x02 -> 0x7f: reserved */
  99. /* 0x80 -> 0xff: vendor-specific */
  100. u_int8_t pattern_length[2];
  101. #if 0
  102. u_int8_t pattern[...];
  103. #endif
  104. };
  105. /*
  106. * Defect desciptors. These are used as the defect lists in the FORMAT UNIT
  107. * and READ DEFECT DATA commands, and as the translate page of the
  108. * SEND DIAGNOSTIC and RECEIVE DIAGNOSTIC RESULTS commands.
  109. */
  110. /* Block format */
  111. struct scsi_defect_descriptor_bf {
  112. u_int8_t block_address[4];
  113. };
  114. /* Bytes from index format */
  115. struct scsi_defect_descriptor_bfif {
  116. u_int8_t cylinder[2];
  117. u_int8_t head;
  118. u_int8_t bytes_from_index[2];
  119. };
  120. /* Physical sector format */
  121. struct scsi_defect_descriptor_psf {
  122. u_int8_t cylinder[2];
  123. u_int8_t head;
  124. u_int8_t sector[2];
  125. };
  126. struct scsi_reassign_blocks {
  127. u_int8_t opcode;
  128. u_int8_t byte2;
  129. u_int8_t unused[3];
  130. u_int8_t control;
  131. };
  132. /*
  133. * XXX Is this also used by ATAPI?
  134. */
  135. #define REZERO_UNIT 0x01
  136. struct scsi_rezero_unit {
  137. u_int8_t opcode;
  138. u_int8_t byte2;
  139. u_int8_t reserved[3];
  140. u_int8_t control;
  141. };
  142. struct scsi_rw {
  143. u_int8_t opcode;
  144. u_int8_t addr[3];
  145. #define SRW_TOPADDR 0x1F /* only 5 bits here */
  146. u_int8_t length;
  147. u_int8_t control;
  148. };
  149. struct scsi_rw_big {
  150. u_int8_t opcode;
  151. u_int8_t byte2;
  152. #define SRWB_RELADDR 0x01
  153. u_int8_t addr[4];
  154. u_int8_t reserved;
  155. u_int8_t length[2];
  156. u_int8_t control;
  157. };
  158. struct scsi_rw_12 {
  159. u_int8_t opcode;
  160. u_int8_t byte2;
  161. u_int8_t addr[4];
  162. u_int8_t length[4];
  163. u_int8_t reserved;
  164. u_int8_t control;
  165. };
  166. struct scsi_rw_16 {
  167. u_int8_t opcode;
  168. u_int8_t byte2;
  169. u_int8_t addr[8];
  170. u_int8_t length[4];
  171. u_int8_t reserved;
  172. u_int8_t control;
  173. };
  174. struct scsi_write_same_10 {
  175. u_int8_t opcode;
  176. u_int8_t flags;
  177. #define WRITE_SAME_F_LBDATA (1 << 1)
  178. #define WRITE_SAME_F_PBDATA (1 << 2)
  179. u_int8_t lba[4];
  180. u_int8_t group_number;
  181. u_int8_t length[2];
  182. u_int8_t control;
  183. };
  184. struct scsi_write_same_16 {
  185. u_int8_t opcode;
  186. u_int8_t flags;
  187. /* includes WRITE SAME 10 flags */
  188. #define WRITE_SAME_F_UNMAP (1 << 3)
  189. #define WRITE_SAME_F_ANCHOR (1 << 4)
  190. u_int8_t lba[8];
  191. u_int8_t length[4];
  192. u_int8_t group_number;
  193. u_int8_t control;
  194. };
  195. struct scsi_unmap {
  196. u_int8_t opcode;
  197. u_int8_t anchor;
  198. u_int8_t _reserved[4];
  199. u_int8_t group_number;
  200. u_int8_t list_len[2];
  201. u_int8_t control;
  202. };
  203. struct scsi_unmap_data {
  204. u_int8_t data_length[2];
  205. u_int8_t desc_length[2];
  206. u_int8_t _reserved[4];
  207. /* followed by struct scsi_unmap_desc */
  208. };
  209. struct scsi_unmap_desc {
  210. u_int8_t logical_addr[8];
  211. u_int8_t logical_blocks[4];
  212. u_int8_t _reserved[4];
  213. };
  214. struct scsi_read_capacity {
  215. u_int8_t opcode;
  216. u_int8_t byte2;
  217. u_int8_t addr[4];
  218. u_int8_t unused[3];
  219. u_int8_t control;
  220. };
  221. struct scsi_read_capacity_16 {
  222. u_int8_t opcode;
  223. u_int8_t byte2;
  224. #define SRC16_SERVICE_ACTION 0x10
  225. u_int8_t addr[8];
  226. u_int8_t length[4];
  227. u_int8_t reserved;
  228. u_int8_t control;
  229. };
  230. struct scsi_start_stop {
  231. u_int8_t opcode;
  232. u_int8_t byte2;
  233. u_int8_t unused[2];
  234. u_int8_t how;
  235. #define SSS_STOP 0x00
  236. #define SSS_START 0x01
  237. #define SSS_LOEJ 0x02
  238. u_int8_t control;
  239. };
  240. /*
  241. * XXX Does ATAPI have an equivalent?
  242. */
  243. struct scsi_synchronize_cache {
  244. u_int8_t opcode;
  245. u_int8_t flags;
  246. #define SSC_RELADR 0x01
  247. #define SSC_IMMED 0x02
  248. u_int8_t addr[4];
  249. u_int8_t reserved;
  250. u_int8_t length[2];
  251. u_int8_t control;
  252. };
  253. /*
  254. * Disk specific opcodes
  255. */
  256. #define REASSIGN_BLOCKS 0x07
  257. #define READ_COMMAND 0x08
  258. #define WRITE_COMMAND 0x0a
  259. #define READ_CAPACITY 0x25
  260. #define READ_CAPACITY_16 0x9e
  261. #define READ_BIG 0x28
  262. #define WRITE_BIG 0x2a
  263. #define READ_12 0xa8
  264. #define WRITE_12 0xaa
  265. #define READ_16 0x88
  266. #define WRITE_16 0x8a
  267. #define SYNCHRONIZE_CACHE 0x35
  268. #define WRITE_SAME_10 0x41
  269. #define WRITE_SAME_16 0x93
  270. #define UNMAP 0x42
  271. struct scsi_read_cap_data {
  272. u_int8_t addr[4];
  273. u_int8_t length[4];
  274. };
  275. struct scsi_read_cap_data_16 {
  276. u_int8_t addr[8];
  277. u_int8_t length[4];
  278. u_int8_t p_type_prot;
  279. u_int8_t logical_per_phys;
  280. u_int8_t lowest_aligned[2];
  281. #define READ_CAP_16_TPE 0x8000
  282. #define READ_CAP_16_TPRZ 0x4000
  283. u_int8_t reserved[16];
  284. };
  285. struct scsi_reassign_blocks_data {
  286. u_int8_t reserved[2];
  287. u_int8_t length[2];
  288. struct {
  289. u_int8_t dlbaddr[4];
  290. } defect_descriptor[1];
  291. };
  292. /* Only the lower 6 bits of the pg_code field are used for page #. */
  293. #define DISK_PGCODE(pg, n) ((pg) != NULL) && (((pg)->pg_code & 0x3f) == n)
  294. #define PAGE_DISK_FORMAT 3
  295. #define PAGE_RIGID_GEOMETRY 4
  296. #define PAGE_FLEX_GEOMETRY 5
  297. #define PAGE_REDUCED_GEOMETRY 6
  298. #define PAGE_CACHING_MODE 8
  299. struct page_disk_format {
  300. u_int8_t pg_code; /* page code (should be 3) */
  301. u_int8_t pg_length; /* page length (should be 0x16) */
  302. u_int8_t trk_z[2]; /* tracks per zone */
  303. u_int8_t alt_sec[2]; /* alternate sectors per zone */
  304. u_int8_t alt_trk_z[2]; /* alternate tracks per zone */
  305. u_int8_t alt_trk_v[2]; /* alternate tracks per volume */
  306. u_int8_t ph_sec_t[2]; /* physical sectors per track */
  307. u_int8_t bytes_s[2]; /* bytes per sector */
  308. u_int8_t interleave[2]; /* interleave */
  309. u_int8_t trk_skew[2]; /* track skew factor */
  310. u_int8_t cyl_skew[2]; /* cylinder skew */
  311. u_int8_t flags; /* various */
  312. #define DISK_FMT_SURF 0x10
  313. #define DISK_FMT_RMB 0x20
  314. #define DISK_FMT_HSEC 0x40
  315. #define DISK_FMT_SSEC 0x80
  316. u_int8_t reserved1;
  317. u_int8_t reserved2;
  318. u_int8_t reserved3;
  319. };
  320. struct page_rigid_geometry {
  321. u_int8_t pg_code; /* page code (should be 4) */
  322. u_int8_t pg_length; /* page length (should be 0x12 or 0x16) */
  323. u_int8_t ncyl[3]; /* number of cylinders */
  324. u_int8_t nheads; /* number of heads */
  325. u_int8_t st_cyl_wp[3]; /* starting cyl., write precomp */
  326. u_int8_t st_cyl_rwc[3]; /* starting cyl., red. write cur */
  327. u_int8_t driv_step[2]; /* drive step rate */
  328. u_int8_t land_zone[3]; /* landing zone cylinder */
  329. u_int8_t sp_sync_ctl; /* spindle synch control */
  330. #define SPINDLE_SYNCH_MASK 0x03 /* mask of valid bits */
  331. #define SPINDLE_SYNCH_NONE 0x00 /* synch disabled or not supported */
  332. #define SPINDLE_SYNCH_SLAVE 0x01 /* disk is a slave */
  333. #define SPINDLE_SYNCH_MASTER 0x02 /* disk is a master */
  334. #define SPINDLE_SYNCH_MCONTROL 0x03 /* disk is a master control */
  335. u_int8_t rot_offset; /* rotational offset (for spindle synch) */
  336. u_int8_t reserved1;
  337. u_int8_t rpm[2]; /* media rotation speed */
  338. u_int8_t reserved2;
  339. u_int8_t reserved3;
  340. };
  341. struct page_flex_geometry {
  342. u_int8_t pg_code; /* page code (should be 5) */
  343. u_int8_t pg_length; /* page length (should be 0x1a or 0x1e) */
  344. u_int8_t xfr_rate[2];
  345. u_int8_t nheads; /* number of heads */
  346. u_int8_t ph_sec_tr; /* physical sectors per track */
  347. u_int8_t bytes_s[2]; /* bytes per sector */
  348. u_int8_t ncyl[2]; /* number of cylinders */
  349. u_int8_t st_cyl_wp[2]; /* start cyl., write precomp */
  350. u_int8_t st_cyl_rwc[2]; /* start cyl., red. write cur */
  351. u_int8_t driv_step[2]; /* drive step rate */
  352. u_int8_t driv_step_w; /* drive step pulse width */
  353. u_int8_t head_settle[2];/* head settle delay */
  354. u_int8_t motor_on; /* motor on delay */
  355. u_int8_t motor_off; /* motor off delay */
  356. u_int8_t flags; /* various flags */
  357. #define MOTOR_ON 0x20 /* motor on (pin 16)? */
  358. #define START_AT_SECTOR_1 0x40 /* start at sector 1 */
  359. #define READY_VALID 0x20 /* RDY (pin 34) valid */
  360. u_int8_t step_p_cyl; /* step pulses per cylinder */
  361. u_int8_t write_pre; /* write precompensation */
  362. u_int8_t head_load; /* head load delay */
  363. u_int8_t head_unload; /* head unload delay */
  364. u_int8_t pin_34_2; /* pin 34 (6) pin 2 (7/11) definition */
  365. u_int8_t pin_4_1; /* pin 4 (8/9) pin 1 (13) definition */
  366. u_int8_t rpm[2]; /* media rotation speed */
  367. u_int8_t reserved1;
  368. u_int8_t reserved2;
  369. };
  370. struct page_reduced_geometry {
  371. u_int8_t pg_code; /* page code (should be 6) */
  372. u_int8_t pg_length; /* page length (should be 0x0B) */
  373. u_int8_t wcd; /* bit 0 = write cache disable */
  374. u_int8_t bytes_s[2]; /* bytes per sector */
  375. u_int8_t sectors[5]; /* total number of sectors */
  376. u_int8_t pow_perf; /* power/performance level */
  377. u_int8_t flags; /* various */
  378. #define LOCK_DISABLED 0x1
  379. #define FORMAT_DISABLED 0x2
  380. #define WRITE_DISABLED 0x4
  381. #define READ_DISABLED 0x8
  382. u_int8_t reserved;
  383. };
  384. struct page_caching_mode {
  385. u_int8_t pg_code; /* page code (should be 8) */
  386. u_int8_t pg_length; /* page length (should be 0x12) */
  387. u_int8_t flags;
  388. #define PG_CACHE_FL_RCD (1<<0)
  389. #define PG_CACHE_FL_MF (1<<1)
  390. #define PG_CACHE_FL_WCE (1<<2)
  391. #define PG_CACHE_FL_SIZE (1<<3)
  392. #define PG_CACHE_FL_DISC (1<<4)
  393. #define PG_CACHE_FL_CAP (1<<5)
  394. #define PG_CACHE_FL_ABPF (1<<6)
  395. #define PG_CACHE_FL_IC (1<<7)
  396. u_int8_t priority;
  397. #define PG_CACHE_PRI_DEMAND(_f) ((_f) & 0x0f)
  398. #define PG_CACHE_PRI_WRITE(_f) (((_f) >> 4) & 0x0f)
  399. u_int8_t dis_prefetch_tl[2];
  400. u_int8_t min_prefetch[2];
  401. u_int8_t max_prefetch[2];
  402. u_int8_t max_prefetch_ceil[2];
  403. };
  404. #define SI_PG_DISK_LIMITS 0xb0 /* block limits */
  405. #define SI_PG_DISK_INFO 0xb1 /* device charateristics */
  406. #define SI_PG_DISK_THIN 0xb2 /* thin provisioning */
  407. struct scsi_vpd_disk_limits {
  408. struct scsi_vpd_hdr hdr;
  409. #define SI_PG_DISK_LIMITS_LEN 0x10
  410. #define SI_PG_DISK_LIMITS_LEN_THIN 0x3c
  411. u_int8_t _reserved1[1];
  412. u_int8_t max_comp_wr_len;
  413. u_int8_t optimal_xfer_granularity[2];
  414. u_int8_t max_xfer_len[4];
  415. u_int8_t optimal_xfer[4];
  416. u_int8_t max_xd_prefetch_len[4];
  417. u_int8_t max_unmap_lba_count[4];
  418. u_int8_t max_unmap_desc_count[4];
  419. u_int8_t optimal_unmap_granularity[4];
  420. u_int8_t unmap_granularity_align[4];
  421. #define SI_PG_DISK_LIMITS_UGAVALID (1U << 31)
  422. u_int8_t _reserved2[28];
  423. };
  424. struct scsi_vpd_disk_info {
  425. struct scsi_vpd_hdr hdr;
  426. u_int8_t rpm[2];
  427. #define VPD_DISK_INFO_RPM_UNDEF 0x0000
  428. #define VPD_DISK_INFO_RPM_NONE 0x0001
  429. u_int8_t _reserved1[1];
  430. u_int8_t form_factor;
  431. #define VPD_DISK_INFO_FORM_MASK 0xf
  432. #define VPD_DISK_INFO_FORM_UNDEF 0x0
  433. #define VPD_DISK_INFO_FORM_5_25 0x1
  434. #define VPD_DISK_INFO_FORM_3_5 0x2
  435. #define VPD_DISK_INFO_FORM_2_5 0x3
  436. #define VPD_DISK_INFO_FORM_1_8 0x4
  437. #define VPD_DISK_INFO_FORM_LT_1_8 0x5
  438. u_int8_t _reserved2[56];
  439. };
  440. struct scsi_vpd_disk_thin {
  441. struct scsi_vpd_hdr hdr;
  442. u_int8_t threshold_exponent;
  443. u_int8_t flags;
  444. #define VPD_DISK_THIN_DP (1 << 0) /* descriptor present */
  445. #define VPD_DISK_THIN_ANC_SUP (0x7 << 1)
  446. #define VPD_DISK_THIN_ANC_SUP_NO (0x0 << 1)
  447. #define VPD_DISK_THIN_ANC_SUP_YES (0x1 << 1)
  448. #define VPD_DISK_THIN_TPWS (1 << 6) /* WRITE SAME 16 */
  449. #define VPD_DISK_THIN_TPU (1 << 7) /* UNMAP */
  450. u_int8_t _reserved1[2];
  451. /* followed by a designation descriptor if DP is set */
  452. };
  453. #endif /* _SCSI_SCSI_DISK_H */