1 | /* $NetBSD: adw_pci.c,v 1.28 2014/10/18 08:33:28 snj Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * Author: Baldassare Dante Profeta <dante@mclink.it> |
8 | * |
9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions |
11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
20 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | * POSSIBILITY OF SUCH DAMAGE. |
29 | */ |
30 | /* |
31 | * Device probe and attach routines for the following |
32 | * Advanced Systems Inc. SCSI controllers: |
33 | * |
34 | * ABP-940UW - Bus-Master PCI Ultra-Wide (253 CDB) |
35 | * ABP-940UW (68) - Bus-Master PCI Ultra-Wide (253 CDB) |
36 | * ABP-940UWD - Bus-Master PCI Ultra-Wide (253 CDB) |
37 | * ABP-970UW - Bus-Master PCI Ultra-Wide (253 CDB) |
38 | * ASB-3940UW - Bus-Master PCI Ultra-Wide (253 CDB) |
39 | * ASB-3940U2W-00 - Bus-Master PCI Ultra2-Wide (253 CDB) |
40 | * ASB-3940U3W-00 - Bus-Master PCI Ultra3-Wide (253 CDB) |
41 | */ |
42 | |
43 | #include <sys/cdefs.h> |
44 | __KERNEL_RCSID(0, "$NetBSD: adw_pci.c,v 1.28 2014/10/18 08:33:28 snj Exp $" ); |
45 | |
46 | #include <sys/param.h> |
47 | #include <sys/systm.h> |
48 | #include <sys/malloc.h> |
49 | #include <sys/kernel.h> |
50 | #include <sys/queue.h> |
51 | #include <sys/device.h> |
52 | |
53 | #include <sys/bus.h> |
54 | #include <sys/intr.h> |
55 | |
56 | #include <dev/scsipi/scsi_all.h> |
57 | #include <dev/scsipi/scsipi_all.h> |
58 | #include <dev/scsipi/scsiconf.h> |
59 | |
60 | #include <dev/pci/pcireg.h> |
61 | #include <dev/pci/pcivar.h> |
62 | #include <dev/pci/pcidevs.h> |
63 | |
64 | #include <dev/ic/adwlib.h> |
65 | #include <dev/ic/adwmcode.h> |
66 | #include <dev/ic/adw.h> |
67 | |
68 | /******************************************************************************/ |
69 | |
70 | #define PCI_BASEADR_IO 0x10 |
71 | |
72 | /******************************************************************************/ |
73 | /* |
74 | * Check the slots looking for a board we recognise |
75 | * If we find one, note its address (slot) and call |
76 | * the actual probe routine to check it out. |
77 | */ |
78 | static int |
79 | adw_pci_match(device_t parent, cfdata_t match, void *aux) |
80 | { |
81 | struct pci_attach_args *pa = aux; |
82 | |
83 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS) |
84 | switch (PCI_PRODUCT(pa->pa_id)) { |
85 | case PCI_PRODUCT_ADVSYS_WIDE: |
86 | case PCI_PRODUCT_ADVSYS_U2W: |
87 | case PCI_PRODUCT_ADVSYS_U3W: |
88 | return (1); |
89 | } |
90 | |
91 | return 0; |
92 | } |
93 | |
94 | |
95 | static void |
96 | adw_pci_attach(device_t parent, device_t self, void *aux) |
97 | { |
98 | struct pci_attach_args *pa = aux; |
99 | ADW_SOFTC *sc = device_private(self); |
100 | bus_space_tag_t iot; |
101 | bus_space_handle_t ioh; |
102 | pci_intr_handle_t ih; |
103 | pci_chipset_tag_t pc = pa->pa_pc; |
104 | u_int32_t command; |
105 | const char *intrstr; |
106 | char intrbuf[PCI_INTRSTR_LEN]; |
107 | |
108 | sc->sc_dev = self; |
109 | |
110 | aprint_naive(": SCSI controller\n" ); |
111 | |
112 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS) |
113 | switch (PCI_PRODUCT(pa->pa_id)) { |
114 | case PCI_PRODUCT_ADVSYS_WIDE: |
115 | sc->chip_type = ADW_CHIP_ASC3550; |
116 | aprint_normal( |
117 | ": AdvanSys ASB-3940UW-00 SCSI adapter\n" ); |
118 | break; |
119 | |
120 | case PCI_PRODUCT_ADVSYS_U2W: |
121 | sc->chip_type = ADW_CHIP_ASC38C0800; |
122 | aprint_normal( |
123 | ": AdvanSys ASB-3940U2W-00 SCSI adapter\n" ); |
124 | break; |
125 | |
126 | case PCI_PRODUCT_ADVSYS_U3W: |
127 | sc->chip_type = ADW_CHIP_ASC38C1600; |
128 | aprint_normal( |
129 | ": AdvanSys ASB-3940U3W-00 SCSI adapter\n" ); |
130 | break; |
131 | |
132 | default: |
133 | aprint_error(": unknown model!\n" ); |
134 | return; |
135 | } |
136 | |
137 | |
138 | /* |
139 | * Make sure IO/MEM/MASTER are enabled |
140 | */ |
141 | command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); |
142 | command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE | |
143 | PCI_COMMAND_MASTER_ENABLE; |
144 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); |
145 | |
146 | if ( (command & PCI_COMMAND_PARITY_ENABLE) == 0) { |
147 | sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR; |
148 | } |
149 | /* |
150 | * Map Device Registers for I/O |
151 | */ |
152 | if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0, |
153 | &iot, &ioh, NULL, NULL)) { |
154 | aprint_error_dev(self, "unable to map device registers\n" ); |
155 | return; |
156 | } |
157 | sc->sc_iot = iot; |
158 | sc->sc_ioh = ioh; |
159 | sc->sc_dmat = pa->pa_dmat; |
160 | |
161 | /* |
162 | * Initialize the board |
163 | */ |
164 | if (adw_init(sc)) { |
165 | aprint_error_dev(self, "adw_init failed" ); |
166 | return; |
167 | } |
168 | |
169 | /* |
170 | * Map Interrupt line |
171 | */ |
172 | if (pci_intr_map(pa, &ih)) { |
173 | aprint_error_dev(self, "couldn't map interrupt\n" ); |
174 | return; |
175 | } |
176 | intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf)); |
177 | |
178 | /* |
179 | * Establish Interrupt handler |
180 | */ |
181 | sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc); |
182 | if (sc->sc_ih == NULL) { |
183 | aprint_error_dev(self, "couldn't establish interrupt" ); |
184 | if (intrstr != NULL) |
185 | aprint_error(" at %s" , intrstr); |
186 | aprint_error("\n" ); |
187 | return; |
188 | } |
189 | aprint_normal_dev(self, "interrupting at %s\n" , intrstr); |
190 | |
191 | /* |
192 | * Attach all the sub-devices we can find |
193 | */ |
194 | adw_attach(sc); |
195 | } |
196 | |
197 | CFATTACH_DECL_NEW(adw_pci, sizeof(ADW_SOFTC), |
198 | adw_pci_match, adw_pci_attach, NULL, NULL); |
199 | |