siop_pci.c revision 1.2 1 /* $NetBSD: siop_pci.c,v 1.2 2000/04/27 14:06:59 bouyer 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 for (pp = siop_products; pp->name != NULL; pp++) {
178 if (PCI_PRODUCT(id) == pp->product && pp->revision <= rev)
179 if (rp == NULL || pp->revision > rp->revision)
180 rp = pp;
181 }
182 return rp;
183 }
184
185 /* Driver internal state */
186 struct siop_pci_softc {
187 struct siop_softc siop;
188 pci_chipset_tag_t sc_pc; /* PCI registers info */
189 pcitag_t sc_tag;
190 void *sc_ih; /* PCI interrupt handle */
191 const struct siop_product_desc *sc_pp; /* Adapter description */
192 };
193
194 int siop_pci_match __P((struct device *, struct cfdata *, void *));
195 void siop_pci_attach __P((struct device *, struct device *, void *));
196
197 struct cfattach siop_pci_ca = {
198 sizeof(struct siop_pci_softc), siop_pci_match, siop_pci_attach
199 };
200
201 int
202 siop_pci_match(parent, match, aux)
203 struct device *parent;
204 struct cfdata *match;
205 void *aux;
206 {
207 struct pci_attach_args *pa = aux;
208 const struct siop_product_desc *pp;
209
210 /* look if it's a known product */
211 pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
212 if (pp)
213 return 1;
214 return 0;
215 }
216
217 void
218 siop_pci_attach(parent, self, aux)
219 struct device *parent, *self;
220 void *aux;
221 {
222 struct pci_attach_args *pa = aux;
223 pci_chipset_tag_t pc = pa->pa_pc;
224 pcitag_t tag = pa->pa_tag;
225 struct siop_pci_softc *sc = (struct siop_pci_softc *)self;
226 const char *intrstr;
227 pci_intr_handle_t intrhandle;
228
229 sc->sc_pp = siop_lookup_product(pa->pa_id, PCI_REVISION(pa->pa_class));
230 if (sc->sc_pp == NULL) {
231 printf("sym: broken match/attach!!\n");
232 return;
233 }
234 printf(": %s\n", sc->sc_pp->name);
235 sc->sc_pc = pc;
236 sc->sc_tag = tag;
237 sc->siop.sc_dmat = pa->pa_dmat;
238 if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_IO, 0,
239 &sc->siop.sc_rt, &sc->siop.sc_rh, &sc->siop.sc_raddr, NULL) != 0) {
240 /* Try to map memory addr */
241 if (pci_mapreg_map(pa, 0x14,
242 PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
243 &sc->siop.sc_rt, &sc->siop.sc_rh,
244 &sc->siop.sc_raddr, NULL) != 0) {
245 printf("%s: unable to map device registers\n",
246 sc->siop.sc_dev.dv_xname);
247 }
248 }
249 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
250 pa->pa_intrline, &intrhandle) != 0) {
251 printf("%s: couldn't map native-PCI interrupt\n",
252 sc->siop.sc_dev.dv_xname);
253 return;
254 }
255 intrstr = pci_intr_string(pa->pa_pc, intrhandle);
256 sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_BIO,
257 siop_intr, &sc->siop);
258 if (sc->sc_ih != NULL) {
259 printf("%s: using %s for native-PCI interrupt\n",
260 sc->siop.sc_dev.dv_xname,
261 intrstr ? intrstr : "unknown interrupt");
262 } else {
263 printf("%s: couldn't establish interrupt",
264 sc->siop.sc_dev.dv_xname);
265 if (intrstr != NULL)
266 printf(" at %s", intrstr);
267 printf("\n");
268 return;
269 }
270 /* copy interesting infos about the chip */
271 sc->siop.features = sc->sc_pp->features;
272 sc->siop.maxburst = sc->sc_pp->maxburst;
273 sc->siop.maxoff = sc->sc_pp->maxoff;
274 sc->siop.clock_div = sc->sc_pp->clock_div;
275 /* attach generic code */
276 siop_attach(&sc->siop);
277 }
278