Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / evbppc / virtex / dev / if_temac.c
blob883138e4d09066babe8760d85f9fc5c4471f712d
1 /* $NetBSD: if_temac.c,v 1.4 2008/02/12 18:03:43 dyoung Exp $ */
3 /*
4 * Copyright (c) 2006 Jachym Holecek
5 * All rights reserved.
7 * Written for DFC Design, s.r.o.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Driver for Xilinx LocalLink TEMAC as wired on the GSRD platform.
35 * TODO:
36 * - Optimize
37 * - Checksum offload
38 * - Address filters
39 * - Support jumbo frames
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: if_temac.c,v 1.4 2008/02/12 18:03:43 dyoung Exp $");
45 #include "bpfilter.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/mbuf.h>
50 #include <sys/kernel.h>
51 #include <sys/socket.h>
52 #include <sys/ioctl.h>
53 #include <sys/device.h>
55 #include <uvm/uvm_extern.h>
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <net/if_media.h>
60 #include <net/if_ether.h>
62 #if NBPFILTER > 0
63 #include <net/bpf.h>
64 #endif
66 #include <machine/bus.h>
68 #include <evbppc/virtex/idcr.h>
69 #include <evbppc/virtex/dev/xcvbusvar.h>
70 #include <evbppc/virtex/dev/cdmacreg.h>
71 #include <evbppc/virtex/dev/temacreg.h>
72 #include <evbppc/virtex/dev/temacvar.h>
74 #include <dev/mii/miivar.h>
77 /* This is outside of TEMAC's DCR window, we have to hardcode it... */
78 #define DCR_ETH_BASE 0x0030
80 #define TEMAC_REGDEBUG 0
81 #define TEMAC_RXDEBUG 0
82 #define TEMAC_TXDEBUG 0
84 #if TEMAC_RXDEBUG > 0 || TEMAC_TXDEBUG > 0
85 #define TEMAC_DEBUG 1
86 #else
87 #define TEMAC_DEBUG 0
88 #endif
90 #if TEMAC_REGDEBUG > 0
91 #define TRACEREG(arg) printf arg
92 #else
93 #define TRACEREG(arg) /* nop */
94 #endif
96 /* DMA control chains take up one (16KB) page. */
97 #define TEMAC_NTXDESC 256
98 #define TEMAC_NRXDESC 256
100 #define TEMAC_TXQLEN 64 /* Software Tx queue length */
101 #define TEMAC_NTXSEG 16 /* Maximum Tx segments per packet */
103 #define TEMAC_NRXSEG 1 /* Maximum Rx segments per packet */
104 #define TEMAC_RXPERIOD 1 /* Interrupt every N descriptors. */
105 #define TEMAC_RXTIMO_HZ 100 /* Rx reaper frequency */
107 /* Next Tx descriptor and descriptor's offset WRT sc_cdaddr. */
108 #define TEMAC_TXSINC(n, i) (((n) + TEMAC_TXQLEN + (i)) % TEMAC_TXQLEN)
109 #define TEMAC_TXINC(n, i) (((n) + TEMAC_NTXDESC + (i)) % TEMAC_NTXDESC)
111 #define TEMAC_TXSNEXT(n) TEMAC_TXSINC((n), 1)
112 #define TEMAC_TXNEXT(n) TEMAC_TXINC((n), 1)
113 #define TEMAC_TXDOFF(n) (offsetof(struct temac_control, cd_txdesc) + \
114 (n) * sizeof(struct cdmac_descr))
116 /* Next Rx descriptor and descriptor's offset WRT sc_cdaddr. */
117 #define TEMAC_RXINC(n, i) (((n) + TEMAC_NRXDESC + (i)) % TEMAC_NRXDESC)
118 #define TEMAC_RXNEXT(n) TEMAC_RXINC((n), 1)
119 #define TEMAC_RXDOFF(n) (offsetof(struct temac_control, cd_rxdesc) + \
120 (n) * sizeof(struct cdmac_descr))
121 #define TEMAC_ISINTR(i) (((i) % TEMAC_RXPERIOD) == 0)
122 #define TEMAC_ISLAST(i) ((i) == (TEMAC_NRXDESC - 1))
125 struct temac_control {
126 struct cdmac_descr cd_txdesc[TEMAC_NTXDESC];
127 struct cdmac_descr cd_rxdesc[TEMAC_NRXDESC];
130 struct temac_txsoft {
131 bus_dmamap_t txs_dmap;
132 struct mbuf *txs_mbuf;
133 int txs_last;
136 struct temac_rxsoft {
137 bus_dmamap_t rxs_dmap;
138 struct mbuf *rxs_mbuf;
141 struct temac_softc {
142 struct device sc_dev;
143 struct ethercom sc_ec;
144 #define sc_if sc_ec.ec_if
146 /* Peripheral registers */
147 bus_space_tag_t sc_iot;
148 bus_space_handle_t sc_ioh;
150 /* CDMAC channel registers */
151 bus_space_tag_t sc_dma_rxt;
152 bus_space_handle_t sc_dma_rxh; /* Rx channel */
153 bus_space_handle_t sc_dma_rsh; /* Rx status */
155 bus_space_tag_t sc_dma_txt;
156 bus_space_handle_t sc_dma_txh; /* Tx channel */
157 bus_space_handle_t sc_dma_tsh; /* Tx status */
159 struct temac_txsoft sc_txsoft[TEMAC_TXQLEN];
160 struct temac_rxsoft sc_rxsoft[TEMAC_NRXDESC];
162 struct callout sc_rx_timo;
163 struct callout sc_mii_tick;
164 struct mii_data sc_mii;
166 bus_dmamap_t sc_control_dmap;
167 #define sc_cdaddr sc_control_dmap->dm_segs[0].ds_addr
169 struct temac_control *sc_control_data;
170 #define sc_rxdescs sc_control_data->cd_rxdesc
171 #define sc_txdescs sc_control_data->cd_txdesc
173 int sc_txbusy;
175 int sc_txfree;
176 int sc_txcur;
177 int sc_txreap;
179 int sc_rxreap;
181 int sc_txsfree;
182 int sc_txscur;
183 int sc_txsreap;
185 int sc_dead; /* Rx/Tx DMA error (fatal) */
186 int sc_rx_drained;
188 int sc_rx_chan;
189 int sc_tx_chan;
191 void *sc_sdhook;
192 void *sc_rx_ih;
193 void *sc_tx_ih;
195 bus_dma_tag_t sc_dmat;
198 /* Device interface. */
199 static void temac_attach(struct device *, struct device *, void *);
201 /* Ifnet interface. */
202 static int temac_init(struct ifnet *);
203 static int temac_ioctl(struct ifnet *, u_long, void *);
204 static void temac_start(struct ifnet *);
205 static void temac_stop(struct ifnet *, int);
207 /* Media management. */
208 static int temac_mii_readreg(struct device *, int, int);
209 static void temac_mii_statchg(struct device *);
210 static void temac_mii_tick(void *);
211 static void temac_mii_writereg(struct device *, int, int, int);
213 /* Indirect hooks. */
214 static void temac_shutdown(void *);
215 static void temac_rx_intr(void *);
216 static void temac_tx_intr(void *);
218 /* Tools. */
219 static inline void temac_rxcdsync(struct temac_softc *, int, int, int);
220 static inline void temac_txcdsync(struct temac_softc *, int, int, int);
221 static void temac_txreap(struct temac_softc *);
222 static void temac_rxreap(struct temac_softc *);
223 static int temac_rxalloc(struct temac_softc *, int, int);
224 static void temac_rxtimo(void *);
225 static void temac_rxdrain(struct temac_softc *);
226 static void temac_reset(struct temac_softc *);
227 static void temac_txkick(struct temac_softc *);
229 /* Register access. */
230 static inline void gmi_write_8(uint32_t, uint32_t, uint32_t);
231 static inline void gmi_write_4(uint32_t, uint32_t);
232 static inline void gmi_read_8(uint32_t, uint32_t *, uint32_t *);
233 static inline uint32_t gmi_read_4(uint32_t);
234 static inline void hif_wait_stat(uint32_t);
236 #define cdmac_rx_stat(sc) \
237 bus_space_read_4((sc)->sc_dma_rxt, (sc)->sc_dma_rsh, 0 /* XXX hack */)
239 #define cdmac_rx_reset(sc) \
240 bus_space_write_4((sc)->sc_dma_rxt, (sc)->sc_dma_rsh, 0, CDMAC_STAT_RESET)
242 #define cdmac_rx_start(sc, val) \
243 bus_space_write_4((sc)->sc_dma_rxt, (sc)->sc_dma_rxh, CDMAC_CURDESC, (val))
245 #define cdmac_tx_stat(sc) \
246 bus_space_read_4((sc)->sc_dma_txt, (sc)->sc_dma_tsh, 0 /* XXX hack */)
248 #define cdmac_tx_reset(sc) \
249 bus_space_write_4((sc)->sc_dma_txt, (sc)->sc_dma_tsh, 0, CDMAC_STAT_RESET)
251 #define cdmac_tx_start(sc, val) \
252 bus_space_write_4((sc)->sc_dma_txt, (sc)->sc_dma_txh, CDMAC_CURDESC, (val))
255 CFATTACH_DECL(temac, sizeof(struct temac_softc),
256 xcvbus_child_match, temac_attach, NULL, NULL);
260 * Private bus utilities.
262 static inline void
263 hif_wait_stat(uint32_t mask)
265 int i = 0;
267 while (mask != (mfidcr(IDCR_HIF_STAT) & mask)) {
268 if (i++ > 100) {
269 printf("%s: timeout waiting for 0x%08x\n",
270 __func__, mask);
271 break;
273 delay(5);
276 TRACEREG(("%s: stat %#08x loops %d\n", __func__, mask, i));
279 static inline void
280 gmi_write_4(uint32_t addr, uint32_t lo)
282 mtidcr(IDCR_HIF_ARG0, lo);
283 mtidcr(IDCR_HIF_CTRL, (addr & HIF_CTRL_GMIADDR) | HIF_CTRL_WRITE);
284 hif_wait_stat(HIF_STAT_GMIWR);
286 TRACEREG(("%s: %#08x <- %#08x\n", __func__, addr, lo));
289 static inline void
290 gmi_write_8(uint32_t addr, uint32_t lo, uint32_t hi)
292 mtidcr(IDCR_HIF_ARG1, hi);
293 gmi_write_4(addr, lo);
296 static inline void
297 gmi_read_8(uint32_t addr, uint32_t *lo, uint32_t *hi)
299 *lo = gmi_read_4(addr);
300 *hi = mfidcr(IDCR_HIF_ARG1);
303 static inline uint32_t
304 gmi_read_4(uint32_t addr)
306 uint32_t res;
308 mtidcr(IDCR_HIF_CTRL, addr & HIF_CTRL_GMIADDR);
309 hif_wait_stat(HIF_STAT_GMIRR);
311 res = mfidcr(IDCR_HIF_ARG0);
312 TRACEREG(("%s: %#08x -> %#08x\n", __func__, addr, res));
313 return (res);
317 * Generic device.
319 static void
320 temac_attach(struct device *parent, struct device *self, void *aux)
322 struct xcvbus_attach_args *vaa = aux;
323 struct ll_dmac *rx = vaa->vaa_rx_dmac;
324 struct ll_dmac *tx = vaa->vaa_tx_dmac;
325 struct temac_softc *sc = (struct temac_softc *)self;
326 struct ifnet *ifp = &sc->sc_if;
327 struct mii_data *mii = &sc->sc_mii;
328 uint8_t enaddr[ETHER_ADDR_LEN];
329 bus_dma_segment_t seg;
330 int error, nseg, i;
332 printf(": TEMAC\n"); /* XXX will be LL_TEMAC, PLB_TEMAC */
334 KASSERT(rx);
335 KASSERT(tx);
337 sc->sc_dmat = vaa->vaa_dmat;
338 sc->sc_dead = 0;
339 sc->sc_rx_drained = 1;
340 sc->sc_txbusy = 0;
341 sc->sc_iot = vaa->vaa_iot;
342 sc->sc_dma_rxt = rx->dmac_iot;
343 sc->sc_dma_txt = tx->dmac_iot;
346 * Map HIF and receive/transmit dmac registers.
348 if ((error = bus_space_map(vaa->vaa_iot, vaa->vaa_addr, TEMAC_SIZE, 0,
349 &sc->sc_ioh)) != 0) {
350 printf("%s: could not map registers\n", device_xname(self));
351 goto fail_0;
354 if ((error = bus_space_map(sc->sc_dma_rxt, rx->dmac_ctrl_addr,
355 CDMAC_CTRL_SIZE, 0, &sc->sc_dma_rxh)) != 0) {
356 printf("%s: could not map Rx control registers\n",
357 device_xname(self));
358 goto fail_0;
360 if ((error = bus_space_map(sc->sc_dma_rxt, rx->dmac_stat_addr,
361 CDMAC_STAT_SIZE, 0, &sc->sc_dma_rsh)) != 0) {
362 printf("%s: could not map Rx status register\n",
363 device_xname(self));
364 goto fail_0;
367 if ((error = bus_space_map(sc->sc_dma_txt, tx->dmac_ctrl_addr,
368 CDMAC_CTRL_SIZE, 0, &sc->sc_dma_txh)) != 0) {
369 printf("%s: could not map Tx control registers\n",
370 device_xname(self));
371 goto fail_0;
373 if ((error = bus_space_map(sc->sc_dma_txt, tx->dmac_stat_addr,
374 CDMAC_STAT_SIZE, 0, &sc->sc_dma_tsh)) != 0) {
375 printf("%s: could not map Tx status register\n",
376 device_xname(self));
377 goto fail_0;
381 * Allocate and initialize DMA control chains.
383 if ((error = bus_dmamem_alloc(sc->sc_dmat,
384 sizeof(struct temac_control), 8, 0, &seg, 1, &nseg, 0)) != 0) {
385 printf("%s: could not allocate control data\n",
386 sc->sc_dev.dv_xname);
387 goto fail_0;
390 if ((error = bus_dmamem_map(sc->sc_dmat, &seg, nseg,
391 sizeof(struct temac_control),
392 (void **)&sc->sc_control_data, BUS_DMA_COHERENT)) != 0) {
393 printf("%s: could not map control data\n",
394 sc->sc_dev.dv_xname);
395 goto fail_1;
398 if ((error = bus_dmamap_create(sc->sc_dmat,
399 sizeof(struct temac_control), 1,
400 sizeof(struct temac_control), 0, 0, &sc->sc_control_dmap)) != 0) {
401 printf("%s: could not create control data DMA map\n",
402 sc->sc_dev.dv_xname);
403 goto fail_2;
406 if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_control_dmap,
407 sc->sc_control_data, sizeof(struct temac_control), NULL, 0)) != 0) {
408 printf("%s: could not load control data DMA map\n",
409 sc->sc_dev.dv_xname);
410 goto fail_3;
414 * Link descriptor chains.
416 memset(sc->sc_control_data, 0, sizeof(struct temac_control));
418 for (i = 0; i < TEMAC_NTXDESC; i++) {
419 sc->sc_txdescs[i].desc_next = sc->sc_cdaddr +
420 TEMAC_TXDOFF(TEMAC_TXNEXT(i));
421 sc->sc_txdescs[i].desc_stat = CDMAC_STAT_DONE;
423 for (i = 0; i < TEMAC_NRXDESC; i++) {
424 sc->sc_rxdescs[i].desc_next = sc->sc_cdaddr +
425 TEMAC_RXDOFF(TEMAC_RXNEXT(i));
426 sc->sc_txdescs[i].desc_stat = CDMAC_STAT_DONE;
429 bus_dmamap_sync(sc->sc_dmat, sc->sc_control_dmap, 0,
430 sizeof(struct temac_control),
431 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
434 * Initialize software state for transmit/receive jobs.
436 for (i = 0; i < TEMAC_TXQLEN; i++) {
437 if ((error = bus_dmamap_create(sc->sc_dmat,
438 ETHER_MAX_LEN_JUMBO, TEMAC_NTXSEG, ETHER_MAX_LEN_JUMBO,
439 0, 0, &sc->sc_txsoft[i].txs_dmap)) != 0) {
440 printf("%s: could not create Tx DMA map %d\n",
441 sc->sc_dev.dv_xname, i);
442 goto fail_4;
444 sc->sc_txsoft[i].txs_mbuf = NULL;
445 sc->sc_txsoft[i].txs_last = 0;
448 for (i = 0; i < TEMAC_NRXDESC; i++) {
449 if ((error = bus_dmamap_create(sc->sc_dmat,
450 MCLBYTES, TEMAC_NRXSEG, MCLBYTES, 0, 0,
451 &sc->sc_rxsoft[i].rxs_dmap)) != 0) {
452 printf("%s: could not create Rx DMA map %d\n",
453 sc->sc_dev.dv_xname, i);
454 goto fail_5;
456 sc->sc_rxsoft[i].rxs_mbuf = NULL;
460 * Setup transfer interrupt handlers.
462 error = ENOMEM;
464 sc->sc_rx_ih = ll_dmac_intr_establish(rx->dmac_chan,
465 temac_rx_intr, sc);
466 if (sc->sc_rx_ih == NULL) {
467 printf("%s: could not establish Rx interrupt\n",
468 device_xname(self));
469 goto fail_5;
472 sc->sc_tx_ih = ll_dmac_intr_establish(tx->dmac_chan,
473 temac_tx_intr, sc);
474 if (sc->sc_tx_ih == NULL) {
475 printf("%s: could not establish Tx interrupt\n",
476 device_xname(self));
477 goto fail_6;
480 /* XXXFreza: faked, should read unicast address filter. */
481 enaddr[0] = 0x00;
482 enaddr[1] = 0x11;
483 enaddr[2] = 0x17;
484 enaddr[3] = 0xff;
485 enaddr[4] = 0xff;
486 enaddr[5] = 0x01;
489 * Initialize the TEMAC.
491 temac_reset(sc);
493 /* Configure MDIO link. */
494 gmi_write_4(TEMAC_GMI_MGMTCF, GMI_MGMT_CLKDIV_100MHz | GMI_MGMT_MDIO);
496 /* Initialize PHY. */
497 mii->mii_ifp = ifp;
498 mii->mii_readreg = temac_mii_readreg;
499 mii->mii_writereg = temac_mii_writereg;
500 mii->mii_statchg = temac_mii_statchg;
501 sc->sc_ec.ec_mii = mii;
502 ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus);
504 mii_attach(&sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY,
505 MII_OFFSET_ANY, 0);
506 if (LIST_FIRST(&mii->mii_phys) == NULL) {
507 ifmedia_add(&mii->mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
508 ifmedia_set(&mii->mii_media, IFM_ETHER|IFM_NONE);
509 } else {
510 ifmedia_set(&mii->mii_media, IFM_ETHER|IFM_AUTO);
513 /* Hold PHY in reset. */
514 bus_space_write_4(sc->sc_iot, sc->sc_ioh, TEMAC_RESET, TEMAC_RESET_PHY);
516 /* Reset EMAC. */
517 bus_space_write_4(sc->sc_iot, sc->sc_ioh, TEMAC_RESET,
518 TEMAC_RESET_EMAC);
519 delay(10000);
521 /* Reset peripheral, awakes PHY and EMAC. */
522 bus_space_write_4(sc->sc_iot, sc->sc_ioh, TEMAC_RESET,
523 TEMAC_RESET_PERIPH);
524 delay(40000);
526 /* (Re-)Configure MDIO link. */
527 gmi_write_4(TEMAC_GMI_MGMTCF, GMI_MGMT_CLKDIV_100MHz | GMI_MGMT_MDIO);
530 * Hook up with network stack.
532 strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
533 ifp->if_softc = sc;
534 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
535 ifp->if_ioctl = temac_ioctl;
536 ifp->if_start = temac_start;
537 ifp->if_init = temac_init;
538 ifp->if_stop = temac_stop;
539 ifp->if_watchdog = NULL;
540 IFQ_SET_READY(&ifp->if_snd);
541 IFQ_SET_MAXLEN(&ifp->if_snd, TEMAC_TXQLEN);
543 sc->sc_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
545 if_attach(ifp);
546 ether_ifattach(ifp, enaddr);
548 sc->sc_sdhook = shutdownhook_establish(temac_shutdown, sc);
549 if (sc->sc_sdhook == NULL)
550 printf("%s: WARNING: unable to establish shutdown hook\n",
551 device_xname(self));
553 callout_setfunc(&sc->sc_mii_tick, temac_mii_tick, sc);
554 callout_setfunc(&sc->sc_rx_timo, temac_rxtimo, sc);
556 return ;
558 fail_6:
559 ll_dmac_intr_disestablish(rx->dmac_chan, sc->sc_rx_ih);
560 i = TEMAC_NRXDESC;
561 fail_5:
562 for (--i; i >= 0; i--)
563 bus_dmamap_destroy(sc->sc_dmat, sc->sc_rxsoft[i].rxs_dmap);
564 i = TEMAC_TXQLEN;
565 fail_4:
566 for (--i; i >= 0; i--)
567 bus_dmamap_destroy(sc->sc_dmat, sc->sc_txsoft[i].txs_dmap);
568 fail_3:
569 bus_dmamap_destroy(sc->sc_dmat, sc->sc_control_dmap);
570 fail_2:
571 bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_control_data,
572 sizeof(struct temac_control));
573 fail_1:
574 bus_dmamem_free(sc->sc_dmat, &seg, nseg);
575 fail_0:
576 printf("%s: error = %d\n", device_xname(self), error);
580 * Network device.
582 static int
583 temac_init(struct ifnet *ifp)
585 struct temac_softc *sc = (struct temac_softc *)ifp->if_softc;
586 uint32_t rcr, tcr;
587 int i, error;
589 /* Reset DMA channels. */
590 cdmac_tx_reset(sc);
591 cdmac_rx_reset(sc);
593 /* Set current media. */
594 if ((error = ether_mediachange(ifp)) != 0)
595 return error;
597 callout_schedule(&sc->sc_mii_tick, hz);
599 /* Enable EMAC engine. */
600 rcr = (gmi_read_4(TEMAC_GMI_RXCF1) | GMI_RX_ENABLE) &
601 ~(GMI_RX_JUMBO | GMI_RX_FCS);
602 gmi_write_4(TEMAC_GMI_RXCF1, rcr);
604 tcr = (gmi_read_4(TEMAC_GMI_TXCF) | GMI_TX_ENABLE) &
605 ~(GMI_TX_JUMBO | GMI_TX_FCS);
606 gmi_write_4(TEMAC_GMI_TXCF, tcr);
608 /* XXXFreza: Force promiscuous mode, for now. */
609 gmi_write_4(TEMAC_GMI_AFM, GMI_AFM_PROMISC);
610 ifp->if_flags |= IFF_PROMISC;
612 /* Rx/Tx queues are drained -- either from attach() or stop(). */
613 sc->sc_txsfree = TEMAC_TXQLEN;
614 sc->sc_txsreap = 0;
615 sc->sc_txscur = 0;
617 sc->sc_txfree = TEMAC_NTXDESC;
618 sc->sc_txreap = 0;
619 sc->sc_txcur = 0;
621 sc->sc_rxreap = 0;
623 /* Allocate and map receive buffers. */
624 if (sc->sc_rx_drained) {
625 for (i = 0; i < TEMAC_NRXDESC; i++) {
626 if ((error = temac_rxalloc(sc, i, 1)) != 0) {
627 printf("%s: failed to allocate Rx "
628 "descriptor %d\n",
629 sc->sc_dev.dv_xname, i);
631 temac_rxdrain(sc);
632 return (error);
635 sc->sc_rx_drained = 0;
637 temac_rxcdsync(sc, 0, TEMAC_NRXDESC,
638 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
639 cdmac_rx_start(sc, sc->sc_cdaddr + TEMAC_RXDOFF(0));
642 ifp->if_flags |= IFF_RUNNING;
643 ifp->if_flags &= ~IFF_OACTIVE;
645 return (0);
648 static int
649 temac_ioctl(struct ifnet *ifp, u_long cmd, void *data)
651 struct temac_softc *sc = (struct temac_softc *)ifp->if_softc;
652 int s, ret;
654 s = splnet();
655 if (sc->sc_dead)
656 ret = EIO;
657 else
658 ret = ether_ioctl(ifp, cmd, data);
659 splx(s);
660 return (ret);
663 static void
664 temac_start(struct ifnet *ifp)
666 struct temac_softc *sc = (struct temac_softc *)ifp->if_softc;
667 struct temac_txsoft *txs;
668 struct mbuf *m;
669 bus_dmamap_t dmap;
670 int error, head, nsegs, i;
672 nsegs = 0;
673 head = sc->sc_txcur;
674 txs = NULL; /* gcc */
676 if (sc->sc_dead)
677 return;
679 KASSERT(sc->sc_txfree >= 0);
680 KASSERT(sc->sc_txsfree >= 0);
683 * Push mbufs into descriptor chain until we drain the interface
684 * queue or run out of descriptors. We'll mark the first segment
685 * as "done" in hope that we might put CDMAC interrupt above IPL_NET
686 * and have it start jobs & mark packets for GC preemtively for
687 * us -- creativity due to limitations in CDMAC transfer engine
688 * (it really consumes lists, not circular queues, AFAICS).
690 * We schedule one interrupt per Tx batch.
692 while (1) {
693 IFQ_POLL(&ifp->if_snd, m);
694 if (m == NULL)
695 break;
697 if (sc->sc_txsfree == 0) {
698 ifp->if_flags |= IFF_OACTIVE;
699 break;
702 txs = &sc->sc_txsoft[sc->sc_txscur];
703 dmap = txs->txs_dmap;
705 if (txs->txs_mbuf != NULL)
706 printf("FOO\n");
707 if (txs->txs_last)
708 printf("BAR\n");
710 if ((error = bus_dmamap_load_mbuf(sc->sc_dmat, dmap, m,
711 BUS_DMA_WRITE | BUS_DMA_NOWAIT)) != 0) {
712 if (error == EFBIG) {
713 printf("%s: Tx consumes too many segments, "
714 "dropped\n", sc->sc_dev.dv_xname);
715 IFQ_DEQUEUE(&ifp->if_snd, m);
716 m_freem(m);
717 continue;
718 } else {
719 printf("%s: Tx stall due to resource "
720 "shortage\n", sc->sc_dev.dv_xname);
721 break;
726 * If we're short on DMA descriptors, notify upper layers
727 * and leave this packet for later.
729 if (dmap->dm_nsegs > sc->sc_txfree) {
730 bus_dmamap_unload(sc->sc_dmat, dmap);
731 ifp->if_flags |= IFF_OACTIVE;
732 break;
735 IFQ_DEQUEUE(&ifp->if_snd, m);
737 bus_dmamap_sync(sc->sc_dmat, dmap, 0, dmap->dm_mapsize,
738 BUS_DMASYNC_PREWRITE);
739 txs->txs_mbuf = m;
742 * Map the packet into descriptor chain. XXX We'll want
743 * to fill checksum offload commands here.
745 * We would be in a race if we weren't blocking CDMAC intr
746 * at this point -- we need to be locked against txreap()
747 * because of dmasync ops.
750 temac_txcdsync(sc, sc->sc_txcur, dmap->dm_nsegs,
751 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
753 for (i = 0; i < dmap->dm_nsegs; i++) {
754 sc->sc_txdescs[sc->sc_txcur].desc_addr =
755 dmap->dm_segs[i].ds_addr;
756 sc->sc_txdescs[sc->sc_txcur].desc_size =
757 dmap->dm_segs[i].ds_len;
758 sc->sc_txdescs[sc->sc_txcur].desc_stat =
759 (i == 0 ? CDMAC_STAT_SOP : 0) |
760 (i == (dmap->dm_nsegs - 1) ? CDMAC_STAT_EOP : 0);
762 sc->sc_txcur = TEMAC_TXNEXT(sc->sc_txcur);
765 sc->sc_txfree -= dmap->dm_nsegs;
766 nsegs += dmap->dm_nsegs;
768 sc->sc_txscur = TEMAC_TXSNEXT(sc->sc_txscur);
769 sc->sc_txsfree--;
772 /* Get data running if we queued any. */
773 if (nsegs > 0) {
774 int tail = TEMAC_TXINC(sc->sc_txcur, -1);
776 /* Mark the last packet in this job. */
777 txs->txs_last = 1;
779 /* Mark the last descriptor in this job. */
780 sc->sc_txdescs[tail].desc_stat |= CDMAC_STAT_STOP |
781 CDMAC_STAT_INTR;
782 temac_txcdsync(sc, head, nsegs,
783 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
785 temac_txkick(sc);
786 #if TEMAC_TXDEBUG > 0
787 printf("%s: start: txcur %03d -> %03d, nseg %03d\n",
788 sc->sc_dev.dv_xname, head, sc->sc_txcur, nsegs);
789 #endif
793 static void
794 temac_stop(struct ifnet *ifp, int disable)
796 struct temac_softc *sc = (struct temac_softc *)ifp->if_softc;
797 struct temac_txsoft *txs;
798 int i;
800 #if TEMAC_DEBUG > 0
801 printf("%s: stop\n", device_xname(&sc->sc_dev));
802 #endif
804 /* Down the MII. */
805 callout_stop(&sc->sc_mii_tick);
806 mii_down(&sc->sc_mii);
808 /* Stop the engine. */
809 temac_reset(sc);
811 /* Drain buffers queues (unconditionally). */
812 temac_rxdrain(sc);
814 for (i = 0; i < TEMAC_TXQLEN; i++) {
815 txs = &sc->sc_txsoft[i];
817 if (txs->txs_mbuf != NULL) {
818 bus_dmamap_unload(sc->sc_dmat, txs->txs_dmap);
819 m_freem(txs->txs_mbuf);
820 txs->txs_mbuf = NULL;
821 txs->txs_last = 0;
824 sc->sc_txbusy = 0;
826 /* Acknowledge we're down. */
827 ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
830 static int
831 temac_mii_readreg(struct device *self, int phy, int reg)
833 mtidcr(IDCR_HIF_ARG0, (phy << 5) | reg);
834 mtidcr(IDCR_HIF_CTRL, TEMAC_GMI_MII_ADDR);
835 hif_wait_stat(HIF_STAT_MIIRR);
837 return (int)mfidcr(IDCR_HIF_ARG0);
840 static void
841 temac_mii_writereg(struct device *self, int phy, int reg, int val)
843 mtidcr(IDCR_HIF_ARG0, val);
844 mtidcr(IDCR_HIF_CTRL, TEMAC_GMI_MII_WRVAL | HIF_CTRL_WRITE);
845 mtidcr(IDCR_HIF_ARG0, (phy << 5) | reg);
846 mtidcr(IDCR_HIF_CTRL, TEMAC_GMI_MII_ADDR | HIF_CTRL_WRITE);
847 hif_wait_stat(HIF_STAT_MIIWR);
850 static void
851 temac_mii_statchg(struct device *self)
853 struct temac_softc *sc = (struct temac_softc *)self;
854 uint32_t rcf, tcf, mmc;
856 /* Full/half duplex link. */
857 rcf = gmi_read_4(TEMAC_GMI_RXCF1);
858 tcf = gmi_read_4(TEMAC_GMI_TXCF);
860 if (sc->sc_mii.mii_media_active & IFM_FDX) {
861 gmi_write_4(TEMAC_GMI_RXCF1, rcf & ~GMI_RX_HDX);
862 gmi_write_4(TEMAC_GMI_TXCF, tcf & ~GMI_TX_HDX);
863 } else {
864 gmi_write_4(TEMAC_GMI_RXCF1, rcf | GMI_RX_HDX);
865 gmi_write_4(TEMAC_GMI_TXCF, tcf | GMI_TX_HDX);
868 /* Link speed. */
869 mmc = gmi_read_4(TEMAC_GMI_MMC) & ~GMI_MMC_SPEED_MASK;
871 switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) {
872 case IFM_10_T:
874 * XXXFreza: the GMAC is not happy with 10Mbit ethernet,
875 * although the documentation claims it's supported. Maybe
876 * it's just my equipment...
878 mmc |= GMI_MMC_SPEED_10;
879 break;
880 case IFM_100_TX:
881 mmc |= GMI_MMC_SPEED_100;
882 break;
883 case IFM_1000_T:
884 mmc |= GMI_MMC_SPEED_1000;
885 break;
888 gmi_write_4(TEMAC_GMI_MMC, mmc);
891 static void
892 temac_mii_tick(void *arg)
894 struct temac_softc *sc = (struct temac_softc *)arg;
895 int s;
897 if (!device_is_active(&sc->sc_dev))
898 return;
900 s = splnet();
901 mii_tick(&sc->sc_mii);
902 splx(s);
904 callout_schedule(&sc->sc_mii_tick, hz);
908 * External hooks.
910 static void
911 temac_shutdown(void *arg)
913 struct temac_softc *sc = (struct temac_softc *)arg;
915 temac_reset(sc);
918 static void
919 temac_tx_intr(void *arg)
921 struct temac_softc *sc = (struct temac_softc *)arg;
922 uint32_t stat;
924 /* XXX: We may need to splnet() here if cdmac(4) changes. */
926 if ((stat = cdmac_tx_stat(sc)) & CDMAC_STAT_ERROR) {
927 printf("%s: transmit DMA is toast (%#08x), halted!\n",
928 sc->sc_dev.dv_xname, stat);
930 /* XXXFreza: how to signal this upstream? */
931 temac_stop(&sc->sc_if, 1);
932 sc->sc_dead = 1;
935 #if TEMAC_DEBUG > 0
936 printf("%s: tx intr 0x%08x\n", device_xname(&sc->sc_dev), stat);
937 #endif
938 temac_txreap(sc);
941 static void
942 temac_rx_intr(void *arg)
944 struct temac_softc *sc = (struct temac_softc *)arg;
945 uint32_t stat;
947 /* XXX: We may need to splnet() here if cdmac(4) changes. */
949 if ((stat = cdmac_rx_stat(sc)) & CDMAC_STAT_ERROR) {
950 printf("%s: receive DMA is toast (%#08x), halted!\n",
951 sc->sc_dev.dv_xname, stat);
953 /* XXXFreza: how to signal this upstream? */
954 temac_stop(&sc->sc_if, 1);
955 sc->sc_dead = 1;
958 #if TEMAC_DEBUG > 0
959 printf("%s: rx intr 0x%08x\n", device_xname(&sc->sc_dev), stat);
960 #endif
961 temac_rxreap(sc);
965 * Utils.
967 static inline void
968 temac_txcdsync(struct temac_softc *sc, int first, int cnt, int flag)
970 if ((first + cnt) > TEMAC_NTXDESC) {
971 bus_dmamap_sync(sc->sc_dmat, sc->sc_control_dmap,
972 TEMAC_TXDOFF(first),
973 sizeof(struct cdmac_descr) * (TEMAC_NTXDESC - first),
974 flag);
975 cnt = (first + cnt) % TEMAC_NTXDESC;
976 first = 0;
979 bus_dmamap_sync(sc->sc_dmat, sc->sc_control_dmap,
980 TEMAC_TXDOFF(first),
981 sizeof(struct cdmac_descr) * cnt,
982 flag);
985 static inline void
986 temac_rxcdsync(struct temac_softc *sc, int first, int cnt, int flag)
988 if ((first + cnt) > TEMAC_NRXDESC) {
989 bus_dmamap_sync(sc->sc_dmat, sc->sc_control_dmap,
990 TEMAC_RXDOFF(first),
991 sizeof(struct cdmac_descr) * (TEMAC_NRXDESC - first),
992 flag);
993 cnt = (first + cnt) % TEMAC_NRXDESC;
994 first = 0;
997 bus_dmamap_sync(sc->sc_dmat, sc->sc_control_dmap,
998 TEMAC_RXDOFF(first),
999 sizeof(struct cdmac_descr) * cnt,
1000 flag);
1003 static void
1004 temac_txreap(struct temac_softc *sc)
1006 struct temac_txsoft *txs;
1007 bus_dmamap_t dmap;
1008 int sent = 0;
1011 * Transmit interrupts happen on the last descriptor of Tx jobs.
1012 * Hence, every time we're called (and we assume txintr is our
1013 * only caller!), we reap packets upto and including the one
1014 * marked as last-in-batch.
1016 * XXX we rely on that we make EXACTLY one batch per intr, no more
1018 while (sc->sc_txsfree != TEMAC_TXQLEN) {
1019 txs = &sc->sc_txsoft[sc->sc_txsreap];
1020 dmap = txs->txs_dmap;
1022 sc->sc_txreap = TEMAC_TXINC(sc->sc_txreap, dmap->dm_nsegs);
1023 sc->sc_txfree += dmap->dm_nsegs;
1025 bus_dmamap_unload(sc->sc_dmat, txs->txs_dmap);
1026 m_freem(txs->txs_mbuf);
1027 txs->txs_mbuf = NULL;
1029 sc->sc_if.if_opackets++;
1030 sent = 1;
1032 sc->sc_txsreap = TEMAC_TXSNEXT(sc->sc_txsreap);
1033 sc->sc_txsfree++;
1035 if (txs->txs_last) {
1036 txs->txs_last = 0;
1037 sc->sc_txbusy = 0; /* channel stopped now */
1039 temac_txkick(sc);
1040 break;
1044 if (sent && (sc->sc_if.if_flags & IFF_OACTIVE))
1045 sc->sc_if.if_flags &= ~IFF_OACTIVE;
1048 static int
1049 temac_rxalloc(struct temac_softc *sc, int which, int verbose)
1051 struct temac_rxsoft *rxs;
1052 struct mbuf *m;
1053 uint32_t stat;
1054 int error;
1056 rxs = &sc->sc_rxsoft[which];
1058 /* The mbuf itself is not our problem, just clear DMA related stuff. */
1059 if (rxs->rxs_mbuf != NULL) {
1060 bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmap);
1061 rxs->rxs_mbuf = NULL;
1065 * We would like to store mbuf and dmap in application specific
1066 * fields of the descriptor, but that doesn't work for Rx. Shame
1067 * on Xilinx for this (and for the useless timer architecture).
1069 * Hence each descriptor needs its own soft state. We may want
1070 * to merge multiple rxs's into a monster mbuf when we support
1071 * jumbo frames though. Also, we use single set of indexing
1072 * variables for both sc_rxdescs[] and sc_rxsoft[].
1074 MGETHDR(m, M_DONTWAIT, MT_DATA);
1075 if (m == NULL) {
1076 if (verbose)
1077 printf("%s: out of Rx header mbufs\n",
1078 sc->sc_dev.dv_xname);
1079 return (ENOBUFS);
1081 MCLAIM(m, &sc->sc_ec.ec_rx_mowner);
1083 MCLGET(m, M_DONTWAIT);
1084 if ((m->m_flags & M_EXT) == 0) {
1085 if (verbose)
1086 printf("%s: out of Rx cluster mbufs\n",
1087 sc->sc_dev.dv_xname);
1088 m_freem(m);
1089 return (ENOBUFS);
1092 rxs->rxs_mbuf = m;
1093 m->m_pkthdr.len = m->m_len = MCLBYTES;
1095 /* Make sure the payload after ethernet header is 4-aligned. */
1096 m_adj(m, 2);
1098 error = bus_dmamap_load_mbuf(sc->sc_dmat, rxs->rxs_dmap, m,
1099 BUS_DMA_NOWAIT);
1100 if (error) {
1101 if (verbose)
1102 printf("%s: could not map Rx descriptor %d, "
1103 "error = %d\n", sc->sc_dev.dv_xname, which, error);
1105 rxs->rxs_mbuf = NULL;
1106 m_freem(m);
1108 return (error);
1111 stat = \
1112 (TEMAC_ISINTR(which) ? CDMAC_STAT_INTR : 0) |
1113 (TEMAC_ISLAST(which) ? CDMAC_STAT_STOP : 0);
1115 bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmap, 0,
1116 rxs->rxs_dmap->dm_mapsize, BUS_DMASYNC_PREREAD);
1118 /* Descriptor post-sync, if needed, left to the caller. */
1120 sc->sc_rxdescs[which].desc_addr = rxs->rxs_dmap->dm_segs[0].ds_addr;
1121 sc->sc_rxdescs[which].desc_size = rxs->rxs_dmap->dm_segs[0].ds_len;
1122 sc->sc_rxdescs[which].desc_stat = stat;
1124 /* Descriptor pre-sync, if needed, left to the caller. */
1126 return (0);
1129 static void
1130 temac_rxreap(struct temac_softc *sc)
1132 struct ifnet *ifp = &sc->sc_if;
1133 uint32_t stat, rxstat, rxsize;
1134 struct mbuf *m;
1135 int nseg, head, tail;
1137 head = sc->sc_rxreap;
1138 tail = 0; /* gcc */
1139 nseg = 0;
1142 * Collect finished entries on the Rx list, kick DMA if we hit
1143 * the end. DMA will always stop on the last descriptor in chain,
1144 * so it will never hit a reap-in-progress descriptor.
1146 while (1) {
1147 /* Maybe we previously failed to refresh this one? */
1148 if (sc->sc_rxsoft[sc->sc_rxreap].rxs_mbuf == NULL) {
1149 if (temac_rxalloc(sc, sc->sc_rxreap, 0) != 0)
1150 break;
1152 sc->sc_rxreap = TEMAC_RXNEXT(sc->sc_rxreap);
1153 continue;
1155 temac_rxcdsync(sc, sc->sc_rxreap, 1,
1156 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
1158 stat = sc->sc_rxdescs[sc->sc_rxreap].desc_stat;
1159 m = NULL;
1161 if ((stat & CDMAC_STAT_DONE) == 0)
1162 break;
1164 /* Count any decriptor we've collected, regardless of status. */
1165 nseg ++;
1167 /* XXXFreza: This won't work for jumbo frames. */
1169 if ((stat & (CDMAC_STAT_EOP | CDMAC_STAT_SOP)) !=
1170 (CDMAC_STAT_EOP | CDMAC_STAT_SOP)) {
1171 printf("%s: Rx packet doesn't fit in "
1172 "one descriptor, stat = %#08x\n",
1173 sc->sc_dev.dv_xname, stat);
1174 goto badframe;
1177 /* Dissect TEMAC footer if this is end of packet. */
1178 rxstat = sc->sc_rxdescs[sc->sc_rxreap].desc_rxstat;
1179 rxsize = sc->sc_rxdescs[sc->sc_rxreap].desc_rxsize &
1180 RXSIZE_MASK;
1182 if ((rxstat & RXSTAT_GOOD) == 0 ||
1183 (rxstat & RXSTAT_SICK) != 0) {
1184 printf("%s: corrupt Rx packet, rxstat = %#08x\n",
1185 sc->sc_dev.dv_xname, rxstat);
1186 goto badframe;
1189 /* We are now bound to succeed. */
1190 bus_dmamap_sync(sc->sc_dmat,
1191 sc->sc_rxsoft[sc->sc_rxreap].rxs_dmap, 0,
1192 sc->sc_rxsoft[sc->sc_rxreap].rxs_dmap->dm_mapsize,
1193 BUS_DMASYNC_POSTREAD);
1195 m = sc->sc_rxsoft[sc->sc_rxreap].rxs_mbuf;
1196 m->m_pkthdr.rcvif = ifp;
1197 m->m_pkthdr.len = m->m_len = rxsize;
1199 badframe:
1200 /* Get ready for more work. */
1201 tail = sc->sc_rxreap;
1202 sc->sc_rxreap = TEMAC_RXNEXT(sc->sc_rxreap);
1204 /* On failures we reuse the descriptor and go ahead. */
1205 if (m == NULL) {
1206 sc->sc_rxdescs[tail].desc_stat =
1207 (TEMAC_ISINTR(tail) ? CDMAC_STAT_INTR : 0) |
1208 (TEMAC_ISLAST(tail) ? CDMAC_STAT_STOP : 0);
1210 ifp->if_ierrors++;
1211 continue;
1214 #if NBPFILTER > 0
1215 if (ifp->if_bpf != NULL)
1216 bpf_mtap(ifp->if_bpf, m);
1217 #endif
1219 ifp->if_ipackets++;
1220 (ifp->if_input)(ifp, m);
1222 /* Refresh descriptor, bail out if we're out of buffers. */
1223 if (temac_rxalloc(sc, tail, 1) != 0) {
1224 sc->sc_rxreap = TEMAC_RXINC(sc->sc_rxreap, -1);
1225 printf("%s: Rx give up for now\n", sc->sc_dev.dv_xname);
1226 break;
1230 /* We may now have a contiguous ready-to-go chunk of descriptors. */
1231 if (nseg > 0) {
1232 #if TEMAC_RXDEBUG > 0
1233 printf("%s: rxreap: rxreap %03d -> %03d, nseg %03d\n",
1234 sc->sc_dev.dv_xname, head, sc->sc_rxreap, nseg);
1235 #endif
1236 temac_rxcdsync(sc, head, nseg,
1237 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
1239 if (TEMAC_ISLAST(tail))
1240 cdmac_rx_start(sc, sc->sc_cdaddr + TEMAC_RXDOFF(0));
1243 /* Ensure maximum Rx latency is kept under control. */
1244 callout_schedule(&sc->sc_rx_timo, hz / TEMAC_RXTIMO_HZ);
1247 static void
1248 temac_rxtimo(void *arg)
1250 struct temac_softc *sc = (struct temac_softc *)arg;
1251 int s;
1253 /* We run TEMAC_RXTIMO_HZ times/sec to ensure Rx doesn't stall. */
1254 s = splnet();
1255 temac_rxreap(sc);
1256 splx(s);
1259 static void
1260 temac_reset(struct temac_softc *sc)
1262 uint32_t rcr, tcr;
1264 /* Kill CDMAC channels. */
1265 cdmac_tx_reset(sc);
1266 cdmac_rx_reset(sc);
1268 /* Disable receiver. */
1269 rcr = gmi_read_4(TEMAC_GMI_RXCF1) & ~GMI_RX_ENABLE;
1270 gmi_write_4(TEMAC_GMI_RXCF1, rcr);
1272 /* Disable transmitter. */
1273 tcr = gmi_read_4(TEMAC_GMI_TXCF) & ~GMI_TX_ENABLE;
1274 gmi_write_4(TEMAC_GMI_TXCF, tcr);
1277 static void
1278 temac_rxdrain(struct temac_softc *sc)
1280 struct temac_rxsoft *rxs;
1281 int i;
1283 for (i = 0; i < TEMAC_NRXDESC; i++) {
1284 rxs = &sc->sc_rxsoft[i];
1286 if (rxs->rxs_mbuf != NULL) {
1287 bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmap);
1288 m_freem(rxs->rxs_mbuf);
1289 rxs->rxs_mbuf = NULL;
1293 sc->sc_rx_drained = 1;
1296 static void
1297 temac_txkick(struct temac_softc *sc)
1299 if (sc->sc_txsoft[sc->sc_txsreap].txs_mbuf != NULL &&
1300 sc->sc_txbusy == 0) {
1301 cdmac_tx_start(sc, sc->sc_cdaddr + TEMAC_TXDOFF(sc->sc_txreap));
1302 sc->sc_txbusy = 1;