2020-04-13 13:49:34 +03:00
|
|
|
/* $NetBSD: wdcvar.h,v 1.100 2020/04/13 10:49:34 jdolecek Exp $ */
|
1998-01-15 02:41:59 +03:00
|
|
|
|
1998-08-15 14:10:47 +04:00
|
|
|
/*-
|
2005-03-02 15:25:27 +03:00
|
|
|
* Copyright (c) 1998, 2003, 2004 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
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
2004-01-01 23:18:33 +03:00
|
|
|
#ifndef _DEV_IC_WDCVAR_H_
|
|
|
|
#define _DEV_IC_WDCVAR_H_
|
|
|
|
|
2004-05-26 00:42:40 +04:00
|
|
|
#include <sys/callout.h>
|
|
|
|
|
2006-09-07 16:46:47 +04:00
|
|
|
#include <dev/ata/ataconf.h>
|
2004-05-26 00:42:40 +04:00
|
|
|
#include <dev/ic/wdcreg.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
|
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
|
|
|
|
2003-12-03 15:01:18 +03:00
|
|
|
#define WDC_NREG 8 /* number of command registers */
|
2004-05-26 00:42:40 +04:00
|
|
|
#define WDC_NSHADOWREG 2 /* number of command "shadow" registers */
|
2003-12-03 15:01:18 +03:00
|
|
|
|
2012-07-31 19:50:31 +04:00
|
|
|
#define WDC_MAXDRIVES 2 /* absolute max number of drives per channel */
|
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs {
|
1998-10-12 20:09:10 +04:00
|
|
|
/* 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;
|
2010-11-05 21:07:23 +03:00
|
|
|
bus_size_t cmd_ios;
|
2004-05-26 00:42:40 +04:00
|
|
|
bus_space_handle_t cmd_iohs[WDC_NREG+WDC_NSHADOWREG];
|
1998-10-12 20:09:10 +04:00
|
|
|
bus_space_tag_t ctl_iot;
|
|
|
|
bus_space_handle_t ctl_ioh;
|
2010-11-05 21:07:23 +03:00
|
|
|
bus_size_t ctl_ios;
|
2004-08-14 19:08:04 +04:00
|
|
|
|
|
|
|
/* data32{iot,ioh} are only used for 32-bit data xfers */
|
2004-08-11 21:49:27 +04:00
|
|
|
bus_space_tag_t data32iot;
|
|
|
|
bus_space_handle_t data32ioh;
|
2006-10-25 21:33:02 +04:00
|
|
|
|
|
|
|
/* SATA native registers */
|
|
|
|
bus_space_tag_t sata_iot;
|
|
|
|
bus_space_handle_t sata_baseioh;
|
|
|
|
bus_space_handle_t sata_control;
|
|
|
|
bus_space_handle_t sata_status;
|
|
|
|
bus_space_handle_t sata_error;
|
|
|
|
|
2003-10-08 14:58:12 +04:00
|
|
|
};
|
|
|
|
|
2004-01-03 22:31:09 +03:00
|
|
|
/*
|
|
|
|
* Per-controller data
|
|
|
|
*/
|
|
|
|
struct wdc_softc {
|
2004-08-20 10:39:37 +04:00
|
|
|
struct atac_softc sc_atac; /* generic ATA controller info */
|
2004-01-03 22:31:09 +03:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
struct wdc_regs *regs; /* register array (per-channel) */
|
|
|
|
|
2012-07-31 19:50:31 +04:00
|
|
|
int wdc_maxdrives; /* max number of drives per channel */
|
|
|
|
|
|
|
|
int cap; /* controller capabilities */
|
1998-10-12 20:09:10 +04:00
|
|
|
#define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
|
2004-08-11 21:49:27 +04:00
|
|
|
#define WDC_CAPABILITY_PREATA 0x0200 /* ctrl can be a pre-ata one */
|
2012-11-20 02:22:56 +04:00
|
|
|
#define WDC_CAPABILITY_WIDEREGS 0x0400 /* ctrl has wide (16bit) registers */
|
|
|
|
#define WDC_CAPABILITY_NO_AUXCTL 0x0800 /* ctrl has no aux control registers */
|
2003-12-30 20:18:11 +03:00
|
|
|
|
2006-09-30 19:56:17 +04:00
|
|
|
#if NATA_DMA || NATA_PIOBM
|
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;
|
2004-01-01 23:18:33 +03:00
|
|
|
int (*dma_init)(void *, int, int, void *, size_t, int);
|
|
|
|
void (*dma_start)(void *, int, int);
|
|
|
|
int (*dma_finish)(void *, int, int, int);
|
2006-09-07 16:46:47 +04:00
|
|
|
#if NATA_PIOBM
|
|
|
|
void (*piobm_start)(void *, int, int, int, int, int);
|
|
|
|
void (*piobm_done)(void *, int, int);
|
|
|
|
#endif
|
2000-04-01 18:32:22 +04:00
|
|
|
/* flags passed to dma_init */
|
2006-09-07 16:46:47 +04:00
|
|
|
#define WDC_DMA_READ 0x01
|
|
|
|
#define WDC_DMA_IRQW 0x02
|
|
|
|
#define WDC_DMA_LBA48 0x04
|
|
|
|
#define WDC_DMA_PIOBM_ATA 0x08
|
|
|
|
#define WDC_DMA_PIOBM_ATAPI 0x10
|
|
|
|
#if NATA_PIOBM
|
|
|
|
/* flags passed to piobm_start */
|
|
|
|
#define WDC_PIOBM_XFER_IRQ 0x01
|
|
|
|
#endif
|
2004-01-01 23:18:33 +03:00
|
|
|
|
2004-08-03 02:20:54 +04:00
|
|
|
/* values passed to dma_finish */
|
|
|
|
#define WDC_DMAEND_END 0 /* check for proper end of a DMA xfer */
|
|
|
|
#define WDC_DMAEND_ABRT 1 /* abort a DMA xfer, verbose */
|
|
|
|
#define WDC_DMAEND_ABRT_QUIET 2 /* abort a DMA xfer, quiet */
|
|
|
|
|
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 */
|
2006-09-30 19:56:17 +04:00
|
|
|
#endif /* NATA_DMA || NATA_PIOBM */
|
1998-04-07 23:51:57 +04:00
|
|
|
|
2004-08-13 07:12:59 +04:00
|
|
|
/* Optional callback to select drive. */
|
2004-08-14 19:08:04 +04:00
|
|
|
void (*select)(struct ata_channel *,int);
|
2002-01-08 01:11:17 +03:00
|
|
|
|
2004-08-13 07:12:59 +04:00
|
|
|
/* Optional callback to ack IRQ. */
|
2004-08-14 19:08:04 +04:00
|
|
|
void (*irqack)(struct ata_channel *);
|
2004-08-11 22:41:46 +04:00
|
|
|
|
2005-08-07 02:07:24 +04:00
|
|
|
/* Optional callback to perform a bus reset */
|
|
|
|
void (*reset)(struct ata_channel *, int);
|
|
|
|
|
2004-08-11 22:41:46 +04:00
|
|
|
/* overridden if the backend has a different data transfer method */
|
2004-08-14 19:08:04 +04:00
|
|
|
void (*datain_pio)(struct ata_channel *, int, void *, size_t);
|
|
|
|
void (*dataout_pio)(struct ata_channel *, int, void *, size_t);
|
1998-01-15 02:41:59 +03:00
|
|
|
};
|
|
|
|
|
2004-08-20 03:25:35 +04:00
|
|
|
/* Given an ata_channel, get the wdc_softc. */
|
2004-08-20 10:39:37 +04:00
|
|
|
#define CHAN_TO_WDC(chp) ((struct wdc_softc *)(chp)->ch_atac)
|
2004-08-20 03:25:35 +04:00
|
|
|
|
|
|
|
/* Given an ata_channel, get the wdc_regs. */
|
|
|
|
#define CHAN_TO_WDC_REGS(chp) (&CHAN_TO_WDC(chp)->regs[(chp)->ch_channel])
|
|
|
|
|
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
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdc_allocate_regs(struct wdc_softc *);
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
void wdc_init_shadow_regs(struct wdc_regs *);
|
2004-05-26 00:42:40 +04:00
|
|
|
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
int wdcprobe(struct wdc_regs *);
|
2019-09-14 20:11:39 +03:00
|
|
|
int wdcprobe_with_reset(struct wdc_regs *,
|
|
|
|
void (*)(struct ata_channel *, int));
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdcattach(struct ata_channel *);
|
2008-01-10 10:44:07 +03:00
|
|
|
int wdcdetach(device_t, int);
|
|
|
|
void wdc_childdetached(device_t, device_t);
|
2004-01-01 23:18:33 +03:00
|
|
|
int wdcintr(void *);
|
|
|
|
|
2006-10-25 21:33:02 +04:00
|
|
|
void wdc_sataprobe(struct ata_channel *);
|
|
|
|
void wdc_drvprobe(struct ata_channel *);
|
|
|
|
|
2004-01-01 23:18:33 +03:00
|
|
|
void wdcrestart(void*);
|
|
|
|
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
int wdcwait(struct ata_channel *, int, int, int, int, int *);
|
2003-10-08 14:58:12 +04:00
|
|
|
#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 */
|
2004-01-01 23:18:33 +03:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdcbit_bucket(struct ata_channel *, int);
|
2004-08-11 21:49:27 +04:00
|
|
|
|
2004-08-14 19:08:04 +04:00
|
|
|
int wdc_dmawait(struct ata_channel *, struct ata_xfer *, int);
|
|
|
|
void wdccommand(struct ata_channel *, u_int8_t, u_int8_t, u_int16_t,
|
2004-01-01 23:18:33 +03:00
|
|
|
u_int8_t, u_int8_t, u_int8_t, u_int8_t);
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdccommandext(struct ata_channel *, u_int8_t, u_int8_t, u_int64_t,
|
2013-02-04 00:13:27 +04:00
|
|
|
u_int16_t, u_int16_t, u_int8_t);
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdccommandshort(struct ata_channel *, int, int);
|
2004-01-01 23:18:33 +03:00
|
|
|
void wdctimeout(void *arg);
|
2012-07-31 19:50:31 +04:00
|
|
|
void wdc_reset_drive(struct ata_drive_datas *, int, uint32_t *);
|
2004-08-14 19:08:04 +04:00
|
|
|
void wdc_reset_channel(struct ata_channel *, int);
|
2005-08-07 02:07:24 +04:00
|
|
|
void wdc_do_reset(struct ata_channel *, int);
|
2004-01-01 23:18:33 +03:00
|
|
|
|
2020-04-13 13:49:34 +03:00
|
|
|
void wdc_exec_command(struct ata_drive_datas *, struct ata_xfer *);
|
1998-01-15 02:41:59 +03:00
|
|
|
|
2005-02-27 03:26:58 +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.
|
2005-02-27 03:26:58 +03:00
|
|
|
*/
|
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch
ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.
Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).
Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.
Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).
Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.
Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
2017-10-07 19:05:31 +03:00
|
|
|
#define wdc_wait_for_drq(chp, timeout, flags, tfd) \
|
|
|
|
wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags), (tfd))
|
|
|
|
#define wdc_wait_for_unbusy(chp, timeout, flags, tfd) \
|
|
|
|
wdcwait((chp), 0, 0, (timeout), (flags), (tfd))
|
|
|
|
#define wdc_wait_for_ready(chp, timeout, flags, tfd) \
|
|
|
|
wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags), (tfd))
|
2004-01-01 23:18:33 +03:00
|
|
|
|
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
|
|
|
|
2004-01-01 23:18:33 +03:00
|
|
|
void wdc_atapibus_attach(struct atabus_softc *);
|
2003-12-30 19:28:37 +03:00
|
|
|
|
2004-01-01 23:18:33 +03:00
|
|
|
#endif /* _DEV_IC_WDCVAR_H_ */
|