if_sq.c revision 1.7.8.2 1 1.7.8.2 nathanw /* $NetBSD: if_sq.c,v 1.7.8.2 2002/01/08 00:27:28 nathanw Exp $ */
2 1.7.8.2 nathanw
3 1.7.8.2 nathanw /*
4 1.7.8.2 nathanw * Copyright (c) 2001 Rafal K. Boni
5 1.7.8.2 nathanw * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
6 1.7.8.2 nathanw * All rights reserved.
7 1.7.8.2 nathanw *
8 1.7.8.2 nathanw * Portions of this code are derived from software contributed to The
9 1.7.8.2 nathanw * NetBSD Foundation by Jason R. Thorpe of the Numerical Aerospace
10 1.7.8.2 nathanw * Simulation Facility, NASA Ames Research Center.
11 1.7.8.2 nathanw *
12 1.7.8.2 nathanw * Redistribution and use in source and binary forms, with or without
13 1.7.8.2 nathanw * modification, are permitted provided that the following conditions
14 1.7.8.2 nathanw * are met:
15 1.7.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
16 1.7.8.2 nathanw * notice, this list of conditions and the following disclaimer.
17 1.7.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
18 1.7.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
19 1.7.8.2 nathanw * documentation and/or other materials provided with the distribution.
20 1.7.8.2 nathanw * 3. The name of the author may not be used to endorse or promote products
21 1.7.8.2 nathanw * derived from this software without specific prior written permission.
22 1.7.8.2 nathanw *
23 1.7.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.7.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.7.8.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.7.8.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.7.8.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.7.8.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.7.8.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.7.8.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.7.8.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.7.8.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.7.8.2 nathanw */
34 1.7.8.2 nathanw
35 1.7.8.2 nathanw #include "bpfilter.h"
36 1.7.8.2 nathanw
37 1.7.8.2 nathanw #include <sys/param.h>
38 1.7.8.2 nathanw #include <sys/systm.h>
39 1.7.8.2 nathanw #include <sys/device.h>
40 1.7.8.2 nathanw #include <sys/callout.h>
41 1.7.8.2 nathanw #include <sys/mbuf.h>
42 1.7.8.2 nathanw #include <sys/malloc.h>
43 1.7.8.2 nathanw #include <sys/kernel.h>
44 1.7.8.2 nathanw #include <sys/socket.h>
45 1.7.8.2 nathanw #include <sys/ioctl.h>
46 1.7.8.2 nathanw #include <sys/errno.h>
47 1.7.8.2 nathanw #include <sys/syslog.h>
48 1.7.8.2 nathanw
49 1.7.8.2 nathanw #include <uvm/uvm_extern.h>
50 1.7.8.2 nathanw
51 1.7.8.2 nathanw #include <machine/endian.h>
52 1.7.8.2 nathanw
53 1.7.8.2 nathanw #include <net/if.h>
54 1.7.8.2 nathanw #include <net/if_dl.h>
55 1.7.8.2 nathanw #include <net/if_media.h>
56 1.7.8.2 nathanw #include <net/if_ether.h>
57 1.7.8.2 nathanw
58 1.7.8.2 nathanw #if NBPFILTER > 0
59 1.7.8.2 nathanw #include <net/bpf.h>
60 1.7.8.2 nathanw #endif
61 1.7.8.2 nathanw
62 1.7.8.2 nathanw #include <machine/bus.h>
63 1.7.8.2 nathanw #include <machine/intr.h>
64 1.7.8.2 nathanw
65 1.7.8.2 nathanw #include <dev/ic/seeq8003reg.h>
66 1.7.8.2 nathanw
67 1.7.8.2 nathanw #include <sgimips/hpc/sqvar.h>
68 1.7.8.2 nathanw #include <sgimips/hpc/hpcvar.h>
69 1.7.8.2 nathanw #include <sgimips/hpc/hpcreg.h>
70 1.7.8.2 nathanw
71 1.7.8.2 nathanw #include <dev/arcbios/arcbios.h>
72 1.7.8.2 nathanw #include <dev/arcbios/arcbiosvar.h>
73 1.7.8.2 nathanw
74 1.7.8.2 nathanw #define static
75 1.7.8.2 nathanw
76 1.7.8.2 nathanw /*
77 1.7.8.2 nathanw * Short TODO list:
78 1.7.8.2 nathanw * (1) Do counters for bad-RX packets.
79 1.7.8.2 nathanw * (2) Allow multi-segment transmits, instead of copying to a single,
80 1.7.8.2 nathanw * contiguous mbuf.
81 1.7.8.2 nathanw * (3) Verify sq_stop() turns off enough stuff; I was still getting
82 1.7.8.2 nathanw * seeq interrupts after sq_stop().
83 1.7.8.2 nathanw * (4) Fix up printfs in driver (most should only fire ifdef SQ_DEBUG
84 1.7.8.2 nathanw * or something similar.
85 1.7.8.2 nathanw * (5) Implement EDLC modes: especially packet auto-pad and simplex
86 1.7.8.2 nathanw * mode.
87 1.7.8.2 nathanw * (6) Should the driver filter out its own transmissions in non-EDLC
88 1.7.8.2 nathanw * mode?
89 1.7.8.2 nathanw * (7) Multicast support -- multicast filter, address management, ...
90 1.7.8.2 nathanw * (8) Deal with RB0 (recv buffer overflow) on reception. Will need
91 1.7.8.2 nathanw * to figure out if RB0 is read-only as stated in one spot in the
92 1.7.8.2 nathanw * HPC spec or read-write (ie, is the 'write a one to clear it')
93 1.7.8.2 nathanw * the correct thing?
94 1.7.8.2 nathanw */
95 1.7.8.2 nathanw
96 1.7.8.2 nathanw static int sq_match(struct device *, struct cfdata *, void *);
97 1.7.8.2 nathanw static void sq_attach(struct device *, struct device *, void *);
98 1.7.8.2 nathanw static int sq_init(struct ifnet *);
99 1.7.8.2 nathanw static void sq_start(struct ifnet *);
100 1.7.8.2 nathanw static void sq_stop(struct ifnet *, int);
101 1.7.8.2 nathanw static void sq_watchdog(struct ifnet *);
102 1.7.8.2 nathanw static int sq_ioctl(struct ifnet *, u_long, caddr_t);
103 1.7.8.2 nathanw
104 1.7.8.2 nathanw static void sq_set_filter(struct sq_softc *);
105 1.7.8.2 nathanw static int sq_intr(void *);
106 1.7.8.2 nathanw static int sq_rxintr(struct sq_softc *);
107 1.7.8.2 nathanw static int sq_txintr(struct sq_softc *);
108 1.7.8.2 nathanw static void sq_reset(struct sq_softc *);
109 1.7.8.2 nathanw static int sq_add_rxbuf(struct sq_softc *, int);
110 1.7.8.2 nathanw static void sq_dump_buffer(u_int32_t addr, u_int32_t len);
111 1.7.8.2 nathanw
112 1.7.8.2 nathanw static void enaddr_aton(const char*, u_int8_t*);
113 1.7.8.2 nathanw
114 1.7.8.2 nathanw /* Actions */
115 1.7.8.2 nathanw #define SQ_RESET 1
116 1.7.8.2 nathanw #define SQ_ADD_TO_DMA 2
117 1.7.8.2 nathanw #define SQ_START_DMA 3
118 1.7.8.2 nathanw #define SQ_DONE_DMA 4
119 1.7.8.2 nathanw #define SQ_RESTART_DMA 5
120 1.7.8.2 nathanw #define SQ_TXINTR_ENTER 6
121 1.7.8.2 nathanw #define SQ_TXINTR_EXIT 7
122 1.7.8.2 nathanw #define SQ_TXINTR_BUSY 8
123 1.7.8.2 nathanw
124 1.7.8.2 nathanw struct sq_action_trace {
125 1.7.8.2 nathanw int action;
126 1.7.8.2 nathanw int bufno;
127 1.7.8.2 nathanw int status;
128 1.7.8.2 nathanw int freebuf;
129 1.7.8.2 nathanw };
130 1.7.8.2 nathanw
131 1.7.8.2 nathanw #define SQ_TRACEBUF_SIZE 100
132 1.7.8.2 nathanw int sq_trace_idx = 0;
133 1.7.8.2 nathanw struct sq_action_trace sq_trace[SQ_TRACEBUF_SIZE];
134 1.7.8.2 nathanw
135 1.7.8.2 nathanw void sq_trace_dump(struct sq_softc* sc);
136 1.7.8.2 nathanw
137 1.7.8.2 nathanw #define SQ_TRACE(act, buf, stat, free) do { \
138 1.7.8.2 nathanw sq_trace[sq_trace_idx].action = (act); \
139 1.7.8.2 nathanw sq_trace[sq_trace_idx].bufno = (buf); \
140 1.7.8.2 nathanw sq_trace[sq_trace_idx].status = (stat); \
141 1.7.8.2 nathanw sq_trace[sq_trace_idx].freebuf = (free); \
142 1.7.8.2 nathanw if (++sq_trace_idx == SQ_TRACEBUF_SIZE) { \
143 1.7.8.2 nathanw memset(&sq_trace, 0, sizeof(sq_trace)); \
144 1.7.8.2 nathanw sq_trace_idx = 0; \
145 1.7.8.2 nathanw } \
146 1.7.8.2 nathanw } while (0)
147 1.7.8.2 nathanw
148 1.7.8.2 nathanw struct cfattach sq_ca = {
149 1.7.8.2 nathanw sizeof(struct sq_softc), sq_match, sq_attach
150 1.7.8.2 nathanw };
151 1.7.8.2 nathanw
152 1.7.8.2 nathanw static int
153 1.7.8.2 nathanw sq_match(struct device *parent, struct cfdata *cf, void *aux)
154 1.7.8.2 nathanw {
155 1.7.8.2 nathanw struct hpc_attach_args *ha = aux;
156 1.7.8.2 nathanw
157 1.7.8.2 nathanw if (strcmp(ha->ha_name, cf->cf_driver->cd_name) == 0)
158 1.7.8.2 nathanw return (1);
159 1.7.8.2 nathanw
160 1.7.8.2 nathanw return (0);
161 1.7.8.2 nathanw }
162 1.7.8.2 nathanw
163 1.7.8.2 nathanw static void
164 1.7.8.2 nathanw sq_attach(struct device *parent, struct device *self, void *aux)
165 1.7.8.2 nathanw {
166 1.7.8.2 nathanw int i, err;
167 1.7.8.2 nathanw char* macaddr;
168 1.7.8.2 nathanw struct sq_softc *sc = (void *)self;
169 1.7.8.2 nathanw struct hpc_attach_args *haa = aux;
170 1.7.8.2 nathanw struct ifnet *ifp = &sc->sc_ethercom.ec_if;
171 1.7.8.2 nathanw
172 1.7.8.2 nathanw sc->sc_hpct = haa->ha_st;
173 1.7.8.2 nathanw if ((err = bus_space_subregion(haa->ha_st, haa->ha_sh,
174 1.7.8.2 nathanw haa->ha_dmaoff,
175 1.7.8.2 nathanw HPC_ENET_REGS_SIZE,
176 1.7.8.2 nathanw &sc->sc_hpch)) != 0) {
177 1.7.8.2 nathanw printf(": unable to map HPC DMA registers, error = %d\n", err);
178 1.7.8.2 nathanw goto fail_0;
179 1.7.8.2 nathanw }
180 1.7.8.2 nathanw
181 1.7.8.2 nathanw sc->sc_regt = haa->ha_st;
182 1.7.8.2 nathanw if ((err = bus_space_subregion(haa->ha_st, haa->ha_sh,
183 1.7.8.2 nathanw haa->ha_devoff,
184 1.7.8.2 nathanw HPC_ENET_DEVREGS_SIZE,
185 1.7.8.2 nathanw &sc->sc_regh)) != 0) {
186 1.7.8.2 nathanw printf(": unable to map Seeq registers, error = %d\n", err);
187 1.7.8.2 nathanw goto fail_0;
188 1.7.8.2 nathanw }
189 1.7.8.2 nathanw
190 1.7.8.2 nathanw sc->sc_dmat = haa->ha_dmat;
191 1.7.8.2 nathanw
192 1.7.8.2 nathanw if ((err = bus_dmamem_alloc(sc->sc_dmat, sizeof(struct sq_control),
193 1.7.8.2 nathanw PAGE_SIZE, PAGE_SIZE, &sc->sc_cdseg,
194 1.7.8.2 nathanw 1, &sc->sc_ncdseg, BUS_DMA_NOWAIT)) != 0) {
195 1.7.8.2 nathanw printf(": unable to allocate control data, error = %d\n", err);
196 1.7.8.2 nathanw goto fail_0;
197 1.7.8.2 nathanw }
198 1.7.8.2 nathanw
199 1.7.8.2 nathanw if ((err = bus_dmamem_map(sc->sc_dmat, &sc->sc_cdseg, sc->sc_ncdseg,
200 1.7.8.2 nathanw sizeof(struct sq_control),
201 1.7.8.2 nathanw (caddr_t *)&sc->sc_control,
202 1.7.8.2 nathanw BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
203 1.7.8.2 nathanw printf(": unable to map control data, error = %d\n", err);
204 1.7.8.2 nathanw goto fail_1;
205 1.7.8.2 nathanw }
206 1.7.8.2 nathanw
207 1.7.8.2 nathanw if ((err = bus_dmamap_create(sc->sc_dmat, sizeof(struct sq_control),
208 1.7.8.2 nathanw 1, sizeof(struct sq_control), PAGE_SIZE,
209 1.7.8.2 nathanw BUS_DMA_NOWAIT, &sc->sc_cdmap)) != 0) {
210 1.7.8.2 nathanw printf(": unable to create DMA map for control data, error "
211 1.7.8.2 nathanw "= %d\n", err);
212 1.7.8.2 nathanw goto fail_2;
213 1.7.8.2 nathanw }
214 1.7.8.2 nathanw
215 1.7.8.2 nathanw if ((err = bus_dmamap_load(sc->sc_dmat, sc->sc_cdmap, sc->sc_control,
216 1.7.8.2 nathanw sizeof(struct sq_control),
217 1.7.8.2 nathanw NULL, BUS_DMA_NOWAIT)) != 0) {
218 1.7.8.2 nathanw printf(": unable to load DMA map for control data, error "
219 1.7.8.2 nathanw "= %d\n", err);
220 1.7.8.2 nathanw goto fail_3;
221 1.7.8.2 nathanw }
222 1.7.8.2 nathanw
223 1.7.8.2 nathanw memset(sc->sc_control, 0, sizeof(struct sq_control));
224 1.7.8.2 nathanw
225 1.7.8.2 nathanw /* Create transmit buffer DMA maps */
226 1.7.8.2 nathanw for (i = 0; i < SQ_NTXDESC; i++) {
227 1.7.8.2 nathanw if ((err = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, MCLBYTES,
228 1.7.8.2 nathanw 0, BUS_DMA_NOWAIT,
229 1.7.8.2 nathanw &sc->sc_txmap[i])) != 0) {
230 1.7.8.2 nathanw printf(": unable to create tx DMA map %d, error = %d\n",
231 1.7.8.2 nathanw i, err);
232 1.7.8.2 nathanw goto fail_4;
233 1.7.8.2 nathanw }
234 1.7.8.2 nathanw }
235 1.7.8.2 nathanw
236 1.7.8.2 nathanw /* Create transmit buffer DMA maps */
237 1.7.8.2 nathanw for (i = 0; i < SQ_NRXDESC; i++) {
238 1.7.8.2 nathanw if ((err = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, MCLBYTES,
239 1.7.8.2 nathanw 0, BUS_DMA_NOWAIT,
240 1.7.8.2 nathanw &sc->sc_rxmap[i])) != 0) {
241 1.7.8.2 nathanw printf(": unable to create rx DMA map %d, error = %d\n",
242 1.7.8.2 nathanw i, err);
243 1.7.8.2 nathanw goto fail_5;
244 1.7.8.2 nathanw }
245 1.7.8.2 nathanw }
246 1.7.8.2 nathanw
247 1.7.8.2 nathanw /* Pre-allocate the receive buffers. */
248 1.7.8.2 nathanw for (i = 0; i < SQ_NRXDESC; i++) {
249 1.7.8.2 nathanw if ((err = sq_add_rxbuf(sc, i)) != 0) {
250 1.7.8.2 nathanw printf(": unable to allocate or map rx buffer %d\n,"
251 1.7.8.2 nathanw " error = %d\n", i, err);
252 1.7.8.2 nathanw goto fail_6;
253 1.7.8.2 nathanw }
254 1.7.8.2 nathanw }
255 1.7.8.2 nathanw
256 1.7.8.2 nathanw if ((macaddr = ARCBIOS->GetEnvironmentVariable("eaddr")) == NULL) {
257 1.7.8.2 nathanw printf(": unable to get MAC address!\n");
258 1.7.8.2 nathanw goto fail_6;
259 1.7.8.2 nathanw }
260 1.7.8.2 nathanw
261 1.7.8.2 nathanw if ((cpu_intr_establish(haa->ha_irq, IPL_NET, sq_intr, sc)) == NULL) {
262 1.7.8.2 nathanw printf(": unable to establish interrupt!\n");
263 1.7.8.2 nathanw goto fail_6;
264 1.7.8.2 nathanw }
265 1.7.8.2 nathanw
266 1.7.8.2 nathanw /* Reset the chip to a known state. */
267 1.7.8.2 nathanw sq_reset(sc);
268 1.7.8.2 nathanw
269 1.7.8.2 nathanw /*
270 1.7.8.2 nathanw * Determine if we're an 8003 or 80c03 by setting the first
271 1.7.8.2 nathanw * MAC address register to non-zero, and then reading it back.
272 1.7.8.2 nathanw * If it's zero, we have an 80c03, because we will have read
273 1.7.8.2 nathanw * the TxCollLSB register.
274 1.7.8.2 nathanw */
275 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCOLLS0, 0xa5);
276 1.7.8.2 nathanw if (bus_space_read_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCOLLS0) == 0)
277 1.7.8.2 nathanw sc->sc_type = SQ_TYPE_80C03;
278 1.7.8.2 nathanw else
279 1.7.8.2 nathanw sc->sc_type = SQ_TYPE_8003;
280 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCOLLS0, 0x00);
281 1.7.8.2 nathanw
282 1.7.8.2 nathanw printf(": SGI Seeq %s\n",
283 1.7.8.2 nathanw sc->sc_type == SQ_TYPE_80C03 ? "80c03" : "8003");
284 1.7.8.2 nathanw
285 1.7.8.2 nathanw enaddr_aton(macaddr, sc->sc_enaddr);
286 1.7.8.2 nathanw
287 1.7.8.2 nathanw printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
288 1.7.8.2 nathanw ether_sprintf(sc->sc_enaddr));
289 1.7.8.2 nathanw
290 1.7.8.2 nathanw strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
291 1.7.8.2 nathanw ifp->if_softc = sc;
292 1.7.8.2 nathanw ifp->if_mtu = ETHERMTU;
293 1.7.8.2 nathanw ifp->if_init = sq_init;
294 1.7.8.2 nathanw ifp->if_stop = sq_stop;
295 1.7.8.2 nathanw ifp->if_start = sq_start;
296 1.7.8.2 nathanw ifp->if_ioctl = sq_ioctl;
297 1.7.8.2 nathanw ifp->if_watchdog = sq_watchdog;
298 1.7.8.2 nathanw ifp->if_flags = IFF_BROADCAST | IFF_NOTRAILERS | IFF_MULTICAST;
299 1.7.8.2 nathanw IFQ_SET_READY(&ifp->if_snd);
300 1.7.8.2 nathanw
301 1.7.8.2 nathanw if_attach(ifp);
302 1.7.8.2 nathanw ether_ifattach(ifp, sc->sc_enaddr);
303 1.7.8.2 nathanw
304 1.7.8.2 nathanw memset(&sq_trace, 0, sizeof(sq_trace));
305 1.7.8.2 nathanw /* Done! */
306 1.7.8.2 nathanw return;
307 1.7.8.2 nathanw
308 1.7.8.2 nathanw /*
309 1.7.8.2 nathanw * Free any resources we've allocated during the failed attach
310 1.7.8.2 nathanw * attempt. Do this in reverse order and fall through.
311 1.7.8.2 nathanw */
312 1.7.8.2 nathanw fail_6:
313 1.7.8.2 nathanw for (i = 0; i < SQ_NRXDESC; i++) {
314 1.7.8.2 nathanw if (sc->sc_rxmbuf[i] != NULL) {
315 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, sc->sc_rxmap[i]);
316 1.7.8.2 nathanw m_freem(sc->sc_rxmbuf[i]);
317 1.7.8.2 nathanw }
318 1.7.8.2 nathanw }
319 1.7.8.2 nathanw fail_5:
320 1.7.8.2 nathanw for (i = 0; i < SQ_NRXDESC; i++) {
321 1.7.8.2 nathanw if (sc->sc_rxmap[i] != NULL)
322 1.7.8.2 nathanw bus_dmamap_destroy(sc->sc_dmat, sc->sc_rxmap[i]);
323 1.7.8.2 nathanw }
324 1.7.8.2 nathanw fail_4:
325 1.7.8.2 nathanw for (i = 0; i < SQ_NTXDESC; i++) {
326 1.7.8.2 nathanw if (sc->sc_txmap[i] != NULL)
327 1.7.8.2 nathanw bus_dmamap_destroy(sc->sc_dmat, sc->sc_txmap[i]);
328 1.7.8.2 nathanw }
329 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, sc->sc_cdmap);
330 1.7.8.2 nathanw fail_3:
331 1.7.8.2 nathanw bus_dmamap_destroy(sc->sc_dmat, sc->sc_cdmap);
332 1.7.8.2 nathanw fail_2:
333 1.7.8.2 nathanw bus_dmamem_unmap(sc->sc_dmat, (caddr_t) sc->sc_control,
334 1.7.8.2 nathanw sizeof(struct sq_control));
335 1.7.8.2 nathanw fail_1:
336 1.7.8.2 nathanw bus_dmamem_free(sc->sc_dmat, &sc->sc_cdseg, sc->sc_ncdseg);
337 1.7.8.2 nathanw fail_0:
338 1.7.8.2 nathanw return;
339 1.7.8.2 nathanw }
340 1.7.8.2 nathanw
341 1.7.8.2 nathanw /* Set up data to get the interface up and running. */
342 1.7.8.2 nathanw int
343 1.7.8.2 nathanw sq_init(struct ifnet *ifp)
344 1.7.8.2 nathanw {
345 1.7.8.2 nathanw int i;
346 1.7.8.2 nathanw u_int32_t reg;
347 1.7.8.2 nathanw struct sq_softc *sc = ifp->if_softc;
348 1.7.8.2 nathanw
349 1.7.8.2 nathanw /* Cancel any in-progress I/O */
350 1.7.8.2 nathanw sq_stop(ifp, 0);
351 1.7.8.2 nathanw
352 1.7.8.2 nathanw sc->sc_nextrx = 0;
353 1.7.8.2 nathanw
354 1.7.8.2 nathanw sc->sc_nfreetx = SQ_NTXDESC;
355 1.7.8.2 nathanw sc->sc_nexttx = sc->sc_prevtx = 0;
356 1.7.8.2 nathanw
357 1.7.8.2 nathanw SQ_TRACE(SQ_RESET, 0, 0, sc->sc_nfreetx);
358 1.7.8.2 nathanw
359 1.7.8.2 nathanw /* Set into 8003 mode, bank 0 to program ethernet address */
360 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCMD, TXCMD_BANK0);
361 1.7.8.2 nathanw
362 1.7.8.2 nathanw /* Now write the address */
363 1.7.8.2 nathanw for (i = 0; i < ETHER_ADDR_LEN; i++)
364 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, i,
365 1.7.8.2 nathanw sc->sc_enaddr[i]);
366 1.7.8.2 nathanw
367 1.7.8.2 nathanw sc->sc_rxcmd = RXCMD_IE_CRC |
368 1.7.8.2 nathanw RXCMD_IE_DRIB |
369 1.7.8.2 nathanw RXCMD_IE_SHORT |
370 1.7.8.2 nathanw RXCMD_IE_END |
371 1.7.8.2 nathanw RXCMD_IE_GOOD;
372 1.7.8.2 nathanw
373 1.7.8.2 nathanw /*
374 1.7.8.2 nathanw * Set the receive filter -- this will add some bits to the
375 1.7.8.2 nathanw * prototype RXCMD register. Do this before setting the
376 1.7.8.2 nathanw * transmit config register, since we might need to switch
377 1.7.8.2 nathanw * banks.
378 1.7.8.2 nathanw */
379 1.7.8.2 nathanw sq_set_filter(sc);
380 1.7.8.2 nathanw
381 1.7.8.2 nathanw /* Set up Seeq transmit command register */
382 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCMD,
383 1.7.8.2 nathanw TXCMD_IE_UFLOW |
384 1.7.8.2 nathanw TXCMD_IE_COLL |
385 1.7.8.2 nathanw TXCMD_IE_16COLL |
386 1.7.8.2 nathanw TXCMD_IE_GOOD);
387 1.7.8.2 nathanw
388 1.7.8.2 nathanw /* Now write the receive command register. */
389 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_RXCMD, sc->sc_rxcmd);
390 1.7.8.2 nathanw
391 1.7.8.2 nathanw /* Set up HPC ethernet DMA config */
392 1.7.8.2 nathanw reg = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_DMACFG);
393 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_DMACFG,
394 1.7.8.2 nathanw reg | ENETR_DMACFG_FIX_RXDC |
395 1.7.8.2 nathanw ENETR_DMACFG_FIX_INTR |
396 1.7.8.2 nathanw ENETR_DMACFG_FIX_EOP);
397 1.7.8.2 nathanw
398 1.7.8.2 nathanw /* Pass the start of the receive ring to the HPC */
399 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_NDBP,
400 1.7.8.2 nathanw SQ_CDRXADDR(sc, 0));
401 1.7.8.2 nathanw
402 1.7.8.2 nathanw /* And turn on the HPC ethernet receive channel */
403 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_CTL,
404 1.7.8.2 nathanw ENETR_CTL_ACTIVE);
405 1.7.8.2 nathanw
406 1.7.8.2 nathanw ifp->if_flags |= IFF_RUNNING;
407 1.7.8.2 nathanw ifp->if_flags &= ~IFF_OACTIVE;
408 1.7.8.2 nathanw
409 1.7.8.2 nathanw return 0;
410 1.7.8.2 nathanw }
411 1.7.8.2 nathanw
412 1.7.8.2 nathanw static void
413 1.7.8.2 nathanw sq_set_filter(struct sq_softc *sc)
414 1.7.8.2 nathanw {
415 1.7.8.2 nathanw struct ethercom *ec = &sc->sc_ethercom;
416 1.7.8.2 nathanw struct ifnet *ifp = &sc->sc_ethercom.ec_if;
417 1.7.8.2 nathanw struct ether_multi *enm;
418 1.7.8.2 nathanw struct ether_multistep step;
419 1.7.8.2 nathanw
420 1.7.8.2 nathanw /*
421 1.7.8.2 nathanw * Check for promiscuous mode. Also implies
422 1.7.8.2 nathanw * all-multicast.
423 1.7.8.2 nathanw */
424 1.7.8.2 nathanw if (ifp->if_flags & IFF_PROMISC) {
425 1.7.8.2 nathanw sc->sc_rxcmd |= RXCMD_REC_ALL;
426 1.7.8.2 nathanw ifp->if_flags |= IFF_ALLMULTI;
427 1.7.8.2 nathanw return;
428 1.7.8.2 nathanw }
429 1.7.8.2 nathanw
430 1.7.8.2 nathanw /*
431 1.7.8.2 nathanw * The 8003 has no hash table. If we have any multicast
432 1.7.8.2 nathanw * addresses on the list, enable reception of all multicast
433 1.7.8.2 nathanw * frames.
434 1.7.8.2 nathanw *
435 1.7.8.2 nathanw * XXX The 80c03 has a hash table. We should use it.
436 1.7.8.2 nathanw */
437 1.7.8.2 nathanw
438 1.7.8.2 nathanw ETHER_FIRST_MULTI(step, ec, enm);
439 1.7.8.2 nathanw
440 1.7.8.2 nathanw if (enm == NULL) {
441 1.7.8.2 nathanw sc->sc_rxcmd |= RXCMD_REC_BROAD;
442 1.7.8.2 nathanw return;
443 1.7.8.2 nathanw }
444 1.7.8.2 nathanw
445 1.7.8.2 nathanw sc->sc_rxcmd |= RXCMD_REC_MULTI;
446 1.7.8.2 nathanw ifp->if_flags |= IFF_ALLMULTI;
447 1.7.8.2 nathanw }
448 1.7.8.2 nathanw
449 1.7.8.2 nathanw int
450 1.7.8.2 nathanw sq_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
451 1.7.8.2 nathanw {
452 1.7.8.2 nathanw int s, error = 0;
453 1.7.8.2 nathanw
454 1.7.8.2 nathanw s = splnet();
455 1.7.8.2 nathanw
456 1.7.8.2 nathanw error = ether_ioctl(ifp, cmd, data);
457 1.7.8.2 nathanw if (error == ENETRESET) {
458 1.7.8.2 nathanw /*
459 1.7.8.2 nathanw * Multicast list has changed; set the hardware filter
460 1.7.8.2 nathanw * accordingly.
461 1.7.8.2 nathanw */
462 1.7.8.2 nathanw error = sq_init(ifp);
463 1.7.8.2 nathanw }
464 1.7.8.2 nathanw
465 1.7.8.2 nathanw splx(s);
466 1.7.8.2 nathanw return (error);
467 1.7.8.2 nathanw }
468 1.7.8.2 nathanw
469 1.7.8.2 nathanw void
470 1.7.8.2 nathanw sq_start(struct ifnet *ifp)
471 1.7.8.2 nathanw {
472 1.7.8.2 nathanw struct sq_softc *sc = ifp->if_softc;
473 1.7.8.2 nathanw u_int32_t status;
474 1.7.8.2 nathanw struct mbuf *m0, *m;
475 1.7.8.2 nathanw bus_dmamap_t dmamap;
476 1.7.8.2 nathanw int err, totlen, nexttx, firsttx, lasttx, ofree, seg;
477 1.7.8.2 nathanw
478 1.7.8.2 nathanw if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
479 1.7.8.2 nathanw return;
480 1.7.8.2 nathanw
481 1.7.8.2 nathanw /*
482 1.7.8.2 nathanw * Remember the previous number of free descriptors and
483 1.7.8.2 nathanw * the first descriptor we'll use.
484 1.7.8.2 nathanw */
485 1.7.8.2 nathanw ofree = sc->sc_nfreetx;
486 1.7.8.2 nathanw firsttx = sc->sc_nexttx;
487 1.7.8.2 nathanw
488 1.7.8.2 nathanw /*
489 1.7.8.2 nathanw * Loop through the send queue, setting up transmit descriptors
490 1.7.8.2 nathanw * until we drain the queue, or use up all available transmit
491 1.7.8.2 nathanw * descriptors.
492 1.7.8.2 nathanw */
493 1.7.8.2 nathanw while (sc->sc_nfreetx != 0) {
494 1.7.8.2 nathanw /*
495 1.7.8.2 nathanw * Grab a packet off the queue.
496 1.7.8.2 nathanw */
497 1.7.8.2 nathanw IFQ_POLL(&ifp->if_snd, m0);
498 1.7.8.2 nathanw if (m0 == NULL)
499 1.7.8.2 nathanw break;
500 1.7.8.2 nathanw m = NULL;
501 1.7.8.2 nathanw
502 1.7.8.2 nathanw dmamap = sc->sc_txmap[sc->sc_nexttx];
503 1.7.8.2 nathanw
504 1.7.8.2 nathanw /*
505 1.7.8.2 nathanw * Load the DMA map. If this fails, the packet either
506 1.7.8.2 nathanw * didn't fit in the alloted number of segments, or we were
507 1.7.8.2 nathanw * short on resources. In this case, we'll copy and try
508 1.7.8.2 nathanw * again.
509 1.7.8.2 nathanw */
510 1.7.8.2 nathanw if (bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
511 1.7.8.2 nathanw BUS_DMA_NOWAIT) != 0) {
512 1.7.8.2 nathanw MGETHDR(m, M_DONTWAIT, MT_DATA);
513 1.7.8.2 nathanw if (m == NULL) {
514 1.7.8.2 nathanw printf("%s: unable to allocate Tx mbuf\n",
515 1.7.8.2 nathanw sc->sc_dev.dv_xname);
516 1.7.8.2 nathanw break;
517 1.7.8.2 nathanw }
518 1.7.8.2 nathanw if (m0->m_pkthdr.len > MHLEN) {
519 1.7.8.2 nathanw MCLGET(m, M_DONTWAIT);
520 1.7.8.2 nathanw if ((m->m_flags & M_EXT) == 0) {
521 1.7.8.2 nathanw printf("%s: unable to allocate Tx "
522 1.7.8.2 nathanw "cluster\n", sc->sc_dev.dv_xname);
523 1.7.8.2 nathanw m_freem(m);
524 1.7.8.2 nathanw break;
525 1.7.8.2 nathanw }
526 1.7.8.2 nathanw }
527 1.7.8.2 nathanw
528 1.7.8.2 nathanw m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
529 1.7.8.2 nathanw m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
530 1.7.8.2 nathanw
531 1.7.8.2 nathanw if ((err = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
532 1.7.8.2 nathanw m, BUS_DMA_NOWAIT)) != 0) {
533 1.7.8.2 nathanw printf("%s: unable to load Tx buffer, "
534 1.7.8.2 nathanw "error = %d\n", sc->sc_dev.dv_xname, err);
535 1.7.8.2 nathanw break;
536 1.7.8.2 nathanw }
537 1.7.8.2 nathanw }
538 1.7.8.2 nathanw
539 1.7.8.2 nathanw /*
540 1.7.8.2 nathanw * Ensure we have enough descriptors free to describe
541 1.7.8.2 nathanw * the packet.
542 1.7.8.2 nathanw */
543 1.7.8.2 nathanw if (dmamap->dm_nsegs > sc->sc_nfreetx) {
544 1.7.8.2 nathanw /*
545 1.7.8.2 nathanw * Not enough free descriptors to transmit this
546 1.7.8.2 nathanw * packet. We haven't committed to anything yet,
547 1.7.8.2 nathanw * so just unload the DMA map, put the packet
548 1.7.8.2 nathanw * back on the queue, and punt. Notify the upper
549 1.7.8.2 nathanw * layer that there are no more slots left.
550 1.7.8.2 nathanw *
551 1.7.8.2 nathanw * XXX We could allocate an mbuf and copy, but
552 1.7.8.2 nathanw * XXX it is worth it?
553 1.7.8.2 nathanw */
554 1.7.8.2 nathanw ifp->if_flags |= IFF_OACTIVE;
555 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, dmamap);
556 1.7.8.2 nathanw if (m != NULL)
557 1.7.8.2 nathanw m_freem(m);
558 1.7.8.2 nathanw break;
559 1.7.8.2 nathanw }
560 1.7.8.2 nathanw
561 1.7.8.2 nathanw IFQ_DEQUEUE(&ifp->if_snd, m0);
562 1.7.8.2 nathanw if (m != NULL) {
563 1.7.8.2 nathanw m_freem(m0);
564 1.7.8.2 nathanw m0 = m;
565 1.7.8.2 nathanw }
566 1.7.8.2 nathanw
567 1.7.8.2 nathanw /*
568 1.7.8.2 nathanw * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
569 1.7.8.2 nathanw */
570 1.7.8.2 nathanw
571 1.7.8.2 nathanw /* Sync the DMA map. */
572 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
573 1.7.8.2 nathanw BUS_DMASYNC_PREWRITE);
574 1.7.8.2 nathanw
575 1.7.8.2 nathanw /*
576 1.7.8.2 nathanw * Initialize the transmit descriptors.
577 1.7.8.2 nathanw */
578 1.7.8.2 nathanw for (nexttx = sc->sc_nexttx, seg = 0, totlen = 0;
579 1.7.8.2 nathanw seg < dmamap->dm_nsegs;
580 1.7.8.2 nathanw seg++, nexttx = SQ_NEXTTX(nexttx)) {
581 1.7.8.2 nathanw sc->sc_txdesc[nexttx].hdd_bufptr =
582 1.7.8.2 nathanw dmamap->dm_segs[seg].ds_addr;
583 1.7.8.2 nathanw sc->sc_txdesc[nexttx].hdd_ctl =
584 1.7.8.2 nathanw dmamap->dm_segs[seg].ds_len;
585 1.7.8.2 nathanw sc->sc_txdesc[nexttx].hdd_descptr=
586 1.7.8.2 nathanw SQ_CDTXADDR(sc, SQ_NEXTTX(nexttx));
587 1.7.8.2 nathanw lasttx = nexttx;
588 1.7.8.2 nathanw totlen += dmamap->dm_segs[seg].ds_len;
589 1.7.8.2 nathanw }
590 1.7.8.2 nathanw
591 1.7.8.2 nathanw /* Last descriptor gets end-of-packet */
592 1.7.8.2 nathanw sc->sc_txdesc[lasttx].hdd_ctl |= HDD_CTL_EOPACKET;
593 1.7.8.2 nathanw
594 1.7.8.2 nathanw /* XXXrkb: if not EDLC, pad to min len manually */
595 1.7.8.2 nathanw if (totlen < ETHER_MIN_LEN) {
596 1.7.8.2 nathanw sc->sc_txdesc[lasttx].hdd_ctl += (ETHER_MIN_LEN - totlen);
597 1.7.8.2 nathanw totlen = ETHER_MIN_LEN;
598 1.7.8.2 nathanw }
599 1.7.8.2 nathanw
600 1.7.8.2 nathanw #if 0
601 1.7.8.2 nathanw printf("%s: transmit %d-%d, len %d\n", sc->sc_dev.dv_xname,
602 1.7.8.2 nathanw sc->sc_nexttx, lasttx,
603 1.7.8.2 nathanw totlen);
604 1.7.8.2 nathanw #endif
605 1.7.8.2 nathanw
606 1.7.8.2 nathanw if (ifp->if_flags & IFF_DEBUG) {
607 1.7.8.2 nathanw printf(" transmit chain:\n");
608 1.7.8.2 nathanw for (seg = sc->sc_nexttx;; seg = SQ_NEXTTX(seg)) {
609 1.7.8.2 nathanw printf(" descriptor %d:\n", seg);
610 1.7.8.2 nathanw printf(" hdd_bufptr: 0x%08x\n",
611 1.7.8.2 nathanw sc->sc_txdesc[seg].hdd_bufptr);
612 1.7.8.2 nathanw printf(" hdd_ctl: 0x%08x\n",
613 1.7.8.2 nathanw sc->sc_txdesc[seg].hdd_ctl);
614 1.7.8.2 nathanw printf(" hdd_descptr: 0x%08x\n",
615 1.7.8.2 nathanw sc->sc_txdesc[seg].hdd_descptr);
616 1.7.8.2 nathanw
617 1.7.8.2 nathanw if (seg == lasttx)
618 1.7.8.2 nathanw break;
619 1.7.8.2 nathanw }
620 1.7.8.2 nathanw }
621 1.7.8.2 nathanw
622 1.7.8.2 nathanw /* Sync the descriptors we're using. */
623 1.7.8.2 nathanw SQ_CDTXSYNC(sc, sc->sc_nexttx, dmamap->dm_nsegs,
624 1.7.8.2 nathanw BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
625 1.7.8.2 nathanw
626 1.7.8.2 nathanw /* Store a pointer to the packet so we can free it later */
627 1.7.8.2 nathanw sc->sc_txmbuf[sc->sc_nexttx] = m0;
628 1.7.8.2 nathanw
629 1.7.8.2 nathanw /* Advance the tx pointer. */
630 1.7.8.2 nathanw sc->sc_nfreetx -= dmamap->dm_nsegs;
631 1.7.8.2 nathanw sc->sc_nexttx = nexttx;
632 1.7.8.2 nathanw
633 1.7.8.2 nathanw #if NBPFILTER > 0
634 1.7.8.2 nathanw /*
635 1.7.8.2 nathanw * Pass the packet to any BPF listeners.
636 1.7.8.2 nathanw */
637 1.7.8.2 nathanw if (ifp->if_bpf)
638 1.7.8.2 nathanw bpf_mtap(ifp->if_bpf, m0);
639 1.7.8.2 nathanw #endif /* NBPFILTER > 0 */
640 1.7.8.2 nathanw }
641 1.7.8.2 nathanw
642 1.7.8.2 nathanw /* All transmit descriptors used up, let upper layers know */
643 1.7.8.2 nathanw if (sc->sc_nfreetx == 0)
644 1.7.8.2 nathanw ifp->if_flags |= IFF_OACTIVE;
645 1.7.8.2 nathanw
646 1.7.8.2 nathanw if (sc->sc_nfreetx != ofree) {
647 1.7.8.2 nathanw #if 0
648 1.7.8.2 nathanw printf("%s: %d packets enqueued, first %d, INTR on %d\n",
649 1.7.8.2 nathanw sc->sc_dev.dv_xname, lasttx - firsttx + 1,
650 1.7.8.2 nathanw firsttx, lasttx);
651 1.7.8.2 nathanw #endif
652 1.7.8.2 nathanw
653 1.7.8.2 nathanw /*
654 1.7.8.2 nathanw * Cause a transmit interrupt to happen on the
655 1.7.8.2 nathanw * last packet we enqueued, mark it as the last
656 1.7.8.2 nathanw * descriptor.
657 1.7.8.2 nathanw */
658 1.7.8.2 nathanw sc->sc_txdesc[lasttx].hdd_ctl |= (HDD_CTL_INTR |
659 1.7.8.2 nathanw HDD_CTL_EOCHAIN);
660 1.7.8.2 nathanw SQ_CDTXSYNC(sc, lasttx, 1,
661 1.7.8.2 nathanw BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
662 1.7.8.2 nathanw
663 1.7.8.2 nathanw /*
664 1.7.8.2 nathanw * There is a potential race condition here if the HPC
665 1.7.8.2 nathanw * DMA channel is active and we try and either update
666 1.7.8.2 nathanw * the 'next descriptor' pointer in the HPC PIO space
667 1.7.8.2 nathanw * or the 'next descriptor' pointer in a previous desc-
668 1.7.8.2 nathanw * riptor.
669 1.7.8.2 nathanw *
670 1.7.8.2 nathanw * To avoid this, if the channel is active, we rely on
671 1.7.8.2 nathanw * the transmit interrupt routine noticing that there
672 1.7.8.2 nathanw * are more packets to send and restarting the HPC DMA
673 1.7.8.2 nathanw * engine, rather than mucking with the DMA state here.
674 1.7.8.2 nathanw */
675 1.7.8.2 nathanw status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch,
676 1.7.8.2 nathanw HPC_ENETX_CTL);
677 1.7.8.2 nathanw
678 1.7.8.2 nathanw if ((status & ENETX_CTL_ACTIVE) != 0) {
679 1.7.8.2 nathanw SQ_TRACE(SQ_ADD_TO_DMA, firsttx, status,
680 1.7.8.2 nathanw sc->sc_nfreetx);
681 1.7.8.2 nathanw sc->sc_txdesc[SQ_PREVTX(firsttx)].hdd_ctl &=
682 1.7.8.2 nathanw ~HDD_CTL_EOCHAIN;
683 1.7.8.2 nathanw SQ_CDTXSYNC(sc, SQ_PREVTX(firsttx), 1,
684 1.7.8.2 nathanw BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
685 1.7.8.2 nathanw } else {
686 1.7.8.2 nathanw SQ_TRACE(SQ_START_DMA, firsttx, status, sc->sc_nfreetx);
687 1.7.8.2 nathanw
688 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch,
689 1.7.8.2 nathanw HPC_ENETX_NDBP, SQ_CDTXADDR(sc, firsttx));
690 1.7.8.2 nathanw
691 1.7.8.2 nathanw /* Kick DMA channel into life */
692 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch,
693 1.7.8.2 nathanw HPC_ENETX_CTL, ENETX_CTL_ACTIVE);
694 1.7.8.2 nathanw }
695 1.7.8.2 nathanw
696 1.7.8.2 nathanw /* Set a watchdog timer in case the chip flakes out. */
697 1.7.8.2 nathanw ifp->if_timer = 5;
698 1.7.8.2 nathanw }
699 1.7.8.2 nathanw }
700 1.7.8.2 nathanw
701 1.7.8.2 nathanw void
702 1.7.8.2 nathanw sq_stop(struct ifnet *ifp, int disable)
703 1.7.8.2 nathanw {
704 1.7.8.2 nathanw int i;
705 1.7.8.2 nathanw struct sq_softc *sc = ifp->if_softc;
706 1.7.8.2 nathanw
707 1.7.8.2 nathanw for (i =0; i < SQ_NTXDESC; i++) {
708 1.7.8.2 nathanw if (sc->sc_txmbuf[i] != NULL) {
709 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, sc->sc_txmap[i]);
710 1.7.8.2 nathanw m_freem(sc->sc_txmbuf[i]);
711 1.7.8.2 nathanw sc->sc_txmbuf[i] = NULL;
712 1.7.8.2 nathanw }
713 1.7.8.2 nathanw }
714 1.7.8.2 nathanw
715 1.7.8.2 nathanw /* Clear Seeq transmit/receive command registers */
716 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_TXCMD, 0);
717 1.7.8.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, SEEQ_RXCMD, 0);
718 1.7.8.2 nathanw
719 1.7.8.2 nathanw sq_reset(sc);
720 1.7.8.2 nathanw
721 1.7.8.2 nathanw ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
722 1.7.8.2 nathanw ifp->if_timer = 0;
723 1.7.8.2 nathanw }
724 1.7.8.2 nathanw
725 1.7.8.2 nathanw /* Device timeout/watchdog routine. */
726 1.7.8.2 nathanw void
727 1.7.8.2 nathanw sq_watchdog(struct ifnet *ifp)
728 1.7.8.2 nathanw {
729 1.7.8.2 nathanw u_int32_t status;
730 1.7.8.2 nathanw struct sq_softc *sc = ifp->if_softc;
731 1.7.8.2 nathanw
732 1.7.8.2 nathanw status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETX_CTL);
733 1.7.8.2 nathanw log(LOG_ERR, "%s: device timeout (prev %d, next %d, free %d, "
734 1.7.8.2 nathanw "status %08x)\n", sc->sc_dev.dv_xname, sc->sc_prevtx,
735 1.7.8.2 nathanw sc->sc_nexttx, sc->sc_nfreetx, status);
736 1.7.8.2 nathanw
737 1.7.8.2 nathanw sq_trace_dump(sc);
738 1.7.8.2 nathanw
739 1.7.8.2 nathanw memset(&sq_trace, 0, sizeof(sq_trace));
740 1.7.8.2 nathanw sq_trace_idx = 0;
741 1.7.8.2 nathanw
742 1.7.8.2 nathanw ++ifp->if_oerrors;
743 1.7.8.2 nathanw
744 1.7.8.2 nathanw sq_init(ifp);
745 1.7.8.2 nathanw }
746 1.7.8.2 nathanw
747 1.7.8.2 nathanw void sq_trace_dump(struct sq_softc* sc)
748 1.7.8.2 nathanw {
749 1.7.8.2 nathanw int i;
750 1.7.8.2 nathanw
751 1.7.8.2 nathanw for(i = 0; i < sq_trace_idx; i++) {
752 1.7.8.2 nathanw printf("%s: [%d] action %d, buf %d, free %d, status %08x\n",
753 1.7.8.2 nathanw sc->sc_dev.dv_xname, i, sq_trace[i].action,
754 1.7.8.2 nathanw sq_trace[i].bufno, sq_trace[i].freebuf,
755 1.7.8.2 nathanw sq_trace[i].status);
756 1.7.8.2 nathanw }
757 1.7.8.2 nathanw }
758 1.7.8.2 nathanw
759 1.7.8.2 nathanw static int
760 1.7.8.2 nathanw sq_intr(void * arg)
761 1.7.8.2 nathanw {
762 1.7.8.2 nathanw struct sq_softc *sc = arg;
763 1.7.8.2 nathanw struct ifnet *ifp = &sc->sc_ethercom.ec_if;
764 1.7.8.2 nathanw int handled = 0;
765 1.7.8.2 nathanw u_int32_t stat;
766 1.7.8.2 nathanw
767 1.7.8.2 nathanw stat = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_RESET);
768 1.7.8.2 nathanw
769 1.7.8.2 nathanw if ((stat & 2) == 0) {
770 1.7.8.2 nathanw printf("%s: Unexpected interrupt!\n", sc->sc_dev.dv_xname);
771 1.7.8.2 nathanw return 0;
772 1.7.8.2 nathanw }
773 1.7.8.2 nathanw
774 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_RESET, 2);
775 1.7.8.2 nathanw
776 1.7.8.2 nathanw /*
777 1.7.8.2 nathanw * If the interface isn't running, the interrupt couldn't
778 1.7.8.2 nathanw * possibly have come from us.
779 1.7.8.2 nathanw */
780 1.7.8.2 nathanw if ((ifp->if_flags & IFF_RUNNING) == 0)
781 1.7.8.2 nathanw return 0;
782 1.7.8.2 nathanw
783 1.7.8.2 nathanw /* Always check for received packets */
784 1.7.8.2 nathanw if (sq_rxintr(sc) != 0)
785 1.7.8.2 nathanw handled++;
786 1.7.8.2 nathanw
787 1.7.8.2 nathanw /* Only handle transmit interrupts if we actually sent something */
788 1.7.8.2 nathanw if (sc->sc_nfreetx < SQ_NTXDESC) {
789 1.7.8.2 nathanw sq_txintr(sc);
790 1.7.8.2 nathanw handled++;
791 1.7.8.2 nathanw }
792 1.7.8.2 nathanw
793 1.7.8.2 nathanw #if NRND > 0
794 1.7.8.2 nathanw if (handled)
795 1.7.8.2 nathanw rnd_add_uint32(&sc->rnd_source, stat);
796 1.7.8.2 nathanw #endif
797 1.7.8.2 nathanw return (handled);
798 1.7.8.2 nathanw }
799 1.7.8.2 nathanw
800 1.7.8.2 nathanw static int
801 1.7.8.2 nathanw sq_rxintr(struct sq_softc *sc)
802 1.7.8.2 nathanw {
803 1.7.8.2 nathanw int count = 0;
804 1.7.8.2 nathanw struct mbuf* m;
805 1.7.8.2 nathanw int i, framelen;
806 1.7.8.2 nathanw u_int8_t pktstat;
807 1.7.8.2 nathanw u_int32_t status;
808 1.7.8.2 nathanw int new_end, orig_end;
809 1.7.8.2 nathanw struct ifnet *ifp = &sc->sc_ethercom.ec_if;
810 1.7.8.2 nathanw
811 1.7.8.2 nathanw for(i = sc->sc_nextrx;; i = SQ_NEXTRX(i)) {
812 1.7.8.2 nathanw SQ_CDRXSYNC(sc, i, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
813 1.7.8.2 nathanw
814 1.7.8.2 nathanw /* If this is a CPU-owned buffer, we're at the end of the list */
815 1.7.8.2 nathanw if (sc->sc_rxdesc[i].hdd_ctl & HDD_CTL_OWN) {
816 1.7.8.2 nathanw #if 0
817 1.7.8.2 nathanw u_int32_t reg;
818 1.7.8.2 nathanw
819 1.7.8.2 nathanw reg = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_CTL);
820 1.7.8.2 nathanw printf("%s: rxintr: done at %d (ctl %08x)\n",
821 1.7.8.2 nathanw sc->sc_dev.dv_xname, i, reg);
822 1.7.8.2 nathanw #endif
823 1.7.8.2 nathanw break;
824 1.7.8.2 nathanw }
825 1.7.8.2 nathanw
826 1.7.8.2 nathanw count++;
827 1.7.8.2 nathanw
828 1.7.8.2 nathanw m = sc->sc_rxmbuf[i];
829 1.7.8.2 nathanw framelen = m->m_ext.ext_size -
830 1.7.8.2 nathanw HDD_CTL_BYTECNT(sc->sc_rxdesc[i].hdd_ctl) - 3;
831 1.7.8.2 nathanw
832 1.7.8.2 nathanw /* Now sync the actual packet data */
833 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, sc->sc_rxmap[i], 0,
834 1.7.8.2 nathanw sc->sc_rxmap[i]->dm_mapsize, BUS_DMASYNC_POSTREAD);
835 1.7.8.2 nathanw
836 1.7.8.2 nathanw pktstat = *((u_int8_t*)m->m_data + framelen + 2);
837 1.7.8.2 nathanw
838 1.7.8.2 nathanw if ((pktstat & RXSTAT_GOOD) == 0) {
839 1.7.8.2 nathanw ifp->if_ierrors++;
840 1.7.8.2 nathanw
841 1.7.8.2 nathanw if (pktstat & RXSTAT_OFLOW)
842 1.7.8.2 nathanw printf("%s: receive FIFO overflow\n", sc->sc_dev.dv_xname);
843 1.7.8.2 nathanw
844 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, sc->sc_rxmap[i], 0,
845 1.7.8.2 nathanw sc->sc_rxmap[i]->dm_mapsize,
846 1.7.8.2 nathanw BUS_DMASYNC_PREREAD);
847 1.7.8.2 nathanw SQ_INIT_RXDESC(sc, i);
848 1.7.8.2 nathanw continue;
849 1.7.8.2 nathanw }
850 1.7.8.2 nathanw
851 1.7.8.2 nathanw if (sq_add_rxbuf(sc, i) != 0) {
852 1.7.8.2 nathanw ifp->if_ierrors++;
853 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, sc->sc_rxmap[i], 0,
854 1.7.8.2 nathanw sc->sc_rxmap[i]->dm_mapsize,
855 1.7.8.2 nathanw BUS_DMASYNC_PREREAD);
856 1.7.8.2 nathanw SQ_INIT_RXDESC(sc, i);
857 1.7.8.2 nathanw continue;
858 1.7.8.2 nathanw }
859 1.7.8.2 nathanw
860 1.7.8.2 nathanw
861 1.7.8.2 nathanw m->m_data += 2;
862 1.7.8.2 nathanw m->m_pkthdr.rcvif = ifp;
863 1.7.8.2 nathanw m->m_pkthdr.len = m->m_len = framelen;
864 1.7.8.2 nathanw
865 1.7.8.2 nathanw ifp->if_ipackets++;
866 1.7.8.2 nathanw
867 1.7.8.2 nathanw #if 0
868 1.7.8.2 nathanw printf("%s: sq_rxintr: buf %d len %d\n", sc->sc_dev.dv_xname,
869 1.7.8.2 nathanw i, framelen);
870 1.7.8.2 nathanw #endif
871 1.7.8.2 nathanw
872 1.7.8.2 nathanw #if NBPFILTER > 0
873 1.7.8.2 nathanw if (ifp->if_bpf)
874 1.7.8.2 nathanw bpf_mtap(ifp->if_bpf, m);
875 1.7.8.2 nathanw #endif
876 1.7.8.2 nathanw (*ifp->if_input)(ifp, m);
877 1.7.8.2 nathanw }
878 1.7.8.2 nathanw
879 1.7.8.2 nathanw
880 1.7.8.2 nathanw /* If anything happened, move ring start/end pointers to new spot */
881 1.7.8.2 nathanw if (i != sc->sc_nextrx) {
882 1.7.8.2 nathanw new_end = SQ_PREVRX(i);
883 1.7.8.2 nathanw sc->sc_rxdesc[new_end].hdd_ctl |= HDD_CTL_EOCHAIN;
884 1.7.8.2 nathanw SQ_CDRXSYNC(sc, new_end, BUS_DMASYNC_PREREAD |
885 1.7.8.2 nathanw BUS_DMASYNC_PREWRITE);
886 1.7.8.2 nathanw
887 1.7.8.2 nathanw orig_end = SQ_PREVRX(sc->sc_nextrx);
888 1.7.8.2 nathanw sc->sc_rxdesc[orig_end].hdd_ctl &= ~HDD_CTL_EOCHAIN;
889 1.7.8.2 nathanw SQ_CDRXSYNC(sc, orig_end, BUS_DMASYNC_PREREAD |
890 1.7.8.2 nathanw BUS_DMASYNC_PREWRITE);
891 1.7.8.2 nathanw
892 1.7.8.2 nathanw sc->sc_nextrx = i;
893 1.7.8.2 nathanw }
894 1.7.8.2 nathanw
895 1.7.8.2 nathanw status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch,
896 1.7.8.2 nathanw HPC_ENETR_CTL);
897 1.7.8.2 nathanw
898 1.7.8.2 nathanw /* If receive channel is stopped, restart it... */
899 1.7.8.2 nathanw if ((status & ENETR_CTL_ACTIVE) == 0) {
900 1.7.8.2 nathanw /* Pass the start of the receive ring to the HPC */
901 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch,
902 1.7.8.2 nathanw HPC_ENETR_NDBP, SQ_CDRXADDR(sc, sc->sc_nextrx));
903 1.7.8.2 nathanw
904 1.7.8.2 nathanw /* And turn on the HPC ethernet receive channel */
905 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_CTL,
906 1.7.8.2 nathanw ENETR_CTL_ACTIVE);
907 1.7.8.2 nathanw }
908 1.7.8.2 nathanw
909 1.7.8.2 nathanw return count;
910 1.7.8.2 nathanw }
911 1.7.8.2 nathanw
912 1.7.8.2 nathanw static int
913 1.7.8.2 nathanw sq_txintr(struct sq_softc *sc)
914 1.7.8.2 nathanw {
915 1.7.8.2 nathanw int i;
916 1.7.8.2 nathanw u_int32_t status;
917 1.7.8.2 nathanw struct ifnet *ifp = &sc->sc_ethercom.ec_if;
918 1.7.8.2 nathanw
919 1.7.8.2 nathanw status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETX_CTL);
920 1.7.8.2 nathanw
921 1.7.8.2 nathanw SQ_TRACE(SQ_TXINTR_ENTER, sc->sc_prevtx, status, sc->sc_nfreetx);
922 1.7.8.2 nathanw
923 1.7.8.2 nathanw if ((status & (ENETX_CTL_ACTIVE | TXSTAT_GOOD)) == 0) {
924 1.7.8.2 nathanw if (status & TXSTAT_COLL)
925 1.7.8.2 nathanw ifp->if_collisions++;
926 1.7.8.2 nathanw
927 1.7.8.2 nathanw if (status & TXSTAT_UFLOW) {
928 1.7.8.2 nathanw printf("%s: transmit underflow\n", sc->sc_dev.dv_xname);
929 1.7.8.2 nathanw ifp->if_oerrors++;
930 1.7.8.2 nathanw }
931 1.7.8.2 nathanw
932 1.7.8.2 nathanw if (status & TXSTAT_16COLL) {
933 1.7.8.2 nathanw printf("%s: max collisions reached\n", sc->sc_dev.dv_xname);
934 1.7.8.2 nathanw ifp->if_oerrors++;
935 1.7.8.2 nathanw ifp->if_collisions += 16;
936 1.7.8.2 nathanw }
937 1.7.8.2 nathanw }
938 1.7.8.2 nathanw
939 1.7.8.2 nathanw i = sc->sc_prevtx;
940 1.7.8.2 nathanw while (sc->sc_nfreetx < SQ_NTXDESC) {
941 1.7.8.2 nathanw /*
942 1.7.8.2 nathanw * Check status first so we don't end up with a case of
943 1.7.8.2 nathanw * the buffer not being finished while the DMA channel
944 1.7.8.2 nathanw * has gone idle.
945 1.7.8.2 nathanw */
946 1.7.8.2 nathanw status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch,
947 1.7.8.2 nathanw HPC_ENETX_CTL);
948 1.7.8.2 nathanw
949 1.7.8.2 nathanw SQ_CDTXSYNC(sc, i, sc->sc_txmap[i]->dm_nsegs,
950 1.7.8.2 nathanw BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
951 1.7.8.2 nathanw
952 1.7.8.2 nathanw /* If not yet transmitted, try and start DMA engine again */
953 1.7.8.2 nathanw if ((sc->sc_txdesc[i].hdd_ctl & HDD_CTL_XMITDONE) == 0) {
954 1.7.8.2 nathanw if ((status & ENETX_CTL_ACTIVE) == 0) {
955 1.7.8.2 nathanw SQ_TRACE(SQ_RESTART_DMA, i, status, sc->sc_nfreetx);
956 1.7.8.2 nathanw
957 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch,
958 1.7.8.2 nathanw HPC_ENETX_NDBP, SQ_CDTXADDR(sc, i));
959 1.7.8.2 nathanw
960 1.7.8.2 nathanw /* Kick DMA channel into life */
961 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch,
962 1.7.8.2 nathanw HPC_ENETX_CTL, ENETX_CTL_ACTIVE);
963 1.7.8.2 nathanw
964 1.7.8.2 nathanw /* Set a watchdog timer in case the chip flakes out. */
965 1.7.8.2 nathanw ifp->if_timer = 5;
966 1.7.8.2 nathanw } else {
967 1.7.8.2 nathanw SQ_TRACE(SQ_TXINTR_BUSY, i, status, sc->sc_nfreetx);
968 1.7.8.2 nathanw }
969 1.7.8.2 nathanw break;
970 1.7.8.2 nathanw }
971 1.7.8.2 nathanw
972 1.7.8.2 nathanw /* Sync the packet data, unload DMA map, free mbuf */
973 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, sc->sc_txmap[i], 0,
974 1.7.8.2 nathanw sc->sc_txmap[i]->dm_mapsize,
975 1.7.8.2 nathanw BUS_DMASYNC_POSTWRITE);
976 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, sc->sc_txmap[i]);
977 1.7.8.2 nathanw m_freem(sc->sc_txmbuf[i]);
978 1.7.8.2 nathanw sc->sc_txmbuf[i] = NULL;
979 1.7.8.2 nathanw
980 1.7.8.2 nathanw ifp->if_opackets++;
981 1.7.8.2 nathanw sc->sc_nfreetx++;
982 1.7.8.2 nathanw
983 1.7.8.2 nathanw SQ_TRACE(SQ_DONE_DMA, i, status, sc->sc_nfreetx);
984 1.7.8.2 nathanw i = SQ_NEXTTX(i);
985 1.7.8.2 nathanw }
986 1.7.8.2 nathanw
987 1.7.8.2 nathanw /* prevtx now points to next xmit packet not yet finished */
988 1.7.8.2 nathanw sc->sc_prevtx = i;
989 1.7.8.2 nathanw
990 1.7.8.2 nathanw /* If we have buffers free, let upper layers know */
991 1.7.8.2 nathanw if (sc->sc_nfreetx > 0)
992 1.7.8.2 nathanw ifp->if_flags &= ~IFF_OACTIVE;
993 1.7.8.2 nathanw
994 1.7.8.2 nathanw /* If all packets have left the coop, cancel watchdog */
995 1.7.8.2 nathanw if (sc->sc_nfreetx == SQ_NTXDESC)
996 1.7.8.2 nathanw ifp->if_timer = 0;
997 1.7.8.2 nathanw
998 1.7.8.2 nathanw SQ_TRACE(SQ_TXINTR_EXIT, sc->sc_prevtx, status, sc->sc_nfreetx);
999 1.7.8.2 nathanw sq_start(ifp);
1000 1.7.8.2 nathanw
1001 1.7.8.2 nathanw return 1;
1002 1.7.8.2 nathanw }
1003 1.7.8.2 nathanw
1004 1.7.8.2 nathanw
1005 1.7.8.2 nathanw void
1006 1.7.8.2 nathanw sq_reset(struct sq_softc *sc)
1007 1.7.8.2 nathanw {
1008 1.7.8.2 nathanw /* Stop HPC dma channels */
1009 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_CTL, 0);
1010 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETX_CTL, 0);
1011 1.7.8.2 nathanw
1012 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_RESET, 3);
1013 1.7.8.2 nathanw delay(20);
1014 1.7.8.2 nathanw bus_space_write_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETR_RESET, 0);
1015 1.7.8.2 nathanw }
1016 1.7.8.2 nathanw
1017 1.7.8.2 nathanw /* sq_add_rxbuf: Add a receive buffer to the indicated descriptor. */
1018 1.7.8.2 nathanw int
1019 1.7.8.2 nathanw sq_add_rxbuf(struct sq_softc *sc, int idx)
1020 1.7.8.2 nathanw {
1021 1.7.8.2 nathanw int err;
1022 1.7.8.2 nathanw struct mbuf *m;
1023 1.7.8.2 nathanw
1024 1.7.8.2 nathanw MGETHDR(m, M_DONTWAIT, MT_DATA);
1025 1.7.8.2 nathanw if (m == NULL)
1026 1.7.8.2 nathanw return (ENOBUFS);
1027 1.7.8.2 nathanw
1028 1.7.8.2 nathanw MCLGET(m, M_DONTWAIT);
1029 1.7.8.2 nathanw if ((m->m_flags & M_EXT) == 0) {
1030 1.7.8.2 nathanw m_freem(m);
1031 1.7.8.2 nathanw return (ENOBUFS);
1032 1.7.8.2 nathanw }
1033 1.7.8.2 nathanw
1034 1.7.8.2 nathanw if (sc->sc_rxmbuf[idx] != NULL)
1035 1.7.8.2 nathanw bus_dmamap_unload(sc->sc_dmat, sc->sc_rxmap[idx]);
1036 1.7.8.2 nathanw
1037 1.7.8.2 nathanw sc->sc_rxmbuf[idx] = m;
1038 1.7.8.2 nathanw
1039 1.7.8.2 nathanw if ((err = bus_dmamap_load(sc->sc_dmat, sc->sc_rxmap[idx],
1040 1.7.8.2 nathanw m->m_ext.ext_buf, m->m_ext.ext_size,
1041 1.7.8.2 nathanw NULL, BUS_DMA_NOWAIT)) != 0) {
1042 1.7.8.2 nathanw printf("%s: can't load rx DMA map %d, error = %d\n",
1043 1.7.8.2 nathanw sc->sc_dev.dv_xname, idx, err);
1044 1.7.8.2 nathanw panic("sq_add_rxbuf"); /* XXX */
1045 1.7.8.2 nathanw }
1046 1.7.8.2 nathanw
1047 1.7.8.2 nathanw bus_dmamap_sync(sc->sc_dmat, sc->sc_rxmap[idx], 0,
1048 1.7.8.2 nathanw sc->sc_rxmap[idx]->dm_mapsize, BUS_DMASYNC_PREREAD);
1049 1.7.8.2 nathanw
1050 1.7.8.2 nathanw SQ_INIT_RXDESC(sc, idx);
1051 1.7.8.2 nathanw
1052 1.7.8.2 nathanw return 0;
1053 1.7.8.2 nathanw }
1054 1.7.8.2 nathanw
1055 1.7.8.2 nathanw void
1056 1.7.8.2 nathanw sq_dump_buffer(u_int32_t addr, u_int32_t len)
1057 1.7.8.2 nathanw {
1058 1.7.8.2 nathanw int i;
1059 1.7.8.2 nathanw u_char* physaddr = (char*) MIPS_PHYS_TO_KSEG1((caddr_t)addr);
1060 1.7.8.2 nathanw
1061 1.7.8.2 nathanw if (len == 0)
1062 1.7.8.2 nathanw return;
1063 1.7.8.2 nathanw
1064 1.7.8.2 nathanw printf("%p: ", physaddr);
1065 1.7.8.2 nathanw
1066 1.7.8.2 nathanw for(i = 0; i < len; i++) {
1067 1.7.8.2 nathanw printf("%02x ", *(physaddr + i) & 0xff);
1068 1.7.8.2 nathanw if ((i % 16) == 15 && i != len - 1)
1069 1.7.8.2 nathanw printf("\n%p: ", physaddr + i);
1070 1.7.8.2 nathanw }
1071 1.7.8.2 nathanw
1072 1.7.8.2 nathanw printf("\n");
1073 1.7.8.2 nathanw }
1074 1.7.8.2 nathanw
1075 1.7.8.2 nathanw
1076 1.7.8.2 nathanw void
1077 1.7.8.2 nathanw enaddr_aton(const char* str, u_int8_t* eaddr)
1078 1.7.8.2 nathanw {
1079 1.7.8.2 nathanw int i;
1080 1.7.8.2 nathanw char c;
1081 1.7.8.2 nathanw
1082 1.7.8.2 nathanw for(i = 0; i < ETHER_ADDR_LEN; i++) {
1083 1.7.8.2 nathanw if (*str == ':')
1084 1.7.8.2 nathanw str++;
1085 1.7.8.2 nathanw
1086 1.7.8.2 nathanw c = *str++;
1087 1.7.8.2 nathanw if (isdigit(c)) {
1088 1.7.8.2 nathanw eaddr[i] = (c - '0');
1089 1.7.8.2 nathanw } else if (isxdigit(c)) {
1090 1.7.8.2 nathanw eaddr[i] = (toupper(c) + 10 - 'A');
1091 1.7.8.2 nathanw }
1092 1.7.8.2 nathanw
1093 1.7.8.2 nathanw c = *str++;
1094 1.7.8.2 nathanw if (isdigit(c)) {
1095 1.7.8.2 nathanw eaddr[i] = (eaddr[i] << 4) | (c - '0');
1096 1.7.8.2 nathanw } else if (isxdigit(c)) {
1097 1.7.8.2 nathanw eaddr[i] = (eaddr[i] << 4) | (toupper(c) + 10 - 'A');
1098 1.7.8.2 nathanw }
1099 1.7.8.2 nathanw }
1100 1.7.8.2 nathanw }
1101