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