adw_pci.c revision 1.1 1 /* $NetBSD: adw_pci.c,v 1.1 1998/09/26 16:09:32 dante Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5 *
6 * Author: Baldassare Dante Profeta <dante (at) mclink.it>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the NetBSD
19 * Foundation, Inc. and its contributors.
20 * 4. Neither the name of The NetBSD Foundation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Device probe and attach routines for the following
38 * Advanced Systems Inc. SCSI controllers:
39 *
40 * Single Channel Products:
41 * ABP940UW - Bus-Master PCI Ultra-Wide (240 CDB)
42 */
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/queue.h>
50 #include <sys/device.h>
51
52 #include <machine/bus.h>
53 #include <machine/intr.h>
54
55 #include <dev/scsipi/scsi_all.h>
56 #include <dev/scsipi/scsipi_all.h>
57 #include <dev/scsipi/scsiconf.h>
58
59 #include <dev/pci/pcireg.h>
60 #include <dev/pci/pcivar.h>
61 #include <dev/pci/pcidevs.h>
62
63 #include <dev/ic/adwlib.h>
64 #include <dev/ic/adw.h>
65
66 /******************************************************************************/
67
68 #define PCI_BASEADR_IO 0x10
69
70 /******************************************************************************/
71
72 int adw_pci_match __P((struct device *, struct cfdata *, void *));
73 void adw_pci_attach __P((struct device *, struct device *, void *));
74
75 struct cfattach adw_pci_ca =
76 {
77 sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach
78 };
79
80 /******************************************************************************/
81 /*
82 * Check the slots looking for a board we recognise
83 * If we find one, note it's address (slot) and call
84 * the actual probe routine to check it out.
85 */
86 int
87 adw_pci_match(parent, match, aux)
88 struct device *parent;
89 struct cfdata *match;
90 void *aux;
91 {
92 struct pci_attach_args *pa = aux;
93
94 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
95 switch (PCI_PRODUCT(pa->pa_id)) {
96 case PCI_PRODUCT_ADVSYS_WIDE:
97 return (1);
98 }
99
100 return 0;
101 }
102
103
104 void
105 adw_pci_attach(parent, self, aux)
106 struct device *parent, *self;
107 void *aux;
108 {
109 struct pci_attach_args *pa = aux;
110 ADW_SOFTC *sc = (void *) self;
111 bus_space_tag_t iot;
112 bus_space_handle_t ioh;
113 pci_intr_handle_t ih;
114 pci_chipset_tag_t pc = pa->pa_pc;
115 u_int32_t command;
116 const char *intrstr;
117
118
119 sc->sc_flags = 0x0;
120 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
121 switch (PCI_PRODUCT(pa->pa_id)) {
122 case PCI_PRODUCT_ADVSYS_WIDE:
123 sc->sc_flags |= ADW_WIDE_BOARD;
124 printf(": AdvanSys ABP-9xxUW SCSI adapter\n");
125 break;
126
127 default:
128 printf(": unknown model!\n");
129 return;
130 }
131
132
133 /*
134 * Make sure IO/MEM/MASTER are enabled
135 */
136 command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
137 if ((command & (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
138 PCI_COMMAND_MASTER_ENABLE)) !=
139 (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
140 PCI_COMMAND_MASTER_ENABLE)) {
141 pci_conf_write(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 }
145
146 /*
147 * Latency timer settings.
148 */
149 {
150 u_int32_t bhlcr;
151
152 bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
153
154 if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) &&
155 (PCI_LATTIMER(bhlcr) < 0x20)) {
156 bhlcr &= 0xFFFF00FFul;
157 bhlcr |= 0x00002000ul;
158 pci_conf_write(pa->pa_pc, pa->pa_tag,
159 PCI_BHLC_REG, bhlcr);
160 }
161 }
162
163
164 if((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_WIDE) &&
165 (command & PCI_COMMAND_PARITY_ENABLE) == 0) {
166 sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
167 }
168
169
170
171 /*
172 * Map Device Registers for I/O
173 */
174 if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
175 &iot, &ioh, NULL, NULL)) {
176 printf("%s: unable to map device registers\n",
177 sc->sc_dev.dv_xname);
178 return;
179 }
180 sc->sc_iot = iot;
181 sc->sc_ioh = ioh;
182 sc->sc_dmat = pa->pa_dmat;
183
184 /*
185 * Initialize the board
186 */
187 if (adw_init(sc))
188 panic("adw_pci_attach: adw_init failed");
189
190 /*
191 * Map Interrupt line
192 */
193 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
194 pa->pa_intrline, &ih)) {
195 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
196 return;
197 }
198 intrstr = pci_intr_string(pc, ih);
199
200 /*
201 * Establish Interrupt handler
202 */
203 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc);
204 if (sc->sc_ih == NULL) {
205 printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
206 if (intrstr != NULL)
207 printf(" at %s", intrstr);
208 printf("\n");
209 return;
210 }
211 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
212
213 /*
214 * Attach all the sub-devices we can find
215 */
216 adw_attach(sc);
217 }
218 /******************************************************************************/
219