2003-12-03 15:01:18 +03:00
|
|
|
/* $NetBSD: wdcvar.h,v 1.45 2003/12/03 12:01:18 bouyer Exp $ */
|
1998-01-15 02:41:59 +03: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.
|
1998-01-15 02:41:59 +03: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
|
|
|
*
|
|
|
|
* 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
|
1998-10-12 20:09:10 +04:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1998-01-15 02:41:59 +03:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1998-10-12 20:09:10 +04:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1998-01-15 02:41:59 +03:00
|
|
|
* 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.
|
1998-01-15 02:41:59 +03: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.
|
1998-01-15 02:41:59 +03:00
|
|
|
*/
|
|
|
|
|
2001-04-25 21:53:04 +04:00
|
|
|
/* XXX For scsipi_adapter and scsipi_channel. */
|
1998-11-20 00:43:00 +03:00
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
2000-04-01 18:32:22 +04:00
|
|
|
#include <dev/scsipi/atapiconf.h>
|
1998-11-20 00:43:00 +03:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WAITTIME (10 * hz) /* time to wait for a completion */
|
|
|
|
/* this is a lot for hard drives, but not for cdroms */
|
1998-09-22 04:21:16 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_queue { /* per channel queue (may be shared) */
|
|
|
|
TAILQ_HEAD(xferhead, wdc_xfer) sc_xfer;
|
2003-10-30 01:05:15 +03:00
|
|
|
int queue_freeze;
|
1998-10-12 20:09:10 +04:00
|
|
|
};
|
|
|
|
|
2003-12-03 15:01:18 +03:00
|
|
|
#define WDC_NREG 8 /* number of command registers */
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
struct channel_softc { /* Per channel data */
|
2000-03-23 11:20:06 +03:00
|
|
|
/* Our timeout callout */
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout ch_callout;
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Our location */
|
|
|
|
int channel;
|
|
|
|
/* Our controller's softc */
|
|
|
|
struct wdc_softc *wdc;
|
|
|
|
/* Our registers */
|
|
|
|
bus_space_tag_t cmd_iot;
|
There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.
To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.
bus_space_write_4(tag, handle, offset, value)
becomes
bus_space_write_4(tag, handles[offset], 0, value)
Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
2003-11-28 02:02:40 +03:00
|
|
|
bus_space_handle_t cmd_baseioh;
|
|
|
|
bus_space_handle_t cmd_iohs[WDC_NREG];
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_tag_t ctl_iot;
|
|
|
|
bus_space_handle_t ctl_ioh;
|
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
|
|
|
/* data32{iot,ioh} are only used for 32 bit data xfers */
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_tag_t data32iot;
|
|
|
|
bus_space_handle_t data32ioh;
|
|
|
|
/* Our state */
|
|
|
|
int ch_flags;
|
|
|
|
#define WDCF_ACTIVE 0x01 /* channel is active */
|
2003-10-08 14:58:12 +04:00
|
|
|
#define WDCF_SHUTDOWN 0x02 /* channel is shutting down */
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WDCF_IRQ_WAIT 0x10 /* controller is waiting for irq */
|
2000-04-01 18:32:22 +04:00
|
|
|
#define WDCF_DMA_WAIT 0x20 /* controller is waiting for DMA */
|
2003-09-20 01:35:56 +04:00
|
|
|
#define WDCF_DISABLED 0x80 /* channel is disabled */
|
2003-10-08 14:58:12 +04:00
|
|
|
#define WDCF_TH_RUN 0x100 /* the kenrel thread is working */
|
|
|
|
#define WDCF_TH_RESET 0x200 /* someone ask the thread to reset */
|
1998-10-12 20:09:10 +04:00
|
|
|
u_int8_t ch_status; /* copy of status register */
|
|
|
|
u_int8_t ch_error; /* copy of error register */
|
|
|
|
/* per-drive infos */
|
|
|
|
struct ata_drive_datas ch_drive[2];
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
struct device *atabus; /* self */
|
|
|
|
struct device *atapibus; /* children */
|
2001-04-25 21:53:04 +04:00
|
|
|
struct scsipi_channel ch_atapi_channel;
|
1999-09-23 15:04:29 +04:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
struct device *ata_drives[2]; /* children */
|
2003-01-27 21:21:23 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* channel queues. May be the same for all channels, if hw channels
|
2003-11-02 14:07:44 +03:00
|
|
|
* are not independent.
|
1998-10-12 20:09:10 +04:00
|
|
|
*/
|
|
|
|
struct channel_queue *ch_queue;
|
2003-10-08 14:58:12 +04:00
|
|
|
/* the channel kenrel thread */
|
|
|
|
struct proc *thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct atabus_softc { /* the atabus softc */
|
|
|
|
struct device sc_dev;
|
|
|
|
struct channel_softc *sc_chan;
|
1998-10-12 20:09:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wdc_softc { /* Per controller state */
|
|
|
|
struct device sc_dev;
|
|
|
|
/* mandatory fields */
|
|
|
|
int cap;
|
|
|
|
/* Capabilities supported by the controller */
|
|
|
|
#define WDC_CAPABILITY_DATA16 0x0001 /* can do 16-bit data access */
|
|
|
|
#define WDC_CAPABILITY_DATA32 0x0002 /* can do 32-bit data access */
|
|
|
|
#define WDC_CAPABILITY_MODE 0x0004 /* controller knows its PIO/DMA modes */
|
|
|
|
#define WDC_CAPABILITY_DMA 0x0008 /* DMA */
|
|
|
|
#define WDC_CAPABILITY_UDMA 0x0010 /* Ultra-DMA/33 */
|
|
|
|
#define WDC_CAPABILITY_HWLOCK 0x0020 /* Needs to lock HW */
|
|
|
|
#define WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
|
|
|
|
#define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
|
|
|
|
#define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
|
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
|
|
|
#define WDC_CAPABILITY_PREATA 0x0200 /* ctrl can be a pre-ata one */
|
2000-06-13 01:10:40 +04:00
|
|
|
#define WDC_CAPABILITY_IRQACK 0x0400 /* callback to ack interrupt */
|
2001-06-13 22:17:38 +04:00
|
|
|
#define WDC_CAPABILITY_NOIRQ 0x1000 /* Controller never interrupts */
|
2002-01-08 01:11:17 +03:00
|
|
|
#define WDC_CAPABILITY_SELECT 0x2000 /* Controller selects target */
|
2003-01-27 21:21:23 +03:00
|
|
|
#define WDC_CAPABILITY_RAID 0x4000 /* Controller "supports" RAID */
|
1998-12-03 21:24:30 +03:00
|
|
|
u_int8_t PIO_cap; /* highest PIO mode supported */
|
|
|
|
u_int8_t DMA_cap; /* highest DMA mode supported */
|
|
|
|
u_int8_t UDMA_cap; /* highest UDMA mode supported */
|
1998-10-12 20:09:10 +04:00
|
|
|
int nchannels; /* Number of channels on this controller */
|
1998-11-21 18:41:41 +03:00
|
|
|
struct channel_softc **channels; /* channels-specific datas (array) */
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-11-20 00:43:00 +03:00
|
|
|
/*
|
|
|
|
* The reference count here is used for both IDE and ATAPI devices.
|
|
|
|
*/
|
2000-04-01 18:32:22 +04:00
|
|
|
struct atapi_adapter sc_atapi_adapter;
|
1998-11-20 00:43:00 +03:00
|
|
|
|
1998-01-15 02:41:59 +03:00
|
|
|
/* if WDC_CAPABILITY_DMA set in 'cap' */
|
1998-10-12 20:09:10 +04:00
|
|
|
void *dma_arg;
|
|
|
|
int (*dma_init) __P((void *, int, int, void *, size_t,
|
|
|
|
int));
|
2000-04-01 18:32:22 +04:00
|
|
|
void (*dma_start) __P((void *, int, int));
|
1998-10-12 20:09:10 +04:00
|
|
|
int (*dma_finish) __P((void *, int, int, int));
|
2000-04-01 18:32:22 +04:00
|
|
|
/* flags passed to dma_init */
|
2003-04-28 09:20:29 +04:00
|
|
|
#define WDC_DMA_READ 0x01
|
|
|
|
#define WDC_DMA_IRQW 0x02
|
|
|
|
#define WDC_DMA_LBA48 0x04
|
2000-04-01 18:32:22 +04:00
|
|
|
int dma_status; /* status returned from dma_finish() */
|
|
|
|
#define WDC_DMAST_NOIRQ 0x01 /* missing IRQ */
|
|
|
|
#define WDC_DMAST_ERR 0x02 /* DMA error */
|
|
|
|
#define WDC_DMAST_UNDER 0x04 /* DMA underrun */
|
1998-04-07 23:51:57 +04:00
|
|
|
|
|
|
|
/* if WDC_CAPABILITY_HWLOCK set in 'cap' */
|
1998-10-12 20:09:10 +04:00
|
|
|
int (*claim_hw) __P((void *, int));
|
|
|
|
void (*free_hw) __P((void *));
|
1998-12-16 15:46:47 +03:00
|
|
|
|
|
|
|
/* if WDC_CAPABILITY_MODE set in 'cap' */
|
|
|
|
void (*set_modes) __P((struct channel_softc *));
|
2000-06-13 01:10:40 +04:00
|
|
|
|
2002-01-08 01:11:17 +03:00
|
|
|
/* if WDC_CAPABILITY_SELECT set in 'cap' */
|
|
|
|
void (*select) __P((struct channel_softc *,int));
|
|
|
|
|
2000-06-13 01:10:40 +04:00
|
|
|
/* if WDC_CAPABILITY_IRQACK set in 'cap' */
|
|
|
|
void (*irqack) __P((struct channel_softc *));
|
1998-01-15 02:41:59 +03:00
|
|
|
};
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* Description of a command to be handled by a controller.
|
|
|
|
* These commands are queued in a list.
|
|
|
|
*/
|
|
|
|
struct wdc_xfer {
|
|
|
|
volatile u_int c_flags;
|
1999-08-09 13:56:00 +04:00
|
|
|
#define C_ATAPI 0x0001 /* xfer is ATAPI request */
|
|
|
|
#define C_TIMEOU 0x0002 /* xfer processing timed out */
|
|
|
|
#define C_POLL 0x0004 /* cmd is polled */
|
|
|
|
#define C_DMA 0x0008 /* cmd uses DMA */
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-12-02 18:53:34 +03:00
|
|
|
/* Informations about our location */
|
|
|
|
struct channel_softc *chp;
|
1998-10-12 20:09:10 +04:00
|
|
|
u_int8_t drive;
|
1998-09-10 23:24:45 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/* Information about the current transfer */
|
|
|
|
void *cmd; /* wdc, ata or scsipi command structure */
|
|
|
|
void *databuf;
|
|
|
|
int c_bcount; /* byte count left */
|
|
|
|
int c_skip; /* bytes already transferred */
|
2001-12-01 03:00:29 +03:00
|
|
|
int c_dscpoll; /* counter for dsc polling (ATAPI) */
|
1998-10-12 20:09:10 +04:00
|
|
|
TAILQ_ENTRY(wdc_xfer) c_xferchain;
|
|
|
|
void (*c_start) __P((struct channel_softc *, struct wdc_xfer *));
|
1999-04-02 01:46:28 +04:00
|
|
|
int (*c_intr) __P((struct channel_softc *, struct wdc_xfer *, int));
|
1999-10-20 19:22:24 +04:00
|
|
|
void (*c_kill_xfer) __P((struct channel_softc *, struct wdc_xfer *));
|
1998-10-12 20:09:10 +04:00
|
|
|
};
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* Public functions which can be called by ATA or ATAPI specific parts,
|
|
|
|
* or bus-specific backends.
|
|
|
|
*/
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
int wdcprobe __P((struct channel_softc *));
|
2003-10-08 14:58:12 +04:00
|
|
|
void wdcattach __P((struct channel_softc *));
|
1999-09-23 15:04:29 +04:00
|
|
|
int wdcdetach __P((struct device *, int));
|
|
|
|
int wdcactivate __P((struct device *, enum devact));
|
1998-10-12 20:09:10 +04:00
|
|
|
int wdcintr __P((void *));
|
|
|
|
void wdc_exec_xfer __P((struct channel_softc *, struct wdc_xfer *));
|
|
|
|
struct wdc_xfer *wdc_get_xfer __P((int)); /* int = WDC_NOSLEEP/CANSLEEP */
|
|
|
|
#define WDC_CANSLEEP 0x00
|
|
|
|
#define WDC_NOSLEEP 0x01
|
|
|
|
void wdc_free_xfer __P((struct channel_softc *, struct wdc_xfer *));
|
1998-11-21 18:41:41 +03:00
|
|
|
void wdcstart __P((struct channel_softc *));
|
1998-10-12 20:09:10 +04:00
|
|
|
void wdcrestart __P((void*));
|
|
|
|
int wdcreset __P((struct channel_softc *, int));
|
2003-10-08 14:58:12 +04:00
|
|
|
#define RESET_POLL 1
|
|
|
|
#define RESET_SLEEP 0 /* wdcreset will use tsleep() */
|
|
|
|
int wdcwait __P((struct channel_softc *, int, int, int, int));
|
|
|
|
#define WDCWAIT_OK 0 /* we have what we asked */
|
|
|
|
#define WDCWAIT_TOUT -1 /* timed out */
|
|
|
|
#define WDCWAIT_THR 1 /* return, the kernel thread has been awakened */
|
2000-04-01 18:32:22 +04:00
|
|
|
int wdc_dmawait __P((struct channel_softc *, struct wdc_xfer *, int));
|
1998-10-12 20:09:10 +04:00
|
|
|
void wdcbit_bucket __P(( struct channel_softc *, int));
|
|
|
|
void wdccommand __P((struct channel_softc *, u_int8_t, u_int8_t, u_int16_t,
|
2002-01-13 20:24:28 +03:00
|
|
|
u_int8_t, u_int8_t, u_int8_t, u_int8_t));
|
|
|
|
void wdccommandext __P((struct channel_softc *, u_int8_t, u_int8_t, u_int64_t,
|
|
|
|
u_int16_t));
|
1998-10-12 20:09:10 +04:00
|
|
|
void wdccommandshort __P((struct channel_softc *, int, int));
|
|
|
|
void wdctimeout __P((void *arg));
|
2003-10-08 14:58:12 +04:00
|
|
|
void wdc_reset_channel __P((struct ata_drive_datas *, int));
|
2001-12-03 03:11:15 +03:00
|
|
|
int wdc_exec_command __P((struct ata_drive_datas *, struct wdc_command*));
|
|
|
|
#define WDC_COMPLETE 0x01
|
|
|
|
#define WDC_QUEUED 0x02
|
|
|
|
#define WDC_TRY_AGAIN 0x03
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-11-20 04:22:37 +03:00
|
|
|
int wdc_addref __P((struct channel_softc *));
|
|
|
|
void wdc_delref __P((struct channel_softc *));
|
1999-10-20 19:22:24 +04:00
|
|
|
void wdc_kill_pending __P((struct channel_softc *));
|
1998-11-20 04:22:37 +03:00
|
|
|
|
2000-11-08 20:57:36 +03:00
|
|
|
void wdc_print_modes (struct channel_softc *);
|
2001-12-03 03:11:15 +03:00
|
|
|
void wdc_probe_caps __P((struct ata_drive_datas*));
|
2000-11-08 20:57:36 +03:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
/*
|
|
|
|
* ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
|
|
|
|
* command is aborted.
|
|
|
|
*/
|
2003-10-08 14:58:12 +04:00
|
|
|
#define wait_for_drq(chp, timeout, flags) \
|
|
|
|
wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
|
|
|
|
#define wait_for_unbusy(chp, timeout, flags) \
|
|
|
|
wdcwait((chp), 0, 0, (timeout), (flags))
|
|
|
|
#define wait_for_ready(chp, timeout, flags) \
|
|
|
|
wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
|
1998-10-12 20:09:10 +04:00
|
|
|
/* ATA/ATAPI specs says a device can take 31s to reset */
|
|
|
|
#define WDC_RESET_WAIT 31000
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
void wdc_atapibus_attach __P((struct atabus_softc *));
|