adv_pci.c revision 1.1 1 1.1 dante /*
2 1.1 dante * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
3 1.1 dante *
4 1.1 dante * Author: Baldassare Dante Profeta <dante (at) mclink.it>
5 1.1 dante *
6 1.1 dante * Redistribution and use in source and binary forms, with or without
7 1.1 dante * modification, are permitted provided that the following conditions are
8 1.1 dante * met: 1. Redistributions of source code must retain the above copyright
9 1.1 dante * notice, this list of conditions and the following disclaimer. 2.
10 1.1 dante * Redistributions in binary form must reproduce the above copyright notice,
11 1.1 dante * this list of conditions and the following disclaimer in the documentation
12 1.1 dante * and/or other materials provided with the distribution. 3. All advertising
13 1.1 dante * materials mentioning features or use of this software must display the
14 1.1 dante * following acknowledgement: This product includes software developed by the
15 1.1 dante * NetBSD Foundation, Inc. and its contributors. 4. Neither the name of The
16 1.1 dante * NetBSD Foundation nor the names of its contributors may be used to endorse
17 1.1 dante * or promote products derived from this software without specific prior
18 1.1 dante * written permission.
19 1.1 dante *
20 1.1 dante * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 dante * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 1.1 dante * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.1 dante * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24 1.1 dante * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 1.1 dante * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.1 dante * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 1.1 dante * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 1.1 dante * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 1.1 dante * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 1.1 dante * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 dante */
32 1.1 dante /*
33 1.1 dante * Device probe and attach routines for the following
34 1.1 dante * Advanced Systems Inc. SCSI controllers:
35 1.1 dante *
36 1.1 dante * Connectivity Products:
37 1.1 dante * ABP510/5150 - Bus-Master ISA (240 CDB) (Footnote 1)
38 1.1 dante * ABP5140 - Bus-Master ISA PnP (16 CDB) (Footnote 1, 3)
39 1.1 dante * ABP5142 - Bus-Master ISA PnP with floppy (16 CDB) (Footnote 4)
40 1.1 dante * ABP920 - Bus-Master PCI (16 CDB)
41 1.1 dante * ABP930 - Bus-Master PCI (16 CDB) (Footnote 5)
42 1.1 dante * ABP930U - Bus-Master PCI Ultra (16 CDB)
43 1.1 dante * ABP930UA - Bus-Master PCI Ultra (16 CDB)
44 1.1 dante * ABP960 - Bus-Master PCI MAC/PC (16 CDB) (Footnote 2)
45 1.1 dante * ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB) (Footnote 2)
46 1.1 dante *
47 1.1 dante * Single Channel Products:
48 1.1 dante * ABP542 - Bus-Master ISA with floppy (240 CDB)
49 1.1 dante * ABP742 - Bus-Master EISA (240 CDB)
50 1.1 dante * ABP842 - Bus-Master VL (240 CDB)
51 1.1 dante * ABP940 - Bus-Master PCI (240 CDB)
52 1.1 dante * ABP940U - Bus-Master PCI Ultra (240 CDB)
53 1.1 dante * ABP970 - Bus-Master PCI MAC/PC (240 CDB)
54 1.1 dante * ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB)
55 1.1 dante * ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
56 1.1 dante *
57 1.1 dante * Multi Channel Products:
58 1.1 dante * ABP752 - Dual Channel Bus-Master EISA (240 CDB Per Channel)
59 1.1 dante * ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
60 1.1 dante * ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel)
61 1.1 dante * ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel)
62 1.1 dante * ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel)
63 1.1 dante *
64 1.1 dante * Footnotes:
65 1.1 dante * 1. This board has been shipped by HP with the 4020i CD-R drive.
66 1.1 dante * The board has no BIOS so it cannot control a boot device, but
67 1.1 dante * it can control any secondary SCSI device.
68 1.1 dante * 2. This board has been sold by Iomega as a Jaz Jet PCI adapter.
69 1.1 dante * 3. This board has been sold by SIIG as the i540 SpeedMaster.
70 1.1 dante * 4. This board has been sold by SIIG as the i542 SpeedMaster.
71 1.1 dante * 5. This board has been sold by SIIG as the Fast SCSI Pro PCI.
72 1.1 dante *
73 1.1 dante */
74 1.1 dante
75 1.1 dante #include <sys/types.h>
76 1.1 dante #include <sys/param.h>
77 1.1 dante #include <sys/systm.h>
78 1.1 dante #include <sys/malloc.h>
79 1.1 dante #include <sys/kernel.h>
80 1.1 dante #include <sys/queue.h>
81 1.1 dante #include <sys/device.h>
82 1.1 dante
83 1.1 dante #include <machine/bus.h>
84 1.1 dante #include <machine/intr.h>
85 1.1 dante
86 1.1 dante #include <dev/scsipi/scsi_all.h>
87 1.1 dante #include <dev/scsipi/scsipi_all.h>
88 1.1 dante #include <dev/scsipi/scsiconf.h>
89 1.1 dante
90 1.1 dante #include <dev/pci/pcireg.h>
91 1.1 dante #include <dev/pci/pcivar.h>
92 1.1 dante #include <dev/pci/pcidevs.h>
93 1.1 dante
94 1.1 dante #include <dev/ic/adv.h>
95 1.1 dante #include <dev/ic/advlib.h>
96 1.1 dante
97 1.1 dante /******************************************************************************/
98 1.1 dante
99 1.1 dante #define PCI_BASEADR_IO 0x10
100 1.1 dante
101 1.1 dante /******************************************************************************/
102 1.1 dante
103 1.1 dante #ifdef __BROKEN_INDIRECT_CONFIG
104 1.1 dante int adv_pci_probe __P((struct device *, void *, void *));
105 1.1 dante #else
106 1.1 dante int adv_pci_probe __P((struct device *, struct cfdata *, void *));
107 1.1 dante #endif
108 1.1 dante void adv_pci_attach __P((struct device *, struct device *, void *));
109 1.1 dante
110 1.1 dante struct cfattach adv_pci_ca =
111 1.1 dante {
112 1.1 dante sizeof(ASC_SOFTC), adv_pci_probe, adv_pci_attach
113 1.1 dante };
114 1.1 dante
115 1.1 dante /******************************************************************************/
116 1.1 dante /*
117 1.1 dante * Check the slots looking for a board we recognise
118 1.1 dante * If we find one, note it's address (slot) and call
119 1.1 dante * the actual probe routine to check it out.
120 1.1 dante */
121 1.1 dante #ifdef __BROKEN_INDIRECT_CONFIG
122 1.1 dante int
123 1.1 dante adv_pci_probe(struct device * parent, void *match, void *aux)
124 1.1 dante #else
125 1.1 dante int
126 1.1 dante adv_pci_probe(struct device * parent, struct cfdata * match, void *aux)
127 1.1 dante #endif
128 1.1 dante {
129 1.1 dante struct pci_attach_args *pa = aux;
130 1.1 dante
131 1.1 dante if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
132 1.1 dante switch (PCI_PRODUCT(pa->pa_id)) {
133 1.1 dante case PCI_PRODUCT_ADVSYS_1200A:
134 1.1 dante case PCI_PRODUCT_ADVSYS_1200B:
135 1.1 dante case PCI_PRODUCT_ADVSYS_ULTRA:
136 1.1 dante return (1);
137 1.1 dante case PCI_PRODUCT_ADVSYS_2300:
138 1.1 dante return (0);
139 1.1 dante }
140 1.1 dante
141 1.1 dante return 0;
142 1.1 dante }
143 1.1 dante
144 1.1 dante
145 1.1 dante void
146 1.1 dante adv_pci_attach(struct device * parent, struct device * self, void *aux)
147 1.1 dante {
148 1.1 dante struct pci_attach_args *pa = aux;
149 1.1 dante ASC_SOFTC *sc = (void *) self;
150 1.1 dante bus_space_tag_t iot;
151 1.1 dante bus_space_handle_t ioh;
152 1.1 dante pci_intr_handle_t ih;
153 1.1 dante pci_chipset_tag_t pc = pa->pa_pc;
154 1.1 dante u_int32_t command;
155 1.1 dante const char *intrstr;
156 1.1 dante
157 1.1 dante
158 1.1 dante sc->sc_flags = 0x0;
159 1.1 dante if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
160 1.1 dante switch (PCI_PRODUCT(pa->pa_id)) {
161 1.1 dante case PCI_PRODUCT_ADVSYS_1200A:
162 1.1 dante printf(": AdvanSys ASC1200A SCSI\n");
163 1.1 dante break;
164 1.1 dante
165 1.1 dante case PCI_PRODUCT_ADVSYS_1200B:
166 1.1 dante printf(": AdvanSys ASC1200B SCSI\n");
167 1.1 dante break;
168 1.1 dante
169 1.1 dante case PCI_PRODUCT_ADVSYS_ULTRA:
170 1.1 dante switch (PCI_REVISION(pa->pa_class)) {
171 1.1 dante case ASC_PCI_REVISION_3050:
172 1.1 dante printf(": AdvanSys ASC3150 Ultra SCSI\n");
173 1.1 dante break;
174 1.1 dante
175 1.1 dante case ASC_PCI_REVISION_3150:
176 1.1 dante printf(": AdvanSys ASC3050 Ultra SCSI\n");
177 1.1 dante break;
178 1.1 dante }
179 1.1 dante break;
180 1.1 dante
181 1.1 dante case PCI_PRODUCT_ADVSYS_2300:
182 1.1 dante sc->sc_flags |= ASC_WIDE_BOARD;
183 1.1 dante printf("adv_pci_attach: Wide boards are not"
184 1.1 dante " supported yet");
185 1.1 dante break;
186 1.1 dante
187 1.1 dante default:
188 1.1 dante printf(": unknown model!\n");
189 1.1 dante return;
190 1.1 dante }
191 1.1 dante
192 1.1 dante
193 1.1 dante /*
194 1.1 dante * Make sure IO/MEM/MASTER are enabled
195 1.1 dante */
196 1.1 dante command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
197 1.1 dante if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
198 1.1 dante PCI_COMMAND_MASTER_ENABLE)) !=
199 1.1 dante (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
200 1.1 dante PCI_COMMAND_MASTER_ENABLE)) {
201 1.1 dante pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
202 1.1 dante command | (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
203 1.1 dante PCI_COMMAND_MASTER_ENABLE));
204 1.1 dante }
205 1.1 dante /*
206 1.1 dante * Latency timer settings.
207 1.1 dante */
208 1.1 dante {
209 1.1 dante u_int32_t bhlcr;
210 1.1 dante
211 1.1 dante bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
212 1.1 dante
213 1.1 dante if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A ||
214 1.1 dante PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) {
215 1.1 dante bhlcr &= 0xFFFF00FFul;
216 1.1 dante pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, bhlcr);
217 1.1 dante } else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) &&
218 1.1 dante (PCI_LATTIMER(bhlcr) < 0x20)) {
219 1.1 dante bhlcr &= 0xFFFF00FFul;
220 1.1 dante bhlcr |= 0x00002000ul;
221 1.1 dante pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, bhlcr);
222 1.1 dante }
223 1.1 dante }
224 1.1 dante
225 1.1 dante
226 1.1 dante /*
227 1.1 dante * Map Device Registers for I/O
228 1.1 dante */
229 1.1 dante if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
230 1.1 dante &iot, &ioh, NULL, NULL)) {
231 1.1 dante printf("%s: unable to map device registers\n",
232 1.1 dante sc->sc_dev.dv_xname);
233 1.1 dante return;
234 1.1 dante }
235 1.1 dante sc->sc_iot = iot;
236 1.1 dante sc->sc_ioh = ioh;
237 1.1 dante sc->sc_dmat = pa->pa_dmat;
238 1.1 dante sc->pci_device_id = pa->pa_id;
239 1.1 dante sc->bus_type = ASC_IS_PCI;
240 1.1 dante
241 1.1 dante /*
242 1.1 dante * Initialize the board
243 1.1 dante */
244 1.1 dante if (adv_init(sc))
245 1.1 dante panic("adv_pci_attach: adv_init failed");
246 1.1 dante
247 1.1 dante /*
248 1.1 dante * Map Interrupt line
249 1.1 dante */
250 1.1 dante if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
251 1.1 dante pa->pa_intrline, &ih)) {
252 1.1 dante printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
253 1.1 dante return;
254 1.1 dante }
255 1.1 dante intrstr = pci_intr_string(pc, ih);
256 1.1 dante
257 1.1 dante /*
258 1.1 dante * Establish Interrupt handler
259 1.1 dante */
260 1.1 dante sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc);
261 1.1 dante if (sc->sc_ih == NULL) {
262 1.1 dante printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
263 1.1 dante if (intrstr != NULL)
264 1.1 dante printf(" at %s", intrstr);
265 1.1 dante printf("\n");
266 1.1 dante return;
267 1.1 dante }
268 1.1 dante printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
269 1.1 dante
270 1.1 dante /*
271 1.1 dante * Attach all the sub-devices we can find
272 1.1 dante */
273 1.1 dante adv_attach(sc);
274 1.1 dante }
275 1.1 dante /******************************************************************************/
276