#ifndef _DEV_IC_WDCVAR_H_
#define _DEV_IC_WDCVAR_H_
#include <sys/timeout.h>
struct channel_queue {
TAILQ_HEAD(xferhead, wdc_xfer) sc_xfer;
};
struct channel_softc_vtbl;
#define WDC_OPTION_PROBE_VERBOSE 0x10000
struct channel_softc {
struct channel_softc_vtbl *_vtbl;
int channel;
struct wdc_softc *wdc;
bus_space_tag_t cmd_iot;
bus_space_handle_t cmd_ioh;
bus_size_t cmd_iosz;
bus_space_tag_t ctl_iot;
bus_space_handle_t ctl_ioh;
bus_size_t ctl_iosz;
bus_space_tag_t data32iot;
bus_space_handle_t data32ioh;
int ch_flags;
#define WDCF_ACTIVE 0x01
#define WDCF_ONESLAVE 0x02
#define WDCF_IRQ_WAIT 0x10
#define WDCF_DMA_WAIT 0x20
#define WDCF_VERBOSE_PROBE 0x40
#define WDCF_DMA_BEFORE_CMD 0x80
u_int8_t ch_status;
u_int8_t ch_prev_log_status;
u_int8_t ch_log_idx;
u_int8_t ch_error;
struct ata_drive_datas ch_drive[2];
struct channel_queue *ch_queue;
struct timeout ch_timo;
int dying;
};
#define _WDC_REGMASK 7
#define _WDC_AUX 8
#define _WDC_RDONLY 16
#define _WDC_WRONLY 32
enum wdc_regs {
wdr_error = _WDC_RDONLY | 1,
wdr_features = _WDC_WRONLY | 1,
wdr_seccnt = 2,
wdr_ireason = 2,
wdr_sector = 3,
wdr_lba_lo = 3,
wdr_cyl_lo = 4,
wdr_lba_mi = 4,
wdr_cyl_hi = 5,
wdr_lba_hi = 5,
wdr_sdh = 6,
wdr_status = _WDC_RDONLY | 7,
wdr_command = _WDC_WRONLY | 7,
wdr_altsts = _WDC_RDONLY | _WDC_AUX,
wdr_ctlr = _WDC_WRONLY | _WDC_AUX
};
#define WDC_NREG 8
#define WDC_NSHADOWREG 2
struct channel_softc_vtbl {
u_int8_t (*read_reg)(struct channel_softc *, enum wdc_regs reg);
void (*write_reg)(struct channel_softc *, enum wdc_regs reg,
u_int8_t var);
void (*lba48_write_reg)(struct channel_softc *, enum wdc_regs reg,
u_int16_t var);
void (*read_raw_multi_2)(struct channel_softc *,
void *data, unsigned int nbytes);
void (*write_raw_multi_2)(struct channel_softc *,
void *data, unsigned int nbytes);
void (*read_raw_multi_4)(struct channel_softc *,
void *data, unsigned int nbytes);
void (*write_raw_multi_4)(struct channel_softc *,
void *data, unsigned int nbytes);
};
#define CHP_READ_REG(chp, a) ((chp)->_vtbl->read_reg)(chp, a)
#define CHP_WRITE_REG(chp, a, b) ((chp)->_vtbl->write_reg)(chp, a, b)
#define CHP_LBA48_WRITE_REG(chp, a, b) \
((chp)->_vtbl->lba48_write_reg)(chp, a, b)
#define CHP_READ_RAW_MULTI_2(chp, a, b) \
((chp)->_vtbl->read_raw_multi_2)(chp, a, b)
#define CHP_WRITE_RAW_MULTI_2(chp, a, b) \
((chp)->_vtbl->write_raw_multi_2)(chp, a, b)
#define CHP_READ_RAW_MULTI_4(chp, a, b) \
((chp)->_vtbl->read_raw_multi_4)(chp, a, b)
#define CHP_WRITE_RAW_MULTI_4(chp, a, b) \
((chp)->_vtbl->write_raw_multi_4)(chp, a, b)
struct wdc_softc {
struct device sc_dev;
int cap;
#define WDC_CAPABILITY_DATA16 0x0001
#define WDC_CAPABILITY_DATA32 0x0002
#define WDC_CAPABILITY_MODE 0x0004
#define WDC_CAPABILITY_DMA 0x0008
#define WDC_CAPABILITY_UDMA 0x0010
#define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100
#define WDC_CAPABILITY_PREATA 0x0200
#define WDC_CAPABILITY_IRQACK 0x0400
#define WDC_CAPABILITY_SINGLE_DRIVE 0x800
#define WDC_CAPABILITY_NO_ATAPI_DMA 0x1000
#define WDC_CAPABILITY_SATA 0x2000
u_int8_t PIO_cap;
u_int8_t DMA_cap;
u_int8_t UDMA_cap;
int nchannels;
struct channel_softc **channels;
u_int16_t quirks;
#define WDC_QUIRK_NOSHORTDMA 0x0001
#define WDC_QUIRK_NOATA 0x0002
#define WDC_QUIRK_NOATAPI 0x0004
#if 0
struct scsipi_adapter sc_atapi_adapter;
#endif
void *dma_arg;
int (*dma_init)(void *, int, int, void *, size_t,
int);
void (*dma_start)(void *, int, int);
int (*dma_finish)(void *, int, int, int);
#define WDC_DMA_READ 0x01
#define WDC_DMA_IRQW 0x02
#define WDC_DMA_LBA48 0x04
int dma_status;
#define WDC_DMAST_NOIRQ 0x01
#define WDC_DMAST_ERR 0x02
#define WDC_DMAST_UNDER 0x04
void (*set_modes)(struct channel_softc *);
void (*irqack)(struct channel_softc *);
void (*reset)(struct channel_softc *);
void (*drv_probe)(struct channel_softc *);
};
struct atapi_return_args;
struct wdc_xfer {
volatile u_int c_flags;
#define C_ATAPI 0x0002
#define C_TIMEOU 0x0004
#define C_NEEDDONE 0x0010
#define C_POLL 0x0020
#define C_DMA 0x0040
#define C_SENSE 0x0080
#define C_MEDIA_ACCESS 0x0100
#define C_POLL_MACHINE 0x0200
#define C_PRIVATEXFER 0x0400
#define C_SCSIXFER 0x0800
struct channel_softc *chp;
u_int8_t drive;
void *cmd;
void *databuf;
int c_bcount;
int c_skip;
TAILQ_ENTRY(wdc_xfer) c_xferchain;
LIST_ENTRY(wdc_xfer) free_list;
void (*c_start)(struct channel_softc *, struct wdc_xfer *);
int (*c_intr)(struct channel_softc *, struct wdc_xfer *, int);
void (*c_kill_xfer)(struct channel_softc *, struct wdc_xfer *);
volatile int endticks;
struct timeout atapi_poll_to;
void (*next)(struct channel_softc *, struct wdc_xfer *, int,
struct atapi_return_args *);
void (*c_done)(struct channel_softc *, struct wdc_xfer *, int,
struct atapi_return_args *);
int transfer_len;
};
int wdcprobe(struct channel_softc *);
void wdcattach(struct channel_softc *);
int wdcdetach(struct channel_softc *, int);
int wdcintr(void *);
struct channel_queue *wdc_alloc_queue(void);
void wdc_free_queue(struct channel_queue *);
void wdc_exec_xfer(struct channel_softc *, struct wdc_xfer *);
struct wdc_xfer *wdc_get_xfer(int);
#define WDC_CANSLEEP 0x00
#define WDC_NOSLEEP 0x01
void wdc_scrub_xfer(struct wdc_xfer *);
void wdc_free_xfer(struct channel_softc *, struct wdc_xfer *);
void wdcstart(struct channel_softc *);
int wdcreset(struct channel_softc *, int);
#define NOWAIT 0x02
#define VERBOSE 0x01
#define SILENT 0x00
int wdc_wait_for_status(struct channel_softc *, int, int, int);
int wdc_dmawait(struct channel_softc *, struct wdc_xfer *, int);
void wdcbit_bucket(struct channel_softc *, int);
void wdccommand(struct channel_softc *, u_int8_t, u_int8_t, u_int16_t,
u_int8_t, u_int8_t, u_int8_t, u_int8_t);
void wdccommandext(struct channel_softc *, u_int8_t, u_int8_t, u_int64_t,
u_int16_t);
void wdccommandshort(struct channel_softc *, int, int);
void wdctimeout(void *arg);
void wdc_do_reset(struct channel_softc *);
#define wdcwait(chp, status, mask, timeout) ((wdc_wait_for_status((chp), (status), (mask), (timeout)) >= 0) ? 0 : -1)
#define wait_for_drq(chp, timeout) wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout))
#define wait_for_unbusy(chp, timeout) wdcwait((chp), 0, 0, (timeout))
#define wait_for_ready(chp, timeout) wdcwait((chp), WDCS_DRDY, \
WDCS_DRDY, (timeout))
#define WDC_RESET_WAIT 31000
void wdc_disable_intr(struct channel_softc *);
void wdc_enable_intr(struct channel_softc *);
void wdc_set_drive(struct channel_softc *, int drive);
void wdc_output_bytes(struct ata_drive_datas *drvp, void *, unsigned int);
void wdc_input_bytes(struct ata_drive_datas *drvp, void *, unsigned int);
void wdc_print_current_modes(struct channel_softc *);
int wdc_ioctl(struct ata_drive_datas *, u_long, caddr_t, int, struct proc *);
u_int8_t wdc_default_read_reg(struct channel_softc *,
enum wdc_regs);
void wdc_default_write_reg(struct channel_softc *,
enum wdc_regs, u_int8_t);
void wdc_default_lba48_write_reg(struct channel_softc *,
enum wdc_regs, u_int16_t);
void wdc_default_read_raw_multi_2(struct channel_softc *,
void *, unsigned int);
void wdc_default_write_raw_multi_2(struct channel_softc *,
void *, unsigned int);
void wdc_default_read_raw_multi_4(struct channel_softc *,
void *, unsigned int);
void wdc_default_write_raw_multi_4(struct channel_softc *,
void *, unsigned int);
#endif