1 /* $NetBSD: siop_pci_common.c,v 1.32 2009/10/19 18:41:16 bouyer Exp $ */
4 * Copyright (c) 2000 Manuel Bouyer.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* SYM53c8xx PCI-SCSI I/O Processors driver: PCI front-end */
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: siop_pci_common.c,v 1.32 2009/10/19 18:41:16 bouyer Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/malloc.h>
37 #include <sys/kernel.h>
39 #include <uvm/uvm_extern.h>
41 #include <machine/endian.h>
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcidevs.h>
47 #include <dev/scsipi/scsipi_all.h>
48 #include <dev/scsipi/scsipiconf.h>
50 #include <dev/ic/siopreg.h>
51 #include <dev/ic/siopvar_common.h>
52 #include <dev/pci/siop_pci_common.h>
54 /* List (array, really :) of chips we know how to handle */
55 static const struct siop_product_desc siop_products
[] = {
56 { PCI_PRODUCT_SYMBIOS_810
,
58 "Symbios Logic 53c810 (fast scsi)",
59 SF_PCI_RL
| SF_CHIP_LS
,
62 { PCI_PRODUCT_SYMBIOS_810
,
64 "Symbios Logic 53c810a (fast scsi)",
65 SF_PCI_RL
| SF_PCI_BOF
| SF_CHIP_PF
| SF_CHIP_LS
,
68 { PCI_PRODUCT_SYMBIOS_815
,
70 "Symbios Logic 53c815 (fast scsi)",
71 SF_PCI_RL
| SF_PCI_BOF
,
74 { PCI_PRODUCT_SYMBIOS_820
,
76 "Symbios Logic 53c820 (fast wide scsi)",
77 SF_PCI_RL
| SF_CHIP_LS
| SF_BUS_WIDE
,
80 { PCI_PRODUCT_SYMBIOS_825
,
82 "Symbios Logic 53c825 (fast wide scsi)",
83 SF_PCI_RL
| SF_PCI_BOF
| SF_BUS_WIDE
,
86 { PCI_PRODUCT_SYMBIOS_825
,
88 "Symbios Logic 53c825a (fast wide scsi)",
89 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
90 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_LS
| SF_CHIP_10REGS
|
94 { PCI_PRODUCT_SYMBIOS_860
,
96 "Symbios Logic 53c860 (ultra scsi)",
97 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
98 SF_CHIP_PF
| SF_CHIP_LS
|
102 { PCI_PRODUCT_SYMBIOS_875
,
104 "Symbios Logic 53c875 (ultra-wide scsi)",
105 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
106 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_LS
| SF_CHIP_10REGS
|
107 SF_BUS_ULTRA
| SF_BUS_WIDE
,
110 { PCI_PRODUCT_SYMBIOS_875
,
112 "Symbios Logic 53c875 (ultra-wide scsi)",
113 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
114 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_DBLR
|
115 SF_CHIP_LS
| SF_CHIP_10REGS
|
116 SF_BUS_ULTRA
| SF_BUS_WIDE
,
119 { PCI_PRODUCT_SYMBIOS_875J
,
121 "Symbios Logic 53c875j (ultra-wide scsi)",
122 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
123 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_DBLR
|
124 SF_CHIP_LS
| SF_CHIP_10REGS
|
125 SF_BUS_ULTRA
| SF_BUS_WIDE
,
128 { PCI_PRODUCT_SYMBIOS_885
,
130 "Symbios Logic 53c885 (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_CHIP_LS
| SF_CHIP_10REGS
|
134 SF_BUS_ULTRA
| SF_BUS_WIDE
,
137 { PCI_PRODUCT_SYMBIOS_895
,
139 "Symbios Logic 53c895 (ultra2-wide scsi)",
140 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
141 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_QUAD
|
142 SF_CHIP_LS
| SF_CHIP_10REGS
|
143 SF_BUS_ULTRA2
| SF_BUS_WIDE
,
146 { PCI_PRODUCT_SYMBIOS_896
,
148 "Symbios Logic 53c896 (ultra2-wide scsi)",
149 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
150 SF_CHIP_LEDC
| SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_QUAD
|
151 SF_CHIP_LS
| SF_CHIP_10REGS
|
152 SF_BUS_ULTRA2
| SF_BUS_WIDE
,
155 { PCI_PRODUCT_SYMBIOS_895A
,
157 "Symbios Logic 53c895a (ultra2-wide scsi)",
158 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
159 SF_CHIP_LEDC
| SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_QUAD
|
160 SF_CHIP_LS
| SF_CHIP_10REGS
|
161 SF_BUS_ULTRA2
| SF_BUS_WIDE
,
164 { PCI_PRODUCT_SYMBIOS_1010
,
166 "Symbios Logic 53c1010-33 rev 0 (ultra3-wide scsi)",
167 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
168 SF_CHIP_LEDC
| SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
|
169 SF_CHIP_LS
| SF_CHIP_10REGS
| SF_CHIP_DFBC
| SF_CHIP_DBLR
|
171 SF_BUS_ULTRA3
| SF_BUS_WIDE
,
174 { PCI_PRODUCT_SYMBIOS_1010
,
176 "Symbios Logic 53c1010-33 (ultra3-wide scsi)",
177 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
178 SF_CHIP_LEDC
| SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
|
179 SF_CHIP_LS
| SF_CHIP_10REGS
| SF_CHIP_DFBC
| SF_CHIP_DBLR
| SF_CHIP_DT
|
181 SF_BUS_ULTRA3
| SF_BUS_WIDE
,
184 { PCI_PRODUCT_SYMBIOS_1010_2
,
186 "Symbios Logic 53c1010-66 (ultra3-wide scsi)",
187 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
188 SF_CHIP_LEDC
| SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
|
189 SF_CHIP_LS
| SF_CHIP_10REGS
| SF_CHIP_DFBC
| SF_CHIP_DBLR
| SF_CHIP_DT
|
191 SF_BUS_ULTRA3
| SF_BUS_WIDE
,
194 { PCI_PRODUCT_SYMBIOS_1510D
,
196 "Symbios Logic 53c1510d (ultra2-wide scsi)",
197 SF_PCI_RL
| SF_PCI_CLS
| SF_PCI_WRI
| SF_PCI_RM
|
198 SF_CHIP_FIFO
| SF_CHIP_PF
| SF_CHIP_RAM
| SF_CHIP_QUAD
|
199 SF_CHIP_LS
| SF_CHIP_10REGS
|
200 SF_BUS_ULTRA2
| SF_BUS_WIDE
,
211 const struct siop_product_desc
*
212 siop_lookup_product(uint32_t id
, int rev
)
214 const struct siop_product_desc
*pp
;
215 const struct siop_product_desc
*rp
= NULL
;
217 if (PCI_VENDOR(id
) != PCI_VENDOR_SYMBIOS
)
220 for (pp
= siop_products
; pp
->name
!= NULL
; pp
++) {
221 if (PCI_PRODUCT(id
) == pp
->product
&& pp
->revision
<= rev
)
222 if (rp
== NULL
|| pp
->revision
> rp
->revision
)
229 siop_pci_attach_common(struct siop_pci_common_softc
*pci_sc
,
230 struct siop_common_softc
*siop_sc
, struct pci_attach_args
*pa
,
233 pci_chipset_tag_t pc
= pa
->pa_pc
;
234 pcitag_t tag
= pa
->pa_tag
;
236 pci_intr_handle_t intrhandle
;
237 bus_space_tag_t iot
, memt
;
238 bus_space_handle_t ioh
, memh
;
240 prop_dictionary_t dict
;
241 int memh_valid
, ioh_valid
;
242 bus_addr_t ioaddr
, memaddr
;
245 aprint_naive(": SCSI controller\n");
248 siop_lookup_product(pa
->pa_id
, PCI_REVISION(pa
->pa_class
));
249 if (pci_sc
->sc_pp
== NULL
) {
250 aprint_error("sym: broken match/attach!!\n");
253 /* copy interesting infos about the chip */
254 siop_sc
->features
= pci_sc
->sc_pp
->features
;
255 #ifdef SIOP_SYMLED /* XXX Should be a devprop! */
256 siop_sc
->features
|= SF_CHIP_LED0
;
258 dict
= device_properties(siop_sc
->sc_dev
);
259 if (prop_dictionary_get_bool(dict
, "use_pciclock", &use_pciclock
))
261 siop_sc
->features
|= SF_CHIP_USEPCIC
;
262 siop_sc
->maxburst
= pci_sc
->sc_pp
->maxburst
;
263 siop_sc
->maxoff
= pci_sc
->sc_pp
->maxoff
;
264 siop_sc
->clock_div
= pci_sc
->sc_pp
->clock_div
;
265 siop_sc
->clock_period
= pci_sc
->sc_pp
->clock_period
;
266 siop_sc
->ram_size
= pci_sc
->sc_pp
->ram_size
;
268 siop_sc
->sc_reset
= siop_pci_reset
;
269 aprint_normal(": %s\n", pci_sc
->sc_pp
->name
);
271 pci_sc
->sc_tag
= tag
;
272 siop_sc
->sc_dmat
= pa
->pa_dmat
;
274 memtype
= pci_mapreg_type(pa
->pa_pc
, pa
->pa_tag
, 0x14);
276 case PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
:
277 case PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_64BIT
:
278 memh_valid
= (pci_mapreg_map(pa
, 0x14, memtype
, 0,
279 &memt
, &memh
, &memaddr
, NULL
) == 0);
285 ioh_valid
= (pci_mapreg_map(pa
, 0x10, PCI_MAPREG_TYPE_IO
, 0,
286 &iot
, &ioh
, &ioaddr
, NULL
) == 0);
289 siop_sc
->sc_rt
= memt
;
290 siop_sc
->sc_rh
= memh
;
291 siop_sc
->sc_raddr
= memaddr
;
292 } else if (ioh_valid
) {
293 siop_sc
->sc_rt
= iot
;
294 siop_sc
->sc_rh
= ioh
;
295 siop_sc
->sc_raddr
= ioaddr
;
297 aprint_error_dev(siop_sc
->sc_dev
,
298 "unable to map device registers\n");
302 if (siop_sc
->features
& SF_CHIP_RAM
) {
305 case PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
:
308 case PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_64BIT
:
312 aprint_error_dev(siop_sc
->sc_dev
,
313 "invalid memory type %d\n",
317 if (pci_mapreg_map(pa
, bar
, memtype
, 0,
318 &siop_sc
->sc_ramt
, &siop_sc
->sc_ramh
,
319 &siop_sc
->sc_scriptaddr
, NULL
) == 0) {
320 aprint_normal_dev(siop_sc
->sc_dev
,
321 "using on-board RAM\n");
323 aprint_error_dev(siop_sc
->sc_dev
,
324 "can't map on-board RAM\n");
325 siop_sc
->features
&= ~SF_CHIP_RAM
;
329 if (pci_intr_map(pa
, &intrhandle
) != 0) {
330 aprint_error_dev(siop_sc
->sc_dev
, "couldn't map interrupt\n");
333 intrstr
= pci_intr_string(pa
->pa_pc
, intrhandle
);
334 pci_sc
->sc_ih
= pci_intr_establish(pa
->pa_pc
, intrhandle
, IPL_BIO
,
336 if (pci_sc
->sc_ih
!= NULL
) {
337 aprint_normal_dev(siop_sc
->sc_dev
, "interrupting at %s\n",
338 intrstr
? intrstr
: "unknown interrupt");
340 aprint_error_dev(siop_sc
->sc_dev
,
341 "couldn't establish interrupt");
343 aprint_error(" at %s", intrstr
);
347 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
,
348 pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
) |
349 PCI_COMMAND_MASTER_ENABLE
);
354 siop_pci_reset(struct siop_common_softc
*sc
)
358 dmode
= bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_DMODE
);
359 if (sc
->features
& SF_PCI_RL
)
361 if (sc
->features
& SF_PCI_RM
)
363 if (sc
->features
& SF_PCI_BOF
)
365 if (sc
->features
& SF_PCI_CLS
)
366 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_DCNTL
,
367 bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_DCNTL
) |
369 if (sc
->features
& SF_PCI_WRI
)
370 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST3
,
371 bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST3
) |
374 int ctest5
= bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
,
376 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST4
,
377 bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST4
) &
379 dmode
&= ~DMODE_BL_MASK
;
380 dmode
|= ((sc
->maxburst
- 1) << DMODE_BL_SHIFT
) & DMODE_BL_MASK
;
381 ctest5
&= ~CTEST5_BBCK
;
382 ctest5
|= (sc
->maxburst
- 1) & CTEST5_BBCK
;
383 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST5
, ctest5
);
385 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST4
,
386 bus_space_read_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_CTEST4
) |
389 bus_space_write_1(sc
->sc_rt
, sc
->sc_rh
, SIOP_DMODE
, dmode
);