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