siop_pci.c revision 1.7 1 1.7 thorpej /* $NetBSD: siop_pci.c,v 1.7 2000/05/10 17:22:46 thorpej Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2000 Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.1 bouyer * must display the following acknowledgement:
16 1.2 bouyer * This product includes software developed by Manuel Bouyer
17 1.2 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.2 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.2 bouyer * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 1.2 bouyer * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 1.2 bouyer * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 1.2 bouyer * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24 1.2 bouyer * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer *
31 1.1 bouyer */
32 1.1 bouyer
33 1.1 bouyer /* SYM53c8xx PCI-SCSI I/O Processors driver: PCI front-end */
34 1.1 bouyer
35 1.1 bouyer #include <sys/param.h>
36 1.1 bouyer #include <sys/systm.h>
37 1.1 bouyer #include <sys/device.h>
38 1.1 bouyer #include <sys/malloc.h>
39 1.1 bouyer #include <sys/buf.h>
40 1.1 bouyer #include <sys/kernel.h>
41 1.1 bouyer
42 1.1 bouyer #include <machine/endian.h>
43 1.1 bouyer
44 1.1 bouyer #include <dev/pci/pcireg.h>
45 1.1 bouyer #include <dev/pci/pcivar.h>
46 1.1 bouyer #include <dev/pci/pcidevs.h>
47 1.1 bouyer
48 1.1 bouyer #include <dev/scsipi/scsipi_all.h>
49 1.1 bouyer #include <dev/scsipi/scsipiconf.h>
50 1.1 bouyer
51 1.1 bouyer #include <dev/ic/siopvar.h>
52 1.1 bouyer
53 1.1 bouyer /* structure describing each chip */
54 1.1 bouyer struct siop_product_desc {
55 1.1 bouyer u_int32_t product;
56 1.1 bouyer int revision;
57 1.1 bouyer const char *name;
58 1.1 bouyer int features; /* features are defined in siopvar.h */
59 1.1 bouyer u_int8_t maxburst;
60 1.4 bouyer u_int8_t maxoff; /* maximum supported offset */
61 1.4 bouyer u_int8_t clock_div; /* clock divider to use for async. logic */
62 1.4 bouyer u_int8_t clock_period; /* clock period (ns * 10) */
63 1.1 bouyer };
64 1.1 bouyer
65 1.1 bouyer /* List (array, really :) of chips we know how to handle */
66 1.1 bouyer const struct siop_product_desc siop_products[] = {
67 1.1 bouyer { PCI_PRODUCT_SYMBIOS_810,
68 1.1 bouyer 0x00,
69 1.1 bouyer "Symbios Logic 53c810 (fast scsi)",
70 1.1 bouyer SF_PCI_RL,
71 1.4 bouyer 4, 8, 3, 250
72 1.1 bouyer },
73 1.1 bouyer { PCI_PRODUCT_SYMBIOS_810,
74 1.1 bouyer 0x10,
75 1.1 bouyer "Symbios Logic 53c810a (fast scsi)",
76 1.1 bouyer SF_PCI_RL | SF_PCI_BOF | SF_CHIP_PF,
77 1.4 bouyer 4, 8, 3, 250
78 1.1 bouyer },
79 1.1 bouyer { PCI_PRODUCT_SYMBIOS_815,
80 1.1 bouyer 0x00,
81 1.1 bouyer "Symbios Logic 53c815 (fast scsi)",
82 1.1 bouyer SF_PCI_RL | SF_PCI_BOF,
83 1.4 bouyer 4, 8, 3, 250
84 1.1 bouyer },
85 1.1 bouyer { PCI_PRODUCT_SYMBIOS_820,
86 1.1 bouyer 0x00,
87 1.1 bouyer "Symbios Logic 53c820 (fast wide scsi)",
88 1.1 bouyer SF_PCI_RL | SF_BUS_WIDE,
89 1.4 bouyer 4, 8, 3, 250
90 1.1 bouyer },
91 1.1 bouyer { PCI_PRODUCT_SYMBIOS_825,
92 1.1 bouyer 0x00,
93 1.1 bouyer "Symbios Logic 53c825 (fast wide scsi)",
94 1.1 bouyer SF_PCI_RL | SF_PCI_BOF | SF_BUS_WIDE,
95 1.4 bouyer 4, 8, 3, 250
96 1.1 bouyer },
97 1.1 bouyer { PCI_PRODUCT_SYMBIOS_825,
98 1.1 bouyer 0x10,
99 1.1 bouyer "Symbios Logic 53c825a (fast wide scsi)",
100 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
101 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
102 1.1 bouyer SF_BUS_WIDE,
103 1.4 bouyer 7, 8, 3, 250
104 1.1 bouyer },
105 1.1 bouyer { PCI_PRODUCT_SYMBIOS_860,
106 1.1 bouyer 0x00,
107 1.1 bouyer "Symbios Logic 53c860 (ultra scsi)",
108 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
109 1.4 bouyer SF_CHIP_PF |
110 1.1 bouyer SF_BUS_ULTRA,
111 1.4 bouyer 4, 8, 5, 125
112 1.1 bouyer },
113 1.1 bouyer { PCI_PRODUCT_SYMBIOS_875,
114 1.1 bouyer 0x00,
115 1.1 bouyer "Symbios Logic 53c875 (ultra-wide scsi)",
116 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
117 1.4 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM |
118 1.1 bouyer SF_BUS_ULTRA | SF_BUS_WIDE,
119 1.4 bouyer 7, 16, 5, 125
120 1.1 bouyer },
121 1.1 bouyer { PCI_PRODUCT_SYMBIOS_875,
122 1.1 bouyer 0x02,
123 1.1 bouyer "Symbios Logic 53c875 (ultra-wide scsi)",
124 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
125 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
126 1.1 bouyer SF_BUS_ULTRA | SF_BUS_WIDE,
127 1.4 bouyer 7, 16, 5, 125
128 1.1 bouyer },
129 1.1 bouyer { PCI_PRODUCT_SYMBIOS_875J,
130 1.1 bouyer 0x00,
131 1.1 bouyer "Symbios Logic 53c875j (ultra-wide scsi)",
132 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
133 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
134 1.1 bouyer SF_BUS_ULTRA | SF_BUS_WIDE,
135 1.4 bouyer 7, 16, 5, 125
136 1.1 bouyer },
137 1.1 bouyer { PCI_PRODUCT_SYMBIOS_885,
138 1.1 bouyer 0x00,
139 1.1 bouyer "Symbios Logic 53c885 (ultra-wide scsi)",
140 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
141 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_DBLR |
142 1.1 bouyer SF_BUS_ULTRA | SF_BUS_WIDE,
143 1.4 bouyer 7, 16, 5, 125
144 1.1 bouyer },
145 1.1 bouyer { PCI_PRODUCT_SYMBIOS_895,
146 1.1 bouyer 0x00,
147 1.1 bouyer "Symbios Logic 53c895 (ultra2-wide scsi)",
148 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
149 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
150 1.1 bouyer SF_BUS_ULTRA2 | SF_BUS_WIDE,
151 1.4 bouyer 7, 31, 7, 62
152 1.1 bouyer },
153 1.1 bouyer { PCI_PRODUCT_SYMBIOS_896,
154 1.1 bouyer 0x00,
155 1.1 bouyer "Symbios Logic 53c896 (ultra2-wide scsi)",
156 1.1 bouyer SF_PCI_RL | SF_PCI_CLS | SF_PCI_WRI | SF_PCI_RM |
157 1.1 bouyer SF_CHIP_FIFO | SF_CHIP_PF | SF_CHIP_RAM | SF_CHIP_QUAD |
158 1.1 bouyer SF_BUS_ULTRA2 | SF_BUS_WIDE,
159 1.4 bouyer 7, 31, 7, 62
160 1.1 bouyer },
161 1.1 bouyer { 0,
162 1.1 bouyer 0x00,
163 1.1 bouyer NULL,
164 1.1 bouyer 0x00,
165 1.4 bouyer 0, 0, 0, 0
166 1.1 bouyer },
167 1.1 bouyer };
168 1.1 bouyer
169 1.1 bouyer const struct siop_product_desc * siop_lookup_product __P((u_int32_t, int));
170 1.1 bouyer
171 1.1 bouyer const struct siop_product_desc *
172 1.1 bouyer siop_lookup_product(id, rev)
173 1.1 bouyer u_int32_t id;
174 1.1 bouyer int rev;
175 1.1 bouyer {
176 1.1 bouyer const struct siop_product_desc *pp;
177 1.1 bouyer const struct siop_product_desc *rp = NULL;
178 1.3 nathanw
179 1.3 nathanw if (PCI_VENDOR(id) != PCI_VENDOR_SYMBIOS)
180 1.3 nathanw return NULL;
181 1.3 nathanw
182 1.1 bouyer for (pp = siop_products; pp->name != NULL; pp++) {
183 1.1 bouyer if (PCI_PRODUCT(id) == pp->product && pp->revision <= rev)
184 1.1 bouyer if (rp == NULL || pp->revision > rp->revision)
185 1.1 bouyer rp = pp;
186 1.1 bouyer }
187 1.1 bouyer return rp;
188 1.1 bouyer }
189 1.1 bouyer
190 1.1 bouyer /* Driver internal state */
191 1.1 bouyer struct siop_pci_softc {
192 1.1 bouyer struct siop_softc siop;
193 1.1 bouyer pci_chipset_tag_t sc_pc; /* PCI registers info */
194 1.1 bouyer pcitag_t sc_tag;
195 1.1 bouyer void *sc_ih; /* PCI interrupt handle */
196 1.1 bouyer const struct siop_product_desc *sc_pp; /* Adapter description */
197 1.1 bouyer };
198 1.1 bouyer
199 1.1 bouyer int siop_pci_match __P((struct device *, struct cfdata *, void *));
200 1.1 bouyer void siop_pci_attach __P((struct device *, struct device *, void *));
201 1.1 bouyer
202 1.1 bouyer struct cfattach siop_pci_ca = {
203 1.1 bouyer sizeof(struct siop_pci_softc), siop_pci_match, siop_pci_attach
204 1.1 bouyer };
205 1.1 bouyer
206 1.1 bouyer int
207 1.1 bouyer siop_pci_match(parent, match, aux)
208 1.1 bouyer struct device *parent;
209 1.1 bouyer struct cfdata *match;
210 1.1 bouyer void *aux;
211 1.1 bouyer {
212 1.1 bouyer struct pci_attach_args *pa = aux;
213 1.1 bouyer const struct siop_product_desc *pp;
214 1.1 bouyer
215 1.1 bouyer /* look if it's a known product */
216 1.1 bouyer pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
217 1.1 bouyer if (pp)
218 1.1 bouyer return 1;
219 1.1 bouyer return 0;
220 1.1 bouyer }
221 1.1 bouyer
222 1.1 bouyer void
223 1.1 bouyer siop_pci_attach(parent, self, aux)
224 1.1 bouyer struct device *parent, *self;
225 1.1 bouyer void *aux;
226 1.1 bouyer {
227 1.1 bouyer struct pci_attach_args *pa = aux;
228 1.1 bouyer pci_chipset_tag_t pc = pa->pa_pc;
229 1.1 bouyer pcitag_t tag = pa->pa_tag;
230 1.1 bouyer struct siop_pci_softc *sc = (struct siop_pci_softc *)self;
231 1.1 bouyer const char *intrstr;
232 1.1 bouyer pci_intr_handle_t intrhandle;
233 1.7 thorpej bus_space_tag_t iot, memt;
234 1.7 thorpej bus_space_handle_t ioh, memh;
235 1.7 thorpej pcireg_t memtype;
236 1.7 thorpej int memh_valid, ioh_valid;
237 1.7 thorpej bus_addr_t ioaddr, memaddr;
238 1.1 bouyer
239 1.1 bouyer sc->sc_pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
240 1.1 bouyer if (sc->sc_pp == NULL) {
241 1.1 bouyer printf("sym: broken match/attach!!\n");
242 1.1 bouyer return;
243 1.1 bouyer }
244 1.1 bouyer printf(": %s\n", sc->sc_pp->name);
245 1.1 bouyer sc->sc_pc = pc;
246 1.1 bouyer sc->sc_tag = tag;
247 1.1 bouyer sc->siop.sc_dmat = pa->pa_dmat;
248 1.7 thorpej
249 1.7 thorpej memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, 0x14);
250 1.7 thorpej switch (memtype) {
251 1.7 thorpej case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
252 1.7 thorpej case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
253 1.7 thorpej memh_valid = (pci_mapreg_map(pa, 0x14, memtype, 0,
254 1.7 thorpej &memt, &memh, &memaddr, NULL) == 0);
255 1.7 thorpej break;
256 1.7 thorpej default:
257 1.7 thorpej memh_valid = 0;
258 1.7 thorpej }
259 1.7 thorpej
260 1.7 thorpej ioh_valid = (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0,
261 1.7 thorpej &iot, &ioh, &ioaddr, NULL) == 0);
262 1.7 thorpej
263 1.7 thorpej if (memh_valid) {
264 1.7 thorpej sc->siop.sc_rt = memt;
265 1.7 thorpej sc->siop.sc_rh = memh;
266 1.7 thorpej sc->siop.sc_raddr = memaddr;
267 1.7 thorpej } else if (ioh_valid) {
268 1.7 thorpej sc->siop.sc_rt = iot;
269 1.7 thorpej sc->siop.sc_rh = ioh;
270 1.7 thorpej sc->siop.sc_raddr = ioaddr;
271 1.7 thorpej } else {
272 1.7 thorpej printf("%s: unable to map device registers\n",
273 1.7 thorpej sc->siop.sc_dev.dv_xname);
274 1.7 thorpej return;
275 1.1 bouyer }
276 1.7 thorpej
277 1.1 bouyer if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
278 1.1 bouyer pa->pa_intrline, &intrhandle) != 0) {
279 1.5 soren printf("%s: couldn't map interrupt\n",
280 1.1 bouyer sc->siop.sc_dev.dv_xname);
281 1.1 bouyer return;
282 1.1 bouyer }
283 1.1 bouyer intrstr = pci_intr_string(pa->pa_pc, intrhandle);
284 1.1 bouyer sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_BIO,
285 1.1 bouyer siop_intr, &sc->siop);
286 1.1 bouyer if (sc->sc_ih != NULL) {
287 1.5 soren printf("%s: interrupting at %s\n",
288 1.1 bouyer sc->siop.sc_dev.dv_xname,
289 1.1 bouyer intrstr ? intrstr : "unknown interrupt");
290 1.1 bouyer } else {
291 1.1 bouyer printf("%s: couldn't establish interrupt",
292 1.1 bouyer sc->siop.sc_dev.dv_xname);
293 1.1 bouyer if (intrstr != NULL)
294 1.1 bouyer printf(" at %s", intrstr);
295 1.1 bouyer printf("\n");
296 1.1 bouyer return;
297 1.1 bouyer }
298 1.1 bouyer /* copy interesting infos about the chip */
299 1.1 bouyer sc->siop.features = sc->sc_pp->features;
300 1.1 bouyer sc->siop.maxburst = sc->sc_pp->maxburst;
301 1.1 bouyer sc->siop.maxoff = sc->sc_pp->maxoff;
302 1.1 bouyer sc->siop.clock_div = sc->sc_pp->clock_div;
303 1.4 bouyer sc->siop.clock_period = sc->sc_pp->clock_period;
304 1.1 bouyer /* attach generic code */
305 1.1 bouyer siop_attach(&sc->siop);
306 1.1 bouyer }
307