xref: /illumos-gate/usr/src/cmd/cdrw/misc_scsi.h (revision 80ab886d233f514d54c2a6bdeb9fdfd951bd6881)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_MISC_SCSI_H
28 #define	_MISC_SCSI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include "device.h"
37 
38 struct track_info {
39 	uint32_t ti_flags;		/* flags, see below */
40 	int ti_track_no;		/* Track number */
41 	int ti_session_no;		/* session no. 0 if cannot find that */
42 	uchar_t ti_track_mode;		/* track ctrl nibble, see READ TOC */
43 	uchar_t ti_data_mode;		/* Mode 0,1,2 or FF */
44 	uint32_t ti_start_address;	/* Start LBA */
45 	uint32_t ti_track_size;		/* Size in blocks */
46 	uint32_t ti_packet_size;	/* If a packet written track */
47 	uint32_t ti_free_blocks;	/* For an incomplete track */
48 	uint32_t ti_lra;		/* LBA of Last written user datablock */
49 	uint32_t ti_nwa;		/* Next writable address */
50 };
51 
52 /*
53  * track_info_flags
54  */
55 #define	TI_FIXED_PACKET		1
56 #define	TI_PACKET_MODE		2
57 #define	TI_BLANK_TRACK		4
58 #define	TI_RESERVED_TRACK	8
59 #define	TI_COPY			0x10
60 #define	TI_DAMAGED_TRACK	0x20
61 #define	TI_NWA_VALID		0x100
62 #define	TI_LRA_VALID		0x200
63 #define	TI_SESSION_NO_VALID	0x1000
64 #define	TI_FREE_BLOCKS_VALID	0x2000
65 
66 /*
67  * Track mode nibble
68  */
69 #define	TRACK_MODE_DATA		0x06
70 #define	TRACK_MODE_AUDIO	0x02
71 
72 /* 74 minutes, each second is 75 blocks */
73 #define	MAX_CD_BLKS		(74*60*75)
74 #define	MAX_DVD_BLKS		2295100
75 
76 /*
77  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
78  * for CDs.  Eg, "1X == 176,400 bytes/second".
79  *
80  * Some devices just multiply speed by 176. But more accurate ones
81  * multiply speed by 176.4.
82  */
83 #define	CD_RATE_TO_X(r)	((r) % 176 ? ((((r)*10)+5)/1764) : (r) / 176)
84 #define	CD_X_TO_RATE(s)	((((s)*1764)+5)/10)
85 
86 /*
87  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
88  * for DVDs. Eg, "1X == 1,385,000 bytes/second".
89  */
90 #define	DVD_RATE_TO_X(r)	(((ulong_t)(r)*1000)/1385000)
91 #define	DVD_X_TO_RATE(s)	(((s)*1385000)/1000)
92 
93 
94 #define	FINALIZE_TIMEOUT		(6 * 12)	/* Six minutes */
95 
96 uint32_t read_scsi32(void *addr);
97 uint16_t read_scsi16(void *addr);
98 void load_scsi32(void *addr, uint32_t val);
99 void load_scsi16(void *addr, uint16_t val);
100 
101 int get_mode_page(int fd, int page_no, int pc, int buf_len, uchar_t *buffer);
102 int set_mode_page(int fd, uchar_t *buffer);
103 int build_track_info(cd_device *dev, int trackno, struct track_info *t_info);
104 uchar_t get_data_mode(int fd, uint32_t lba);
105 int prepare_for_write(cd_device *dev, int track_mode, int test_write,
106     int keep_disc_open);
107 int finalize(cd_device *dev);
108 int get_last_possible_lba(cd_device *dev);
109 int read_audio_through_read_cd(cd_device *dev, uint_t start_lba, uint_t nblks,
110     uchar_t *buf);
111 int eject_media(cd_device *dev);
112 int cd_speed_ctrl(cd_device *dev, int cmd, int speed);
113 int rt_streaming_ctrl(cd_device *dev, int cmd, int speed);
114 
115 void tao_init(int mode);
116 void tao_fini(void);
117 void write_init(int mode);
118 void write_fini(void);
119 
120 #ifdef	__cplusplus
121 }
122 #endif
123 
124 #endif /* _MISC_SCSI_H */
125