scsi_sa.h revision 280438
1/*-
2 * Structure and function declarations for the
3 * SCSI Sequential Access Peripheral driver for CAM.
4 *
5 * Copyright (c) 1999, 2000 Matthew Jacob
6 * Copyright (c) 2013, 2014, 2015 Spectra Logic Corporation
7 * All rights reserved.
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 *    without modification, immediately at the beginning of the file.
15 * 2. The name of the author may not be used to endorse or promote products
16 *    derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: stable/10/sys/cam/scsi/scsi_sa.h 280438 2015-03-24 14:36:10Z ken $
31 */
32
33#ifndef	_SCSI_SCSI_SA_H
34#define _SCSI_SCSI_SA_H 1
35
36#include <sys/cdefs.h>
37
38struct scsi_read_block_limits
39{
40	u_int8_t opcode;
41	u_int8_t byte2;
42	u_int8_t unused[3];
43	u_int8_t control;
44};
45
46struct scsi_read_block_limits_data
47{
48	u_int8_t gran;
49#define	RBL_GRAN_MASK	0x1F
50#define RBL_GRAN(rblim) ((rblim)->gran & RBL_GRAN_MASK)
51	u_int8_t maximum[3];
52	u_int8_t minimum[2];
53};
54
55struct scsi_sa_rw
56{
57	u_int8_t opcode;
58        u_int8_t sli_fixed;
59#define SAR_SLI		0x02
60#define SARW_FIXED	0x01
61	u_int8_t length[3];
62        u_int8_t control;
63};
64
65struct scsi_load_unload
66{
67	u_int8_t opcode;
68        u_int8_t immediate;
69#define SLU_IMMED	0x01
70	u_int8_t reserved[2];
71	u_int8_t eot_reten_load;
72#define SLU_EOT		0x04
73#define SLU_RETEN	0x02
74#define SLU_LOAD	0x01
75        u_int8_t control;
76};
77
78struct scsi_rewind
79{
80	u_int8_t opcode;
81        u_int8_t immediate;
82#define SREW_IMMED	0x01
83	u_int8_t reserved[3];
84        u_int8_t control;
85};
86
87typedef enum {
88	SS_BLOCKS,
89	SS_FILEMARKS,
90	SS_SEQFILEMARKS,
91	SS_EOD,
92	SS_SETMARKS,
93	SS_SEQSETMARKS
94} scsi_space_code;
95
96struct scsi_space
97{
98	u_int8_t opcode;
99        u_int8_t code;
100#define SREW_IMMED	0x01
101	u_int8_t count[3];
102        u_int8_t control;
103};
104
105struct scsi_write_filemarks
106{
107	u_int8_t opcode;
108        u_int8_t byte2;
109#define SWFMRK_IMMED	0x01
110#define SWFMRK_WSMK	0x02
111	u_int8_t num_marks[3];
112        u_int8_t control;
113};
114
115/*
116 * Reserve and release unit have the same exact cdb format, but different
117 * opcodes.
118 */
119struct scsi_reserve_release_unit
120{
121	u_int8_t opcode;
122	u_int8_t lun_thirdparty;
123#define SRRU_LUN_MASK	0xE0
124#define SRRU_3RD_PARTY	0x10
125#define SRRU_3RD_SHAMT	1
126#define SRRU_3RD_MASK	0xE
127	u_int8_t reserved[3];
128	u_int8_t control;
129};
130
131/*
132 * Erase a tape
133 */
134struct scsi_erase
135{
136	u_int8_t opcode;
137	u_int8_t lun_imm_long;
138#define SE_LUN_MASK	0xE0
139#define SE_LONG		0x1
140#define SE_IMMED	0x2
141	u_int8_t reserved[3];
142	u_int8_t control;
143};
144
145/*
146 * Set tape capacity.
147 */
148struct scsi_set_capacity
149{
150	u_int8_t opcode;
151	u_int8_t byte1;
152#define	SA_SSC_IMMED		0x01
153	u_int8_t reserved;
154	u_int8_t cap_proportion[2];
155	u_int8_t control;
156};
157
158/*
159 * Format tape media.  The CDB opcode is the same as the disk-specific
160 * FORMAT UNIT command, but the fields are different inside the CDB.  Thus
161 * the reason for a separate definition here.
162 */
163struct scsi_format_medium
164{
165	u_int8_t opcode;
166	u_int8_t byte1;
167#define	SFM_IMMED		0x01
168#define	SFM_VERIFY		0x02
169	u_int8_t byte2;
170#define	SFM_FORMAT_DEFAULT	0x00
171#define	SFM_FORMAT_PARTITION	0x01
172#define	SFM_FORMAT_DEF_PART	0x02
173#define	SFM_FORMAT_MASK		0x0f
174	u_int8_t length[2];
175	u_int8_t control;
176};
177
178struct scsi_allow_overwrite
179{
180	u_int8_t opcode;
181	u_int8_t reserved1;
182	u_int8_t allow_overwrite;
183#define	SAO_ALLOW_OVERWRITE_DISABLED	0x00
184#define	SAO_ALLOW_OVERWRITE_CUR_POS	0x01
185#define	SAO_ALLOW_OVERWRITE_FORMAT	0x02
186	u_int8_t partition;
187	u_int8_t logical_id[8];
188	u_int8_t reserved2[3];
189	u_int8_t control;
190};
191
192/*
193 * Dev specific mode page masks.
194 */
195#define SMH_SA_WP		0x80
196#define	SMH_SA_BUF_MODE_MASK	0x70
197#define SMH_SA_BUF_MODE_NOBUF	0x00
198#define SMH_SA_BUF_MODE_SIBUF	0x10	/* Single-Initiator buffering */
199#define SMH_SA_BUF_MODE_MIBUF	0x20	/* Multi-Initiator buffering */
200#define SMH_SA_SPEED_MASK	0x0F
201#define SMH_SA_SPEED_DEFAULT	0x00
202
203/*
204 * Sequential-access specific mode page numbers.
205 */
206#define SA_DEVICE_CONFIGURATION_PAGE	0x10
207#define SA_MEDIUM_PARTITION_PAGE_1	0x11
208#define SA_MEDIUM_PARTITION_PAGE_2	0x12
209#define SA_MEDIUM_PARTITION_PAGE_3	0x13
210#define SA_MEDIUM_PARTITION_PAGE_4	0x14
211#define SA_DATA_COMPRESSION_PAGE	0x0f	/* SCSI-3 */
212
213/*
214 * Mode page definitions.
215 */
216
217/* See SCSI-II spec 9.3.3.1 */
218struct scsi_dev_conf_page {
219	u_int8_t pagecode;	/* 0x10 */
220	u_int8_t pagelength;	/* 0x0e */
221	u_int8_t byte2;		/* CAP, CAF, Active Format */
222	u_int8_t active_partition;
223	u_int8_t wb_full_ratio;
224	u_int8_t rb_empty_ratio;
225	u_int8_t wrdelay_time[2];
226	u_int8_t byte8;
227#define	SA_DBR			0x80	/* data buffer recovery */
228#define	SA_BIS			0x40	/* block identifiers supported */
229#define	SA_RSMK			0x20	/* report setmarks */
230#define	SA_AVC			0x10	/* automatic velocity control */
231#define	SA_SOCF_MASK		0x0c	/* stop on consecutive formats */
232#define	SA_RBO			0x02	/* recover buffer order */
233#define	SA_REW			0x01	/* report early warning */
234	u_int8_t gap_size;
235	u_int8_t byte10;
236/* from SCSI-3: SSC-4 Working draft (2/14) 8.3.3 */
237#define	SA_EOD_DEF_MASK		0xe0	/* EOD defined */
238#define	SA_EEG			0x10	/* Enable EOD Generation */
239#define	SA_SEW			0x08	/* Synchronize at Early Warning */
240#define	SA_SOFT_WP		0x04	/* Software Write Protect */
241#define	SA_BAML			0x02	/* Block Address Mode Lock */
242#define	SA_BAM			0x01	/* Block Address Mode */
243	u_int8_t ew_bufsize[3];
244	u_int8_t sel_comp_alg;
245#define	SA_COMP_NONE		0x00
246#define	SA_COMP_DEFAULT		0x01
247	/* the following is 'reserved' in SCSI-2 but is defined in SSC-r22 */
248	u_int8_t extra_wp;
249#define	SA_ASOC_WP		0x04	/* Associated Write Protect */
250#define	SA_PERS_WP		0x02	/* Persistent Write Protect */
251#define	SA_PERM_WP		0x01	/* Permanent Write Protect */
252};
253
254/* from SCSI-3: SSC-Rev10 (6/97) */
255struct scsi_data_compression_page {
256	u_int8_t page_code;	/* 0x0f */
257	u_int8_t page_length;	/* 0x0e */
258	u_int8_t dce_and_dcc;
259#define SA_DCP_DCE		0x80 	/* Data compression enable */
260#define SA_DCP_DCC		0x40	/* Data compression capable */
261	u_int8_t dde_and_red;
262#define SA_DCP_DDE		0x80	/* Data decompression enable */
263#define SA_DCP_RED_MASK		0x60	/* Report Exception on Decomp. */
264#define SA_DCP_RED_SHAMT	5
265#define SA_DCP_RED_0		0x00
266#define SA_DCP_RED_1		0x20
267#define SA_DCP_RED_2		0x40
268	u_int8_t comp_algorithm[4];
269	u_int8_t decomp_algorithm[4];
270	u_int8_t reserved[4];
271};
272
273typedef union {
274	struct { u_int8_t pagecode, pagelength; } hdr;
275	struct scsi_dev_conf_page dconf;
276	struct scsi_data_compression_page dcomp;
277} sa_comp_t;
278
279/*
280 * Control Data Protection subpage.  This is as defined in SSC3r03.
281 */
282struct scsi_control_data_prot_subpage {
283	uint8_t page_code;
284#define	SA_CTRL_DP_PAGE_CODE		0x0a
285	uint8_t subpage_code;
286#define	SA_CTRL_DP_SUBPAGE_CODE		0xf0
287	uint8_t length[2];
288	uint8_t prot_method;
289#define	SA_CTRL_DP_NO_LBP		0x00
290#define	SA_CTRL_DP_REED_SOLOMON		0x01
291#define	SA_CTRL_DP_METHOD_MAX		0xff
292	uint8_t pi_length;
293#define	SA_CTRL_DP_PI_LENGTH_MASK	0x3f
294#define	SA_CTRL_DP_RS_LENGTH		4
295	uint8_t prot_bits;
296#define	SA_CTRL_DP_LBP_W		0x80
297#define	SA_CTRL_DP_LBP_R		0x40
298#define	SA_CTRL_DP_RBDP			0x20
299	uint8_t reserved[];
300};
301
302/*
303 * This is the Read/Write Control mode page used on IBM Enterprise Tape
304 * Drives.  They are known as 3592, TS, or Jaguar drives.  The SCSI inquiry
305 * data will show a Product ID "03592XXX", where XXX is 'J1A', 'E05' (TS1120),
306 * 'E06' (TS1130), 'E07' (TS1140) or 'E08' (TS1150).
307 *
308 * This page definition is current as of the 3592 SCSI Reference v6,
309 * released on December 16th, 2014.
310 */
311struct scsi_tape_ibm_rw_control {
312	uint8_t page_code;
313#define SA_IBM_RW_CTRL_PAGE_CODE		0x25
314	uint8_t page_length;
315	uint8_t ignore_seq_checks;
316#define	SA_IBM_RW_CTRL_LOC_IGNORE_SEQ		0x04
317#define	SA_IBM_RW_CTRL_SPC_BLK_IGNORE_SEQ	0x02
318#define	SA_IBM_RW_CTRL_SPC_FM_IGNORE_SEQ	0x01
319	uint8_t ignore_data_checks;
320#define	SA_IBM_RW_CTRL_LOC_IGNORE_DATA		0x04
321#define	SA_IBM_RW_CTRL_SPC_BLK_IGNORE_DATA	0x02
322#define	SA_IBM_RW_CTRL_SPC_FM_IGNORE_DATA	0x01
323	uint8_t reserved1;
324	uint8_t leop_method;
325#define	SA_IBM_RW_CTRL_LEOP_DEFAULT		0x00
326#define	SA_IBM_RW_CTRL_LEOP_MAX_CAP		0x01
327#define	SA_IBM_RW_CTRL_LEOP_CONST_CAP		0x02
328	uint8_t leop_ew[2];
329	uint8_t byte8;
330#define	SA_IBM_RW_CTRL_DISABLE_FASTSYNC		0x80
331#define	SA_IBM_RW_CTRL_DISABLE_SKIPSYNC		0x40
332#define	SA_IBM_RW_CTRL_DISABLE_CROSS_EOD	0x08
333#define	SA_IBM_RW_CTRL_DISABLE_CROSS_PERM_ERR	0x04
334#define	SA_IBM_RW_CTRL_REPORT_SEG_EW		0x02
335#define	SA_IBM_RW_CTRL_REPORT_HOUSEKEEPING_ERR	0x01
336	uint8_t default_write_dens_bop_0;
337	uint8_t pending_write_dens_bop_0;
338	uint8_t reserved2[21];
339};
340
341struct scsi_tape_read_position {
342	u_int8_t opcode;		/* READ_POSITION */
343	u_int8_t byte1;			/* set LSB to read hardware block pos */
344#define	SA_RPOS_SHORT_FORM	0x00
345#define	SA_RPOS_SHORT_VENDOR	0x01
346#define	SA_RPOS_LONG_FORM	0x06
347#define	SA_RPOS_EXTENDED_FORM	0x08
348	u_int8_t reserved[5];
349	u_int8_t length[2];
350	u_int8_t control;
351};
352
353struct scsi_tape_position_data	{	/* Short Form */
354	u_int8_t flags;
355#define	SA_RPOS_BOP		0x80	/* Beginning of Partition */
356#define	SA_RPOS_EOP		0x40	/* End of Partition */
357#define	SA_RPOS_BCU		0x20	/* Block Count Unknown (SCSI3) */
358#define	SA_RPOS_BYCU		0x10	/* Byte Count Unknown (SCSI3) */
359#define	SA_RPOS_BPU		0x04	/* Block Position Unknown */
360#define	SA_RPOS_PERR		0x02	/* Position Error (SCSI3) */
361#define	SA_RPOS_BPEW		0x01	/* Beyond Programmable Early Warning */
362#define	SA_RPOS_UNCERTAIN	SA_RPOS_BPU
363	u_int8_t partition;
364	u_int8_t reserved[2];
365	u_int8_t firstblk[4];
366	u_int8_t lastblk[4];
367	u_int8_t reserved2;
368	u_int8_t nbufblk[3];
369	u_int8_t nbufbyte[4];
370};
371
372struct scsi_tape_position_long_data {
373	u_int8_t flags;
374#define	SA_RPOS_LONG_BOP	0x80	/* Beginning of Partition */
375#define	SA_RPOS_LONG_EOP	0x40	/* End of Partition */
376#define	SA_RPOS_LONG_MPU	0x08	/* Mark Position Unknown */
377#define	SA_RPOS_LONG_LONU	0x04	/* Logical Object Number Unknown */
378#define	SA_RPOS_LONG_BPEW	0x01	/* Beyond Programmable Early Warning */
379	u_int8_t reserved[3];
380	u_int8_t partition[4];
381	u_int8_t logical_object_num[8];
382	u_int8_t logical_file_num[8];
383	u_int8_t set_id[8];
384};
385
386struct scsi_tape_position_ext_data {
387	u_int8_t flags;
388#define	SA_RPOS_EXT_BOP		0x80	/* Beginning of Partition */
389#define	SA_RPOS_EXT_EOP		0x40	/* End of Partition */
390#define	SA_RPOS_EXT_LOCU	0x20	/* Logical Object Count Unknown */
391#define	SA_RPOS_EXT_BYCU	0x10	/* Byte Count Unknown */
392#define	SA_RPOS_EXT_LOLU	0x04	/* Logical Object Location Unknown */
393#define	SA_RPOS_EXT_PERR	0x02	/* Position Error */
394#define	SA_RPOS_EXT_BPEW	0x01	/* Beyond Programmable Early Warning */
395	u_int8_t partition;
396	u_int8_t length[2];
397	u_int8_t reserved;
398	u_int8_t num_objects[3];
399	u_int8_t first_object[8];
400	u_int8_t last_object[8];
401	u_int8_t bytes_in_buffer[8];
402};
403
404struct scsi_tape_locate {
405	u_int8_t opcode;
406	u_int8_t byte1;
407#define	SA_SPOS_IMMED		0x01
408#define	SA_SPOS_CP		0x02
409#define	SA_SPOS_BT		0x04
410	u_int8_t reserved1;
411	u_int8_t blkaddr[4];
412#define	SA_SPOS_MAX_BLK		0xffffffff
413	u_int8_t reserved2;
414	u_int8_t partition;
415	u_int8_t control;
416};
417
418struct scsi_locate_16 {
419	u_int8_t opcode;
420	u_int8_t byte1;
421#define	SA_LC_IMMEDIATE		0x01
422#define	SA_LC_CP		0x02
423#define	SA_LC_DEST_TYPE_MASK	0x38
424#define	SA_LC_DEST_TYPE_SHIFT	3
425#define	SA_LC_DEST_OBJECT	0x00
426#define	SA_LC_DEST_FILE		0x01
427#define	SA_LC_DEST_SET		0x02
428#define	SA_LC_DEST_EOD		0x03
429	u_int8_t byte2;
430#define	SA_LC_BAM_IMPLICIT	0x00
431#define	SA_LC_BAM_EXPLICIT	0x01
432	u_int8_t partition;
433	u_int8_t logical_id[8];
434	u_int8_t reserved[3];
435	u_int8_t control;
436};
437
438struct scsi_report_density_support {
439	u_int8_t opcode;
440	u_int8_t byte1;
441#define	SRDS_MEDIA		0x01
442#define	SRDS_MEDIUM_TYPE	0x02
443	u_int8_t reserved[5];
444	u_int8_t length[2];
445#define	SRDS_MAX_LENGTH		0xffff
446	u_int8_t control;
447};
448
449struct scsi_density_hdr {
450	u_int8_t length[2];
451	u_int8_t reserved[2];
452	u_int8_t descriptor[];
453};
454
455struct scsi_density_data {
456	u_int8_t primary_density_code;
457	u_int8_t secondary_density_code;
458	u_int8_t byte2;
459#define	SDD_DLV			0x01
460#define	SDD_DEFLT		0x20
461#define	SDD_DUP			0x40
462#define SDD_WRTOK		0x80
463	u_int8_t length[2];
464#define	SDD_DEFAULT_LENGTH	52
465	u_int8_t bits_per_mm[3];
466	u_int8_t media_width[2];
467	u_int8_t tracks[2];
468	u_int8_t capacity[4];
469	u_int8_t assigning_org[8];
470	u_int8_t density_name[8];
471	u_int8_t description[20];
472};
473
474struct scsi_medium_type_data {
475	u_int8_t medium_type;
476	u_int8_t reserved1;
477	u_int8_t length[2];
478#define	SMTD_DEFAULT_LENGTH	52
479	u_int8_t num_density_codes;
480	u_int8_t primary_density_codes[9];
481	u_int8_t media_width[2];
482	u_int8_t medium_length[2];
483	u_int8_t reserved2[2];
484	u_int8_t assigning_org[8];
485	u_int8_t medium_type_name[8];
486	u_int8_t description[20];
487};
488
489/*
490 * Security Protocol Specific values for the Tape Data Encryption protocol
491 * (0x20) used with SECURITY PROTOCOL IN.  See below for values used with
492 * SECURITY PROTOCOL OUT.  Current as of SSC4r03.
493 */
494#define	TDE_IN_SUPPORT_PAGE		0x0000
495#define	TDE_OUT_SUPPORT_PAGE		0x0001
496#define	TDE_DATA_ENC_CAP_PAGE		0x0010
497#define	TDE_SUPPORTED_KEY_FORMATS_PAGE	0x0011
498#define	TDE_DATA_ENC_MAN_CAP_PAGE	0x0012
499#define	TDE_DATA_ENC_STATUS_PAGE	0x0020
500#define	TDE_NEXT_BLOCK_ENC_STATUS_PAGE	0x0021
501#define	TDE_GET_ENC_MAN_ATTR_PAGE	0x0022
502#define	TDE_RANDOM_NUM_PAGE		0x0030
503#define	TDE_KEY_WRAP_PK_PAGE		0x0031
504
505/*
506 * Tape Data Encryption protocol pages used with SECURITY PROTOCOL IN and
507 * SECURITY PROTOCOL OUT.
508 */
509/*
510 * Tape Data Encryption In Support page (0x0000).
511 */
512struct tde_in_support_page {
513	uint8_t page_code[2];
514	uint8_t page_length[2];
515	uint8_t page_codes[];
516};
517
518/*
519 * Tape Data Encryption Out Support page (0x0001).
520 */
521struct tde_out_support_page {
522	uint8_t page_code[2];
523	uint8_t page_length[2];
524	uint8_t page_codes[];
525};
526
527/*
528 * Logical block encryption algorithm descriptor.  This is reported in the
529 * Data Encryption Capabilities page.
530 */
531struct tde_block_enc_alg_desc {
532	uint8_t alg_index;
533	uint8_t reserved1;
534	uint8_t desc_length[2];
535	uint8_t byte4;
536#define	TDE_BEA_AVFMV			0x80
537#define	TDE_BEA_SDK_C			0x40
538#define	TDE_BEA_MAC_C			0x20
539#define	TDE_BEA_DELB_C			0x10
540#define	TDE_BEA_DECRYPT_C_MASK		0x0c
541#define	TDE_BEA_DECRYPT_C_EXT		0x0c
542#define	TDE_BEA_DECRYPT_C_HARD		0x08
543#define	TDE_BEA_DECRYPT_C_SOFT		0x04
544#define	TDE_BEA_DECRYPT_C_NO_CAP	0x00
545#define	TDE_BEA_ENCRYPT_C_MASK		0x03
546#define	TDE_BEA_ENCRYPT_C_EXT		0x03
547#define	TDE_BEA_ENCRYPT_C_HARD		0x02
548#define	TDE_BEA_ENCRYPT_C_SOFT		0x01
549#define	TDE_BEA_ENCRYPT_C_NO_CAP	0x00
550	uint8_t byte5;
551#define	TDE_BEA_AVFCLP_MASK		0xc0
552#define	TDE_BEA_AVFCLP_VALID		0x80
553#define	TDE_BEA_AVFCLP_NOT_VALID	0x40
554#define	TDE_BEA_AVFCLP_NOT_APP		0x00
555#define	TDE_BEA_NONCE_C_MASK		0x30
556#define	TDE_BEA_NONCE_C_SUPPORTED	0x30
557#define	TDE_BEA_NONCE_C_PROVIDED	0x20
558#define	TDE_BEA_NONCE_C_GENERATED	0x10
559#define	TDE_BEA_NONCE_C_NOT_REQUIRED	0x00
560#define	TDE_BEA_KADF_C			0x08
561#define	TDE_BEA_VCELB_C			0x04
562#define	TDE_BEA_UKADF			0x02
563#define	TDE_BEA_AKADF			0x01
564	uint8_t max_unauth_key_bytes[2];
565	uint8_t max_auth_key_bytes[2];
566	uint8_t lbe_key_size[2];
567	uint8_t byte12;
568#define	TDE_BEA_DKAD_C_MASK		0xc0
569#define	TDE_BEA_DKAD_C_CAPABLE		0xc0
570#define	TDE_BEA_DKAD_C_NOT_ALLOWED	0x80
571#define	TDE_BEA_DKAD_C_REQUIRED		0x40
572#define	TDE_BEA_EEMC_C_MASK		0x30
573#define	TDE_BEA_EEMC_C_ALLOWED		0x20
574#define	TDE_BEA_EEMC_C_NOT_ALLOWED	0x10
575#define	TDE_BEA_EEMC_C_NOT_SPECIFIED	0x00
576	/*
577	 * Raw Decryption Mode Control Capabilities (RDMC_C) field.  The
578	 * descriptions are too complex to represent as a simple name.
579	 */
580#define	TDE_BEA_RDMC_C_MASK		0x0e
581#define	TDE_BEA_RDMC_C_MODE_7		0x0e
582#define	TDE_BEA_RDMC_C_MODE_6		0x0c
583#define	TDE_BEA_RDMC_C_MODE_5		0x0a
584#define	TDE_BEA_RDMC_C_MODE_4		0x08
585#define	TDE_BEA_RDMC_C_MODE_1		0x02
586#define	TDE_BEA_EAREM			0x01
587	uint8_t byte13;
588#define	TDE_BEA_MAX_EEDKS_MASK		0x0f
589	uint8_t msdk_count[2];
590	uint8_t max_eedk_size[2];
591	uint8_t reserved2[2];
592	uint8_t security_algo_code[4];
593};
594
595/*
596 * Data Encryption Capabilities page (0x0010).
597 */
598struct tde_data_enc_cap_page {
599	uint8_t page_code[2];
600	uint8_t page_length;
601	uint8_t byte4;
602#define	DATA_ENC_CAP_EXTDECC_MASK		0x0c
603#define	DATA_ENC_CAP_EXTDECC_NOT_REPORTED	0x00
604#define	DATA_ENC_CAP_EXTDECC_NOT_CAPABLE	0x04
605#define	DATA_ENC_CAP_EXTDECC_CAPABLE		0x08
606#define	DATA_ENC_CAP_CFG_P_MASK			0x03
607#define	DATA_ENC_CAP_CFG_P_NOT_REPORTED		0x00
608#define	DATA_ENC_CAP_CFG_P_ALLOWED		0x01
609#define	DATA_ENC_CAP_CFG_P_NOT_ALLOWED		0x02
610	uint8_t reserved[15];
611	struct tde_block_enc_alg_desc alg_descs[];
612};
613
614/*
615 * Tape Data Encryption Supported Key Formats page (0x0011).
616 */
617struct tde_supported_key_formats_page {
618	uint8_t page_code[2];
619	uint8_t page_length[2];
620	uint8_t key_formats_list[];
621};
622
623/*
624 * Tape Data Encryption Management Capabilities page (0x0012).
625 */
626struct tde_data_enc_man_cap_page {
627	uint8_t page_code[2];
628	uint8_t page_length[2];
629	uint8_t byte4;
630#define	TDE_DEMC_LOCK_C		0x01
631	uint8_t byte5;
632#define	TDE_DEMC_CKOD_C		0x04
633#define	TDE_DEMC_CKORP_C	0x02
634#define	TDE_DEMC_CKORL_C	0x01
635	uint8_t reserved1;
636	uint8_t byte7;
637#define	TDE_DEMC_AITN_C		0x04
638#define	TDE_DEMC_LOCAL_C	0x02
639#define	TDE_DEMC_PUBLIC_C	0x01
640	uint8_t reserved2[8];
641};
642
643/*
644 * Tape Data Encryption Status Page (0x0020).
645 */
646struct tde_data_enc_status_page {
647	uint8_t page_code[2];
648	uint8_t page_length[2];
649	uint8_t scope;
650#define	TDE_DES_IT_NEXUS_SCOPE_MASK	0xe0
651#define	TDE_DES_LBE_SCOPE_MASK		0x07
652	uint8_t encryption_mode;
653	uint8_t decryption_mode;
654	uint8_t algo_index;
655	uint8_t key_instance_counter[4];
656	uint8_t byte12;
657#define	TDE_DES_PARAM_CTRL_MASK		0x70
658#define	TDE_DES_PARAM_CTRL_MGMT		0x40
659#define	TDE_DES_PARAM_CTRL_CHANGER	0x30
660#define	TDE_DES_PARAM_CTRL_DRIVE	0x20
661#define	TDE_DES_PARAM_CTRL_EXT		0x10
662#define	TDE_DES_PARAM_CTRL_NOT_REPORTED	0x00
663#define	TDE_DES_VCELB			0x08
664#define	TDE_DES_CEEMS_MASK		0x06
665#define	TDE_DES_RDMD			0x01
666	uint8_t enc_params_kad_format;
667	uint8_t asdk_count[2];
668	uint8_t reserved[8];
669	uint8_t key_assoc_data_desc[];
670};
671
672/*
673 * Tape Data Encryption Next Block Encryption Status page (0x0021).
674 */
675struct tde_next_block_enc_status_page {
676	uint8_t page_code[2];
677	uint8_t page_length[2];
678	uint8_t logical_obj_number[8];
679	uint8_t status;
680#define	TDE_NBES_COMP_STATUS_MASK	0xf0
681#define	TDE_NBES_COMP_INCAPABLE		0x00
682#define	TDE_NBES_COMP_NOT_YET		0x10
683#define	TDE_NBES_COMP_NOT_A_BLOCK	0x20
684#define	TDE_NBES_COMP_NOT_COMPRESSED	0x30
685#define	TDE_NBES_COMP_COMPRESSED	0x40
686#define	TDE_NBES_ENC_STATUS_MASK	0x0f
687#define	TDE_NBES_ENC_INCAPABLE		0x00
688#define	TDE_NBES_ENC_NOT_YET		0x01
689#define	TDE_NBES_ENC_NOT_A_BLOCK	0x02
690#define	TDE_NBES_ENC_NOT_ENCRYPTED	0x03
691#define	TDE_NBES_ENC_ALG_NOT_SUPPORTED	0x04
692#define	TDE_NBES_ENC_SUPPORTED_ALG	0x05
693#define	TDE_NBES_ENC_NO_KEY		0x06
694	uint8_t algo_index;
695	uint8_t byte14;
696#define	TDE_NBES_EMES			0x02
697#define	TDE_NBES_RDMDS			0x01
698	uint8_t next_block_kad_format;
699	uint8_t key_assoc_data_desc[];
700};
701
702/*
703 * Tape Data Encryption Get Encryption Management Attributes page (0x0022).
704 */
705struct tde_get_enc_man_attr_page {
706	uint8_t page_code[2];
707	uint8_t reserved[3];
708	uint8_t byte5;
709#define	TDE_GEMA_CAOD			0x01
710	uint8_t page_length[2];
711	uint8_t enc_mgmt_attr_desc[];
712};
713
714/*
715 * Tape Data Encryption Random Number page (0x0030).
716 */
717struct tde_random_num_page {
718	uint8_t page_code[2];
719	uint8_t page_length[2];
720	uint8_t random_number[32];
721};
722
723/*
724 * Tape Data Encryption Device Server Key Wrapping Public Key page (0x0031).
725 */
726struct tde_key_wrap_pk_page {
727	uint8_t page_code[2];
728	uint8_t page_length[2];
729	uint8_t public_key_type[4];
730	uint8_t public_key_format[4];
731	uint8_t public_key_length[2];
732	uint8_t public_key[];
733};
734
735/*
736 * Security Protocol Specific values for the Tape Data Encryption protocol
737 * (0x20) used with SECURITY PROTOCOL OUT.  See above for values used with
738 * SECURITY PROTOCOL IN.  Current as of SSCr03.
739 */
740#define	TDE_SET_DATA_ENC_PAGE		0x0010
741#define	TDE_SA_ENCAP_PAGE		0x0011
742#define	TDE_SET_ENC_MGMT_ATTR_PAGE	0x0022
743
744/*
745 * Tape Data Encryption Set Data Encryption page (0x0010).
746 */
747struct tde_set_data_enc_page {
748	uint8_t page_code[2];
749	uint8_t page_length[2];
750	uint8_t byte4;
751#define	TDE_SDE_SCOPE_MASK		0xe0
752#define	TDE_SDE_SCOPE_ALL_IT_NEXUS	0x80
753#define	TDE_SDE_SCOPE_LOCAL		0x40
754#define	TDE_SDE_SCOPE_PUBLIC		0x00
755#define	TDE_SDE_LOCK			0x01
756	uint8_t byte5;
757#define	TDE_SDE_CEEM_MASK		0xc0
758#define	TDE_SDE_CEEM_ENCRYPT		0xc0
759#define	TDE_SDE_CEEM_EXTERNAL		0x80
760#define	TDE_SDE_CEEM_NO_CHECK		0x40
761#define	TDE_SDE_RDMC_MASK		0x30
762#define	TDE_SDE_RDMC_DISABLED		0x30
763#define	TDE_SDE_RDMC_ENABLED		0x20
764#define	TDE_SDE_RDMC_DEFAULT		0x00
765#define	TDE_SDE_SDK			0x08
766#define	TDE_SDE_CKOD			0x04
767#define	TDE_SDE_CKORP			0x02
768#define	TDE_SDE_CKORL			0x01
769	uint8_t encryption_mode;
770#define	TDE_SDE_ENC_MODE_DISABLE	0x00
771#define	TDE_SDE_ENC_MODE_EXTERNAL	0x01
772#define	TDE_SDE_ENC_MODE_ENCRYPT	0x02
773	uint8_t decryption_mode;
774#define	TDE_SDE_DEC_MODE_DISABLE	0x00
775#define	TDE_SDE_DEC_MODE_RAW		0x01
776#define	TDE_SDE_DEC_MODE_DECRYPT	0x02
777#define	TDE_SDE_DEC_MODE_MIXED		0x03
778	uint8_t algo_index;
779	uint8_t lbe_key_format;
780#define	TDE_SDE_KEY_PLAINTEXT		0x00
781#define	TDE_SDE_KEY_VENDOR_SPEC		0x01
782#define	TDE_SDE_KEY_PUBLIC_WRAP		0x02
783#define	TDE_SDE_KEY_ESP_SCSI		0x03
784	uint8_t kad_format;
785#define	TDE_SDE_KAD_ASCII		0x02
786#define	TDE_SDE_KAD_BINARY		0x01
787#define	TDE_SDE_KAD_UNSPECIFIED		0x00
788	uint8_t reserved[7];
789	uint8_t lbe_key_length[2];
790	uint8_t lbe_key[];
791};
792
793/*
794 * Used for the Vendor Specific key format (0x01).
795 */
796struct tde_key_format_vendor {
797	uint8_t t10_vendor_id[8];
798	uint8_t vendor_key[];
799};
800
801/*
802 * Used for the public key wrapped format (0x02).
803 */
804struct tde_key_format_public_wrap {
805	uint8_t parameter_set[2];
806#define	TDE_PARAM_SET_RSA2048		0x0000
807#define	TDE_PARAM_SET_ECC521		0x0010
808	uint8_t label_length[2];
809	uint8_t label[];
810};
811
812/*
813 * Tape Data Encryption SA Encapsulation page (0x0011).
814 */
815struct tde_sa_encap_page {
816	uint8_t page_code[2];
817	uint8_t data_desc[];
818};
819
820/*
821 * Tape Data Encryption Set Encryption Management Attributes page (0x0022).
822 */
823struct tde_set_enc_mgmt_attr_page {
824	uint8_t page_code[2];
825	uint8_t reserved[3];
826	uint8_t byte5;
827#define	TDE_SEMA_CAOD			0x01
828	uint8_t page_length[2];
829	uint8_t attr_desc[];
830};
831
832/*
833 * Tape Data Encryption descriptor format.
834 * SSC4r03 Section 8.5.4.2.1 Table 197
835 */
836struct tde_data_enc_desc {
837	uint8_t key_desc_type;
838#define	TDE_KEY_DESC_WK_KAD		0x04
839#define	TDE_KEY_DESC_M_KAD		0x03
840#define	TDE_KEY_DESC_NONCE_VALUE	0x02
841#define	TDE_KEY_DESC_A_KAD		0x01
842#define	TDE_KEY_DESC_U_KAD		0x00
843	uint8_t byte2;
844#define	TDE_KEY_DESC_AUTH_MASK		0x07
845#define	TDE_KEY_DESC_AUTH_FAILED	0x04
846#define	TDE_KEY_DESC_AUTH_SUCCESS	0x03
847#define	TDE_KEY_DESC_AUTH_NO_ATTEMPT	0x02
848#define	TDE_KEY_DESC_AUTH_U_KAD		0x01
849	uint8_t key_desc_length[2];
850	uint8_t key_desc[];
851};
852
853/*
854 * Wrapped Key descriptor format.
855 * SSC4r03 Section 8.5.4.3.1 Table 200
856 */
857struct tde_wrapped_key_desc {
858	uint8_t wrapped_key_type;
859#define	TDE_WRAP_KEY_DESC_LENGTH	0x04
860#define	TDE_WRAP_KEY_DESC_IDENT		0x03
861#define	TDE_WRAP_KEY_DESC_INFO		0x02
862#define	TDE_WRAP_KEY_DESC_ENTITY_ID	0x01
863#define	TDE_WRAP_KEY_DESC_DEVICE_ID	0x00
864	uint8_t reserved;
865	uint8_t wrapped_desc_length[2];
866	uint8_t wrapped_desc[];
867};
868
869/*
870 * Encryption management attributes descriptor format.
871 * SSC4r03 Section 8.5.4.4.1 Table 202
872 */
873struct tde_enc_mgmt_attr_desc {
874	uint8_t enc_mgmt_attr_type[2];
875#define	TDE_EMAD_DESIRED_KEY_MGR_OP	0x0000
876#define	TDE_EMAD_LOG_BLOCK_ENC_KEY_CRIT	0x0001
877#define	TDE_EMAD_LOG_BLOCK_ENC_KEY_WRAP	0x0002
878	uint8_t reserved;
879	uint8_t byte2;
880#define	TDE_EMAD_CRIT			0x80
881	uint8_t attr_length[2];
882	uint8_t attributes[];
883#define	TDE_EMAD_DESIRED_KEY_CREATE	0x0001
884#define	TDE_EMAD_DESIRED_KEY_RESOLVE	0x0002
885};
886
887/*
888 * Logical block encryption key selection criteria descriptor format.
889 * SSC4r03 Section 8.5.4.4.3.1 Table 206
890 */
891struct tde_lb_enc_key_sel_desc {
892	uint8_t lbe_key_sel_crit_type[2];
893	/*
894	 * The CRIT bit is the top bit of the first byte of the type.
895	 */
896#define	TDE_LBE_KEY_SEL_CRIT		0x80
897#define	TDE_LBE_KEY_SEL_ALGO		0x0001
898#define	TDE_LBE_KEY_SEL_ID		0x0002
899	uint8_t lbe_key_sel_crit_length[2];
900	uint8_t lbe_key_sel_crit[];
901};
902
903/*
904 * Logical block encryption key wrapping attribute descriptor format.
905 * SSC4r03 Section 8.5.4.4.4.1 Table 209
906 */
907struct tde_lb_enc_key_wrap_desc {
908	uint8_t lbe_key_wrap_type[2];
909	/*
910	 * The CRIT bit is the top bit of the first byte of the type.
911	 */
912#define	TDE_LBE_KEY_WRAP_CRIT		0x80
913#define	TDE_LBE_KEY_WRAP_KEKS		0x0001
914	uint8_t lbe_key_wrap_length[2];
915	uint8_t lbe_key_wrap_attr[];
916};
917
918/*
919 * Opcodes
920 */
921#define REWIND			0x01
922#define FORMAT_MEDIUM		0x04
923#define READ_BLOCK_LIMITS	0x05
924#define SA_READ			0x08
925#define SA_WRITE		0x0A
926#define SET_CAPACITY		0x0B
927#define WRITE_FILEMARKS		0x10
928#define SPACE			0x11
929#define RESERVE_UNIT		0x16
930#define RELEASE_UNIT		0x17
931#define ERASE			0x19
932#define LOAD_UNLOAD		0x1B
933#define	LOCATE			0x2B
934#define	READ_POSITION		0x34
935#define	REPORT_DENSITY_SUPPORT	0x44
936#define	ALLOW_OVERWRITE		0x82
937#define	LOCATE_16		0x92
938
939/*
940 * Tape specific density codes- only enough of them here to recognize
941 * some specific older units so we can choose 2FM@EOD or FIXED blocksize
942 * quirks.
943 */
944#define SCSI_DENSITY_HALFINCH_800	0x01
945#define SCSI_DENSITY_HALFINCH_1600	0x02
946#define SCSI_DENSITY_HALFINCH_6250	0x03
947#define SCSI_DENSITY_HALFINCH_6250C	0xC3	/* HP Compressed 6250 */
948#define SCSI_DENSITY_QIC_11_4TRK	0x04
949#define SCSI_DENSITY_QIC_11_9TRK	0x84	/* Vendor Unique Emulex */
950#define SCSI_DENSITY_QIC_24		0x05
951#define SCSI_DENSITY_HALFINCH_PE	0x06
952#define SCSI_DENSITY_QIC_120		0x0f
953#define SCSI_DENSITY_QIC_150		0x10
954#define	SCSI_DENSITY_QIC_525_320	0x11
955#define	SCSI_DENSITY_QIC_1320		0x12
956#define	SCSI_DENSITY_QIC_2GB		0x22
957#define	SCSI_DENSITY_QIC_4GB		0x26
958#define	SCSI_DENSITY_QIC_3080		0x29
959
960__BEGIN_DECLS
961void	scsi_read_block_limits(struct ccb_scsiio *, u_int32_t,
962			       void (*cbfcnp)(struct cam_periph *, union ccb *),
963			       u_int8_t, struct scsi_read_block_limits_data *,
964			       u_int8_t , u_int32_t);
965
966void	scsi_sa_read_write(struct ccb_scsiio *csio, u_int32_t retries,
967			   void (*cbfcnp)(struct cam_periph *, union ccb *),
968			   u_int8_t tag_action, int readop, int sli,
969			   int fixed, u_int32_t length, u_int8_t *data_ptr,
970			   u_int32_t dxfer_len, u_int8_t sense_len,
971			   u_int32_t timeout);
972
973void	scsi_rewind(struct ccb_scsiio *csio, u_int32_t retries,
974		    void (*cbfcnp)(struct cam_periph *, union ccb *),
975		    u_int8_t tag_action, int immediate, u_int8_t sense_len,
976		    u_int32_t timeout);
977
978void	scsi_space(struct ccb_scsiio *csio, u_int32_t retries,
979		   void (*cbfcnp)(struct cam_periph *, union ccb *),
980		   u_int8_t tag_action, scsi_space_code code,
981		   u_int32_t count, u_int8_t sense_len, u_int32_t timeout);
982
983void	scsi_load_unload(struct ccb_scsiio *csio, u_int32_t retries,
984			 void (*cbfcnp)(struct cam_periph *, union ccb *),
985			 u_int8_t tag_action, int immediate,   int eot,
986			 int reten, int load, u_int8_t sense_len,
987			 u_int32_t timeout);
988
989void	scsi_write_filemarks(struct ccb_scsiio *csio, u_int32_t retries,
990			     void (*cbfcnp)(struct cam_periph *, union ccb *),
991			     u_int8_t tag_action, int immediate, int setmark,
992			     u_int32_t num_marks, u_int8_t sense_len,
993			     u_int32_t timeout);
994
995void	scsi_reserve_release_unit(struct ccb_scsiio *csio, u_int32_t retries,
996				  void (*cbfcnp)(struct cam_periph *,
997				  union ccb *), u_int8_t tag_action,
998				  int third_party, int third_party_id,
999				  u_int8_t sense_len, u_int32_t timeout,
1000				  int reserve);
1001
1002void	scsi_erase(struct ccb_scsiio *csio, u_int32_t retries,
1003		   void (*cbfcnp)(struct cam_periph *, union ccb *),
1004		   u_int8_t tag_action, int immediate, int long_erase,
1005		   u_int8_t sense_len, u_int32_t timeout);
1006
1007void	scsi_data_comp_page(struct scsi_data_compression_page *page,
1008			    u_int8_t dce, u_int8_t dde, u_int8_t red,
1009			    u_int32_t comp_algorithm,
1010			    u_int32_t decomp_algorithm);
1011
1012void	scsi_read_position(struct ccb_scsiio *csio, u_int32_t retries,
1013                           void (*cbfcnp)(struct cam_periph *, union ccb *),
1014                           u_int8_t tag_action, int hardsoft,
1015                           struct scsi_tape_position_data *sbp,
1016                           u_int8_t sense_len, u_int32_t timeout);
1017void	scsi_read_position_10(struct ccb_scsiio *csio, u_int32_t retries,
1018			      void (*cbfcnp)(struct cam_periph *, union ccb *),
1019			      u_int8_t tag_action, int service_action,
1020			      u_int8_t *data_ptr, u_int32_t length,
1021			      u_int32_t sense_len, u_int32_t timeout);
1022
1023void	scsi_set_position(struct ccb_scsiio *csio, u_int32_t retries,
1024                         void (*cbfcnp)(struct cam_periph *, union ccb *),
1025                         u_int8_t tag_action, int hardsoft, u_int32_t blkno,
1026                         u_int8_t sense_len, u_int32_t timeout);
1027
1028void	scsi_locate_10(struct ccb_scsiio *csio, u_int32_t retries,
1029		       void (*cbfcnp)(struct cam_periph *, union ccb *),
1030		       u_int8_t tag_action, int immed, int cp, int hard,
1031		       int64_t partition, u_int32_t block_address,
1032		       int sense_len, u_int32_t timeout);
1033
1034void	scsi_locate_16(struct ccb_scsiio *csio, u_int32_t retries,
1035		       void (*cbfcnp)(struct cam_periph *, union ccb *),
1036		       u_int8_t tag_action, int immed, int cp,
1037		       u_int8_t dest_type, int bam, int64_t partition,
1038		       u_int64_t logical_id, int sense_len,
1039		       u_int32_t timeout);
1040
1041void	scsi_report_density_support(struct ccb_scsiio *csio, u_int32_t retries,
1042				    void (*cbfcnp)(struct cam_periph *,
1043						   union ccb *),
1044				    u_int8_t tag_action, int media,
1045				    int medium_type, u_int8_t *data_ptr,
1046				    u_int32_t length, u_int32_t sense_len,
1047				    u_int32_t timeout);
1048
1049void	scsi_set_capacity(struct ccb_scsiio *csio, u_int32_t retries,
1050			  void (*cbfcnp)(struct cam_periph *, union ccb *),
1051			  u_int8_t tag_action, int byte1, u_int32_t proportion,
1052			  u_int32_t sense_len, u_int32_t timeout);
1053
1054void	scsi_format_medium(struct ccb_scsiio *csio, u_int32_t retries,
1055			   void (*cbfcnp)(struct cam_periph *, union ccb *),
1056			   u_int8_t tag_action, int byte1, int byte2,
1057			   u_int8_t *data_ptr, u_int32_t length,
1058			   u_int32_t sense_len, u_int32_t timeout);
1059
1060void	scsi_allow_overwrite(struct ccb_scsiio *csio, u_int32_t retries,
1061			     void (*cbfcnp)(struct cam_periph *, union ccb *),
1062			     u_int8_t tag_action, int allow_overwrite,
1063			     int partition, u_int64_t logical_id,
1064			     u_int32_t sense_len, u_int32_t timeout);
1065
1066__END_DECLS
1067
1068#endif /* _SCSI_SCSI_SA_H */
1069