wdcvar.h revision 1.7 1 /* $NetBSD: wdcvar.h,v 1.7 1998/11/17 14:14:52 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #define WAITTIME (10 * hz) /* time to wait for a completion */
40 /* this is a lot for hard drives, but not for cdroms */
41
42 struct channel_queue { /* per channel queue (may be shared) */
43 TAILQ_HEAD(xferhead, wdc_xfer) sc_xfer;
44 };
45
46 struct channel_softc { /* Per channel data */
47 /* Our location */
48 int channel;
49 /* Our controller's softc */
50 struct wdc_softc *wdc;
51 /* Our registers */
52 bus_space_tag_t cmd_iot;
53 bus_space_handle_t cmd_ioh;
54 bus_space_tag_t ctl_iot;
55 bus_space_handle_t ctl_ioh;
56 /* data32{iot,ioh} are only used for 32 bit xfers */
57 bus_space_tag_t data32iot;
58 bus_space_handle_t data32ioh;
59 /* Our state */
60 int ch_flags;
61 #define WDCF_ACTIVE 0x01 /* channel is active */
62 #define WDCF_IRQ_WAIT 0x10 /* controller is waiting for irq */
63 u_int8_t ch_status; /* copy of status register */
64 u_int8_t ch_error; /* copy of error register */
65 /* per-drive infos */
66 struct ata_drive_datas ch_drive[2];
67
68 /*
69 * channel queues. May be the same for all channels, if hw channels
70 * are not independants
71 */
72 struct channel_queue *ch_queue;
73 };
74
75 struct wdc_softc { /* Per controller state */
76 struct device sc_dev;
77 /* mandatory fields */
78 int cap;
79 /* Capabilities supported by the controller */
80 #define WDC_CAPABILITY_DATA16 0x0001 /* can do 16-bit data access */
81 #define WDC_CAPABILITY_DATA32 0x0002 /* can do 32-bit data access */
82 #define WDC_CAPABILITY_MODE 0x0004 /* controller knows its PIO/DMA modes */
83 #define WDC_CAPABILITY_DMA 0x0008 /* DMA */
84 #define WDC_CAPABILITY_UDMA 0x0010 /* Ultra-DMA/33 */
85 #define WDC_CAPABILITY_HWLOCK 0x0020 /* Needs to lock HW */
86 #define WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
87 #define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
88 #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
89 u_int8_t pio_mode; /* highest PIO mode supported */
90 u_int8_t dma_mode; /* highest DMA mode supported */
91 int nchannels; /* Number of channels on this controller */
92 struct channel_softc *channels; /* channels-specific datas (array) */
93
94 /* if WDC_CAPABILITY_DMA set in 'cap' */
95 void *dma_arg;
96 int (*dma_init) __P((void *, int, int, void *, size_t,
97 int));
98 void (*dma_start) __P((void *, int, int, int));
99 int (*dma_finish) __P((void *, int, int, int));
100 /* flags passed to DMA functions */
101 #define WDC_DMA_READ 0x01
102 #define WDC_DMA_POLL 0x02
103
104 /* if WDC_CAPABILITY_HWLOCK set in 'cap' */
105 int (*claim_hw) __P((void *, int));
106 void (*free_hw) __P((void *));
107 };
108
109 /*
110 * Description of a command to be handled by a controller.
111 * These commands are queued in a list.
112 */
113 struct wdc_xfer {
114 volatile u_int c_flags;
115 #define C_INUSE 0x0001 /* xfer struct is in use */
116 #define C_ATAPI 0x0002 /* xfer is ATAPI request */
117 #define C_TIMEOU 0x0004 /* xfer processing timed out */
118 #define C_NEEDDONE 0x0010 /* need to call upper-level done */
119 #define C_POLL 0x0020 /* cmd is polled */
120 #define C_DMA 0x0040 /* cmd uses DMA */
121 #define C_SENSE 0x0080 /* cmd is a internal command */
122
123 /* Information about our location */
124 u_int8_t drive;
125 u_int8_t channel;
126
127 /* Information about the current transfer */
128 void *cmd; /* wdc, ata or scsipi command structure */
129 void *databuf;
130 int c_bcount; /* byte count left */
131 int c_skip; /* bytes already transferred */
132 TAILQ_ENTRY(wdc_xfer) c_xferchain;
133 LIST_ENTRY(wdc_xfer) free_list;
134 void (*c_start) __P((struct channel_softc *, struct wdc_xfer *));
135 int (*c_intr) __P((struct channel_softc *, struct wdc_xfer *));
136 };
137
138 /*
139 * Public functions which can be called by ATA or ATAPI specific parts,
140 * or bus-specific backends.
141 */
142
143 int wdcprobe __P((struct channel_softc *));
144 void wdcattach __P((struct channel_softc *));
145 int wdcintr __P((void *));
146 void wdc_exec_xfer __P((struct channel_softc *, struct wdc_xfer *));
147 struct wdc_xfer *wdc_get_xfer __P((int)); /* int = WDC_NOSLEEP/CANSLEEP */
148 #define WDC_CANSLEEP 0x00
149 #define WDC_NOSLEEP 0x01
150 void wdc_free_xfer __P((struct channel_softc *, struct wdc_xfer *));
151 void wdcstart __P((struct wdc_softc *, int));
152 void wdcrestart __P((void*));
153 int wdcreset __P((struct channel_softc *, int));
154 #define VERBOSE 1
155 #define SILENT 0 /* wdcreset will not print errors */
156 int wdcwait __P((struct channel_softc *, int, int, int));
157 void wdcbit_bucket __P(( struct channel_softc *, int));
158 void wdccommand __P((struct channel_softc *, u_int8_t, u_int8_t, u_int16_t,
159 u_int8_t, u_int8_t, u_int8_t, u_int8_t));
160 void wdccommandshort __P((struct channel_softc *, int, int));
161 void wdctimeout __P((void *arg));
162
163 /*
164 * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
165 * command is aborted.
166 */
167 #define wait_for_drq(chp, timeout) wdcwait((chp), \
168 WDCS_DRDY | WDCS_DSC | WDCS_DRQ, \
169 WDCS_DRDY | WDCS_DSC | WDCS_DRQ, (timeout))
170 #define wait_for_unbusy(chp, timeout) wdcwait((chp), 0, 0, (timeout))
171 #define wait_for_ready(chp, timeout) wdcwait((chp), WDCS_DRDY | WDCS_DSC, \
172 WDCS_DRDY | WDCS_DSC, (timeout))
173 /* ATA/ATAPI specs says a device can take 31s to reset */
174 #define WDC_RESET_WAIT 31000
175
176 void wdc_atapibus_attach __P((struct channel_softc *));
177 int atapi_print __P((void *, const char *));
178