xref: /netbsd-src/sys/dev/pci/adw_pci.c (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /* $NetBSD: adw_pci.c,v 1.17 2005/12/11 12:22:48 christos Exp $	 */
2 
3 /*
4  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
5  * 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  *      ABP-940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
42  *	ABP-940UW (68)	- Bus-Master PCI Ultra-Wide (253 CDB)
43  *	ABP-940UWD	- Bus-Master PCI Ultra-Wide (253 CDB)
44  *	ABP-970UW	- Bus-Master PCI Ultra-Wide (253 CDB)
45  *	ASB-3940UW	- Bus-Master PCI Ultra-Wide (253 CDB)
46  *	ASB-3940U2W-00	- Bus-Master PCI Ultra2-Wide (253 CDB)
47  *	ASB-3940U3W-00	- Bus-Master PCI Ultra3-Wide (253 CDB)
48  */
49 
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: adw_pci.c,v 1.17 2005/12/11 12:22:48 christos Exp $");
52 
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/malloc.h>
56 #include <sys/kernel.h>
57 #include <sys/queue.h>
58 #include <sys/device.h>
59 
60 #include <machine/bus.h>
61 #include <machine/intr.h>
62 
63 #include <dev/scsipi/scsi_all.h>
64 #include <dev/scsipi/scsipi_all.h>
65 #include <dev/scsipi/scsiconf.h>
66 
67 #include <dev/pci/pcireg.h>
68 #include <dev/pci/pcivar.h>
69 #include <dev/pci/pcidevs.h>
70 
71 #include <dev/ic/adwlib.h>
72 #include <dev/ic/adwmcode.h>
73 #include <dev/ic/adw.h>
74 
75 /******************************************************************************/
76 
77 #define PCI_BASEADR_IO        0x10
78 
79 /******************************************************************************/
80 /*
81  * Check the slots looking for a board we recognise
82  * If we find one, note it's address (slot) and call
83  * the actual probe routine to check it out.
84  */
85 static int
86 adw_pci_match(struct device *parent, struct cfdata *match, void *aux)
87 {
88 	struct pci_attach_args *pa = aux;
89 
90 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
91 		switch (PCI_PRODUCT(pa->pa_id)) {
92 		case PCI_PRODUCT_ADVSYS_WIDE:
93 		case PCI_PRODUCT_ADVSYS_U2W:
94 		case PCI_PRODUCT_ADVSYS_U3W:
95 			return (1);
96 		}
97 
98 	return 0;
99 }
100 
101 
102 static void
103 adw_pci_attach(struct device *parent, struct device *self, void *aux)
104 {
105 	struct pci_attach_args *pa = aux;
106 	ADW_SOFTC      *sc = (void *) self;
107 	bus_space_tag_t iot;
108 	bus_space_handle_t ioh;
109 	pci_intr_handle_t ih;
110 	pci_chipset_tag_t pc = pa->pa_pc;
111 	u_int32_t       command;
112 	const char     *intrstr;
113 
114 	aprint_naive(": SCSI controller\n");
115 
116 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ADVSYS)
117 		switch (PCI_PRODUCT(pa->pa_id)) {
118 		case PCI_PRODUCT_ADVSYS_WIDE:
119 			sc->chip_type = ADW_CHIP_ASC3550;
120 			aprint_normal(
121 			    ": AdvanSys ASB-3940UW-00 SCSI adapter\n");
122 			break;
123 
124 		case PCI_PRODUCT_ADVSYS_U2W:
125 			sc->chip_type = ADW_CHIP_ASC38C0800;
126 			aprint_normal(
127 			    ": AdvanSys ASB-3940U2W-00 SCSI adapter\n");
128 			break;
129 
130 		case PCI_PRODUCT_ADVSYS_U3W:
131 			sc->chip_type = ADW_CHIP_ASC38C1600;
132 			aprint_normal(
133 			    ": AdvanSys ASB-3940U3W-00 SCSI adapter\n");
134 			break;
135 
136 		default:
137 			aprint_error(": unknown model!\n");
138 			return;
139 		}
140 
141 
142 	/*
143 	 * Make sure IO/MEM/MASTER are enabled
144 	 */
145 	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
146 	command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
147 			PCI_COMMAND_MASTER_ENABLE;
148 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
149 
150 	if ( (command & PCI_COMMAND_PARITY_ENABLE) == 0) {
151 		sc->cfg.control_flag |= CONTROL_FLAG_IGNORE_PERR;
152 	}
153 	/*
154 	 * Map Device Registers for I/O
155 	 */
156 	if (pci_mapreg_map(pa, PCI_BASEADR_IO, PCI_MAPREG_TYPE_IO, 0,
157 			   &iot, &ioh, NULL, NULL)) {
158 		aprint_error("%s: unable to map device registers\n",
159 		       sc->sc_dev.dv_xname);
160 		return;
161 	}
162 	sc->sc_iot = iot;
163 	sc->sc_ioh = ioh;
164 	sc->sc_dmat = pa->pa_dmat;
165 
166 	/*
167 	 * Initialize the board
168 	 */
169 	if (adw_init(sc)) {
170 		aprint_error("%s: adw_init failed", sc->sc_dev.dv_xname);
171 		return;
172 	}
173 
174 	/*
175 	 * Map Interrupt line
176 	 */
177 	if (pci_intr_map(pa, &ih)) {
178 		aprint_error("%s: couldn't map interrupt\n",
179 		    sc->sc_dev.dv_xname);
180 		return;
181 	}
182 	intrstr = pci_intr_string(pc, ih);
183 
184 	/*
185 	 * Establish Interrupt handler
186 	 */
187 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, adw_intr, sc);
188 	if (sc->sc_ih == NULL) {
189 		aprint_error("%s: couldn't establish interrupt",
190 		    sc->sc_dev.dv_xname);
191 		if (intrstr != NULL)
192 			aprint_normal(" at %s", intrstr);
193 		aprint_normal("\n");
194 		return;
195 	}
196 	aprint_normal("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
197 
198 	/*
199 	 * Attach all the sub-devices we can find
200 	 */
201 	adw_attach(sc);
202 }
203 
204 CFATTACH_DECL(adw_pci, sizeof(ADW_SOFTC),
205     adw_pci_match, adw_pci_attach, NULL, NULL);
206