wdcvar.h revision 1.11 1 1.11 bouyer /* $NetBSD: wdcvar.h,v 1.11 1998/12/02 15:53:35 bouyer Exp $ */
2 1.1 cgd
3 1.3 mycroft /*-
4 1.3 mycroft * Copyright (c) 1998 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.8 thorpej /* XXX for scsipi_adapter */
40 1.8 thorpej #include <dev/scsipi/scsipi_all.h>
41 1.8 thorpej #include <dev/scsipi/scsipiconf.h>
42 1.8 thorpej
43 1.6 bouyer #define WAITTIME (10 * hz) /* time to wait for a completion */
44 1.6 bouyer /* this is a lot for hard drives, but not for cdroms */
45 1.5 mark
46 1.6 bouyer struct channel_queue { /* per channel queue (may be shared) */
47 1.6 bouyer TAILQ_HEAD(xferhead, wdc_xfer) sc_xfer;
48 1.6 bouyer };
49 1.6 bouyer
50 1.6 bouyer struct channel_softc { /* Per channel data */
51 1.6 bouyer /* Our location */
52 1.6 bouyer int channel;
53 1.6 bouyer /* Our controller's softc */
54 1.6 bouyer struct wdc_softc *wdc;
55 1.6 bouyer /* Our registers */
56 1.6 bouyer bus_space_tag_t cmd_iot;
57 1.6 bouyer bus_space_handle_t cmd_ioh;
58 1.6 bouyer bus_space_tag_t ctl_iot;
59 1.6 bouyer bus_space_handle_t ctl_ioh;
60 1.5 mark /* data32{iot,ioh} are only used for 32 bit xfers */
61 1.6 bouyer bus_space_tag_t data32iot;
62 1.6 bouyer bus_space_handle_t data32ioh;
63 1.6 bouyer /* Our state */
64 1.6 bouyer int ch_flags;
65 1.6 bouyer #define WDCF_ACTIVE 0x01 /* channel is active */
66 1.6 bouyer #define WDCF_IRQ_WAIT 0x10 /* controller is waiting for irq */
67 1.6 bouyer u_int8_t ch_status; /* copy of status register */
68 1.6 bouyer u_int8_t ch_error; /* copy of error register */
69 1.6 bouyer /* per-drive infos */
70 1.6 bouyer struct ata_drive_datas ch_drive[2];
71 1.6 bouyer
72 1.6 bouyer /*
73 1.6 bouyer * channel queues. May be the same for all channels, if hw channels
74 1.6 bouyer * are not independants
75 1.6 bouyer */
76 1.6 bouyer struct channel_queue *ch_queue;
77 1.6 bouyer };
78 1.6 bouyer
79 1.6 bouyer struct wdc_softc { /* Per controller state */
80 1.6 bouyer struct device sc_dev;
81 1.6 bouyer /* mandatory fields */
82 1.6 bouyer int cap;
83 1.6 bouyer /* Capabilities supported by the controller */
84 1.6 bouyer #define WDC_CAPABILITY_DATA16 0x0001 /* can do 16-bit data access */
85 1.6 bouyer #define WDC_CAPABILITY_DATA32 0x0002 /* can do 32-bit data access */
86 1.6 bouyer #define WDC_CAPABILITY_MODE 0x0004 /* controller knows its PIO/DMA modes */
87 1.6 bouyer #define WDC_CAPABILITY_DMA 0x0008 /* DMA */
88 1.6 bouyer #define WDC_CAPABILITY_UDMA 0x0010 /* Ultra-DMA/33 */
89 1.6 bouyer #define WDC_CAPABILITY_HWLOCK 0x0020 /* Needs to lock HW */
90 1.6 bouyer #define WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
91 1.6 bouyer #define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
92 1.6 bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
93 1.6 bouyer u_int8_t pio_mode; /* highest PIO mode supported */
94 1.6 bouyer u_int8_t dma_mode; /* highest DMA mode supported */
95 1.6 bouyer int nchannels; /* Number of channels on this controller */
96 1.10 drochner struct channel_softc **channels; /* channels-specific datas (array) */
97 1.8 thorpej
98 1.8 thorpej /*
99 1.8 thorpej * The reference count here is used for both IDE and ATAPI devices.
100 1.8 thorpej */
101 1.8 thorpej struct scsipi_adapter sc_atapi_adapter;
102 1.1 cgd
103 1.1 cgd /* if WDC_CAPABILITY_DMA set in 'cap' */
104 1.6 bouyer void *dma_arg;
105 1.6 bouyer int (*dma_init) __P((void *, int, int, void *, size_t,
106 1.6 bouyer int));
107 1.6 bouyer void (*dma_start) __P((void *, int, int, int));
108 1.6 bouyer int (*dma_finish) __P((void *, int, int, int));
109 1.6 bouyer /* flags passed to DMA functions */
110 1.6 bouyer #define WDC_DMA_READ 0x01
111 1.6 bouyer #define WDC_DMA_POLL 0x02
112 1.2 leo
113 1.2 leo /* if WDC_CAPABILITY_HWLOCK set in 'cap' */
114 1.6 bouyer int (*claim_hw) __P((void *, int));
115 1.6 bouyer void (*free_hw) __P((void *));
116 1.1 cgd };
117 1.1 cgd
118 1.6 bouyer /*
119 1.6 bouyer * Description of a command to be handled by a controller.
120 1.6 bouyer * These commands are queued in a list.
121 1.6 bouyer */
122 1.6 bouyer struct wdc_xfer {
123 1.6 bouyer volatile u_int c_flags;
124 1.6 bouyer #define C_INUSE 0x0001 /* xfer struct is in use */
125 1.6 bouyer #define C_ATAPI 0x0002 /* xfer is ATAPI request */
126 1.6 bouyer #define C_TIMEOU 0x0004 /* xfer processing timed out */
127 1.6 bouyer #define C_NEEDDONE 0x0010 /* need to call upper-level done */
128 1.6 bouyer #define C_POLL 0x0020 /* cmd is polled */
129 1.6 bouyer #define C_DMA 0x0040 /* cmd uses DMA */
130 1.7 bouyer #define C_SENSE 0x0080 /* cmd is a internal command */
131 1.6 bouyer
132 1.11 bouyer /* Informations about our location */
133 1.11 bouyer struct channel_softc *chp;
134 1.6 bouyer u_int8_t drive;
135 1.6 bouyer
136 1.6 bouyer /* Information about the current transfer */
137 1.6 bouyer void *cmd; /* wdc, ata or scsipi command structure */
138 1.6 bouyer void *databuf;
139 1.6 bouyer int c_bcount; /* byte count left */
140 1.6 bouyer int c_skip; /* bytes already transferred */
141 1.6 bouyer TAILQ_ENTRY(wdc_xfer) c_xferchain;
142 1.6 bouyer LIST_ENTRY(wdc_xfer) free_list;
143 1.6 bouyer void (*c_start) __P((struct channel_softc *, struct wdc_xfer *));
144 1.6 bouyer int (*c_intr) __P((struct channel_softc *, struct wdc_xfer *));
145 1.6 bouyer };
146 1.4 kenh
147 1.6 bouyer /*
148 1.6 bouyer * Public functions which can be called by ATA or ATAPI specific parts,
149 1.6 bouyer * or bus-specific backends.
150 1.6 bouyer */
151 1.1 cgd
152 1.6 bouyer int wdcprobe __P((struct channel_softc *));
153 1.6 bouyer void wdcattach __P((struct channel_softc *));
154 1.6 bouyer int wdcintr __P((void *));
155 1.6 bouyer void wdc_exec_xfer __P((struct channel_softc *, struct wdc_xfer *));
156 1.6 bouyer struct wdc_xfer *wdc_get_xfer __P((int)); /* int = WDC_NOSLEEP/CANSLEEP */
157 1.6 bouyer #define WDC_CANSLEEP 0x00
158 1.6 bouyer #define WDC_NOSLEEP 0x01
159 1.6 bouyer void wdc_free_xfer __P((struct channel_softc *, struct wdc_xfer *));
160 1.10 drochner void wdcstart __P((struct channel_softc *));
161 1.6 bouyer void wdcrestart __P((void*));
162 1.6 bouyer int wdcreset __P((struct channel_softc *, int));
163 1.6 bouyer #define VERBOSE 1
164 1.6 bouyer #define SILENT 0 /* wdcreset will not print errors */
165 1.6 bouyer int wdcwait __P((struct channel_softc *, int, int, int));
166 1.6 bouyer void wdcbit_bucket __P(( struct channel_softc *, int));
167 1.6 bouyer void wdccommand __P((struct channel_softc *, u_int8_t, u_int8_t, u_int16_t,
168 1.6 bouyer u_int8_t, u_int8_t, u_int8_t, u_int8_t));
169 1.6 bouyer void wdccommandshort __P((struct channel_softc *, int, int));
170 1.6 bouyer void wdctimeout __P((void *arg));
171 1.9 thorpej
172 1.9 thorpej int wdc_addref __P((struct channel_softc *));
173 1.9 thorpej void wdc_delref __P((struct channel_softc *));
174 1.6 bouyer
175 1.6 bouyer /*
176 1.6 bouyer * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
177 1.6 bouyer * command is aborted.
178 1.6 bouyer */
179 1.6 bouyer #define wait_for_drq(chp, timeout) wdcwait((chp), \
180 1.6 bouyer WDCS_DRDY | WDCS_DSC | WDCS_DRQ, \
181 1.6 bouyer WDCS_DRDY | WDCS_DSC | WDCS_DRQ, (timeout))
182 1.6 bouyer #define wait_for_unbusy(chp, timeout) wdcwait((chp), 0, 0, (timeout))
183 1.6 bouyer #define wait_for_ready(chp, timeout) wdcwait((chp), WDCS_DRDY | WDCS_DSC, \
184 1.6 bouyer WDCS_DRDY | WDCS_DSC, (timeout))
185 1.6 bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
186 1.6 bouyer #define WDC_RESET_WAIT 31000
187 1.1 cgd
188 1.6 bouyer void wdc_atapibus_attach __P((struct channel_softc *));
189 1.6 bouyer int atapi_print __P((void *, const char *));
190