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