if_ne_mainbus.c revision 1.2.2.1 1 1.2.2.1 yamt /* $NetBSD: if_ne_mainbus.c,v 1.2.2.1 2013/01/16 05:32:58 yamt Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*-
4 1.1 nonaka * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.1 nonaka * All rights reserved.
6 1.1 nonaka *
7 1.1 nonaka * This code is derived from software contributed to The NetBSD Foundation
8 1.1 nonaka * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 nonaka * NASA Ames Research Center.
10 1.1 nonaka *
11 1.1 nonaka * Redistribution and use in source and binary forms, with or without
12 1.1 nonaka * modification, are permitted provided that the following conditions
13 1.1 nonaka * are met:
14 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
15 1.1 nonaka * notice, this list of conditions and the following disclaimer.
16 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
18 1.1 nonaka * documentation and/or other materials provided with the distribution.
19 1.1 nonaka *
20 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 nonaka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 nonaka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 nonaka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 nonaka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 nonaka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 nonaka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 nonaka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 nonaka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 nonaka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 nonaka * POSSIBILITY OF SUCH DAMAGE.
31 1.1 nonaka */
32 1.1 nonaka
33 1.1 nonaka #include <sys/cdefs.h>
34 1.2.2.1 yamt __KERNEL_RCSID(0, "$NetBSD: if_ne_mainbus.c,v 1.2.2.1 2013/01/16 05:32:58 yamt Exp $");
35 1.1 nonaka
36 1.1 nonaka #include <sys/param.h>
37 1.1 nonaka #include <sys/systm.h>
38 1.1 nonaka #include <sys/mbuf.h>
39 1.1 nonaka #include <sys/socket.h>
40 1.1 nonaka #include <sys/ioctl.h>
41 1.1 nonaka #include <sys/errno.h>
42 1.1 nonaka #include <sys/syslog.h>
43 1.1 nonaka #include <sys/select.h>
44 1.1 nonaka #include <sys/device.h>
45 1.2 dyoung #include <sys/bus.h>
46 1.1 nonaka
47 1.1 nonaka #include <net/if.h>
48 1.1 nonaka #include <net/if_dl.h>
49 1.1 nonaka #include <net/if_ether.h>
50 1.1 nonaka #include <net/if_media.h>
51 1.1 nonaka
52 1.1 nonaka #include <sys/intr.h>
53 1.1 nonaka
54 1.1 nonaka #include <dev/ic/dp8390reg.h>
55 1.1 nonaka #include <dev/ic/dp8390var.h>
56 1.1 nonaka
57 1.1 nonaka #include <dev/ic/ne2000reg.h>
58 1.1 nonaka #include <dev/ic/ne2000var.h>
59 1.1 nonaka
60 1.1 nonaka #include <machine/autoconf.h>
61 1.1 nonaka
62 1.1 nonaka #include <sh3/exception.h>
63 1.1 nonaka
64 1.1 nonaka static int ne_mainbus_match(device_t, cfdata_t, void *);
65 1.1 nonaka static void ne_mainbus_attach(device_t, device_t, void *);
66 1.1 nonaka
67 1.1 nonaka struct ne_mainbus_softc {
68 1.1 nonaka struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
69 1.1 nonaka
70 1.1 nonaka void *sc_ih; /* interrupt cookie */
71 1.1 nonaka };
72 1.1 nonaka
73 1.1 nonaka CFATTACH_DECL_NEW(ne_mainbus, sizeof(struct ne_mainbus_softc),
74 1.1 nonaka ne_mainbus_match, ne_mainbus_attach, NULL, NULL);
75 1.1 nonaka
76 1.1 nonaka extern struct _bus_space t_sh7706lan_bus_io;
77 1.1 nonaka
78 1.1 nonaka static int
79 1.1 nonaka ne_mainbus_match(device_t parent, cfdata_t cf, void *aux)
80 1.1 nonaka {
81 1.1 nonaka struct mainbus_attach_args *maa = (struct mainbus_attach_args *)aux;
82 1.1 nonaka bus_space_tag_t nict = &t_sh7706lan_bus_io;
83 1.1 nonaka bus_space_handle_t nich;
84 1.1 nonaka bus_space_tag_t asict;
85 1.1 nonaka bus_space_handle_t asich;
86 1.1 nonaka int rv = 0;
87 1.1 nonaka
88 1.1 nonaka if (strcmp(maa->ma_name, "ne") != 0)
89 1.1 nonaka return 0;
90 1.1 nonaka
91 1.1 nonaka /* Map i/o space. */
92 1.1 nonaka if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich))
93 1.1 nonaka return 0;
94 1.1 nonaka
95 1.1 nonaka asict = nict;
96 1.1 nonaka if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
97 1.1 nonaka NE2000_ASIC_NPORTS, &asich))
98 1.1 nonaka goto out;
99 1.1 nonaka
100 1.1 nonaka /* Look for an NE2000-compatible card. */
101 1.1 nonaka rv = ne2000_detect(nict, nich, asict, asich);
102 1.1 nonaka
103 1.1 nonaka out:
104 1.1 nonaka bus_space_unmap(nict, nich, NE2000_NPORTS);
105 1.1 nonaka return rv;
106 1.1 nonaka }
107 1.1 nonaka
108 1.1 nonaka static void
109 1.1 nonaka ne_mainbus_attach(device_t parent, device_t self, void *aux)
110 1.1 nonaka {
111 1.1 nonaka struct ne_mainbus_softc *msc = device_private(self);
112 1.1 nonaka struct ne2000_softc *nsc = &msc->sc_ne2000;
113 1.1 nonaka struct dp8390_softc *dsc = &nsc->sc_dp8390;
114 1.1 nonaka bus_space_tag_t nict = &t_sh7706lan_bus_io;
115 1.1 nonaka bus_space_handle_t nich;
116 1.1 nonaka bus_space_tag_t asict = nict;
117 1.1 nonaka bus_space_handle_t asich;
118 1.1 nonaka const char *typestr;
119 1.1 nonaka int netype;
120 1.1 nonaka
121 1.1 nonaka dsc->sc_dev = self;
122 1.1 nonaka
123 1.1 nonaka aprint_naive("\n");
124 1.1 nonaka aprint_normal("\n");
125 1.1 nonaka
126 1.1 nonaka /* Map i/o space. */
127 1.1 nonaka if (bus_space_map(nict, 0x10000300, NE2000_NPORTS, 0, &nich)){
128 1.1 nonaka aprint_error_dev(self, "can't map i/o space\n");
129 1.1 nonaka return;
130 1.1 nonaka }
131 1.1 nonaka
132 1.1 nonaka if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
133 1.1 nonaka NE2000_ASIC_NPORTS, &asich)) {
134 1.1 nonaka aprint_error_dev(self, "can't subregion i/o space\n");
135 1.1 nonaka bus_space_unmap(nict, nich, NE2000_NPORTS);
136 1.1 nonaka return;
137 1.1 nonaka }
138 1.1 nonaka
139 1.1 nonaka dsc->sc_regt = nict;
140 1.1 nonaka dsc->sc_regh = nich;
141 1.1 nonaka
142 1.1 nonaka nsc->sc_asict = asict;
143 1.1 nonaka nsc->sc_asich = asich;
144 1.1 nonaka
145 1.1 nonaka /*
146 1.1 nonaka * Detect it again, so we can print some information about the
147 1.1 nonaka * interface.
148 1.1 nonaka */
149 1.1 nonaka netype = ne2000_detect(nict, nich, asict, asich);
150 1.1 nonaka switch (netype) {
151 1.1 nonaka case NE2000_TYPE_NE1000:
152 1.1 nonaka typestr = "NE1000";
153 1.1 nonaka break;
154 1.1 nonaka
155 1.1 nonaka case NE2000_TYPE_NE2000:
156 1.1 nonaka typestr = "NE2000";
157 1.1 nonaka break;
158 1.1 nonaka
159 1.1 nonaka case NE2000_TYPE_RTL8019:
160 1.1 nonaka typestr = "NE2000 (RTL8019)";
161 1.1 nonaka break;
162 1.1 nonaka
163 1.1 nonaka default:
164 1.1 nonaka aprint_error_dev(self, "where did the card go?!\n");
165 1.1 nonaka bus_space_unmap(nict, nich, NE2000_NPORTS);
166 1.1 nonaka return;
167 1.1 nonaka }
168 1.1 nonaka
169 1.1 nonaka aprint_normal_dev(self, "%s Ethernet\n", typestr);
170 1.1 nonaka
171 1.1 nonaka /* This interface is always enabled. */
172 1.1 nonaka dsc->sc_enabled = 1;
173 1.1 nonaka
174 1.1 nonaka /* force 8bit */
175 1.1 nonaka nsc->sc_quirk |= NE2000_QUIRK_8BIT;
176 1.1 nonaka
177 1.1 nonaka /*
178 1.1 nonaka * Do generic NE2000 attach. This will read the station address
179 1.1 nonaka * from the EEPROM.
180 1.1 nonaka */
181 1.1 nonaka ne2000_attach(nsc, NULL);
182 1.1 nonaka
183 1.1 nonaka /* Establish the interrupt handler. */
184 1.1 nonaka msc->sc_ih = intc_intr_establish(SH7709_INTEVT2_IRQ2, IST_LEVEL,
185 1.1 nonaka IPL_NET, dp8390_intr, dsc);
186 1.1 nonaka if (msc->sc_ih == NULL)
187 1.1 nonaka aprint_error_dev(self,
188 1.1 nonaka "couldn't establish interrupt handler\n");
189 1.1 nonaka }
190