1*8f7c20edStsutsui /* $NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $ */
2119ee74bSmatt
3119ee74bSmatt /*-
4d08eb2a3Sthorpej * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5119ee74bSmatt * All rights reserved.
6119ee74bSmatt *
7119ee74bSmatt * This code is derived from software contributed to The NetBSD Foundation
8119ee74bSmatt * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9119ee74bSmatt * NASA Ames Research Center and Matt Thomas of the 3am Software Foundry.
10119ee74bSmatt *
11119ee74bSmatt * Redistribution and use in source and binary forms, with or without
12119ee74bSmatt * modification, are permitted provided that the following conditions
13119ee74bSmatt * are met:
14119ee74bSmatt * 1. Redistributions of source code must retain the above copyright
15119ee74bSmatt * notice, this list of conditions and the following disclaimer.
16119ee74bSmatt * 2. Redistributions in binary form must reproduce the above copyright
17119ee74bSmatt * notice, this list of conditions and the following disclaimer in the
18119ee74bSmatt * documentation and/or other materials provided with the distribution.
19119ee74bSmatt *
20119ee74bSmatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21119ee74bSmatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22119ee74bSmatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23119ee74bSmatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24119ee74bSmatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25119ee74bSmatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26119ee74bSmatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27119ee74bSmatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28119ee74bSmatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29119ee74bSmatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30119ee74bSmatt * POSSIBILITY OF SUCH DAMAGE.
31119ee74bSmatt */
32119ee74bSmatt
339d2580ffSlukem #include <sys/cdefs.h>
34*8f7c20edStsutsui __KERNEL_RCSID(0, "$NetBSD: if_ne_isapnp.c,v 1.27 2010/03/03 13:39:57 tsutsui Exp $");
359d2580ffSlukem
36119ee74bSmatt #include <sys/param.h>
37119ee74bSmatt #include <sys/systm.h>
38119ee74bSmatt #include <sys/mbuf.h>
39119ee74bSmatt #include <sys/socket.h>
40119ee74bSmatt #include <sys/ioctl.h>
41119ee74bSmatt #include <sys/errno.h>
42119ee74bSmatt #include <sys/syslog.h>
43119ee74bSmatt #include <sys/select.h>
44119ee74bSmatt #include <sys/device.h>
45119ee74bSmatt
46119ee74bSmatt #include <net/if.h>
47119ee74bSmatt #include <net/if_dl.h>
48119ee74bSmatt #include <net/if_ether.h>
49119ee74bSmatt #include <net/if_media.h>
50119ee74bSmatt
51a2a38285Sad #include <sys/intr.h>
52a2a38285Sad #include <sys/bus.h>
53119ee74bSmatt
54119ee74bSmatt #include <dev/ic/dp8390reg.h>
55119ee74bSmatt #include <dev/ic/dp8390var.h>
56119ee74bSmatt
57119ee74bSmatt #include <dev/ic/ne2000reg.h>
58119ee74bSmatt #include <dev/ic/ne2000var.h>
59119ee74bSmatt
60119ee74bSmatt #include <dev/isa/isavar.h>
61119ee74bSmatt
62119ee74bSmatt #include <dev/isapnp/isapnpreg.h>
63119ee74bSmatt #include <dev/isapnp/isapnpvar.h>
64bdb2269aSchristos #include <dev/isapnp/isapnpdevs.h>
65119ee74bSmatt
66cf80f73dScube static int ne_isapnp_match(device_t, cfdata_t , void *);
67cf80f73dScube static void ne_isapnp_attach(device_t, device_t, void *);
68119ee74bSmatt
69119ee74bSmatt struct ne_isapnp_softc {
70119ee74bSmatt struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
71119ee74bSmatt
72119ee74bSmatt /* ISA-specific goo. */
73119ee74bSmatt void *sc_ih; /* interrupt cookie */
74119ee74bSmatt };
75119ee74bSmatt
76cf80f73dScube CFATTACH_DECL_NEW(ne_isapnp, sizeof(struct ne_isapnp_softc),
77c9b3657cSthorpej ne_isapnp_match, ne_isapnp_attach, NULL, NULL);
78119ee74bSmatt
79119ee74bSmatt static int
ne_isapnp_match(device_t parent,cfdata_t match,void * aux)80cf80f73dScube ne_isapnp_match(device_t parent, cfdata_t match, void *aux)
81119ee74bSmatt {
826ada3afdSmycroft int pri, variant;
832cccf3bdSmycroft
846ada3afdSmycroft pri = isapnp_devmatch(aux, &isapnp_ne_devinfo, &variant);
856ada3afdSmycroft if (pri && variant > 0)
866ada3afdSmycroft pri = 0;
876ada3afdSmycroft return (pri);
88119ee74bSmatt }
89119ee74bSmatt
90119ee74bSmatt static void
ne_isapnp_attach(device_t parent,device_t self,void * aux)91cf80f73dScube ne_isapnp_attach(device_t parent, device_t self, void *aux)
92119ee74bSmatt {
93838ee1e0Sthorpej struct ne_isapnp_softc * const isc = device_private(self);
94119ee74bSmatt struct ne2000_softc * const nsc = &isc->sc_ne2000;
95119ee74bSmatt struct dp8390_softc * const dsc = &nsc->sc_dp8390;
96119ee74bSmatt struct isapnp_attach_args * const ipa = aux;
97985f99feSthorpej bus_space_tag_t nict;
98985f99feSthorpej bus_space_handle_t nich;
99985f99feSthorpej bus_space_tag_t asict;
100119ee74bSmatt bus_space_handle_t asich;
101119ee74bSmatt const char *typestr;
102d08eb2a3Sthorpej int netype;
103119ee74bSmatt
104cf80f73dScube aprint_normal("\n");
105cf80f73dScube
106cf80f73dScube dsc->sc_dev = self;
107119ee74bSmatt
108119ee74bSmatt if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
109cf80f73dScube aprint_error_dev(self, "can't configure isapnp resources\n");
110119ee74bSmatt return;
111119ee74bSmatt }
112119ee74bSmatt
113985f99feSthorpej nict = ipa->ipa_iot;
114985f99feSthorpej nich = ipa->ipa_io[0].h;
115985f99feSthorpej
116985f99feSthorpej asict = nict;
117985f99feSthorpej
118119ee74bSmatt if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
119119ee74bSmatt NE2000_ASIC_NPORTS, &asich)) {
120cf80f73dScube aprint_error_dev(self, "can't subregion i/o space\n");
121119ee74bSmatt return;
122119ee74bSmatt }
123119ee74bSmatt
124119ee74bSmatt dsc->sc_regt = nict;
125119ee74bSmatt dsc->sc_regh = nich;
126119ee74bSmatt
127119ee74bSmatt nsc->sc_asict = asict;
128119ee74bSmatt nsc->sc_asich = asich;
129119ee74bSmatt
130119ee74bSmatt /*
131119ee74bSmatt * Detect it again, so we can print some information about the
132119ee74bSmatt * interface.
133119ee74bSmatt */
134d08eb2a3Sthorpej netype = ne2000_detect(nict, nich, asict, asich);
135d08eb2a3Sthorpej switch (netype) {
136119ee74bSmatt case NE2000_TYPE_NE1000:
137119ee74bSmatt typestr = "NE1000";
138119ee74bSmatt break;
139119ee74bSmatt
140119ee74bSmatt case NE2000_TYPE_NE2000:
141119ee74bSmatt typestr = "NE2000";
142*8f7c20edStsutsui break;
143*8f7c20edStsutsui
144*8f7c20edStsutsui case NE2000_TYPE_RTL8019:
145d08eb2a3Sthorpej typestr = "NE2000 (RTL8019)";
146119ee74bSmatt break;
147119ee74bSmatt
148119ee74bSmatt default:
149cf80f73dScube aprint_error_dev(self, "where did the card go?!\n");
150119ee74bSmatt return;
151119ee74bSmatt }
152119ee74bSmatt
153cf80f73dScube aprint_normal_dev(self, "%s Ethernet\n", typestr);
154119ee74bSmatt
155119ee74bSmatt /* This interface is always enabled. */
156119ee74bSmatt dsc->sc_enabled = 1;
157119ee74bSmatt
158119ee74bSmatt /*
159119ee74bSmatt * Do generic NE2000 attach. This will read the station address
160119ee74bSmatt * from the EEPROM.
161119ee74bSmatt */
162043e519dSthorpej ne2000_attach(nsc, NULL);
163119ee74bSmatt
164119ee74bSmatt /* Establish the interrupt handler. */
165119ee74bSmatt isc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
166c12bf4ccSchristos ipa->ipa_irq[0].type, IPL_NET, dp8390_intr, dsc);
167119ee74bSmatt if (isc->sc_ih == NULL)
168cf80f73dScube aprint_error_dev(self,
169cf80f73dScube "couldn't establish interrupt handler\n");
170119ee74bSmatt }
171