if ((chp->ch_drive[i].drive_flags & DRIVE_OLD) == 0) continue;  CHP_WRITE_REG(chp, wdr_sdh, WDSD_IBM | (i << 4)); delay(10); CHP_WRITE_REG(chp, wdr_features, 0x58); CHP_WRITE_REG(chp, wdr_cyl_lo, 0xa5); if ((CHP_READ_REG(chp, wdr_error) == 0x58) || (CHP_READ_REG(chp, wdr_cyl_lo) != 0xa5)) { WDCDEBUG_PRINT(("%s:%d:%d: register " "writability failed\n", chp->wdc->sc_dev.dv_xname, chp->channel, i), DEBUG_PROBE); chp->ch_drive[i].drive_flags &= ~DRIVE_OLD; } CHP_WRITE_REG(chp, wdr_sdh, WDSD_IBM | (i << 4)); delay(100); if (wait_for_ready(chp, 10000) != 0) { WDCDEBUG_PRINT(("%s:%d:%d: not ready\n", chp->wdc->sc_dev.dv_xname, chp->channel, i), DEBUG_PROBE);
if (!wdc_preata_drive(chp, i))
wdcattach(chp)	struct channel_softc *chp;{	int channel_flags, ctrl_flags, i;#ifndef __OpenBSD__	int error;#endif	struct ata_atapi_attach aa_link;	struct ataparams params;	static int inited = 0;	extern int cold;	if (!cold)		at_poll = AT_WAIT;#ifndef __OpenBSD__	if ((error = wdc_addref(chp)) != 0) {		printf("%s: unable to enable controller\n",		    chp->wdc->sc_dev.dv_xname);		return;	}#endif	if (!chp->_vtbl)		chp->_vtbl = &wdc_default_vtbl;	if (wdcprobe(chp) == 0) {		/* If no drives, abort attach here. */#ifndef __OpenBSD__		wdc_delref(chp);#endif		return;	}#ifdef WDCDEBUG	if (chp->wdc->sc_dev.dv_cfdata->cf_flags & WDC_OPTION_PROBE_VERBOSE)		wdcdebug_mask |= DEBUG_PROBE;#endif	/* init list only once */	if (inited == 0) {		LIST_INIT(&xfer_free_list);		inited++;	}	TAILQ_INIT(&chp->ch_queue->sc_xfer);	timeout_set(&chp->ch_timo, wdctimeout, chp);		for (i = 0; i < 2; i++) {		chp->ch_drive[i].chnl_softc = chp;		chp->ch_drive[i].drive = i;		/* If controller can't do 16bit flag the drives as 32bit */		if ((chp->wdc->cap &		    (WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32)) ==		    WDC_CAPABILITY_DATA32)			chp->ch_drive[i].drive_flags |= DRIVE_CAP32;		if ((chp->ch_drive[i].drive_flags & DRIVE) == 0)			continue;		if (i == 1 && ((chp->ch_drive[0].drive_flags & DRIVE) == 0))			chp->ch_flags |= WDCF_ONESLAVE;		/* Issue a IDENTIFY command, to try to detect slave ghost */		if (ata_get_params(&chp->ch_drive[i], at_poll, &params) ==		    CMD_OK) {			/* If IDENTIFY succeded, this is not an OLD ctrl */			chp->ch_drive[0].drive_flags &= ~DRIVE_OLD;			chp->ch_drive[1].drive_flags &= ~DRIVE_OLD;		} else {			chp->ch_drive[i].drive_flags &=			    ~(DRIVE_ATA | DRIVE_ATAPI);			WDCDEBUG_PRINT(("%s:%d:%d: IDENTIFY failed\n",			    chp->wdc->sc_dev.dv_xname,			    chp->channel, i), DEBUG_PROBE);			if ((chp->ch_drive[i].drive_flags & DRIVE_OLD) == 0)				continue;			/*			 * Pre-ATA drive ?			 * Test registers writability (Error register not			 * writable, but cyllo is), then try an ATA command.			 */			CHP_WRITE_REG(chp, wdr_sdh, WDSD_IBM | (i << 4));			delay(10);			CHP_WRITE_REG(chp, wdr_features, 0x58);			CHP_WRITE_REG(chp, wdr_cyl_lo, 0xa5);			if ((CHP_READ_REG(chp, wdr_error) == 0x58) ||			    (CHP_READ_REG(chp, wdr_cyl_lo) != 0xa5)) {				WDCDEBUG_PRINT(("%s:%d:%d: register "				    "writability failed\n",				    chp->wdc->sc_dev.dv_xname,				    chp->channel, i), DEBUG_PROBE);				    chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;			}			CHP_WRITE_REG(chp, wdr_sdh, WDSD_IBM | (i << 4));			delay(100);			if (wait_for_ready(chp, 10000) != 0) {				WDCDEBUG_PRINT(("%s:%d:%d: not ready\n",				    chp->wdc->sc_dev.dv_xname,				    chp->channel, i), DEBUG_PROBE);				chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;				continue;			}			CHP_WRITE_REG(chp, wdr_command, WDCC_RECAL);			if (wait_for_ready(chp, 10000) != 0) {				WDCDEBUG_PRINT(("%s:%d:%d: WDCC_RECAL failed\n",				    chp->wdc->sc_dev.dv_xname,				    chp->channel, i), DEBUG_PROBE);				chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;			}		}	}	ctrl_flags = chp->wdc->sc_dev.dv_cfdata->cf_flags;	channel_flags = (ctrl_flags >> (NBBY * chp->channel)) & 0xff;	WDCDEBUG_PRINT(("wdcattach: ch_drive_flags 0x%x 0x%x\n",	    chp->ch_drive[0].drive_flags, chp->ch_drive[1].drive_flags),	    DEBUG_PROBE);	/* If no drives, abort here */	if ((chp->ch_drive[0].drive_flags & DRIVE) == 0 &&	    (chp->ch_drive[1].drive_flags & DRIVE) == 0)		goto exit;	/*	 * Attach an ATAPI bus, if needed.	 */	if ((chp->ch_drive[0].drive_flags & DRIVE_ATAPI) ||	    (chp->ch_drive[1].drive_flags & DRIVE_ATAPI)) {#if NATAPISCSI > 0		wdc_atapibus_attach(chp);#else		/*		 * Fills in a fake aa_link and call config_found, so that		 * the config machinery will print		 * "atapibus at xxx not configured"		 */		bzero(&aa_link, sizeof(struct ata_atapi_attach));		aa_link.aa_type = T_ATAPI;		aa_link.aa_channel = chp->channel;		aa_link.aa_openings = 1;		aa_link.aa_drv_data = 0;		aa_link.aa_bus_private = NULL;		(void)config_found(&chp->wdc->sc_dev, (void *)&aa_link,		    atapi_print);#endif	}	for (i = 0; i < 2; i++) {		if ((chp->ch_drive[i].drive_flags &		    (DRIVE_ATA | DRIVE_OLD)) == 0) {			continue;		}		bzero(&aa_link, sizeof(struct ata_atapi_attach));		aa_link.aa_type = T_ATA;		aa_link.aa_channel = chp->channel;		aa_link.aa_openings = 1;		aa_link.aa_drv_data = &chp->ch_drive[i];		config_found(&chp->wdc->sc_dev, (void *)&aa_link, wdprint);	}	/*	 * reset drive_flags for unnatached devices, reset state for attached	 *  ones	 */	for (i = 0; i < 2; i++) {		if (chp->ch_drive[i].drive_name[0] == 0)			chp->ch_drive[i].drive_flags = 0;		else			chp->ch_drive[i].state = 0;	}	/*	 * Reset channel. The probe, with some combinations of ATA/ATAPI	 * devices keep it in a mostly working, but strange state (with busy	 * led on)	 */	if ((chp->wdc->cap & WDC_CAPABILITY_NO_EXTRA_RESETS) == 0) {		wdcreset(chp, VERBOSE);		/*		 * Read status registers to avoid spurious interrupts.		 */		for (i = 1; i >= 0; i--) {			if (chp->ch_drive[i].drive_flags & DRIVE) {				CHP_WRITE_REG(chp,				    wdr_sdh, WDSD_IBM | (i << 4));				if (wait_for_unbusy(chp, 10000) < 0)					printf("%s:%d:%d: device busy\n",					    chp->wdc->sc_dev.dv_xname,					    chp->channel, i);			}		}	}#ifndef __OpenBSD__	wdc_delref(chp);#endif exit:#ifdef WDCDEBUG	if (chp->wdc->sc_dev.dv_cfdata->cf_flags & WDC_OPTION_PROBE_VERBOSE)		wdcdebug_mask &= ~DEBUG_PROBE;#endif	return;}