2004-08-13 01:05:09 +04:00
|
|
|
/* $NetBSD: wdc.c,v 1.196 2004/08/12 21:05:09 thorpej Exp $ */
|
1998-10-12 20:09:10 +04:00
|
|
|
|
|
|
|
/*
|
2003-10-08 14:58:12 +04:00
|
|
|
* Copyright (c) 1998, 2001, 2003 Manuel Bouyer. All rights reserved.
|
1998-10-12 20:09:10 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Manuel Bouyer.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-08-15 14:10:47 +04:00
|
|
|
/*-
|
2003-09-20 01:35:56 +04:00
|
|
|
* Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
|
1998-08-15 14:10:47 +04:00
|
|
|
* All rights reserved.
|
1997-08-27 15:22:52 +04:00
|
|
|
*
|
1998-08-15 14:10:47 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
|
1998-01-15 02:41:59 +03:00
|
|
|
*
|
1997-08-27 15:22:52 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1998-08-15 14:10:47 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1997-08-27 15:22:52 +04:00
|
|
|
*
|
1998-08-15 14:10:47 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
|
|
|
|
1998-01-15 02:41:59 +03:00
|
|
|
/*
|
|
|
|
* CODE UNTESTED IN THE CURRENT REVISION:
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-08-13 01:05:09 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.196 2004/08/12 21:05:09 thorpej Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1999-02-21 02:47:52 +03:00
|
|
|
#ifndef WDCDEBUG
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WDCDEBUG
|
1999-02-21 02:47:52 +03:00
|
|
|
#endif /* WDCDEBUG */
|
1998-10-12 20:09:10 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/device.h>
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <sys/malloc.h>
|
1999-08-09 13:55:18 +04:00
|
|
|
#include <sys/pool.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <machine/intr.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
1998-02-04 17:13:40 +03:00
|
|
|
#ifndef __BUS_SPACE_HAS_STREAM_METHODS
|
1998-10-12 20:09:10 +04:00
|
|
|
#define bus_space_write_multi_stream_2 bus_space_write_multi_2
|
|
|
|
#define bus_space_write_multi_stream_4 bus_space_write_multi_4
|
|
|
|
#define bus_space_read_multi_stream_2 bus_space_read_multi_2
|
|
|
|
#define bus_space_read_multi_stream_4 bus_space_read_multi_4
|
1998-02-04 17:13:40 +03:00
|
|
|
#endif /* __BUS_SPACE_HAS_STREAM_METHODS */
|
1998-02-03 07:26:45 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <dev/ata/atavar.h>
|
|
|
|
#include <dev/ata/atareg.h>
|
1998-01-15 02:41:59 +03:00
|
|
|
#include <dev/ic/wdcreg.h>
|
|
|
|
#include <dev/ic/wdcvar.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
2003-01-27 21:21:23 +03:00
|
|
|
#include "ataraid.h"
|
1998-10-12 20:09:10 +04:00
|
|
|
#include "atapibus.h"
|
2001-12-05 23:43:00 +03:00
|
|
|
#include "wd.h"
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2003-01-27 21:21:23 +03:00
|
|
|
#if NATARAID > 0
|
|
|
|
#include <dev/ata/ata_raidvar.h>
|
|
|
|
#endif
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WDCDELAY 100 /* 100 microseconds */
|
|
|
|
#define WDCNDELAY_RST (WDC_RESET_WAIT * 1000 / WDCDELAY)
|
1997-08-27 15:22:52 +04:00
|
|
|
#if 0
|
1998-10-12 20:09:10 +04:00
|
|
|
/* If you enable this, it will report any delays more than WDCDELAY * N long. */
|
1997-08-27 15:22:52 +04:00
|
|
|
#define WDCNDELAY_DEBUG 50
|
|
|
|
#endif
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* When polling wait that much and then tsleep for 1/hz seconds */
|
|
|
|
#define WDCDELAY_POLL 1 /* ms */
|
|
|
|
|
|
|
|
/* timeout for the control commands */
|
|
|
|
#define WDC_CTRL_DELAY 10000 /* 10s, for the recall command */
|
|
|
|
|
1999-08-09 13:55:18 +04:00
|
|
|
struct pool wdc_xfer_pool;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2001-12-05 23:43:00 +03:00
|
|
|
#if NWD > 0
|
2001-12-03 03:11:15 +03:00
|
|
|
extern const struct ata_bustype wdc_ata_bustype; /* in ata_wdc.c */
|
2001-12-05 23:43:00 +03:00
|
|
|
#else
|
|
|
|
/* A fake one, the autoconfig will print "wd at foo ... not configured */
|
|
|
|
const struct ata_bustype wdc_ata_bustype = {
|
|
|
|
SCSIPI_BUSTYPE_ATA,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
#endif
|
2001-12-03 01:44:32 +03:00
|
|
|
|
2004-01-03 04:50:52 +03:00
|
|
|
static int wdcprobe1(struct wdc_channel*, int);
|
|
|
|
static void __wdcerror(struct wdc_channel*, char *);
|
|
|
|
static int __wdcwait_reset(struct wdc_channel *, int, int);
|
|
|
|
static void __wdccommand_done(struct wdc_channel *, struct ata_xfer *);
|
2004-08-01 01:26:42 +04:00
|
|
|
static void __wdccommand_done_end(struct wdc_channel *, struct ata_xfer *);
|
|
|
|
static void __wdccommand_kill_xfer(struct wdc_channel *,
|
|
|
|
struct ata_xfer *, int);
|
2004-01-03 04:50:52 +03:00
|
|
|
static void __wdccommand_start(struct wdc_channel *, struct ata_xfer *);
|
2004-08-01 01:26:42 +04:00
|
|
|
static int __wdccommand_intr(struct wdc_channel *, struct ata_xfer *, int);
|
2004-01-03 04:50:52 +03:00
|
|
|
static int __wdcwait(struct wdc_channel *, int, int, int);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
|
|
|
#define DEBUG_INTR 0x01
|
|
|
|
#define DEBUG_XFERS 0x02
|
|
|
|
#define DEBUG_STATUS 0x04
|
|
|
|
#define DEBUG_FUNCS 0x08
|
|
|
|
#define DEBUG_PROBE 0x10
|
1999-09-23 15:04:29 +04:00
|
|
|
#define DEBUG_DETACH 0x20
|
2000-04-04 16:43:13 +04:00
|
|
|
#define DEBUG_DELAY 0x40
|
1998-10-12 20:09:10 +04:00
|
|
|
#ifdef WDCDEBUG
|
1998-10-13 12:59:45 +04:00
|
|
|
int wdcdebug_mask = 0;
|
1998-10-12 20:09:10 +04:00
|
|
|
int wdc_nxfer = 0;
|
|
|
|
#define WDCDEBUG_PRINT(args, level) if (wdcdebug_mask & (level)) printf args
|
1997-08-27 15:22:52 +04:00
|
|
|
#else
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WDCDEBUG_PRINT(args, level)
|
1997-08-27 15:22:52 +04:00
|
|
|
#endif
|
|
|
|
|
2003-12-30 19:28:37 +03:00
|
|
|
/*
|
|
|
|
* A queue of atabus instances, used to ensure the same bus probe order
|
|
|
|
* for a given hardware configuration at each boot.
|
|
|
|
*/
|
|
|
|
struct atabus_initq_head atabus_initq_head =
|
|
|
|
TAILQ_HEAD_INITIALIZER(atabus_initq_head);
|
|
|
|
struct simplelock atabus_interlock = SIMPLELOCK_INITIALIZER;
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2004-05-26 00:42:40 +04:00
|
|
|
/*
|
|
|
|
* Initialize the "shadow register" handles for a standard wdc controller.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wdc_init_shadow_regs(struct wdc_channel *chp)
|
|
|
|
{
|
|
|
|
|
|
|
|
chp->cmd_iohs[wd_status] = chp->cmd_iohs[wd_command];
|
|
|
|
chp->cmd_iohs[wd_features] = chp->cmd_iohs[wd_error];
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:28:37 +03:00
|
|
|
/* Test to see controller with at last one attached drive is there.
|
|
|
|
* Returns a bit for each possible drive found (0x01 for drive 0,
|
|
|
|
* 0x02 for drive 1).
|
|
|
|
* Logic:
|
|
|
|
* - If a status register is at 0xff, assume there is no drive here
|
|
|
|
* (ISA has pull-up resistors). Similarly if the status register has
|
|
|
|
* the value we last wrote to the bus (for IDE interfaces without pullups).
|
|
|
|
* If no drive at all -> return.
|
|
|
|
* - reset the controller, wait for it to complete (may take up to 31s !).
|
|
|
|
* If timeout -> return.
|
|
|
|
* - test ATA/ATAPI signatures. If at last one drive found -> return.
|
|
|
|
* - try an ATA command on the master.
|
|
|
|
*/
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2003-12-30 20:18:11 +03:00
|
|
|
static void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_drvprobe(struct wdc_channel *chp)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1999-03-10 16:11:43 +03:00
|
|
|
struct ataparams params;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-10-25 12:30:46 +04:00
|
|
|
u_int8_t st0 = 0, st1 = 0;
|
2003-12-30 20:18:11 +03:00
|
|
|
int i, error;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
2003-12-30 20:18:11 +03:00
|
|
|
if (wdcprobe1(chp, 0) == 0) {
|
|
|
|
/* No drives, abort the attach here. */
|
|
|
|
return;
|
2003-12-15 03:27:13 +03:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* for ATA/OLD drives, wait for DRDY, 3s timeout */
|
|
|
|
for (i = 0; i < mstohz(3000); i++) {
|
2004-05-15 21:15:09 +04:00
|
|
|
if (chp->ch_drive[0].drive_flags & (DRIVE_ATA|DRIVE_OLD)) {
|
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM);
|
|
|
|
delay(10); /* 400ns delay */
|
|
|
|
st0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2004-05-15 21:15:09 +04:00
|
|
|
if (chp->ch_drive[1].drive_flags & (DRIVE_ATA|DRIVE_OLD)) {
|
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,1);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM | 0x10);
|
|
|
|
delay(10); /* 400ns delay */
|
|
|
|
st1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
if (((chp->ch_drive[0].drive_flags & (DRIVE_ATA|DRIVE_OLD))
|
|
|
|
== 0 ||
|
|
|
|
(st0 & WDCS_DRDY)) &&
|
|
|
|
((chp->ch_drive[1].drive_flags & (DRIVE_ATA|DRIVE_OLD))
|
|
|
|
== 0 ||
|
|
|
|
(st1 & WDCS_DRDY)))
|
|
|
|
break;
|
2003-12-30 20:18:11 +03:00
|
|
|
tsleep(¶ms, PRIBIO, "atadrdy", 1);
|
1999-03-10 16:11:43 +03:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
if ((st0 & WDCS_DRDY) == 0)
|
|
|
|
chp->ch_drive[0].drive_flags &= ~(DRIVE_ATA|DRIVE_OLD);
|
|
|
|
if ((st1 & WDCS_DRDY) == 0)
|
|
|
|
chp->ch_drive[1].drive_flags &= ~(DRIVE_ATA|DRIVE_OLD);
|
|
|
|
|
|
|
|
WDCDEBUG_PRINT(("%s:%d: wait DRDY st0 0x%x st1 0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, st0, st1), DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
/* Wait a bit, some devices are weird just after a reset. */
|
|
|
|
delay(5000);
|
1999-03-10 16:11:43 +03:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2004-01-08 01:03:56 +03:00
|
|
|
/* XXX This should be done by other code. */
|
1999-03-10 16:11:43 +03:00
|
|
|
chp->ch_drive[i].chnl_softc = chp;
|
|
|
|
chp->ch_drive[i].drive = i;
|
2004-01-08 01:03:56 +03:00
|
|
|
|
2000-01-17 03:01:00 +03:00
|
|
|
/*
|
|
|
|
* Init error counter so that an error withing the first xfers
|
|
|
|
* will trigger a downgrade
|
|
|
|
*/
|
|
|
|
chp->ch_drive[i].n_dmaerrs = NERRS_MAX-1;
|
|
|
|
|
1999-03-10 16:11:43 +03:00
|
|
|
/* If controller can't do 16bit flag the drives as 32bit */
|
2004-01-04 01:56:52 +03:00
|
|
|
if ((wdc->cap &
|
1999-03-10 16:11:43 +03:00
|
|
|
(WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32)) ==
|
|
|
|
WDC_CAPABILITY_DATA32)
|
|
|
|
chp->ch_drive[i].drive_flags |= DRIVE_CAP32;
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
if ((chp->ch_drive[i].drive_flags & DRIVE) == 0)
|
|
|
|
continue;
|
1999-03-10 16:11:43 +03:00
|
|
|
|
2003-10-23 03:59:00 +04:00
|
|
|
/* Shortcut in case we've been shutdown */
|
|
|
|
if (chp->ch_flags & WDCF_SHUTDOWN)
|
2003-12-30 20:18:11 +03:00
|
|
|
return;
|
2003-10-23 03:59:00 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* issue an identify, to try to detect ghosts */
|
2003-10-07 01:51:31 +04:00
|
|
|
error = ata_get_params(&chp->ch_drive[i],
|
2003-10-08 14:58:12 +04:00
|
|
|
AT_WAIT | AT_POLL, ¶ms);
|
2000-04-04 13:25:51 +04:00
|
|
|
if (error != CMD_OK) {
|
2003-12-30 20:18:11 +03:00
|
|
|
tsleep(¶ms, PRIBIO, "atacnf", mstohz(1000));
|
2003-10-23 03:59:00 +04:00
|
|
|
|
|
|
|
/* Shortcut in case we've been shutdown */
|
|
|
|
if (chp->ch_flags & WDCF_SHUTDOWN)
|
2003-12-30 20:18:11 +03:00
|
|
|
return;
|
2003-10-23 03:59:00 +04:00
|
|
|
|
2003-10-07 01:51:31 +04:00
|
|
|
error = ata_get_params(&chp->ch_drive[i],
|
2003-10-08 14:58:12 +04:00
|
|
|
AT_WAIT | AT_POLL, ¶ms);
|
2000-04-04 13:25:51 +04:00
|
|
|
}
|
1999-11-28 23:04:22 +03:00
|
|
|
if (error == CMD_OK) {
|
2003-11-02 14:07:44 +03:00
|
|
|
/* If IDENTIFY succeeded, this is not an OLD ctrl */
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
chp->ch_drive[0].drive_flags &= ~DRIVE_OLD;
|
|
|
|
chp->ch_drive[1].drive_flags &= ~DRIVE_OLD;
|
|
|
|
} else {
|
2003-11-17 23:01:35 +03:00
|
|
|
chp->ch_drive[i].drive_flags &=
|
1999-03-10 16:11:43 +03:00
|
|
|
~(DRIVE_ATA | DRIVE_ATAPI);
|
1999-11-28 23:04:22 +03:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:%d: IDENTIFY failed (%d)\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, i, error), DEBUG_PROBE);
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
if ((chp->ch_drive[i].drive_flags & DRIVE_OLD) == 0)
|
|
|
|
continue;
|
1999-06-23 23:00:17 +04:00
|
|
|
/*
|
|
|
|
* Pre-ATA drive ?
|
|
|
|
* Test registers writability (Error register not
|
|
|
|
* writable, but cyllo is), then try an ATA command.
|
|
|
|
*/
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,i);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sdh], 0, WDSD_IBM | (i << 4));
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
delay(10); /* 400ns delay */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_error],
|
|
|
|
0, 0x58);
|
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0, 0xa5);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_error], 0) == 0x58 ||
|
|
|
|
bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0xa5) {
|
1999-06-23 23:00:17 +04:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:%d: register "
|
|
|
|
"writability failed\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, i), DEBUG_PROBE);
|
1999-06-23 23:00:17 +04:00
|
|
|
chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;
|
2003-11-17 23:01:35 +03:00
|
|
|
continue;
|
1999-06-23 23:00:17 +04:00
|
|
|
}
|
2004-01-01 23:25:22 +03:00
|
|
|
if (wdc_wait_for_ready(chp, 10000, 0) == WDCWAIT_TOUT) {
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:%d: not ready\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, i), DEBUG_PROBE);
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;
|
|
|
|
continue;
|
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_command], 0, WDCC_RECAL);
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
delay(10); /* 400ns delay */
|
2004-01-01 23:25:22 +03:00
|
|
|
if (wdc_wait_for_ready(chp, 10000, 0) == WDCWAIT_TOUT) {
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:%d: WDCC_RECAL failed\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, i), DEBUG_PROBE);
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
chp->ch_drive[i].drive_flags &= ~DRIVE_OLD;
|
2003-11-17 23:01:35 +03:00
|
|
|
} else {
|
|
|
|
chp->ch_drive[0].drive_flags &=
|
|
|
|
~(DRIVE_ATA | DRIVE_ATAPI);
|
|
|
|
chp->ch_drive[1].drive_flags &=
|
|
|
|
~(DRIVE_ATA | DRIVE_ATAPI);
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
}
|
1999-03-10 16:11:43 +03:00
|
|
|
}
|
|
|
|
}
|
2003-12-30 20:18:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
atabusconfig(struct atabus_softc *atabus_sc)
|
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = atabus_sc->sc_chan;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-08-11 03:09:38 +04:00
|
|
|
int i;
|
2003-12-30 20:18:11 +03:00
|
|
|
struct atabus_initq *atabus_initq = NULL;
|
|
|
|
|
|
|
|
/* Probe for the drives. */
|
2004-01-04 01:56:52 +03:00
|
|
|
(*wdc->drv_probe)(chp);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
WDCDEBUG_PRINT(("atabusattach: 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 out;
|
|
|
|
|
2003-12-30 20:18:11 +03:00
|
|
|
/* Shortcut in case we've been shutdown */
|
|
|
|
if (chp->ch_flags & WDCF_SHUTDOWN)
|
|
|
|
goto out;
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* Make sure the devices probe in atabus order to avoid jitter. */
|
|
|
|
simple_lock(&atabus_interlock);
|
|
|
|
while(1) {
|
|
|
|
atabus_initq = TAILQ_FIRST(&atabus_initq_head);
|
|
|
|
if (atabus_initq->atabus_sc == atabus_sc)
|
|
|
|
break;
|
|
|
|
ltsleep(&atabus_initq_head, PRIBIO, "ata_initq", 0,
|
|
|
|
&atabus_interlock);
|
|
|
|
}
|
|
|
|
simple_unlock(&atabus_interlock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach an ATAPI bus, if needed.
|
|
|
|
*/
|
|
|
|
if ((chp->ch_drive[0].drive_flags & DRIVE_ATAPI) ||
|
|
|
|
(chp->ch_drive[1].drive_flags & DRIVE_ATAPI)) {
|
|
|
|
#if NATAPIBUS > 0
|
|
|
|
wdc_atapibus_attach(atabus_sc);
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Fake the autoconfig "not configured" message
|
|
|
|
*/
|
|
|
|
aprint_normal("atapibus at %s not configured\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname);
|
2003-10-08 14:58:12 +04:00
|
|
|
chp->atapibus = NULL;
|
2003-10-15 23:54:30 +04:00
|
|
|
chp->ch_drive[0].drive_flags &= ~DRIVE_ATAPI;
|
|
|
|
chp->ch_drive[1].drive_flags &= ~DRIVE_ATAPI;
|
2003-10-08 14:58:12 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
struct ata_device adev;
|
|
|
|
if ((chp->ch_drive[i].drive_flags &
|
|
|
|
(DRIVE_ATA | DRIVE_OLD)) == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memset(&adev, 0, sizeof(struct ata_device));
|
|
|
|
adev.adev_bustype = &wdc_ata_bustype;
|
2004-01-04 01:56:52 +03:00
|
|
|
adev.adev_channel = chp->ch_channel;
|
2003-10-08 14:58:12 +04:00
|
|
|
adev.adev_openings = 1;
|
|
|
|
adev.adev_drv_data = &chp->ch_drive[i];
|
|
|
|
chp->ata_drives[i] = config_found(&atabus_sc->sc_dev,
|
2003-12-30 19:28:37 +03:00
|
|
|
&adev, ataprint);
|
2003-10-15 23:54:30 +04:00
|
|
|
if (chp->ata_drives[i] != NULL)
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_probe_caps(&chp->ch_drive[i]);
|
2003-10-15 23:54:30 +04:00
|
|
|
else
|
|
|
|
chp->ch_drive[i].drive_flags &=
|
|
|
|
~(DRIVE_ATA | DRIVE_OLD);
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now that we know the drives, the controller can set its modes */
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_MODE) {
|
|
|
|
wdc->set_modes(chp);
|
2004-08-13 00:59:27 +04:00
|
|
|
ata_print_modes(chp);
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
#if NATARAID > 0
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_RAID)
|
2003-10-08 14:58:12 +04:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
if (chp->ata_drives[i] != NULL)
|
|
|
|
ata_raid_check_component(chp->ata_drives[i]);
|
|
|
|
#endif /* NATARAID > 0 */
|
|
|
|
|
|
|
|
/*
|
2003-11-02 14:07:44 +03:00
|
|
|
* reset drive_flags for unattached devices, reset state for attached
|
2003-10-08 14:58:12 +04:00
|
|
|
* ones
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (chp->ch_drive[i].drv_softc == NULL)
|
|
|
|
chp->ch_drive[i].drive_flags = 0;
|
|
|
|
else
|
|
|
|
chp->ch_drive[i].state = 0;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:40:12 +03:00
|
|
|
out:
|
2003-10-08 14:58:12 +04:00
|
|
|
if (atabus_initq == NULL) {
|
|
|
|
simple_lock(&atabus_interlock);
|
|
|
|
while(1) {
|
|
|
|
atabus_initq = TAILQ_FIRST(&atabus_initq_head);
|
|
|
|
if (atabus_initq->atabus_sc == atabus_sc)
|
|
|
|
break;
|
|
|
|
ltsleep(&atabus_initq_head, PRIBIO, "ata_initq", 0,
|
|
|
|
&atabus_interlock);
|
|
|
|
}
|
|
|
|
simple_unlock(&atabus_interlock);
|
|
|
|
}
|
|
|
|
simple_lock(&atabus_interlock);
|
|
|
|
TAILQ_REMOVE(&atabus_initq_head, atabus_initq, atabus_initq);
|
|
|
|
simple_unlock(&atabus_interlock);
|
|
|
|
|
|
|
|
free(atabus_initq, M_DEVBUF);
|
|
|
|
wakeup(&atabus_initq_head);
|
|
|
|
|
2004-08-11 03:09:38 +04:00
|
|
|
wdc_delref(chp);
|
2004-08-12 18:36:46 +04:00
|
|
|
|
|
|
|
config_pending_decr();
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcprobe(struct wdc_channel *chp)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
2003-12-30 19:40:12 +03:00
|
|
|
|
|
|
|
return (wdcprobe1(chp, 1));
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
2004-01-02 00:18:28 +03:00
|
|
|
static int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcprobe1(struct wdc_channel *chp, int poll)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-10-08 14:58:12 +04:00
|
|
|
u_int8_t st0, st1, sc, sn, cl, ch;
|
|
|
|
u_int8_t ret_value = 0x03;
|
|
|
|
u_int8_t drive;
|
2003-11-26 00:03:15 +03:00
|
|
|
int s;
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check to see if the wdc channel responds at all.
|
|
|
|
*/
|
|
|
|
|
2004-05-15 21:15:09 +04:00
|
|
|
s = splbio();
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc == NULL ||
|
|
|
|
(wdc->cap & WDC_CAPABILITY_NO_EXTRA_RESETS) == 0) {
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
2003-10-08 14:58:12 +04:00
|
|
|
WDSD_IBM);
|
|
|
|
delay(10); /* 400ns delay */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
st0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,1);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
2003-10-08 14:58:12 +04:00
|
|
|
WDSD_IBM | 0x10);
|
|
|
|
delay(10); /* 400ns delay */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
st1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
WDCDEBUG_PRINT(("%s:%d: before reset, st0=0x%x, st1=0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, st0, st1), DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2003-10-16 00:26:33 +04:00
|
|
|
if (st0 == 0xff || st0 == WDSD_IBM)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2003-10-16 00:26:33 +04:00
|
|
|
if (st1 == 0xff || st1 == (WDSD_IBM | 0x10))
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
|
|
|
/* Register writability test, drive 0. */
|
|
|
|
if (ret_value & 0x01) {
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM);
|
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0, 0x02);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x02) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 0 wd_cyl_lo: "
|
|
|
|
"got 0x%x != 0x02\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0, 0x01);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 0 wd_cyl_lo: "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
2004-01-02 00:18:28 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0, 0x01);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 0 wd_sector: "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0, 0x02);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
if (cl != 0x02) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 0 wd_sector: "
|
|
|
|
"got 0x%x != 0x02\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 0 wd_cyl_lo(2): "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
/* Register writability test, drive 1. */
|
|
|
|
if (ret_value & 0x02) {
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,1);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM | 0x10);
|
2004-01-02 00:18:28 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0, 0x02);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x02) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 1 wd_cyl_lo: "
|
|
|
|
"got 0x%x != 0x02\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0, 0x01);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 1 wd_cyl_lo: "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0, 0x01);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 1 wd_sector: "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
2004-01-02 00:18:28 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0, 0x02);
|
2004-05-15 21:15:09 +04:00
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
if (cl != 0x02) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 1 wd_sector: "
|
|
|
|
"got 0x%x != 0x02\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
if (cl != 0x01) {
|
|
|
|
WDCDEBUG_PRINT(("%s:%d drive 1 wd_cyl_lo(2): "
|
|
|
|
"got 0x%x != 0x01\n",
|
|
|
|
wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, cl),
|
|
|
|
DEBUG_PROBE);
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
2004-05-15 21:15:09 +04:00
|
|
|
if (ret_value == 0) {
|
|
|
|
splx(s);
|
2003-10-08 14:58:12 +04:00
|
|
|
return 0;
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2004-05-15 21:15:09 +04:00
|
|
|
|
2004-06-24 01:10:52 +04:00
|
|
|
#if 0 /* XXX this break some ATA or ATAPI devices */
|
2004-05-15 21:15:09 +04:00
|
|
|
/*
|
|
|
|
* reset bus. Also send an ATAPI_RESET to devices, in case there are
|
|
|
|
* ATAPI device out there which don't react to the bus reset
|
|
|
|
*/
|
|
|
|
if (ret_value & 0x01) {
|
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_command], 0,
|
|
|
|
ATAPI_SOFT_RESET);
|
|
|
|
}
|
|
|
|
if (ret_value & 0x02) {
|
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM | 0x10);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_command], 0,
|
|
|
|
ATAPI_SOFT_RESET);
|
|
|
|
}
|
2003-11-26 00:03:15 +03:00
|
|
|
|
2004-05-25 00:45:30 +04:00
|
|
|
delay(5000);
|
2004-06-24 01:10:52 +04:00
|
|
|
#endif
|
2004-05-25 00:45:30 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
wdc->select(chp,0);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0, WDSD_IBM);
|
2003-10-08 14:58:12 +04:00
|
|
|
delay(10); /* 400ns delay */
|
2004-05-15 21:15:09 +04:00
|
|
|
/* assert SRST, wait for reset to complete */
|
2003-10-08 14:58:12 +04:00
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_RST | WDCTL_IDS | WDCTL_4BIT);
|
2004-03-25 22:45:09 +03:00
|
|
|
DELAY(1000);
|
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_IDS | WDCTL_4BIT);
|
2003-10-08 14:58:12 +04:00
|
|
|
DELAY(2000);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
(void) bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_error], 0);
|
2003-10-08 14:58:12 +04:00
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr, WDCTL_4BIT);
|
|
|
|
delay(10); /* 400ns delay */
|
2003-11-26 00:03:15 +03:00
|
|
|
/* ACK interrupt in case there is one pending left (Promise ATA100) */
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && (wdc->cap & WDC_CAPABILITY_IRQACK))
|
|
|
|
wdc->irqack(chp);
|
2003-11-26 00:03:15 +03:00
|
|
|
splx(s);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value = __wdcwait_reset(chp, ret_value, poll);
|
|
|
|
WDCDEBUG_PRINT(("%s:%d: after reset, ret_value=0x%d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe", chp->ch_channel,
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value), DEBUG_PROBE);
|
|
|
|
|
|
|
|
/* if reset failed, there's nothing here */
|
|
|
|
if (ret_value == 0)
|
|
|
|
return 0;
|
Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
of the probe (not necessary, but makes the probe/attach faster). This is
only set by the ISA front-end, all other controllers supported can't have
pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-12 00:50:28 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/*
|
2004-01-02 00:18:28 +03:00
|
|
|
* Test presence of drives. First test register signatures looking
|
|
|
|
* for ATAPI devices. If it's not an ATAPI and reset said there may
|
|
|
|
* be something here assume it's ATA or OLD. Ghost will be killed
|
|
|
|
* later in attach routine.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
2003-10-08 14:58:12 +04:00
|
|
|
for (drive = 0; drive < 2; drive++) {
|
|
|
|
if ((ret_value & (0x01 << drive)) == 0)
|
|
|
|
continue;
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc != NULL && wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,drive);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
2003-10-08 14:58:12 +04:00
|
|
|
WDSD_IBM | (drive << 4));
|
|
|
|
delay(10); /* 400ns delay */
|
|
|
|
/* Save registers contents */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
sc = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_seccnt], 0);
|
|
|
|
sn = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
cl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
ch = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_hi], 0);
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
WDCDEBUG_PRINT(("%s:%d:%d: after reset, sc=0x%x sn=0x%x "
|
|
|
|
"cl=0x%x ch=0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, drive, sc, sn, cl, ch), DEBUG_PROBE);
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
2003-10-08 14:58:12 +04:00
|
|
|
* sc & sn are supposted to be 0x1 for ATAPI but in some cases
|
|
|
|
* we get wrong values here, so ignore it.
|
1998-10-12 20:09:10 +04:00
|
|
|
*/
|
2003-10-08 14:58:12 +04:00
|
|
|
if (cl == 0x14 && ch == 0xeb) {
|
|
|
|
chp->ch_drive[drive].drive_flags |= DRIVE_ATAPI;
|
|
|
|
} else {
|
|
|
|
chp->ch_drive[drive].drive_flags |= DRIVE_ATA;
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc == NULL ||
|
|
|
|
(wdc->cap & WDC_CAPABILITY_PREATA) != 0)
|
2003-10-08 14:58:12 +04:00
|
|
|
chp->ch_drive[drive].drive_flags |= DRIVE_OLD;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
return (ret_value);
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcattach(struct wdc_channel *chp)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-10-08 14:58:12 +04:00
|
|
|
static int inited = 0;
|
1998-10-13 12:59:45 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
if (chp->ch_flags & WDCF_DISABLED)
|
|
|
|
return;
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2004-08-11 22:41:46 +04:00
|
|
|
/* default data transfer methods */
|
|
|
|
if (!wdc->datain_pio)
|
|
|
|
wdc->datain_pio = wdc_datain_pio;
|
|
|
|
if (!wdc->dataout_pio)
|
|
|
|
wdc->dataout_pio = wdc_dataout_pio;
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* initialise global data */
|
|
|
|
callout_init(&chp->ch_callout);
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->drv_probe == NULL)
|
|
|
|
wdc->drv_probe = wdc_drvprobe;
|
2003-10-08 14:58:12 +04:00
|
|
|
if (inited == 0) {
|
2004-01-01 20:18:53 +03:00
|
|
|
/* Initialize the ata_xfer pool. */
|
|
|
|
pool_init(&wdc_xfer_pool, sizeof(struct ata_xfer), 0,
|
2003-10-08 14:58:12 +04:00
|
|
|
0, 0, "wdcspl", NULL);
|
|
|
|
inited++;
|
|
|
|
}
|
2004-01-01 20:18:53 +03:00
|
|
|
TAILQ_INIT(&chp->ch_queue->queue_xfer);
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze = 0;
|
2004-08-04 22:24:10 +04:00
|
|
|
chp->ch_queue->active_xfer = NULL;
|
2003-09-20 06:19:36 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
chp->atabus = config_found(&wdc->sc_dev, chp, atabusprint);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:40:12 +03:00
|
|
|
int
|
|
|
|
wdcactivate(struct device *self, enum devact act)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
|
|
|
struct wdc_softc *wdc = (struct wdc_softc *)self;
|
|
|
|
int s, i, error = 0;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
for (i = 0; i < wdc->nchannels; i++) {
|
|
|
|
error = config_deactivate(wdc->channels[i]->atabus);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-12-30 19:40:12 +03:00
|
|
|
wdcdetach(struct device *self, int flags)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
|
|
|
struct wdc_softc *wdc = (struct wdc_softc *)self;
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp;
|
2004-08-10 06:40:51 +04:00
|
|
|
struct scsipi_adapter *adapt = &wdc->sc_atapi_adapter._generic;
|
2003-10-08 14:58:12 +04:00
|
|
|
int i, error = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < wdc->nchannels; i++) {
|
|
|
|
chp = wdc->channels[i];
|
|
|
|
WDCDEBUG_PRINT(("wdcdetach: %s: detaching %s\n",
|
|
|
|
wdc->sc_dev.dv_xname, chp->atabus->dv_xname), DEBUG_DETACH);
|
|
|
|
error = config_detach(chp->atabus, flags);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
2004-08-10 06:40:51 +04:00
|
|
|
if (adapt->adapt_refcnt != 0) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("wdcdetach: refcnt should be 0 here??\n");
|
|
|
|
#endif
|
|
|
|
(void) (*adapt->adapt_enable)(&wdc->sc_dev, 0);
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/*
|
1998-10-12 20:09:10 +04:00
|
|
|
* Start I/O on a controller, for the given channel.
|
|
|
|
* The first xfer may be not for our channel if the channel queues
|
|
|
|
* are shared.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcstart(struct wdc_channel *chp)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *xfer;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-21 13:12:46 +04:00
|
|
|
#ifdef WDC_DIAGNOSTIC
|
|
|
|
int spl1, spl2;
|
|
|
|
|
|
|
|
spl1 = splbio();
|
|
|
|
spl2 = splbio();
|
|
|
|
if (spl2 != spl1) {
|
|
|
|
printf("wdcstart: not at splbio()\n");
|
|
|
|
panic("wdcstart");
|
|
|
|
}
|
|
|
|
splx(spl2);
|
|
|
|
splx(spl1);
|
|
|
|
#endif /* WDC_DIAGNOSTIC */
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/* is there a xfer ? */
|
2004-01-01 20:18:53 +03:00
|
|
|
if ((xfer = TAILQ_FIRST(&chp->ch_queue->queue_xfer)) == NULL)
|
1997-08-27 15:22:52 +04:00
|
|
|
return;
|
1998-11-29 20:34:49 +03:00
|
|
|
|
|
|
|
/* adjust chp, in case we have a shared queue */
|
2004-01-01 20:18:53 +03:00
|
|
|
chp = xfer->c_chp;
|
1998-11-29 20:34:49 +03:00
|
|
|
|
2004-08-04 22:24:10 +04:00
|
|
|
if (chp->ch_queue->active_xfer != NULL) {
|
1998-10-12 20:09:10 +04:00
|
|
|
return; /* channel aleady active */
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2003-10-30 01:05:15 +03:00
|
|
|
if (__predict_false(chp->ch_queue->queue_freeze > 0)) {
|
2003-10-30 00:44:41 +03:00
|
|
|
return; /* queue froozen */
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((chp->ch_flags & WDCF_IRQ_WAIT) != 0)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("wdcstart: channel waiting for irq");
|
1998-10-12 20:09:10 +04:00
|
|
|
#endif
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_HWLOCK)
|
|
|
|
if (!(*wdc->claim_hw)(chp, 0))
|
1998-04-07 23:51:57 +04:00
|
|
|
return;
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdcstart: xfer %p channel %d drive %d\n", xfer,
|
2004-01-04 01:56:52 +03:00
|
|
|
chp->ch_channel, xfer->c_drive), DEBUG_XFERS);
|
2004-01-01 20:18:53 +03:00
|
|
|
if (chp->ch_drive[xfer->c_drive].drive_flags & DRIVE_RESET) {
|
|
|
|
chp->ch_drive[xfer->c_drive].drive_flags &= ~DRIVE_RESET;
|
|
|
|
chp->ch_drive[xfer->c_drive].state = 0;
|
1998-10-20 21:00:26 +04:00
|
|
|
}
|
2004-08-04 22:24:10 +04:00
|
|
|
chp->ch_queue->active_xfer = xfer;
|
|
|
|
TAILQ_REMOVE(&chp->ch_queue->queue_xfer, xfer, c_xferchain);
|
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_NOIRQ)
|
2001-06-13 22:17:38 +04:00
|
|
|
KASSERT(xfer->c_flags & C_POLL);
|
1998-10-12 20:09:10 +04:00
|
|
|
xfer->c_start(chp, xfer);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* restart an interrupted I/O */
|
|
|
|
void
|
2003-12-30 19:40:12 +03:00
|
|
|
wdcrestart(void *v)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = v;
|
1998-10-12 20:09:10 +04:00
|
|
|
int s;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
s = splbio();
|
1998-11-21 18:41:41 +03:00
|
|
|
wdcstart(chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
splx(s);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* Interrupt routine for the controller. Acknowledge the interrupt, check for
|
|
|
|
* errors on the current operation, mark it done if necessary, and start the
|
|
|
|
* next request. Also check for a partially done transfer, and continue with
|
|
|
|
* the next chunk if so.
|
|
|
|
*/
|
|
|
|
int
|
2003-12-30 19:40:12 +03:00
|
|
|
wdcintr(void *arg)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = arg;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *xfer;
|
1999-10-21 18:37:58 +04:00
|
|
|
int ret;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if ((wdc->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
|
2000-03-21 01:53:36 +03:00
|
|
|
WDCDEBUG_PRINT(("wdcintr: deactivated controller\n"),
|
|
|
|
DEBUG_INTR);
|
|
|
|
return (0);
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((chp->ch_flags & WDCF_IRQ_WAIT) == 0) {
|
|
|
|
WDCDEBUG_PRINT(("wdcintr: inactive controller\n"), DEBUG_INTR);
|
2002-03-29 01:51:58 +03:00
|
|
|
/* try to clear the pending interrupt anyway */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
(void)bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
2000-03-21 01:53:36 +03:00
|
|
|
return (0);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdcintr\n"), DEBUG_INTR);
|
2004-08-04 22:24:10 +04:00
|
|
|
xfer = chp->ch_queue->active_xfer;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (xfer == NULL)
|
|
|
|
panic("wdcintr: no xfer");
|
|
|
|
#endif
|
2000-04-01 18:32:22 +04:00
|
|
|
if (chp->ch_flags & WDCF_DMA_WAIT) {
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->dma_status =
|
|
|
|
(*wdc->dma_finish)(wdc->dma_arg, chp->ch_channel,
|
2004-08-03 02:20:54 +04:00
|
|
|
xfer->c_drive, WDC_DMAEND_END);
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->dma_status & WDC_DMAST_NOIRQ) {
|
2000-04-01 18:32:22 +04:00
|
|
|
/* IRQ not for us, not detected by DMA engine */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
chp->ch_flags &= ~WDCF_DMA_WAIT;
|
|
|
|
}
|
|
|
|
chp->ch_flags &= ~WDCF_IRQ_WAIT;
|
1999-10-21 18:37:58 +04:00
|
|
|
ret = xfer->c_intr(chp, xfer, 1);
|
|
|
|
if (ret == 0) /* irq was not for us, still waiting for irq */
|
|
|
|
chp->ch_flags |= WDCF_IRQ_WAIT;
|
|
|
|
return (ret);
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put all disk in RESET state */
|
2003-09-20 01:35:56 +04:00
|
|
|
void
|
2004-08-02 01:40:41 +04:00
|
|
|
wdc_reset_drive(struct ata_drive_datas *drvp, int flags)
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = drvp->chnl_softc;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("ata_reset_channel %s:%d for drive %d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, drvp->drive),
|
1998-10-13 19:02:41 +04:00
|
|
|
DEBUG_FUNCS);
|
2004-08-01 01:26:42 +04:00
|
|
|
|
|
|
|
|
2004-08-02 01:40:41 +04:00
|
|
|
wdc_reset_channel(chp, flags);
|
2004-08-01 01:26:42 +04:00
|
|
|
}
|
|
|
|
|
2004-08-02 01:40:41 +04:00
|
|
|
void
|
|
|
|
wdc_reset_channel(struct wdc_channel *chp, int flags)
|
2004-08-01 01:26:42 +04:00
|
|
|
{
|
2004-08-04 22:24:10 +04:00
|
|
|
TAILQ_HEAD(, ata_xfer) reset_xfer;
|
2004-08-02 01:40:41 +04:00
|
|
|
struct ata_xfer *xfer, *next_xfer;
|
2004-08-01 01:26:42 +04:00
|
|
|
int drive;
|
|
|
|
|
2004-08-03 02:02:35 +04:00
|
|
|
chp->ch_queue->queue_freeze++;
|
2004-08-04 22:24:10 +04:00
|
|
|
TAILQ_INIT(&reset_xfer);
|
2004-08-03 02:02:35 +04:00
|
|
|
|
|
|
|
/* if we can poll or wait it's OK, otherwise wake up the kernel
|
|
|
|
* thread
|
|
|
|
*/
|
|
|
|
if ((flags & (AT_POLL | AT_WAIT)) == 0) {
|
|
|
|
if (chp->ch_flags & WDCF_TH_RESET) {
|
|
|
|
/* no need to schedule a reset more than one time */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
chp->ch_flags |= WDCF_TH_RESET;
|
|
|
|
chp->ch_reset_flags = flags & (AT_RST_EMERG | AT_RST_NOCMD);
|
|
|
|
wakeup(&chp->ch_thread);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chp->ch_flags &= ~WDCF_IRQ_WAIT;
|
2004-08-04 22:24:10 +04:00
|
|
|
/*
|
|
|
|
* if the current command if on an ATAPI device, issue a
|
|
|
|
* ATAPI_SOFT_RESET
|
|
|
|
*/
|
|
|
|
xfer = chp->ch_queue->active_xfer;
|
|
|
|
if (xfer && xfer->c_chp == chp && (xfer->c_flags & C_ATAPI)) {
|
|
|
|
wdccommandshort(chp, xfer->c_drive, ATAPI_SOFT_RESET);
|
|
|
|
if (flags & AT_WAIT)
|
|
|
|
tsleep(&flags, PRIBIO, "atardl", mstohz(1) + 1);
|
|
|
|
else
|
|
|
|
delay(1000);
|
2004-08-03 02:02:35 +04:00
|
|
|
}
|
|
|
|
|
2004-08-04 22:24:10 +04:00
|
|
|
/* reset the channel */
|
|
|
|
if (flags & AT_WAIT)
|
|
|
|
(void) wdcreset(chp, RESET_SLEEP);
|
|
|
|
else
|
|
|
|
(void) wdcreset(chp, RESET_POLL);
|
|
|
|
|
2004-08-03 02:02:35 +04:00
|
|
|
/*
|
2004-08-04 22:24:10 +04:00
|
|
|
* wait a bit after reset; in case the DMA engines needs some time
|
2004-08-03 02:02:35 +04:00
|
|
|
* to recover.
|
|
|
|
*/
|
|
|
|
if (flags & AT_WAIT)
|
2004-08-04 22:24:10 +04:00
|
|
|
tsleep(&flags, PRIBIO, "atardl", mstohz(1) + 1);
|
2004-08-03 02:02:35 +04:00
|
|
|
else
|
|
|
|
delay(1000);
|
2004-08-01 01:26:42 +04:00
|
|
|
/*
|
|
|
|
* look for pending xfers. If we have a shared queue, we'll also reset
|
|
|
|
* the other channel if the current xfer is running on it.
|
2004-08-03 02:02:35 +04:00
|
|
|
* Then we'll dequeue only the xfers for this channel.
|
2004-08-01 01:26:42 +04:00
|
|
|
*/
|
|
|
|
if ((flags & AT_RST_NOCMD) == 0) {
|
2004-08-04 22:24:10 +04:00
|
|
|
/*
|
|
|
|
* move all xfers queued for this channel to the reset queue,
|
|
|
|
* and then process the current xfer and then the reset queue.
|
|
|
|
* We have to use a temporary queue because c_kill_xfer()
|
|
|
|
* may requeue commands.
|
|
|
|
*/
|
|
|
|
for (xfer = TAILQ_FIRST(&chp->ch_queue->queue_xfer);
|
|
|
|
xfer != NULL; xfer = next_xfer) {
|
|
|
|
next_xfer = TAILQ_NEXT(xfer, c_xferchain);
|
|
|
|
if (xfer->c_chp != chp)
|
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&chp->ch_queue->queue_xfer,
|
|
|
|
xfer, c_xferchain);
|
|
|
|
TAILQ_INSERT_TAIL(&reset_xfer, xfer, c_xferchain);
|
|
|
|
}
|
|
|
|
xfer = chp->ch_queue->active_xfer;
|
2004-08-03 02:02:35 +04:00
|
|
|
if (xfer) {
|
|
|
|
if (xfer->c_chp != chp)
|
|
|
|
wdc_reset_channel(xfer->c_chp, flags);
|
|
|
|
else {
|
2004-08-04 22:24:10 +04:00
|
|
|
callout_stop(&chp->ch_callout);
|
2004-08-03 02:02:35 +04:00
|
|
|
/*
|
|
|
|
* If we're waiting for DMA, stop the
|
|
|
|
* DMA engine
|
|
|
|
*/
|
|
|
|
if (chp->ch_flags & WDCF_DMA_WAIT) {
|
|
|
|
(*chp->ch_wdc->dma_finish)(
|
|
|
|
chp->ch_wdc->dma_arg,
|
|
|
|
chp->ch_channel,
|
|
|
|
xfer->c_drive,
|
2004-08-03 02:20:54 +04:00
|
|
|
WDC_DMAEND_ABRT_QUIET);
|
2004-08-04 22:24:10 +04:00
|
|
|
chp->ch_flags &= ~WDCF_DMA_WAIT;
|
2004-08-03 02:02:35 +04:00
|
|
|
}
|
2004-08-04 22:24:10 +04:00
|
|
|
chp->ch_queue->active_xfer = NULL;
|
|
|
|
if ((flags & AT_RST_EMERG) == 0)
|
|
|
|
xfer->c_kill_xfer(
|
|
|
|
chp, xfer, KILL_RESET);
|
2004-08-03 02:02:35 +04:00
|
|
|
}
|
|
|
|
}
|
2004-08-04 22:24:10 +04:00
|
|
|
|
|
|
|
for (xfer = TAILQ_FIRST(&reset_xfer);
|
2004-08-02 01:40:41 +04:00
|
|
|
xfer != NULL; xfer = next_xfer) {
|
|
|
|
next_xfer = TAILQ_NEXT(xfer, c_xferchain);
|
2004-08-04 22:24:10 +04:00
|
|
|
TAILQ_REMOVE(&reset_xfer, xfer, c_xferchain);
|
2004-08-01 01:26:42 +04:00
|
|
|
if ((flags & AT_RST_EMERG) == 0)
|
|
|
|
xfer->c_kill_xfer(chp, xfer, KILL_RESET);
|
|
|
|
}
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
for (drive = 0; drive < 2; drive++) {
|
|
|
|
chp->ch_drive[drive].state = 0;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2004-08-03 02:02:35 +04:00
|
|
|
chp->ch_flags &= ~WDCF_TH_RESET;
|
2004-08-01 01:26:42 +04:00
|
|
|
if ((flags & AT_RST_EMERG) == 0) {
|
|
|
|
chp->ch_queue->queue_freeze--;
|
|
|
|
wdcstart(chp);
|
|
|
|
} else {
|
|
|
|
/* make sure that we can use polled commands */
|
|
|
|
TAILQ_INIT(&chp->ch_queue->queue_xfer);
|
|
|
|
chp->ch_queue->queue_freeze = 0;
|
2004-08-04 22:24:10 +04:00
|
|
|
chp->ch_queue->active_xfer = NULL;
|
2004-08-01 01:26:42 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcreset(struct wdc_channel *chp, int poll)
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1998-10-12 20:09:10 +04:00
|
|
|
int drv_mask1, drv_mask2;
|
2003-11-26 00:03:15 +03:00
|
|
|
int s = 0;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,0);
|
2003-11-26 00:03:15 +03:00
|
|
|
if (poll != RESET_SLEEP)
|
|
|
|
s = splbio();
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
/* master */
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0, WDSD_IBM);
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
delay(10); /* 400ns delay */
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
WDCTL_RST | WDCTL_IDS | WDCTL_4BIT);
|
|
|
|
delay(2000);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
(void) bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_error], 0);
|
2003-10-08 14:58:12 +04:00
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_4BIT | WDCTL_IDS);
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
delay(10); /* 400ns delay */
|
2003-11-26 00:03:15 +03:00
|
|
|
if (poll != RESET_SLEEP) {
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_IRQACK)
|
|
|
|
wdc->irqack(chp);
|
2003-11-26 00:03:15 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
drv_mask1 = (chp->ch_drive[0].drive_flags & DRIVE) ? 0x01:0x00;
|
|
|
|
drv_mask1 |= (chp->ch_drive[1].drive_flags & DRIVE) ? 0x02:0x00;
|
2003-10-08 14:58:12 +04:00
|
|
|
drv_mask2 = __wdcwait_reset(chp, drv_mask1,
|
|
|
|
(poll == RESET_SLEEP) ? 0 : 1);
|
|
|
|
if (drv_mask2 != drv_mask1) {
|
1998-10-12 20:09:10 +04:00
|
|
|
printf("%s channel %d: reset failed for",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel);
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((drv_mask1 & 0x01) != 0 && (drv_mask2 & 0x01) == 0)
|
|
|
|
printf(" drive 0");
|
|
|
|
if ((drv_mask1 & 0x02) != 0 && (drv_mask2 & 0x02) == 0)
|
|
|
|
printf(" drive 1");
|
|
|
|
printf("\n");
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr, WDCTL_4BIT);
|
1998-10-12 20:09:10 +04:00
|
|
|
return (drv_mask1 != drv_mask2) ? 1 : 0;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
static int
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdcwait_reset(struct wdc_channel *chp, int drv_mask, int poll)
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-10-08 14:58:12 +04:00
|
|
|
int timeout, nloop;
|
2003-10-30 01:09:41 +03:00
|
|
|
u_int8_t st0 = 0, st1 = 0;
|
1999-08-06 16:00:23 +04:00
|
|
|
#ifdef WDCDEBUG
|
2003-10-25 12:37:00 +04:00
|
|
|
u_int8_t sc0 = 0, sn0 = 0, cl0 = 0, ch0 = 0;
|
|
|
|
u_int8_t sc1 = 0, sn1 = 0, cl1 = 0, ch1 = 0;
|
1999-08-06 16:00:23 +04:00
|
|
|
#endif
|
2003-10-08 14:58:12 +04:00
|
|
|
|
|
|
|
if (poll)
|
|
|
|
nloop = WDCNDELAY_RST;
|
|
|
|
else
|
|
|
|
nloop = WDC_RESET_WAIT * hz / 1000;
|
1998-10-12 20:09:10 +04:00
|
|
|
/* wait for BSY to deassert */
|
2003-10-08 14:58:12 +04:00
|
|
|
for (timeout = 0; timeout < nloop; timeout++) {
|
2004-05-15 21:15:09 +04:00
|
|
|
if ((drv_mask & 0x01) != 0) {
|
|
|
|
if (wdc && wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM); /* master */
|
|
|
|
delay(10);
|
|
|
|
st0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
1999-08-06 16:00:23 +04:00
|
|
|
#ifdef WDCDEBUG
|
2004-05-15 21:15:09 +04:00
|
|
|
sc0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_seccnt], 0);
|
|
|
|
sn0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
cl0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
ch0 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_hi], 0);
|
1999-08-06 16:00:23 +04:00
|
|
|
#endif
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
|
|
|
if ((drv_mask & 0x02) != 0) {
|
|
|
|
if (wdc && wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,1);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh],
|
|
|
|
0, WDSD_IBM | 0x10); /* slave */
|
|
|
|
delay(10);
|
|
|
|
st1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_status], 0);
|
1999-08-06 16:00:23 +04:00
|
|
|
#ifdef WDCDEBUG
|
2004-05-15 21:15:09 +04:00
|
|
|
sc1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_seccnt], 0);
|
|
|
|
sn1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
cl1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
ch1 = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_hi], 0);
|
1999-08-06 16:00:23 +04:00
|
|
|
#endif
|
2004-05-15 21:15:09 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
|
|
|
|
if ((drv_mask & 0x01) == 0) {
|
|
|
|
/* no master */
|
|
|
|
if ((drv_mask & 0x02) != 0 && (st1 & WDCS_BSY) == 0) {
|
|
|
|
/* No master, slave is ready, it's done */
|
1999-03-31 15:18:31 +04:00
|
|
|
goto end;
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
|
|
|
} else if ((drv_mask & 0x02) == 0) {
|
|
|
|
/* no slave */
|
|
|
|
if ((drv_mask & 0x01) != 0 && (st0 & WDCS_BSY) == 0) {
|
|
|
|
/* No slave, master is ready, it's done */
|
1999-03-31 15:18:31 +04:00
|
|
|
goto end;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
} else {
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Wait for both master and slave to be ready */
|
|
|
|
if ((st0 & WDCS_BSY) == 0 && (st1 & WDCS_BSY) == 0) {
|
1999-03-31 15:18:31 +04:00
|
|
|
goto end;
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
if (poll)
|
|
|
|
delay(WDCDELAY);
|
|
|
|
else
|
|
|
|
tsleep(&nloop, PRIBIO, "atarst", 1);
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
2002-07-26 18:10:22 +04:00
|
|
|
/* Reset timed out. Maybe it's because drv_mask was not right */
|
1998-10-12 20:09:10 +04:00
|
|
|
if (st0 & WDCS_BSY)
|
|
|
|
drv_mask &= ~0x01;
|
|
|
|
if (st1 & WDCS_BSY)
|
|
|
|
drv_mask &= ~0x02;
|
1999-03-31 15:18:31 +04:00
|
|
|
end:
|
1999-08-06 16:00:23 +04:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:0: after reset, sc=0x%x sn=0x%x "
|
|
|
|
"cl=0x%x ch=0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, sc0, sn0, cl0, ch0), DEBUG_PROBE);
|
1999-08-06 16:00:23 +04:00
|
|
|
WDCDEBUG_PRINT(("%s:%d:1: after reset, sc=0x%x sn=0x%x "
|
|
|
|
"cl=0x%x ch=0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->ch_channel, sc1, sn1, cl1, ch1), DEBUG_PROBE);
|
1999-08-06 16:00:23 +04:00
|
|
|
|
2003-10-30 01:09:41 +03:00
|
|
|
WDCDEBUG_PRINT(("%s:%d: wdcwait_reset() end, st0=0x%x st1=0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc != NULL ? wdc->sc_dev.dv_xname : "wdcprobe", chp->ch_channel,
|
2003-10-30 01:09:41 +03:00
|
|
|
st0, st1), DEBUG_PROBE);
|
1999-03-31 15:18:31 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
return drv_mask;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* Wait for a drive to be !BSY, and have mask in its status register.
|
|
|
|
* return -1 for a timeout after "timeout" ms.
|
|
|
|
*/
|
2004-01-02 00:18:28 +03:00
|
|
|
static int
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdcwait(struct wdc_channel *chp, int mask, int bits, int timeout)
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1998-10-12 20:09:10 +04:00
|
|
|
u_char status;
|
|
|
|
int time = 0;
|
1999-02-21 05:07:52 +03:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
WDCDEBUG_PRINT(("__wdcwait %s:%d\n", wdc != NULL ?
|
|
|
|
wdc->sc_dev.dv_xname : "none",
|
|
|
|
chp->ch_channel), DEBUG_STATUS);
|
1998-10-12 20:09:10 +04:00
|
|
|
chp->ch_error = 0;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
timeout = timeout * 1000 / WDCDELAY; /* delay uses microseconds */
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
for (;;) {
|
|
|
|
chp->ch_status = status =
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_status], 0);
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
if ((status & (WDCS_BSY | mask)) == bits)
|
1997-08-27 15:22:52 +04:00
|
|
|
break;
|
1998-10-12 20:09:10 +04:00
|
|
|
if (++time > timeout) {
|
2003-10-08 14:58:12 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdcwait: timeout (time=%d), "
|
2000-04-04 16:43:13 +04:00
|
|
|
"status %x error %x (mask 0x%x bits 0x%x)\n",
|
|
|
|
time, status,
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_error], 0), mask, bits),
|
2000-04-04 16:43:13 +04:00
|
|
|
DEBUG_STATUS | DEBUG_PROBE | DEBUG_DELAY);
|
2003-10-08 14:58:12 +04:00
|
|
|
return(WDCWAIT_TOUT);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
delay(WDCDELAY);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2000-04-04 16:43:13 +04:00
|
|
|
#ifdef WDCDEBUG
|
|
|
|
if (time > 0 && (wdcdebug_mask & DEBUG_DELAY))
|
2003-10-08 14:58:12 +04:00
|
|
|
printf("__wdcwait: did busy-wait, time=%d\n", time);
|
2000-04-04 16:43:13 +04:00
|
|
|
#endif
|
1998-10-12 20:09:10 +04:00
|
|
|
if (status & WDCS_ERR)
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
chp->ch_error = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_error], 0);
|
1998-10-12 20:09:10 +04:00
|
|
|
#ifdef WDCNDELAY_DEBUG
|
|
|
|
/* After autoconfig, there should be no long delays. */
|
|
|
|
if (!cold && time > WDCNDELAY_DEBUG) {
|
2004-08-04 22:24:10 +04:00
|
|
|
struct ata_xfer *xfer = chp->ch_queue->active_xfer;
|
1998-10-12 20:09:10 +04:00
|
|
|
if (xfer == NULL)
|
|
|
|
printf("%s channel %d: warning: busy-wait took %dus\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDELAY * time);
|
|
|
|
else
|
|
|
|
printf("%s:%d:%d: warning: busy-wait took %dus\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel,
|
1998-10-12 20:09:10 +04:00
|
|
|
xfer->drive,
|
|
|
|
WDCDELAY * time);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
#endif
|
2003-10-08 14:58:12 +04:00
|
|
|
return(WDCWAIT_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call __wdcwait(), polling using tsleep() or waking up the kernel
|
|
|
|
* thread if possible
|
|
|
|
*/
|
|
|
|
int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcwait(struct wdc_channel *chp, int mask, int bits, int timeout, int flags)
|
2003-10-08 14:58:12 +04:00
|
|
|
{
|
|
|
|
int error, i, timeout_hz = mstohz(timeout);
|
|
|
|
|
|
|
|
if (timeout_hz == 0 ||
|
|
|
|
(flags & (AT_WAIT | AT_POLL)) == AT_POLL)
|
|
|
|
error = __wdcwait(chp, mask, bits, timeout);
|
|
|
|
else {
|
|
|
|
error = __wdcwait(chp, mask, bits, WDCDELAY_POLL);
|
|
|
|
if (error != 0) {
|
2003-10-30 00:44:41 +03:00
|
|
|
if ((chp->ch_flags & WDCF_TH_RUN) ||
|
|
|
|
(flags & AT_WAIT)) {
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
2003-10-30 00:44:41 +03:00
|
|
|
* we're running in the channel thread
|
|
|
|
* or some userland thread context
|
2003-10-08 14:58:12 +04:00
|
|
|
*/
|
|
|
|
for (i = 0; i < timeout_hz; i++) {
|
|
|
|
if (__wdcwait(chp, mask, bits,
|
|
|
|
WDCDELAY_POLL) == 0) {
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tsleep(&chp, PRIBIO, "atapoll", 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* we're probably in interrupt context,
|
|
|
|
* ask the thread to come back here
|
|
|
|
*/
|
2003-10-30 00:44:41 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
2003-10-30 01:05:15 +03:00
|
|
|
if (chp->ch_queue->queue_freeze > 0)
|
|
|
|
panic("wdcwait: queue_freeze");
|
2003-10-30 00:44:41 +03:00
|
|
|
#endif
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze++;
|
2004-01-04 02:59:58 +03:00
|
|
|
wakeup(&chp->ch_thread);
|
2003-10-08 14:58:12 +04:00
|
|
|
return(WDCWAIT_THR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-12-30 19:40:12 +03:00
|
|
|
return (error);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2000-04-01 18:32:22 +04:00
|
|
|
/*
|
|
|
|
* Busy-wait for DMA to complete
|
|
|
|
*/
|
|
|
|
int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_dmawait(struct wdc_channel *chp, struct ata_xfer *xfer, int timeout)
|
2000-04-01 18:32:22 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2000-04-01 18:32:22 +04:00
|
|
|
int time;
|
2004-01-04 01:56:52 +03:00
|
|
|
|
2000-04-01 18:32:22 +04:00
|
|
|
for (time = 0; time < timeout * 1000 / WDCDELAY; time++) {
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->dma_status =
|
|
|
|
(*wdc->dma_finish)(wdc->dma_arg,
|
2004-08-03 02:20:54 +04:00
|
|
|
chp->ch_channel, xfer->c_drive, WDC_DMAEND_END);
|
2004-01-04 01:56:52 +03:00
|
|
|
if ((wdc->dma_status & WDC_DMAST_NOIRQ) == 0)
|
2000-04-01 18:32:22 +04:00
|
|
|
return 0;
|
|
|
|
delay(WDCDELAY);
|
|
|
|
}
|
|
|
|
/* timeout, force a DMA halt */
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->dma_status = (*wdc->dma_finish)(wdc->dma_arg,
|
2004-08-03 02:20:54 +04:00
|
|
|
chp->ch_channel, xfer->c_drive, WDC_DMAEND_ABRT);
|
2000-04-01 18:32:22 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
void
|
2003-12-30 19:40:12 +03:00
|
|
|
wdctimeout(void *arg)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = (struct wdc_channel *)arg;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-08-04 22:24:10 +04:00
|
|
|
struct ata_xfer *xfer = chp->ch_queue->active_xfer;
|
1998-10-12 20:09:10 +04:00
|
|
|
int s;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdctimeout\n"), DEBUG_FUNCS);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
s = splbio();
|
|
|
|
if ((chp->ch_flags & WDCF_IRQ_WAIT) != 0) {
|
|
|
|
__wdcerror(chp, "lost interrupt");
|
2000-04-05 10:27:36 +04:00
|
|
|
printf("\ttype: %s tc_bcount: %d tc_skip: %d\n",
|
|
|
|
(xfer->c_flags & C_ATAPI) ? "atapi" : "ata",
|
|
|
|
xfer->c_bcount,
|
|
|
|
xfer->c_skip);
|
2000-04-01 18:32:22 +04:00
|
|
|
if (chp->ch_flags & WDCF_DMA_WAIT) {
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->dma_status =
|
|
|
|
(*wdc->dma_finish)(wdc->dma_arg,
|
2004-08-03 02:20:54 +04:00
|
|
|
chp->ch_channel, xfer->c_drive,
|
|
|
|
WDC_DMAEND_ABRT);
|
2000-04-01 18:32:22 +04:00
|
|
|
chp->ch_flags &= ~WDCF_DMA_WAIT;
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
2002-12-06 17:05:34 +03:00
|
|
|
* Call the interrupt routine. If we just missed an interrupt,
|
1998-10-12 20:09:10 +04:00
|
|
|
* it will do what's needed. Else, it will take the needed
|
|
|
|
* action (reset the device).
|
1999-08-06 16:00:23 +04:00
|
|
|
* Before that we need to reinstall the timeout callback,
|
|
|
|
* in case it will miss another irq while in this transfer
|
|
|
|
* We arbitray chose it to be 1s
|
1998-10-12 20:09:10 +04:00
|
|
|
*/
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&chp->ch_callout, hz, wdctimeout, chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
xfer->c_flags |= C_TIMEOU;
|
|
|
|
chp->ch_flags &= ~WDCF_IRQ_WAIT;
|
1999-04-02 01:46:28 +04:00
|
|
|
xfer->c_intr(chp, xfer, 1);
|
1998-10-12 20:09:10 +04:00
|
|
|
} else
|
|
|
|
__wdcerror(chp, "missing untimeout");
|
|
|
|
splx(s);
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
/*
|
2003-11-02 14:07:44 +03:00
|
|
|
* Probe drive's capabilities, for use by the controller later
|
1998-10-12 20:09:10 +04:00
|
|
|
* Assumes drvp points to an existing drive.
|
|
|
|
* XXX this should be a controller-indep function
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
1998-10-12 20:09:10 +04:00
|
|
|
void
|
2003-12-30 19:40:12 +03:00
|
|
|
wdc_probe_caps(struct ata_drive_datas *drvp)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ataparams params, params2;
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = drvp->chnl_softc;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1998-10-12 20:09:10 +04:00
|
|
|
struct device *drv_dev = drvp->drv_softc;
|
|
|
|
int i, printed;
|
|
|
|
char *sep = "";
|
1998-12-02 13:52:24 +03:00
|
|
|
int cf_flags;
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2003-09-20 01:35:56 +04:00
|
|
|
if (ata_get_params(drvp, AT_WAIT, ¶ms) != CMD_OK) {
|
1998-10-12 20:09:10 +04:00
|
|
|
/* IDENTIFY failed. Can't tell more about the device */
|
|
|
|
return;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((wdc->cap & (WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32)) ==
|
|
|
|
(WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32)) {
|
1997-08-27 15:22:52 +04:00
|
|
|
/*
|
1998-11-11 22:38:27 +03:00
|
|
|
* Controller claims 16 and 32 bit transfers.
|
|
|
|
* Re-do an IDENTIFY with 32-bit transfers,
|
1998-10-12 20:09:10 +04:00
|
|
|
* and compare results.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->drive_flags |= DRIVE_CAP32;
|
2003-09-20 01:35:56 +04:00
|
|
|
ata_get_params(drvp, AT_WAIT, ¶ms2);
|
1998-10-12 20:09:10 +04:00
|
|
|
if (memcmp(¶ms, ¶ms2, sizeof(struct ataparams)) != 0) {
|
|
|
|
/* Not good. fall back to 16bits */
|
|
|
|
drvp->drive_flags &= ~DRIVE_CAP32;
|
|
|
|
} else {
|
2003-09-20 01:35:56 +04:00
|
|
|
aprint_normal("%s: 32-bit data port\n",
|
2003-05-18 01:52:03 +04:00
|
|
|
drv_dev->dv_xname);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-18 23:06:24 +03:00
|
|
|
#if 0 /* Some ultra-DMA drives claims to only support ATA-3. sigh */
|
|
|
|
if (params.atap_ata_major > 0x01 &&
|
|
|
|
params.atap_ata_major != 0xffff) {
|
|
|
|
for (i = 14; i > 0; i--) {
|
|
|
|
if (params.atap_ata_major & (1 << i)) {
|
2003-09-20 01:35:56 +04:00
|
|
|
aprint_normal("%s: ATA version %d\n",
|
|
|
|
drv_dev->dv_xname, i);
|
1999-01-18 23:06:24 +03:00
|
|
|
drvp->ata_vers = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-09-20 01:35:56 +04:00
|
|
|
}
|
1999-01-18 23:06:24 +03:00
|
|
|
#endif
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* An ATAPI device is at last PIO mode 3 */
|
|
|
|
if (drvp->drive_flags & DRIVE_ATAPI)
|
|
|
|
drvp->PIO_mode = 3;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* It's not in the specs, but it seems that some drive
|
|
|
|
* returns 0xffff in atap_extensions when this field is invalid
|
|
|
|
*/
|
|
|
|
if (params.atap_extensions != 0xffff &&
|
|
|
|
(params.atap_extensions & WDC_EXT_MODES)) {
|
|
|
|
printed = 0;
|
|
|
|
/*
|
|
|
|
* XXX some drives report something wrong here (they claim to
|
|
|
|
* support PIO mode 8 !). As mode is coded on 3 bits in
|
|
|
|
* SET FEATURE, limit it to 7 (so limit i to 4).
|
2002-07-26 18:10:22 +04:00
|
|
|
* If higher mode than 7 is found, abort.
|
1998-10-12 20:09:10 +04:00
|
|
|
*/
|
1998-11-11 22:38:27 +03:00
|
|
|
for (i = 7; i >= 0; i--) {
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((params.atap_piomode_supp & (1 << i)) == 0)
|
|
|
|
continue;
|
1998-11-11 22:38:27 +03:00
|
|
|
if (i > 4)
|
|
|
|
return;
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* See if mode is accepted.
|
|
|
|
* If the controller can't set its PIO mode,
|
|
|
|
* assume the defaults are good, so don't try
|
|
|
|
* to set it
|
|
|
|
*/
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_MODE) != 0)
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
|
|
|
* It's OK to pool here, it's fast enouth
|
|
|
|
* to not bother waiting for interrupt
|
|
|
|
*/
|
1998-10-12 20:09:10 +04:00
|
|
|
if (ata_set_mode(drvp, 0x08 | (i + 3),
|
2003-09-20 01:35:56 +04:00
|
|
|
AT_WAIT) != CMD_OK)
|
1998-10-12 20:09:10 +04:00
|
|
|
continue;
|
|
|
|
if (!printed) {
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal("%s: drive supports PIO mode %d",
|
1998-11-11 22:38:27 +03:00
|
|
|
drv_dev->dv_xname, i + 3);
|
1998-10-12 20:09:10 +04:00
|
|
|
sep = ",";
|
|
|
|
printed = 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If controller's driver can't set its PIO mode,
|
|
|
|
* get the highter one for the drive.
|
|
|
|
*/
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_MODE) == 0 ||
|
1998-12-03 21:24:30 +03:00
|
|
|
wdc->PIO_cap >= i + 3) {
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->PIO_mode = i + 3;
|
1998-12-02 13:52:24 +03:00
|
|
|
drvp->PIO_cap = i + 3;
|
1998-10-12 20:09:10 +04:00
|
|
|
break;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (!printed) {
|
|
|
|
/*
|
|
|
|
* We didn't find a valid PIO mode.
|
|
|
|
* Assume the values returned for DMA are buggy too
|
|
|
|
*/
|
|
|
|
return;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-13 19:18:46 +04:00
|
|
|
drvp->drive_flags |= DRIVE_MODE;
|
1998-10-12 20:09:10 +04:00
|
|
|
printed = 0;
|
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
if ((params.atap_dmamode_supp & (1 << i)) == 0)
|
|
|
|
continue;
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_DMA) &&
|
|
|
|
(wdc->cap & WDC_CAPABILITY_MODE))
|
2003-09-20 01:35:56 +04:00
|
|
|
if (ata_set_mode(drvp, 0x20 | i, AT_WAIT)
|
1998-10-12 20:09:10 +04:00
|
|
|
!= CMD_OK)
|
|
|
|
continue;
|
|
|
|
if (!printed) {
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal("%s DMA mode %d", sep, i);
|
1998-10-12 20:09:10 +04:00
|
|
|
sep = ",";
|
|
|
|
printed = 1;
|
|
|
|
}
|
|
|
|
if (wdc->cap & WDC_CAPABILITY_DMA) {
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_MODE) &&
|
1998-12-03 21:24:30 +03:00
|
|
|
wdc->DMA_cap < i)
|
1998-10-12 20:09:10 +04:00
|
|
|
continue;
|
|
|
|
drvp->DMA_mode = i;
|
1998-12-02 13:52:24 +03:00
|
|
|
drvp->DMA_cap = i;
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->drive_flags |= DRIVE_DMA;
|
|
|
|
}
|
|
|
|
break;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (params.atap_extensions & WDC_EXT_UDMA_MODES) {
|
1999-08-09 13:55:18 +04:00
|
|
|
printed = 0;
|
1998-10-12 20:09:10 +04:00
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
if ((params.atap_udmamode_supp & (1 << i))
|
|
|
|
== 0)
|
|
|
|
continue;
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_MODE) &&
|
|
|
|
(wdc->cap & WDC_CAPABILITY_UDMA))
|
|
|
|
if (ata_set_mode(drvp, 0x40 | i,
|
2003-09-20 01:35:56 +04:00
|
|
|
AT_WAIT) != CMD_OK)
|
1998-10-12 20:09:10 +04:00
|
|
|
continue;
|
1999-08-09 13:55:18 +04:00
|
|
|
if (!printed) {
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal("%s Ultra-DMA mode %d",
|
|
|
|
sep, i);
|
2000-11-08 20:57:36 +03:00
|
|
|
if (i == 2)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/33)");
|
2000-11-08 20:57:36 +03:00
|
|
|
else if (i == 4)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/66)");
|
2000-11-08 20:57:36 +03:00
|
|
|
else if (i == 5)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/100)");
|
2002-08-25 21:22:38 +04:00
|
|
|
else if (i == 6)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/133)");
|
1999-08-09 13:55:18 +04:00
|
|
|
sep = ",";
|
|
|
|
printed = 1;
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_UDMA) {
|
1998-12-03 18:38:59 +03:00
|
|
|
if ((wdc->cap & WDC_CAPABILITY_MODE) &&
|
1998-12-03 21:24:30 +03:00
|
|
|
wdc->UDMA_cap < i)
|
1998-12-03 18:38:59 +03:00
|
|
|
continue;
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->UDMA_mode = i;
|
1998-12-02 13:52:24 +03:00
|
|
|
drvp->UDMA_cap = i;
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->drive_flags |= DRIVE_UDMA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal("\n");
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1999-01-18 23:06:24 +03:00
|
|
|
|
2004-08-11 21:49:27 +04:00
|
|
|
drvp->drive_flags &= ~DRIVE_NOSTREAM;
|
|
|
|
if (drvp->drive_flags & DRIVE_ATAPI) {
|
|
|
|
if (wdc->cap & WDC_CAPABILITY_ATAPI_NOSTREAM)
|
|
|
|
drvp->drive_flags |= DRIVE_NOSTREAM;
|
|
|
|
} else {
|
|
|
|
if (wdc->cap & WDC_CAPABILITY_ATA_NOSTREAM)
|
|
|
|
drvp->drive_flags |= DRIVE_NOSTREAM;
|
|
|
|
}
|
|
|
|
|
1999-01-18 23:06:24 +03:00
|
|
|
/* Try to guess ATA version here, if it didn't get reported */
|
|
|
|
if (drvp->ata_vers == 0) {
|
|
|
|
if (drvp->drive_flags & DRIVE_UDMA)
|
|
|
|
drvp->ata_vers = 4; /* should be at last ATA-4 */
|
|
|
|
else if (drvp->PIO_cap > 2)
|
|
|
|
drvp->ata_vers = 2; /* should be at last ATA-2 */
|
|
|
|
}
|
1998-12-02 13:52:24 +03:00
|
|
|
cf_flags = drv_dev->dv_cfdata->cf_flags;
|
|
|
|
if (cf_flags & ATA_CONFIG_PIO_SET) {
|
|
|
|
drvp->PIO_mode =
|
|
|
|
(cf_flags & ATA_CONFIG_PIO_MODES) >> ATA_CONFIG_PIO_OFF;
|
|
|
|
drvp->drive_flags |= DRIVE_MODE;
|
|
|
|
}
|
|
|
|
if ((wdc->cap & WDC_CAPABILITY_DMA) == 0) {
|
|
|
|
/* don't care about DMA modes */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cf_flags & ATA_CONFIG_DMA_SET) {
|
|
|
|
if ((cf_flags & ATA_CONFIG_DMA_MODES) ==
|
|
|
|
ATA_CONFIG_DMA_DISABLE) {
|
|
|
|
drvp->drive_flags &= ~DRIVE_DMA;
|
|
|
|
} else {
|
|
|
|
drvp->DMA_mode = (cf_flags & ATA_CONFIG_DMA_MODES) >>
|
|
|
|
ATA_CONFIG_DMA_OFF;
|
|
|
|
drvp->drive_flags |= DRIVE_DMA | DRIVE_MODE;
|
|
|
|
}
|
|
|
|
}
|
2001-11-14 23:18:11 +03:00
|
|
|
if ((wdc->cap & WDC_CAPABILITY_UDMA) == 0) {
|
|
|
|
/* don't care about UDMA modes */
|
|
|
|
return;
|
|
|
|
}
|
1998-12-02 13:52:24 +03:00
|
|
|
if (cf_flags & ATA_CONFIG_UDMA_SET) {
|
|
|
|
if ((cf_flags & ATA_CONFIG_UDMA_MODES) ==
|
|
|
|
ATA_CONFIG_UDMA_DISABLE) {
|
|
|
|
drvp->drive_flags &= ~DRIVE_UDMA;
|
|
|
|
} else {
|
|
|
|
drvp->UDMA_mode = (cf_flags & ATA_CONFIG_UDMA_MODES) >>
|
|
|
|
ATA_CONFIG_UDMA_OFF;
|
|
|
|
drvp->drive_flags |= DRIVE_UDMA | DRIVE_MODE;
|
|
|
|
}
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-08-12 08:57:19 +04:00
|
|
|
wdc_exec_command(struct ata_drive_datas *drvp, struct ata_command *ata_c)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-03 04:50:52 +03:00
|
|
|
struct wdc_channel *chp = drvp->chnl_softc;
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *xfer;
|
1998-10-12 20:09:10 +04:00
|
|
|
int s, ret;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("wdc_exec_command %s:%d:%d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, drvp->drive),
|
1998-10-13 19:02:41 +04:00
|
|
|
DEBUG_FUNCS);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* set up an xfer and queue. Wait for completion */
|
2004-08-12 08:57:19 +04:00
|
|
|
xfer = wdc_get_xfer(ata_c->flags & AT_WAIT ? WDC_CANSLEEP :
|
1998-10-12 20:09:10 +04:00
|
|
|
WDC_NOSLEEP);
|
|
|
|
if (xfer == NULL) {
|
2004-08-12 09:02:50 +04:00
|
|
|
return ATACMD_TRY_AGAIN;
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_NOIRQ)
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_POLL;
|
|
|
|
if (ata_c->flags & AT_POLL)
|
1998-10-12 20:09:10 +04:00
|
|
|
xfer->c_flags |= C_POLL;
|
2004-01-01 20:18:53 +03:00
|
|
|
xfer->c_drive = drvp->drive;
|
2004-08-12 08:57:19 +04:00
|
|
|
xfer->c_databuf = ata_c->data;
|
|
|
|
xfer->c_bcount = ata_c->bcount;
|
|
|
|
xfer->c_cmd = ata_c;
|
1998-10-12 20:09:10 +04:00
|
|
|
xfer->c_start = __wdccommand_start;
|
|
|
|
xfer->c_intr = __wdccommand_intr;
|
2004-08-01 01:26:42 +04:00
|
|
|
xfer->c_kill_xfer = __wdccommand_kill_xfer;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
s = splbio();
|
|
|
|
wdc_exec_xfer(chp, xfer);
|
|
|
|
#ifdef DIAGNOSTIC
|
2004-08-12 08:57:19 +04:00
|
|
|
if ((ata_c->flags & AT_POLL) != 0 &&
|
|
|
|
(ata_c->flags & AT_DONE) == 0)
|
2002-09-27 19:35:29 +04:00
|
|
|
panic("wdc_exec_command: polled command not done");
|
1997-08-27 15:22:52 +04:00
|
|
|
#endif
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_DONE) {
|
2004-08-12 09:02:50 +04:00
|
|
|
ret = ATACMD_COMPLETE;
|
1998-10-12 20:09:10 +04:00
|
|
|
} else {
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_WAIT) {
|
|
|
|
while ((ata_c->flags & AT_DONE) == 0) {
|
|
|
|
tsleep(ata_c, PRIBIO, "wdccmd", 0);
|
1999-07-30 18:59:10 +04:00
|
|
|
}
|
2004-08-12 09:02:50 +04:00
|
|
|
ret = ATACMD_COMPLETE;
|
1998-10-12 20:09:10 +04:00
|
|
|
} else {
|
2004-08-12 09:02:50 +04:00
|
|
|
ret = ATACMD_QUEUED;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
1998-10-12 20:09:10 +04:00
|
|
|
return ret;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2004-01-02 00:18:28 +03:00
|
|
|
static void
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdccommand_start(struct wdc_channel *chp, struct ata_xfer *xfer)
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-01-01 20:18:53 +03:00
|
|
|
int drive = xfer->c_drive;
|
2004-08-12 08:57:19 +04:00
|
|
|
struct ata_command *ata_c = xfer->c_cmd;
|
1998-10-12 20:09:10 +04:00
|
|
|
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_start %s:%d:%d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive),
|
1998-10-13 19:02:41 +04:00
|
|
|
DEBUG_FUNCS);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,drive);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDSD_IBM | (drive << 4));
|
2004-08-12 08:57:19 +04:00
|
|
|
switch(wdcwait(chp, ata_c->r_st_bmask | WDCS_DRQ,
|
|
|
|
ata_c->r_st_bmask, ata_c->timeout, ata_c->flags)) {
|
2003-10-08 14:58:12 +04:00
|
|
|
case WDCWAIT_OK:
|
|
|
|
break;
|
|
|
|
case WDCWAIT_TOUT:
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_TIMEOU;
|
1998-10-12 20:09:10 +04:00
|
|
|
__wdccommand_done(chp, xfer);
|
1998-12-08 16:29:31 +03:00
|
|
|
return;
|
2003-10-08 14:58:12 +04:00
|
|
|
case WDCWAIT_THR:
|
|
|
|
return;
|
|
|
|
}
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_POLL) {
|
2003-10-08 14:58:12 +04:00
|
|
|
/* polled command, disable interrupts */
|
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_4BIT | WDCTL_IDS);
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
2004-08-12 08:57:19 +04:00
|
|
|
wdccommand(chp, drive, ata_c->r_command, ata_c->r_cyl, ata_c->r_head,
|
|
|
|
ata_c->r_sector, ata_c->r_count, ata_c->r_features);
|
2003-10-09 22:40:19 +04:00
|
|
|
|
2004-08-12 08:57:19 +04:00
|
|
|
if ((ata_c->flags & AT_POLL) == 0) {
|
1998-10-12 20:09:10 +04:00
|
|
|
chp->ch_flags |= WDCF_IRQ_WAIT; /* wait for interrupt */
|
2004-08-12 08:57:19 +04:00
|
|
|
callout_reset(&chp->ch_callout, ata_c->timeout / 1000 * hz,
|
2000-03-23 10:01:25 +03:00
|
|
|
wdctimeout, chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Polled command. Wait for drive ready or drq. Done in intr().
|
|
|
|
* Wait for at last 400ns for status bit to be valid.
|
|
|
|
*/
|
2003-09-25 23:29:48 +04:00
|
|
|
delay(10); /* 400ns delay */
|
1999-04-02 01:46:28 +04:00
|
|
|
__wdccommand_intr(chp, xfer, 0);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2004-01-02 00:18:28 +03:00
|
|
|
static int
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdccommand_intr(struct wdc_channel *chp, struct ata_xfer *xfer, int irq)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-08-12 08:57:19 +04:00
|
|
|
struct ata_command *ata_c = xfer->c_cmd;
|
|
|
|
int bcount = ata_c->bcount;
|
|
|
|
char *data = ata_c->data;
|
2003-10-08 14:58:12 +04:00
|
|
|
int wflags;
|
|
|
|
|
2004-08-12 08:57:19 +04:00
|
|
|
if ((ata_c->flags & (AT_WAIT | AT_POLL)) == (AT_WAIT | AT_POLL)) {
|
2003-10-08 14:58:12 +04:00
|
|
|
/* both wait and poll, we can tsleep here */
|
2003-10-30 00:44:41 +03:00
|
|
|
wflags = AT_WAIT | AT_POLL;
|
2003-10-08 14:58:12 +04:00
|
|
|
} else {
|
|
|
|
wflags = AT_POLL;
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2003-12-30 19:40:12 +03:00
|
|
|
again:
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_intr %s:%d:%d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive),
|
2004-01-01 20:18:53 +03:00
|
|
|
DEBUG_INTR);
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
|
|
|
* after a ATAPI_SOFT_RESET, the device will have released the bus.
|
|
|
|
* Reselect again, it doesn't hurt for others commands, and the time
|
|
|
|
* penalty for the extra regiter write is acceptable,
|
|
|
|
* wdc_exec_command() isn't called often (mosly for autoconfig)
|
|
|
|
*/
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
2004-01-01 20:18:53 +03:00
|
|
|
WDSD_IBM | (xfer->c_drive << 4));
|
2004-08-12 08:57:19 +04:00
|
|
|
if ((ata_c->flags & AT_XFDONE) != 0) {
|
2002-04-10 01:17:53 +04:00
|
|
|
/*
|
|
|
|
* We have completed a data xfer. The drive should now be
|
|
|
|
* in its initial state
|
|
|
|
*/
|
2004-08-12 08:57:19 +04:00
|
|
|
if (wdcwait(chp, ata_c->r_st_bmask | WDCS_DRQ,
|
|
|
|
ata_c->r_st_bmask, (irq == 0) ? ata_c->timeout : 0,
|
2003-10-08 14:58:12 +04:00
|
|
|
wflags) == WDCWAIT_TOUT) {
|
2002-04-10 01:17:53 +04:00
|
|
|
if (irq && (xfer->c_flags & C_TIMEOU) == 0)
|
|
|
|
return 0; /* IRQ was not for us */
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_TIMEOU;
|
2002-04-10 01:17:53 +04:00
|
|
|
}
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
goto out;
|
2002-04-10 01:17:53 +04:00
|
|
|
}
|
2004-08-12 08:57:19 +04:00
|
|
|
if (wdcwait(chp, ata_c->r_st_pmask, ata_c->r_st_pmask,
|
|
|
|
(irq == 0) ? ata_c->timeout : 0, wflags) == WDCWAIT_TOUT) {
|
1999-04-02 01:46:28 +04:00
|
|
|
if (irq && (xfer->c_flags & C_TIMEOU) == 0)
|
1999-03-25 19:17:36 +03:00
|
|
|
return 0; /* IRQ was not for us */
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_TIMEOU;
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
goto out;
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_IRQACK)
|
|
|
|
wdc->irqack(chp);
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_READ) {
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
if ((chp->ch_status & WDCS_DRQ) == 0) {
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_TIMEOU;
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
goto out;
|
|
|
|
}
|
2004-01-01 20:18:53 +03:00
|
|
|
if (chp->ch_drive[xfer->c_drive].drive_flags & DRIVE_CAP32) {
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_read_multi_4(chp->data32iot, chp->data32ioh,
|
|
|
|
0, (u_int32_t*)data, bcount >> 2);
|
|
|
|
data += bcount & 0xfffffffc;
|
|
|
|
bcount = bcount & 0x03;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (bcount > 0)
|
2004-08-11 22:41:46 +04:00
|
|
|
wdc->datain_pio(chp, DRIVE_NOSTREAM, data, bcount);
|
2002-04-10 01:17:53 +04:00
|
|
|
/* at this point the drive should be in its initial state */
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_XFDONE;
|
2003-10-08 14:58:12 +04:00
|
|
|
/* XXX should read status register here ? */
|
2004-08-12 08:57:19 +04:00
|
|
|
} else if (ata_c->flags & AT_WRITE) {
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
if ((chp->ch_status & WDCS_DRQ) == 0) {
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_TIMEOU;
|
Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.
Also remove the SINGLE_DRIVE nonsense again.
2003-09-23 13:19:22 +04:00
|
|
|
goto out;
|
|
|
|
}
|
2004-01-01 20:18:53 +03:00
|
|
|
if (chp->ch_drive[xfer->c_drive].drive_flags & DRIVE_CAP32) {
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_write_multi_4(chp->data32iot, chp->data32ioh,
|
|
|
|
0, (u_int32_t*)data, bcount >> 2);
|
|
|
|
data += bcount & 0xfffffffc;
|
|
|
|
bcount = bcount & 0x03;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (bcount > 0)
|
2004-08-11 22:41:46 +04:00
|
|
|
wdc->dataout_pio(chp, DRIVE_NOSTREAM, data, bcount);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_XFDONE;
|
|
|
|
if ((ata_c->flags & AT_POLL) == 0) {
|
2002-04-10 01:17:53 +04:00
|
|
|
chp->ch_flags |= WDCF_IRQ_WAIT; /* wait for interrupt */
|
|
|
|
callout_reset(&chp->ch_callout,
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->timeout / 1000 * hz, wdctimeout, chp);
|
2002-04-10 01:17:53 +04:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
goto again;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
2003-12-30 19:40:12 +03:00
|
|
|
out:
|
1998-10-12 20:09:10 +04:00
|
|
|
__wdccommand_done(chp, xfer);
|
|
|
|
return 1;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2004-01-02 00:18:28 +03:00
|
|
|
static void
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdccommand_done(struct wdc_channel *chp, struct ata_xfer *xfer)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-08-12 08:57:19 +04:00
|
|
|
struct ata_command *ata_c = xfer->c_cmd;
|
1998-10-12 20:09:10 +04:00
|
|
|
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_done %s:%d:%d\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, xfer->c_drive),
|
2004-01-01 20:18:53 +03:00
|
|
|
DEBUG_FUNCS);
|
1999-08-06 16:00:23 +04:00
|
|
|
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if (chp->ch_status & WDCS_DWF)
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_DF;
|
1998-10-12 20:09:10 +04:00
|
|
|
if (chp->ch_status & WDCS_ERR) {
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_ERROR;
|
|
|
|
ata_c->r_error = chp->ch_error;
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
2004-08-12 08:57:19 +04:00
|
|
|
if ((ata_c->flags & AT_READREG) != 0 &&
|
2004-01-04 01:56:52 +03:00
|
|
|
(wdc->sc_dev.dv_flags & DVF_ACTIVE) != 0 &&
|
2004-08-12 08:57:19 +04:00
|
|
|
(ata_c->flags & (AT_ERROR | AT_DF)) == 0) {
|
|
|
|
ata_c->r_head = bus_space_read_1(chp->cmd_iot,
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
chp->cmd_iohs[wd_sdh], 0);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_count = bus_space_read_1(chp->cmd_iot,
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
chp->cmd_iohs[wd_seccnt], 0);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_sector = bus_space_read_1(chp->cmd_iot,
|
2004-05-27 20:47:35 +04:00
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_cyl |= bus_space_read_1(chp->cmd_iot,
|
2004-05-27 20:47:35 +04:00
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_cyl = bus_space_read_1(chp->cmd_iot,
|
2004-05-27 20:47:35 +04:00
|
|
|
chp->cmd_iohs[wd_cyl_hi], 0) << 8;
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_error = bus_space_read_1(chp->cmd_iot,
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
chp->cmd_iohs[wd_error], 0);
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->r_features = bus_space_read_1(chp->cmd_iot,
|
2004-05-27 06:23:12 +04:00
|
|
|
chp->cmd_iohs[wd_features], 0);
|
1998-11-24 02:02:11 +03:00
|
|
|
}
|
2004-08-04 22:24:10 +04:00
|
|
|
callout_stop(&chp->ch_callout);
|
2004-08-05 02:44:04 +04:00
|
|
|
chp->ch_queue->active_xfer = NULL;
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_POLL) {
|
2004-08-05 02:44:04 +04:00
|
|
|
/* enable interrupts */
|
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_4BIT);
|
|
|
|
delay(10); /* some drives need a little delay here */
|
|
|
|
}
|
|
|
|
if (chp->ch_drive[xfer->c_drive].drive_flags & DRIVE_WAITDRAIN) {
|
|
|
|
__wdccommand_kill_xfer(chp, xfer, KILL_GONE);
|
|
|
|
chp->ch_drive[xfer->c_drive].drive_flags &= ~DRIVE_WAITDRAIN;
|
|
|
|
wakeup(&chp->ch_queue->active_xfer);
|
|
|
|
} else
|
|
|
|
__wdccommand_done_end(chp, xfer);
|
2004-08-01 01:26:42 +04:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2004-08-01 01:26:42 +04:00
|
|
|
static void
|
|
|
|
__wdccommand_done_end(struct wdc_channel *chp, struct ata_xfer *xfer)
|
|
|
|
{
|
2004-08-12 08:57:19 +04:00
|
|
|
struct ata_command *ata_c = xfer->c_cmd;
|
2004-08-01 01:26:42 +04:00
|
|
|
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_DONE;
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_free_xfer(chp, xfer);
|
2004-08-12 08:57:19 +04:00
|
|
|
if (ata_c->flags & AT_WAIT)
|
|
|
|
wakeup(ata_c);
|
|
|
|
else if (ata_c->callback)
|
|
|
|
ata_c->callback(ata_c->callback_arg);
|
1998-11-21 18:41:41 +03:00
|
|
|
wdcstart(chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
return;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 01:26:42 +04:00
|
|
|
static void
|
|
|
|
__wdccommand_kill_xfer(struct wdc_channel *chp, struct ata_xfer *xfer,
|
|
|
|
int reason)
|
|
|
|
{
|
2004-08-12 08:57:19 +04:00
|
|
|
struct ata_command *ata_c = xfer->c_cmd;
|
2004-08-01 01:26:42 +04:00
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
case KILL_GONE:
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_GONE;
|
2004-08-01 01:26:42 +04:00
|
|
|
break;
|
|
|
|
case KILL_RESET:
|
2004-08-12 08:57:19 +04:00
|
|
|
ata_c->flags |= AT_RESET;
|
2004-08-01 01:26:42 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("__wdccommand_kill_xfer: unknown reason %d\n",
|
|
|
|
reason);
|
|
|
|
panic("__wdccommand_kill_xfer");
|
|
|
|
}
|
|
|
|
__wdccommand_done_end(chp, xfer);
|
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/*
|
1998-10-12 20:09:10 +04:00
|
|
|
* Send a command. The drive should be ready.
|
1997-08-27 15:22:52 +04:00
|
|
|
* Assumes interrupts are blocked.
|
|
|
|
*/
|
1998-10-12 20:09:10 +04:00
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdccommand(struct wdc_channel *chp, u_int8_t drive, u_int8_t command,
|
2003-12-30 19:40:12 +03:00
|
|
|
u_int16_t cylin, u_int8_t head, u_int8_t sector, u_int8_t count,
|
2004-05-27 06:23:12 +04:00
|
|
|
u_int8_t features)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-12-30 19:40:12 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdccommand %s:%d:%d: command=0x%x cylin=%d head=%d "
|
2004-05-27 06:23:12 +04:00
|
|
|
"sector=%d count=%d features=%d\n", wdc->sc_dev.dv_xname,
|
2004-01-04 01:56:52 +03:00
|
|
|
chp->ch_channel, drive, command, cylin, head, sector, count,
|
2004-05-27 06:23:12 +04:00
|
|
|
features), DEBUG_FUNCS);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,drive);
|
2002-01-08 01:11:17 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Select drive, head, and addressing mode. */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDSD_IBM | (drive << 4) | head);
|
2004-05-27 06:09:26 +04:00
|
|
|
/* Load parameters into the wd_features register. */
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_features], 0,
|
2004-05-27 06:23:12 +04:00
|
|
|
features);
|
2004-05-27 20:47:35 +04:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_seccnt], 0, count);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sector], 0, sector);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_cyl_lo], 0, cylin);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_cyl_hi],
|
|
|
|
0, cylin >> 8);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
|
|
|
/* Send command. */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_command], 0, command);
|
1998-10-12 20:09:10 +04:00
|
|
|
return;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
2002-01-13 20:24:28 +03:00
|
|
|
/*
|
|
|
|
* Send a 48-bit addressing command. The drive should be ready.
|
|
|
|
* Assumes interrupts are blocked.
|
|
|
|
*/
|
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdccommandext(struct wdc_channel *chp, u_int8_t drive, u_int8_t command,
|
2003-12-30 19:40:12 +03:00
|
|
|
u_int64_t blkno, u_int16_t count)
|
2002-01-13 20:24:28 +03:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2003-12-30 19:40:12 +03:00
|
|
|
|
2002-01-13 20:24:28 +03:00
|
|
|
WDCDEBUG_PRINT(("wdccommandext %s:%d:%d: command=0x%x blkno=%d "
|
2004-01-04 01:56:52 +03:00
|
|
|
"count=%d\n", wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, drive, command, (u_int32_t) blkno, count),
|
2002-01-13 20:24:28 +03:00
|
|
|
DEBUG_FUNCS);
|
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,drive);
|
2002-01-13 20:24:28 +03:00
|
|
|
|
|
|
|
/* Select drive, head, and addressing mode. */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
2002-01-13 20:24:28 +03:00
|
|
|
(drive << 4) | WDSD_LBA);
|
|
|
|
|
|
|
|
/* previous */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_features], 0, 0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_seccnt],
|
|
|
|
0, count >> 8);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_lo],
|
|
|
|
0, blkno >> 24);
|
2004-05-27 20:47:35 +04:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_mi],
|
|
|
|
0, blkno >> 32);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_hi],
|
|
|
|
0, blkno >> 40);
|
2002-01-13 20:24:28 +03:00
|
|
|
|
|
|
|
/* current */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_features], 0, 0);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_seccnt], 0, count);
|
2004-05-27 20:47:35 +04:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_lo], 0, blkno);
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_mi],
|
|
|
|
0, blkno >> 8);
|
2004-05-27 20:47:35 +04:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_hi],
|
|
|
|
0, blkno >> 16);
|
2002-01-13 20:24:28 +03:00
|
|
|
|
|
|
|
/* Send command. */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_command], 0, command);
|
2002-01-13 20:24:28 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
/*
|
1998-10-12 20:09:10 +04:00
|
|
|
* Simplified version of wdccommand(). Unbusy/ready/drq must be
|
|
|
|
* tested by the caller.
|
1997-08-27 15:22:52 +04:00
|
|
|
*/
|
1998-10-12 20:09:10 +04:00
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdccommandshort(struct wdc_channel *chp, int drive, int command)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdccommandshort %s:%d:%d command 0x%x\n",
|
2004-01-04 01:56:52 +03:00
|
|
|
wdc->sc_dev.dv_xname, chp->ch_channel, drive, command),
|
1998-10-12 20:09:10 +04:00
|
|
|
DEBUG_FUNCS);
|
2002-01-08 01:11:17 +03:00
|
|
|
|
2004-01-04 01:56:52 +03:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
wdc->select(chp,drive);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Select drive. */
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sdh], 0,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDSD_IBM | (drive << 4));
|
1997-08-27 15:22:52 +04:00
|
|
|
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_command], 0, command);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Add a command to the queue and start controller. Must be called at splbio */
|
1997-08-27 15:22:52 +04:00
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_exec_xfer(struct wdc_channel *chp, struct ata_xfer *xfer)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2003-12-30 19:40:12 +03:00
|
|
|
|
1998-10-13 13:33:59 +04:00
|
|
|
WDCDEBUG_PRINT(("wdc_exec_xfer %p channel %d drive %d\n", xfer,
|
2004-01-04 01:56:52 +03:00
|
|
|
chp->ch_channel, xfer->c_drive), DEBUG_XFERS);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* complete xfer setup */
|
2004-01-01 20:18:53 +03:00
|
|
|
xfer->c_chp = chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
/* insert at the end of command list */
|
2004-01-01 20:18:53 +03:00
|
|
|
TAILQ_INSERT_TAIL(&chp->ch_queue->queue_xfer, xfer, c_xferchain);
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdcstart from wdc_exec_xfer, flags 0x%x\n",
|
1998-10-13 13:33:59 +04:00
|
|
|
chp->ch_flags), DEBUG_XFERS);
|
1998-11-21 18:41:41 +03:00
|
|
|
wdcstart(chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *
|
2003-12-30 19:40:12 +03:00
|
|
|
wdc_get_xfer(int flags)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *xfer;
|
1999-08-25 21:08:20 +04:00
|
|
|
int s;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1999-08-25 21:08:20 +04:00
|
|
|
s = splbio();
|
1999-08-09 13:55:18 +04:00
|
|
|
xfer = pool_get(&wdc_xfer_pool,
|
|
|
|
((flags & WDC_NOSLEEP) != 0 ? PR_NOWAIT : PR_WAITOK));
|
1999-08-25 21:08:20 +04:00
|
|
|
splx(s);
|
2001-09-18 09:32:14 +04:00
|
|
|
if (xfer != NULL) {
|
2004-01-01 20:18:53 +03:00
|
|
|
memset(xfer, 0, sizeof(struct ata_xfer));
|
2001-09-18 09:32:14 +04:00
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
return xfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_free_xfer(struct wdc_channel *chp, struct ata_xfer *xfer)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
1997-08-27 15:22:52 +04:00
|
|
|
int s;
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc->cap & WDC_CAPABILITY_HWLOCK)
|
|
|
|
(*wdc->free_hw)(chp);
|
1997-08-27 15:22:52 +04:00
|
|
|
s = splbio();
|
1999-08-09 13:55:18 +04:00
|
|
|
pool_put(&wdc_xfer_pool, xfer);
|
1999-08-25 21:08:20 +04:00
|
|
|
splx(s);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1999-10-20 19:22:24 +04:00
|
|
|
/*
|
2004-01-03 04:50:52 +03:00
|
|
|
* Kill off all pending xfers for a wdc_channel.
|
1999-10-20 19:22:24 +04:00
|
|
|
*
|
|
|
|
* Must be called at splbio().
|
|
|
|
*/
|
|
|
|
void
|
2004-08-05 02:44:04 +04:00
|
|
|
wdc_kill_pending(struct ata_drive_datas *drvp)
|
1999-10-20 19:22:24 +04:00
|
|
|
{
|
2004-08-05 02:44:04 +04:00
|
|
|
struct wdc_channel *chp = drvp->chnl_softc;
|
2004-08-04 22:24:10 +04:00
|
|
|
struct ata_xfer *xfer, *next_xfer;
|
2004-08-05 02:44:04 +04:00
|
|
|
int s = splbio();
|
2004-08-04 22:24:10 +04:00
|
|
|
|
|
|
|
for (xfer = TAILQ_FIRST(&chp->ch_queue->queue_xfer);
|
|
|
|
xfer != NULL; xfer = next_xfer) {
|
|
|
|
next_xfer = TAILQ_NEXT(xfer, c_xferchain);
|
2004-08-05 02:44:04 +04:00
|
|
|
if (xfer->c_chp != chp || xfer->c_drive != drvp->drive)
|
2004-08-04 22:24:10 +04:00
|
|
|
continue;
|
|
|
|
TAILQ_REMOVE(&chp->ch_queue->queue_xfer, xfer, c_xferchain);
|
2004-08-01 01:26:42 +04:00
|
|
|
(*xfer->c_kill_xfer)(chp, xfer, KILL_GONE);
|
1999-10-20 19:22:24 +04:00
|
|
|
}
|
2004-08-05 02:44:04 +04:00
|
|
|
|
|
|
|
while ((xfer = chp->ch_queue->active_xfer) != NULL) {
|
|
|
|
if (xfer->c_chp == chp && xfer->c_drive == drvp->drive) {
|
|
|
|
drvp->drive_flags |= DRIVE_WAITDRAIN;
|
|
|
|
(void) tsleep(&chp->ch_queue->active_xfer,
|
|
|
|
PRIBIO, "atdrn", 0);
|
|
|
|
} else {
|
|
|
|
/* no more xfer for us */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
1999-10-20 19:22:24 +04:00
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
static void
|
2004-01-03 04:50:52 +03:00
|
|
|
__wdcerror(struct wdc_channel *chp, char *msg)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2004-01-01 20:18:53 +03:00
|
|
|
struct ata_xfer *xfer = TAILQ_FIRST(&chp->ch_queue->queue_xfer);
|
2000-04-05 10:27:36 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
if (xfer == NULL)
|
2004-01-04 01:56:52 +03:00
|
|
|
printf("%s:%d: %s\n", wdc->sc_dev.dv_xname, chp->ch_channel,
|
1998-10-12 20:09:10 +04:00
|
|
|
msg);
|
1997-08-27 15:22:52 +04:00
|
|
|
else
|
2004-01-04 01:56:52 +03:00
|
|
|
printf("%s:%d:%d: %s\n", wdc->sc_dev.dv_xname,
|
|
|
|
chp->ch_channel, xfer->c_drive, msg);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the bit bucket
|
|
|
|
*/
|
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdcbit_bucket(struct wdc_channel *chp, int size)
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
|
|
|
|
1998-01-15 02:41:59 +03:00
|
|
|
for (; size >= 2; size -= 2)
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
(void)bus_space_read_2(chp->cmd_iot, chp->cmd_iohs[wd_data], 0);
|
1998-01-15 02:41:59 +03:00
|
|
|
if (size)
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
(void)bus_space_read_1(chp->cmd_iot, chp->cmd_iohs[wd_data], 0);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
1998-11-20 04:22:37 +03:00
|
|
|
|
|
|
|
int
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_addref(struct wdc_channel *chp)
|
1998-11-20 04:22:37 +03:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_adapter *adapt = &wdc->sc_atapi_adapter._generic;
|
1998-11-20 04:22:37 +03:00
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splbio();
|
2001-04-25 21:53:04 +04:00
|
|
|
if (adapt->adapt_refcnt++ == 0 &&
|
|
|
|
adapt->adapt_enable != NULL) {
|
|
|
|
error = (*adapt->adapt_enable)(&wdc->sc_dev, 1);
|
1998-11-20 04:22:37 +03:00
|
|
|
if (error)
|
2001-04-25 21:53:04 +04:00
|
|
|
adapt->adapt_refcnt--;
|
1998-11-20 04:22:37 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-01-03 04:50:52 +03:00
|
|
|
wdc_delref(struct wdc_channel *chp)
|
1998-11-20 04:22:37 +03:00
|
|
|
{
|
2004-01-04 01:56:52 +03:00
|
|
|
struct wdc_softc *wdc = chp->ch_wdc;
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_adapter *adapt = &wdc->sc_atapi_adapter._generic;
|
1998-11-20 04:22:37 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
2001-04-25 21:53:04 +04:00
|
|
|
if (adapt->adapt_refcnt-- == 1 &&
|
|
|
|
adapt->adapt_enable != NULL)
|
|
|
|
(void) (*adapt->adapt_enable)(&wdc->sc_dev, 0);
|
1998-11-20 04:22:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
2000-11-08 20:57:36 +03:00
|
|
|
|
2004-08-11 21:49:27 +04:00
|
|
|
void
|
|
|
|
wdc_datain_pio(chp, flags, buf, len)
|
|
|
|
struct wdc_channel *chp;
|
|
|
|
int flags;
|
|
|
|
void *buf;
|
|
|
|
size_t len;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (flags & DRIVE_NOSTREAM) {
|
|
|
|
if (flags & DRIVE_CAP32) {
|
|
|
|
bus_space_read_multi_4(chp->data32iot,
|
|
|
|
chp->data32ioh, 0, buf, len >> 2);
|
|
|
|
buf = (char *)buf + (len & ~3);
|
|
|
|
len &= 3;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
bus_space_read_multi_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0, buf, len >> 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (flags & DRIVE_CAP32) {
|
|
|
|
bus_space_read_multi_stream_4(chp->data32iot,
|
|
|
|
chp->data32ioh, 0, buf, len >> 2);
|
|
|
|
buf = (char *)buf + (len & ~3);
|
|
|
|
len &= 3;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
bus_space_read_multi_stream_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0, buf, len >> 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wdc_dataout_pio(chp, flags, buf, len)
|
|
|
|
struct wdc_channel *chp;
|
|
|
|
int flags;
|
|
|
|
void *buf;
|
|
|
|
size_t len;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (flags & DRIVE_NOSTREAM) {
|
|
|
|
if (flags & DRIVE_CAP32) {
|
|
|
|
bus_space_write_multi_4(chp->data32iot,
|
|
|
|
chp->data32ioh, 0, buf, len >> 2);
|
|
|
|
buf = (char *)buf + (len & ~3);
|
|
|
|
len &= 3;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
bus_space_write_multi_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0, buf, len >> 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (flags & DRIVE_CAP32) {
|
|
|
|
bus_space_write_multi_stream_4(chp->data32iot,
|
|
|
|
chp->data32ioh, 0, buf, len >> 2);
|
|
|
|
buf = (char *)buf + (len & ~3);
|
|
|
|
len &= 3;
|
|
|
|
}
|
|
|
|
if (len) {
|
|
|
|
bus_space_write_multi_stream_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0, buf, len >> 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|