scsi_da.h revision 268151
1/*
2 * Structures and definitions for SCSI commands to Direct Access Devices
3 */
4
5/*-
6 * Some lines of this file come from a file of the name "scsi.h"
7 * distributed by OSF as part of mach2.5,
8 *  so the following disclaimer has been kept.
9 *
10 * Copyright 1990 by Open Software Foundation,
11 * Grenoble, FRANCE
12 *
13 * 		All Rights Reserved
14 *
15 *   Permission to use, copy, modify, and distribute this software and
16 * its documentation for any purpose and without fee is hereby granted,
17 * provided that the above copyright notice appears in all copies and
18 * that both the copyright notice and this permission notice appear in
19 * supporting documentation, and that the name of OSF or Open Software
20 * Foundation not be used in advertising or publicity pertaining to
21 * distribution of the software without specific, written prior
22 * permission.
23 *
24 *   OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
25 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
26 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
27 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
28 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
29 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
30 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 */
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 * $FreeBSD: stable/10/sys/cam/scsi/scsi_da.h 268151 2014-07-02 10:45:31Z mav $
50 */
51
52#ifndef	_SCSI_SCSI_DA_H
53#define _SCSI_SCSI_DA_H 1
54
55#include <sys/cdefs.h>
56
57struct scsi_rezero_unit
58{
59	u_int8_t opcode;
60#define SRZU_LUN_MASK 0xE0
61	u_int8_t byte2;
62	u_int8_t reserved[3];
63	u_int8_t control;
64};
65
66/*
67 * NOTE:  The lower three bits of byte2 of the format CDB are the same as
68 * the lower three bits of byte2 of the read defect data CDB, below.
69 */
70struct scsi_format_unit
71{
72	u_int8_t opcode;
73	u_int8_t byte2;
74#define FU_FORMAT_MASK	SRDD10_DLIST_FORMAT_MASK
75#define FU_BLOCK_FORMAT	SRDD10_BLOCK_FORMAT
76#define FU_BFI_FORMAT	SRDD10_BYTES_FROM_INDEX_FORMAT
77#define FU_PHYS_FORMAT	SRDD10_PHYSICAL_SECTOR_FORMAT
78#define FU_CMPLST	0x08
79#define FU_FMT_DATA	0x10
80	u_int8_t vendor_specific;
81	u_int8_t interleave[2];
82	u_int8_t control;
83};
84
85struct scsi_reassign_blocks
86{
87	u_int8_t opcode;
88	u_int8_t byte2;
89	u_int8_t unused[3];
90	u_int8_t control;
91};
92
93struct scsi_read_defect_data_10
94{
95	u_int8_t opcode;
96
97	/*
98	 * The most significant 3 bits are the LUN, the other 5 are
99	 * reserved.
100	 */
101#define SRDD10_LUN_MASK 0xE0
102	u_int8_t byte2;
103#define SRDD10_GLIST 0x08
104#define SRDD10_PLIST 0x10
105#define SRDD10_DLIST_FORMAT_MASK 0x07
106#define SRDD10_BLOCK_FORMAT            0x00
107#define SRDD10_BYTES_FROM_INDEX_FORMAT 0x04
108#define SRDD10_PHYSICAL_SECTOR_FORMAT  0x05
109	u_int8_t format;
110
111	u_int8_t reserved[4];
112
113	u_int8_t alloc_length[2];
114#define	SRDD10_MAX_LENGTH		0xffff
115
116	u_int8_t control;
117};
118
119struct scsi_sanitize
120{
121	u_int8_t opcode;
122	u_int8_t byte2;
123#define SSZ_SERVICE_ACTION_OVERWRITE         0x01
124#define SSZ_SERVICE_ACTION_BLOCK_ERASE       0x02
125#define SSZ_SERVICE_ACTION_CRYPTO_ERASE      0x03
126#define SSZ_SERVICE_ACTION_EXIT_MODE_FAILURE 0x1F
127#define SSZ_UNRESTRICTED_EXIT                0x20
128#define SSZ_IMMED                            0x80
129	u_int8_t reserved[5];
130	u_int8_t length[2];
131	u_int8_t control;
132};
133
134struct scsi_sanitize_parameter_list
135{
136	u_int8_t byte1;
137#define SSZPL_INVERT 0x80
138	u_int8_t reserved;
139	u_int8_t length[2];
140	/* Variable length initialization pattern. */
141#define SSZPL_MAX_PATTERN_LENGTH 65535
142};
143
144struct scsi_read_defect_data_12
145{
146	u_int8_t opcode;
147
148	/*
149	 * The most significant 3 bits are the LUN, the other 5 are
150	 * reserved.
151	 */
152#define SRDD12_LUN_MASK 0xE0
153	u_int8_t byte2;
154
155#define SRDD12_GLIST 0x08
156#define SRDD12_PLIST 0x10
157#define SRDD12_DLIST_FORMAT_MASK 0x07
158#define SRDD12_BLOCK_FORMAT            0x00
159#define SRDD12_BYTES_FROM_INDEX_FORMAT 0x04
160#define SRDD12_PHYSICAL_SECTOR_FORMAT  0x05
161	u_int8_t format;
162
163	u_int8_t reserved[4];
164
165	u_int8_t alloc_length[4];
166
167	u_int8_t control;
168
169};
170
171
172/*
173 * Opcodes
174 */
175#define REZERO_UNIT		0x01
176#define FORMAT_UNIT		0x04
177#define	REASSIGN_BLOCKS		0x07
178#define MODE_SELECT		0x15
179#define MODE_SENSE		0x1a
180#define	READ_FORMAT_CAPACITIES	0x23
181#define	WRITE_AND_VERIFY	0x2e
182#define	VERIFY			0x2f
183#define READ_DEFECT_DATA_10	0x37
184#define SANITIZE		0x48
185#define READ_DEFECT_DATA_12	0xb7
186
187struct format_defect_list_header
188{
189	u_int8_t reserved;
190	u_int8_t byte2;
191#define FU_DLH_VS	0x01
192#define FU_DLH_IMMED	0x02
193#define FU_DLH_DSP	0x04
194#define FU_DLH_IP	0x08
195#define FU_DLH_STPF	0x10
196#define FU_DLH_DCRT	0x20
197#define FU_DLH_DPRY	0x40
198#define FU_DLH_FOV	0x80
199	u_int8_t defect_list_length[2];
200};
201
202struct format_ipat_descriptor
203{
204	u_int8_t byte1;
205#define	FU_INIT_NO_HDR		0x00
206#define FU_INIT_LBA_MSB		0x40
207#define FU_INIT_LBA_EACH	0x80
208#define FU_INIT_SI		0x20
209	u_int8_t pattern_type;
210#define FU_INIT_PAT_DEFAULT	0x00
211#define FU_INIT_PAT_REPEAT	0x01
212	u_int8_t pat_length[2];
213};
214
215struct scsi_read_format_capacities
216{
217	uint8_t	opcode;		/* READ_FORMAT_CAPACITIES */
218	uint8_t	byte2;
219#define	SRFC_LUN_MASK	0xE0
220	uint8_t	reserved0[5];
221	uint8_t	alloc_length[2];
222	uint8_t	reserved1[3];
223};
224
225struct scsi_verify_10
226{
227	uint8_t	opcode;		/* VERIFY(10) */
228	uint8_t	byte2;
229#define	SVFY_LUN_MASK	0xE0
230#define	SVFY_RELADR	0x01
231#define	SVFY_BYTCHK	0x02
232#define	SVFY_DPO	0x10
233	uint8_t	addr[4];	/* LBA to begin verification at */
234	uint8_t	group;
235	uint8_t	length[2];		/* number of blocks to verify */
236	uint8_t	control;
237};
238
239struct scsi_verify_12
240{
241	uint8_t	opcode;		/* VERIFY(12) */
242	uint8_t	byte2;
243	uint8_t	addr[4];	/* LBA to begin verification at */
244	uint8_t	length[4];		/* number of blocks to verify */
245	uint8_t	group;
246	uint8_t	control;
247};
248
249struct scsi_verify_16
250{
251	uint8_t	opcode;		/* VERIFY(16) */
252	uint8_t	byte2;
253	uint8_t	addr[8];	/* LBA to begin verification at */
254	uint8_t	length[4];		/* number of blocks to verify */
255	uint8_t	group;
256	uint8_t	control;
257};
258
259struct scsi_compare_and_write
260{
261	uint8_t	opcode;		/* COMPARE AND WRITE */
262	uint8_t	byte2;
263	uint8_t	addr[8];	/* LBA to begin verification at */
264	uint8_t	reserved[3];
265	uint8_t	length;		/* number of blocks */
266	uint8_t	group;
267	uint8_t	control;
268};
269
270struct scsi_write_and_verify
271{
272	uint8_t	opcode;		/* WRITE_AND_VERIFY */
273	uint8_t	byte2;
274#define	SWVY_LUN_MASK	0xE0
275#define	SWVY_RELADR	0x01
276#define	SWVY_BYTECHK	0x02
277#define	SWVY_DPO	0x10
278	uint8_t	addr[4];	/* LBA to begin verification at */
279	uint8_t	reserved0[1];
280	uint8_t	len[2];		/* number of blocks to write and verify */
281	uint8_t	reserved1[3];
282};
283
284/*
285 * Replies to READ_FORMAT_CAPACITIES look like this:
286 *
287 * struct format_capacity_list_header
288 * struct format_capacity_descriptor[1..n]
289 *
290 * These are similar, but not totally identical to, the
291 * defect list used to format a rigid disk.
292 *
293 * The appropriate csio_decode() format string looks like this:
294 * "{} *i3 {Len} i1 {Blocks} i4 {} *b6 {Code} b2 {Blocklen} i3"
295 *
296 * If the capacity_list_length is greater than
297 * sizeof(struct format_capacity_descriptor), then there are
298 * additional format capacity descriptors available which
299 * denote which format(s) the drive can handle.
300 *
301 * (Source: USB Mass Storage UFI Specification)
302 */
303
304struct format_capacity_list_header {
305	uint8_t	unused[3];
306	uint8_t	capacity_list_length;
307};
308
309struct format_capacity_descriptor {
310	uint8_t	nblocks[4];	/* total number of LBAs */
311	uint8_t	byte4;		/* only present in max/cur descriptor */
312#define FCD_CODE_MASK	0x03	/* mask for code field above */
313#define FCD_UNFORMATTED	0x01	/* unformatted media present,
314				 * maximum capacity returned */
315#define FCD_FORMATTED	0x02	/* formatted media present,
316				 * current capacity returned */
317#define FCD_NOMEDIA	0x03	/* no media present,
318				 * maximum device capacity returned */
319	uint8_t	block_length[3];	/* length of an LBA in bytes */
320};
321
322struct scsi_reassign_blocks_data
323{
324	u_int8_t reserved[2];
325	u_int8_t length[2];
326	struct {
327		u_int8_t dlbaddr[4];	/* defect logical block address */
328	} defect_descriptor[1];
329};
330
331
332/*
333 * This is the list header for the READ DEFECT DATA(10) command above.
334 * It may be a bit wrong to append the 10 at the end of the data structure,
335 * since it's only 4 bytes but it does tie it to the 10 byte command.
336 */
337struct scsi_read_defect_data_hdr_10
338{
339	u_int8_t reserved;
340#define SRDDH10_GLIST 0x08
341#define SRDDH10_PLIST 0x10
342#define SRDDH10_DLIST_FORMAT_MASK 0x07
343#define SRDDH10_BLOCK_FORMAT            0x00
344#define SRDDH10_BYTES_FROM_INDEX_FORMAT 0x04
345#define SRDDH10_PHYSICAL_SECTOR_FORMAT  0x05
346	u_int8_t format;
347	u_int8_t length[2];
348};
349
350struct scsi_defect_desc_block
351{
352	u_int8_t address[4];
353};
354
355struct scsi_defect_desc_bytes_from_index
356{
357	u_int8_t cylinder[3];
358	u_int8_t head;
359	u_int8_t bytes_from_index[4];
360};
361
362struct scsi_defect_desc_phys_sector
363{
364	u_int8_t cylinder[3];
365	u_int8_t head;
366	u_int8_t sector[4];
367};
368
369struct scsi_read_defect_data_hdr_12
370{
371	u_int8_t reserved;
372#define SRDDH12_GLIST 0x08
373#define SRDDH12_PLIST 0x10
374#define SRDDH12_DLIST_FORMAT_MASK 0x07
375#define SRDDH12_BLOCK_FORMAT            0x00
376#define SRDDH12_BYTES_FROM_INDEX_FORMAT 0x04
377#define SRDDH12_PHYSICAL_SECTOR_FORMAT  0x05
378	u_int8_t format;
379	u_int8_t length[4];
380};
381
382union	disk_pages /* this is the structure copied from osf */
383{
384	struct format_device_page {
385		u_int8_t pg_code;	/* page code (should be 3)	      */
386#define	SMS_FORMAT_DEVICE_PAGE	0x03	/* only 6 bits valid */
387		u_int8_t pg_length;	/* page length (should be 0x16)	      */
388#define	SMS_FORMAT_DEVICE_PLEN	0x16
389		u_int8_t trk_z_1;	/* tracks per zone (MSB)	      */
390		u_int8_t trk_z_0;	/* tracks per zone (LSB)	      */
391		u_int8_t alt_sec_1;	/* alternate sectors per zone (MSB)   */
392		u_int8_t alt_sec_0;	/* alternate sectors per zone (LSB)   */
393		u_int8_t alt_trk_z_1;	/* alternate tracks per zone (MSB)    */
394		u_int8_t alt_trk_z_0;	/* alternate tracks per zone (LSB)    */
395		u_int8_t alt_trk_v_1;	/* alternate tracks per volume (MSB)  */
396		u_int8_t alt_trk_v_0;	/* alternate tracks per volume (LSB)  */
397		u_int8_t ph_sec_t_1;	/* physical sectors per track (MSB)   */
398		u_int8_t ph_sec_t_0;	/* physical sectors per track (LSB)   */
399		u_int8_t bytes_s_1;	/* bytes per sector (MSB)	      */
400		u_int8_t bytes_s_0;	/* bytes per sector (LSB)	      */
401		u_int8_t interleave_1;	/* interleave (MSB)		      */
402		u_int8_t interleave_0;	/* interleave (LSB)		      */
403		u_int8_t trk_skew_1;	/* track skew factor (MSB)	      */
404		u_int8_t trk_skew_0;	/* track skew factor (LSB)	      */
405		u_int8_t cyl_skew_1;	/* cylinder skew (MSB)		      */
406		u_int8_t cyl_skew_0;	/* cylinder skew (LSB)		      */
407		u_int8_t flags;		/* various */
408#define			DISK_FMT_SURF	0x10
409#define	       		DISK_FMT_RMB	0x20
410#define			DISK_FMT_HSEC	0x40
411#define			DISK_FMT_SSEC	0x80
412		u_int8_t reserved21;
413		u_int8_t reserved22;
414		u_int8_t reserved23;
415	} format_device;
416	struct rigid_geometry_page {
417		u_int8_t pg_code;	/* page code (should be 4)	      */
418#define SMS_RIGID_GEOMETRY_PAGE 0x04
419		u_int8_t pg_length;	/* page length (should be 0x16)	      */
420#define SMS_RIGID_GEOMETRY_PLEN 0x16
421		u_int8_t ncyl_2;	/* number of cylinders (MSB)	      */
422		u_int8_t ncyl_1;	/* number of cylinders 		      */
423		u_int8_t ncyl_0;	/* number of cylinders (LSB)	      */
424		u_int8_t nheads;	/* number of heads 		      */
425		u_int8_t st_cyl_wp_2;	/* starting cyl., write precomp (MSB) */
426		u_int8_t st_cyl_wp_1;	/* starting cyl., write precomp	      */
427		u_int8_t st_cyl_wp_0;	/* starting cyl., write precomp (LSB) */
428		u_int8_t st_cyl_rwc_2;	/* starting cyl., red. write cur (MSB)*/
429		u_int8_t st_cyl_rwc_1;	/* starting cyl., red. write cur      */
430		u_int8_t st_cyl_rwc_0;	/* starting cyl., red. write cur (LSB)*/
431		u_int8_t driv_step_1;	/* drive step rate (MSB)	      */
432		u_int8_t driv_step_0;	/* drive step rate (LSB)	      */
433		u_int8_t land_zone_2;	/* landing zone cylinder (MSB)	      */
434		u_int8_t land_zone_1;	/* landing zone cylinder 	      */
435		u_int8_t land_zone_0;	/* landing zone cylinder (LSB)	      */
436		u_int8_t rpl;		/* rotational position locking (2 bits) */
437		u_int8_t rot_offset;	/* rotational offset */
438		u_int8_t reserved19;
439		u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */
440		u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */
441		u_int8_t reserved22;
442		u_int8_t reserved23;
443    	} rigid_geometry;
444	struct flexible_disk_page {
445		u_int8_t pg_code;	/* page code (should be 5)	      */
446#define SMS_FLEXIBLE_GEOMETRY_PAGE 0x05
447		u_int8_t pg_length;	/* page length (should be 0x1E)	      */
448#define SMS_FLEXIBLE_GEOMETRY_PLEN 0x1E
449		u_int8_t xfr_rate_1;	/* transfer rate (MSB)		      */
450		u_int8_t xfr_rate_0;	/* transfer rate (LSB)		      */
451		u_int8_t nheads;	/* number of heads 		      */
452		u_int8_t sec_per_track;	/* Sectors per track		      */
453		u_int8_t bytes_s_1;	/* bytes per sector (MSB)	      */
454		u_int8_t bytes_s_0;	/* bytes per sector (LSB)	      */
455		u_int8_t ncyl_1;	/* number of cylinders (MSB)	      */
456		u_int8_t ncyl_0;	/* number of cylinders (LSB)	      */
457		u_int8_t st_cyl_wp_1;	/* starting cyl., write precomp (MSB) */
458		u_int8_t st_cyl_wp_0;	/* starting cyl., write precomp (LSB) */
459		u_int8_t st_cyl_rwc_1;	/* starting cyl., red. write cur (MSB)*/
460		u_int8_t st_cyl_rwc_0;	/* starting cyl., red. write cur (LSB)*/
461		u_int8_t driv_step_1;	/* drive step rate (MSB)	      */
462		u_int8_t driv_step_0;	/* drive step rate (LSB)	      */
463		u_int8_t driv_step_pw;	/* drive step pulse width	      */
464		u_int8_t head_stl_del_1;/* Head settle delay (MSB)	      */
465		u_int8_t head_stl_del_0;/* Head settle delay (LSB)	      */
466		u_int8_t motor_on_del;	/* Motor on delay		      */
467		u_int8_t motor_off_del;	/* Motor off delay		      */
468		u_int8_t trdy_ssn_mo;	/* XXX ??? */
469		u_int8_t spc;		/* XXX ??? */
470		u_int8_t write_comp;	/* Write compensation */
471		u_int8_t head_load_del; /* Head load delay */
472		u_int8_t head_uload_del;/* Head un-load delay */
473		u_int8_t pin32_pin2;
474		u_int8_t pin4_pint1;
475		u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */
476		u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */
477		u_int8_t reserved30;
478		u_int8_t reserved31;
479    	} flexible_disk;
480};
481
482/*
483 * XXX KDM
484 * Here for CTL compatibility, reconcile this.
485 */
486struct scsi_format_page {
487	uint8_t page_code;
488	uint8_t page_length;
489	uint8_t tracks_per_zone[2];
490	uint8_t alt_sectors_per_zone[2];
491	uint8_t alt_tracks_per_zone[2];
492	uint8_t alt_tracks_per_lun[2];
493	uint8_t sectors_per_track[2];
494	uint8_t bytes_per_sector[2];
495	uint8_t interleave[2];
496	uint8_t track_skew[2];
497	uint8_t cylinder_skew[2];
498	uint8_t flags;
499#define	SFP_SSEC	0x80
500#define	SFP_HSEC	0x40
501#define	SFP_RMB		0x20
502#define	SFP_SURF	0x10
503	uint8_t reserved[3];
504};
505
506/*
507 * XXX KDM
508 * Here for CTL compatibility, reconcile this.
509 */
510struct scsi_rigid_disk_page {
511	uint8_t page_code;
512#define	SMS_RIGID_DISK_PAGE		0x04
513	uint8_t page_length;
514	uint8_t cylinders[3];
515	uint8_t heads;
516	uint8_t start_write_precomp[3];
517	uint8_t start_reduced_current[3];
518	uint8_t step_rate[2];
519	uint8_t landing_zone_cylinder[3];
520	uint8_t rpl;
521#define	SRDP_RPL_DISABLED	0x00
522#define	SRDP_RPL_SLAVE		0x01
523#define	SRDP_RPL_MASTER		0x02
524#define	SRDP_RPL_MASTER_CONTROL	0x03
525	uint8_t rotational_offset;
526	uint8_t reserved1;
527	uint8_t rotation_rate[2];
528	uint8_t reserved2[2];
529};
530
531
532struct scsi_da_rw_recovery_page {
533	u_int8_t page_code;
534#define SMS_RW_ERROR_RECOVERY_PAGE	0x01
535	u_int8_t page_length;
536	u_int8_t byte3;
537#define SMS_RWER_AWRE			0x80
538#define SMS_RWER_ARRE			0x40
539#define SMS_RWER_TB			0x20
540#define SMS_RWER_RC			0x10
541#define SMS_RWER_EER			0x08
542#define SMS_RWER_PER			0x04
543#define SMS_RWER_DTE			0x02
544#define SMS_RWER_DCR			0x01
545	u_int8_t read_retry_count;
546	u_int8_t correction_span;
547	u_int8_t head_offset_count;
548	u_int8_t data_strobe_offset_cnt;
549	u_int8_t reserved;
550	u_int8_t write_retry_count;
551	u_int8_t reserved2;
552	u_int8_t recovery_time_limit[2];
553};
554
555__BEGIN_DECLS
556/*
557 * XXX This is only left out of the kernel build to silence warnings.  If,
558 * for some reason this function is used in the kernel, the ifdefs should
559 * be moved so it is included both in the kernel and userland.
560 */
561#ifndef _KERNEL
562void scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
563		      void (*cbfcnp)(struct cam_periph *, union ccb *),
564		      u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
565		      u_int8_t *data_ptr, u_int32_t dxfer_len,
566		      u_int8_t sense_len, u_int32_t timeout);
567
568void scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
569		   void (*cbfcnp)(struct cam_periph *, union ccb *),
570		   u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
571		   u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
572		   u_int32_t timeout);
573
574#endif /* !_KERNEL */
575__END_DECLS
576
577#endif /* _SCSI_SCSI_DA_H */
578