2003-12-15 03:27:13 +03:00
|
|
|
/* $NetBSD: wdc.c,v 1.161 2003/12/15 00:27:13 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>
|
2003-12-15 03:27:13 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.161 2003/12/15 00:27:13 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>
|
2003-10-08 14:58:12 +04:00
|
|
|
#include <sys/kthread.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#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
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
int atabusmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void atabusattach __P((struct device *, struct device *, void *));
|
|
|
|
void atabus_create_thread __P((void *));
|
|
|
|
void atabus_thread __P((void *));
|
|
|
|
void atabusconfig __P((struct atabus_softc *));
|
|
|
|
int atabusactivate __P((struct device *, enum devact));
|
|
|
|
int atabusdetach __P((struct device *, int flags));
|
|
|
|
int atabusprint __P((void *, const char *));
|
|
|
|
|
|
|
|
CFATTACH_DECL(atabus, sizeof(struct atabus_softc),
|
|
|
|
atabusmatch, atabusattach, atabusdetach, atabusactivate);
|
|
|
|
|
|
|
|
struct atabus_initq {
|
|
|
|
struct atabus_softc *atabus_sc;
|
|
|
|
TAILQ_ENTRY(atabus_initq) atabus_initq;
|
|
|
|
};
|
|
|
|
static TAILQ_HEAD(, atabus_initq) atabus_initq_head =
|
|
|
|
TAILQ_HEAD_INITIALIZER(atabus_initq_head);
|
|
|
|
static struct simplelock atabus_interlock = SIMPLELOCK_INITIALIZER;
|
|
|
|
|
2003-12-14 21:51:10 +03:00
|
|
|
int wdcprobe1 __P((struct channel_softc*, int));
|
1998-10-12 20:09:10 +04:00
|
|
|
static void __wdcerror __P((struct channel_softc*, char *));
|
2003-10-08 14:58:12 +04:00
|
|
|
static int __wdcwait_reset __P((struct channel_softc *, int, int));
|
1998-10-12 20:09:10 +04:00
|
|
|
void __wdccommand_done __P((struct channel_softc *, struct wdc_xfer *));
|
|
|
|
void __wdccommand_start __P((struct channel_softc *, struct wdc_xfer *));
|
1999-04-02 01:46:28 +04:00
|
|
|
int __wdccommand_intr __P((struct channel_softc *, struct wdc_xfer *, int));
|
2003-10-08 14:58:12 +04:00
|
|
|
int __wdcwait __P((struct channel_softc *, int, int, int));
|
1998-10-12 20:09:10 +04:00
|
|
|
int wdprint __P((void *, const char *));
|
2003-09-25 23:29:48 +04:00
|
|
|
void wdc_finish_attach __P((struct device *));
|
2003-09-20 01:35:56 +04:00
|
|
|
void wdc_channel_attach __P((struct channel_softc *));
|
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
|
|
|
|
|
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
atabusprint(aux, pnp)
|
1998-10-12 20:09:10 +04:00
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct channel_softc *chan = aux;
|
1998-10-12 20:09:10 +04:00
|
|
|
if (pnp)
|
2003-10-08 14:58:12 +04:00
|
|
|
aprint_normal("atabus at %s", pnp);
|
|
|
|
aprint_normal(" channel %d", chan->channel);
|
1998-10-12 20:09:10 +04:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
atabusmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct channel_softc *chp = aux;
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
if (chp == NULL)
|
|
|
|
return (0);
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2003-10-09 00:57:59 +04:00
|
|
|
if (cf->cf_loc[ATACF_CHANNEL] != chp->channel &&
|
|
|
|
cf->cf_loc[ATACF_CHANNEL] != ATACF_CHANNEL_DEFAULT)
|
2003-10-08 14:58:12 +04:00
|
|
|
return (0);
|
1998-11-19 22:52:42 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
void
|
|
|
|
atabusattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct atabus_softc *atabus_sc = (struct atabus_softc *)self;
|
|
|
|
struct channel_softc *chp = aux;
|
|
|
|
struct atabus_initq *atabus_initq;
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
atabus_sc->sc_chan = chp;
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2003-11-01 00:25:09 +03:00
|
|
|
aprint_normal("\n");
|
|
|
|
aprint_naive("\n");
|
2003-10-08 14:58:12 +04:00
|
|
|
atabus_initq = malloc(sizeof(struct atabus_initq), M_DEVBUF, M_NOWAIT);
|
|
|
|
atabus_initq->atabus_sc = atabus_sc;
|
|
|
|
TAILQ_INSERT_TAIL(&atabus_initq_head, atabus_initq, atabus_initq);
|
|
|
|
config_pending_incr();
|
|
|
|
kthread_create(atabus_create_thread, atabus_sc);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
1998-01-15 02:41:59 +03:00
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
void
|
2003-10-08 14:58:12 +04:00
|
|
|
atabus_create_thread(arg)
|
|
|
|
void *arg;
|
2003-09-25 23:29:48 +04:00
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct atabus_softc *atabus_sc = arg;
|
|
|
|
struct channel_softc *chp = atabus_sc->sc_chan;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((error = kthread_create1(atabus_thread, atabus_sc, &chp->thread,
|
|
|
|
"%s", atabus_sc->sc_dev.dv_xname)) != 0)
|
|
|
|
printf("unable to create kernel thread for %s: error %d\n",
|
|
|
|
atabus_sc->sc_dev.dv_xname, error);
|
2003-09-25 23:29:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-08 14:58:12 +04:00
|
|
|
atabus_thread(arg)
|
|
|
|
void *arg;
|
2003-09-20 01:35:56 +04:00
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct atabus_softc *atabus_sc = arg;
|
|
|
|
struct channel_softc *chp = atabus_sc->sc_chan;
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
int s;
|
2003-09-20 01:35:56 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
s = splbio();
|
|
|
|
chp->ch_flags |= WDCF_TH_RUN;
|
|
|
|
splx(s);
|
|
|
|
atabusconfig(atabus_sc);
|
2003-10-30 00:44:41 +03:00
|
|
|
for(;;) {
|
2003-10-08 14:58:12 +04:00
|
|
|
s = splbio();
|
2003-10-30 00:44:41 +03:00
|
|
|
if ((chp->ch_flags & (WDCF_TH_RESET | WDCF_SHUTDOWN)) == 0 &&
|
|
|
|
((chp->ch_flags & WDCF_ACTIVE) == 0 ||
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze == 0)) {
|
2003-10-30 00:44:41 +03:00
|
|
|
chp->ch_flags &= ~WDCF_TH_RUN;
|
|
|
|
tsleep(&chp->thread, PRIBIO, "atath", 0);
|
|
|
|
chp->ch_flags |= WDCF_TH_RUN;
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
splx(s);
|
|
|
|
if (chp->ch_flags & WDCF_SHUTDOWN)
|
|
|
|
break;
|
|
|
|
s = splbio();
|
|
|
|
if (chp->ch_flags & WDCF_TH_RESET) {
|
|
|
|
int drive;
|
|
|
|
(void) wdcreset(chp, RESET_SLEEP);
|
|
|
|
for (drive = 0; drive < 2; drive++) {
|
|
|
|
chp->ch_drive[drive].state = 0;
|
|
|
|
}
|
|
|
|
chp->ch_flags &= ~WDCF_TH_RESET;
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze--;
|
2003-10-08 14:58:12 +04:00
|
|
|
wdcstart(chp);
|
|
|
|
} else if ((chp->ch_flags & WDCF_ACTIVE) != 0 &&
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze == 1) {
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
2003-10-30 01:05:15 +03:00
|
|
|
* caller has bumped queue_freeze, decrease it
|
2003-10-08 14:58:12 +04:00
|
|
|
*/
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze--;
|
2003-10-08 14:58:12 +04:00
|
|
|
xfer = chp->ch_queue->sc_xfer.tqh_first;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (xfer == NULL)
|
|
|
|
panic("channel active with no xfer ?");
|
|
|
|
#endif
|
|
|
|
xfer->c_start(chp, xfer);
|
2003-10-30 01:05:15 +03:00
|
|
|
} else if (chp->ch_queue->queue_freeze > 1) {
|
|
|
|
panic("queue_freeze");
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
chp->thread = NULL;
|
|
|
|
wakeup(&chp->ch_flags);
|
|
|
|
kthread_exit(0);
|
2003-09-20 01:35:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-08 14:58:12 +04:00
|
|
|
atabusconfig(atabus_sc)
|
|
|
|
struct atabus_softc *atabus_sc;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct channel_softc *chp = atabus_sc->sc_chan;
|
2003-10-30 04:58:17 +03:00
|
|
|
int i, error, need_delref = 0;
|
1999-03-10 16:11:43 +03:00
|
|
|
struct ataparams params;
|
2003-10-08 14:58:12 +04:00
|
|
|
struct atabus_initq *atabus_initq = NULL;
|
2003-10-25 12:30:46 +04:00
|
|
|
u_int8_t st0 = 0, st1 = 0;
|
2000-03-23 10:01:25 +03:00
|
|
|
|
1998-11-20 04:22:37 +03:00
|
|
|
if ((error = wdc_addref(chp)) != 0) {
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_error("%s: unable to enable controller\n",
|
1998-11-20 04:22:37 +03:00
|
|
|
chp->wdc->sc_dev.dv_xname);
|
2003-10-23 03:59:00 +04:00
|
|
|
goto out;
|
1998-11-20 04:22:37 +03:00
|
|
|
}
|
2003-10-23 03:59:00 +04:00
|
|
|
need_delref = 1;
|
1998-11-20 04:22:37 +03:00
|
|
|
|
2003-12-15 03:27:13 +03:00
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_DRVPROBE) != 0) {
|
|
|
|
if ((*chp->wdc->drv_probe)(chp) == 0) {
|
|
|
|
/* If no drives, abort attach here. */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else if (wdcprobe1(chp, 0) == 0) {
|
1998-11-20 04:22:37 +03:00
|
|
|
/* If no drives, abort attach here. */
|
1999-09-23 15:04:29 +04:00
|
|
|
goto out;
|
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++) {
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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,
|
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
|
|
|
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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,
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
tsleep(&atabus_sc, 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",
|
|
|
|
chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, st0, st1), DEBUG_PROBE);
|
|
|
|
|
|
|
|
/* 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++) {
|
|
|
|
chp->ch_drive[i].chnl_softc = chp;
|
|
|
|
chp->ch_drive[i].drive = i;
|
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 */
|
|
|
|
if ((chp->wdc->cap &
|
|
|
|
(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)
|
|
|
|
goto out;
|
|
|
|
|
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-10-08 14:58:12 +04:00
|
|
|
tsleep(&atabus_sc, 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)
|
|
|
|
goto out;
|
|
|
|
|
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",
|
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->wdc->sc_dev.dv_xname,
|
1999-11-28 23:04:22 +03:00
|
|
|
chp->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.
|
|
|
|
*/
|
2002-01-08 01:11:17 +03:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->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",
|
|
|
|
chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, i), DEBUG_PROBE);
|
|
|
|
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
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
if (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",
|
|
|
|
chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, i), DEBUG_PROBE);
|
|
|
|
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 */
|
2003-10-08 14:58:12 +04:00
|
|
|
if (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",
|
|
|
|
chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, i), DEBUG_PROBE);
|
|
|
|
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-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;
|
|
|
|
|
|
|
|
/* 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",
|
|
|
|
chp->wdc->sc_dev.dv_xname);
|
|
|
|
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;
|
|
|
|
adev.adev_channel = chp->channel;
|
|
|
|
adev.adev_openings = 1;
|
|
|
|
adev.adev_drv_data = &chp->ch_drive[i];
|
|
|
|
chp->ata_drives[i] = config_found(&atabus_sc->sc_dev,
|
|
|
|
&adev, wdprint);
|
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 */
|
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_MODE) {
|
|
|
|
chp->wdc->set_modes(chp);
|
|
|
|
wdc_print_modes(chp);
|
|
|
|
}
|
|
|
|
#if NATARAID > 0
|
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_RAID)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
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);
|
|
|
|
|
|
|
|
config_pending_decr();
|
2003-10-23 03:59:00 +04:00
|
|
|
if (need_delref)
|
|
|
|
wdc_delref(chp);
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
wdprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
struct ata_device *adev = aux;
|
|
|
|
if (pnp)
|
|
|
|
aprint_normal("wd at %s", pnp);
|
|
|
|
aprint_normal(" drive %d", adev->adev_drv_data->drive);
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
wdcprobe(chp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
{
|
2003-12-14 21:51:10 +03:00
|
|
|
return wdcprobe1(chp, 1);
|
2003-10-08 14:58:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-12-14 21:51:10 +03:00
|
|
|
wdcprobe1(chp, poll)
|
2003-10-08 14:58:12 +04:00
|
|
|
struct channel_softc *chp;
|
|
|
|
int poll;
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (chp->wdc == NULL ||
|
|
|
|
(chp->wdc->cap & WDC_CAPABILITY_NO_EXTRA_RESETS) == 0) {
|
|
|
|
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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,
|
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
|
|
|
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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,
|
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",
|
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->channel, st0, st1), DEBUG_PROBE);
|
|
|
|
|
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) {
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x02)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0) != 0x02)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
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
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x01;
|
|
|
|
}
|
|
|
|
/* Register writability test, drive 1. */
|
|
|
|
if (ret_value & 0x02) {
|
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->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);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_cyl_lo],
|
|
|
|
0, 0x02);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x02)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
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);
|
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0) != 0x02)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
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
|
|
|
if (bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0) != 0x01)
|
2003-10-08 14:58:12 +04:00
|
|
|
ret_value &= ~0x02;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_value == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2003-11-26 00:03:15 +03:00
|
|
|
s = splbio();
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_SELECT))
|
|
|
|
chp->wdc->select(chp,0);
|
|
|
|
/* assert SRST, wait for reset to complete */
|
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 */
|
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
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);
|
|
|
|
delay(10); /* 400ns delay */
|
2003-11-26 00:03:15 +03:00
|
|
|
/* ACK interrupt in case there is one pending left (Promise ATA100) */
|
2003-11-29 19:17:31 +03:00
|
|
|
if (chp->wdc && (chp->wdc->cap & WDC_CAPABILITY_IRQACK))
|
2003-11-26 00:03:15 +03:00
|
|
|
chp->wdc->irqack(chp);
|
|
|
|
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",
|
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe", chp->channel,
|
|
|
|
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
|
|
|
/*
|
2003-10-08 14:58:12 +04: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;
|
|
|
|
if (chp->wdc && chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->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",
|
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->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;
|
|
|
|
if (chp->wdc == NULL ||
|
|
|
|
(chp->wdc->cap & WDC_CAPABILITY_PREATA) != 0)
|
|
|
|
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
|
|
|
|
wdcattach(chp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* initialise global data */
|
|
|
|
callout_init(&chp->ch_callout);
|
|
|
|
if (inited == 0) {
|
|
|
|
/* Initialize the wdc_xfer pool. */
|
|
|
|
pool_init(&wdc_xfer_pool, sizeof(struct wdc_xfer), 0,
|
|
|
|
0, 0, "wdcspl", NULL);
|
|
|
|
inited++;
|
|
|
|
}
|
|
|
|
TAILQ_INIT(&chp->ch_queue->sc_xfer);
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze = 0;
|
2003-09-20 06:19:36 +04:00
|
|
|
|
2003-10-16 00:29:26 +04:00
|
|
|
chp->atabus = config_found(&chp->wdc->sc_dev, chp, atabusprint);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1999-09-23 15:04:29 +04:00
|
|
|
/*
|
|
|
|
* Call activate routine of underlying devices.
|
|
|
|
*/
|
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
atabusactivate(self, act)
|
1999-09-23 15:04:29 +04:00
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct atabus_softc *atabus_sc = (struct atabus_softc *)self;
|
|
|
|
struct channel_softc *chp = atabus_sc->sc_chan;
|
2000-04-05 10:27:36 +04:00
|
|
|
struct device *sc = 0;
|
2003-10-08 14:58:12 +04:00
|
|
|
int s, i, error = 0;
|
1999-09-23 15:04:29 +04:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
|
|
|
* We might call deactivate routine for
|
|
|
|
* the children of atapibus twice (once via
|
|
|
|
* atapibus, once directly), but since
|
|
|
|
* config_deactivate maintains DVF_ACTIVE flag,
|
|
|
|
* it's safe.
|
|
|
|
*/
|
|
|
|
sc = chp->atapibus;
|
|
|
|
if (sc != NULL) {
|
|
|
|
error = config_deactivate(sc);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
1999-09-23 15:04:29 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
sc = chp->ch_drive[i].drv_softc;
|
|
|
|
WDCDEBUG_PRINT(("atabusactivate: %s:"
|
|
|
|
" deactivating %s\n", atabus_sc->sc_dev.dv_xname,
|
|
|
|
sc == NULL ? "nodrv" : sc->dv_xname),
|
|
|
|
DEBUG_DETACH);
|
1999-09-23 15:04:29 +04:00
|
|
|
if (sc != NULL) {
|
|
|
|
error = config_deactivate(sc);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
#ifdef WDCDEBUG
|
2000-04-05 10:27:36 +04:00
|
|
|
if (sc && error != 0)
|
2003-10-08 14:58:12 +04:00
|
|
|
WDCDEBUG_PRINT(("atabusactivate: %s: "
|
|
|
|
"error %d deactivating %s\n", atabus_sc->sc_dev.dv_xname,
|
|
|
|
error, sc->dv_xname), DEBUG_DETACH);
|
1999-09-23 15:04:29 +04:00
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
int wdcactivate(self, act)
|
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-23 15:04:29 +04:00
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
atabusdetach(self, flags)
|
1999-09-23 15:04:29 +04:00
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
2003-10-08 14:58:12 +04:00
|
|
|
struct atabus_softc *atabus_sc = (struct atabus_softc *)self;
|
|
|
|
struct channel_softc *chp = atabus_sc->sc_chan;
|
2000-04-05 10:27:36 +04:00
|
|
|
struct device *sc = 0;
|
2003-10-08 14:58:12 +04:00
|
|
|
int i, error = 0;
|
1999-09-23 15:04:29 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/* shutdown channel */
|
|
|
|
chp->ch_flags |= WDCF_SHUTDOWN;
|
2003-10-16 00:29:26 +04:00
|
|
|
wakeup(&chp->thread);
|
2003-10-08 14:58:12 +04:00
|
|
|
while (chp->thread != NULL)
|
|
|
|
tsleep(&chp->ch_flags, PRIBIO, "atadown", 0);
|
1999-09-23 15:04:29 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
/*
|
|
|
|
* Detach atapibus and its children.
|
|
|
|
*/
|
|
|
|
sc = chp->atapibus;
|
|
|
|
if (sc != NULL) {
|
|
|
|
WDCDEBUG_PRINT(("atabusdetach: %s: detaching %s\n",
|
|
|
|
atabus_sc->sc_dev.dv_xname, sc->dv_xname), DEBUG_DETACH);
|
|
|
|
error = config_detach(sc, flags);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach our other children.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (chp->ch_drive[i].drive_flags & DRIVE_ATAPI)
|
|
|
|
continue;
|
|
|
|
sc = chp->ch_drive[i].drv_softc;
|
|
|
|
WDCDEBUG_PRINT(("atabusdetach: %s: detaching %s\n",
|
|
|
|
atabus_sc->sc_dev.dv_xname,
|
|
|
|
sc == NULL ? "nodrv" : sc->dv_xname),
|
|
|
|
DEBUG_DETACH);
|
1999-09-23 15:04:29 +04:00
|
|
|
if (sc != NULL) {
|
|
|
|
error = config_detach(sc, flags);
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_kill_pending(chp);
|
|
|
|
|
1999-09-23 15:04:29 +04:00
|
|
|
out:
|
|
|
|
#ifdef WDCDEBUG
|
2000-04-05 10:27:36 +04:00
|
|
|
if (sc && error != 0)
|
2003-10-08 14:58:12 +04:00
|
|
|
WDCDEBUG_PRINT(("atabusdetach: %s: error %d detaching %s\n",
|
|
|
|
atabus_sc->sc_dev.dv_xname, error, sc->dv_xname),
|
|
|
|
DEBUG_DETACH);
|
1999-09-23 15:04:29 +04:00
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
int
|
|
|
|
wdcdetach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct wdc_softc *wdc = (struct wdc_softc *)self;
|
|
|
|
struct channel_softc *chp;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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
|
1998-11-21 18:41:41 +03:00
|
|
|
wdcstart(chp)
|
|
|
|
struct channel_softc *chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
|
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 ? */
|
1998-11-21 18:41:41 +03:00
|
|
|
if ((xfer = chp->ch_queue->sc_xfer.tqh_first) == 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 */
|
1998-12-02 18:53:34 +03:00
|
|
|
chp = xfer->chp;
|
1998-11-29 20:34:49 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((chp->ch_flags & WDCF_ACTIVE) != 0 ) {
|
|
|
|
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
|
1998-11-21 18:41:41 +03:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_HWLOCK)
|
|
|
|
if (!(*chp->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,
|
1998-12-02 18:53:34 +03:00
|
|
|
chp->channel, xfer->drive), DEBUG_XFERS);
|
1998-10-12 20:09:10 +04:00
|
|
|
chp->ch_flags |= WDCF_ACTIVE;
|
1998-10-20 21:00:26 +04:00
|
|
|
if (chp->ch_drive[xfer->drive].drive_flags & DRIVE_RESET) {
|
|
|
|
chp->ch_drive[xfer->drive].drive_flags &= ~DRIVE_RESET;
|
|
|
|
chp->ch_drive[xfer->drive].state = 0;
|
|
|
|
}
|
2001-06-13 22:17:38 +04:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_NOIRQ)
|
|
|
|
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
|
|
|
|
wdcrestart(v)
|
|
|
|
void *v;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp = v;
|
|
|
|
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
|
|
|
|
wdcintr(arg)
|
|
|
|
void *arg;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp = arg;
|
|
|
|
struct wdc_xfer *xfer;
|
1999-10-21 18:37:58 +04:00
|
|
|
int ret;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
2000-03-21 01:53:36 +03:00
|
|
|
if ((chp->wdc->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
|
|
|
|
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);
|
|
|
|
xfer = chp->ch_queue->sc_xfer.tqh_first;
|
2000-04-01 18:32:22 +04:00
|
|
|
if (chp->ch_flags & WDCF_DMA_WAIT) {
|
|
|
|
chp->wdc->dma_status =
|
|
|
|
(*chp->wdc->dma_finish)(chp->wdc->dma_arg, chp->channel,
|
|
|
|
xfer->drive, 0);
|
|
|
|
if (chp->wdc->dma_status & WDC_DMAST_NOIRQ) {
|
|
|
|
/* 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
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_reset_channel(drvp, flags)
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ata_drive_datas *drvp;
|
2003-10-08 14:58:12 +04:00
|
|
|
int flags;
|
1998-10-12 20:09:10 +04:00
|
|
|
{
|
|
|
|
struct channel_softc *chp = drvp->chnl_softc;
|
|
|
|
int drive;
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("ata_reset_channel %s:%d for drive %d\n",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, drvp->drive),
|
|
|
|
DEBUG_FUNCS);
|
2003-10-30 00:44:41 +03:00
|
|
|
if ((flags & AT_POLL) == 0) {
|
2003-11-07 11:58:33 +03:00
|
|
|
if (chp->ch_flags & WDCF_TH_RESET) {
|
|
|
|
/* no need to schedule a reset more than one time */
|
|
|
|
return;
|
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
chp->ch_flags |= WDCF_TH_RESET;
|
2003-10-30 01:05:15 +03:00
|
|
|
chp->ch_queue->queue_freeze++;
|
2003-10-08 14:58:12 +04:00
|
|
|
wakeup(&chp->thread);
|
|
|
|
return;
|
|
|
|
}
|
2003-10-30 00:44:41 +03:00
|
|
|
(void) wdcreset(chp, RESET_POLL);
|
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
|
|
|
}
|
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
|
2003-10-08 14:58:12 +04:00
|
|
|
wdcreset(chp, poll)
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp;
|
2003-10-08 14:58:12 +04:00
|
|
|
int poll;
|
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
|
|
|
|
2002-01-08 01:11:17 +03:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->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) {
|
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
|
|
|
|
chp->wdc->irqack(chp);
|
|
|
|
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",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel);
|
|
|
|
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
|
2003-10-08 14:58:12 +04:00
|
|
|
__wdcwait_reset(chp, drv_mask, poll)
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp;
|
|
|
|
int drv_mask;
|
|
|
|
{
|
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++) {
|
2002-01-15 00:51:35 +03:00
|
|
|
if (chp->wdc && chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
2002-01-08 01:11:17 +03:00
|
|
|
chp->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,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDSD_IBM); /* master */
|
1999-03-31 15:18:31 +04:00
|
|
|
delay(10);
|
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);
|
1999-08-06 16:00:23 +04:00
|
|
|
#ifdef WDCDEBUG
|
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
|
|
|
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
|
2002-01-15 00:51:35 +03:00
|
|
|
if (chp->wdc && chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
2002-01-08 01:11:17 +03:00
|
|
|
chp->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,
|
1998-10-12 20:09:10 +04:00
|
|
|
WDSD_IBM | 0x10); /* slave */
|
1999-03-31 15:18:31 +04:00
|
|
|
delay(10);
|
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);
|
1999-08-06 16:00:23 +04:00
|
|
|
#ifdef WDCDEBUG
|
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
|
|
|
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
|
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",
|
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->channel, sc0, sn0, cl0, ch0), DEBUG_PROBE);
|
|
|
|
WDCDEBUG_PRINT(("%s:%d:1: after reset, sc=0x%x sn=0x%x "
|
|
|
|
"cl=0x%x ch=0x%x\n",
|
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe",
|
|
|
|
chp->channel, sc1, sn1, cl1, ch1), DEBUG_PROBE);
|
|
|
|
|
2003-10-30 01:09:41 +03:00
|
|
|
WDCDEBUG_PRINT(("%s:%d: wdcwait_reset() end, st0=0x%x st1=0x%x\n",
|
1999-03-31 15:18:31 +04:00
|
|
|
chp->wdc ? chp->wdc->sc_dev.dv_xname : "wdcprobe", chp->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.
|
|
|
|
*/
|
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
__wdcwait(chp, mask, bits, timeout)
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp;
|
|
|
|
int mask, bits, timeout;
|
|
|
|
{
|
|
|
|
u_char status;
|
|
|
|
int time = 0;
|
1999-02-21 05:07:52 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdcwait %s:%d\n", chp->wdc ?chp->wdc->sc_dev.dv_xname
|
1999-02-21 05:07:52 +03:00
|
|
|
:"none", chp->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) {
|
|
|
|
struct wdc_xfer *xfer = chp->ch_queue->sc_xfer.tqh_first;
|
|
|
|
if (xfer == NULL)
|
|
|
|
printf("%s channel %d: warning: busy-wait took %dus\n",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel,
|
|
|
|
WDCDELAY * time);
|
|
|
|
else
|
|
|
|
printf("%s:%d:%d: warning: busy-wait took %dus\n",
|
1998-12-02 18:53:34 +03:00
|
|
|
chp->wdc->sc_dev.dv_xname, chp->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
|
|
|
|
wdcwait(chp, mask, bits, timeout, flags)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
int mask, bits, timeout, flags;
|
|
|
|
{
|
|
|
|
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++;
|
2003-10-08 14:58:12 +04:00
|
|
|
wakeup(&chp->thread);
|
|
|
|
return(WDCWAIT_THR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
wdc_dmawait(chp, xfer, timeout)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
int timeout;
|
|
|
|
{
|
|
|
|
int time;
|
|
|
|
for (time = 0; time < timeout * 1000 / WDCDELAY; time++) {
|
|
|
|
chp->wdc->dma_status =
|
|
|
|
(*chp->wdc->dma_finish)(chp->wdc->dma_arg,
|
|
|
|
chp->channel, xfer->drive, 0);
|
|
|
|
if ((chp->wdc->dma_status & WDC_DMAST_NOIRQ) == 0)
|
|
|
|
return 0;
|
|
|
|
delay(WDCDELAY);
|
|
|
|
}
|
|
|
|
/* timeout, force a DMA halt */
|
|
|
|
chp->wdc->dma_status = (*chp->wdc->dma_finish)(chp->wdc->dma_arg,
|
|
|
|
chp->channel, xfer->drive, 1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
void
|
|
|
|
wdctimeout(arg)
|
|
|
|
void *arg;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp = (struct channel_softc *)arg;
|
|
|
|
struct wdc_xfer *xfer = chp->ch_queue->sc_xfer.tqh_first;
|
|
|
|
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) {
|
|
|
|
chp->wdc->dma_status =
|
|
|
|
(*chp->wdc->dma_finish)(chp->wdc->dma_arg,
|
|
|
|
chp->channel, xfer->drive, 1);
|
|
|
|
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
|
|
|
|
wdc_probe_caps(drvp)
|
|
|
|
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;
|
|
|
|
struct channel_softc *chp = drvp->chnl_softc;
|
|
|
|
struct device *drv_dev = drvp->drv_softc;
|
|
|
|
struct wdc_softc *wdc = chp->wdc;
|
|
|
|
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
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
1998-12-16 16:02:03 +03:00
|
|
|
/*
|
1999-02-08 18:22:28 +03:00
|
|
|
* downgrade the transfer mode of a drive after an error. return 1 if
|
1998-12-16 16:02:03 +03:00
|
|
|
* downgrade was possible, 0 otherwise.
|
|
|
|
*/
|
|
|
|
int
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_downgrade_mode(drvp, flags)
|
1998-12-16 16:02:03 +03:00
|
|
|
struct ata_drive_datas *drvp;
|
|
|
|
{
|
|
|
|
struct channel_softc *chp = drvp->chnl_softc;
|
|
|
|
struct device *drv_dev = drvp->drv_softc;
|
|
|
|
struct wdc_softc *wdc = chp->wdc;
|
|
|
|
int cf_flags = drv_dev->dv_cfdata->cf_flags;
|
|
|
|
|
|
|
|
/* if drive or controller don't know its mode, we can't do much */
|
|
|
|
if ((drvp->drive_flags & DRIVE_MODE) == 0 ||
|
|
|
|
(wdc->cap & WDC_CAPABILITY_MODE) == 0)
|
|
|
|
return 0;
|
|
|
|
/* current drive mode was set by a config flag, let it this way */
|
|
|
|
if ((cf_flags & ATA_CONFIG_PIO_SET) ||
|
|
|
|
(cf_flags & ATA_CONFIG_DMA_SET) ||
|
|
|
|
(cf_flags & ATA_CONFIG_UDMA_SET))
|
|
|
|
return 0;
|
|
|
|
|
1999-08-30 16:58:58 +04:00
|
|
|
/*
|
|
|
|
* If we were using Ultra-DMA mode > 2, downgrade to mode 2 first.
|
|
|
|
* Maybe we didn't properly notice the cable type
|
2000-01-17 03:01:00 +03:00
|
|
|
* If we were using Ultra-DMA mode 2, downgrade to mode 1 first.
|
|
|
|
* It helps in some cases.
|
1999-08-30 16:58:58 +04:00
|
|
|
*/
|
2000-01-17 03:01:00 +03:00
|
|
|
if ((drvp->drive_flags & DRIVE_UDMA) && drvp->UDMA_mode >= 2) {
|
|
|
|
drvp->UDMA_mode = (drvp->UDMA_mode == 2) ? 1 : 2;
|
|
|
|
printf("%s: transfer error, downgrading to Ultra-DMA mode %d\n",
|
1999-08-30 16:58:58 +04:00
|
|
|
drv_dev->dv_xname, drvp->UDMA_mode);
|
|
|
|
}
|
|
|
|
|
1999-03-07 17:02:53 +03:00
|
|
|
/*
|
|
|
|
* If we were using ultra-DMA, don't downgrade to multiword DMA
|
|
|
|
* if we noticed a CRC error. It has been noticed that CRC errors
|
|
|
|
* in ultra-DMA lead to silent data corruption in multiword DMA.
|
|
|
|
* Data corruption is less likely to occur in PIO mode.
|
|
|
|
*/
|
1999-08-30 16:58:58 +04:00
|
|
|
else if ((drvp->drive_flags & DRIVE_UDMA) &&
|
1999-03-07 17:02:53 +03:00
|
|
|
(drvp->drive_flags & DRIVE_DMAERR) == 0) {
|
1998-12-16 16:02:03 +03:00
|
|
|
drvp->drive_flags &= ~DRIVE_UDMA;
|
|
|
|
drvp->drive_flags |= DRIVE_DMA;
|
|
|
|
drvp->DMA_mode = drvp->DMA_cap;
|
1999-02-08 18:22:28 +03:00
|
|
|
printf("%s: transfer error, downgrading to DMA mode %d\n",
|
1998-12-16 16:02:03 +03:00
|
|
|
drv_dev->dv_xname, drvp->DMA_mode);
|
1999-03-07 17:02:53 +03:00
|
|
|
} else if (drvp->drive_flags & (DRIVE_DMA | DRIVE_UDMA)) {
|
|
|
|
drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);
|
1998-12-16 16:02:03 +03:00
|
|
|
drvp->PIO_mode = drvp->PIO_cap;
|
1999-02-08 18:22:28 +03:00
|
|
|
printf("%s: transfer error, downgrading to PIO mode %d\n",
|
1998-12-16 16:02:03 +03:00
|
|
|
drv_dev->dv_xname, drvp->PIO_mode);
|
|
|
|
} else /* already using PIO, can't downgrade */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wdc->set_modes(chp);
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_print_modes(chp);
|
|
|
|
/* reset the channel, which will shedule all drives for setup */
|
|
|
|
wdc_reset_channel(drvp, flags);
|
1998-12-16 16:02:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
int
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_exec_command(drvp, wdc_c)
|
|
|
|
struct ata_drive_datas *drvp;
|
|
|
|
struct wdc_command *wdc_c;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp = drvp->chnl_softc;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct wdc_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",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, drvp->drive),
|
|
|
|
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 */
|
|
|
|
xfer = wdc_get_xfer(wdc_c->flags & AT_WAIT ? WDC_CANSLEEP :
|
|
|
|
WDC_NOSLEEP);
|
|
|
|
if (xfer == NULL) {
|
|
|
|
return WDC_TRY_AGAIN;
|
|
|
|
}
|
|
|
|
|
2001-06-13 22:17:38 +04:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_NOIRQ)
|
|
|
|
wdc_c->flags |= AT_POLL;
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc_c->flags & AT_POLL)
|
|
|
|
xfer->c_flags |= C_POLL;
|
|
|
|
xfer->drive = drvp->drive;
|
|
|
|
xfer->databuf = wdc_c->data;
|
|
|
|
xfer->c_bcount = wdc_c->bcount;
|
|
|
|
xfer->cmd = wdc_c;
|
|
|
|
xfer->c_start = __wdccommand_start;
|
|
|
|
xfer->c_intr = __wdccommand_intr;
|
1999-10-20 19:22:24 +04:00
|
|
|
xfer->c_kill_xfer = __wdccommand_done;
|
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
|
|
|
|
if ((wdc_c->flags & AT_POLL) != 0 &&
|
|
|
|
(wdc_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
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc_c->flags & AT_DONE) {
|
|
|
|
ret = WDC_COMPLETE;
|
|
|
|
} else {
|
|
|
|
if (wdc_c->flags & AT_WAIT) {
|
1999-07-30 18:59:10 +04:00
|
|
|
while ((wdc_c->flags & AT_DONE) == 0) {
|
|
|
|
tsleep(wdc_c, PRIBIO, "wdccmd", 0);
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
ret = WDC_COMPLETE;
|
|
|
|
} else {
|
|
|
|
ret = WDC_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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-12 20:09:10 +04:00
|
|
|
__wdccommand_start(chp, xfer)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
{
|
|
|
|
int drive = xfer->drive;
|
|
|
|
struct wdc_command *wdc_c = xfer->cmd;
|
|
|
|
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_start %s:%d:%d\n",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive),
|
|
|
|
DEBUG_FUNCS);
|
1998-10-12 20:09:10 +04:00
|
|
|
|
2002-01-08 01:11:17 +03:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->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));
|
2003-10-08 14:58:12 +04:00
|
|
|
switch(wdcwait(chp, wdc_c->r_st_bmask | WDCS_DRQ,
|
|
|
|
wdc_c->r_st_bmask, wdc_c->timeout, wdc_c->flags)) {
|
|
|
|
case WDCWAIT_OK:
|
|
|
|
break;
|
|
|
|
case WDCWAIT_TOUT:
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_c->flags |= AT_TIMEOU;
|
|
|
|
__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;
|
|
|
|
}
|
|
|
|
if (wdc_c->flags & AT_POLL) {
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
wdccommand(chp, drive, wdc_c->r_command, wdc_c->r_cyl, wdc_c->r_head,
|
|
|
|
wdc_c->r_sector, wdc_c->r_count, wdc_c->r_precomp);
|
2003-10-09 22:40:19 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((wdc_c->flags & AT_POLL) == 0) {
|
|
|
|
chp->ch_flags |= WDCF_IRQ_WAIT; /* wait for interrupt */
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&chp->ch_callout, wdc_c->timeout / 1000 * hz,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-04-02 01:46:28 +04:00
|
|
|
__wdccommand_intr(chp, xfer, irq)
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc *chp;
|
|
|
|
struct wdc_xfer *xfer;
|
1999-04-02 01:46:28 +04:00
|
|
|
int irq;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct wdc_command *wdc_c = xfer->cmd;
|
|
|
|
int bcount = wdc_c->bcount;
|
|
|
|
char *data = wdc_c->data;
|
2003-10-08 14:58:12 +04:00
|
|
|
int wflags;
|
|
|
|
|
|
|
|
if ((wdc_c->flags & (AT_WAIT | AT_POLL)) == (AT_WAIT | AT_POLL)) {
|
|
|
|
/* 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
|
|
|
|
2002-04-10 01:17:53 +04:00
|
|
|
again:
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_intr %s:%d:%d\n",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive), 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,
|
2003-10-08 14:58:12 +04:00
|
|
|
WDSD_IBM | (xfer->drive << 4));
|
2002-04-10 01:17:53 +04:00
|
|
|
if ((wdc_c->flags & AT_XFDONE) != 0) {
|
|
|
|
/*
|
|
|
|
* We have completed a data xfer. The drive should now be
|
|
|
|
* in its initial state
|
|
|
|
*/
|
|
|
|
if (wdcwait(chp, wdc_c->r_st_bmask | WDCS_DRQ,
|
2003-10-08 14:58:12 +04:00
|
|
|
wdc_c->r_st_bmask, (irq == 0) ? wdc_c->timeout : 0,
|
|
|
|
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 */
|
|
|
|
wdc_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;
|
2002-04-10 01:17:53 +04:00
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdcwait(chp, wdc_c->r_st_pmask, wdc_c->r_st_pmask,
|
2003-10-08 14:58:12 +04:00
|
|
|
(irq == 0) ? wdc_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 */
|
|
|
|
wdc_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
|
|
|
}
|
2000-06-13 01:10:40 +04:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_IRQACK)
|
|
|
|
chp->wdc->irqack(chp);
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc_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) {
|
|
|
|
wdc_c->flags |= AT_TIMEOU;
|
|
|
|
goto out;
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (chp->ch_drive[xfer->drive].drive_flags & DRIVE_CAP32) {
|
|
|
|
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)
|
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_multi_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0,
|
|
|
|
(u_int16_t *)data, bcount >> 1);
|
2002-04-10 01:17:53 +04:00
|
|
|
/* at this point the drive should be in its initial state */
|
|
|
|
wdc_c->flags |= AT_XFDONE;
|
2003-10-08 14:58:12 +04:00
|
|
|
/* XXX should read status register here ? */
|
1998-10-12 20:09:10 +04:00
|
|
|
} else if (wdc_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) {
|
|
|
|
wdc_c->flags |= AT_TIMEOU;
|
|
|
|
goto out;
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
if (chp->ch_drive[xfer->drive].drive_flags & DRIVE_CAP32) {
|
|
|
|
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)
|
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_multi_2(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_data], 0,
|
|
|
|
(u_int16_t *)data, bcount >> 1);
|
2002-04-10 01:17:53 +04:00
|
|
|
wdc_c->flags |= AT_XFDONE;
|
|
|
|
if ((wdc_c->flags & AT_POLL) == 0) {
|
|
|
|
chp->ch_flags |= WDCF_IRQ_WAIT; /* wait for interrupt */
|
|
|
|
callout_reset(&chp->ch_callout,
|
|
|
|
wdc_c->timeout / 1000 * hz, wdctimeout, chp);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
goto again;
|
|
|
|
}
|
1997-08-27 15:22:52 +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
|
|
|
out:
|
1998-10-12 20:09:10 +04:00
|
|
|
__wdccommand_done(chp, xfer);
|
|
|
|
return 1;
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-12 20:09:10 +04:00
|
|
|
__wdccommand_done(chp, xfer)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
struct wdc_xfer *xfer;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct wdc_command *wdc_c = xfer->cmd;
|
|
|
|
|
1998-10-13 19:02:41 +04:00
|
|
|
WDCDEBUG_PRINT(("__wdccommand_done %s:%d:%d\n",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, xfer->drive), DEBUG_FUNCS);
|
1999-08-06 16:00:23 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&chp->ch_callout);
|
1999-08-06 16:00:23 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if (chp->ch_status & WDCS_DWF)
|
|
|
|
wdc_c->flags |= AT_DF;
|
|
|
|
if (chp->ch_status & WDCS_ERR) {
|
|
|
|
wdc_c->flags |= AT_ERROR;
|
|
|
|
wdc_c->r_error = chp->ch_error;
|
|
|
|
}
|
|
|
|
wdc_c->flags |= AT_DONE;
|
2000-03-21 01:53:36 +03:00
|
|
|
if ((wdc_c->flags & AT_READREG) != 0 &&
|
|
|
|
(chp->wdc->sc_dev.dv_flags & DVF_ACTIVE) != 0 &&
|
1999-10-20 19:22:24 +04:00
|
|
|
(wdc_c->flags & (AT_ERROR | AT_DF)) == 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
|
|
|
wdc_c->r_head = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sdh], 0);
|
|
|
|
wdc_c->r_cyl = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_hi], 0) << 8;
|
|
|
|
wdc_c->r_cyl |= bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_cyl_lo], 0);
|
|
|
|
wdc_c->r_sector = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_sector], 0);
|
|
|
|
wdc_c->r_count = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_seccnt], 0);
|
|
|
|
wdc_c->r_error = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_error], 0);
|
|
|
|
wdc_c->r_precomp = bus_space_read_1(chp->cmd_iot,
|
|
|
|
chp->cmd_iohs[wd_precomp], 0);
|
1998-11-24 02:02:11 +03:00
|
|
|
}
|
2003-10-08 14:58:12 +04:00
|
|
|
|
2003-10-07 01:51:31 +04:00
|
|
|
if (wdc_c->flags & AT_POLL) {
|
|
|
|
/* enable interrupts */
|
|
|
|
bus_space_write_1(chp->ctl_iot, chp->ctl_ioh, wd_aux_ctlr,
|
|
|
|
WDCTL_4BIT);
|
|
|
|
}
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_free_xfer(chp, xfer);
|
1999-08-09 13:55:18 +04:00
|
|
|
if (wdc_c->flags & AT_WAIT)
|
|
|
|
wakeup(wdc_c);
|
|
|
|
else if (wdc_c->callback)
|
|
|
|
wdc_c->callback(wdc_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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
wdccommand(chp, drive, command, cylin, head, sector, count, precomp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
u_int8_t drive;
|
|
|
|
u_int8_t command;
|
|
|
|
u_int16_t cylin;
|
|
|
|
u_int8_t head, sector, count, precomp;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
WDCDEBUG_PRINT(("wdccommand %s:%d:%d: command=0x%x cylin=%d head=%d "
|
|
|
|
"sector=%d count=%d precomp=%d\n", chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, drive, command, cylin, head, sector, count, precomp),
|
|
|
|
DEBUG_FUNCS);
|
|
|
|
|
2002-01-08 01:11:17 +03:00
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->wdc->select(chp,drive);
|
|
|
|
|
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);
|
|
|
|
/* Load parameters. wd_features(ATA/ATAPI) = wd_precomp(ST506) */
|
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_precomp], 0,
|
1998-10-12 20:09:10 +04:00
|
|
|
precomp);
|
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);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_sector], 0, sector);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_seccnt], 0, count);
|
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
|
|
|
|
wdccommandext(chp, drive, command, blkno, count)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
u_int8_t drive;
|
|
|
|
u_int8_t command;
|
|
|
|
u_int64_t blkno;
|
|
|
|
u_int16_t count;
|
|
|
|
{
|
|
|
|
WDCDEBUG_PRINT(("wdccommandext %s:%d:%d: command=0x%x blkno=%d "
|
|
|
|
"count=%d\n", chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, drive, command, (u_int32_t) blkno, count),
|
|
|
|
DEBUG_FUNCS);
|
|
|
|
|
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->wdc->select(chp,drive);
|
|
|
|
|
|
|
|
/* 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_hi],
|
|
|
|
0, blkno >> 40);
|
|
|
|
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_lo],
|
|
|
|
0, blkno >> 24);
|
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);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_hi],
|
|
|
|
0, blkno >> 16);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_mi],
|
|
|
|
0, blkno >> 8);
|
|
|
|
bus_space_write_1(chp->cmd_iot, chp->cmd_iohs[wd_lba_lo], 0, blkno);
|
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
|
|
|
|
wdccommandshort(chp, drive, command)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
int drive;
|
|
|
|
int command;
|
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",
|
|
|
|
chp->wdc->sc_dev.dv_xname, chp->channel, drive, command),
|
|
|
|
DEBUG_FUNCS);
|
2002-01-08 01:11:17 +03:00
|
|
|
|
|
|
|
if (chp->wdc->cap & WDC_CAPABILITY_SELECT)
|
|
|
|
chp->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
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_exec_xfer(chp, xfer)
|
|
|
|
struct channel_softc *chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
{
|
1998-10-13 13:33:59 +04:00
|
|
|
WDCDEBUG_PRINT(("wdc_exec_xfer %p channel %d drive %d\n", xfer,
|
|
|
|
chp->channel, xfer->drive), DEBUG_XFERS);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* complete xfer setup */
|
1998-12-02 18:53:34 +03:00
|
|
|
xfer->chp = chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* If we are a polled command, and the list is not empty,
|
|
|
|
* we are doing a dump. Drop the list to allow the polled command
|
|
|
|
* to complete, we're going to reboot soon anyway.
|
|
|
|
*/
|
|
|
|
if ((xfer->c_flags & C_POLL) != 0 &&
|
|
|
|
chp->ch_queue->sc_xfer.tqh_first != NULL) {
|
|
|
|
TAILQ_INIT(&chp->ch_queue->sc_xfer);
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
/* insert at the end of command list */
|
1998-10-12 20:09:10 +04:00
|
|
|
TAILQ_INSERT_TAIL(&chp->ch_queue->sc_xfer,xfer , c_xferchain);
|
|
|
|
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
|
|
|
|
|
|
|
struct wdc_xfer *
|
|
|
|
wdc_get_xfer(flags)
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct wdc_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) {
|
|
|
|
memset(xfer, 0, sizeof(struct wdc_xfer));
|
|
|
|
}
|
1997-08-27 15:22:52 +04:00
|
|
|
return xfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-12 20:09:10 +04:00
|
|
|
wdc_free_xfer(chp, xfer)
|
|
|
|
struct channel_softc *chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct wdc_softc *wdc = chp->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();
|
1998-10-12 20:09:10 +04:00
|
|
|
chp->ch_flags &= ~WDCF_ACTIVE;
|
|
|
|
TAILQ_REMOVE(&chp->ch_queue->sc_xfer, xfer, c_xferchain);
|
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
|
|
|
/*
|
|
|
|
* Kill off all pending xfers for a channel_softc.
|
|
|
|
*
|
|
|
|
* Must be called at splbio().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wdc_kill_pending(chp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
{
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
|
|
|
|
while ((xfer = TAILQ_FIRST(&chp->ch_queue->sc_xfer)) != NULL) {
|
|
|
|
chp = xfer->chp;
|
|
|
|
(*xfer->c_kill_xfer)(chp, xfer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
static void
|
|
|
|
__wdcerror(chp, msg)
|
|
|
|
struct channel_softc *chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
char *msg;
|
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct wdc_xfer *xfer = chp->ch_queue->sc_xfer.tqh_first;
|
2000-04-05 10:27:36 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
if (xfer == NULL)
|
1998-10-12 20:09:10 +04:00
|
|
|
printf("%s:%d: %s\n", chp->wdc->sc_dev.dv_xname, chp->channel,
|
|
|
|
msg);
|
1997-08-27 15:22:52 +04:00
|
|
|
else
|
1998-10-12 20:09:10 +04:00
|
|
|
printf("%s:%d:%d: %s\n", chp->wdc->sc_dev.dv_xname,
|
1998-12-02 18:53:34 +03:00
|
|
|
chp->channel, xfer->drive, msg);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the bit bucket
|
|
|
|
*/
|
|
|
|
void
|
1998-10-12 20:09:10 +04:00
|
|
|
wdcbit_bucket(chp, size)
|
|
|
|
struct channel_softc *chp;
|
1997-08-27 15:22:52 +04:00
|
|
|
int size;
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
wdc_addref(chp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
{
|
|
|
|
struct wdc_softc *wdc = chp->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
|
|
|
|
wdc_delref(chp)
|
|
|
|
struct channel_softc *chp;
|
|
|
|
{
|
|
|
|
struct wdc_softc *wdc = chp->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
|
|
|
|
|
|
|
void
|
|
|
|
wdc_print_modes(struct channel_softc *chp)
|
|
|
|
{
|
|
|
|
int drive;
|
|
|
|
struct ata_drive_datas *drvp;
|
|
|
|
|
|
|
|
for (drive = 0; drive < 2; drive++) {
|
|
|
|
drvp = &chp->ch_drive[drive];
|
|
|
|
if ((drvp->drive_flags & DRIVE) == 0)
|
|
|
|
continue;
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal("%s(%s:%d:%d): using PIO mode %d",
|
2000-11-08 20:57:36 +03:00
|
|
|
drvp->drv_softc->dv_xname,
|
|
|
|
chp->wdc->sc_dev.dv_xname,
|
|
|
|
chp->channel, drive, drvp->PIO_mode);
|
|
|
|
if (drvp->drive_flags & DRIVE_DMA)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(", DMA mode %d", drvp->DMA_mode);
|
2000-11-08 20:57:36 +03:00
|
|
|
if (drvp->drive_flags & DRIVE_UDMA) {
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(", Ultra-DMA mode %d", drvp->UDMA_mode);
|
2000-11-08 20:57:36 +03:00
|
|
|
if (drvp->UDMA_mode == 2)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/33)");
|
2000-11-08 20:57:36 +03:00
|
|
|
else if (drvp->UDMA_mode == 4)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/66)");
|
2000-11-08 20:57:36 +03:00
|
|
|
else if (drvp->UDMA_mode == 5)
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (Ultra/100)");
|
|
|
|
else if (drvp->UDMA_mode == 6)
|
|
|
|
aprint_normal(" (Ultra/133)");
|
2000-11-08 20:57:36 +03:00
|
|
|
}
|
|
|
|
if (drvp->drive_flags & (DRIVE_DMA | DRIVE_UDMA))
|
2003-05-18 01:52:03 +04:00
|
|
|
aprint_normal(" (using DMA data transfers)");
|
|
|
|
aprint_normal("\n");
|
2000-11-08 20:57:36 +03:00
|
|
|
}
|
|
|
|
}
|