xref: /illumos-gate/usr/src/cmd/cdrw/misc_scsi.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
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	_MISC_SCSI_H
27 #define	_MISC_SCSI_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include "device.h"
34 
35 struct track_info {
36 	uint32_t ti_flags;		/* flags, see below */
37 	int ti_track_no;		/* Track number */
38 	int ti_session_no;		/* session no. 0 if cannot find that */
39 	uchar_t ti_track_mode;		/* track ctrl nibble, see READ TOC */
40 	uchar_t ti_data_mode;		/* Mode 0,1,2 or FF */
41 	uint32_t ti_start_address;	/* Start LBA */
42 	uint32_t ti_track_size;		/* Size in blocks */
43 	uint32_t ti_packet_size;	/* If a packet written track */
44 	uint32_t ti_free_blocks;	/* For an incomplete track */
45 	uint32_t ti_lra;		/* LBA of Last written user datablock */
46 	uint32_t ti_nwa;		/* Next writable address */
47 };
48 
49 /*
50  * track_info_flags
51  */
52 #define	TI_FIXED_PACKET		1
53 #define	TI_PACKET_MODE		2
54 #define	TI_BLANK_TRACK		4
55 #define	TI_RESERVED_TRACK	8
56 #define	TI_COPY			0x10
57 #define	TI_DAMAGED_TRACK	0x20
58 #define	TI_NWA_VALID		0x100
59 #define	TI_LRA_VALID		0x200
60 #define	TI_SESSION_NO_VALID	0x1000
61 #define	TI_FREE_BLOCKS_VALID	0x2000
62 
63 /*
64  * Track mode nibble
65  */
66 #define	TRACK_MODE_DATA		0x06
67 #define	TRACK_MODE_AUDIO	0x02
68 
69 /* 74 minutes, each second is 75 blocks */
70 #define	MAX_CD_BLKS		(74*60*75)
71 #define	MAX_DVD_BLKS		2295100
72 
73 /*
74  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
75  * for CDs.  Eg, "1X == 176,400 bytes/second".
76  *
77  * Some devices just multiply speed by 176. But more accurate ones
78  * multiply speed by 176.4.
79  */
80 #define	CD_RATE_TO_X(r) ((r) % 176 ? ((uint_t)(((double)(r)*10)/1764 + 0.5)) :\
81 		(r) / 176)
82 #define	CD_X_TO_RATE(s)	((((s)*1764)+5)/10)
83 
84 /*
85  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
86  * for DVDs. Eg, "1X == 1,385,000 bytes/second".
87  */
88 #define	DVD_RATE_TO_X(r)	(((ulong_t)(r)*1000)/1385000)
89 #define	DVD_X_TO_RATE(s)	(((s)*1385000)/1000)
90 
91 
92 #define	FINALIZE_TIMEOUT		(6 * 12)	/* Six minutes */
93 
94 uint32_t read_scsi32(void *addr);
95 uint16_t read_scsi16(void *addr);
96 void load_scsi32(void *addr, uint32_t val);
97 void load_scsi16(void *addr, uint16_t val);
98 
99 int get_mode_page(int fd, int page_no, int pc, int buf_len, uchar_t *buffer);
100 int set_mode_page(int fd, uchar_t *buffer);
101 int build_track_info(cd_device *dev, int trackno, struct track_info *t_info);
102 uchar_t get_data_mode(int fd, uint32_t lba);
103 int prepare_for_write(cd_device *dev, int track_mode, int test_write,
104     int keep_disc_open);
105 int finalize(cd_device *dev);
106 uint32_t get_last_possible_lba(cd_device *dev);
107 int read_audio_through_read_cd(cd_device *dev, uint_t start_lba, uint_t nblks,
108     uchar_t *buf);
109 int eject_media(cd_device *dev);
110 int cd_speed_ctrl(cd_device *dev, int cmd, int speed);
111 int rt_streaming_ctrl(cd_device *dev, int cmd, int speed);
112 
113 void tao_init(int mode);
114 void tao_fini(void);
115 void write_init(int mode);
116 void write_fini(void);
117 
118 #ifdef	__cplusplus
119 }
120 #endif
121 
122 #endif /* _MISC_SCSI_H */
123