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