xref: /netbsd/sys/dev/mca/if_ne_mca.c (revision bf9ec67e)
1 /*	$NetBSD: if_ne_mca.c,v 1.3 2001/11/13 07:46:26 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jaromir Dolecek.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Driver for Novell NE/2 Ethernet Adapter (and clones).
41  *
42  * According to Linux ne2 driver, Arco and Compex card should be also
43  * supported by this driver. However, NetBSD driver was only tested
44  * with the Novell adapter so far.
45  */
46 
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: if_ne_mca.c,v 1.3 2001/11/13 07:46:26 lukem Exp $");
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/mbuf.h>
53 #include <sys/errno.h>
54 #include <sys/device.h>
55 #include <sys/protosw.h>
56 #include <sys/socket.h>
57 
58 #include <net/if.h>
59 #include <net/if_types.h>
60 #include <net/if_media.h>
61 #include <net/if_ether.h>
62 
63 #include <machine/bus.h>
64 
65 #include <dev/ic/dp8390reg.h>
66 #include <dev/ic/dp8390var.h>
67 
68 #include <dev/ic/ne2000reg.h>
69 #include <dev/ic/ne2000var.h>
70 
71 #include <dev/ic/rtl80x9reg.h>
72 #include <dev/ic/rtl80x9var.h>
73 
74 #include <dev/mca/mcadevs.h>
75 #include <dev/mca/mcavar.h>
76 
77 #define	NE2_NPORTS	0x30
78 
79 struct ne_mca_softc {
80 	struct ne2000_softc sc_ne2000;		/* real "ne2000" softc */
81 
82 	/* MCA-specific goo */
83 	void		*sc_ih;		/* interrupt handle */
84 };
85 
86 int	ne_mca_match __P((struct device *, struct cfdata *, void *));
87 void	ne_mca_attach __P((struct device *, struct device *, void *));
88 
89 struct cfattach ne_mca_ca = {
90 	sizeof(struct ne_mca_softc), ne_mca_match, ne_mca_attach
91 };
92 
93 static const struct ne_mca_products {
94 	u_int32_t ne_id;
95 	const char *ne_name;
96 } ne_mca_products[] = {
97 	{ MCA_PRODUCT_ARCOAE,	"Arco Electronics AE/2 Ethernet Adapter" },
98 	{ MCA_PRODUCT_NE2,	"Novell NE/2 Ethernet Adapter" },
99 	{ MCA_PRODUCT_CENET16, "Compex Inc. PS/2 ENET16-MC/P Microchannel Ad."},
100 	{ 0, NULL }
101 };
102 
103 static const struct ne_mca_products *ne_mca_lookup __P((int id));
104 
105 static const struct ne_mca_products *
106 ne_mca_lookup(int id)
107 {
108 	const struct ne_mca_products *np;
109 
110 	for(np = ne_mca_products; np->ne_name; np++)
111 		if (id == np->ne_id)
112 			return (np);
113 
114 	return (NULL);
115 }
116 
117 int
118 ne_mca_match(struct device *parent, struct cfdata *cf, void *aux)
119 {
120 	struct mca_attach_args *ma = aux;
121 
122 	if (ne_mca_lookup(ma->ma_id))
123 		return (1);
124 
125 	return (0);
126 }
127 
128 /* These values were taken from NE/2 ADF file */
129 static const int ne_mca_irq[] = {
130 	3, 4, 5, 9
131 };
132 static const int ne_mca_iobase[] = {
133 	0, 0x1000, 0x2020, 0x8020, 0xa0a0, 0xb0b0, 0xc0c0, 0xc3d0
134 };
135 
136 void
137 ne_mca_attach(struct device *parent, struct device *self, void *aux)
138 {
139 	struct ne_mca_softc *psc = (struct ne_mca_softc *)self;
140 	struct ne2000_softc *nsc = &psc->sc_ne2000;
141 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
142 	struct mca_attach_args *ma = aux;
143 	bus_space_tag_t nict;
144 	bus_space_handle_t nich;
145 	bus_space_tag_t asict;
146 	bus_space_handle_t asich;
147 	int pos2, iobase, irq;
148 	const struct ne_mca_products *np;
149 
150 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
151 
152 	/*
153 	 * POS register 2: (adf pos0)
154 	 *
155 	 * 7 6 5 4 3 2 1 0
156 	 *   \_/ | \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
157 	 *    |  |     \____ I/O, Mem: 001=0x1000-0x102f 010=0x2020-0x204f
158 	 *    |  |             011=0x8020-0x804f 100=0xa0a0-0xa0cf
159 	 *    |  |             101=0xb0b0-0xb0df 110=0xc0c0-0xc0ef
160 	 *     \  \            111=0xc3d0-0xc3ff
161 	 *      \  \________ Boot Rom: 1=disabled 0=enabled
162 	 *       \__________ Interrupt level: 00=3 01=4 10=5 11=9
163 	 */
164 
165 	np = ne_mca_lookup(ma->ma_id);
166 
167 	iobase = ne_mca_iobase[(pos2 & 0x0e) >> 1];
168 	irq = ne_mca_irq[(pos2 & 0x60) >> 5];
169 
170 	printf(" slot %d irq %d: %s\n", ma->ma_slot + 1, irq, np->ne_name);
171 
172 	nict = ma->ma_iot;
173 
174 	/* Map the device. */
175 	if (bus_space_map(nict, iobase, NE2_NPORTS, 0, &nich)) {
176 		printf("%s: can't map i/o space\n", dsc->sc_dev.dv_xname);
177 		return;
178 	}
179 
180 	asict = nict;
181 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
182 	    NE2000_ASIC_NPORTS, &asich)) {
183 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
184 		return;
185 	}
186 
187 	dsc->sc_regt = nict;
188 	dsc->sc_regh = nich;
189 
190 	nsc->sc_asict = asict;
191 	nsc->sc_asich = asich;
192 
193 	/* This interface is always enabled. */
194 	dsc->sc_enabled = 1;
195 
196 	dsc->sc_mediachange	= NULL;
197 	dsc->sc_mediastatus	= NULL;
198 	dsc->sc_media_init	= NULL;
199 	dsc->init_card		= NULL;
200 
201 	/*
202 	 * This is necessary for NE/2. Hopefully the other clones also work
203 	 * this way.
204 	 */
205 	nsc->sc_type = NE2000_TYPE_AX88190;
206 
207 	/*
208 	 * Do generic NE2000 attach.  This will read the station address
209 	 * from the EEPROM.
210 	 */
211 	if (ne2000_attach(nsc, NULL))
212 		return;
213 
214 	/* establish interrupt handler */
215 	psc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, dp8390_intr,
216 			dsc);
217 	if (psc->sc_ih == NULL) {
218 		printf("%s: couldn't establish interrupt handler\n",
219 		       dsc->sc_dev.dv_xname);
220 		return;
221 	}
222 }
223