xref: /openbsd-src/sys/dev/pci/adw_pci.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: adw_pci.c,v 1.17 2015/03/14 03:38:48 jsg Exp $ */
2 /* $NetBSD: adw_pci.c,v 1.7 2000/05/26 15:13:46 dante Exp $	 */
3 
4 /*
5  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * Author: Baldassare Dante Profeta <dante@mclink.it>
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*
32  * Device probe and attach routines for the following
33  * Advanced Systems Inc. SCSI controllers:
34  *
35  *      ABP-940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
36  *	ABP-940UW (68)	- Bus-Master PCI Ultra-Wide (253 CDB)
37  *	ABP-940UWD	- Bus-Master PCI Ultra-Wide (253 CDB)
38  *	ABP-970UW	- Bus-Master PCI Ultra-Wide (253 CDB)
39  *	ASB-3940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
40  *	ASB-3940U2W-00	- Bus-Master PCI Ultra2-Wide (253 CDB)
41  *	ASB-3940U3W-00	- Bus-Master PCI Ultra3-Wide (253 CDB)
42  */
43 
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/queue.h>
50 #include <sys/device.h>
51 #include <sys/timeout.h>
52 
53 #include <machine/bus.h>
54 
55 #include <scsi/scsi_all.h>
56 #include <scsi/scsiconf.h>
57 
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
60 #include <dev/pci/pcidevs.h>
61 
62 #include <dev/ic/adwlib.h>
63 #include <dev/microcode/adw/adwmcode.h>
64 #include <dev/ic/adw.h>
65 
66 /******************************************************************************/
67 
68 #define PCI_BASEADR_IO        0x10
69 
70 /******************************************************************************/
71 
72 int adw_pci_match(struct device *, void *, void *);
73 void adw_pci_attach(struct device *, struct device *, void *);
74 
75 struct cfattach adw_pci_ca =
76 {
77 	sizeof(ADW_SOFTC), adw_pci_match, adw_pci_attach
78 };
79 
80 const struct pci_matchid adw_pci_devices[] = {
81 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_WIDE },
82 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_U2W },
83 	{ PCI_VENDOR_ADVSYS, PCI_PRODUCT_ADVSYS_U3W },
84 };
85 
86 /******************************************************************************/
87 /*
88  * Check the slots looking for a board we recognise
89  * If we find one, note its address (slot) and call
90  * the actual probe routine to check it out.
91  */
92 int
93 adw_pci_match(parent, match, aux)
94 	struct device  *parent;
95 	void           *match;
96 	void           *aux;
97 {
98 	return (pci_matchbyid((struct pci_attach_args *)aux, adw_pci_devices,
99 	    nitems(adw_pci_devices)));
100 }
101 
102 
103 void
104 adw_pci_attach(parent, self, aux)
105 	struct device  *parent, *self;
106 	void           *aux;
107 {
108 	struct pci_attach_args *pa = aux;
109 	ADW_SOFTC      *sc = (void *) self;
110 	bus_space_tag_t iot;
111 	bus_space_handle_t ioh;
112 	pci_intr_handle_t ih;
113 	pci_chipset_tag_t pc = pa->pa_pc;
114 	pcireg_t	command;
115 	const char     *intrstr;
116 
117 	/*
118 	 * Set chip type
119 	 */
120 	switch (PCI_PRODUCT(pa->pa_id)) {
121 	case PCI_PRODUCT_ADVSYS_WIDE:
122 		sc->chip_type = ADW_CHIP_ASC3550;
123 		break;
124 
125 	case PCI_PRODUCT_ADVSYS_U2W:
126 		sc->chip_type = ADW_CHIP_ASC38C0800;
127 		break;
128 
129 	case PCI_PRODUCT_ADVSYS_U3W:
130 		sc->chip_type = ADW_CHIP_ASC38C1600;
131 		break;
132 
133 	default:
134 		printf("\n%s: unknown model: %d\n", sc->sc_dev.dv_xname,
135 		       PCI_PRODUCT(pa->pa_id));
136 		return;
137 	}
138 
139 	command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
140 	if ( (command & PCI_COMMAND_PARITY_ENABLE) == 0)
141 		sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
142 
143 	/*
144 	 * Map Device Registers for I/O
145 	 */
146 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
147 			   &iot, &ioh, NULL, NULL, 0)) {
148 		printf("\n%s: unable to map device registers\n",
149 		       sc->sc_dev.dv_xname);
150 		return;
151 	}
152 	sc->sc_iot = iot;
153 	sc->sc_ioh = ioh;
154 	sc->sc_dmat = pa->pa_dmat;
155 
156 	/*
157 	 * Initialize the board
158 	 */
159 	if (adw_init(sc)) {
160 		printf("%s: adw_init failed", sc->sc_dev.dv_xname);
161 		return;
162 	}
163 
164 	/*
165 	 * Map Interrupt line
166 	 */
167 	if (pci_intr_map(pa, &ih)) {
168 		printf("\n%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
169 		return;
170 	}
171 	intrstr = pci_intr_string(pc, ih);
172 
173 	/*
174 	 * Establish Interrupt handler
175 	 */
176 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc,
177 				       sc->sc_dev.dv_xname);
178 	if (sc->sc_ih == NULL) {
179 		printf("\n%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
180 		if (intrstr != NULL)
181 			printf(" at %s", intrstr);
182 		printf("\n");
183 		return;
184 	}
185 	printf(": %s\n", intrstr);
186 
187 	/*
188 	 * Attach all the sub-devices we can find
189 	 */
190 	adw_attach(sc);
191 }
192 /******************************************************************************/
193