int delay = (irq == 0) ? ATAPI_DELAY : 0;
int delay = (irq == 0) ? ATAPI_DELAY : 1;
wdc_atapi_ctrl(chp, xfer, irq)	struct channel_softc *chp;	struct wdc_xfer *xfer;	int irq;{	struct scsi_xfer *sc_xfer = xfer->cmd;	struct ata_drive_datas *drvp = &chp->ch_drive[xfer->drive];	char *errstring = NULL;	int delay = (irq == 0) ? ATAPI_DELAY : 0;	/* Ack interrupt done in wait_for_unbusy */again:	WDCDEBUG_PRINT(("wdc_atapi_ctrl %s:%d:%d state %d\n",	    chp->wdc->sc_dev.dv_xname, chp->channel, drvp->drive, drvp->state),	    DEBUG_INTR | DEBUG_FUNCS);	/* We shouldn't have to select the drive in these states.	   If we do, there are other, more serious problems */	if (drvp->state != IDENTIFY_WAIT &&	    drvp->state != PIOMODE_WAIT &&	    drvp->state != DMAMODE_WAIT)		wdc_select_drive(chp, xfer->drive, delay);	switch (drvp->state) {		/* You need to send an ATAPI drive an ATAPI-specific		   command to revive it after a hard reset. Identify		   is about the most innocuous thing you can do		   that's guaranteed to be there */	case IDENTIFY:		wdccommandshort(chp, drvp->drive, ATAPI_IDENTIFY_DEVICE);		drvp->state = IDENTIFY_WAIT;		break;		case IDENTIFY_WAIT:		errstring = "IDENTIFY";				/* Some ATAPI devices need to try to read the media		   before responding. Well, let's hope resets while		   polling are few and far between */		if (wdcwait(chp, 0, 0, (irq == 0) ? 10000 : 0)) 			goto timeout;		/* We don't really care if this operation failed.		   It's just there to wake the drive from its stupor. */		if (!(chp->ch_status & WDCS_ERR)) {			wdcbit_bucket(chp, 512);				errstring = "Post IDENTIFY";			/* Wait for the drive to become unbusy before shoving			   the PIOMODE command down its throat */			if (wdcwait(chp, 0, 0, 10000))				goto timeout;		}		drvp->state = PIOMODE;		goto again;	case PIOMODE:piomode:		/* Don't try to set mode if controller can't be adjusted */		if ((chp->wdc->cap & WDC_CAPABILITY_MODE) == 0)			goto ready;		/* Also don't try if the drive didn't report its mode */		if ((drvp->drive_flags & DRIVE_MODE) == 0)			goto ready;		wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,		    0x08 | drvp->PIO_mode, WDSF_SET_MODE);		drvp->state = PIOMODE_WAIT;		break;	case PIOMODE_WAIT:		errstring = "piomode";		if (wait_for_unbusy(chp, delay))			goto timeout;		if (chp->ch_status & WDCS_ERR) {			if (drvp->PIO_mode < 3) {				drvp->PIO_mode = 3;				goto piomode;			} else {				goto error;			}		}	/* fall through */	case DMAMODE:		if (drvp->drive_flags & DRIVE_UDMA) {			wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,			    0x40 | drvp->UDMA_mode, WDSF_SET_MODE);		} else if (drvp->drive_flags & DRIVE_DMA) {			wdccommand(chp, drvp->drive, SET_FEATURES, 0, 0, 0,			    0x20 | drvp->DMA_mode, WDSF_SET_MODE);		} else {			goto ready;		}		drvp->state = DMAMODE_WAIT;		break;	case DMAMODE_WAIT:		errstring = "dmamode";		if (wait_for_unbusy(chp, delay))			goto timeout;		if (chp->ch_status & WDCS_ERR)			goto error;	/* fall through */	case READY:	ready:		drvp->state = READY;		xfer->c_intr = wdc_atapi_intr;		wdc_atapi_start(chp, xfer);		return (1);	}	if ((sc_xfer->flags & SCSI_POLL) == 0 &&	    (drvp->atapi_cap & ACAP_DSC) == 0) {		chp->ch_flags |= WDCF_IRQ_WAIT;		xfer->c_intr = wdc_atapi_ctrl;		timeout(wdctimeout, chp, sc_xfer->timeout * hz / 1000);	} else {		goto again;	}	return (1);timeout:	if (irq && (xfer->c_flags & C_TIMEOU) == 0) {		return (0); /* IRQ was not for us */	}	printf("%s:%d:%d: %s timed out\n",	    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive, errstring);	sc_xfer->error = XS_TIMEOUT;	wdc_atapi_reset(chp, xfer);	return (1);error:	printf("%s:%d:%d: %s ",	    chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive,	    errstring);	printf("error (0x%x)\n", chp->ch_error);	sc_xfer->error = XS_SHORTSENSE;	atapi_to_scsi_sense(sc_xfer, chp->ch_error);	wdc_atapi_reset(chp, xfer);	return (1);}