xref: /openbsd-src/sys/dev/pci/adv_pci.c (revision db3296cf5c1dd9058ceecc3a29fe4aaa0bd26000)
1 /*	$OpenBSD: adv_pci.c,v 1.7 2002/11/19 18:40:16 jason 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(struct device *, void *, void *);
93 void	adv_pci_attach(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 const struct pci_matchid adv_pci_devices[] = {
101 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200A },
102 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200B },
103 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_ULTRA },
104 };
105 
106 /******************************************************************************/
107 /*
108  * Check the slots looking for a board we recognise
109  * If we find one, note it's address (slot) and call
110  * the actual probe routine to check it out.
111  */
112 int
113 adv_pci_match(parent, match, aux)
114 	struct device *parent;
115 	void *match, *aux;
116 {
117 	return (pci_matchbyid((struct pci_attach_args *)aux, adv_pci_devices,
118 	    sizeof(adv_pci_devices)/sizeof(adv_pci_devices[0])));
119 }
120 
121 
122 void
123 adv_pci_attach(parent, self, aux)
124 	struct device *parent, *self;
125 	void *aux;
126 {
127 	struct pci_attach_args *pa = aux;
128 	ASC_SOFTC      *sc = (void *) self;
129 	bus_space_handle_t ioh;
130 	bus_addr_t advbase;
131 	bus_size_t advsize;
132 	pci_intr_handle_t ih;
133 	pci_chipset_tag_t pc = pa->pa_pc;
134 	const char     *intrstr;
135 	int retval;
136 
137 	sc->sc_flags = 0x0;
138 
139 	/*
140 	 * Latency timer settings.
141 	 */
142 	{
143 		u_int32_t       bhlcr;
144 
145 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
146 
147 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A ||
148 		    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) {
149 			bhlcr &= 0xFFFF00FFul;
150 			pci_conf_write(pa->pa_pc, pa->pa_tag,
151 					PCI_BHLC_REG, bhlcr);
152 		} else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) &&
153 			   (PCI_LATTIMER(bhlcr) < 0x20)) {
154 			bhlcr &= 0xFFFF00FFul;
155 			bhlcr |= 0x00002000ul;
156 			pci_conf_write(pa->pa_pc, pa->pa_tag,
157 					PCI_BHLC_REG, bhlcr);
158 		}
159 	}
160 
161 
162 	/*
163 	 * Map Device Registers for I/O
164 	 */
165 	retval = pci_io_find(pc, pa->pa_tag, PCI_CBIO, &advbase, &advsize);
166 	if (retval == 0)
167 		retval = bus_space_map(pa->pa_iot, advbase, advsize, 0, &ioh);
168 	if (retval) {
169 		printf("\n%s: unable to map device registers\n",
170 		       sc->sc_dev.dv_xname);
171 		return;
172 	}
173 	sc->sc_iot = pa->pa_iot;
174 	sc->sc_ioh = ioh;
175 	sc->sc_dmat = pa->pa_dmat;
176 	sc->pci_device_id = pa->pa_id;
177 	sc->bus_type = ASC_IS_PCI;
178 
179 	/*
180 	 * Initialize the board
181 	 */
182 	if (adv_init(sc))
183 		panic("adv_pci_attach: adv_init failed");
184 
185 	/*
186 	 * Map Interrupt line
187 	 */
188 	if (pci_intr_map(pa, &ih)) {
189 		printf("\n%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
190 		return;
191 	}
192 	intrstr = pci_intr_string(pc, ih);
193 
194 	/*
195 	 * Establish Interrupt handler
196 	 */
197 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc,
198 				       sc->sc_dev.dv_xname);
199 	if (sc->sc_ih == NULL) {
200 		printf("\n%s: couldn't establish interrupt",
201 		       sc->sc_dev.dv_xname);
202 		if (intrstr != NULL)
203 			printf(" at %s", intrstr);
204 		printf("\n");
205 		return;
206 	}
207 	printf(": %s\n", intrstr);
208 
209 	/*
210 	 * Attach all the sub-devices we can find
211 	 */
212 	adv_attach(sc);
213 }
214 /******************************************************************************/
215