xref: /openbsd-src/sys/dev/pci/adv_pci.c (revision d0fc3bb68efd6c434b4053cd7adb29023cbec341)
1 /*	$OpenBSD: adv_pci.c,v 1.14 2021/03/05 12:40:13 jsg 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/param.h>
59 #include <sys/systm.h>
60 #include <sys/malloc.h>
61 #include <sys/kernel.h>
62 #include <sys/queue.h>
63 #include <sys/device.h>
64 
65 #include <machine/bus.h>
66 #include <machine/intr.h>
67 
68 #include <scsi/scsi_all.h>
69 #include <scsi/scsiconf.h>
70 
71 #include <dev/pci/pcireg.h>
72 #include <dev/pci/pcivar.h>
73 #include <dev/pci/pcidevs.h>
74 
75 #include <dev/ic/adv.h>
76 #include <dev/ic/advlib.h>
77 
78 /******************************************************************************/
79 
80 #define PCI_CBIO        0x10
81 
82 /******************************************************************************/
83 
84 int	adv_pci_match(struct device *, void *, void *);
85 void	adv_pci_attach(struct device *, struct device *, void *);
86 
87 struct cfattach adv_pci_ca =
88 {
89 	sizeof(ASC_SOFTC), adv_pci_match, adv_pci_attach
90 };
91 
92 const struct pci_matchid adv_pci_devices[] = {
93 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200A },
94 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_1200B },
95 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_ULTRA },
96 };
97 
98 /******************************************************************************/
99 /*
100  * Check the slots looking for a board we recognise
101  * If we find one, note its address (slot) and call
102  * the actual probe routine to check it out.
103  */
104 int
105 adv_pci_match(struct device *parent, void *match, void *aux)
106 {
107 	return (pci_matchbyid((struct pci_attach_args *)aux, adv_pci_devices,
108 	    nitems(adv_pci_devices)));
109 }
110 
111 
112 void
113 adv_pci_attach(struct device *parent, struct device *self, void *aux)
114 {
115 	struct pci_attach_args *pa = aux;
116 	ASC_SOFTC      *sc = (void *) self;
117 	bus_space_handle_t ioh;
118 	bus_size_t advsize;
119 	pci_intr_handle_t ih;
120 	pci_chipset_tag_t pc = pa->pa_pc;
121 	const char     *intrstr;
122 	int retval;
123 
124 	sc->sc_flags = 0x0;
125 
126 	/*
127 	 * Latency timer settings.
128 	 */
129 	{
130 		u_int32_t       bhlcr;
131 
132 		bhlcr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
133 
134 		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200A ||
135 		    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_1200B) {
136 			bhlcr &= 0xFFFF00FFul;
137 			pci_conf_write(pa->pa_pc, pa->pa_tag,
138 					PCI_BHLC_REG, bhlcr);
139 		} else if ((PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ADVSYS_ULTRA) &&
140 			   (PCI_LATTIMER(bhlcr) < 0x20)) {
141 			bhlcr &= 0xFFFF00FFul;
142 			bhlcr |= 0x00002000ul;
143 			pci_conf_write(pa->pa_pc, pa->pa_tag,
144 					PCI_BHLC_REG, bhlcr);
145 		}
146 	}
147 
148 
149 	/*
150 	 * Map Device Registers for I/O
151 	 */
152 	retval = pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
153 	    &sc->sc_iot, &ioh, NULL, &advsize, 0);
154 	if (retval) {
155 		printf(": unable to map device registers\n");
156 		return;
157 	}
158 	sc->sc_ioh = ioh;
159 	sc->sc_dmat = pa->pa_dmat;
160 	sc->pci_device_id = pa->pa_id;
161 	sc->bus_type = ASC_IS_PCI;
162 
163 	/*
164 	 * Initialize the board
165 	 */
166 	if (adv_init(sc)) {
167 		printf(": adv_init failed\n");
168 		bus_space_unmap(sc->sc_iot, ioh, advsize);
169 		return;
170 	}
171 
172 	/*
173 	 * Map Interrupt line
174 	 */
175 	if (pci_intr_map(pa, &ih)) {
176 		printf(": couldn't map interrupt\n");
177 		bus_space_unmap(sc->sc_iot, ioh, advsize);
178 		return;
179 	}
180 	intrstr = pci_intr_string(pc, ih);
181 
182 	/*
183 	 * Establish Interrupt handler
184 	 */
185 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adv_intr, sc,
186 				       sc->sc_dev.dv_xname);
187 	if (sc->sc_ih == NULL) {
188 		printf(": couldn't establish interrupt");
189 		if (intrstr != NULL)
190 			printf(" at %s", intrstr);
191 		printf("\n");
192 		bus_space_unmap(sc->sc_iot, ioh, advsize);
193 		return;
194 	}
195 	printf(": %s\n", intrstr);
196 
197 	/*
198 	 * Attach all the sub-devices we can find
199 	 */
200 	adv_attach(sc);
201 }
202 /******************************************************************************/
203