xref: /illumos-gate/usr/src/cmd/cdrw/misc_scsi.h (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57d7a4f21Szk  * Common Development and Distribution License (the "License").
67d7a4f21Szk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*4d218355Szk  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_MISC_SCSI_H
277c478bd9Sstevel@tonic-gate #define	_MISC_SCSI_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include "device.h"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate struct track_info {
367c478bd9Sstevel@tonic-gate 	uint32_t ti_flags;		/* flags, see below */
377c478bd9Sstevel@tonic-gate 	int ti_track_no;		/* Track number */
387c478bd9Sstevel@tonic-gate 	int ti_session_no;		/* session no. 0 if cannot find that */
397c478bd9Sstevel@tonic-gate 	uchar_t ti_track_mode;		/* track ctrl nibble, see READ TOC */
407c478bd9Sstevel@tonic-gate 	uchar_t ti_data_mode;		/* Mode 0,1,2 or FF */
417c478bd9Sstevel@tonic-gate 	uint32_t ti_start_address;	/* Start LBA */
427c478bd9Sstevel@tonic-gate 	uint32_t ti_track_size;		/* Size in blocks */
437c478bd9Sstevel@tonic-gate 	uint32_t ti_packet_size;	/* If a packet written track */
447c478bd9Sstevel@tonic-gate 	uint32_t ti_free_blocks;	/* For an incomplete track */
457c478bd9Sstevel@tonic-gate 	uint32_t ti_lra;		/* LBA of Last written user datablock */
467c478bd9Sstevel@tonic-gate 	uint32_t ti_nwa;		/* Next writable address */
477c478bd9Sstevel@tonic-gate };
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * track_info_flags
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	TI_FIXED_PACKET		1
537c478bd9Sstevel@tonic-gate #define	TI_PACKET_MODE		2
547c478bd9Sstevel@tonic-gate #define	TI_BLANK_TRACK		4
557c478bd9Sstevel@tonic-gate #define	TI_RESERVED_TRACK	8
567c478bd9Sstevel@tonic-gate #define	TI_COPY			0x10
577c478bd9Sstevel@tonic-gate #define	TI_DAMAGED_TRACK	0x20
587c478bd9Sstevel@tonic-gate #define	TI_NWA_VALID		0x100
597c478bd9Sstevel@tonic-gate #define	TI_LRA_VALID		0x200
607c478bd9Sstevel@tonic-gate #define	TI_SESSION_NO_VALID	0x1000
617c478bd9Sstevel@tonic-gate #define	TI_FREE_BLOCKS_VALID	0x2000
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * Track mode nibble
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate #define	TRACK_MODE_DATA		0x06
677c478bd9Sstevel@tonic-gate #define	TRACK_MODE_AUDIO	0x02
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /* 74 minutes, each second is 75 blocks */
707c478bd9Sstevel@tonic-gate #define	MAX_CD_BLKS		(74*60*75)
717c478bd9Sstevel@tonic-gate #define	MAX_DVD_BLKS		2295100
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
7498584592Sarutz  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
7598584592Sarutz  * for CDs.  Eg, "1X == 176,400 bytes/second".
7698584592Sarutz  *
777c478bd9Sstevel@tonic-gate  * Some devices just multiply speed by 176. But more accurate ones
787c478bd9Sstevel@tonic-gate  * multiply speed by 176.4.
797c478bd9Sstevel@tonic-gate  */
807d7a4f21Szk #define	CD_RATE_TO_X(r) ((r) % 176 ? ((uint_t)(((double)(r)*10)/1764 + 0.5)) :\
817d7a4f21Szk 		(r) / 176)
8298584592Sarutz #define	CD_X_TO_RATE(s)	((((s)*1764)+5)/10)
8398584592Sarutz 
8498584592Sarutz /*
8598584592Sarutz  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
8698584592Sarutz  * for DVDs. Eg, "1X == 1,385,000 bytes/second".
8798584592Sarutz  */
8898584592Sarutz #define	DVD_RATE_TO_X(r)	(((ulong_t)(r)*1000)/1385000)
8998584592Sarutz #define	DVD_X_TO_RATE(s)	(((s)*1385000)/1000)
9098584592Sarutz 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	FINALIZE_TIMEOUT		(6 * 12)	/* Six minutes */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate uint32_t read_scsi32(void *addr);
957c478bd9Sstevel@tonic-gate uint16_t read_scsi16(void *addr);
967c478bd9Sstevel@tonic-gate void load_scsi32(void *addr, uint32_t val);
977c478bd9Sstevel@tonic-gate void load_scsi16(void *addr, uint16_t val);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate int get_mode_page(int fd, int page_no, int pc, int buf_len, uchar_t *buffer);
1007c478bd9Sstevel@tonic-gate int set_mode_page(int fd, uchar_t *buffer);
1017c478bd9Sstevel@tonic-gate int build_track_info(cd_device *dev, int trackno, struct track_info *t_info);
1027c478bd9Sstevel@tonic-gate uchar_t get_data_mode(int fd, uint32_t lba);
1037c478bd9Sstevel@tonic-gate int prepare_for_write(cd_device *dev, int track_mode, int test_write,
1047c478bd9Sstevel@tonic-gate     int keep_disc_open);
1057c478bd9Sstevel@tonic-gate int finalize(cd_device *dev);
106*4d218355Szk uint32_t get_last_possible_lba(cd_device *dev);
1077c478bd9Sstevel@tonic-gate int read_audio_through_read_cd(cd_device *dev, uint_t start_lba, uint_t nblks,
1087c478bd9Sstevel@tonic-gate     uchar_t *buf);
1097c478bd9Sstevel@tonic-gate int eject_media(cd_device *dev);
1107c478bd9Sstevel@tonic-gate int cd_speed_ctrl(cd_device *dev, int cmd, int speed);
1117c478bd9Sstevel@tonic-gate int rt_streaming_ctrl(cd_device *dev, int cmd, int speed);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate void tao_init(int mode);
1147c478bd9Sstevel@tonic-gate void tao_fini(void);
1157c478bd9Sstevel@tonic-gate void write_init(int mode);
1167c478bd9Sstevel@tonic-gate void write_fini(void);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate #endif
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #endif /* _MISC_SCSI_H */
123