if_netdock_nubus.c revision 1.1.4.2 1 1.1.4.2 nathanw /* $NetBSD: if_netdock_nubus.c,v 1.1.4.2 2002/08/01 02:42:22 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.2 nathanw struct cfattach netdock_nubus_ca = {
190 1.1.4.2 nathanw sizeof(struct netdock_softc), netdock_nubus_match, netdock_nubus_attach
191 1.1.4.2 nathanw };
192 1.1.4.2 nathanw
193 1.1.4.2 nathanw /***********************/
194 1.1.4.2 nathanw
195 1.1.4.2 nathanw static int
196 1.1.4.2 nathanw netdock_nubus_match(parent, cf, aux)
197 1.1.4.2 nathanw struct device *parent;
198 1.1.4.2 nathanw struct cfdata *cf;
199 1.1.4.2 nathanw void *aux;
200 1.1.4.2 nathanw {
201 1.1.4.2 nathanw struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
202 1.1.4.2 nathanw bus_space_handle_t bsh;
203 1.1.4.2 nathanw int rv;
204 1.1.4.2 nathanw
205 1.1.4.2 nathanw if (bus_space_map(na->na_tag, NUBUS_SLOT2PA(na->slot),
206 1.1.4.2 nathanw NBMEMSIZE, 0, &bsh))
207 1.1.4.2 nathanw return (0);
208 1.1.4.2 nathanw
209 1.1.4.2 nathanw rv = 0;
210 1.1.4.2 nathanw
211 1.1.4.2 nathanw if (na->category == NETDOCK_NUBUS_CATEGORY &&
212 1.1.4.2 nathanw na->type == NETDOCK_NUBUS_TYPE &&
213 1.1.4.2 nathanw na->drsw == NETDOCK_NUBUS_DRSW) {
214 1.1.4.2 nathanw /* assuming this IS Asante NetDock */
215 1.1.4.2 nathanw rv = 1;
216 1.1.4.2 nathanw }
217 1.1.4.2 nathanw
218 1.1.4.2 nathanw if (na->category == ETHERMICRODOCK_NUBUS_CATEGORY &&
219 1.1.4.2 nathanw na->type == ETHERMICRODOCK_NUBUS_TYPE &&
220 1.1.4.2 nathanw na->drsw == ETHERMICRODOCK_NUBUS_DRSW) {
221 1.1.4.2 nathanw /* assuming this IS Newer EtherMicroDock */
222 1.1.4.2 nathanw rv = 1;
223 1.1.4.2 nathanw }
224 1.1.4.2 nathanw
225 1.1.4.2 nathanw bus_space_unmap(na->na_tag, bsh, NBMEMSIZE);
226 1.1.4.2 nathanw
227 1.1.4.2 nathanw return rv;
228 1.1.4.2 nathanw }
229 1.1.4.2 nathanw
230 1.1.4.2 nathanw static void
231 1.1.4.2 nathanw netdock_nubus_attach(parent, self, aux)
232 1.1.4.2 nathanw struct device *parent, *self;
233 1.1.4.2 nathanw void *aux;
234 1.1.4.2 nathanw {
235 1.1.4.2 nathanw struct netdock_softc *sc = (struct netdock_softc *)self;
236 1.1.4.2 nathanw struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
237 1.1.4.2 nathanw bus_space_tag_t bst;
238 1.1.4.2 nathanw bus_space_handle_t bsh;
239 1.1.4.2 nathanw u_int8_t enaddr[ETHER_ADDR_LEN];
240 1.1.4.2 nathanw char *cardtype;
241 1.1.4.2 nathanw
242 1.1.4.2 nathanw bst = na->na_tag;
243 1.1.4.2 nathanw if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) {
244 1.1.4.2 nathanw printf(": failed to map memory space.\n");
245 1.1.4.2 nathanw return;
246 1.1.4.2 nathanw }
247 1.1.4.2 nathanw
248 1.1.4.2 nathanw sc->sc_regt = bst;
249 1.1.4.2 nathanw cardtype = nubus_get_card_name(bst, bsh, na->fmt);
250 1.1.4.2 nathanw
251 1.1.4.2 nathanw #ifdef NETDOCK_DEBUG_DRIVER
252 1.1.4.2 nathanw netdock_print_driver(bst, bsh, na);
253 1.1.4.2 nathanw #endif
254 1.1.4.2 nathanw
255 1.1.4.2 nathanw if (netdock_nb_get_enaddr(bst, bsh, na, enaddr)) {
256 1.1.4.2 nathanw printf(": can't find MAC address.\n");
257 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
258 1.1.4.2 nathanw return;
259 1.1.4.2 nathanw }
260 1.1.4.2 nathanw
261 1.1.4.2 nathanw if (bus_space_subregion(bst, bsh, 0xe00300, 0xf0000, &sc->sc_regh)) {
262 1.1.4.2 nathanw printf(": failed to map register space.\n");
263 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
264 1.1.4.2 nathanw return;
265 1.1.4.2 nathanw }
266 1.1.4.2 nathanw
267 1.1.4.2 nathanw printf(": %s\n", cardtype);
268 1.1.4.2 nathanw
269 1.1.4.2 nathanw if (netdock_setup(sc, enaddr)) {
270 1.1.4.2 nathanw bus_space_unmap(bst, bsh, NBMEMSIZE);
271 1.1.4.2 nathanw return;
272 1.1.4.2 nathanw }
273 1.1.4.2 nathanw
274 1.1.4.2 nathanw add_nubus_intr(na->slot, netdock_intr, (void *)sc);
275 1.1.4.2 nathanw
276 1.1.4.2 nathanw return;
277 1.1.4.2 nathanw }
278 1.1.4.2 nathanw
279 1.1.4.2 nathanw static int
280 1.1.4.2 nathanw netdock_nb_get_enaddr(bst, bsh, na, ep)
281 1.1.4.2 nathanw bus_space_tag_t bst;
282 1.1.4.2 nathanw bus_space_handle_t bsh;
283 1.1.4.2 nathanw struct nubus_attach_args *na;
284 1.1.4.2 nathanw u_int8_t *ep;
285 1.1.4.2 nathanw {
286 1.1.4.2 nathanw nubus_dir dir;
287 1.1.4.2 nathanw nubus_dirent dirent;
288 1.1.4.2 nathanw
289 1.1.4.2 nathanw /*
290 1.1.4.2 nathanw * these hardwired resource IDs are only for NetDock
291 1.1.4.2 nathanw */
292 1.1.4.2 nathanw nubus_get_main_dir(na->fmt, &dir);
293 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x81, &dirent) <= 0)
294 1.1.4.2 nathanw return 1;
295 1.1.4.2 nathanw nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
296 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x80, &dirent) <= 0)
297 1.1.4.2 nathanw return 1;
298 1.1.4.2 nathanw if (nubus_get_ind_data(bst, bsh, na->fmt, &dirent,
299 1.1.4.2 nathanw ep, ETHER_ADDR_LEN) <= 0)
300 1.1.4.2 nathanw return 1;
301 1.1.4.2 nathanw
302 1.1.4.2 nathanw return 0;
303 1.1.4.2 nathanw }
304 1.1.4.2 nathanw
305 1.1.4.2 nathanw #ifdef NETDOCK_DEBUG_DRIVER
306 1.1.4.2 nathanw static void
307 1.1.4.2 nathanw netdock_print_driver(bst, bsh, na)
308 1.1.4.2 nathanw bus_space_tag_t bst;
309 1.1.4.2 nathanw bus_space_handle_t bsh;
310 1.1.4.2 nathanw struct nubus_attach_args *na;
311 1.1.4.2 nathanw {
312 1.1.4.2 nathanw #define HEADSIZE (8+4)
313 1.1.4.2 nathanw #define CODESIZE (6759-4)
314 1.1.4.2 nathanw unsigned char mydata[HEADSIZE + CODESIZE];
315 1.1.4.2 nathanw nubus_dir dir;
316 1.1.4.2 nathanw nubus_dirent dirent;
317 1.1.4.2 nathanw int i, rv;
318 1.1.4.2 nathanw
319 1.1.4.2 nathanw nubus_get_main_dir(na->fmt, &dir);
320 1.1.4.2 nathanw rv = nubus_find_rsrc(bst, bsh, na->fmt, &dir, 0x81, &dirent);
321 1.1.4.2 nathanw if (rv <= 0) {
322 1.1.4.2 nathanw printf(": can't find sResource.\n");
323 1.1.4.2 nathanw return;
324 1.1.4.2 nathanw }
325 1.1.4.2 nathanw nubus_get_dir_from_rsrc(na->fmt, &dirent, &dir);
326 1.1.4.2 nathanw if (nubus_find_rsrc(bst, bsh, na->fmt, &dir, NUBUS_RSRC_DRVRDIR,
327 1.1.4.2 nathanw &dirent) <= 0) {
328 1.1.4.2 nathanw printf(": can't find sResource.\n");
329 1.1.4.2 nathanw return;
330 1.1.4.2 nathanw }
331 1.1.4.2 nathanw if (nubus_get_ind_data(bst, bsh, na->fmt,
332 1.1.4.2 nathanw &dirent, mydata, HEADSIZE+CODESIZE) <= 0) {
333 1.1.4.2 nathanw printf(": can't find indirect data.\n");
334 1.1.4.2 nathanw return;
335 1.1.4.2 nathanw }
336 1.1.4.2 nathanw printf("\n########## begin driver dir");
337 1.1.4.2 nathanw for (i = 0; i < HEADSIZE; i++) {
338 1.1.4.2 nathanw if (i % 16 == 0)
339 1.1.4.2 nathanw printf("\n%02x:",i);
340 1.1.4.2 nathanw printf(" %02x", mydata[i]);
341 1.1.4.2 nathanw }
342 1.1.4.2 nathanw printf("\n########## begin driver code");
343 1.1.4.2 nathanw for (i = 0; i < CODESIZE; i++) {
344 1.1.4.2 nathanw if (i % 16 == 0)
345 1.1.4.2 nathanw printf("\n%02x:",i);
346 1.1.4.2 nathanw printf(" %02x", mydata[i + HEADSIZE]);
347 1.1.4.2 nathanw }
348 1.1.4.2 nathanw #if 0
349 1.1.4.2 nathanw printf("\n########## begin driver code (partial)\n");
350 1.1.4.2 nathanw #define PARTSIZE 256
351 1.1.4.2 nathanw #define OFFSET 0x1568
352 1.1.4.2 nathanw for (i = OFFSET; i < OFFSET + PARTSIZE; i++) {
353 1.1.4.2 nathanw if ((i - OFFSET) % 16 == 0)
354 1.1.4.2 nathanw printf("\n%02x:",i);
355 1.1.4.2 nathanw printf(" %02x", mydata[i + HEADSIZE]);
356 1.1.4.2 nathanw }
357 1.1.4.2 nathanw #endif
358 1.1.4.2 nathanw printf("\n########## end\n");
359 1.1.4.2 nathanw }
360 1.1.4.2 nathanw #endif
361 1.1.4.2 nathanw
362 1.1.4.2 nathanw
363 1.1.4.2 nathanw int
364 1.1.4.2 nathanw netdock_setup(sc, lladdr)
365 1.1.4.2 nathanw struct netdock_softc *sc;
366 1.1.4.2 nathanw u_int8_t *lladdr;
367 1.1.4.2 nathanw {
368 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
369 1.1.4.2 nathanw
370 1.1.4.2 nathanw bcopy(lladdr, sc->sc_enaddr, ETHER_ADDR_LEN);
371 1.1.4.2 nathanw printf("%s: Ethernet address %s\n",
372 1.1.4.2 nathanw sc->sc_dev.dv_xname, ether_sprintf(lladdr));
373 1.1.4.2 nathanw
374 1.1.4.2 nathanw bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
375 1.1.4.2 nathanw ifp->if_softc = sc;
376 1.1.4.2 nathanw ifp->if_ioctl = netdock_ioctl;
377 1.1.4.2 nathanw ifp->if_start = netdock_start;
378 1.1.4.2 nathanw ifp->if_flags =
379 1.1.4.2 nathanw IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
380 1.1.4.2 nathanw ifp->if_watchdog = netdock_watchdog;
381 1.1.4.2 nathanw
382 1.1.4.2 nathanw if_attach(ifp);
383 1.1.4.2 nathanw ether_ifattach(ifp, lladdr);
384 1.1.4.2 nathanw
385 1.1.4.2 nathanw return (0);
386 1.1.4.2 nathanw }
387 1.1.4.2 nathanw
388 1.1.4.2 nathanw static int
389 1.1.4.2 nathanw netdock_ioctl(ifp, cmd, data)
390 1.1.4.2 nathanw struct ifnet *ifp;
391 1.1.4.2 nathanw u_long cmd;
392 1.1.4.2 nathanw caddr_t data;
393 1.1.4.2 nathanw {
394 1.1.4.2 nathanw struct ifaddr *ifa;
395 1.1.4.2 nathanw struct ifreq *ifr;
396 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
397 1.1.4.2 nathanw int s = splnet();
398 1.1.4.2 nathanw int err = 0;
399 1.1.4.2 nathanw int temp;
400 1.1.4.2 nathanw
401 1.1.4.2 nathanw switch (cmd) {
402 1.1.4.2 nathanw case SIOCSIFADDR:
403 1.1.4.2 nathanw ifa = (struct ifaddr *)data;
404 1.1.4.2 nathanw ifp->if_flags |= IFF_UP;
405 1.1.4.2 nathanw switch (ifa->ifa_addr->sa_family) {
406 1.1.4.2 nathanw #ifdef INET
407 1.1.4.2 nathanw case AF_INET:
408 1.1.4.2 nathanw (void)netdock_init(sc);
409 1.1.4.2 nathanw arp_ifinit(ifp, ifa);
410 1.1.4.2 nathanw break;
411 1.1.4.2 nathanw #endif
412 1.1.4.2 nathanw default:
413 1.1.4.2 nathanw (void)netdock_init(sc);
414 1.1.4.2 nathanw break;
415 1.1.4.2 nathanw }
416 1.1.4.2 nathanw break;
417 1.1.4.2 nathanw
418 1.1.4.2 nathanw case SIOCSIFFLAGS:
419 1.1.4.2 nathanw if ((ifp->if_flags & IFF_UP) == 0 &&
420 1.1.4.2 nathanw (ifp->if_flags & IFF_RUNNING) != 0) {
421 1.1.4.2 nathanw netdock_stop(sc);
422 1.1.4.2 nathanw ifp->if_flags &= ~IFF_RUNNING;
423 1.1.4.2 nathanw } else if ((ifp->if_flags & IFF_UP) != 0 &&
424 1.1.4.2 nathanw (ifp->if_flags & IFF_RUNNING) == 0) {
425 1.1.4.2 nathanw (void)netdock_init(sc);
426 1.1.4.2 nathanw } else {
427 1.1.4.2 nathanw temp = ifp->if_flags & IFF_UP;
428 1.1.4.2 nathanw netdock_reset(sc);
429 1.1.4.2 nathanw ifp->if_flags |= temp;
430 1.1.4.2 nathanw netdock_start(ifp);
431 1.1.4.2 nathanw }
432 1.1.4.2 nathanw break;
433 1.1.4.2 nathanw
434 1.1.4.2 nathanw case SIOCADDMULTI:
435 1.1.4.2 nathanw case SIOCDELMULTI:
436 1.1.4.2 nathanw ifr = (struct ifreq *)data;
437 1.1.4.2 nathanw if (cmd == SIOCADDMULTI)
438 1.1.4.2 nathanw err = ether_addmulti(ifr, &sc->sc_ethercom);
439 1.1.4.2 nathanw else
440 1.1.4.2 nathanw err = ether_delmulti(ifr, &sc->sc_ethercom);
441 1.1.4.2 nathanw
442 1.1.4.2 nathanw if (err == ENETRESET) {
443 1.1.4.2 nathanw temp = ifp->if_flags & IFF_UP;
444 1.1.4.2 nathanw netdock_reset(sc);
445 1.1.4.2 nathanw ifp->if_flags |= temp;
446 1.1.4.2 nathanw err = 0;
447 1.1.4.2 nathanw }
448 1.1.4.2 nathanw break;
449 1.1.4.2 nathanw default:
450 1.1.4.2 nathanw err = EINVAL;
451 1.1.4.2 nathanw break;
452 1.1.4.2 nathanw }
453 1.1.4.2 nathanw splx(s);
454 1.1.4.2 nathanw return (err);
455 1.1.4.2 nathanw }
456 1.1.4.2 nathanw
457 1.1.4.2 nathanw static void
458 1.1.4.2 nathanw netdock_start(ifp)
459 1.1.4.2 nathanw struct ifnet *ifp;
460 1.1.4.2 nathanw {
461 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
462 1.1.4.2 nathanw struct mbuf *m;
463 1.1.4.2 nathanw
464 1.1.4.2 nathanw if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
465 1.1.4.2 nathanw return;
466 1.1.4.2 nathanw
467 1.1.4.2 nathanw while (1) {
468 1.1.4.2 nathanw IF_DEQUEUE(&ifp->if_snd, m);
469 1.1.4.2 nathanw if (m == 0)
470 1.1.4.2 nathanw return;
471 1.1.4.2 nathanw
472 1.1.4.2 nathanw if ((m->m_flags & M_PKTHDR) == 0)
473 1.1.4.2 nathanw panic("%s: netdock_start: no header mbuf",
474 1.1.4.2 nathanw sc->sc_dev.dv_xname);
475 1.1.4.2 nathanw
476 1.1.4.2 nathanw #if NBPFILTER > 0
477 1.1.4.2 nathanw if (ifp->if_bpf)
478 1.1.4.2 nathanw bpf_mtap(ifp->if_bpf, m);
479 1.1.4.2 nathanw #endif
480 1.1.4.2 nathanw
481 1.1.4.2 nathanw if ((netdock_put(sc, m)) == 0) {
482 1.1.4.2 nathanw IF_PREPEND(&ifp->if_snd, m);
483 1.1.4.2 nathanw return;
484 1.1.4.2 nathanw }
485 1.1.4.2 nathanw
486 1.1.4.2 nathanw ifp->if_opackets++;
487 1.1.4.2 nathanw }
488 1.1.4.2 nathanw
489 1.1.4.2 nathanw }
490 1.1.4.2 nathanw
491 1.1.4.2 nathanw static void
492 1.1.4.2 nathanw netdock_reset(sc)
493 1.1.4.2 nathanw struct netdock_softc *sc;
494 1.1.4.2 nathanw {
495 1.1.4.2 nathanw
496 1.1.4.2 nathanw netdock_stop(sc);
497 1.1.4.2 nathanw netdock_init(sc);
498 1.1.4.2 nathanw }
499 1.1.4.2 nathanw
500 1.1.4.2 nathanw static int
501 1.1.4.2 nathanw netdock_init(sc)
502 1.1.4.2 nathanw struct netdock_softc *sc;
503 1.1.4.2 nathanw {
504 1.1.4.2 nathanw int s;
505 1.1.4.2 nathanw int saveisr;
506 1.1.4.2 nathanw int savetmp;
507 1.1.4.2 nathanw
508 1.1.4.2 nathanw if (sc->sc_if.if_flags & IFF_RUNNING)
509 1.1.4.2 nathanw return (0);
510 1.1.4.2 nathanw
511 1.1.4.2 nathanw s = splnet();
512 1.1.4.2 nathanw
513 1.1.4.2 nathanw /* 0606 */
514 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
515 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0);
516 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
517 1.1.4.2 nathanw
518 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8104);
519 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0004, 0x0043);
520 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
521 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, 0x6618);
522 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8010);
523 1.1.4.2 nathanw
524 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 0, sc->sc_enaddr[0]);
525 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 1, sc->sc_enaddr[1]);
526 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 2, sc->sc_enaddr[2]);
527 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 3, sc->sc_enaddr[3]);
528 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 4, sc->sc_enaddr[4]);
529 1.1.4.2 nathanw NIC_PUT_1(sc, REG_0004 + 5, sc->sc_enaddr[5]);
530 1.1.4.2 nathanw
531 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0x2008);
532 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
533 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x4000);
534 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_MASK);
535 1.1.4.2 nathanw
536 1.1.4.2 nathanw
537 1.1.4.2 nathanw /* 1320 */
538 1.1.4.2 nathanw saveisr = NIC_GET_2(sc, REG_ISR);
539 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , 0);
540 1.1.4.2 nathanw savetmp = NIC_GET_2(sc, REG_000E);
541 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
542 1.1.4.2 nathanw NIC_ANDW(sc, REG_ISR, ~ISR_BIT_03);
543 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, savetmp);
544 1.1.4.2 nathanw
545 1.1.4.2 nathanw /* 1382 */
546 1.1.4.2 nathanw savetmp = NIC_GET_2(sc, REG_000E);
547 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0100);
548 1.1.4.2 nathanw NIC_ORW(sc, REG_ISR, ISR_BIT_03);
549 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, savetmp);
550 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR , saveisr);
551 1.1.4.2 nathanw
552 1.1.4.2 nathanw
553 1.1.4.2 nathanw sc->sc_if.if_flags |= IFF_RUNNING;
554 1.1.4.2 nathanw sc->sc_if.if_flags &= ~IFF_OACTIVE;
555 1.1.4.2 nathanw
556 1.1.4.2 nathanw splx(s);
557 1.1.4.2 nathanw return (0);
558 1.1.4.2 nathanw }
559 1.1.4.2 nathanw
560 1.1.4.2 nathanw static int
561 1.1.4.2 nathanw netdock_stop(sc)
562 1.1.4.2 nathanw struct netdock_softc *sc;
563 1.1.4.2 nathanw {
564 1.1.4.2 nathanw int s = splnet();
565 1.1.4.2 nathanw
566 1.1.4.2 nathanw sc->sc_if.if_timer = 0;
567 1.1.4.2 nathanw sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_UP);
568 1.1.4.2 nathanw
569 1.1.4.2 nathanw splx(s);
570 1.1.4.2 nathanw return (0);
571 1.1.4.2 nathanw }
572 1.1.4.2 nathanw
573 1.1.4.2 nathanw static void
574 1.1.4.2 nathanw netdock_watchdog(ifp)
575 1.1.4.2 nathanw struct ifnet *ifp;
576 1.1.4.2 nathanw {
577 1.1.4.2 nathanw struct netdock_softc *sc = ifp->if_softc;
578 1.1.4.2 nathanw int tmp;
579 1.1.4.2 nathanw
580 1.1.4.2 nathanw printf("netdock_watchdog: resetting chip\n");
581 1.1.4.2 nathanw tmp = ifp->if_flags & IFF_UP;
582 1.1.4.2 nathanw netdock_reset(sc);
583 1.1.4.2 nathanw ifp->if_flags |= tmp;
584 1.1.4.2 nathanw }
585 1.1.4.2 nathanw
586 1.1.4.2 nathanw static u_int
587 1.1.4.2 nathanw netdock_put(sc, m0)
588 1.1.4.2 nathanw struct netdock_softc *sc;
589 1.1.4.2 nathanw struct mbuf *m0;
590 1.1.4.2 nathanw {
591 1.1.4.2 nathanw struct mbuf *m;
592 1.1.4.2 nathanw u_int totlen = 0;
593 1.1.4.2 nathanw u_int tmplen;
594 1.1.4.2 nathanw int isr;
595 1.1.4.2 nathanw int timeout;
596 1.1.4.2 nathanw int tmp;
597 1.1.4.2 nathanw u_int i;
598 1.1.4.2 nathanw
599 1.1.4.2 nathanw for (m = m0; m; m = m->m_next)
600 1.1.4.2 nathanw totlen += m->m_len;
601 1.1.4.2 nathanw
602 1.1.4.2 nathanw if (totlen >= ETHER_MAX_LEN)
603 1.1.4.2 nathanw panic("%s: netdock_put: packet overflow", sc->sc_dev.dv_xname);
604 1.1.4.2 nathanw
605 1.1.4.2 nathanw totlen += 6;
606 1.1.4.2 nathanw tmplen = totlen;
607 1.1.4.2 nathanw tmplen &= 0xff00;
608 1.1.4.2 nathanw tmplen |= 0x2000;
609 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, tmplen);
610 1.1.4.2 nathanw
611 1.1.4.2 nathanw timeout = 0x3000;
612 1.1.4.2 nathanw while ((((isr = NIC_GET_2(sc, REG_ISR)) & ISR_READY) == 0) &&
613 1.1.4.2 nathanw timeout--) {
614 1.1.4.2 nathanw if (isr & ISR_TX)
615 1.1.4.2 nathanw netdock_txint(sc);
616 1.1.4.2 nathanw }
617 1.1.4.2 nathanw if (timeout == 0)
618 1.1.4.2 nathanw return (0);
619 1.1.4.2 nathanw
620 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0002);
621 1.1.4.2 nathanw tmp <<= 8;
622 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, tmp);
623 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x240);
624 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
625 1.1.4.2 nathanw tmplen = ((totlen << 8) & 0xfe00) | ((totlen >> 8) & 0x00ff);
626 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, tmplen);
627 1.1.4.2 nathanw
628 1.1.4.2 nathanw for (m = m0; m; m = m->m_next) {
629 1.1.4.2 nathanw u_char *data = mtod(m, u_char *);
630 1.1.4.2 nathanw int len = m->m_len;
631 1.1.4.2 nathanw int len4 = len >> 2;
632 1.1.4.2 nathanw u_int32_t *data4 = (u_int32_t *)data;
633 1.1.4.2 nathanw for (i = 0; i < len4; i++)
634 1.1.4.2 nathanw NIC_PUT_4(sc, REG_DATA, data4[i]);
635 1.1.4.2 nathanw for (i = len4 << 2; i < len; i++)
636 1.1.4.2 nathanw NIC_PUT_1(sc, REG_DATA, data[i]);
637 1.1.4.2 nathanw }
638 1.1.4.2 nathanw
639 1.1.4.2 nathanw if (totlen & 0x01)
640 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, 0x2020);
641 1.1.4.2 nathanw else
642 1.1.4.2 nathanw NIC_PUT_2(sc, REG_DATA, 0);
643 1.1.4.2 nathanw
644 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0xc000);
645 1.1.4.2 nathanw
646 1.1.4.2 nathanw m_freem(m0);
647 1.1.4.2 nathanw /* sc->sc_if.if_timer = 5; */
648 1.1.4.2 nathanw return (totlen);
649 1.1.4.2 nathanw }
650 1.1.4.2 nathanw
651 1.1.4.2 nathanw void
652 1.1.4.2 nathanw netdock_intr(arg)
653 1.1.4.2 nathanw void *arg;
654 1.1.4.2 nathanw {
655 1.1.4.2 nathanw struct netdock_softc *sc = (struct netdock_softc *)arg;
656 1.1.4.2 nathanw int isr;
657 1.1.4.2 nathanw int tmp;
658 1.1.4.2 nathanw
659 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, 0);
660 1.1.4.2 nathanw while ((isr = (NIC_GET_2(sc, REG_ISR) & ISR_ALL)) != 0) {
661 1.1.4.2 nathanw if (isr & ISR_TX)
662 1.1.4.2 nathanw netdock_txint(sc);
663 1.1.4.2 nathanw
664 1.1.4.2 nathanw if (isr & ISR_RX)
665 1.1.4.2 nathanw netdock_rxint(sc);
666 1.1.4.2 nathanw
667 1.1.4.2 nathanw if (isr & (ISR_BIT_0C | ISR_BIT_0D)) {
668 1.1.4.2 nathanw if (isr & ISR_BIT_0C) {
669 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
670 1.1.4.2 nathanw NIC_BSET(sc, REG_0004, 0x08);
671 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
672 1.1.4.2 nathanw }
673 1.1.4.2 nathanw if (isr & ISR_BIT_0D) {
674 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
675 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0002);
676 1.1.4.2 nathanw if (tmp & REG_0002_BIT_04)
677 1.1.4.2 nathanw NIC_GET_2(sc, REG_0006);
678 1.1.4.2 nathanw tmp = NIC_GET_2(sc, REG_0000);
679 1.1.4.2 nathanw if (tmp & REG_0000_BIT_08)
680 1.1.4.2 nathanw NIC_BSET(sc, REG_0000, 0x08);
681 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
682 1.1.4.2 nathanw }
683 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, isr);
684 1.1.4.2 nathanw }
685 1.1.4.2 nathanw }
686 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_MASK);
687 1.1.4.2 nathanw }
688 1.1.4.2 nathanw
689 1.1.4.2 nathanw static void
690 1.1.4.2 nathanw netdock_txint(sc)
691 1.1.4.2 nathanw struct netdock_softc *sc;
692 1.1.4.2 nathanw {
693 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
694 1.1.4.2 nathanw int savereg0002;
695 1.1.4.2 nathanw int reg0004;
696 1.1.4.2 nathanw int regdata;
697 1.1.4.2 nathanw
698 1.1.4.2 nathanw ifp->if_flags &= ~IFF_OACTIVE;
699 1.1.4.2 nathanw ifp->if_timer = 0;
700 1.1.4.2 nathanw
701 1.1.4.2 nathanw savereg0002 = NIC_GET_2(sc, REG_0002);
702 1.1.4.2 nathanw
703 1.1.4.2 nathanw while (((reg0004 = NIC_GET_2(sc, REG_0004)) & REG_0004_BIT_0F) == 0) {
704 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, reg0004);
705 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x0060);
706 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
707 1.1.4.2 nathanw regdata = NIC_GET_2(sc, REG_DATA);
708 1.1.4.2 nathanw if ((regdata & REG_DATA_BIT_08) == 0) {
709 1.1.4.2 nathanw /* ifp->if_collisions++; */
710 1.1.4.2 nathanw if (regdata & REG_DATA_BIT_07)
711 1.1.4.2 nathanw /* ifp->if_oerrors++; */
712 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
713 1.1.4.2 nathanw NIC_ORW(sc, REG_0000, 0x0100);
714 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
715 1.1.4.2 nathanw }
716 1.1.4.2 nathanw NIC_GET_2(sc ,REG_DATA);
717 1.1.4.2 nathanw
718 1.1.4.2 nathanw if (regdata & REG_DATA_BIT_0F)
719 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
720 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0xa000);
721 1.1.4.2 nathanw NIC_PUT_2(sc, REG_ISR, ISR_TX);
722 1.1.4.2 nathanw }
723 1.1.4.2 nathanw
724 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0002, savereg0002);
725 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0);
726 1.1.4.2 nathanw NIC_GET_2(sc, REG_0006);
727 1.1.4.2 nathanw NIC_PUT_2(sc, REG_000E, 0x0200);
728 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0);
729 1.1.4.2 nathanw }
730 1.1.4.2 nathanw
731 1.1.4.2 nathanw static void
732 1.1.4.2 nathanw netdock_rxint(sc)
733 1.1.4.2 nathanw struct netdock_softc *sc;
734 1.1.4.2 nathanw {
735 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
736 1.1.4.2 nathanw int regdata1;
737 1.1.4.2 nathanw int regdata2;
738 1.1.4.2 nathanw u_int len;
739 1.1.4.2 nathanw int timeout;
740 1.1.4.2 nathanw
741 1.1.4.2 nathanw while ((NIC_GET_2(sc, REG_0004) & REG_0004_BIT_07) == 0) {
742 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
743 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0x00e0);
744 1.1.4.2 nathanw NIC_GET_2(sc, REG_ISR);
745 1.1.4.2 nathanw regdata1 = NIC_GET_2(sc, REG_DATA);
746 1.1.4.2 nathanw regdata2 = NIC_GET_2(sc, REG_DATA);
747 1.1.4.2 nathanw len = ((regdata2 << 8) & 0x0700) | ((regdata2 >> 8) & 0x00ff);
748 1.1.4.2 nathanw
749 1.1.4.2 nathanw #if 0
750 1.1.4.2 nathanw printf("netdock_rxint: r1=0x%04x, r2=0x%04x, len=%d\n",
751 1.1.4.2 nathanw regdata1, regdata2, len);
752 1.1.4.2 nathanw #endif
753 1.1.4.2 nathanw
754 1.1.4.2 nathanw if ((regdata1 & REG_DATA_BIT_04) == 0)
755 1.1.4.2 nathanw len -= 2;
756 1.1.4.2 nathanw
757 1.1.4.2 nathanw if ((regdata1 & 0x00ac) == 0) {
758 1.1.4.2 nathanw if (netdock_read(sc, len))
759 1.1.4.2 nathanw ifp->if_ipackets++;
760 1.1.4.2 nathanw else
761 1.1.4.2 nathanw ifp->if_ierrors++;
762 1.1.4.2 nathanw } else {
763 1.1.4.2 nathanw ifp->if_ierrors++;
764 1.1.4.2 nathanw
765 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_02)
766 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
767 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_03)
768 1.1.4.2 nathanw ;
769 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_05)
770 1.1.4.2 nathanw NIC_GET_4(sc, REG_EFD00);
771 1.1.4.2 nathanw if (regdata1 & REG_DATA_BIT_07)
772 1.1.4.2 nathanw ;
773 1.1.4.2 nathanw }
774 1.1.4.2 nathanw
775 1.1.4.2 nathanw timeout = 0x14;
776 1.1.4.2 nathanw while ((NIC_GET_2(sc, REG_0000) & REG_0000_BIT_08) && timeout--)
777 1.1.4.2 nathanw ;
778 1.1.4.2 nathanw if (timeout == 0)
779 1.1.4.2 nathanw ;
780 1.1.4.2 nathanw
781 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0000, 0x8000);
782 1.1.4.2 nathanw }
783 1.1.4.2 nathanw NIC_PUT_2(sc, REG_0006, 0);
784 1.1.4.2 nathanw }
785 1.1.4.2 nathanw
786 1.1.4.2 nathanw static int
787 1.1.4.2 nathanw netdock_read(sc, len)
788 1.1.4.2 nathanw struct netdock_softc *sc;
789 1.1.4.2 nathanw int len;
790 1.1.4.2 nathanw {
791 1.1.4.2 nathanw struct ifnet *ifp = &sc->sc_if;
792 1.1.4.2 nathanw struct mbuf *m;
793 1.1.4.2 nathanw
794 1.1.4.2 nathanw m = netdock_get(sc, len);
795 1.1.4.2 nathanw if (m == 0)
796 1.1.4.2 nathanw return (0);
797 1.1.4.2 nathanw
798 1.1.4.2 nathanw /* the data comes with frame checksum and ethernet header */
799 1.1.4.2 nathanw m->m_flags |= M_HASFCS;
800 1.1.4.2 nathanw
801 1.1.4.2 nathanw #if NBPFILTER > 0
802 1.1.4.2 nathanw if (ifp->if_bpf)
803 1.1.4.2 nathanw bpf_mtap(ifp->if_bpf, m);
804 1.1.4.2 nathanw #endif
805 1.1.4.2 nathanw
806 1.1.4.2 nathanw (*ifp->if_input)(ifp, m);
807 1.1.4.2 nathanw
808 1.1.4.2 nathanw return (1);
809 1.1.4.2 nathanw }
810 1.1.4.2 nathanw
811 1.1.4.2 nathanw static struct mbuf *
812 1.1.4.2 nathanw netdock_get(sc, datalen)
813 1.1.4.2 nathanw struct netdock_softc *sc;
814 1.1.4.2 nathanw int datalen;
815 1.1.4.2 nathanw {
816 1.1.4.2 nathanw struct mbuf *m, *top, **mp;
817 1.1.4.2 nathanw u_char *data;
818 1.1.4.2 nathanw int i;
819 1.1.4.2 nathanw int len;
820 1.1.4.2 nathanw int len4;
821 1.1.4.2 nathanw u_int32_t *data4;
822 1.1.4.2 nathanw
823 1.1.4.2 nathanw MGETHDR(m, M_DONTWAIT, MT_DATA);
824 1.1.4.2 nathanw if (m == NULL)
825 1.1.4.2 nathanw return (NULL);
826 1.1.4.2 nathanw m->m_pkthdr.rcvif = &sc->sc_if;
827 1.1.4.2 nathanw m->m_pkthdr.len = datalen;
828 1.1.4.2 nathanw len = MHLEN;
829 1.1.4.2 nathanw top = NULL;
830 1.1.4.2 nathanw mp = ⊤
831 1.1.4.2 nathanw
832 1.1.4.2 nathanw while (datalen > 0) {
833 1.1.4.2 nathanw if (top) {
834 1.1.4.2 nathanw MGET(m, M_DONTWAIT, MT_DATA);
835 1.1.4.2 nathanw if (m == 0) {
836 1.1.4.2 nathanw m_freem(top);
837 1.1.4.2 nathanw return (NULL);
838 1.1.4.2 nathanw }
839 1.1.4.2 nathanw len = MLEN;
840 1.1.4.2 nathanw }
841 1.1.4.2 nathanw if (datalen >= MINCLSIZE) {
842 1.1.4.2 nathanw MCLGET(m, M_DONTWAIT);
843 1.1.4.2 nathanw if ((m->m_flags & M_EXT) == 0) {
844 1.1.4.2 nathanw if (top)
845 1.1.4.2 nathanw m_freem(top);
846 1.1.4.2 nathanw return (NULL);
847 1.1.4.2 nathanw }
848 1.1.4.2 nathanw len = MCLBYTES;
849 1.1.4.2 nathanw }
850 1.1.4.2 nathanw
851 1.1.4.2 nathanw if (mp == &top) {
852 1.1.4.2 nathanw caddr_t newdata = (caddr_t)
853 1.1.4.2 nathanw ALIGN(m->m_data + sizeof(struct ether_header)) -
854 1.1.4.2 nathanw sizeof(struct ether_header);
855 1.1.4.2 nathanw len -= newdata - m->m_data;
856 1.1.4.2 nathanw m->m_data = newdata;
857 1.1.4.2 nathanw }
858 1.1.4.2 nathanw
859 1.1.4.2 nathanw m->m_len = len = min(datalen, len);
860 1.1.4.2 nathanw
861 1.1.4.2 nathanw data = mtod(m, u_char *);
862 1.1.4.2 nathanw len4 = len >> 2;
863 1.1.4.2 nathanw data4 = (u_int32_t *)data;
864 1.1.4.2 nathanw for (i = 0; i < len4; i++)
865 1.1.4.2 nathanw data4[i] = NIC_GET_4(sc, REG_DATA);
866 1.1.4.2 nathanw for (i = len4 << 2; i < len; i++)
867 1.1.4.2 nathanw data[i] = NIC_GET_1(sc, REG_DATA);
868 1.1.4.2 nathanw
869 1.1.4.2 nathanw datalen -= len;
870 1.1.4.2 nathanw *mp = m;
871 1.1.4.2 nathanw mp = &m->m_next;
872 1.1.4.2 nathanw }
873 1.1.4.2 nathanw
874 1.1.4.2 nathanw return (top);
875 1.1.4.2 nathanw }
876