xref: /openbsd/sys/dev/isa/if_ne_isapnp.c (revision 23c939fc)
1*23c939fcSfgsch /*	$OpenBSD: if_ne_isapnp.c,v 1.1 1998/09/22 06:33:19 fgsch Exp $	*/
2*23c939fcSfgsch /*	$NetBSD: if_ne_isapnp.c,v 1.7 1998/07/23 19:30:45 christos Exp $	*/
3*23c939fcSfgsch 
4*23c939fcSfgsch /*-
5*23c939fcSfgsch  * Copyright (c) 1997 The NetBSD Foundation, Inc.
6*23c939fcSfgsch  * All rights reserved.
7*23c939fcSfgsch  *
8*23c939fcSfgsch  * This code is derived from software contributed to The NetBSD Foundation
9*23c939fcSfgsch  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10*23c939fcSfgsch  * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
11*23c939fcSfgsch  *
12*23c939fcSfgsch  * Redistribution and use in source and binary forms, with or without
13*23c939fcSfgsch  * modification, are permitted provided that the following conditions
14*23c939fcSfgsch  * are met:
15*23c939fcSfgsch  * 1. Redistributions of source code must retain the above copyright
16*23c939fcSfgsch  *    notice, this list of conditions and the following disclaimer.
17*23c939fcSfgsch  * 2. Redistributions in binary form must reproduce the above copyright
18*23c939fcSfgsch  *    notice, this list of conditions and the following disclaimer in the
19*23c939fcSfgsch  *    documentation and/or other materials provided with the distribution.
20*23c939fcSfgsch  * 3. All advertising materials mentioning features or use of this software
21*23c939fcSfgsch  *    must display the following acknowledgement:
22*23c939fcSfgsch  *	This product includes software developed by the NetBSD
23*23c939fcSfgsch  *	Foundation, Inc. and its contributors.
24*23c939fcSfgsch  * 4. Neither the name of The NetBSD Foundation nor the names of its
25*23c939fcSfgsch  *    contributors may be used to endorse or promote products derived
26*23c939fcSfgsch  *    from this software without specific prior written permission.
27*23c939fcSfgsch  *
28*23c939fcSfgsch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29*23c939fcSfgsch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30*23c939fcSfgsch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31*23c939fcSfgsch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32*23c939fcSfgsch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33*23c939fcSfgsch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34*23c939fcSfgsch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35*23c939fcSfgsch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36*23c939fcSfgsch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37*23c939fcSfgsch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38*23c939fcSfgsch  * POSSIBILITY OF SUCH DAMAGE.
39*23c939fcSfgsch  */
40*23c939fcSfgsch 
41*23c939fcSfgsch #include "bpfilter.h"
42*23c939fcSfgsch 
43*23c939fcSfgsch #include <sys/param.h>
44*23c939fcSfgsch #include <sys/systm.h>
45*23c939fcSfgsch #include <sys/mbuf.h>
46*23c939fcSfgsch #include <sys/socket.h>
47*23c939fcSfgsch #include <sys/ioctl.h>
48*23c939fcSfgsch #include <sys/errno.h>
49*23c939fcSfgsch #include <sys/syslog.h>
50*23c939fcSfgsch #include <sys/select.h>
51*23c939fcSfgsch #include <sys/device.h>
52*23c939fcSfgsch 
53*23c939fcSfgsch #include <net/if.h>
54*23c939fcSfgsch #include <net/if_dl.h>
55*23c939fcSfgsch #ifdef __NetBSD__
56*23c939fcSfgsch #include <net/if_ether.h>
57*23c939fcSfgsch #endif
58*23c939fcSfgsch #include <net/if_media.h>
59*23c939fcSfgsch 
60*23c939fcSfgsch #ifdef INET
61*23c939fcSfgsch #include <netinet/in.h>
62*23c939fcSfgsch #include <netinet/in_systm.h>
63*23c939fcSfgsch #include <netinet/in_var.h>
64*23c939fcSfgsch #include <netinet/ip.h>
65*23c939fcSfgsch #ifdef __NetBSD__
66*23c939fcSfgsch #include <netinet/if_inarp.h>
67*23c939fcSfgsch #else
68*23c939fcSfgsch #include <netinet/if_ether.h>
69*23c939fcSfgsch #endif
70*23c939fcSfgsch #endif
71*23c939fcSfgsch 
72*23c939fcSfgsch #ifdef NS
73*23c939fcSfgsch #include <netns/ns.h>
74*23c939fcSfgsch #include <netns/ns_if.h>
75*23c939fcSfgsch #endif
76*23c939fcSfgsch 
77*23c939fcSfgsch #if NBPFILTER > 0
78*23c939fcSfgsch #include <net/bpf.h>
79*23c939fcSfgsch #include <net/bpfdesc.h>
80*23c939fcSfgsch #endif
81*23c939fcSfgsch 
82*23c939fcSfgsch #include <machine/intr.h>
83*23c939fcSfgsch #include <machine/bus.h>
84*23c939fcSfgsch 
85*23c939fcSfgsch #include <dev/ic/dp8390reg.h>
86*23c939fcSfgsch #include <dev/ic/dp8390var.h>
87*23c939fcSfgsch 
88*23c939fcSfgsch #include <dev/ic/ne2000reg.h>
89*23c939fcSfgsch #include <dev/ic/ne2000var.h>
90*23c939fcSfgsch 
91*23c939fcSfgsch #include <dev/isa/isavar.h>
92*23c939fcSfgsch 
93*23c939fcSfgsch #include <dev/isa/isapnpreg.h>
94*23c939fcSfgsch #ifdef __NetBSD__
95*23c939fcSfgsch #include <dev/isa/isapnpvar.h>
96*23c939fcSfgsch #include <dev/isa/isapnpdevs.h>
97*23c939fcSfgsch #endif
98*23c939fcSfgsch 
99*23c939fcSfgsch static int ne_isapnp_match __P((struct device *, void *, void *));
100*23c939fcSfgsch static void ne_isapnp_attach __P((struct device *, struct device *, void *));
101*23c939fcSfgsch 
102*23c939fcSfgsch struct ne_isapnp_softc {
103*23c939fcSfgsch 	struct	ne2000_softc sc_ne2000;		/* real "ne2000" softc */
104*23c939fcSfgsch 
105*23c939fcSfgsch 	/* ISA-specific goo. */
106*23c939fcSfgsch 	void	*sc_ih;				/* interrupt cookie */
107*23c939fcSfgsch };
108*23c939fcSfgsch 
109*23c939fcSfgsch struct cfattach ne_isapnp_ca = {
110*23c939fcSfgsch 	sizeof(struct ne_isapnp_softc), ne_isapnp_match, ne_isapnp_attach
111*23c939fcSfgsch };
112*23c939fcSfgsch 
113*23c939fcSfgsch static int
114*23c939fcSfgsch ne_isapnp_match(parent, match, aux)
115*23c939fcSfgsch 	struct device *parent;
116*23c939fcSfgsch 	void *match, *aux;
117*23c939fcSfgsch {
118*23c939fcSfgsch 	return 1;
119*23c939fcSfgsch }
120*23c939fcSfgsch 
121*23c939fcSfgsch static void
122*23c939fcSfgsch ne_isapnp_attach(
123*23c939fcSfgsch 	struct device *parent,
124*23c939fcSfgsch 	struct device *self,
125*23c939fcSfgsch 	void *aux)
126*23c939fcSfgsch {
127*23c939fcSfgsch 	struct ne_isapnp_softc * const isc = (struct ne_isapnp_softc *)self;
128*23c939fcSfgsch 	struct ne2000_softc * const nsc = &isc->sc_ne2000;
129*23c939fcSfgsch 	struct dp8390_softc * const dsc = &nsc->sc_dp8390;
130*23c939fcSfgsch 	struct isa_attach_args * const ipa = aux;
131*23c939fcSfgsch 	bus_space_tag_t nict;
132*23c939fcSfgsch 	bus_space_handle_t nich;
133*23c939fcSfgsch 	bus_space_tag_t asict;
134*23c939fcSfgsch 	bus_space_handle_t asich;
135*23c939fcSfgsch 	const char *typestr;
136*23c939fcSfgsch 
137*23c939fcSfgsch 	printf("\n");
138*23c939fcSfgsch 
139*23c939fcSfgsch 	nict = ipa->ia_iot;
140*23c939fcSfgsch 	nich = ipa->ipa_io[0].h;
141*23c939fcSfgsch 
142*23c939fcSfgsch 	asict = nict;
143*23c939fcSfgsch 
144*23c939fcSfgsch 	if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
145*23c939fcSfgsch 	    NE2000_ASIC_NPORTS, &asich)) {
146*23c939fcSfgsch 		printf("%s: can't subregion i/o space\n", dsc->sc_dev.dv_xname);
147*23c939fcSfgsch 		return;
148*23c939fcSfgsch 	}
149*23c939fcSfgsch 
150*23c939fcSfgsch 	dsc->sc_regt = nict;
151*23c939fcSfgsch 	dsc->sc_regh = nich;
152*23c939fcSfgsch 
153*23c939fcSfgsch 	nsc->sc_asict = asict;
154*23c939fcSfgsch 	nsc->sc_asich = asich;
155*23c939fcSfgsch 
156*23c939fcSfgsch 	/*
157*23c939fcSfgsch 	 * Detect it again, so we can print some information about the
158*23c939fcSfgsch 	 * interface.
159*23c939fcSfgsch 	 */
160*23c939fcSfgsch 	switch (ne2000_detect(nict, nich, asict, asich)) {
161*23c939fcSfgsch 	case NE2000_TYPE_NE1000:
162*23c939fcSfgsch 		typestr = "NE1000";
163*23c939fcSfgsch 		break;
164*23c939fcSfgsch 
165*23c939fcSfgsch 	case NE2000_TYPE_NE2000:
166*23c939fcSfgsch 		typestr = "NE2000";
167*23c939fcSfgsch 		break;
168*23c939fcSfgsch 
169*23c939fcSfgsch 	default:
170*23c939fcSfgsch 		printf("%s: where did the card go?!\n", dsc->sc_dev.dv_xname);
171*23c939fcSfgsch 		return;
172*23c939fcSfgsch 	}
173*23c939fcSfgsch 
174*23c939fcSfgsch 	printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, typestr);
175*23c939fcSfgsch 
176*23c939fcSfgsch 	/* This interface is always enabled. */
177*23c939fcSfgsch 	dsc->sc_enabled = 1;
178*23c939fcSfgsch 
179*23c939fcSfgsch 	/*
180*23c939fcSfgsch 	 * Do generic NE2000 attach.  This will read the station address
181*23c939fcSfgsch 	 * from the EEPROM.
182*23c939fcSfgsch 	 */
183*23c939fcSfgsch 	ne2000_attach(nsc, NULL);
184*23c939fcSfgsch 
185*23c939fcSfgsch 	/* Establish the interrupt handler. */
186*23c939fcSfgsch 	isc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
187*23c939fcSfgsch 	    IST_EDGE, IPL_NET, dp8390_intr, dsc,
188*23c939fcSfgsch 	    dsc->sc_dev.dv_xname);
189*23c939fcSfgsch 	if (isc->sc_ih == NULL)
190*23c939fcSfgsch 		printf("%s: couldn't establish interrupt handler\n",
191*23c939fcSfgsch 		    dsc->sc_dev.dv_xname);
192*23c939fcSfgsch }
193