ahc_cardbus.c revision 1.3.6.2 1 1.3.6.2 bouyer /* $NetBSD: ahc_cardbus.c,v 1.3.6.2 2000/11/20 11:39:52 bouyer Exp $ */
2 1.3.6.2 bouyer
3 1.3.6.2 bouyer /*-
4 1.3.6.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.3.6.2 bouyer * All rights reserved.
6 1.3.6.2 bouyer *
7 1.3.6.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.3.6.2 bouyer * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.3.6.2 bouyer * NASA Ames Research Center.
10 1.3.6.2 bouyer *
11 1.3.6.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.3.6.2 bouyer * modification, are permitted provided that the following conditions
13 1.3.6.2 bouyer * are met:
14 1.3.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.3.6.2 bouyer * notice, this list of conditions and the following disclaimer.
16 1.3.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
17 1.3.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
18 1.3.6.2 bouyer * documentation and/or other materials provided with the distribution.
19 1.3.6.2 bouyer * 3. All advertising materials mentioning features or use of this software
20 1.3.6.2 bouyer * must display the following acknowledgement:
21 1.3.6.2 bouyer * This product includes software developed by the NetBSD
22 1.3.6.2 bouyer * Foundation, Inc. and its contributors.
23 1.3.6.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.3.6.2 bouyer * contributors may be used to endorse or promote products derived
25 1.3.6.2 bouyer * from this software without specific prior written permission.
26 1.3.6.2 bouyer *
27 1.3.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.3.6.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.3.6.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.3.6.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.3.6.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.3.6.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.3.6.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.3.6.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.3.6.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.3.6.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.3.6.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
38 1.3.6.2 bouyer */
39 1.3.6.2 bouyer
40 1.3.6.2 bouyer /*
41 1.3.6.2 bouyer * CardBus front-end for the Adaptec AIC-7xxx family of SCSI controllers.
42 1.3.6.2 bouyer *
43 1.3.6.2 bouyer * TODO:
44 1.3.6.2 bouyer * - power management
45 1.3.6.2 bouyer */
46 1.3.6.2 bouyer
47 1.3.6.2 bouyer #include <sys/param.h>
48 1.3.6.2 bouyer #include <sys/systm.h>
49 1.3.6.2 bouyer #include <sys/malloc.h>
50 1.3.6.2 bouyer #include <sys/kernel.h>
51 1.3.6.2 bouyer #include <sys/queue.h>
52 1.3.6.2 bouyer #include <sys/device.h>
53 1.3.6.2 bouyer
54 1.3.6.2 bouyer #include <machine/bus.h>
55 1.3.6.2 bouyer #include <machine/intr.h>
56 1.3.6.2 bouyer
57 1.3.6.2 bouyer #include <dev/scsipi/scsi_all.h>
58 1.3.6.2 bouyer #include <dev/scsipi/scsipi_all.h>
59 1.3.6.2 bouyer #include <dev/scsipi/scsiconf.h>
60 1.3.6.2 bouyer
61 1.3.6.2 bouyer #include <dev/pci/pcireg.h>
62 1.3.6.2 bouyer
63 1.3.6.2 bouyer #include <dev/cardbus/cardbusvar.h>
64 1.3.6.2 bouyer #include <dev/cardbus/cardbusdevs.h>
65 1.3.6.2 bouyer
66 1.3.6.2 bouyer #include <dev/ic/aic7xxxvar.h>
67 1.3.6.2 bouyer
68 1.3.6.2 bouyer #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
69 1.3.6.2 bouyer
70 1.3.6.2 bouyer #define AHC_CARDBUS_IOBA 0x10
71 1.3.6.2 bouyer #define AHC_CARDBUS_MMBA 0x14
72 1.3.6.2 bouyer
73 1.3.6.2 bouyer struct ahc_cardbus_softc {
74 1.3.6.2 bouyer struct ahc_softc sc_ahc; /* real AHC */
75 1.3.6.2 bouyer
76 1.3.6.2 bouyer /* CardBus-specific goo. */
77 1.3.6.2 bouyer cardbus_devfunc_t sc_ct; /* our CardBus devfuncs */
78 1.3.6.2 bouyer int sc_intrline; /* our interrupt line */
79 1.3.6.2 bouyer cardbustag_t sc_tag;
80 1.3.6.2 bouyer
81 1.3.6.2 bouyer int sc_cbenable; /* what CardBus access type to enable */
82 1.3.6.2 bouyer int sc_csr; /* CSR bits */
83 1.3.6.2 bouyer };
84 1.3.6.2 bouyer
85 1.3.6.2 bouyer int ahc_cardbus_match __P((struct device *, struct cfdata *, void *));
86 1.3.6.2 bouyer void ahc_cardbus_attach __P((struct device *, struct device *, void *));
87 1.3.6.2 bouyer
88 1.3.6.2 bouyer struct cfattach ahc_cardbus_ca = {
89 1.3.6.2 bouyer sizeof(struct ahc_softc), ahc_cardbus_match, ahc_cardbus_attach,
90 1.3.6.2 bouyer };
91 1.3.6.2 bouyer
92 1.3.6.2 bouyer int
93 1.3.6.2 bouyer ahc_cardbus_match(parent, match, aux)
94 1.3.6.2 bouyer struct device *parent;
95 1.3.6.2 bouyer struct cfdata *match;
96 1.3.6.2 bouyer void *aux;
97 1.3.6.2 bouyer {
98 1.3.6.2 bouyer struct cardbus_attach_args *ca = aux;
99 1.3.6.2 bouyer
100 1.3.6.2 bouyer if (CARDBUS_VENDOR(ca->ca_id) == CARDBUS_VENDOR_ADP &&
101 1.3.6.2 bouyer CARDBUS_PRODUCT(ca->ca_id) == CARDBUS_PRODUCT_ADP_1480)
102 1.3.6.2 bouyer return (1);
103 1.3.6.2 bouyer
104 1.3.6.2 bouyer return (0);
105 1.3.6.2 bouyer }
106 1.3.6.2 bouyer
107 1.3.6.2 bouyer void
108 1.3.6.2 bouyer ahc_cardbus_attach(parent, self, aux)
109 1.3.6.2 bouyer struct device *parent, *self;
110 1.3.6.2 bouyer void *aux;
111 1.3.6.2 bouyer {
112 1.3.6.2 bouyer struct cardbus_attach_args *ca = aux;
113 1.3.6.2 bouyer struct ahc_cardbus_softc *csc = (void *) self;
114 1.3.6.2 bouyer struct ahc_softc *ahc = &csc->sc_ahc;
115 1.3.6.2 bouyer cardbus_devfunc_t ct = ca->ca_ct;
116 1.3.6.2 bouyer cardbus_chipset_tag_t cc = ct->ct_cc;
117 1.3.6.2 bouyer cardbus_function_tag_t cf = ct->ct_cf;
118 1.3.6.2 bouyer bus_space_tag_t bst;
119 1.3.6.2 bouyer bus_space_handle_t bsh;
120 1.3.6.2 bouyer pcireg_t reg;
121 1.3.6.2 bouyer u_int sxfrctl1 = 0;
122 1.3.6.2 bouyer ahc_chip ahc_t = AHC_NONE;
123 1.3.6.2 bouyer ahc_feature ahc_fe = AHC_FENONE;
124 1.3.6.2 bouyer ahc_flag ahc_f = AHC_FNONE;
125 1.3.6.2 bouyer
126 1.3.6.2 bouyer
127 1.3.6.2 bouyer csc->sc_ct = ct;
128 1.3.6.2 bouyer csc->sc_tag = ca->ca_tag;
129 1.3.6.2 bouyer csc->sc_intrline = ca->ca_intrline;
130 1.3.6.2 bouyer
131 1.3.6.2 bouyer printf(": Adaptec ADP-1480 SCSI\n");
132 1.3.6.2 bouyer
133 1.3.6.2 bouyer /*
134 1.3.6.2 bouyer * Map the device.
135 1.3.6.2 bouyer */
136 1.3.6.2 bouyer csc->sc_csr = PCI_COMMAND_MASTER_ENABLE;
137 1.3.6.2 bouyer if (Cardbus_mapreg_map(csc->sc_ct, AHC_CARDBUS_MMBA,
138 1.3.6.2 bouyer PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
139 1.3.6.2 bouyer &bst, &bsh, NULL, NULL) == 0) {
140 1.3.6.2 bouyer csc->sc_cbenable = CARDBUS_MEM_ENABLE;
141 1.3.6.2 bouyer csc->sc_csr |= PCI_COMMAND_MEM_ENABLE;
142 1.3.6.2 bouyer } else if (Cardbus_mapreg_map(csc->sc_ct, AHC_CARDBUS_IOBA,
143 1.3.6.2 bouyer PCI_MAPREG_TYPE_IO, 0, &bst, &bsh, NULL, NULL) == 0) {
144 1.3.6.2 bouyer csc->sc_cbenable = CARDBUS_IO_ENABLE;
145 1.3.6.2 bouyer csc->sc_csr |= PCI_COMMAND_IO_ENABLE;
146 1.3.6.2 bouyer } else {
147 1.3.6.2 bouyer printf("%s: unable to map device registers\n",
148 1.3.6.2 bouyer ahc_name(ahc));
149 1.3.6.2 bouyer return;
150 1.3.6.2 bouyer }
151 1.3.6.2 bouyer
152 1.3.6.2 bouyer /* Make sure the right access type is on the CardBus bridge. */
153 1.3.6.2 bouyer (*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cbenable);
154 1.3.6.2 bouyer (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
155 1.3.6.2 bouyer
156 1.3.6.2 bouyer /* Enable the appropriate bits in the PCI CSR. */
157 1.3.6.2 bouyer reg = cardbus_conf_read(cc, cf, ca->ca_tag, PCI_COMMAND_STATUS_REG);
158 1.3.6.2 bouyer reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
159 1.3.6.2 bouyer reg |= csc->sc_csr;
160 1.3.6.2 bouyer cardbus_conf_write(cc, cf, ca->ca_tag, PCI_COMMAND_STATUS_REG, reg);
161 1.3.6.2 bouyer
162 1.3.6.2 bouyer /*
163 1.3.6.2 bouyer * Make sure the latency timer is set to some reasonable
164 1.3.6.2 bouyer * value.
165 1.3.6.2 bouyer */
166 1.3.6.2 bouyer reg = cardbus_conf_read(cc, cf, ca->ca_tag, PCI_BHLC_REG);
167 1.3.6.2 bouyer if (PCI_LATTIMER(reg) < 0x20) {
168 1.3.6.2 bouyer reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
169 1.3.6.2 bouyer reg |= (0x20 << PCI_LATTIMER_SHIFT);
170 1.3.6.2 bouyer cardbus_conf_write(cc, cf, ca->ca_tag, PCI_BHLC_REG, reg);
171 1.3.6.2 bouyer }
172 1.3.6.2 bouyer
173 1.3.6.2 bouyer /*
174 1.3.6.2 bouyer * ADP-1480 is always an AIC-7860.
175 1.3.6.2 bouyer */
176 1.3.6.2 bouyer ahc_t = AHC_AIC7860;
177 1.3.6.2 bouyer ahc_fe = AHC_AIC7860_FE;
178 1.3.6.2 bouyer
179 1.3.6.2 bouyer /*
180 1.3.6.2 bouyer * On all CardBus adapters, we allow SCB paging.
181 1.3.6.2 bouyer */
182 1.3.6.2 bouyer ahc_f = AHC_PAGESCBS;
183 1.3.6.2 bouyer
184 1.3.6.2 bouyer if (ahc_alloc(ahc, bsh, bst, ca->ca_dmat, ahc_t | AHC_PCI /* XXX */,
185 1.3.6.2 bouyer ahc_fe, ahc_f) < 0) {
186 1.3.6.2 bouyer printf("%s: unable to initialize softc\n", ahc_name(ahc));
187 1.3.6.2 bouyer return;
188 1.3.6.2 bouyer }
189 1.3.6.2 bouyer
190 1.3.6.2 bouyer ahc->channel = 'A';
191 1.3.6.2 bouyer
192 1.3.6.2 bouyer ahc_reset(ahc);
193 1.3.6.2 bouyer
194 1.3.6.2 bouyer /*
195 1.3.6.2 bouyer * Establish the interrupt.
196 1.3.6.2 bouyer */
197 1.3.6.2 bouyer ahc->ih = cardbus_intr_establish(cc, cf, ca->ca_intrline, IPL_BIO,
198 1.3.6.2 bouyer ahc_intr, ahc);
199 1.3.6.2 bouyer if (ahc->ih == NULL) {
200 1.3.6.2 bouyer printf("%s: unable to establish interrupt at %d\n",
201 1.3.6.2 bouyer ahc_name(ahc), ca->ca_intrline);
202 1.3.6.2 bouyer return;
203 1.3.6.2 bouyer }
204 1.3.6.2 bouyer printf("%s: interrupting at %d\n", ahc_name(ahc), ca->ca_intrline);
205 1.3.6.2 bouyer
206 1.3.6.2 bouyer /*
207 1.3.6.2 bouyer * Do chip-specific initialization.
208 1.3.6.2 bouyer */
209 1.3.6.2 bouyer {
210 1.3.6.2 bouyer u_char sblkctl;
211 1.3.6.2 bouyer const char *id_string;
212 1.3.6.2 bouyer
213 1.3.6.2 bouyer switch (ahc->chip & AHC_CHIPID_MASK) {
214 1.3.6.2 bouyer case AHC_AIC7860:
215 1.3.6.2 bouyer id_string = "aic7860 ";
216 1.3.6.2 bouyer check_extport(ahc, &sxfrctl1);
217 1.3.6.2 bouyer break;
218 1.3.6.2 bouyer
219 1.3.6.2 bouyer default:
220 1.3.6.2 bouyer printf("%s: unknown controller type\n", ahc_name(ahc));
221 1.3.6.2 bouyer ahc_free(ahc);
222 1.3.6.2 bouyer return;
223 1.3.6.2 bouyer }
224 1.3.6.2 bouyer
225 1.3.6.2 bouyer /*
226 1.3.6.2 bouyer * Take the LED out of diagnostic mode.
227 1.3.6.2 bouyer */
228 1.3.6.2 bouyer sblkctl = ahc_inb(ahc, SBLKCTL);
229 1.3.6.2 bouyer ahc_outb(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
230 1.3.6.2 bouyer
231 1.3.6.2 bouyer /*
232 1.3.6.2 bouyer * I don't know where this is set in the SEEPROM or by the
233 1.3.6.2 bouyer * BIOS, so we default to 100%.
234 1.3.6.2 bouyer */
235 1.3.6.2 bouyer ahc_outb(ahc, DSPCISTATUS, DFTHRSH_100);
236 1.3.6.2 bouyer
237 1.3.6.2 bouyer if (ahc->flags & AHC_USEDEFAULTS) {
238 1.3.6.2 bouyer /*
239 1.3.6.2 bouyer * We can't "use defaults", as we have no way
240 1.3.6.2 bouyer * of knowing what default settings hould be.
241 1.3.6.2 bouyer */
242 1.3.6.2 bouyer printf("%s: CardBus device requires an SEEPROM\n",
243 1.3.6.2 bouyer ahc_name(ahc));
244 1.3.6.2 bouyer return;
245 1.3.6.2 bouyer }
246 1.3.6.2 bouyer
247 1.3.6.2 bouyer printf("%s: %s", ahc_name(ahc), id_string);
248 1.3.6.2 bouyer }
249 1.3.6.2 bouyer
250 1.3.6.2 bouyer /*
251 1.3.6.2 bouyer * XXX does this card have external SRAM? - fvdl
252 1.3.6.2 bouyer */
253 1.3.6.2 bouyer
254 1.3.6.2 bouyer /*
255 1.3.6.2 bouyer * Record our termination setting for the
256 1.3.6.2 bouyer * generic initialization routine.
257 1.3.6.2 bouyer */
258 1.3.6.2 bouyer if ((sxfrctl1 & STPWEN) != 0)
259 1.3.6.2 bouyer ahc->flags |= AHC_TERM_ENB_A;
260 1.3.6.2 bouyer
261 1.3.6.2 bouyer if (ahc_init(ahc)) {
262 1.3.6.2 bouyer ahc_free(ahc);
263 1.3.6.2 bouyer return;
264 1.3.6.2 bouyer }
265 1.3.6.2 bouyer
266 1.3.6.2 bouyer ahc_attach(ahc);
267 1.3.6.2 bouyer }
268