xref: /openbsd-src/sys/dev/pci/adv_pci.c (revision 62a742911104f98b9185b2c6b6007d9b1c36396c)
1 /*	$OpenBSD: adv_pci.c,v 1.4 1998/11/17 07:55:46 downsj Exp $	*/
2 /*	$NetBSD: adv_pci.c,v 1.5 1998/09/26 15:52:55 dante Exp $	*/
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc. 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  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *        This product includes software developed by the NetBSD
20  *        Foundation, Inc. and its contributors.
21  * 4. Neither the name of The NetBSD Foundation nor the names of its
22  *    contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 /*
38  * Device probe and attach routines for the following
39  * Advanced Systems Inc. SCSI controllers:
40  *
41  *    Connectivity Products:
42  *      ABP920 - Bus-Master PCI (16 CDB)
43  *      ABP930 - Bus-Master PCI (16 CDB)		(Footnote 1)
44  *      ABP930U - Bus-Master PCI Ultra (16 CDB)
45  *      ABP930UA - Bus-Master PCI Ultra (16 CDB)
46  *      ABP960 - Bus-Master PCI MAC/PC (16 CDB)		(Footnote 2)
47  *      ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB)	(Footnote 2)
48  *
49  *   Single Channel Products:
50  *      ABP940 - Bus-Master PCI (240 CDB)
51  *      ABP940U - Bus-Master PCI Ultra (240 CDB)
52  *      ABP970 - Bus-Master PCI MAC/PC (240 CDB)
53  *      ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB)
54  *
55  *   Multi Channel Products:
56  *      ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel)
57  *      ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel)
58  *      ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel)
59  *
60  *   Footnotes:
61  *     1. This board has been sold by SIIG as the Fast SCSI Pro PCI.
62  *     2. This board has been sold by Iomega as a Jaz Jet PCI adapter.
63  */
64 
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/malloc.h>
69 #include <sys/kernel.h>
70 #include <sys/queue.h>
71 #include <sys/device.h>
72 
73 #include <machine/bus.h>
74 #include <machine/intr.h>
75 
76 #include <scsi/scsi_all.h>
77 #include <scsi/scsiconf.h>
78 
79 #include <dev/pci/pcireg.h>
80 #include <dev/pci/pcivar.h>
81 #include <dev/pci/pcidevs.h>
82 
83 #include <dev/ic/adv.h>
84 #include <dev/ic/advlib.h>
85 
86 /******************************************************************************/
87 
88 #define PCI_CBIO        0x10
89 
90 /******************************************************************************/
91 
92 int	adv_pci_match __P((struct device *, void *, void *));
93 void	adv_pci_attach __P((struct device *, struct device *, void *));
94 
95 struct cfattach adv_pci_ca =
96 {
97 	sizeof(ASC_SOFTC), adv_pci_match, adv_pci_attach
98 };
99 
100 /******************************************************************************/
101 /*
102  * Check the slots looking for a board we recognise
103  * If we find one, note it's address (slot) and call
104  * the actual probe routine to check it out.
105  */
106 int
107 adv_pci_match(parent, match, aux)
108 	struct device *parent;
109 	void *match, *aux;
110 {
111 	struct pci_attach_args *pa = aux;
112 
113 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
114 		switch (PCI_PRODUCT(pa->pa_id)) {
115 		case PCI_PRODUCT_ADVSYS_1200A:
116 		case PCI_PRODUCT_ADVSYS_1200B:
117 		case PCI_PRODUCT_ADVSYS_ULTRA:
118 			return (1);
119 		}
120 
121 	return 0;
122 }
123 
124 
125 void
126 adv_pci_attach(parent, self, aux)
127 	struct device *parent, *self;
128 	void *aux;
129 {
130 	struct pci_attach_args *pa = aux;
131 	ASC_SOFTC      *sc = (void *) self;
132 	bus_space_handle_t ioh;
133 	bus_addr_t advbase;
134 	bus_size_t advsize;
135 	pci_intr_handle_t ih;
136 	pci_chipset_tag_t pc = pa->pa_pc;
137 	const char     *intrstr;
138 	int retval;
139 
140 	sc->sc_flags = 0x0;
141 
142 	/*
143 	 * Latency timer settings.
144 	 */
145 	{
146 		u_int32_t       bhlcr;
147 
148 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
149 
150 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A ||
151 		    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) {
152 			bhlcr &= 0xFFFF00FFul;
153 			pci_conf_write(pa->pa_pc, pa->pa_tag,
154 					PCI_BHLC_REG, bhlcr);
155 		} else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) &&
156 			   (PCI_LATTIMER(bhlcr) < 0x20)) {
157 			bhlcr &= 0xFFFF00FFul;
158 			bhlcr |= 0x00002000ul;
159 			pci_conf_write(pa->pa_pc, pa->pa_tag,
160 					PCI_BHLC_REG, bhlcr);
161 		}
162 	}
163 
164 
165 	/*
166 	 * Map Device Registers for I/O
167 	 */
168 	retval = pci_io_find(pc, pa->pa_tag, PCI_CBIO, &advbase, &advsize);
169 	if (retval == 0)
170 		retval = bus_space_map(pa->pa_iot, advbase, advsize, 0, &ioh);
171 	if (retval) {
172 		printf("\n%s: unable to map device registers\n",
173 		       sc->sc_dev.dv_xname);
174 		return;
175 	}
176 	sc->sc_iot = pa->pa_iot;
177 	sc->sc_ioh = ioh;
178 	sc->sc_dmat = pa->pa_dmat;
179 	sc->pci_device_id = pa->pa_id;
180 	sc->bus_type = ASC_IS_PCI;
181 
182 	/*
183 	 * Initialize the board
184 	 */
185 	if (adv_init(sc))
186 		panic("adv_pci_attach: adv_init failed");
187 
188 	/*
189 	 * Map Interrupt line
190 	 */
191 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
192 			 pa->pa_intrline, &ih)) {
193 		printf("\n%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
194 		return;
195 	}
196 	intrstr = pci_intr_string(pc, ih);
197 
198 	/*
199 	 * Establish Interrupt handler
200 	 */
201 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc,
202 				       sc->sc_dev.dv_xname);
203 	if (sc->sc_ih == NULL) {
204 		printf("\n%s: couldn't establish interrupt",
205 		       sc->sc_dev.dv_xname);
206 		if (intrstr != NULL)
207 			printf(" at %s", intrstr);
208 		printf("\n");
209 		return;
210 	}
211 	printf(": %s\n", intrstr);
212 
213 	/*
214 	 * Attach all the sub-devices we can find
215 	 */
216 	adv_attach(sc);
217 }
218 /******************************************************************************/
219