xref: /titanic_50/usr/src/cmd/cdrw/mmc.h (revision e98fafb9956429b59c817d4fbd27720c73879203)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_MMC_H
27 #define	_MMC_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /* bytelengths for some SCSI data structures */
36 #define	SENSE_DATA_SIZE		16
37 #define	TRACK_INFO_SIZE		36
38 #define	DISC_INFO_BLOCK_SIZE	32
39 #define	INQUIRY_DATA_LENGTH	96
40 #define	GET_PERF_DATA_LEN	24
41 #define	SET_STREAM_DATA_LEN	28
42 
43 #define	DEFAULT_SCSI_TIMEOUT    60
44 
45 #define	MMC_FTR_HDR_LEN		8	/* byte len of Feature Header */
46 /*
47  * byte length of the static part of a Feature Descriptor
48  */
49 #define	MMC_FTR_DSCRPTR_BASE_LEN	4
50 #define	MMC_PRFL_DSCRPTR_LEN	4	/* byte len of Profile Descriptor */
51 /*
52  * MMC Features; can be added to over time
53  */
54 #define	MMC_FTR_PRFL_LIST	0x0000	/* Profile List Feature */
55 #define	MMC_FTR_CORE		0x0001	/* Core Feature */
56 #define	MMC_FTR_MORPHING	0x0002	/* Morphing Feature */
57 #define	MMC_FTR_REM_MED		0x0003	/* Removable Medium Feature */
58 #define	MMC_FTR_WR_PROTECT	0x0004	/* Write Protect Feature */
59 #define	MMC_FTR_RAND_READ	0x0010	/* Random Readable Feature */
60 #define	MMC_FTR_MULTI_READ	0x001D	/* Multi-Read Feature */
61 #define	MMC_FTR_CD_READ		0x001E	/* CD Read Feature */
62 #define	MMC_FTR_DVD_READ	0x001F	/* DVD Read Feature */
63 #define	MMC_FTR_RAND_WR		0x0020	/* Random Writable Feature */
64 #define	MMC_FTR_INC_STR_WR	0x0021	/* Incremental Streaming Writable */
65 #define	MMC_FTR_SCTR_ERSBL	0x0022	/* Sector Erasable Feature */
66 #define	MMC_FTR_FORMATTABLE	0x0023	/* Formattable Feature */
67 #define	MMC_FTR_DFCT_MNGMNT	0x0024	/* Hardware Defect Management Feature */
68 #define	MMC_FTR_RT_STREAM	0x0107	/* Real Time Streaming Feature */
69 
70 /* Constants for READ TOC/PMA/ATIP command */
71 #define	FORMAT_FORMATTED_TOC	0
72 #define	FORMAT_MULTISESS_INFO	1
73 #define	FORMAT_RAW_TOC		2
74 
75 /* size in bytes of raw TOC Data Length field */
76 #define	RTOC_DATA_LEN_SZ	2
77 
78 /* Point field values for Raw TOC Track Descriptor */
79 #define	POINT_SESS_FIRST_TRK	0xA0	/* 1st track in session */
80 #define	POINT_SESS_LAST_TRK	0xA1	/* Last track in session */
81 #define	POINT_LEADOUT_ADDR	0xA2	/* Starting leadout address */
82 
83 /* Q Sub-channel constants */
84 #define	Q_MODE_1		1	/* Mode-1 Q */
85 #define	Q_MODE_2		2	/* Mode-2 Q */
86 
87 /* Convert Minute,Second,Frame address into Logical Block Address */
88 #define	MSF2LBA(m, s, f)	(((m) * 60 + (s)) * 75 + (f) - 150)
89 
90 /*
91  * MMC Response Data structures.  Use the read_scsi[16,32] and load_scsi[16,32]
92  * routines when reading/writing fields > 1 byte in size.
93  */
94 /*
95  * Structures for the Raw TOC Response Format of the READ TOC/PMA/ATIP
96  * command.
97  */
98 typedef struct rtoc_hdr {	/* Raw TOC response format Header */
99 	uchar_t rh_data_len1;
100 	uchar_t rh_data_len0;
101 	uchar_t rh_first_sess_num;
102 	uchar_t rh_last_sess_num;
103 } rtoc_hdr_t;
104 
105 typedef struct rtoc_td {	/* Raw TOC response format Track Descriptor */
106 	uchar_t rt_session_num;
107 #if defined(_BIT_FIELDS_LTOH)
108 	uchar_t	rt_control	: 4;
109 	uchar_t rt_adr		: 4;
110 #elif defined(_BIT_FIELDS_HTOL)
111 	uchar_t rt_adr		: 4;
112 	uchar_t rt_control	: 4;
113 #else
114 #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
115 #endif	/* _BIT_FIELDS_LTOH */
116 
117 	uchar_t rt_tno;
118 	uchar_t rt_point;
119 	uchar_t rt_min;
120 	uchar_t rt_sec;
121 	uchar_t rt_frame;
122 	uchar_t rt_zero;
123 	uchar_t	rt_pmin;
124 	uchar_t rt_psec;
125 	uchar_t rt_pframe;
126 } rtoc_td_t;
127 
128 int test_unit_ready(int fd);
129 int inquiry(int fd, uchar_t *inq);
130 int read_capacity(int fd, uchar_t *capbuf);
131 int read_track_info(int fd, int trackno, uchar_t *ti);
132 int mode_sense(int fd, uchar_t pc, int dbd, int page_len, uchar_t *buffer);
133 int mode_select(int fd, int page_len, uchar_t *buffer);
134 int read_toc(int fd, int format, int trackno, int buflen, uchar_t *buf);
135 int read_disc_info(int fd, uchar_t *di);
136 int get_configuration(int fd, uint16_t feature, int bufsize, uchar_t *buf);
137 int read10(int fd, uint32_t start_blk, uint16_t nblk, uchar_t *buf,
138     uint32_t bufsize);
139 int write10(int fd, uint32_t start_blk, uint16_t nblk, uchar_t *buf,
140     uint32_t bufsize);
141 int close_track(int fd, int trackno, int close_session, int immediate);
142 int blank_disc(int fd, int type, int immediate);
143 int read_cd(int fd, uint32_t start_blk, uint16_t nblk, uchar_t sector_type,
144     uchar_t *buf, uint32_t bufsize);
145 int load_unload(int fd, int load);
146 int prevent_allow_mr(int fd, int op);
147 int read_header(int fd, uint32_t lba, uchar_t *buf);
148 int set_cd_speed(int fd, uint16_t read_speed, uint16_t write_speed);
149 int get_performance(int fd, int get_write_performance, uchar_t *perf);
150 int set_streaming(int fd, uchar_t *buf);
151 int rezero_unit(int fd);
152 int start_stop(int fd, int start);
153 int flush_cache(int fd);
154 int set_reservation(int fd, ulong_t size);
155 int format_media(int fd);
156 uint32_t read_format_capacity(int fd, uint_t *bsize);
157 void reset_dev(int fd);
158 
159 int uscsi_error;		/* used for debugging failed uscsi */
160 
161 #define	REZERO_UNIT_CMD 	0x01
162 #define	FORMAT_UNIT_CMD		0x04
163 #define	INQUIRY_CMD		0x12
164 #define	MODE_SELECT_6_CMD	0x15
165 #define	MODE_SENSE_6_CMD	0x1A
166 #define	START_STOP_CMD		0x1B
167 #define	PREVENT_ALLOW_CMD	0x1E
168 #define	READ_FORMAT_CAP_CMD	0x23
169 #define	READ_CAP_CMD		0x25
170 #define	READ_10_CMD		0x28
171 #define	WRITE_10_CMD		0x2A
172 #define	SYNC_CACHE_CMD		0x35
173 #define	READ_TOC_CMD		0x43
174 #define	MODE_SELECT_10_CMD	0x55
175 #define	MODE_SENSE_10_CMD	0x5A
176 #define	READ_HDR_CMD		0x44
177 #define	GET_CONFIG_CMD		0x46
178 
179 #define	READ_INFO_CMD		0x51
180 #define	READ_TRACK_CMD		0x52
181 #define	SET_RESERVATION_CMD	0x53
182 #define	CLOSE_TRACK_CMD		0x5B
183 
184 #define	BLANK_CMD		0xA1
185 #define	GET_PERFORMANCE_CMD	0xAC
186 #define	READ_DVD_STRUCTURE	0xAD
187 #define	READ_CD_CMD		0xBE
188 #define	SET_CD_SPEED		0xBB
189 
190 #define	STREAM_CMD		0xB6
191 #define	READ_AUDIO_CMD		0xD8
192 
193 #ifdef	__cplusplus
194 }
195 #endif
196 
197 #endif /* _MMC_H */
198