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