misc_scsi.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <libintl.h>
#include "mmc.h"
#include "util.h"
#include "misc_scsi.h"
#include "transport.h"
#include "main.h"
#include "toshiba.h"
#include "msgs.h"
read_scsi32(void *addr)
{
return (ret);
}
read_scsi16(void *addr)
{
return (ret);
}
void
{
}
void
{
}
/*
* will get the mode page only i.e. will strip off the header.
*/
int
{
int ret;
/* Ask 254 bytes only to make our IDE driver happy */
if (ret == 0) {
return (0);
}
return (1);
}
/*
* will take care of adding mode header and any extra bytes at the end.
*/
int
{
int ret;
if (debug) {
int i;
(void) printf("MODE: [");
for (i = 0; i < p_len; i++) {
}
(void) printf("]\n");
}
return (ret);
}
/*
* Builds track information database for track trackno. If trackno is
* -1, builds the database for next blank track.
*/
int
{
int ret;
/* 1st try READ TRACK INFORMATION */
/* Gererate faked information for writing to DVD */
if (device_type != CD_RW) {
t_info->ti_start_address = 0;
/* only 1 track on DVD make it max size */
&bsize);
}
t_info->ti_free_blocks = 0;
}
if (debug)
(void) printf("using read_track_info for TOC \n");
else
return (1);
}
/* READ TRACK INFORMATION not supported, try other options */
/*
* We can get info for next blank track if READ TRACK INFO is not
* supported.
*/
if (trackno == -1)
return (0);
if (debug)
(void) printf("using READ_TOC for TOC\n");
/* Try Read TOC */
return (0);
}
/* Numbers for audio tracks are always in 2K chunks */
}
/* Now find out the session thing */
/*
* Make sure that the call succeeds and returns the requested
* TOC size correctly.
*/
/* For ATAPI drives or old Toshiba drives */
}
/* If this goes through well TOC length will always be 0x0a */
}
/*
* This might be the last track of this session. If so,
* exclude the leadout and next lead in.
*/
/*
* 1.5 Min leadout + 1 min. leadin + 2 sec. pre-gap.
* For 2nd+ leadout it will be 0.5 min. But currently
* there is no direct way. And it will not happen
* for any normal case.
*
* ((1.5 +1)*60 + 2)*75 = 11400 frames (blocks)
*/
}
}
return (1);
}
{
int ret;
if (ret == 0)
mode = 0xff;
else
return (mode);
}
/*
* Set page code 5 for TAO mode.
*/
int
int keep_disc_open)
{
int no_err;
int reset_device;
"Multi-session is not supported on DVD media\n"));
exit(1);
}
(void) printf("Preparing to write in DAO\n");
}
/* Some drives do not support this command but still do it */
if (no_err)
/*
* If the device is already in simulation mode and again a
* simulation is requested, then set the device in non-simulation
* 1st and then take it to simulation mode. This will flush any
* previous fake state in the drive.
*/
reset_device = 1;
} else {
reset_device = 0;
}
if (no_err != 0) {
buf[0] &= 0x3f;
/* set TAO or DAO writing mode */
/* set simulation flag */
if (test_write && (!reset_device)) {
} else {
}
/* Turn on HW buffer underrun protection (BUFE) */
if (!test_write) {
}
/* set track mode type */
if (device_type == CD_RW) {
} else {
}
if (keep_disc_open) {
}
/* Select track type (audio or data) */
if (track_mode == TRACK_MODE_DATA) {
} else {
}
/* Need to clear these fields for setting into DAO */
if (write_mode == DAO_MODE)
/* print out mode for detailed log */
int i;
(void) printf("setting = [ ");
for (i = 0; i < 15; i++)
(void) printf("]\n");
}
if (no_err && reset_device) {
/* Turn the test write bit back on */
}
/*
* Since BUFE is the only optional flag we are
* setting we will try to turn it off if the command
* fails.
*/
if (!no_err) {
/*
* Some old drives may not support HW
* buffer underrun protection, try again
* after turning it off.
*/
if (debug)
(void) printf("Turning off BUFE\n");
}
}
return (no_err);
}
/*
* Close session. This will write TOC.
*/
int
{
int immediate;
int finalize_max;
/*
* For ATAPI devices we will use the immediate mode and will
* poll the command for completion so that this command may
* not hog the channel. But for SCSI, we will use the treditional
* way of issuing the command with a large enough timeout. This
* is done because immediate mode was designed for ATAPI and some
* SCSI RW drives might not be even tested with it.
*/
/* SCSI device */
immediate = 0;
} else {
/* non-SCSI (e.g ATAPI) device */
immediate = 1;
}
/* We need to close track before close session */
if (device_type == DVD_PLUS) {
return (0);
}
/*
* For DVD-RW close track is not well defined
* some drives dont like it, others want us
* to close track before closing the session.
* NOTE that for MMC specification it is not mandatory
* to support close track.
*/
if (device_type == DVD_MINUS) {
return (0);
} else {
/* command is already done */
if (!immediate)
return (1);
}
} else {
return (0);
}
} else {
if (!immediate)
return (1);
}
if (immediate) {
(void) sleep(10);
err = 0;
if (device_type == CD_RW) {
/* Finalization should not take more than 6 minutes */
} else {
/* some DVD-RW drives take longer than 6 minutes */
}
if (ret != 0)
break;
if (uscsi_status != 2)
err = 1;
/* not ready but not becoming ready */
err = 1;
/* illegal mode for this track */
err = 1;
} else {
err = 1;
}
if (err == 1) {
if (debug) {
(void) printf("Finalization failed\n");
(void) printf("%x %x %x %x\n",
}
return (0);
}
if (uscsi_status == 2) {
int i;
/* illegal field in command packet */
/* print it out! */
(void) printf("\n");
for (i = 0; i < 18; i++)
(void) printf("%x ",
(unsigned)(rqbuf[i]));
(void) printf("\n");
}
}
(void) sleep(5);
}
}
return (ret);
}
/*
* Find out media capacity.
*/
int
{
int cap;
return (0);
}
} else {
cap = 0;
}
return (cap);
}
int
{
int retry;
int ret;
if (ret)
break;
}
return (ret);
}
int
{
if (vol_running) {
/* If there is a media, try using DKIOCEJECT 1st */
return (1);
}
}
}
/* if eject fails */
/*
* check that eject is not blocked on the device
*/
return (0);
}
return (0);
}
return (1);
}
/*
* Get CD speed from Page code 2A. since GET PERFORMANCE is not supported
* (which is already checked before) this mode page *will* have the speed.
*/
static uint16_t
{
mp2a) == 0) {
rate = 0;
} else {
if (cmd == GET_READ_SPEED) {
} else {
}
}
return (rate);
}
/*
* CD speed related functions (ioctl style) for drives which do not support
* real time streaming.
*/
int
{
if (cmd == SET_READ_SPEED) {
rate));
}
if (cmd == SET_WRITE_SPEED) {
}
return (0);
}
/*
* cd speed related functions for drives which support RT-streaming
*/
int
{
int write_perf;
int ret;
write_perf = 0;
write_perf = 1;
ret = 0;
goto end_rsc;
}
goto end_rsc;
}
if (cmd == SET_WRITE_SPEED) {
} else {
}
/* If rt_speed_ctrl fails for any reason use cd_speed_ctrl */
if (ret == 0) {
if (debug)
(void) printf(" real time speed control"
" failed, using CD speed control\n");
}
return (ret);
}
/*
* Initialize device for track-at-once mode of writing. All of the data will
* need to be written to the track without interruption.
* This initialized TAO by setting page code 5 and speed.
*/
void
write_init(int mode)
{
if (simulation)
print_n_flush("...");
/* DVD- requires DAO mode */
if (device_type == DVD_MINUS) {
}
/* For debug, print out device config information */
if (debug) {
int i;
(void) printf("Drive profile = ");
for (i = 10; i < 70; i += 8)
(void) printf("\n");
}
/* DVD+ and DVD- have no support for AUDIO, bail out */
exit(1);
}
/* l10n_NOTE : 'failed' as in Initializing device...failed */
exit(1);
}
/* l10n_NOTE : 'done' as in "Initializing device...done" */
/* if speed change option was used (-p) then try to set the speed */
if (requested_speed != 0) {
if (verbose)
requested_speed) == 0) {
exit(1);
}
if (verbose) {
int speed;
GET_WRITE_SPEED, 0);
if (speed == requested_speed) {
speed);
} else {
(void) printf(
gettext("Speed set to closest approximation "
"of %dX allowed by device (%dX).\n"),
}
}
}
}
void
write_fini(void)
{
/* Some drives don't like this while in test write mode */
if (!simulation) {
/*
* It is possible that the drive is busy writing the
* buffered portion. So do not get upset yet.
*/
(void) sleep(10);
if (debug) {
(void) printf("status %x, %x/%x/%x\n",
}
if ((device_type == DVD_MINUS) &&
if (verbose) {
(void) printf(
"skipping finalizing\n");
}
} else {
/* l10n_NOTE : 'failed' as in finishing up...failed */
"Could not finalize the disc.\n"));
exit(1);
}
}
}
if (vol_running) {
(void) eject_media(target);
}
/*
* Some drives such as the pioneer A04 will retain a
* ghost TOC after a simulation write is done. The
* media will actually be blank, but the drive will
* report a TOC. There is currently no other way to
* re-initialize the media other than ejecting or
* to ask the drive to clear the leadout. The laser
* is currently off so nothing is written to the
* media (on a good behaving drive).
* NOTE that a device reset does not work to make
* the drive re-initialize the media.
*/
if (!vol_running) {
blanking_type = "clear";
blank();
}
}
/* l10n_NOTE : 'done' as in "Finishing up...done" */
}