2006-10-30 05:32:33 +00:00
|
|
|
/* -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 8; -*- */
|
|
|
|
|
|
|
|
/* scsi block commands */
|
|
|
|
|
2010-02-14 08:45:14 +00:00
|
|
|
/* Copyright (c) 2004 - 2006 Derek Foreman, Ben Jansens
|
|
|
|
Copyright (c) 2006 - 2010 Thomas Schmitt <scdbackup@gmx.net>
|
|
|
|
Provided under GPL version 2 or later.
|
|
|
|
*/
|
|
|
|
|
2010-05-16 09:07:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
2010-02-14 08:45:14 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
#include <string.h>
|
2007-03-15 19:50:57 +00:00
|
|
|
#include <unistd.h>
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
#include "transport.h"
|
|
|
|
#include "sbc.h"
|
2007-03-15 19:50:57 +00:00
|
|
|
#include "spc.h"
|
2006-10-30 05:32:33 +00:00
|
|
|
#include "options.h"
|
|
|
|
|
2007-09-12 10:45:34 +00:00
|
|
|
|
|
|
|
/* ts A70910
|
|
|
|
debug: for tracing calls which might use open drive fds
|
|
|
|
or for catching SCSI usage of emulated drives. */
|
|
|
|
int mmc_function_spy(struct burn_drive *d, char * text);
|
|
|
|
|
|
|
|
|
2009-11-30 10:00:34 +00:00
|
|
|
/* START STOP UNIT as of SBC-1 and SBC-2
|
|
|
|
0: Opcode 0x1B
|
|
|
|
1: bit0= Immed
|
|
|
|
bit1-7= reserved
|
|
|
|
2: reserved
|
|
|
|
3: reserved
|
|
|
|
4: bit0= Start (else Stop unit)
|
|
|
|
bit1= Load/Eject (according to Start resp. Stop)
|
|
|
|
bit2-3= reserved
|
|
|
|
bit4-7= Power Condition
|
|
|
|
0= Start Valid: process Start and Load/Eject bits
|
|
|
|
1= assume Active state
|
|
|
|
2= assume Idle state
|
|
|
|
3= assume Stanby state
|
|
|
|
(5= SBC-1 only: assume Sleep state)
|
|
|
|
7= transfer control of power conditions to logical unit
|
|
|
|
10= force idle condition timer to 0
|
|
|
|
11= force standby condition timer to 0
|
|
|
|
All others are reserved.
|
|
|
|
5: Control (set to 0)
|
|
|
|
*/
|
2007-05-21 18:57:09 +00:00
|
|
|
static unsigned char SBC_LOAD[] = { 0x1b, 0, 0, 0, 3, 0 };
|
|
|
|
static unsigned char SBC_UNLOAD[] = { 0x1b, 0, 0, 0, 2, 0 };
|
|
|
|
static unsigned char SBC_START_UNIT[] = { 0x1b, 0, 0, 0, 1, 0 };
|
2009-08-24 13:10:53 +00:00
|
|
|
static unsigned char SBC_STOP_UNIT[] = { 0x1b, 0, 0, 0, 0, 0 };
|
2006-10-30 05:32:33 +00:00
|
|
|
|
|
|
|
void sbc_load(struct burn_drive *d)
|
|
|
|
{
|
2011-06-07 14:40:31 +00:00
|
|
|
struct command *c;
|
2006-10-30 05:32:33 +00:00
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
c = &(d->casual_command);
|
2007-09-12 10:45:34 +00:00
|
|
|
if (mmc_function_spy(d, "load") <= 0)
|
|
|
|
return;
|
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
scsi_init_command(c, SBC_LOAD, sizeof(SBC_LOAD));
|
|
|
|
c->retry = 1;
|
2007-09-18 20:03:20 +00:00
|
|
|
|
2007-09-21 12:04:27 +00:00
|
|
|
/* ts A70921 : Had to revoke Immed because of LG GSA-4082B */
|
2011-06-07 14:40:31 +00:00
|
|
|
/* c->opcode[1] |= 1; / * ts A70918 : Immed */
|
2007-09-18 20:03:20 +00:00
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
c->dir = NO_TRANSFER;
|
2011-11-30 08:11:52 +00:00
|
|
|
c->timeout = Libburn_mmc_load_timeouT;
|
2011-06-07 14:40:31 +00:00
|
|
|
d->issue_command(d, c);
|
|
|
|
if (c->error)
|
2007-09-18 20:03:20 +00:00
|
|
|
return;
|
2007-09-23 16:35:44 +00:00
|
|
|
/* ts A70923 : Needed regardless of Immed bit. Was once 1 minute, now
|
2007-09-18 20:15:25 +00:00
|
|
|
5 minutes for loading. If this does not suffice then other commands
|
2007-09-18 20:03:20 +00:00
|
|
|
shall fail righteously. */
|
2007-09-23 16:35:44 +00:00
|
|
|
spc_wait_unit_attention(d, 300, "waiting after START UNIT (+ LOAD)",0);
|
2006-10-30 05:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sbc_eject(struct burn_drive *d)
|
|
|
|
{
|
2011-06-07 14:40:31 +00:00
|
|
|
struct command *c;
|
2006-10-30 05:32:33 +00:00
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
c = &(d->casual_command);
|
2007-09-12 10:45:34 +00:00
|
|
|
if (mmc_function_spy(d, "eject") <= 0)
|
|
|
|
return;
|
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
scsi_init_command(c, SBC_UNLOAD, sizeof(SBC_UNLOAD));
|
|
|
|
/* c->opcode[1] |= 1; / * ts A70918 : Immed , ts B00109 : revoked */
|
|
|
|
c->page = NULL;
|
|
|
|
c->dir = NO_TRANSFER;
|
|
|
|
d->issue_command(d, c);
|
2010-01-09 14:32:51 +00:00
|
|
|
/* ts A70918 : Wait long. A late eject could surprise or hurt user.
|
|
|
|
ts B00109 : Asynchronous eject revoked, as one cannot reliably
|
|
|
|
distinguish out from unready.
|
2011-06-07 14:40:31 +00:00
|
|
|
if (c->error)
|
2007-09-18 20:03:20 +00:00
|
|
|
return;
|
|
|
|
spc_wait_unit_attention(d, 1800, "STOP UNIT (+ EJECT)", 0);
|
2010-01-09 14:32:51 +00:00
|
|
|
*/
|
2006-10-30 05:32:33 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 17:56:18 +00:00
|
|
|
|
|
|
|
/* ts A91112 : Now with flag */
|
|
|
|
/* @param flag bit0= asynchronous waiting
|
|
|
|
*/
|
|
|
|
int sbc_start_unit_flag(struct burn_drive *d, int flag)
|
2006-11-18 19:49:18 +00:00
|
|
|
{
|
2011-06-07 14:40:31 +00:00
|
|
|
struct command *c;
|
2009-08-24 20:24:39 +00:00
|
|
|
int ret;
|
2006-11-18 19:49:18 +00:00
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
c = &(d->casual_command);
|
2007-09-12 10:45:34 +00:00
|
|
|
if (mmc_function_spy(d, "start_unit") <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
scsi_init_command(c, SBC_START_UNIT, sizeof(SBC_START_UNIT));
|
|
|
|
c->retry = 1;
|
|
|
|
c->opcode[1] |= (flag & 1); /* ts A70918 : Immed */
|
|
|
|
c->dir = NO_TRANSFER;
|
|
|
|
d->issue_command(d, c);
|
|
|
|
if (c->error)
|
2007-09-18 20:03:20 +00:00
|
|
|
return 0;
|
2009-11-12 17:56:18 +00:00
|
|
|
if (!(flag & 1))
|
|
|
|
return 1;
|
|
|
|
/* ts A70918 : asynchronous */
|
2009-08-24 20:24:39 +00:00
|
|
|
ret = spc_wait_unit_attention(d, 1800, "START UNIT", 0);
|
|
|
|
return ret;
|
2006-11-18 19:49:18 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 17:56:18 +00:00
|
|
|
|
|
|
|
int sbc_start_unit(struct burn_drive *d)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
d->is_stopped = 0; /* no endless starting attempts */
|
|
|
|
|
|
|
|
/* Asynchronous, not to block controller by waiting */
|
|
|
|
ret = sbc_start_unit_flag(d, 1);
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret;
|
2009-11-30 10:00:34 +00:00
|
|
|
/* Synchronous to catch Pioneer DVR-216D which is ready too early.
|
2009-11-12 17:56:18 +00:00
|
|
|
A pending START UNIT can prevent ejecting of the tray.
|
|
|
|
*/
|
|
|
|
ret = sbc_start_unit_flag(d, 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-24 13:10:53 +00:00
|
|
|
/* ts A90824 : Trying to reduce drive noise */
|
|
|
|
int sbc_stop_unit(struct burn_drive *d)
|
|
|
|
{
|
2011-06-07 14:40:31 +00:00
|
|
|
struct command *c;
|
2009-08-24 20:24:39 +00:00
|
|
|
int ret;
|
2009-08-24 13:10:53 +00:00
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
c = &(d->casual_command);
|
2009-08-24 13:10:53 +00:00
|
|
|
if (mmc_function_spy(d, "stop_unit") <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-07 14:40:31 +00:00
|
|
|
scsi_init_command(c, SBC_STOP_UNIT, sizeof(SBC_STOP_UNIT));
|
|
|
|
c->retry = 0;
|
|
|
|
c->opcode[1] |= 1; /* Immed */
|
|
|
|
c->dir = NO_TRANSFER;
|
|
|
|
d->issue_command(d, c);
|
|
|
|
if (c->error)
|
2009-08-24 13:10:53 +00:00
|
|
|
return 0;
|
2009-08-24 20:24:39 +00:00
|
|
|
ret = spc_wait_unit_attention(d, 1800, "STOP UNIT", 0);
|
|
|
|
d->is_stopped = 1;
|
|
|
|
return ret;
|
2009-08-24 13:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-18 19:49:18 +00:00
|
|
|
|
2006-10-30 05:32:33 +00:00
|
|
|
/* ts A61021 : the sbc specific part of sg.c:enumerate_common()
|
|
|
|
*/
|
|
|
|
int sbc_setup_drive(struct burn_drive *d)
|
|
|
|
{
|
|
|
|
d->eject = sbc_eject;
|
|
|
|
d->load = sbc_load;
|
2006-11-18 19:49:18 +00:00
|
|
|
d->start_unit = sbc_start_unit;
|
2009-08-24 13:10:53 +00:00
|
|
|
d->stop_unit = sbc_stop_unit;
|
2009-08-24 20:24:39 +00:00
|
|
|
d->is_stopped = 0;
|
2006-10-30 05:32:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|