if_ne_mainbus.c revision 1.1.8.2 1 1.1.8.2 jruoho /* $NetBSD: if_ne_mainbus.c,v 1.1.8.2 2011/06/06 09:06:13 jruoho Exp $ */
2 1.1.8.2 jruoho /*
3 1.1.8.2 jruoho * Copyright (c) 2010 KIYOHARA Takashi
4 1.1.8.2 jruoho * All rights reserved.
5 1.1.8.2 jruoho *
6 1.1.8.2 jruoho * Redistribution and use in source and binary forms, with or without
7 1.1.8.2 jruoho * modification, are permitted provided that the following conditions
8 1.1.8.2 jruoho * are met:
9 1.1.8.2 jruoho * 1. Redistributions of source code must retain the above copyright
10 1.1.8.2 jruoho * notice, this list of conditions and the following disclaimer.
11 1.1.8.2 jruoho * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.8.2 jruoho * notice, this list of conditions and the following disclaimer in the
13 1.1.8.2 jruoho * documentation and/or other materials provided with the distribution.
14 1.1.8.2 jruoho *
15 1.1.8.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.8.2 jruoho * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1.8.2 jruoho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1.8.2 jruoho * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1.8.2 jruoho * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1.8.2 jruoho * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1.8.2 jruoho * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1.8.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1.8.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1.8.2 jruoho * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1.8.2 jruoho * POSSIBILITY OF SUCH DAMAGE.
26 1.1.8.2 jruoho *
27 1.1.8.2 jruoho */
28 1.1.8.2 jruoho #include <sys/cdefs.h>
29 1.1.8.2 jruoho __KERNEL_RCSID(0, "$NetBSD: if_ne_mainbus.c,v 1.1.8.2 2011/06/06 09:06:13 jruoho Exp $");
30 1.1.8.2 jruoho
31 1.1.8.2 jruoho #include <sys/param.h>
32 1.1.8.2 jruoho #include <sys/bus.h>
33 1.1.8.2 jruoho #include <sys/device.h>
34 1.1.8.2 jruoho #include <sys/errno.h>
35 1.1.8.2 jruoho
36 1.1.8.2 jruoho #include <machine/autoconf.h>
37 1.1.8.2 jruoho #include <machine/intr.h>
38 1.1.8.2 jruoho #include <machine/mmeye.h>
39 1.1.8.2 jruoho
40 1.1.8.2 jruoho #include <net/if.h>
41 1.1.8.2 jruoho #include <net/if_dl.h>
42 1.1.8.2 jruoho #include <net/if_ether.h>
43 1.1.8.2 jruoho #include <net/if_media.h>
44 1.1.8.2 jruoho
45 1.1.8.2 jruoho #include <dev/ic/dp8390reg.h>
46 1.1.8.2 jruoho #include <dev/ic/dp8390var.h>
47 1.1.8.2 jruoho
48 1.1.8.2 jruoho #include <dev/ic/ne2000reg.h>
49 1.1.8.2 jruoho #include <dev/ic/ne2000var.h>
50 1.1.8.2 jruoho
51 1.1.8.2 jruoho #include "locators.h"
52 1.1.8.2 jruoho
53 1.1.8.2 jruoho static int ne_mainbus_match(device_t, cfdata_t , void *);
54 1.1.8.2 jruoho static void ne_mainbus_attach(device_t, device_t, void *);
55 1.1.8.2 jruoho
56 1.1.8.2 jruoho CFATTACH_DECL_NEW(ne_mainbus, sizeof(struct ne2000_softc),
57 1.1.8.2 jruoho ne_mainbus_match, ne_mainbus_attach, NULL, NULL);
58 1.1.8.2 jruoho
59 1.1.8.2 jruoho static int
60 1.1.8.2 jruoho ne_mainbus_match(device_t parent, cfdata_t match, void *aux)
61 1.1.8.2 jruoho {
62 1.1.8.2 jruoho struct mainbus_attach_args *ma = aux;
63 1.1.8.2 jruoho bus_space_tag_t nict, asict;
64 1.1.8.2 jruoho bus_space_handle_t nich, asich;
65 1.1.8.2 jruoho int rv = 0;
66 1.1.8.2 jruoho
67 1.1.8.2 jruoho if (strcmp(ma->ma_name, match->cf_name) != 0)
68 1.1.8.2 jruoho return 0;
69 1.1.8.2 jruoho
70 1.1.8.2 jruoho /* Disallow wildcarded values. */
71 1.1.8.2 jruoho if (ma->ma_addr1 == MAINBUSCF_ADDR1_DEFAULT ||
72 1.1.8.2 jruoho ma->ma_irq1 == MAINBUSCF_IRQ1_DEFAULT)
73 1.1.8.2 jruoho return 0;
74 1.1.8.2 jruoho
75 1.1.8.2 jruoho /* Make sure this is a valid NE[12]000 i/o address. */
76 1.1.8.2 jruoho if ((ma->ma_addr1 & 0x1f) != 0)
77 1.1.8.2 jruoho return 0;
78 1.1.8.2 jruoho
79 1.1.8.2 jruoho /* Map i/o space. */
80 1.1.8.2 jruoho nict = SH3_BUS_SPACE_PCMCIA_IO;
81 1.1.8.2 jruoho if (bus_space_map(nict, ma->ma_addr1, NE2000_NPORTS, 0, &nich))
82 1.1.8.2 jruoho return 0;
83 1.1.8.2 jruoho
84 1.1.8.2 jruoho if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
85 1.1.8.2 jruoho NE2000_ASIC_NPORTS, &asich))
86 1.1.8.2 jruoho goto out;
87 1.1.8.2 jruoho asict = nict;
88 1.1.8.2 jruoho
89 1.1.8.2 jruoho /* Look for an NE2000-compatible card. */
90 1.1.8.2 jruoho rv = ne2000_detect(nict, nich, asict, asich);
91 1.1.8.2 jruoho
92 1.1.8.2 jruoho out:
93 1.1.8.2 jruoho bus_space_unmap(nict, nich, NE2000_NPORTS);
94 1.1.8.2 jruoho return rv;
95 1.1.8.2 jruoho }
96 1.1.8.2 jruoho
97 1.1.8.2 jruoho void
98 1.1.8.2 jruoho ne_mainbus_attach(device_t parent, device_t self, void *aux)
99 1.1.8.2 jruoho {
100 1.1.8.2 jruoho struct ne2000_softc *sc = device_private(self);
101 1.1.8.2 jruoho struct dp8390_softc *dsc = &sc->sc_dp8390;
102 1.1.8.2 jruoho struct mainbus_attach_args *ma = aux;
103 1.1.8.2 jruoho bus_space_tag_t nict, asict;
104 1.1.8.2 jruoho bus_space_handle_t nich, asich;
105 1.1.8.2 jruoho int netype;
106 1.1.8.2 jruoho const char *typestr;
107 1.1.8.2 jruoho void *ih;
108 1.1.8.2 jruoho
109 1.1.8.2 jruoho dsc->sc_dev = self;
110 1.1.8.2 jruoho aprint_normal("\n");
111 1.1.8.2 jruoho
112 1.1.8.2 jruoho /* Map i/o space. */
113 1.1.8.2 jruoho nict = SH3_BUS_SPACE_PCMCIA_IO;
114 1.1.8.2 jruoho if (bus_space_map(nict, ma->ma_addr1, NE2000_NPORTS, 0, &nich)) {
115 1.1.8.2 jruoho aprint_error_dev(self, "can't map i/o space\n");
116 1.1.8.2 jruoho return;
117 1.1.8.2 jruoho }
118 1.1.8.2 jruoho
119 1.1.8.2 jruoho if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
120 1.1.8.2 jruoho NE2000_ASIC_NPORTS, &asich)) {
121 1.1.8.2 jruoho aprint_error_dev(self, "can't subregion i/o space\n");
122 1.1.8.2 jruoho return;
123 1.1.8.2 jruoho }
124 1.1.8.2 jruoho asict = nict;
125 1.1.8.2 jruoho
126 1.1.8.2 jruoho dsc->sc_regt = nict;
127 1.1.8.2 jruoho dsc->sc_regh = nich;
128 1.1.8.2 jruoho
129 1.1.8.2 jruoho sc->sc_asict = asict;
130 1.1.8.2 jruoho sc->sc_asich = asich;
131 1.1.8.2 jruoho
132 1.1.8.2 jruoho /*
133 1.1.8.2 jruoho * Detect it again, so we can print some information about the
134 1.1.8.2 jruoho * interface.
135 1.1.8.2 jruoho */
136 1.1.8.2 jruoho netype = ne2000_detect(nict, nich, asict, asich);
137 1.1.8.2 jruoho switch (netype) {
138 1.1.8.2 jruoho case NE2000_TYPE_RTL8019:
139 1.1.8.2 jruoho typestr = "NE2000 (RTL8019)";
140 1.1.8.2 jruoho break;
141 1.1.8.2 jruoho
142 1.1.8.2 jruoho case NE2000_TYPE_NE1000:
143 1.1.8.2 jruoho case NE2000_TYPE_NE2000:
144 1.1.8.2 jruoho default:
145 1.1.8.2 jruoho aprint_error_dev(self, "where did the card go?!\n");
146 1.1.8.2 jruoho return;
147 1.1.8.2 jruoho }
148 1.1.8.2 jruoho
149 1.1.8.2 jruoho aprint_normal_dev(self, "%s Ethernet\n", typestr);
150 1.1.8.2 jruoho
151 1.1.8.2 jruoho /* This interface is always enabled. */
152 1.1.8.2 jruoho dsc->sc_enabled = 1;
153 1.1.8.2 jruoho
154 1.1.8.2 jruoho /*
155 1.1.8.2 jruoho * Do generic NE2000 attach. This will read the station address
156 1.1.8.2 jruoho * from the EEPROM.
157 1.1.8.2 jruoho */
158 1.1.8.2 jruoho ne2000_attach(sc, NULL);
159 1.1.8.2 jruoho
160 1.1.8.2 jruoho /* Establish the interrupt handler. */
161 1.1.8.2 jruoho ih = mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_NET,
162 1.1.8.2 jruoho dp8390_intr, dsc);
163 1.1.8.2 jruoho if (ih == NULL)
164 1.1.8.2 jruoho aprint_error_dev(self,
165 1.1.8.2 jruoho "couldn't establish interrupt handler\n");
166 1.1.8.2 jruoho }
167