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