wdcvar.h revision 1.53 1 1.53 thorpej /* $NetBSD: wdcvar.h,v 1.53 2004/01/03 19:31:09 thorpej Exp $ */
2 1.1 cgd
3 1.3 mycroft /*-
4 1.37 mycroft * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
5 1.3 mycroft * All rights reserved.
6 1.1 cgd *
7 1.3 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.3 mycroft * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.6 bouyer * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.6 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.6 bouyer * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.3 mycroft * This product includes software developed by the NetBSD
21 1.3 mycroft * Foundation, Inc. and its contributors.
22 1.3 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 mycroft * contributors may be used to endorse or promote products derived
24 1.3 mycroft * from this software without specific prior written permission.
25 1.1 cgd *
26 1.3 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.50 thorpej #ifndef _DEV_IC_WDCVAR_H_
40 1.50 thorpej #define _DEV_IC_WDCVAR_H_
41 1.50 thorpej
42 1.29 bouyer /* XXX For scsipi_adapter and scsipi_channel. */
43 1.8 thorpej #include <dev/scsipi/scsipi_all.h>
44 1.24 bouyer #include <dev/scsipi/atapiconf.h>
45 1.8 thorpej
46 1.22 thorpej #include <sys/callout.h>
47 1.22 thorpej
48 1.6 bouyer #define WAITTIME (10 * hz) /* time to wait for a completion */
49 1.6 bouyer /* this is a lot for hard drives, but not for cdroms */
50 1.5 mark
51 1.45 bouyer #define WDC_NREG 8 /* number of command registers */
52 1.6 bouyer
53 1.53 thorpej /*
54 1.53 thorpej * Per-channel data
55 1.53 thorpej */
56 1.53 thorpej struct wdc_channel {
57 1.53 thorpej struct callout ch_callout; /* callout handle */
58 1.53 thorpej int channel; /* location */
59 1.53 thorpej struct wdc_softc *wdc; /* controller's softc */
60 1.53 thorpej
61 1.6 bouyer /* Our registers */
62 1.6 bouyer bus_space_tag_t cmd_iot;
63 1.44 fvdl bus_space_handle_t cmd_baseioh;
64 1.44 fvdl bus_space_handle_t cmd_iohs[WDC_NREG];
65 1.6 bouyer bus_space_tag_t ctl_iot;
66 1.6 bouyer bus_space_handle_t ctl_ioh;
67 1.53 thorpej
68 1.44 fvdl /* data32{iot,ioh} are only used for 32 bit data xfers */
69 1.6 bouyer bus_space_tag_t data32iot;
70 1.6 bouyer bus_space_handle_t data32ioh;
71 1.53 thorpej
72 1.6 bouyer /* Our state */
73 1.6 bouyer int ch_flags;
74 1.6 bouyer #define WDCF_ACTIVE 0x01 /* channel is active */
75 1.41 bouyer #define WDCF_SHUTDOWN 0x02 /* channel is shutting down */
76 1.6 bouyer #define WDCF_IRQ_WAIT 0x10 /* controller is waiting for irq */
77 1.24 bouyer #define WDCF_DMA_WAIT 0x20 /* controller is waiting for DMA */
78 1.37 mycroft #define WDCF_DISABLED 0x80 /* channel is disabled */
79 1.41 bouyer #define WDCF_TH_RUN 0x100 /* the kenrel thread is working */
80 1.41 bouyer #define WDCF_TH_RESET 0x200 /* someone ask the thread to reset */
81 1.53 thorpej u_int8_t ch_status; /* copy of status register */
82 1.53 thorpej u_int8_t ch_error; /* copy of error register */
83 1.53 thorpej
84 1.53 thorpej /* per-drive info */
85 1.6 bouyer struct ata_drive_datas ch_drive[2];
86 1.6 bouyer
87 1.41 bouyer struct device *atabus; /* self */
88 1.53 thorpej
89 1.53 thorpej /* ATAPI children */
90 1.53 thorpej struct device *atapibus;
91 1.29 bouyer struct scsipi_channel ch_atapi_channel;
92 1.19 enami
93 1.53 thorpej /* ATA children */
94 1.53 thorpej struct device *ata_drives[2];
95 1.35 thorpej
96 1.6 bouyer /*
97 1.53 thorpej * Channel queues. May be the same for all channels, if hw
98 1.53 thorpej * channels are not independent.
99 1.6 bouyer */
100 1.49 thorpej struct ata_queue *ch_queue;
101 1.48 thorpej
102 1.53 thorpej /* The channel kernel thread */
103 1.41 bouyer struct proc *thread;
104 1.41 bouyer };
105 1.41 bouyer
106 1.53 thorpej /*
107 1.53 thorpej * Per-controller data
108 1.53 thorpej */
109 1.53 thorpej struct wdc_softc {
110 1.53 thorpej struct device sc_dev; /* generic device info */
111 1.53 thorpej
112 1.53 thorpej int cap; /* controller capabilities */
113 1.6 bouyer #define WDC_CAPABILITY_DATA16 0x0001 /* can do 16-bit data access */
114 1.6 bouyer #define WDC_CAPABILITY_DATA32 0x0002 /* can do 32-bit data access */
115 1.6 bouyer #define WDC_CAPABILITY_MODE 0x0004 /* controller knows its PIO/DMA modes */
116 1.6 bouyer #define WDC_CAPABILITY_DMA 0x0008 /* DMA */
117 1.6 bouyer #define WDC_CAPABILITY_UDMA 0x0010 /* Ultra-DMA/33 */
118 1.6 bouyer #define WDC_CAPABILITY_HWLOCK 0x0020 /* Needs to lock HW */
119 1.6 bouyer #define WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
120 1.6 bouyer #define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
121 1.6 bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
122 1.53 thorpej #define WDC_CAPABILITY_PREATA 0x0200 /* ctrl can be a pre-ata one */
123 1.53 thorpej #define WDC_CAPABILITY_IRQACK 0x0400 /* callback to ack interrupt */
124 1.30 bjh21 #define WDC_CAPABILITY_NOIRQ 0x1000 /* Controller never interrupts */
125 1.33 dbj #define WDC_CAPABILITY_SELECT 0x2000 /* Controller selects target */
126 1.35 thorpej #define WDC_CAPABILITY_RAID 0x4000 /* Controller "supports" RAID */
127 1.53 thorpej u_int8_t PIO_cap; /* highest PIO mode supported */
128 1.53 thorpej u_int8_t DMA_cap; /* highest DMA mode supported */
129 1.53 thorpej u_int8_t UDMA_cap; /* highest UDMA mode supported */
130 1.53 thorpej int nchannels; /* # channels on this controller */
131 1.53 thorpej struct wdc_channel **channels; /* channel-specific data (array) */
132 1.8 thorpej
133 1.8 thorpej /*
134 1.8 thorpej * The reference count here is used for both IDE and ATAPI devices.
135 1.8 thorpej */
136 1.24 bouyer struct atapi_adapter sc_atapi_adapter;
137 1.1 cgd
138 1.48 thorpej /* Function used to probe for drives. */
139 1.52 thorpej void (*drv_probe)(struct wdc_channel *);
140 1.48 thorpej
141 1.1 cgd /* if WDC_CAPABILITY_DMA set in 'cap' */
142 1.6 bouyer void *dma_arg;
143 1.50 thorpej int (*dma_init)(void *, int, int, void *, size_t, int);
144 1.50 thorpej void (*dma_start)(void *, int, int);
145 1.50 thorpej int (*dma_finish)(void *, int, int, int);
146 1.24 bouyer /* flags passed to dma_init */
147 1.36 nakayama #define WDC_DMA_READ 0x01
148 1.36 nakayama #define WDC_DMA_IRQW 0x02
149 1.36 nakayama #define WDC_DMA_LBA48 0x04
150 1.50 thorpej
151 1.24 bouyer int dma_status; /* status returned from dma_finish() */
152 1.24 bouyer #define WDC_DMAST_NOIRQ 0x01 /* missing IRQ */
153 1.24 bouyer #define WDC_DMAST_ERR 0x02 /* DMA error */
154 1.24 bouyer #define WDC_DMAST_UNDER 0x04 /* DMA underrun */
155 1.2 leo
156 1.2 leo /* if WDC_CAPABILITY_HWLOCK set in 'cap' */
157 1.50 thorpej int (*claim_hw)(void *, int);
158 1.50 thorpej void (*free_hw)(void *);
159 1.14 bouyer
160 1.14 bouyer /* if WDC_CAPABILITY_MODE set in 'cap' */
161 1.52 thorpej void (*set_modes)(struct wdc_channel *);
162 1.33 dbj
163 1.33 dbj /* if WDC_CAPABILITY_SELECT set in 'cap' */
164 1.52 thorpej void (*select)(struct wdc_channel *,int);
165 1.25 bouyer
166 1.25 bouyer /* if WDC_CAPABILITY_IRQACK set in 'cap' */
167 1.52 thorpej void (*irqack)(struct wdc_channel *);
168 1.1 cgd };
169 1.1 cgd
170 1.6 bouyer /*
171 1.6 bouyer * Public functions which can be called by ATA or ATAPI specific parts,
172 1.6 bouyer * or bus-specific backends.
173 1.6 bouyer */
174 1.1 cgd
175 1.52 thorpej int wdcprobe(struct wdc_channel *);
176 1.52 thorpej void wdcattach(struct wdc_channel *);
177 1.50 thorpej int wdcdetach(struct device *, int);
178 1.50 thorpej int wdcactivate(struct device *, enum devact);
179 1.50 thorpej int wdcintr(void *);
180 1.52 thorpej void wdc_exec_xfer(struct wdc_channel *, struct ata_xfer *);
181 1.50 thorpej
182 1.50 thorpej struct ata_xfer *wdc_get_xfer(int); /* int = WDC_NOSLEEP/CANSLEEP */
183 1.6 bouyer #define WDC_CANSLEEP 0x00
184 1.6 bouyer #define WDC_NOSLEEP 0x01
185 1.50 thorpej
186 1.52 thorpej void wdc_free_xfer (struct wdc_channel *, struct ata_xfer *);
187 1.52 thorpej void wdcstart(struct wdc_channel *);
188 1.50 thorpej void wdcrestart(void*);
189 1.50 thorpej
190 1.52 thorpej int wdcreset(struct wdc_channel *, int);
191 1.41 bouyer #define RESET_POLL 1
192 1.41 bouyer #define RESET_SLEEP 0 /* wdcreset will use tsleep() */
193 1.50 thorpej
194 1.52 thorpej int wdcwait(struct wdc_channel *, int, int, int, int);
195 1.41 bouyer #define WDCWAIT_OK 0 /* we have what we asked */
196 1.41 bouyer #define WDCWAIT_TOUT -1 /* timed out */
197 1.41 bouyer #define WDCWAIT_THR 1 /* return, the kernel thread has been awakened */
198 1.50 thorpej
199 1.52 thorpej int wdc_dmawait(struct wdc_channel *, struct ata_xfer *, int);
200 1.52 thorpej void wdcbit_bucket( struct wdc_channel *, int);
201 1.52 thorpej void wdccommand(struct wdc_channel *, u_int8_t, u_int8_t, u_int16_t,
202 1.50 thorpej u_int8_t, u_int8_t, u_int8_t, u_int8_t);
203 1.52 thorpej void wdccommandext(struct wdc_channel *, u_int8_t, u_int8_t, u_int64_t,
204 1.50 thorpej u_int16_t);
205 1.52 thorpej void wdccommandshort(struct wdc_channel *, int, int);
206 1.50 thorpej void wdctimeout(void *arg);
207 1.50 thorpej void wdc_reset_channel(struct ata_drive_datas *, int);
208 1.50 thorpej
209 1.50 thorpej int wdc_exec_command(struct ata_drive_datas *, struct wdc_command*);
210 1.32 bouyer #define WDC_COMPLETE 0x01
211 1.32 bouyer #define WDC_QUEUED 0x02
212 1.32 bouyer #define WDC_TRY_AGAIN 0x03
213 1.9 thorpej
214 1.52 thorpej int wdc_addref(struct wdc_channel *);
215 1.52 thorpej void wdc_delref(struct wdc_channel *);
216 1.52 thorpej void wdc_kill_pending(struct wdc_channel *);
217 1.26 wrstuden
218 1.52 thorpej void wdc_print_modes (struct wdc_channel *);
219 1.50 thorpej void wdc_probe_caps(struct ata_drive_datas*);
220 1.6 bouyer
221 1.6 bouyer /*
222 1.6 bouyer * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
223 1.6 bouyer * command is aborted.
224 1.6 bouyer */
225 1.51 thorpej #define wdc_wait_for_drq(chp, timeout, flags) \
226 1.41 bouyer wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
227 1.51 thorpej #define wdc_wait_for_unbusy(chp, timeout, flags) \
228 1.41 bouyer wdcwait((chp), 0, 0, (timeout), (flags))
229 1.51 thorpej #define wdc_wait_for_ready(chp, timeout, flags) \
230 1.41 bouyer wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
231 1.50 thorpej
232 1.6 bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
233 1.6 bouyer #define WDC_RESET_WAIT 31000
234 1.1 cgd
235 1.50 thorpej void wdc_atapibus_attach(struct atabus_softc *);
236 1.47 thorpej
237 1.47 thorpej /* XXX */
238 1.47 thorpej struct atabus_softc;
239 1.47 thorpej void atabusconfig(struct atabus_softc *);
240 1.50 thorpej
241 1.50 thorpej #endif /* _DEV_IC_WDCVAR_H_ */
242