>From julian@jules.DIALix.oz.au Fri Sep 10 22:58:30 1993
>Date: Sat, 11 Sep 93 12:59:39 +0800 1/ fix bug where cd0a was unusable because it was compared against the number of 2k blocks not the number of 512byte blocks.. gave an error for all reads past 1/4 way through the disk (cd0d was ok). 2/ fix open code so that it now notices if a disk has been changed and updates the disklabel. 3/ use the new error handling code from st.c 4/ start adding stuff to get ready for using cd_scsi_cmd from cd_start (like is done in st and sd) 5/ more general cleanups including making dmesg report sector size of disk.. (believe it or not SUN drives use 512 byte)
This commit is contained in:
parent
c8f3143ccb
commit
2a9074862d
647
sys/scsi/cd.c
647
sys/scsi/cd.c
@ -14,7 +14,7 @@
|
||||
*
|
||||
* Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
|
||||
*
|
||||
* $Id: cd.c,v 1.8 1993/09/09 07:18:52 rgrimes Exp $
|
||||
* $Id: cd.c,v 1.9 1993/09/20 06:27:02 rgrimes Exp $
|
||||
*/
|
||||
|
||||
#define SPLCD splbio
|
||||
@ -213,7 +213,10 @@ struct scsi_switch *scsi_switch;
|
||||
cd_get_parms(unit, SCSI_NOSLEEP | SCSI_NOMASK);
|
||||
if(dp->disksize)
|
||||
{
|
||||
printf("cd%d: cd present\n", unit);
|
||||
printf("cd%d: cd present.[%d x %d byte records]\n",
|
||||
unit,
|
||||
cd->params.disksize,
|
||||
cd->params.blksize);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -264,16 +267,22 @@ cdopen(dev)
|
||||
if ((! (cd->flags & CDVALID))
|
||||
&& ( cd->openparts))
|
||||
return(ENXIO);
|
||||
|
||||
/*******************************************************\
|
||||
* Check that it is still responding and ok. *
|
||||
* if the media has been changed this will result in a *
|
||||
* "unit attention" error which the error code will *
|
||||
* disregard because the CDVALID flag is not yet set *
|
||||
\*******************************************************/
|
||||
if (cd_req_sense(unit, SCSI_SILENT) != 0) {
|
||||
cd_test_ready(unit, SCSI_SILENT);
|
||||
|
||||
/*******************************************************\
|
||||
* Next time actually take notice of error returns *
|
||||
\*******************************************************/
|
||||
if (cd_test_ready(unit, SCSI_SILENT) != 0) {
|
||||
#ifdef CDDEBUG
|
||||
if(scsi_debug & TRACEOPENS)
|
||||
printf("not reponding\n");
|
||||
printf("not ready\n");
|
||||
#endif /*CDDEBUG*/
|
||||
return(ENXIO);
|
||||
}
|
||||
@ -283,7 +292,7 @@ cdopen(dev)
|
||||
#endif /*CDDEBUG*/
|
||||
/*******************************************************\
|
||||
* In case it is a funny one, tell it to start *
|
||||
* not needed for hard drives *
|
||||
* not needed for some drives *
|
||||
\*******************************************************/
|
||||
cd_start_unit(unit,part,CD_START);
|
||||
cd_prevent_unit(unit,PR_PREVENT,SCSI_SILENT);
|
||||
@ -593,15 +602,20 @@ int unit;
|
||||
/*******************************************************\
|
||||
* We have a buf, now we should move the data into *
|
||||
* a scsi_xfer definition and try start it *
|
||||
\*******************************************************/
|
||||
/*******************************************************\
|
||||
* *
|
||||
* First, translate the block to absolute *
|
||||
* and put it in terms of the logical blocksize of the *
|
||||
* device.. *
|
||||
* really a bit silly until we have real partitions, but.*
|
||||
\*******************************************************/
|
||||
p = cd->disklabel.d_partitions + PARTITION(bp->b_dev);
|
||||
blkno = ((bp->b_blkno / (cd->params.blksize/512)) + p->p_offset);
|
||||
blkno = bp->b_blkno / (cd->params.blksize/512);
|
||||
if(PARTITION(bp->b_dev) != RAW_PART)
|
||||
{
|
||||
p = cd->disklabel.d_partitions + PARTITION(bp->b_dev);
|
||||
blkno += p->p_offset;
|
||||
}
|
||||
nblk = (bp->b_bcount + (cd->params.blksize - 1)) / (cd->params.blksize);
|
||||
/* what if something asks for 512 bytes not on a 2k boundary? *//*XXX*/
|
||||
|
||||
/*******************************************************\
|
||||
* Fill out the scsi command *
|
||||
@ -659,70 +673,71 @@ struct scsi_xfer *xs;
|
||||
{
|
||||
struct buf *bp;
|
||||
int retval;
|
||||
struct cd_data *cd;
|
||||
struct cd_data *cd = cd_driver->cd_data[unit];
|
||||
|
||||
#ifdef CDDEBUG
|
||||
if(scsi_debug & PRINTROUTINES) printf("cd_done%d ",unit);
|
||||
#endif /*CDDEBUG*/
|
||||
cd = cd_driver->cd_data[unit];
|
||||
#ifdef PARANOIA
|
||||
if (! (xs->flags & INUSE)) /* paranoia always pays off */
|
||||
panic("scsi_xfer not in use!");
|
||||
if(bp = xs->bp)
|
||||
{
|
||||
switch(xs->error)
|
||||
{
|
||||
case XS_NOERROR:
|
||||
bp->b_error = 0;
|
||||
bp->b_resid = 0;
|
||||
break;
|
||||
|
||||
case XS_SENSE:
|
||||
retval = (cd_interpret_sense(unit,xs));
|
||||
if(retval)
|
||||
{
|
||||
bp->b_flags |= B_ERROR;
|
||||
bp->b_error = retval;
|
||||
}
|
||||
break;
|
||||
|
||||
case XS_TIMEOUT:
|
||||
printf("cd%d timeout\n",unit);
|
||||
|
||||
case XS_BUSY:
|
||||
/***********************************\
|
||||
* Just resubmit it straight back to *
|
||||
* the SCSI driver to try it again *
|
||||
\***********************************/
|
||||
if(xs->retries--)
|
||||
{
|
||||
xs->error = XS_NOERROR;
|
||||
xs->flags &= ~ITSDONE;
|
||||
if ((*(cd->sc_sw->scsi_cmd))(xs)
|
||||
== SUCCESSFULLY_QUEUED)
|
||||
{ /* shhh! don't wake the job, ok? */
|
||||
/* don't tell cdstart either, */
|
||||
return;
|
||||
}
|
||||
/* xs->error is set by the scsi driver */
|
||||
} /* Fall through */
|
||||
|
||||
case XS_DRIVER_STUFFUP:
|
||||
bp->b_flags |= B_ERROR;
|
||||
bp->b_error = EIO;
|
||||
break;
|
||||
default:
|
||||
printf("cd%d: unknown error category from scsi driver\n"
|
||||
,unit);
|
||||
}
|
||||
biodone(bp);
|
||||
cd_free_xs(unit,xs,0);
|
||||
cdstart(unit); /* If there's anything waiting.. do it */
|
||||
}
|
||||
else /* special has finished */
|
||||
#endif /*PARANOIA*/
|
||||
if(!(bp = xs->bp))
|
||||
{
|
||||
wakeup(xs);
|
||||
return 0;
|
||||
}
|
||||
switch(xs->error)
|
||||
{
|
||||
case XS_NOERROR:
|
||||
bp->b_error = 0;
|
||||
bp->b_resid = 0;
|
||||
break;
|
||||
|
||||
case XS_SENSE:
|
||||
retval = (cd_interpret_sense(unit,xs));
|
||||
if(retval)
|
||||
{
|
||||
bp->b_flags |= B_ERROR;
|
||||
bp->b_error = retval;
|
||||
}
|
||||
break;
|
||||
|
||||
case XS_TIMEOUT:
|
||||
printf("cd%d timeout\n",unit);
|
||||
|
||||
case XS_BUSY:
|
||||
/***********************************\
|
||||
* Just resubmit it straight back to *
|
||||
* the SCSI driver to try it again *
|
||||
\***********************************/
|
||||
if(xs->retries--)
|
||||
{
|
||||
xs->error = XS_NOERROR;
|
||||
xs->flags &= ~ITSDONE;
|
||||
if ((*(cd->sc_sw->scsi_cmd))(xs)
|
||||
== SUCCESSFULLY_QUEUED)
|
||||
{ /* shhh! don't wake the job, ok? */
|
||||
/* don't tell cdstart either, */
|
||||
return 0;
|
||||
}
|
||||
/* xs->error is set by the scsi driver */
|
||||
} /* Fall through */
|
||||
|
||||
case XS_DRIVER_STUFFUP:
|
||||
bp->b_flags |= B_ERROR;
|
||||
bp->b_error = EIO;
|
||||
break;
|
||||
default:
|
||||
printf("cd%d: unknown error category from scsi driver\n"
|
||||
,unit);
|
||||
}
|
||||
biodone(bp);
|
||||
cd_free_xs(unit,xs,0);
|
||||
cdstart(unit); /* If there's anything waiting.. do it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* Perform special action on behalf of the user *
|
||||
* Knows about the internals of this device *
|
||||
@ -1079,7 +1094,8 @@ unsigned char unit;
|
||||
|
||||
cd->disklabel.d_npartitions = 1;
|
||||
cd->disklabel.d_partitions[0].p_offset = 0;
|
||||
cd->disklabel.d_partitions[0].p_size = cd->params.disksize;
|
||||
cd->disklabel.d_partitions[0].p_size
|
||||
= cd->params.disksize * (cd->params.blksize / 512);
|
||||
cd->disklabel.d_partitions[0].p_fstype = 9;
|
||||
|
||||
cd->disklabel.d_magic = DISKMAGIC;
|
||||
@ -1094,6 +1110,28 @@ unsigned char unit;
|
||||
return(ESUCCESS);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* Get scsi driver to send a "are you ready" command *
|
||||
\*******************************************************/
|
||||
cd_test_ready(unit,flags)
|
||||
int unit,flags;
|
||||
{
|
||||
struct scsi_test_unit_ready scsi_cmd;
|
||||
|
||||
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
||||
scsi_cmd.op_code = TEST_UNIT_READY;
|
||||
|
||||
return (cd_scsi_cmd(unit,
|
||||
&scsi_cmd,
|
||||
sizeof(scsi_cmd),
|
||||
0,
|
||||
0,
|
||||
100000,
|
||||
NULL,
|
||||
flags));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************\
|
||||
* Find out form the device what it's capacity is *
|
||||
\*******************************************************/
|
||||
@ -1121,6 +1159,7 @@ cd_size(unit, flags)
|
||||
&rdcap,
|
||||
sizeof(rdcap),
|
||||
2000,
|
||||
NULL,
|
||||
flags) != 0)
|
||||
{
|
||||
printf("cd%d: could not get size\n", unit);
|
||||
@ -1143,31 +1182,6 @@ cd_size(unit, flags)
|
||||
return(size);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* Check with the device that it is ok, (via scsi driver)*
|
||||
\*******************************************************/
|
||||
cd_req_sense(unit, flags)
|
||||
{
|
||||
struct scsi_sense_data sense_data;
|
||||
struct scsi_sense scsi_cmd;
|
||||
|
||||
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
||||
scsi_cmd.op_code = REQUEST_SENSE;
|
||||
scsi_cmd.length = sizeof(sense_data);
|
||||
|
||||
if (cd_scsi_cmd(unit,
|
||||
&scsi_cmd,
|
||||
sizeof(scsi_cmd),
|
||||
&sense_data,
|
||||
sizeof(sense_data),
|
||||
2000,
|
||||
flags) != 0)
|
||||
{
|
||||
return(ENXIO);
|
||||
}
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* Get the requested page into the buffer given *
|
||||
@ -1191,6 +1205,7 @@ int page;
|
||||
data,
|
||||
sizeof(*data),
|
||||
20000, /* should be immed */
|
||||
NULL,
|
||||
0);
|
||||
return (retval);
|
||||
}
|
||||
@ -1215,6 +1230,7 @@ struct cd_mode_data *data;
|
||||
data,
|
||||
sizeof(*data),
|
||||
20000, /* should be immed */
|
||||
NULL,
|
||||
0)
|
||||
);
|
||||
}
|
||||
@ -1241,6 +1257,7 @@ int unit,blk,len;
|
||||
0,
|
||||
0,
|
||||
200000, /* should be immed */
|
||||
NULL,
|
||||
0);
|
||||
return(retval);
|
||||
}
|
||||
@ -1269,6 +1286,7 @@ int unit,blk,len;
|
||||
0,
|
||||
0,
|
||||
20000, /* should be immed */
|
||||
NULL,
|
||||
0);
|
||||
return(retval);
|
||||
}
|
||||
@ -1293,6 +1311,7 @@ int unit,strack,sindex,etrack,eindex;
|
||||
0,
|
||||
0,
|
||||
20000, /* should be immed */
|
||||
NULL,
|
||||
0);
|
||||
return(retval);
|
||||
}
|
||||
@ -1319,6 +1338,7 @@ int unit,startm,starts,startf,endm,ends,endf;
|
||||
0,
|
||||
0,
|
||||
2000,
|
||||
NULL,
|
||||
0));
|
||||
}
|
||||
/*******************************************************\
|
||||
@ -1339,15 +1359,23 @@ int unit,go;
|
||||
0,
|
||||
0,
|
||||
2000,
|
||||
NULL,
|
||||
0));
|
||||
}
|
||||
/*******************************************************\
|
||||
* Get scsi driver to send a "start up" command *
|
||||
* Get scsi driver to send a "RESET" command *
|
||||
\*******************************************************/
|
||||
cd_reset(unit)
|
||||
int unit;
|
||||
{
|
||||
return(cd_scsi_cmd(unit,0,0,0,0,2000,SCSI_RESET));
|
||||
return(cd_scsi_cmd(unit,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
2000,
|
||||
NULL,
|
||||
SCSI_RESET));
|
||||
}
|
||||
/*******************************************************\
|
||||
* Get scsi driver to send a "start up" command *
|
||||
@ -1355,9 +1383,12 @@ int unit;
|
||||
cd_start_unit(unit,part,type)
|
||||
{
|
||||
struct scsi_start_stop scsi_cmd;
|
||||
struct cd_data *cd = cd_driver->cd_data[unit];
|
||||
|
||||
if(type==CD_EJECT && (cd_driver->cd_data[unit]->openparts&~(1<<part)) == 0 ) {
|
||||
cd_prevent_unit(unit,CD_EJECT,0);
|
||||
if(type==CD_EJECT
|
||||
/*&& (cd->openparts == 0)*/)/* trouble is WE have it open *//*XXX*/
|
||||
{
|
||||
cd_prevent_unit(unit,PR_ALLOW,0);
|
||||
}
|
||||
|
||||
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
||||
@ -1371,6 +1402,7 @@ cd_start_unit(unit,part,type)
|
||||
0,
|
||||
0,
|
||||
2000,
|
||||
NULL,
|
||||
0) != 0) {
|
||||
return(ENXIO);
|
||||
} else
|
||||
@ -1383,17 +1415,21 @@ cd_prevent_unit(unit,type,flags)
|
||||
int unit,type,flags;
|
||||
{
|
||||
struct scsi_prevent scsi_cmd;
|
||||
struct cd_data *cd = cd_driver->cd_data[unit];
|
||||
|
||||
if(type==CD_EJECT || type==PR_PREVENT || cd_driver->cd_data[unit]->openparts == 0 ) {
|
||||
if(type==PR_PREVENT
|
||||
|| ( type==PR_ALLOW && cd->openparts == 0 ))/*XXX*/
|
||||
{
|
||||
bzero(&scsi_cmd, sizeof(scsi_cmd));
|
||||
scsi_cmd.op_code = PREVENT_ALLOW;
|
||||
scsi_cmd.how = (type==CD_EJECT)?PR_ALLOW:type;
|
||||
scsi_cmd.how = type;
|
||||
if (cd_scsi_cmd(unit,
|
||||
&scsi_cmd,
|
||||
sizeof(struct scsi_prevent),
|
||||
0,
|
||||
0,
|
||||
5000,
|
||||
NULL,
|
||||
0) != 0)
|
||||
{
|
||||
if(!(flags & SCSI_SILENT))
|
||||
@ -1431,6 +1467,7 @@ struct cd_sub_channel_info *data;
|
||||
data,
|
||||
len,
|
||||
5000,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
|
||||
@ -1463,6 +1500,7 @@ struct cd_toc_entry *data;
|
||||
data,
|
||||
len,
|
||||
5000,
|
||||
NULL,
|
||||
0);
|
||||
}
|
||||
|
||||
@ -1529,7 +1567,7 @@ dev_t dev;
|
||||
* Also tell it where to read/write the data, and how *
|
||||
* long the data is supposed to be *
|
||||
\*******************************************************/
|
||||
int cd_scsi_cmd(unit,scsi_cmd,cmdlen,data_addr,datalen,timeout,flags)
|
||||
int cd_scsi_cmd(unit,scsi_cmd,cmdlen,data_addr,datalen,timeout,bp,flags)
|
||||
|
||||
int unit,flags;
|
||||
struct scsi_generic *scsi_cmd;
|
||||
@ -1537,6 +1575,7 @@ int cmdlen;
|
||||
int timeout;
|
||||
u_char *data_addr;
|
||||
int datalen;
|
||||
struct buf *bp;
|
||||
{
|
||||
struct scsi_xfer *xs;
|
||||
int retval;
|
||||
@ -1546,101 +1585,128 @@ int datalen;
|
||||
#ifdef CDDEBUG
|
||||
if(scsi_debug & PRINTROUTINES) printf("\ncd_scsi_cmd%d ",unit);
|
||||
#endif /*CDDEBUG*/
|
||||
if(cd->sc_sw) /* If we have a scsi driver */
|
||||
#ifdef PARANOID
|
||||
if(!(cd->sc_sw)) /* If we have a scsi driver */
|
||||
{
|
||||
xs = cd_get_xs(unit,flags); /* should wait unless booting */
|
||||
if(!xs)
|
||||
/* !? how'd we GET here? */
|
||||
panic("attempt to run bad cd device");
|
||||
}
|
||||
#endif /*PARANOID*/
|
||||
xs = cd_get_xs(unit,flags); /* should wait unless booting */
|
||||
if(!xs)
|
||||
{
|
||||
printf("cd%d: scsi_cmd controller busy"
|
||||
" (this should never happen)\n",unit);
|
||||
return(EBUSY);
|
||||
}
|
||||
xs->flags |= INUSE;
|
||||
/*******************************************************\
|
||||
* Fill out the scsi_xfer structure *
|
||||
\*******************************************************/
|
||||
xs->flags |= flags;
|
||||
xs->adapter = cd->ctlr;
|
||||
xs->targ = cd->targ;
|
||||
xs->lu = cd->lu;
|
||||
xs->retries = CD_RETRIES;
|
||||
xs->timeout = timeout;
|
||||
xs->cmd = scsi_cmd;
|
||||
xs->cmdlen = cmdlen;
|
||||
xs->data = data_addr;
|
||||
xs->datalen = datalen;
|
||||
xs->resid = datalen;
|
||||
xs->when_done = (flags & SCSI_NOMASK)
|
||||
?(int (*)())0
|
||||
:cd_done;
|
||||
xs->done_arg = unit;
|
||||
xs->done_arg2 = (int)xs;
|
||||
xs->bp = bp;
|
||||
retry: xs->error = XS_NOERROR;
|
||||
/*******************************************************\
|
||||
* Do the transfer. If we are polling we will return: *
|
||||
* COMPLETE, Was poll, and cd_done has been called *
|
||||
* HAD_ERROR, Was poll and an error was encountered *
|
||||
* TRY_AGAIN_LATER, Adapter short resources, try again *
|
||||
* *
|
||||
* if under full steam (interrupts) it will return: *
|
||||
* SUCCESSFULLY_QUEUED, will do a wakeup when complete *
|
||||
* HAD_ERROR, had an erro before it could queue *
|
||||
* TRY_AGAIN_LATER, (as for polling) *
|
||||
* After the wakeup, we must still check if it succeeded *
|
||||
* *
|
||||
* If we have a bp however, all the error proccessing *
|
||||
* and the buffer code both expect us to return straight *
|
||||
* to them, so as soon as the command is queued, return *
|
||||
\*******************************************************/
|
||||
retval = (*(cd->sc_sw->scsi_cmd))(xs);
|
||||
if(bp) return retval; /* will sleep (or not) elsewhere */
|
||||
|
||||
/*******************************************************\
|
||||
* Only here for non I/O cmds. It's cheaper to process *
|
||||
* the error status here than at interrupt time so *
|
||||
* sd_done will have done nothing except wake us up. *
|
||||
\*******************************************************/
|
||||
switch(retval)
|
||||
{
|
||||
case SUCCESSFULLY_QUEUED:
|
||||
s = splbio();
|
||||
while(!(xs->flags & ITSDONE))
|
||||
sleep(xs,PRIBIO+1);
|
||||
splx(s);
|
||||
/* Fall through to check the result */
|
||||
|
||||
case HAD_ERROR:
|
||||
switch(xs->error)
|
||||
{
|
||||
printf("cd%d: scsi_cmd controller busy"
|
||||
" (this should never happen)\n",unit);
|
||||
return(EBUSY);
|
||||
}
|
||||
xs->flags |= INUSE;
|
||||
/*******************************************************\
|
||||
* Fill out the scsi_xfer structure *
|
||||
\*******************************************************/
|
||||
xs->flags |= flags;
|
||||
xs->adapter = cd->ctlr;
|
||||
xs->targ = cd->targ;
|
||||
xs->lu = cd->lu;
|
||||
xs->retries = CD_RETRIES;
|
||||
xs->timeout = timeout;
|
||||
xs->cmd = scsi_cmd;
|
||||
xs->cmdlen = cmdlen;
|
||||
xs->data = data_addr;
|
||||
xs->datalen = datalen;
|
||||
xs->resid = datalen;
|
||||
xs->when_done = (flags & SCSI_NOMASK)
|
||||
?(int (*)())0
|
||||
:cd_done;
|
||||
xs->done_arg = unit;
|
||||
xs->done_arg2 = (int)xs;
|
||||
retry: xs->error = XS_NOERROR;
|
||||
xs->bp = 0;
|
||||
retval = (*(cd->sc_sw->scsi_cmd))(xs);
|
||||
switch(retval)
|
||||
{
|
||||
case SUCCESSFULLY_QUEUED:
|
||||
s = splbio();
|
||||
while(!(xs->flags & ITSDONE))
|
||||
sleep(xs,PRIBIO+1);
|
||||
splx(s);
|
||||
|
||||
case HAD_ERROR:
|
||||
/*printf("err = %d ",xs->error);*/
|
||||
switch(xs->error)
|
||||
{
|
||||
case XS_NOERROR:
|
||||
retval = ESUCCESS;
|
||||
break;
|
||||
case XS_SENSE:
|
||||
retval = (cd_interpret_sense(unit,xs));
|
||||
break;
|
||||
case XS_DRIVER_STUFFUP:
|
||||
retval = EIO;
|
||||
break;
|
||||
|
||||
|
||||
case XS_BUSY:
|
||||
case XS_TIMEOUT:
|
||||
if(xs->retries-- )
|
||||
{
|
||||
xs->flags &= ~ITSDONE;
|
||||
goto retry;
|
||||
}
|
||||
retval = EIO;
|
||||
break;
|
||||
default:
|
||||
retval = EIO;
|
||||
printf("cd%d: unknown error category from scsi driver\n"
|
||||
,unit);
|
||||
}
|
||||
break;
|
||||
case COMPLETE:
|
||||
case XS_NOERROR: /* usually this one */
|
||||
retval = ESUCCESS;
|
||||
break;
|
||||
case TRY_AGAIN_LATER:
|
||||
|
||||
case XS_SENSE:
|
||||
retval = (cd_interpret_sense(unit,xs));
|
||||
break;
|
||||
case XS_BUSY:
|
||||
/* should sleep here 1 sec */
|
||||
/* fall through */
|
||||
case XS_TIMEOUT:
|
||||
if(xs->retries-- )
|
||||
{
|
||||
if(tsleep( 0,PRIBIO + 2,"retry",hz * 2))
|
||||
{
|
||||
xs->flags &= ~ITSDONE;
|
||||
goto retry;
|
||||
}
|
||||
xs->flags &= ~ITSDONE;
|
||||
goto retry;
|
||||
}
|
||||
/* fall through */
|
||||
case XS_DRIVER_STUFFUP:
|
||||
retval = EIO;
|
||||
break;
|
||||
default:
|
||||
retval = EIO;
|
||||
printf("cd%d: unknown error category from scsi driver\n"
|
||||
,unit);
|
||||
}
|
||||
break;
|
||||
case COMPLETE:
|
||||
retval = ESUCCESS;
|
||||
break;
|
||||
|
||||
case TRY_AGAIN_LATER:
|
||||
if(xs->retries-- )
|
||||
{
|
||||
if(tsleep( 0,PRIBIO + 2,"retry",hz * 2))
|
||||
{
|
||||
xs->flags &= ~ITSDONE;
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
cd_free_xs(unit,xs,flags);
|
||||
cdstart(unit); /* check if anything is waiting fr the xs */
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("cd%d: not set up\n",unit);
|
||||
return(EINVAL);
|
||||
/* fall through */
|
||||
default:
|
||||
retval = EIO;
|
||||
}
|
||||
|
||||
/*******************************************************\
|
||||
* we have finished doing the command, free the struct *
|
||||
* and check if anyone else needs it *
|
||||
\*******************************************************/
|
||||
cd_free_xs(unit,xs,flags);
|
||||
cdstart(unit); /* check if anything is waiting for the xs */
|
||||
return(retval);
|
||||
}
|
||||
/***************************************************************\
|
||||
@ -1655,6 +1721,18 @@ struct scsi_xfer *xs;
|
||||
struct scsi_sense_data *sense;
|
||||
int key;
|
||||
int silent;
|
||||
int info;
|
||||
struct cd_data *cd = cd_driver->cd_data[unit];
|
||||
|
||||
static char *error_mes[] = { "soft error (corrected)",
|
||||
"not ready", "medium error",
|
||||
"non-media hardware failure", "illegal request",
|
||||
"unit attention", "readonly device",
|
||||
"no data found", "vendor unique",
|
||||
"copy aborted", "command aborted",
|
||||
"search returned equal", "volume overflow",
|
||||
"verify miscompare", "unknown error key"
|
||||
};
|
||||
|
||||
/***************************************************************\
|
||||
* If the flags say errs are ok, then always return ok. *
|
||||
@ -1663,160 +1741,119 @@ struct scsi_xfer *xs;
|
||||
silent = (xs->flags & SCSI_SILENT);
|
||||
|
||||
sense = &(xs->sense);
|
||||
#ifdef CDDEBUG
|
||||
if(cd_debug)
|
||||
{
|
||||
int count = 0;
|
||||
printf("code%x valid%x\n"
|
||||
,sense->error_code & SSD_ERRCODE
|
||||
,sense->error_code & SSD_ERRCODE_VALID ? 1 : 0);
|
||||
printf("seg%x key%x ili%x eom%x fmark%x\n"
|
||||
,sense->ext.extended.segment
|
||||
,sense->ext.extended.flags & SSD_KEY
|
||||
,sense->ext.extended.flags & SSD_ILI ? 1 : 0
|
||||
,sense->ext.extended.flags & SSD_EOM ? 1 : 0
|
||||
,sense->ext.extended.flags & SSD_FILEMARK ? 1 : 0);
|
||||
printf("info: %x %x %x %x followed by %d extra bytes\n"
|
||||
,sense->ext.extended.info[0]
|
||||
,sense->ext.extended.info[1]
|
||||
,sense->ext.extended.info[2]
|
||||
,sense->ext.extended.info[3]
|
||||
,sense->ext.extended.extra_len);
|
||||
printf("extra: ");
|
||||
while(count < sense->ext.extended.extra_len)
|
||||
{
|
||||
printf ("%x ",sense->ext.extended.extra_bytes[count++]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif /*CDDEBUG*/
|
||||
switch(sense->error_code & SSD_ERRCODE)
|
||||
{
|
||||
/***************************************************************\
|
||||
* If it's code 70, use the extended stuff and interpret the key *
|
||||
\***************************************************************/
|
||||
case 0x71:/* delayed error */
|
||||
printf("cd%d: DELAYED ERROR, key = 0x%x\n",unit,key);
|
||||
case 0x70:
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
info = ntohl(*((long *)sense->ext.extended.info));
|
||||
}
|
||||
else
|
||||
{
|
||||
info = 0;
|
||||
}
|
||||
|
||||
key=sense->ext.extended.flags & SSD_KEY;
|
||||
switch(key)
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
case 0x0:
|
||||
return(ESUCCESS);
|
||||
case 0x1:
|
||||
if(!silent)
|
||||
printf("cd%d: %s", unit, error_mes[key - 1]);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf("cd%d: soft error(corrected)", unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
switch (key)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
case 0x2: /* NOT READY */
|
||||
case 0x5: /* ILLEGAL REQUEST */
|
||||
case 0x6: /* UNIT ATTENTION */
|
||||
case 0x7: /* DATA PROTECT */
|
||||
break;
|
||||
case 0x8: /* BLANK CHECK */
|
||||
printf(", requested size: %d (decimal)",
|
||||
info);
|
||||
break;
|
||||
default:
|
||||
printf(", info = %d (decimal)", info);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 0x0: /* NO SENSE */
|
||||
case 0x1: /* RECOVERED ERROR */
|
||||
xs->resid = 0;
|
||||
case 0xc: /* EQUAL */
|
||||
return(ESUCCESS);
|
||||
case 0x2:
|
||||
if(!silent)printf("cd%d: not ready\n", unit);
|
||||
case 0x2: /* NOT READY */
|
||||
cd->flags &= ~(CDVALID | CDHAVELABEL);
|
||||
return(ENODEV);
|
||||
case 0x3:
|
||||
if(!silent)
|
||||
{
|
||||
printf("cd%d: medium error", unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return(EIO);
|
||||
case 0x4:
|
||||
if(!silent)printf("cd%d: non-media hardware failure\n",
|
||||
unit);
|
||||
return(EIO);
|
||||
case 0x5:
|
||||
if(!silent)printf("cd%d: illegal request\n",
|
||||
unit);
|
||||
case 0x5: /* ILLEGAL REQUEST */
|
||||
return(EINVAL);
|
||||
case 0x6:
|
||||
if(!silent)printf("cd%d: Unit attention\n", unit);
|
||||
if (cd_driver->cd_data[unit]->openparts)
|
||||
cd_driver->cd_data[unit]->flags &= ~(CDVALID | CDHAVELABEL);
|
||||
case 0x6: /* UNIT ATTENTION */
|
||||
cd->flags &= ~(CDVALID | CDHAVELABEL);
|
||||
if (cd->openparts)
|
||||
{
|
||||
return(EIO);
|
||||
}
|
||||
return(ESUCCESS);
|
||||
case 0x7:
|
||||
if(!silent)
|
||||
{
|
||||
printf("cd%d: attempted protection violation",
|
||||
unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
case 0x7: /* DATA PROTECT */
|
||||
return(EACCES);
|
||||
case 0x8:
|
||||
if(!silent)
|
||||
{
|
||||
printf("cd%d: block wrong state (worm)",
|
||||
unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return(EIO);
|
||||
case 0x9:
|
||||
if(!silent)printf("cd%d: vendor unique\n", unit);
|
||||
return(EIO);
|
||||
case 0xa:
|
||||
if(!silent)printf("cd%d: copy aborted\n", unit);
|
||||
return(EIO);
|
||||
case 0xb:
|
||||
if(!silent)printf("cd%d: command aborted\n", unit);
|
||||
return(EIO);
|
||||
case 0xc:
|
||||
if(!silent)
|
||||
{
|
||||
printf("cd%d: search returned", unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return(ESUCCESS);
|
||||
case 0xd:
|
||||
if(!silent)printf("cd%d: volume overflow\n", unit);
|
||||
case 0xd: /* VOLUME OVERFLOW */
|
||||
return(ENOSPC);
|
||||
case 0xe:
|
||||
if(!silent)
|
||||
{
|
||||
printf("cd%d: verify miscompare", unit);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
(sense->ext.extended.info[0] <<24)|
|
||||
(sense->ext.extended.info[1] <<16)|
|
||||
(sense->ext.extended.info[2] <<8)|
|
||||
(sense->ext.extended.info[3] ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return(EIO);
|
||||
case 0xf:
|
||||
if(!silent)printf("cd%d: unknown error key\n", unit);
|
||||
case 0x8: /* BLANK CHECK */
|
||||
return(ESUCCESS);
|
||||
default:
|
||||
return(EIO);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*******************************\
|
||||
* Not code 70, just report it *
|
||||
\*******************************/
|
||||
default:
|
||||
if(!silent)
|
||||
{
|
||||
if(!silent)
|
||||
printf("cd%d: error code %d", unit,
|
||||
sense->error_code & SSD_ERRCODE);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf("cd%d: error code %d",
|
||||
unit,
|
||||
sense->error_code & SSD_ERRCODE);
|
||||
if(sense->error_code & SSD_ERRCODE_VALID)
|
||||
{
|
||||
printf(" block no. %d (decimal)",
|
||||
printf(" at block no. %d (decimal)",
|
||||
(sense->ext.unextended.blockhi <<16)
|
||||
+ (sense->ext.unextended.blockmed <<8)
|
||||
+ (sense->ext.unextended.blocklow ));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return(EIO);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user