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