xref: /freebsd/sys/cam/scsi/scsi_da.h (revision cc16dea626cf2fc80cde667ac4798065108e596c)
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$
50  */
51 
52 #ifndef	_SCSI_SCSI_DA_H
53 #define _SCSI_SCSI_DA_H 1
54 
55 #include <sys/cdefs.h>
56 
57 struct 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  */
70 struct 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 
85 struct 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 
93 struct 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 
119 struct scsi_read_defect_data_12
120 {
121 	u_int8_t opcode;
122 
123 	/*
124 	 * The most significant 3 bits are the LUN, the other 5 are
125 	 * reserved.
126 	 */
127 #define SRDD12_LUN_MASK 0xE0
128 	u_int8_t byte2;
129 
130 #define SRDD12_GLIST 0x08
131 #define SRDD12_PLIST 0x10
132 #define SRDD12_DLIST_FORMAT_MASK 0x07
133 #define SRDD12_BLOCK_FORMAT            0x00
134 #define SRDD12_BYTES_FROM_INDEX_FORMAT 0x04
135 #define SRDD12_PHYSICAL_SECTOR_FORMAT  0x05
136 	u_int8_t format;
137 
138 	u_int8_t reserved[4];
139 
140 	u_int8_t alloc_length[4];
141 
142 	u_int8_t control;
143 
144 };
145 
146 
147 /*
148  * Opcodes
149  */
150 #define REZERO_UNIT		0x01
151 #define FORMAT_UNIT		0x04
152 #define	REASSIGN_BLOCKS		0x07
153 #define MODE_SELECT		0x15
154 #define MODE_SENSE		0x1a
155 #define	READ_FORMAT_CAPACITIES	0x23
156 #define	WRITE_AND_VERIFY	0x2e
157 #define	VERIFY			0x2f
158 #define READ_DEFECT_DATA_10	0x37
159 #define READ_DEFECT_DATA_12	0xb7
160 
161 struct format_defect_list_header
162 {
163 	u_int8_t reserved;
164 	u_int8_t byte2;
165 #define FU_DLH_VS	0x01
166 #define FU_DLH_IMMED	0x02
167 #define FU_DLH_DSP	0x04
168 #define FU_DLH_IP	0x08
169 #define FU_DLH_STPF	0x10
170 #define FU_DLH_DCRT	0x20
171 #define FU_DLH_DPRY	0x40
172 #define FU_DLH_FOV	0x80
173 	u_int8_t defect_list_length[2];
174 };
175 
176 struct format_ipat_descriptor
177 {
178 	u_int8_t byte1;
179 #define	FU_INIT_NO_HDR		0x00
180 #define FU_INIT_LBA_MSB		0x40
181 #define FU_INIT_LBA_EACH	0x80
182 #define FU_INIT_SI		0x20
183 	u_int8_t pattern_type;
184 #define FU_INIT_PAT_DEFAULT	0x00
185 #define FU_INIT_PAT_REPEAT	0x01
186 	u_int8_t pat_length[2];
187 };
188 
189 struct scsi_read_format_capacities
190 {
191 	uint8_t	opcode;		/* READ_FORMAT_CAPACITIES */
192 	uint8_t	byte2;
193 #define	SRFC_LUN_MASK	0xE0
194 	uint8_t	reserved0[5];
195 	uint8_t	alloc_length[2];
196 	uint8_t	reserved1[3];
197 };
198 
199 struct scsi_verify
200 {
201 	uint8_t	opcode;		/* VERIFY */
202 	uint8_t	byte2;
203 #define	SVFY_LUN_MASK	0xE0
204 #define	SVFY_RELADR	0x01
205 #define	SVFY_BYTECHK	0x02
206 #define	SVFY_DPO	0x10
207 	uint8_t	addr[4];	/* LBA to begin verification at */
208 	uint8_t	reserved0[1];
209 	uint8_t	len[2];		/* number of blocks to verify */
210 	uint8_t	reserved1[3];
211 };
212 
213 struct scsi_write_and_verify
214 {
215 	uint8_t	opcode;		/* WRITE_AND_VERIFY */
216 	uint8_t	byte2;
217 #define	SWVY_LUN_MASK	0xE0
218 #define	SWVY_RELADR	0x01
219 #define	SWVY_BYTECHK	0x02
220 #define	SWVY_DPO	0x10
221 	uint8_t	addr[4];	/* LBA to begin verification at */
222 	uint8_t	reserved0[1];
223 	uint8_t	len[2];		/* number of blocks to write and verify */
224 	uint8_t	reserved1[3];
225 };
226 
227 /*
228  * Replies to READ_FORMAT_CAPACITIES look like this:
229  *
230  * struct format_capacity_list_header
231  * struct format_capacity_descriptor[1..n]
232  *
233  * These are similar, but not totally identical to, the
234  * defect list used to format a rigid disk.
235  *
236  * The appropriate csio_decode() format string looks like this:
237  * "{} *i3 {Len} i1 {Blocks} i4 {} *b6 {Code} b2 {Blocklen} i3"
238  *
239  * If the capacity_list_length is greater than
240  * sizeof(struct format_capacity_descriptor), then there are
241  * additional format capacity descriptors available which
242  * denote which format(s) the drive can handle.
243  *
244  * (Source: USB Mass Storage UFI Specification)
245  */
246 
247 struct format_capacity_list_header {
248 	uint8_t	unused[3];
249 	uint8_t	capacity_list_length;
250 };
251 
252 struct format_capacity_descriptor {
253 	uint8_t	nblocks[4];	/* total number of LBAs */
254 	uint8_t	byte4;		/* only present in max/cur descriptor */
255 #define FCD_CODE_MASK	0x03	/* mask for code field above */
256 #define FCD_UNFORMATTED	0x01	/* unformatted media present,
257 				 * maximum capacity returned */
258 #define FCD_FORMATTED	0x02	/* formatted media present,
259 				 * current capacity returned */
260 #define FCD_NOMEDIA	0x03	/* no media present,
261 				 * maximum device capacity returned */
262 	uint8_t	block_length[3];	/* length of an LBA in bytes */
263 };
264 
265 struct scsi_reassign_blocks_data
266 {
267 	u_int8_t reserved[2];
268 	u_int8_t length[2];
269 	struct {
270 		u_int8_t dlbaddr[4];	/* defect logical block address */
271 	} defect_descriptor[1];
272 };
273 
274 
275 /*
276  * This is the list header for the READ DEFECT DATA(10) command above.
277  * It may be a bit wrong to append the 10 at the end of the data structure,
278  * since it's only 4 bytes but it does tie it to the 10 byte command.
279  */
280 struct scsi_read_defect_data_hdr_10
281 {
282 	u_int8_t reserved;
283 #define SRDDH10_GLIST 0x08
284 #define SRDDH10_PLIST 0x10
285 #define SRDDH10_DLIST_FORMAT_MASK 0x07
286 #define SRDDH10_BLOCK_FORMAT            0x00
287 #define SRDDH10_BYTES_FROM_INDEX_FORMAT 0x04
288 #define SRDDH10_PHYSICAL_SECTOR_FORMAT  0x05
289 	u_int8_t format;
290 	u_int8_t length[2];
291 };
292 
293 struct scsi_defect_desc_block
294 {
295 	u_int8_t address[4];
296 };
297 
298 struct scsi_defect_desc_bytes_from_index
299 {
300 	u_int8_t cylinder[3];
301 	u_int8_t head;
302 	u_int8_t bytes_from_index[4];
303 };
304 
305 struct scsi_defect_desc_phys_sector
306 {
307 	u_int8_t cylinder[3];
308 	u_int8_t head;
309 	u_int8_t sector[4];
310 };
311 
312 struct scsi_read_defect_data_hdr_12
313 {
314 	u_int8_t reserved;
315 #define SRDDH12_GLIST 0x08
316 #define SRDDH12_PLIST 0x10
317 #define SRDDH12_DLIST_FORMAT_MASK 0x07
318 #define SRDDH12_BLOCK_FORMAT            0x00
319 #define SRDDH12_BYTES_FROM_INDEX_FORMAT 0x04
320 #define SRDDH12_PHYSICAL_SECTOR_FORMAT  0x05
321 	u_int8_t format;
322 	u_int8_t length[4];
323 };
324 
325 union	disk_pages /* this is the structure copied from osf */
326 {
327 	struct format_device_page {
328 		u_int8_t pg_code;	/* page code (should be 3)	      */
329 #define	SMS_FORMAT_DEVICE_PAGE	0x03	/* only 6 bits valid */
330 		u_int8_t pg_length;	/* page length (should be 0x16)	      */
331 #define	SMS_FORMAT_DEVICE_PLEN	0x16
332 		u_int8_t trk_z_1;	/* tracks per zone (MSB)	      */
333 		u_int8_t trk_z_0;	/* tracks per zone (LSB)	      */
334 		u_int8_t alt_sec_1;	/* alternate sectors per zone (MSB)   */
335 		u_int8_t alt_sec_0;	/* alternate sectors per zone (LSB)   */
336 		u_int8_t alt_trk_z_1;	/* alternate tracks per zone (MSB)    */
337 		u_int8_t alt_trk_z_0;	/* alternate tracks per zone (LSB)    */
338 		u_int8_t alt_trk_v_1;	/* alternate tracks per volume (MSB)  */
339 		u_int8_t alt_trk_v_0;	/* alternate tracks per volume (LSB)  */
340 		u_int8_t ph_sec_t_1;	/* physical sectors per track (MSB)   */
341 		u_int8_t ph_sec_t_0;	/* physical sectors per track (LSB)   */
342 		u_int8_t bytes_s_1;	/* bytes per sector (MSB)	      */
343 		u_int8_t bytes_s_0;	/* bytes per sector (LSB)	      */
344 		u_int8_t interleave_1;	/* interleave (MSB)		      */
345 		u_int8_t interleave_0;	/* interleave (LSB)		      */
346 		u_int8_t trk_skew_1;	/* track skew factor (MSB)	      */
347 		u_int8_t trk_skew_0;	/* track skew factor (LSB)	      */
348 		u_int8_t cyl_skew_1;	/* cylinder skew (MSB)		      */
349 		u_int8_t cyl_skew_0;	/* cylinder skew (LSB)		      */
350 		u_int8_t flags;		/* various */
351 #define			DISK_FMT_SURF	0x10
352 #define	       		DISK_FMT_RMB	0x20
353 #define			DISK_FMT_HSEC	0x40
354 #define			DISK_FMT_SSEC	0x80
355 		u_int8_t reserved21;
356 		u_int8_t reserved22;
357 		u_int8_t reserved23;
358 	} format_device;
359 	struct rigid_geometry_page {
360 		u_int8_t pg_code;	/* page code (should be 4)	      */
361 #define SMS_RIGID_GEOMETRY_PAGE 0x04
362 		u_int8_t pg_length;	/* page length (should be 0x16)	      */
363 #define SMS_RIGID_GEOMETRY_PLEN 0x16
364 		u_int8_t ncyl_2;	/* number of cylinders (MSB)	      */
365 		u_int8_t ncyl_1;	/* number of cylinders 		      */
366 		u_int8_t ncyl_0;	/* number of cylinders (LSB)	      */
367 		u_int8_t nheads;	/* number of heads 		      */
368 		u_int8_t st_cyl_wp_2;	/* starting cyl., write precomp (MSB) */
369 		u_int8_t st_cyl_wp_1;	/* starting cyl., write precomp	      */
370 		u_int8_t st_cyl_wp_0;	/* starting cyl., write precomp (LSB) */
371 		u_int8_t st_cyl_rwc_2;	/* starting cyl., red. write cur (MSB)*/
372 		u_int8_t st_cyl_rwc_1;	/* starting cyl., red. write cur      */
373 		u_int8_t st_cyl_rwc_0;	/* starting cyl., red. write cur (LSB)*/
374 		u_int8_t driv_step_1;	/* drive step rate (MSB)	      */
375 		u_int8_t driv_step_0;	/* drive step rate (LSB)	      */
376 		u_int8_t land_zone_2;	/* landing zone cylinder (MSB)	      */
377 		u_int8_t land_zone_1;	/* landing zone cylinder 	      */
378 		u_int8_t land_zone_0;	/* landing zone cylinder (LSB)	      */
379 		u_int8_t rpl;		/* rotational position locking (2 bits) */
380 		u_int8_t rot_offset;	/* rotational offset */
381 		u_int8_t reserved19;
382 		u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */
383 		u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */
384 		u_int8_t reserved22;
385 		u_int8_t reserved23;
386     	} rigid_geometry;
387 	struct flexible_disk_page {
388 		u_int8_t pg_code;	/* page code (should be 5)	      */
389 #define SMS_FLEXIBLE_GEOMETRY_PAGE 0x05
390 		u_int8_t pg_length;	/* page length (should be 0x1E)	      */
391 #define SMS_FLEXIBLE_GEOMETRY_PLEN 0x1E
392 		u_int8_t xfr_rate_1;	/* transfer rate (MSB)		      */
393 		u_int8_t xfr_rate_0;	/* transfer rate (LSB)		      */
394 		u_int8_t nheads;	/* number of heads 		      */
395 		u_int8_t sec_per_track;	/* Sectors per track		      */
396 		u_int8_t bytes_s_1;	/* bytes per sector (MSB)	      */
397 		u_int8_t bytes_s_0;	/* bytes per sector (LSB)	      */
398 		u_int8_t ncyl_1;	/* number of cylinders (MSB)	      */
399 		u_int8_t ncyl_0;	/* number of cylinders (LSB)	      */
400 		u_int8_t st_cyl_wp_1;	/* starting cyl., write precomp (MSB) */
401 		u_int8_t st_cyl_wp_0;	/* starting cyl., write precomp (LSB) */
402 		u_int8_t st_cyl_rwc_1;	/* starting cyl., red. write cur (MSB)*/
403 		u_int8_t st_cyl_rwc_0;	/* starting cyl., red. write cur (LSB)*/
404 		u_int8_t driv_step_1;	/* drive step rate (MSB)	      */
405 		u_int8_t driv_step_0;	/* drive step rate (LSB)	      */
406 		u_int8_t driv_step_pw;	/* drive step pulse width	      */
407 		u_int8_t head_stl_del_1;/* Head settle delay (MSB)	      */
408 		u_int8_t head_stl_del_0;/* Head settle delay (LSB)	      */
409 		u_int8_t motor_on_del;	/* Motor on delay		      */
410 		u_int8_t motor_off_del;	/* Motor off delay		      */
411 		u_int8_t trdy_ssn_mo;	/* XXX ??? */
412 		u_int8_t spc;		/* XXX ??? */
413 		u_int8_t write_comp;	/* Write compensation */
414 		u_int8_t head_load_del; /* Head load delay */
415 		u_int8_t head_uload_del;/* Head un-load delay */
416 		u_int8_t pin32_pin2;
417 		u_int8_t pin4_pint1;
418 		u_int8_t medium_rot_rate_1; /* medium rotation rate (RPM) (MSB) */
419 		u_int8_t medium_rot_rate_0; /* medium rotation rate (RPM) (LSB) */
420 		u_int8_t reserved30;
421 		u_int8_t reserved31;
422     	} flexible_disk;
423 };
424 
425 /*
426  * XXX KDM
427  * Here for CTL compatibility, reconcile this.
428  */
429 struct scsi_format_page {
430 	uint8_t page_code;
431 	uint8_t page_length;
432 	uint8_t tracks_per_zone[2];
433 	uint8_t alt_sectors_per_zone[2];
434 	uint8_t alt_tracks_per_zone[2];
435 	uint8_t alt_tracks_per_lun[2];
436 	uint8_t sectors_per_track[2];
437 	uint8_t bytes_per_sector[2];
438 	uint8_t interleave[2];
439 	uint8_t track_skew[2];
440 	uint8_t cylinder_skew[2];
441 	uint8_t flags;
442 #define	SFP_SSEC	0x80
443 #define	SFP_HSEC	0x40
444 #define	SFP_RMB		0x20
445 #define	SFP_SURF	0x10
446 	uint8_t reserved[3];
447 };
448 
449 /*
450  * XXX KDM
451  * Here for CTL compatibility, reconcile this.
452  */
453 struct scsi_rigid_disk_page {
454 	uint8_t page_code;
455 #define	SMS_RIGID_DISK_PAGE		0x04
456 	uint8_t page_length;
457 	uint8_t cylinders[3];
458 	uint8_t heads;
459 	uint8_t start_write_precomp[3];
460 	uint8_t start_reduced_current[3];
461 	uint8_t step_rate[2];
462 	uint8_t landing_zone_cylinder[3];
463 	uint8_t rpl;
464 #define	SRDP_RPL_DISABLED	0x00
465 #define	SRDP_RPL_SLAVE		0x01
466 #define	SRDP_RPL_MASTER		0x02
467 #define	SRDP_RPL_MASTER_CONTROL	0x03
468 	uint8_t rotational_offset;
469 	uint8_t reserved1;
470 	uint8_t rotation_rate[2];
471 	uint8_t reserved2[2];
472 };
473 
474 
475 struct scsi_da_rw_recovery_page {
476 	u_int8_t page_code;
477 #define SMS_RW_ERROR_RECOVERY_PAGE	0x01
478 	u_int8_t page_length;
479 	u_int8_t byte3;
480 #define SMS_RWER_AWRE			0x80
481 #define SMS_RWER_ARRE			0x40
482 #define SMS_RWER_TB			0x20
483 #define SMS_RWER_RC			0x10
484 #define SMS_RWER_EER			0x08
485 #define SMS_RWER_PER			0x04
486 #define SMS_RWER_DTE			0x02
487 #define SMS_RWER_DCR			0x01
488 	u_int8_t read_retry_count;
489 	u_int8_t correction_span;
490 	u_int8_t head_offset_count;
491 	u_int8_t data_strobe_offset_cnt;
492 	u_int8_t reserved;
493 	u_int8_t write_retry_count;
494 	u_int8_t reserved2;
495 	u_int8_t recovery_time_limit[2];
496 };
497 
498 __BEGIN_DECLS
499 /*
500  * XXX This is only left out of the kernel build to silence warnings.  If,
501  * for some reason this function is used in the kernel, the ifdefs should
502  * be moved so it is included both in the kernel and userland.
503  */
504 #ifndef _KERNEL
505 void scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
506 		      void (*cbfcnp)(struct cam_periph *, union ccb *),
507 		      u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
508 		      u_int8_t *data_ptr, u_int32_t dxfer_len,
509 		      u_int8_t sense_len, u_int32_t timeout);
510 
511 #endif /* !_KERNEL */
512 __END_DECLS
513 
514 #endif /* _SCSI_SCSI_DA_H */
515