if_netdock_nubus.c revision 1.1.4.3 1 1.1.4.3 nathanw /* $NetBSD: if_netdock_nubus.c,v 1.1.4.3 2002/10/18 02:38:27 nathanw Exp $ */
2 1.1.4.2 nathanw
3 1.1.4.2 nathanw /*
4 1.1.4.2 nathanw * Copyright (C) 2000,2002 Daishi Kato <daishi (at) axlight.com>
5 1.1.4.2 nathanw * All rights reserved.
6 1.1.4.2 nathanw *
7 1.1.4.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 nathanw * modification, are permitted provided that the following conditions
9 1.1.4.2 nathanw * are met:
10 1.1.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.1.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.1.4.2 nathanw * must display the following acknowledgement:
17 1.1.4.2 nathanw * This product includes software developed by Daishi Kato
18 1.1.4.2 nathanw * 4. The name of the author may not be used to endorse or promote products
19 1.1.4.2 nathanw * derived from this software without specific prior written permission.
20 1.1.4.2 nathanw *
21 1.1.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1.4.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1.4.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1.4.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1.4.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1.4.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1.4.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1.4.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1.4.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1.4.2 nathanw */
32 1.1.4.2 nathanw
33 1.1.4.2 nathanw /*
34 1.1.4.2 nathanw * Asante NetDock (for Duo series) driver
35 1.1.4.2 nathanw * the chip inside is not known
36 1.1.4.2 nathanw */
37 1.1.4.2 nathanw
38 1.1.4.2 nathanw /*
39 1.1.4.2 nathanw * The author would like to thank Takeo Kuwata <tkuwata (at) mac.com> for
40 1.1.4.2 nathanw * his help in stabilizing this driver.
41 1.1.4.2 nathanw */
42 1.1.4.2 nathanw
43 1.1.4.2 nathanw /***********************/
44 1.1.4.2 nathanw
45 1.1.4.2 nathanw #include <sys/param.h>
46 1.1.4.2 nathanw #include <sys/device.h>
47 1.1.4.2 nathanw #include <sys/socket.h>
48 1.1.4.2 nathanw #include <sys/systm.h>
49 1.1.4.2 nathanw #include <sys/mbuf.h>
50 1.1.4.2 nathanw #include <sys/ioctl.h>
51 1.1.4.2 nathanw
52 1.1.4.2 nathanw #include <net/if.h>
53 1.1.4.2 nathanw #include <net/if_dl.h>
54 1.1.4.2 nathanw #include <net/if_ether.h>
55 1.1.4.2 nathanw
56 1.1.4.2 nathanw #include "opt_inet.h"
57 1.1.4.2 nathanw #ifdef INET
58 1.1.4.2 nathanw #include <netinet/in.h>
59 1.1.4.2 nathanw #include <netinet/if_inarp.h>
60 1.1.4.2 nathanw #endif
61 1.1.4.2 nathanw
62 1.1.4.2 nathanw #include "bpfilter.h"
63 1.1.4.2 nathanw #if NBPFILTER > 0
64 1.1.4.2 nathanw #include <net/bpf.h>
65 1.1.4.2 nathanw #endif
66 1.1.4.2 nathanw
67 1.1.4.2 nathanw #include <machine/bus.h>
68 1.1.4.2 nathanw #include <machine/viareg.h>
69 1.1.4.2 nathanw #include <mac68k/nubus/nubus.h>
70 1.1.4.2 nathanw
71 1.1.4.2 nathanw /***********************/
72 1.1.4.2 nathanw
73 1.1.4.2 nathanw #define NETDOCK_DEBUG
74 1.1.4.2 nathanw
75 1.1.4.2 nathanw #define NETDOCK_NUBUS_CATEGORY 0x0020
76 1.1.4.2 nathanw #define NETDOCK_NUBUS_TYPE 0x0003
77 1.1.4.2 nathanw #define NETDOCK_NUBUS_DRSW 0x0103
78 1.1.4.2 nathanw #define NETDOCK_NUBUS_DRHW 0x0100
79 1.1.4.2 nathanw
80 1.1.4.2 nathanw #define ETHERMICRODOCK_NUBUS_CATEGORY 0x0020
81 1.1.4.2 nathanw #define ETHERMICRODOCK_NUBUS_TYPE 0x0003
82 1.1.4.2 nathanw #define ETHERMICRODOCK_NUBUS_DRSW 0x0102
83 1.1.4.2 nathanw #define ETHERMICRODOCK_NUBUS_DRHW 0x0100
84 1.1.4.2 nathanw
85 1.1.4.2 nathanw #define REG_ISR 0x000c
86 1.1.4.2 nathanw #define REG_000E 0x000e
87 1.1.4.2 nathanw #define REG_0000 0x0000
88 1.1.4.2 nathanw #define REG_0002 0x0002
89 1.1.4.2 nathanw #define REG_0004 0x0004
90 1.1.4.2 nathanw #define REG_0006 0x0006
91 1.1.4.2 nathanw #define REG_DATA 0x0008
92 1.1.4.2 nathanw #define REG_EFD00 0xefd00
93 1.1.4.2 nathanw
94 1.1.4.2 nathanw #define ISR_ALL 0x3300
95 1.1.4.2 nathanw #define ISR_TX 0x0200
96 1.1.4.2 nathanw #define ISR_RX 0x0100
97 1.1.4.2 nathanw #define ISR_READY 0x0800
98 1.1.4.2 nathanw #define ISR_BIT_0C 0x1000
99 1.1.4.2 nathanw #define ISR_BIT_0D 0x2000
100 1.1.4.2 nathanw #define ISR_MASK 0x0033
101 1.1.4.2 nathanw #define ISR_BIT_03 0x0008
102 1.1.4.2 nathanw
103 1.1.4.2 nathanw #define REG_0002_BIT_04 0x0010
104 1.1.4.2 nathanw #define REG_0000_BIT_08 0x0100
105 1.1.4.2 nathanw #define REG_0004_BIT_0F 0x8000
106 1.1.4.2 nathanw #define REG_0004_BIT_07 0x0080
107 1.1.4.2 nathanw #define REG_DATA_BIT_02 0x0004
108 1.1.4.2 nathanw #define REG_DATA_BIT_03 0x0008
109 1.1.4.2 nathanw #define REG_DATA_BIT_04 0x0010
110 1.1.4.2 nathanw #define REG_DATA_BIT_05 0x0020
111 1.1.4.2 nathanw #define REG_DATA_BIT_08 0x0100
112 1.1.4.2 nathanw #define REG_DATA_BIT_07 0x0080
113 1.1.4.2 nathanw #define REG_DATA_BIT_0F 0x8000
114 1.1.4.2 nathanw
115 1.1.4.2 nathanw /***********************/
116 1.1.4.2 nathanw
117 1.1.4.2 nathanw typedef struct netdock_softc {
118 1.1.4.2 nathanw struct device sc_dev;
119 1.1.4.2 nathanw struct ethercom sc_ethercom;
120 1.1.4.2 nathanw #define sc_if sc_ethercom.ec_if
121 1.1.4.2 nathanw
122 1.1.4.2 nathanw bus_space_tag_t sc_regt;
123 1.1.4.2 nathanw bus_space_handle_t sc_regh;
124 1.1.4.2 nathanw
125 1.1.4.2 nathanw u_int8_t sc_enaddr[ETHER_ADDR_LEN];
126 1.1.4.2 nathanw
127 1.1.4.2 nathanw } netdock_softc_t;
128 1.1.4.2 nathanw
129 1.1.4.2 nathanw /***********************/
130 1.1.4.2 nathanw
131 1.1.4.2 nathanw static int netdock_nubus_match __P((struct device *, struct cfdata *,
132 1.1.4.2 nathanw void*));
133 1.1.4.2 nathanw static void netdock_nubus_attach __P((struct device *, struct device *,
134 1.1.4.2 nathanw void *));
135 1.1.4.2 nathanw static int netdock_nb_get_enaddr __P((bus_space_tag_t, bus_space_handle_t,
136 1.1.4.2 nathanw struct nubus_attach_args *, u_int8_t *));
137 1.1.4.2 nathanw #ifdef NETDOCK_DEBUG_DRIVER
138 1.1.4.2 nathanw static void netdock_print_driver __P((bus_space_tag_t, bus_space_handle_t,
139 1.1.4.2 nathanw struct nubus_attach_args *));
140 1.1.4.2 nathanw #endif
141 1.1.4.2 nathanw
142 1.1.4.2 nathanw int netdock_setup __P((struct netdock_softc *, u_int8_t *));
143 1.1.4.2 nathanw void netdock_intr __P((void *));
144 1.1.4.2 nathanw
145 1.1.4.2 nathanw static void netdock_watchdog __P((struct ifnet *));
146 1.1.4.2 nathanw static int netdock_init __P((struct netdock_softc *));
147 1.1.4.2 nathanw static int netdock_stop __P((struct netdock_softc *));
148 1.1.4.2 nathanw static int netdock_ioctl __P((struct ifnet *, u_long, caddr_t));
149 1.1.4.2 nathanw static void netdock_start __P((struct ifnet *));
150 1.1.4.2 nathanw static void netdock_reset __P((struct netdock_softc *));
151 1.1.4.2 nathanw static void netdock_txint __P((struct netdock_softc *));
152 1.1.4.2 nathanw static void netdock_rxint __P((struct netdock_softc *));
153 1.1.4.2 nathanw
154 1.1.4.2 nathanw static u_int netdock_put __P((struct netdock_softc *, struct mbuf *));
155 1.1.4.2 nathanw static int netdock_read __P((struct netdock_softc *, int));
156 1.1.4.2 nathanw static struct mbuf *netdock_get __P((struct netdock_softc *, int));
157 1.1.4.2 nathanw
158 1.1.4.2 nathanw /***********************/
159 1.1.4.2 nathanw
160 1.1.4.2 nathanw #define NIC_GET_1(sc, o) (bus_space_read_1((sc)->sc_regt, \
161 1.1.4.2 nathanw (sc)->sc_regh, (o)))
162 1.1.4.2 nathanw #define NIC_PUT_1(sc, o, val) (bus_space_write_1((sc)->sc_regt, \
163 1.1.4.2 nathanw (sc)->sc_regh, (o), (val)))
164 1.1.4.2 nathanw #define NIC_GET_2(sc, o) (bus_space_read_2((sc)->sc_regt, \
165 1.1.4.2 nathanw (sc)->sc_regh, (o)))
166 1.1.4.2 nathanw #define NIC_PUT_2(sc, o, val) (bus_space_write_2((sc)->sc_regt, \
167 1.1.4.2 nathanw (sc)->sc_regh, (o), (val)))
168 1.1.4.2 nathanw #define NIC_GET_4(sc, o) (bus_space_read_4((sc)->sc_regt, \
169 1.1.4.2 nathanw (sc)->sc_regh, (o)))
170 1.1.4.2 nathanw #define NIC_PUT_4(sc, o, val) (bus_space_write_4((sc)->sc_regt, \
171 1.1.4.2 nathanw (sc)->sc_regh, (o), (val)))
172 1.1.4.2 nathanw
173 1.1.4.2 nathanw #define NIC_BSET(sc, o, b) \
174 1.1.4.2 nathanw __asm__ __volatile("bset %0,%1" : : "di" ((u_short)(b)), \
175 1.1.4.2 nathanw "g" (*(u_int8_t *)((sc)->sc_regh.base + (o))))
176 1.1.4.2 nathanw #define NIC_BCLR(sc, o, b) \
177 1.1.4.2 nathanw __asm__ __volatile("bclr %0,%1" : : "di" ((u_short)(b)), \
178 1.1.4.2 nathanw "g" (*(u_int8_t *)((sc)->sc_regh.base + (o))))
179 1.1.4.2 nathanw #define NIC_ANDW(sc, o, b) \
180 1.1.4.2 nathanw __asm__ __volatile("andw %0,%1" : : "di" ((u_short)(b)), \
181 1.1.4.2 nathanw "g" (*(u_int8_t *)((sc)->sc_regh.base + (o))))
182 1.1.4.2 nathanw #define NIC_ORW(sc, o, b) \
183 1.1.4.2 nathanw __asm__ __volatile("orw %0,%1" : : "di" ((u_short)(b)), \
184 1.1.4.2 nathanw "g" (*(u_int8_t *)((sc)->sc_regh.base + (o))))
185 1.1.4.2 nathanw
186 1.1.4.2 nathanw
187 1.1.4.2 nathanw /***********************/
188 1.1.4.2 nathanw
189 1.1.4.3 nathanw CFATTACH_DECL(netdock_nubus, sizeof(struct netdock_softc),
190 1.1.4.3 nathanw netdock_nubus_match, netdock_nubus_attach, NULL, NULL);
191 1.1.4.2 nathanw
192 1.1.4.2 nathanw /***********************/
193 1.1.4.2 nathanw
194 1.1.4.2 nathanw static int
195 1.1.4.2 nathanw netdock_nubus_match(parent, cf, aux)
196 1.1.4.2 nathanw struct device *parent;
197 1.1.4.2 nathanw struct cfdata *cf;
198 1.1.4.2 nathanw void *aux;
199 1.1.4.2 nathanw {
200 1.1.4.2 nathanw struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
201 1.1.4.2 nathanw bus_space_handle_t bsh;
202 1.1.4.2 nathanw int rv;
203 1.1.4.2 nathanw
204 1.1.4.2 nathanw if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot),
205 1.1.4.2 nathanw NBMEMSIZE, 0, &bsh))
206 1.1.4.2 nathanw return (0);
207 1.1.4.2 nathanw
208 1.1.4.2 nathanw rv = 0;
209 1.1.4.2 nathanw
210 1.1.4.2 nathanw if (na->category == NETDOCK_NUBUS_CATEGORY &&
211 1.1.4.2 nathanw na->type == NETDOCK_NUBUS_TYPE &&
212 1.1.4.2 nathanw na->drsw == NETDOCK_NUBUS_DRSW) {
213 1.1.4.2 nathanw /* assuming this IS Asante NetDock */
214 1.1.4.2 nathanw rv = 1;
215 1.1.4.2 nathanw }
216 1.1.4.2 nathanw
217 1.1.4.2 nathanw if (na->category == ETHERMICRODOCK_NUBUS_CATEGORY &&
218 1.1.4.2 nathanw na->type == ETHERMICRODOCK_NUBUS_TYPE &&
219 1.1.4.2 nathanw na->drsw == ETHERMICRODOCK_NUBUS_DRSW) {
220 1.1.4.2 nathanw /* assuming this IS Newer EtherMicroDock */
221 1.1.4.2 nathanw rv = 1;
222 1.1.4.2 nathanw }
223 1.1.4.2 nathanw
224 1.1.4.2 nathanw bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
225 1.1.4.2 nathanw
226 1.1.4.2 nathanw return rv;
227 1.1.4.2 nathanw }
228 1.1.4.2 nathanw
229 1.1.4.2 nathanw static void
230 1.1.4.2 nathanw netdock_nubus_attach(parent, self, aux)
231 1.1.4.2 nathanw struct device *parent, *self;
232 1.1.4.2 nathanw void *aux;
233 1.1.4.2 nathanw {
234 1.1.4.2 nathanw struct netdock_softc *sc = (struct netdock_softc *)self;
235 1.1.4.2 nathanw struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
236 1.1.4.2 nathanw bus_space_tag_t bst;
237 1.1.4.2 nathanw bus_space_handle_t bsh;
238 1.1.4.2 nathanw u_int8_t enaddr[ETHER_ADDR_LEN];
239 1.1.4.2 nathanw char *cardtype;
240 1.1.4.2 nathanw
241 1.1.4.2 nathanw bst = na->na_tag;
242 1.1.4.2 nathanw if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
243 1.1.4.2 nathanw printf(": failed to map memory space.\n");
244 1.1.4.2 nathanw return;
245 1.1.4.2 nathanw }
246 1.1.4.2 nathanw
247 1.1.4.2 nathanw sc->sc_regt = bst;
248 1.1.4.2 nathanw cardtype = nubus_get_card_name(bst, bsh, na->fmt);
249 1.1.4.2 nathanw
250 1.1.4.2 nathanw #ifdef NETDOCK_DEBUG_DRIVER
251 1.1.4.2 nathanw netdock_print_driver(bst, bsh, na);
252 1.1.4.2 nathanw #endif
253 1.1.4.2 nathanw
254 1.1.4.2 nathanw if (netdock_nb_get_enaddr(bst, bsh, na, enaddr)) {
255 1.1.4.2 nathanw printf(": can't find MAC address.\n");
256 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
257 1.1.4.2 nathanw return;
258 1.1.4.2 nathanw }
259 1.1.4.2 nathanw
260 1.1.4.2 nathanw if (bus_space_subregion(bst, bsh, 0xe00300, 0xf0000, &sc->sc_regh)) {
261 1.1.4.2 nathanw printf(": failed to map register space.\n");
262 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
263 1.1.4.2 nathanw return;
264 1.1.4.2 nathanw }
265 1.1.4.2 nathanw
266 1.1.4.2 nathanw printf(": %s\n", cardtype);
267 1.1.4.2 nathanw
268 1.1.4.2 nathanw if (netdock_setup(sc, enaddr)) {
269 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
270 1.1.4.2 nathanw return;
271 1.1.4.2 nathanw }
272 1.1.4.2 nathanw
273 1.1.4.2 nathanw add_nubus_intr(na->slot, netdock_intr, (void *)sc);
274 1.1.4.2 nathanw
275 1.1.4.2 nathanw return;
276 1.1.4.2 nathanw }
277 1.1.4.2 nathanw
278 1.1.4.2 nathanw static int
279 1.1.4.2 nathanw netdock_nb_get_enaddr(bst, bsh, na, ep)
280 1.1.4.2 nathanw bus_space_tag_t bst;
281 1.1.4.2 nathanw bus_space_handle_t bsh;
282 1.1.4.2 nathanw struct nubus_attach_args *na;
283 1.1.4.2 nathanw u_int8_t *ep;
284 1.1.4.2 nathanw {
285 1.1.4.2 nathanw nubus_dir dir;
286 1.1.4.2 nathanw nubus_dirent dirent;
287 1.1.4.2 nathanw
288 1.1.4.2 nathanw /*
289 1.1.4.2 nathanw * these hardwired resource IDs are only for NetDock
290 1.1.4.2 nathanw */
291 1.1.4.2 nathanw nubus_get_main_dir(na->fmt, &dir);
292 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x81, &dirent) <= 0)
293 1.1.4.2 nathanw return 1;
294 1.1.4.2 nathanw nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
295 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x80, &dirent) <= 0)
296 1.1.4.2 nathanw return 1;
297 1.1.4.2 nathanw if (nubus_get_ind_data(bst, bsh, na->fmt, &dirent,
298 1.1.4.2 nathanw ep, ETHER_ADDR_LEN) <= 0)
299 1.1.4.2 nathanw return 1;
300 1.1.4.2 nathanw
301 1.1.4.2 nathanw return 0;
302 1.1.4.2 nathanw }
303 1.1.4.2 nathanw
304 1.1.4.2 nathanw #ifdef NETDOCK_DEBUG_DRIVER
305 1.1.4.2 nathanw static void
306 1.1.4.2 nathanw netdock_print_driver(bst, bsh, na)
307 1.1.4.2 nathanw bus_space_tag_t bst;
308 1.1.4.2 nathanw bus_space_handle_t bsh;
309 1.1.4.2 nathanw struct nubus_attach_args *na;
310 1.1.4.2 nathanw {
311 1.1.4.2 nathanw #define HEADSIZE (8+4)
312 1.1.4.2 nathanw #define CODESIZE (6759-4)
313 1.1.4.2 nathanw unsigned char mydata[HEADSIZE + CODESIZE];
314 1.1.4.2 nathanw nubus_dir dir;
315 1.1.4.2 nathanw nubus_dirent dirent;
316 1.1.4.2 nathanw int i, rv;
317 1.1.4.2 nathanw
318 1.1.4.2 nathanw nubus_get_main_dir(na->fmt, &dir);
319 1.1.4.2 nathanw rv = nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x81, &dirent);
320 1.1.4.2 nathanw if (rv <= 0) {
321 1.1.4.2 nathanw printf(": can't find sResource.\n");
322 1.1.4.2 nathanw return;
323 1.1.4.2 nathanw }
324 1.1.4.2 nathanw nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
325 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, NUBUS_RSRC_DRVRDIR,
326 1.1.4.2 nathanw &dirent) <= 0) {
327 1.1.4.2 nathanw printf(": can't find sResource.\n");
328 1.1.4.2 nathanw return;
329 1.1.4.2 nathanw }
330 1.1.4.2 nathanw if (nubus_get_ind_data(bst, bsh, na->fmt,
331 1.1.4.2 nathanw &dirent, mydata, HEADSIZE+CODESIZE) <= 0) {
332 1.1.4.2 nathanw printf(": can't find indirect data.\n");
333 1.1.4.2 nathanw return;
334 1.1.4.2 nathanw }
335 1.1.4.2 nathanw printf("\n########## begin driver dir");
336 1.1.4.2 nathanw for (i = 0; i < HEADSIZE; i++) {
337 1.1.4.2 nathanw if (i % 16 == 0)
338 1.1.4.2 nathanw printf("\n%02x:",i);
339 1.1.4.2 nathanw printf(" %02x", mydata[i]);
340 1.1.4.2 nathanw }
341 1.1.4.2 nathanw printf("\n########## begin driver code");
342 1.1.4.2 nathanw for (i = 0; i < CODESIZE; i++) {
343 1.1.4.2 nathanw if (i % 16 == 0)
344 1.1.4.2 nathanw printf("\n%02x:",i);
345 1.1.4.2 nathanw printf(" %02x", mydata[i + HEADSIZE]);
346 1.1.4.2 nathanw }
347 1.1.4.2 nathanw #if 0
348 1.1.4.2 nathanw printf("\n########## begin driver code (partial)\n");
349 1.1.4.2 nathanw #define PARTSIZE 256
350 1.1.4.2 nathanw #define OFFSET 0x1568
351 1.1.4.2 nathanw for (i = OFFSET; i < OFFSET + PARTSIZE; i++) {
352 1.1.4.2 nathanw if ((i - OFFSET) % 16 == 0)
353 1.1.4.2 nathanw printf("\n%02x:",i);
354 1.1.4.2 nathanw printf(" %02x", mydata[i + HEADSIZE]);
355 1.1.4.2 nathanw }
356 1.1.4.2 nathanw #endif
357 1.1.4.2 nathanw printf("\n########## end\n");
358 1.1.4.2 nathanw }
359 1.1.4.2 nathanw #endif
360 1.1.4.2 nathanw
361 1.1.4.2 nathanw
362 1.1.4.2 nathanw int
363 1.1.4.2 nathanw netdock_setup(sc, lladdr)
364 1.1.4.2 nathanw struct netdock_softc *sc;
365 1.1.4.2 nathanw u_int8_t *lladdr;
366 1.1.4.2 nathanw {
367 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
368 1.1.4.2 nathanw
369 1.1.4.2 nathanw bcopy(lladdr, sc->sc_enaddr, ETHER_ADDR_LEN);
370 1.1.4.2 nathanw printf("%s: Ethernet address %s\n",
371 1.1.4.2 nathanw sc->sc_dev.dv_xname, ether_sprintf(lladdr));
372 1.1.4.2 nathanw
373 1.1.4.2 nathanw bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
374 1.1.4.2 nathanw ifp->if_softc = sc;
375 1.1.4.2 nathanw ifp->if_ioctl = netdock_ioctl;
376 1.1.4.2 nathanw ifp->if_start = netdock_start;
377 1.1.4.2 nathanw ifp->if_flags =
378 1.1.4.2 nathanw IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
379 1.1.4.2 nathanw ifp->if_watchdog = netdock_watchdog;
380 1.1.4.2 nathanw
381 1.1.4.2 nathanw if_attach(ifp);
382 1.1.4.2 nathanw ether_ifattach(ifp, lladdr);
383 1.1.4.2 nathanw
384 1.1.4.2 nathanw return (0);
385 1.1.4.2 nathanw }
386 1.1.4.2 nathanw
387 1.1.4.2 nathanw static int
388 1.1.4.2 nathanw netdock_ioctl(ifp, cmd, data)
389 1.1.4.2 nathanw struct ifnet *ifp;
390 1.1.4.2 nathanw u_long cmd;
391 1.1.4.2 nathanw caddr_t data;
392 1.1.4.2 nathanw {
393 1.1.4.2 nathanw struct ifaddr *ifa;
394 1.1.4.2 nathanw struct ifreq *ifr;
395 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
396 1.1.4.2 nathanw int s = splnet();
397 1.1.4.2 nathanw int err = 0;
398 1.1.4.2 nathanw int temp;
399 1.1.4.2 nathanw
400 1.1.4.2 nathanw switch (cmd) {
401 1.1.4.2 nathanw case SIOCSIFADDR:
402 1.1.4.2 nathanw ifa = (struct ifaddr *)data;
403 1.1.4.2 nathanw ifp->if_flags |= IFF_UP;
404 1.1.4.2 nathanw switch (ifa->ifa_addr->sa_family) {
405 1.1.4.2 nathanw #ifdef INET
406 1.1.4.2 nathanw case AF_INET:
407 1.1.4.2 nathanw (void)netdock_init(sc);
408 1.1.4.2 nathanw arp_ifinit(ifp, ifa);
409 1.1.4.2 nathanw break;
410 1.1.4.2 nathanw #endif
411 1.1.4.2 nathanw default:
412 1.1.4.2 nathanw (void)netdock_init(sc);
413 1.1.4.2 nathanw break;
414 1.1.4.2 nathanw }
415 1.1.4.2 nathanw break;
416 1.1.4.2 nathanw
417 1.1.4.2 nathanw case SIOCSIFFLAGS:
418 1.1.4.2 nathanw if ((ifp->if_flags & IFF_UP) == 0 &&
419 1.1.4.2 nathanw (ifp->if_flags & IFF_RUNNING) != 0) {
420 1.1.4.2 nathanw netdock_stop(sc);
421 1.1.4.2 nathanw ifp->if_flags &= ~IFF_RUNNING;
422 1.1.4.2 nathanw } else if ((ifp->if_flags & IFF_UP) != 0 &&
423 1.1.4.2 nathanw (ifp->if_flags & IFF_RUNNING) == 0) {
424 1.1.4.2 nathanw (void)netdock_init(sc);
425 1.1.4.2 nathanw } else {
426 1.1.4.2 nathanw temp = ifp->if_flags & IFF_UP;
427 1.1.4.2 nathanw netdock_reset(sc);
428 1.1.4.2 nathanw ifp->if_flags |= temp;
429 1.1.4.2 nathanw netdock_start(ifp);
430 1.1.4.2 nathanw }
431 1.1.4.2 nathanw break;
432 1.1.4.2 nathanw
433 1.1.4.2 nathanw case SIOCADDMULTI:
434 1.1.4.2 nathanw case SIOCDELMULTI:
435 1.1.4.2 nathanw ifr = (struct ifreq *)data;
436 1.1.4.2 nathanw if (cmd == SIOCADDMULTI)
437 1.1.4.2 nathanw err = ether_addmulti(ifr, &sc->sc_ethercom);
438 1.1.4.2 nathanw else
439 1.1.4.2 nathanw err = ether_delmulti(ifr, &sc->sc_ethercom);
440 1.1.4.2 nathanw
441 1.1.4.2 nathanw if (err == ENETRESET) {
442 1.1.4.2 nathanw temp = ifp->if_flags & IFF_UP;
443 1.1.4.2 nathanw netdock_reset(sc);
444 1.1.4.2 nathanw ifp->if_flags |= temp;
445 1.1.4.2 nathanw err = 0;
446 1.1.4.2 nathanw }
447 1.1.4.2 nathanw break;
448 1.1.4.2 nathanw default:
449 1.1.4.2 nathanw err = EINVAL;
450 1.1.4.2 nathanw break;
451 1.1.4.2 nathanw }
452 1.1.4.2 nathanw splx(s);
453 1.1.4.2 nathanw return (err);
454 1.1.4.2 nathanw }
455 1.1.4.2 nathanw
456 1.1.4.2 nathanw static void
457 1.1.4.2 nathanw netdock_start(ifp)
458 1.1.4.2 nathanw struct ifnet *ifp;
459 1.1.4.2 nathanw {
460 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
461 1.1.4.2 nathanw struct mbuf *m;
462 1.1.4.2 nathanw
463 1.1.4.2 nathanw if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
464 1.1.4.2 nathanw return;
465 1.1.4.2 nathanw
466 1.1.4.2 nathanw while (1) {
467 1.1.4.2 nathanw IF_DEQUEUE(&ifp->if_snd, m);
468 1.1.4.2 nathanw if (m == 0)
469 1.1.4.2 nathanw return;
470 1.1.4.2 nathanw
471 1.1.4.2 nathanw if ((m->m_flags & M_PKTHDR) == 0)
472 1.1.4.2 nathanw panic("%s: netdock_start: no header mbuf",
473 1.1.4.2 nathanw sc->sc_dev.dv_xname);
474 1.1.4.2 nathanw
475 1.1.4.2 nathanw #if NBPFILTER > 0
476 1.1.4.2 nathanw if (ifp->if_bpf)
477 1.1.4.2 nathanw bpf_mtap(ifp->if_bpf, m);
478 1.1.4.2 nathanw #endif
479 1.1.4.2 nathanw
480 1.1.4.2 nathanw if ((netdock_put(sc, m)) == 0) {
481 1.1.4.2 nathanw IF_PREPEND(&ifp->if_snd, m);
482 1.1.4.2 nathanw return;
483 1.1.4.2 nathanw }
484 1.1.4.2 nathanw
485 1.1.4.2 nathanw ifp->if_opackets++;
486 1.1.4.2 nathanw }
487 1.1.4.2 nathanw
488 1.1.4.2 nathanw }
489 1.1.4.2 nathanw
490 1.1.4.2 nathanw static void
491 1.1.4.2 nathanw netdock_reset(sc)
492 1.1.4.2 nathanw struct netdock_softc *sc;
493 1.1.4.2 nathanw {
494 1.1.4.2 nathanw
495 1.1.4.2 nathanw netdock_stop(sc);
496 1.1.4.2 nathanw netdock_init(sc);
497 1.1.4.2 nathanw }
498 1.1.4.2 nathanw
499 1.1.4.2 nathanw static int
500 1.1.4.2 nathanw netdock_init(sc)
501 1.1.4.2 nathanw struct netdock_softc *sc;
502 1.1.4.2 nathanw {
503 1.1.4.2 nathanw int s;
504 1.1.4.2 nathanw int saveisr;
505 1.1.4.2 nathanw int savetmp;
506 1.1.4.2 nathanw
507 1.1.4.2 nathanw if (sc->sc_if.if_flags & IFF_RUNNING)
508 1.1.4.2 nathanw return (0);
509 1.1.4.2 nathanw
510 1.1.4.2 nathanw s = splnet();
511 1.1.4.2 nathanw
512 1.1.4.2 nathanw /* 0606 */
513 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
514 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0);
515 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
516 1.1.4.2 nathanw
517 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8104);
518 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0004, 0x0043);
519 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
520 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, 0x6618);
521 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8010);
522 1.1.4.2 nathanw
523 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 0, sc->sc_enaddr[0]);
524 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 1, sc->sc_enaddr[1]);
525 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 2, sc->sc_enaddr[2]);
526 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 3, sc->sc_enaddr[3]);
527 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 4, sc->sc_enaddr[4]);
528 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 5, sc->sc_enaddr[5]);
529 1.1.4.2 nathanw
530 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0x2008);
531 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
532 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x4000);
533 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_MASK);
534 1.1.4.2 nathanw
535 1.1.4.2 nathanw
536 1.1.4.2 nathanw /* 1320 */
537 1.1.4.2 nathanw saveisr = NIC_GET_2(sc, REG_ISR);
538 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0);
539 1.1.4.2 nathanw savetmp = NIC_GET_2(sc, REG_000E);
540 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
541 1.1.4.2 nathanw NIC_ANDW(sc, REG_ISR, ~ISR_BIT_03);
542 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, savetmp);
543 1.1.4.2 nathanw
544 1.1.4.2 nathanw /* 1382 */
545 1.1.4.2 nathanw savetmp = NIC_GET_2(sc, REG_000E);
546 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
547 1.1.4.2 nathanw NIC_ORW(sc, REG_ISR, ISR_BIT_03);
548 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, savetmp);
549 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , saveisr);
550 1.1.4.2 nathanw
551 1.1.4.2 nathanw
552 1.1.4.2 nathanw sc->sc_if.if_flags |= IFF_RUNNING;
553 1.1.4.2 nathanw sc->sc_if.if_flags &= ~IFF_OACTIVE;
554 1.1.4.2 nathanw
555 1.1.4.2 nathanw splx(s);
556 1.1.4.2 nathanw return (0);
557 1.1.4.2 nathanw }
558 1.1.4.2 nathanw
559 1.1.4.2 nathanw static int
560 1.1.4.2 nathanw netdock_stop(sc)
561 1.1.4.2 nathanw struct netdock_softc *sc;
562 1.1.4.2 nathanw {
563 1.1.4.2 nathanw int s = splnet();
564 1.1.4.2 nathanw
565 1.1.4.2 nathanw sc->sc_if.if_timer = 0;
566 1.1.4.2 nathanw sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_UP);
567 1.1.4.2 nathanw
568 1.1.4.2 nathanw splx(s);
569 1.1.4.2 nathanw return (0);
570 1.1.4.2 nathanw }
571 1.1.4.2 nathanw
572 1.1.4.2 nathanw static void
573 1.1.4.2 nathanw netdock_watchdog(ifp)
574 1.1.4.2 nathanw struct ifnet *ifp;
575 1.1.4.2 nathanw {
576 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
577 1.1.4.2 nathanw int tmp;
578 1.1.4.2 nathanw
579 1.1.4.2 nathanw printf("netdock_watchdog: resetting chip\n");
580 1.1.4.2 nathanw tmp = ifp->if_flags & IFF_UP;
581 1.1.4.2 nathanw netdock_reset(sc);
582 1.1.4.2 nathanw ifp->if_flags |= tmp;
583 1.1.4.2 nathanw }
584 1.1.4.2 nathanw
585 1.1.4.2 nathanw static u_int
586 1.1.4.2 nathanw netdock_put(sc, m0)
587 1.1.4.2 nathanw struct netdock_softc *sc;
588 1.1.4.2 nathanw struct mbuf *m0;
589 1.1.4.2 nathanw {
590 1.1.4.2 nathanw struct mbuf *m;
591 1.1.4.2 nathanw u_int totlen = 0;
592 1.1.4.2 nathanw u_int tmplen;
593 1.1.4.2 nathanw int isr;
594 1.1.4.2 nathanw int timeout;
595 1.1.4.2 nathanw int tmp;
596 1.1.4.2 nathanw u_int i;
597 1.1.4.2 nathanw
598 1.1.4.2 nathanw for (m = m0; m; m = m->m_next)
599 1.1.4.2 nathanw totlen += m->m_len;
600 1.1.4.2 nathanw
601 1.1.4.2 nathanw if (totlen >= ETHER_MAX_LEN)
602 1.1.4.2 nathanw panic("%s: netdock_put: packet overflow", sc->sc_dev.dv_xname);
603 1.1.4.2 nathanw
604 1.1.4.2 nathanw totlen += 6;
605 1.1.4.2 nathanw tmplen = totlen;
606 1.1.4.2 nathanw tmplen &= 0xff00;
607 1.1.4.2 nathanw tmplen |= 0x2000;
608 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, tmplen);
609 1.1.4.2 nathanw
610 1.1.4.2 nathanw timeout = 0x3000;
611 1.1.4.2 nathanw while ((((isr = NIC_GET_2(sc, REG_ISR)) & ISR_READY) == 0) &&
612 1.1.4.2 nathanw timeout--) {
613 1.1.4.2 nathanw if (isr & ISR_TX)
614 1.1.4.2 nathanw netdock_txint(sc);
615 1.1.4.2 nathanw }
616 1.1.4.2 nathanw if (timeout == 0)
617 1.1.4.2 nathanw return (0);
618 1.1.4.2 nathanw
619 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0002);
620 1.1.4.2 nathanw tmp <<= 8;
621 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, tmp);
622 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x240);
623 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
624 1.1.4.2 nathanw tmplen = ((totlen << 8) & 0xfe00) | ((totlen >> 8) & 0x00ff);
625 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, tmplen);
626 1.1.4.2 nathanw
627 1.1.4.2 nathanw for (m = m0; m; m = m->m_next) {
628 1.1.4.2 nathanw u_char *data = mtod(m, u_char *);
629 1.1.4.2 nathanw int len = m->m_len;
630 1.1.4.2 nathanw int len4 = len >> 2;
631 1.1.4.2 nathanw u_int32_t *data4 = (u_int32_t *)data;
632 1.1.4.2 nathanw for (i = 0; i < len4; i++)
633 1.1.4.2 nathanw NIC_PUT_4(sc, REG_DATA, data4[i]);
634 1.1.4.2 nathanw for (i = len4 << 2; i < len; i++)
635 1.1.4.2 nathanw NIC_PUT_1(sc, REG_DATA, data[i]);
636 1.1.4.2 nathanw }
637 1.1.4.2 nathanw
638 1.1.4.2 nathanw if (totlen & 0x01)
639 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, 0x2020);
640 1.1.4.2 nathanw else
641 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, 0);
642 1.1.4.2 nathanw
643 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0xc000);
644 1.1.4.2 nathanw
645 1.1.4.2 nathanw m_freem(m0);
646 1.1.4.2 nathanw /* sc->sc_if.if_timer = 5; */
647 1.1.4.2 nathanw return (totlen);
648 1.1.4.2 nathanw }
649 1.1.4.2 nathanw
650 1.1.4.2 nathanw void
651 1.1.4.2 nathanw netdock_intr(arg)
652 1.1.4.2 nathanw void *arg;
653 1.1.4.2 nathanw {
654 1.1.4.2 nathanw struct netdock_softc *sc = (struct netdock_softc *)arg;
655 1.1.4.2 nathanw int isr;
656 1.1.4.2 nathanw int tmp;
657 1.1.4.2 nathanw
658 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, 0);
659 1.1.4.2 nathanw while ((isr = (NIC_GET_2(sc, REG_ISR) & ISR_ALL)) != 0) {
660 1.1.4.2 nathanw if (isr & ISR_TX)
661 1.1.4.2 nathanw netdock_txint(sc);
662 1.1.4.2 nathanw
663 1.1.4.2 nathanw if (isr & ISR_RX)
664 1.1.4.2 nathanw netdock_rxint(sc);
665 1.1.4.2 nathanw
666 1.1.4.2 nathanw if (isr & (ISR_BIT_0C | ISR_BIT_0D)) {
667 1.1.4.2 nathanw if (isr & ISR_BIT_0C) {
668 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
669 1.1.4.2 nathanw NIC_BSET(sc, REG_0004, 0x08);
670 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
671 1.1.4.2 nathanw }
672 1.1.4.2 nathanw if (isr & ISR_BIT_0D) {
673 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
674 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0002);
675 1.1.4.2 nathanw if (tmp & REG_0002_BIT_04)
676 1.1.4.2 nathanw NIC_GET_2(sc, REG_0006);
677 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0000);
678 1.1.4.2 nathanw if (tmp & REG_0000_BIT_08)
679 1.1.4.2 nathanw NIC_BSET(sc, REG_0000, 0x08);
680 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
681 1.1.4.2 nathanw }
682 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, isr);
683 1.1.4.2 nathanw }
684 1.1.4.2 nathanw }
685 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_MASK);
686 1.1.4.2 nathanw }
687 1.1.4.2 nathanw
688 1.1.4.2 nathanw static void
689 1.1.4.2 nathanw netdock_txint(sc)
690 1.1.4.2 nathanw struct netdock_softc *sc;
691 1.1.4.2 nathanw {
692 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
693 1.1.4.2 nathanw int savereg0002;
694 1.1.4.2 nathanw int reg0004;
695 1.1.4.2 nathanw int regdata;
696 1.1.4.2 nathanw
697 1.1.4.2 nathanw ifp->if_flags &= ~IFF_OACTIVE;
698 1.1.4.2 nathanw ifp->if_timer = 0;
699 1.1.4.2 nathanw
700 1.1.4.2 nathanw savereg0002 = NIC_GET_2(sc, REG_0002);
701 1.1.4.2 nathanw
702 1.1.4.2 nathanw while (((reg0004 = NIC_GET_2(sc, REG_0004)) & REG_0004_BIT_0F) == 0) {
703 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, reg0004);
704 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x0060);
705 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
706 1.1.4.2 nathanw regdata = NIC_GET_2(sc, REG_DATA);
707 1.1.4.2 nathanw if ((regdata & REG_DATA_BIT_08) == 0) {
708 1.1.4.2 nathanw /* ifp->if_collisions++; */
709 1.1.4.2 nathanw if (regdata & REG_DATA_BIT_07)
710 1.1.4.2 nathanw /* ifp->if_oerrors++; */
711 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
712 1.1.4.2 nathanw NIC_ORW(sc, REG_0000, 0x0100);
713 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
714 1.1.4.2 nathanw }
715 1.1.4.2 nathanw NIC_GET_2(sc ,REG_DATA);
716 1.1.4.2 nathanw
717 1.1.4.2 nathanw if (regdata & REG_DATA_BIT_0F)
718 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
719 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0xa000);
720 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_TX);
721 1.1.4.2 nathanw }
722 1.1.4.2 nathanw
723 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, savereg0002);
724 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
725 1.1.4.2 nathanw NIC_GET_2(sc, REG_0006);
726 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
727 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0);
728 1.1.4.2 nathanw }
729 1.1.4.2 nathanw
730 1.1.4.2 nathanw static void
731 1.1.4.2 nathanw netdock_rxint(sc)
732 1.1.4.2 nathanw struct netdock_softc *sc;
733 1.1.4.2 nathanw {
734 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
735 1.1.4.2 nathanw int regdata1;
736 1.1.4.2 nathanw int regdata2;
737 1.1.4.2 nathanw u_int len;
738 1.1.4.2 nathanw int timeout;
739 1.1.4.2 nathanw
740 1.1.4.2 nathanw while ((NIC_GET_2(sc, REG_0004) & REG_0004_BIT_07) == 0) {
741 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
742 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x00e0);
743 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
744 1.1.4.2 nathanw regdata1 = NIC_GET_2(sc, REG_DATA);
745 1.1.4.2 nathanw regdata2 = NIC_GET_2(sc, REG_DATA);
746 1.1.4.2 nathanw len = ((regdata2 << 8) & 0x0700) | ((regdata2 >> 8) & 0x00ff);
747 1.1.4.2 nathanw
748 1.1.4.2 nathanw #if 0
749 1.1.4.2 nathanw printf("netdock_rxint: r1=0x%04x, r2=0x%04x, len=%d\n",
750 1.1.4.2 nathanw regdata1, regdata2, len);
751 1.1.4.2 nathanw #endif
752 1.1.4.2 nathanw
753 1.1.4.2 nathanw if ((regdata1 & REG_DATA_BIT_04) == 0)
754 1.1.4.2 nathanw len -= 2;
755 1.1.4.2 nathanw
756 1.1.4.2 nathanw if ((regdata1 & 0x00ac) == 0) {
757 1.1.4.2 nathanw if (netdock_read(sc, len))
758 1.1.4.2 nathanw ifp->if_ipackets++;
759 1.1.4.2 nathanw else
760 1.1.4.2 nathanw ifp->if_ierrors++;
761 1.1.4.2 nathanw } else {
762 1.1.4.2 nathanw ifp->if_ierrors++;
763 1.1.4.2 nathanw
764 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_02)
765 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
766 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_03)
767 1.1.4.2 nathanw ;
768 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_05)
769 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
770 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_07)
771 1.1.4.2 nathanw ;
772 1.1.4.2 nathanw }
773 1.1.4.2 nathanw
774 1.1.4.2 nathanw timeout = 0x14;
775 1.1.4.2 nathanw while ((NIC_GET_2(sc, REG_0000) & REG_0000_BIT_08) && timeout--)
776 1.1.4.2 nathanw ;
777 1.1.4.2 nathanw if (timeout == 0)
778 1.1.4.2 nathanw ;
779 1.1.4.2 nathanw
780 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8000);
781 1.1.4.2 nathanw }
782 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0);
783 1.1.4.2 nathanw }
784 1.1.4.2 nathanw
785 1.1.4.2 nathanw static int
786 1.1.4.2 nathanw netdock_read(sc, len)
787 1.1.4.2 nathanw struct netdock_softc *sc;
788 1.1.4.2 nathanw int len;
789 1.1.4.2 nathanw {
790 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
791 1.1.4.2 nathanw struct mbuf *m;
792 1.1.4.2 nathanw
793 1.1.4.2 nathanw m = netdock_get(sc, len);
794 1.1.4.2 nathanw if (m == 0)
795 1.1.4.2 nathanw return (0);
796 1.1.4.2 nathanw
797 1.1.4.2 nathanw /* the data comes with frame checksum and ethernet header */
798 1.1.4.2 nathanw m->m_flags |= M_HASFCS;
799 1.1.4.2 nathanw
800 1.1.4.2 nathanw #if NBPFILTER > 0
801 1.1.4.2 nathanw if (ifp->if_bpf)
802 1.1.4.2 nathanw bpf_mtap(ifp->if_bpf, m);
803 1.1.4.2 nathanw #endif
804 1.1.4.2 nathanw
805 1.1.4.2 nathanw (*ifp->if_input)(ifp, m);
806 1.1.4.2 nathanw
807 1.1.4.2 nathanw return (1);
808 1.1.4.2 nathanw }
809 1.1.4.2 nathanw
810 1.1.4.2 nathanw static struct mbuf *
811 1.1.4.2 nathanw netdock_get(sc, datalen)
812 1.1.4.2 nathanw struct netdock_softc *sc;
813 1.1.4.2 nathanw int datalen;
814 1.1.4.2 nathanw {
815 1.1.4.2 nathanw struct mbuf *m, *top, **mp;
816 1.1.4.2 nathanw u_char *data;
817 1.1.4.2 nathanw int i;
818 1.1.4.2 nathanw int len;
819 1.1.4.2 nathanw int len4;
820 1.1.4.2 nathanw u_int32_t *data4;
821 1.1.4.2 nathanw
822 1.1.4.2 nathanw MGETHDR(m, M_DONTWAIT, MT_DATA);
823 1.1.4.2 nathanw if (m == NULL)
824 1.1.4.2 nathanw return (NULL);
825 1.1.4.2 nathanw m->m_pkthdr.rcvif = &sc->sc_if;
826 1.1.4.2 nathanw m->m_pkthdr.len = datalen;
827 1.1.4.2 nathanw len = MHLEN;
828 1.1.4.2 nathanw top = NULL;
829 1.1.4.2 nathanw mp = ⊤
830 1.1.4.2 nathanw
831 1.1.4.2 nathanw while (datalen > 0) {
832 1.1.4.2 nathanw if (top) {
833 1.1.4.2 nathanw MGET(m, M_DONTWAIT, MT_DATA);
834 1.1.4.2 nathanw if (m == 0) {
835 1.1.4.2 nathanw m_freem(top);
836 1.1.4.2 nathanw return (NULL);
837 1.1.4.2 nathanw }
838 1.1.4.2 nathanw len = MLEN;
839 1.1.4.2 nathanw }
840 1.1.4.2 nathanw if (datalen >= MINCLSIZE) {
841 1.1.4.2 nathanw MCLGET(m, M_DONTWAIT);
842 1.1.4.2 nathanw if ((m->m_flags & M_EXT) == 0) {
843 1.1.4.2 nathanw if (top)
844 1.1.4.2 nathanw m_freem(top);
845 1.1.4.2 nathanw return (NULL);
846 1.1.4.2 nathanw }
847 1.1.4.2 nathanw len = MCLBYTES;
848 1.1.4.2 nathanw }
849 1.1.4.2 nathanw
850 1.1.4.2 nathanw if (mp == &top) {
851 1.1.4.2 nathanw caddr_t newdata = (caddr_t)
852 1.1.4.2 nathanw ALIGN(m->m_data + sizeof(struct ether_header)) -
853 1.1.4.2 nathanw sizeof(struct ether_header);
854 1.1.4.2 nathanw len -= newdata - m->m_data;
855 1.1.4.2 nathanw m->m_data = newdata;
856 1.1.4.2 nathanw }
857 1.1.4.2 nathanw
858 1.1.4.2 nathanw m->m_len = len = min(datalen, len);
859 1.1.4.2 nathanw
860 1.1.4.2 nathanw data = mtod(m, u_char *);
861 1.1.4.2 nathanw len4 = len >> 2;
862 1.1.4.2 nathanw data4 = (u_int32_t *)data;
863 1.1.4.2 nathanw for (i = 0; i < len4; i++)
864 1.1.4.2 nathanw data4[i] = NIC_GET_4(sc, REG_DATA);
865 1.1.4.2 nathanw for (i = len4 << 2; i < len; i++)
866 1.1.4.2 nathanw data[i] = NIC_GET_1(sc, REG_DATA);
867 1.1.4.2 nathanw
868 1.1.4.2 nathanw datalen -= len;
869 1.1.4.2 nathanw *mp = m;
870 1.1.4.2 nathanw mp = &m->m_next;
871 1.1.4.2 nathanw }
872 1.1.4.2 nathanw
873 1.1.4.2 nathanw return (top);
874 1.1.4.2 nathanw }
875