2 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Herb Peyerl.
16 * 4. The name of Herb Peyerl may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 * Modified from the FreeBSD 1.1.5.1 version by:
37 * INRIA - Sophia Antipolis, France
38 * avega@sophia.inria.fr
42 * Promiscuous mode added and interrupt logic slightly changed
43 * to reduce the number of adapter failures. Transceiver select
44 * logic changed to use value from EEPROM. Autoconfiguration
48 * Chelindbank (Chelyabinsk, Russia)
49 * babkin@hq.icb.chel.su
53 * Pccard support for 3C589 by:
59 * MAINTAINER: Matthew N. Dodd <winter@jurai.net>
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/malloc.h>
68 #include <sys/socket.h>
69 #include <sys/sockio.h>
72 #include <machine/bus.h>
73 #include <machine/resource.h>
77 #include <net/if_var.h>
78 #include <net/if_dl.h>
79 #include <net/if_media.h>
80 #include <net/if_types.h>
81 #include <net/ethernet.h>
84 #include <dev/ep/if_epreg.h>
85 #include <dev/ep/if_epvar.h>
87 /* Exported variables */
88 devclass_t ep_devclass;
90 static int ep_media2if_media[] =
91 {IFM_10_T, IFM_10_5, IFM_NONE, IFM_10_2, IFM_NONE};
94 static void epinit(void *);
95 static int epioctl(struct ifnet *, u_long, caddr_t);
96 static void epstart(struct ifnet *);
98 static void ep_intr_locked(struct ep_softc *);
99 static void epstart_locked(struct ifnet *);
100 static void epinit_locked(struct ep_softc *);
101 static void eptick(void *);
102 static void epwatchdog(struct ep_softc *);
104 /* if_media functions */
105 static int ep_ifmedia_upd(struct ifnet *);
106 static void ep_ifmedia_sts(struct ifnet *, struct ifmediareq *);
108 static void epstop(struct ep_softc *);
109 static void epread(struct ep_softc *);
110 static int eeprom_rdy(struct ep_softc *);
112 #define EP_FTST(sc, f) (sc->stat & (f))
113 #define EP_FSET(sc, f) (sc->stat |= (f))
114 #define EP_FRST(sc, f) (sc->stat &= ~(f))
117 eeprom_rdy(struct ep_softc *sc)
121 for (i = 0; is_eeprom_busy(sc) && i < MAX_EEPROMBUSY; i++)
124 if (i >= MAX_EEPROMBUSY) {
125 device_printf(sc->dev, "eeprom failed to come ready.\n");
133 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
137 ep_get_e(struct ep_softc *sc, uint16_t offset, uint16_t *result)
143 CSR_WRITE_2(sc, EP_W0_EEPROM_COMMAND,
144 (EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
149 (*result) = CSR_READ_2(sc, EP_W0_EEPROM_DATA);
155 ep_get_macaddr(struct ep_softc *sc, u_char *addr)
162 macaddr = (uint16_t *) addr;
165 for (i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
166 error = ep_get_e(sc, i, &result);
169 macaddr[i] = htons(result);
175 ep_alloc(device_t dev)
177 struct ep_softc *sc = device_get_softc(dev);
183 sc->iobase = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
186 device_printf(dev, "No I/O space?!\n");
191 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
193 device_printf(dev, "No irq?!\n");
198 sc->stat = 0; /* 16 bit access */
200 sc->bst = rman_get_bustag(sc->iobase);
201 sc->bsh = rman_get_bushandle(sc->iobase);
203 sc->ep_connectors = 0;
204 sc->ep_connector = 0;
208 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
211 sc->epb.prod_id = result;
213 error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
216 sc->epb.res_cfg = result;
225 ep_get_media(struct ep_softc *sc)
230 config = CSR_READ_2(sc, EP_W0_CONFIG_CTRL);
232 sc->ep_connectors |= AUI;
234 sc->ep_connectors |= BNC;
236 sc->ep_connectors |= UTP;
238 if (!(sc->ep_connectors & 7))
240 device_printf(sc->dev, "no connectors!\n");
243 * This works for most of the cards so we'll do it here.
244 * The cards that require something different can override
247 sc->ep_connector = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
251 ep_free(device_t dev)
253 struct ep_softc *sc = device_get_softc(dev);
256 bus_teardown_intr(dev, sc->irq, sc->ep_intrhand);
258 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->iobase);
260 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
267 ep_setup_station(struct ep_softc *sc, u_char *enaddr)
272 * Setup the station address
275 for (i = 0; i < ETHER_ADDR_LEN; i++)
276 CSR_WRITE_1(sc, EP_W2_ADDR_0 + i, enaddr[i]);
280 ep_attach(struct ep_softc *sc)
282 struct ifnet *ifp = NULL;
283 struct ifmedia *ifm = NULL;
288 if (! (sc->stat & F_ENADDR_SKIP)) {
289 error = ep_get_macaddr(sc, sc->eaddr);
291 device_printf(sc->dev, "Unable to get MAC address!\n");
296 ep_setup_station(sc, sc->eaddr);
297 ifp = sc->ifp = if_alloc(IFT_ETHER);
299 device_printf(sc->dev, "if_alloc() failed\n");
305 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
306 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
307 ifp->if_start = epstart;
308 ifp->if_ioctl = epioctl;
309 ifp->if_init = epinit;
310 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
311 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
312 IFQ_SET_READY(&ifp->if_snd);
314 callout_init_mtx(&sc->watchdog_timer, &sc->sc_mtx, 0);
315 if (!sc->epb.mii_trans) {
316 ifmedia_init(&sc->ifmedia, 0, ep_ifmedia_upd, ep_ifmedia_sts);
318 if (sc->ep_connectors & AUI)
319 ifmedia_add(&sc->ifmedia,
320 IFM_ETHER | IFM_10_5, 0, NULL);
321 if (sc->ep_connectors & UTP)
322 ifmedia_add(&sc->ifmedia,
323 IFM_ETHER | IFM_10_T, 0, NULL);
324 if (sc->ep_connectors & BNC)
325 ifmedia_add(&sc->ifmedia,
326 IFM_ETHER | IFM_10_2, 0, NULL);
327 if (!sc->ep_connectors)
328 ifmedia_add(&sc->ifmedia,
329 IFM_ETHER | IFM_NONE, 0, NULL);
331 ifmedia_set(&sc->ifmedia,
332 IFM_ETHER | ep_media2if_media[sc->ep_connector]);
335 ifm->ifm_media = ifm->ifm_cur->ifm_media;
338 ether_ifattach(ifp, sc->eaddr);
340 #ifdef EP_LOCAL_STATS
341 sc->rx_no_first = sc->rx_no_mbuf = sc->rx_bpf_disc =
342 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
344 EP_FSET(sc, F_RX_FIRST);
345 sc->top = sc->mcur = 0;
355 ep_detach(device_t dev)
360 sc = device_get_softc(dev);
362 EP_ASSERT_UNLOCKED(sc);
364 if (bus_child_present(dev))
367 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
370 callout_drain(&sc->watchdog_timer);
382 struct ep_softc *sc = xsc;
389 * The order in here seems important. Otherwise we may not receive
393 epinit_locked(struct ep_softc *sc)
395 struct ifnet *ifp = sc->ifp;
401 EP_ASSERT_LOCKED(sc);
405 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
407 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
410 /* Disable the card */
411 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, 0);
413 /* Enable the card */
414 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
417 /* Reload the ether_addr. */
418 ep_setup_station(sc, IF_LLADDR(sc->ifp));
420 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
421 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
424 /* Window 1 is operating window */
426 for (i = 0; i < 31; i++)
427 CSR_READ_1(sc, EP_W1_TX_STATUS);
429 /* get rid of stray intr's */
430 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | 0xff);
432 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
433 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
435 if (ifp->if_flags & IFF_PROMISC)
436 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
437 FIL_MULTICAST | FIL_BRDCST | FIL_PROMISC);
439 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
440 FIL_MULTICAST | FIL_BRDCST);
442 if (!sc->epb.mii_trans)
445 if (sc->stat & F_HAS_TX_PLL)
446 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
447 CSR_WRITE_2(sc, EP_COMMAND, RX_ENABLE);
448 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
450 ifp->if_drv_flags |= IFF_DRV_RUNNING;
451 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; /* just in case */
453 #ifdef EP_LOCAL_STATS
454 sc->rx_no_first = sc->rx_no_mbuf =
455 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
457 EP_FSET(sc, F_RX_FIRST);
460 sc->top = sc->mcur = 0;
462 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
463 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_START_THRESH | 16);
467 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
471 epstart(struct ifnet *ifp)
481 epstart_locked(struct ifnet *ifp)
491 EP_ASSERT_LOCKED(sc);
493 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
497 /* Sneak a peek at the next packet */
498 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
501 if (!started && (sc->stat & F_HAS_TX_PLL))
502 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
504 for (len = 0, m = m0; m != NULL; m = m->m_next)
510 * The 3c509 automatically pads short packets to minimum
511 * ethernet length, but we drop packets that are too large.
512 * Perhaps we should truncate them instead?
514 if (len + pad > ETHER_MAX_LEN) {
515 /* packet is obviously too large: toss it */
516 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
520 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
521 /* no room in FIFO */
522 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
524 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
525 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
526 IFQ_DRV_PREPEND(&ifp->if_snd, m0);
530 CSR_WRITE_2(sc, EP_COMMAND,
531 SET_TX_AVAIL_THRESH | EP_THRESH_DISABLE);
533 /* XXX 4.x and earlier would splhigh here */
535 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, len);
536 /* Second dword meaningless */
537 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, 0x0);
539 if (EP_FTST(sc, F_ACCESS_32_BITS)) {
540 for (m = m0; m != NULL; m = m->m_next) {
542 CSR_WRITE_MULTI_4(sc, EP_W1_TX_PIO_WR_1,
543 mtod(m, uint32_t *), m->m_len / 4);
545 CSR_WRITE_MULTI_1(sc, EP_W1_TX_PIO_WR_1,
546 mtod(m, uint8_t *)+(m->m_len & (~3)),
550 for (m = m0; m != NULL; m = m->m_next) {
552 CSR_WRITE_MULTI_2(sc, EP_W1_TX_PIO_WR_1,
553 mtod(m, uint16_t *), m->m_len / 2);
555 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1,
556 *(mtod(m, uint8_t *)+m->m_len - 1));
561 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1, 0); /* Padding */
563 /* XXX and drop splhigh here */
568 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
572 * Is another packet coming in? We don't want to overflow
576 if (CSR_READ_2(sc, EP_W1_RX_STATUS) & RX_BYTES_MASK) {
578 * we check if we have packets left, in that case
579 * we prepare to come back later
581 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
582 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
595 sc = (struct ep_softc *) arg;
602 ep_intr_locked(struct ep_softc *sc)
607 /* XXX 4.x splbio'd here to reduce interruptability */
610 * quick fix: Try to detect an interrupt when the card goes away.
612 if (sc->gone || CSR_READ_2(sc, EP_STATUS) == 0xffff)
616 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
620 while ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS) {
622 /* first acknowledge all interrupt sources */
623 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | (status & S_MASK));
625 if (status & (S_RX_COMPLETE | S_RX_EARLY))
627 if (status & S_TX_AVAIL) {
630 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
632 CSR_READ_2(sc, EP_W1_FREE_TX);
635 if (status & S_CARD_FAILURE) {
637 #ifdef EP_LOCAL_STATS
638 device_printf(sc->dev, "\n\tStatus: %x\n", status);
640 printf("\tFIFO Diagnostic: %x\n",
641 CSR_READ_2(sc, EP_W4_FIFO_DIAG));
642 printf("\tStat: %x\n", sc->stat);
643 printf("\tIpackets=%d, Opackets=%d\n",
644 ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
645 ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS));
646 printf("\tNOF=%d, NOMB=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
647 sc->rx_no_first, sc->rx_no_mbuf, sc->rx_overrunf,
648 sc->rx_overrunl, sc->tx_underrun);
652 device_printf(sc->dev,
653 "Status: %x (input buffer overflow)\n", status);
655 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
662 if (status & S_TX_COMPLETE) {
665 * We need ACK. We do it at the end.
667 * We need to read TX_STATUS until we get a
668 * 0 status in order to turn off the interrupt flag.
670 while ((status = CSR_READ_1(sc, EP_W1_TX_STATUS)) &
672 if (status & TXS_SUCCES_INTR_REQ)
675 (TXS_UNDERRUN | TXS_JABBER |
676 TXS_MAX_COLLISION)) {
677 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
678 if (status & TXS_UNDERRUN) {
679 #ifdef EP_LOCAL_STATS
683 if (status & TXS_MAX_COLLISION) {
685 * TXS_MAX_COLLISION we
688 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
690 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
691 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
693 * To have a tx_avail_int but giving
694 * the chance to the Reception
696 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
697 CSR_WRITE_2(sc, EP_COMMAND,
698 SET_TX_AVAIL_THRESH | 8);
700 /* pops up the next status */
701 CSR_WRITE_1(sc, EP_W1_TX_STATUS, 0x0);
703 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
705 CSR_READ_2(sc, EP_W1_FREE_TX);
707 } /* end TX_COMPLETE */
710 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
712 if ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS)
716 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
720 epread(struct ep_softc *sc)
722 struct mbuf *top, *mcur, *m;
725 short rx_fifo2, status;
728 /* XXX Must be called with sc locked */
731 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
735 if (status & ERR_RX) {
736 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
737 if (status & ERR_RX_OVERRUN) {
739 * We can think the rx latency is actually
740 * greather than we expect
742 #ifdef EP_LOCAL_STATS
743 if (EP_FTST(sc, F_RX_FIRST))
751 rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
753 if (EP_FTST(sc, F_RX_FIRST)) {
754 MGETHDR(m, M_NOWAIT, MT_DATA);
757 if (rx_fifo >= MINCLSIZE)
759 sc->top = sc->mcur = top = m;
760 #define EROUND ((sizeof(struct ether_header) + 3) & ~3)
761 #define EOFF (EROUND - sizeof(struct ether_header))
764 /* Read what should be the header. */
765 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
766 mtod(top, uint16_t *), sizeof(struct ether_header) / 2);
767 top->m_len = sizeof(struct ether_header);
768 rx_fifo -= sizeof(struct ether_header);
769 sc->cur_len = rx_fifo2;
771 /* come here if we didn't have a complete packet last time */
774 sc->cur_len += rx_fifo2;
777 /* Reads what is left in the RX FIFO */
778 while (rx_fifo > 0) {
779 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
780 if (lenthisone == 0) { /* no room in this one */
782 MGET(m, M_NOWAIT, MT_DATA);
785 if (rx_fifo >= MINCLSIZE)
789 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
791 if (EP_FTST(sc, F_ACCESS_32_BITS)) {
792 /* default for EISA configured cards */
793 CSR_READ_MULTI_4(sc, EP_W1_RX_PIO_RD_1,
794 (uint32_t *)(mtod(m, caddr_t)+m->m_len),
796 m->m_len += (lenthisone & ~3);
798 CSR_READ_MULTI_1(sc, EP_W1_RX_PIO_RD_1,
799 mtod(m, caddr_t)+m->m_len, lenthisone & 3);
800 m->m_len += (lenthisone & 3);
802 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
803 (uint16_t *)(mtod(m, caddr_t)+m->m_len),
805 m->m_len += lenthisone;
807 *(mtod(m, caddr_t)+m->m_len - 1) =
808 CSR_READ_1(sc, EP_W1_RX_PIO_RD_1);
810 rx_fifo -= lenthisone;
813 if (status & ERR_RX_INCOMPLETE) {
814 /* we haven't received the complete packet */
816 #ifdef EP_LOCAL_STATS
817 /* to know how often we come here */
820 EP_FRST(sc, F_RX_FIRST);
821 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
822 if (!(status & ERR_RX_INCOMPLETE)) {
824 * We see if by now, the packet has completly
829 CSR_WRITE_2(sc, EP_COMMAND,
830 SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
833 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
834 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
835 EP_FSET(sc, F_RX_FIRST);
836 top->m_pkthdr.rcvif = sc->ifp;
837 top->m_pkthdr.len = sc->cur_len;
840 * Drop locks before calling if_input() since it may re-enter
841 * ep_start() in the netisr case. This would result in a
842 * lock reversal. Better performance might be obtained by
843 * chaining all packets received, dropping the lock, and then
844 * calling if_input() on each one.
847 (*ifp->if_input) (ifp, top);
851 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
855 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
859 #ifdef EP_LOCAL_STATS
863 EP_FSET(sc, F_RX_FIRST);
865 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
869 ep_ifmedia_upd(struct ifnet *ifp)
871 struct ep_softc *sc = ifp->if_softc;
875 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
877 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
880 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
882 if (sc->ep_connectors & UTP) {
883 i = ACF_CONNECTOR_UTP;
885 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, ENABLE_UTP);
889 if (sc->ep_connectors & BNC) {
890 i = ACF_CONNECTOR_BNC;
891 CSR_WRITE_2(sc, EP_COMMAND, START_TRANSCEIVER);
892 DELAY(DELAY_MULTIPLE * 1000);
896 if (sc->ep_connectors & AUI)
897 i = ACF_CONNECTOR_AUI;
900 i = sc->ep_connector;
901 device_printf(sc->dev,
902 "strange connector type in EEPROM: assuming AUI\n");
906 j = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) & 0x3fff;
907 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
913 ep_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
915 struct ep_softc *sc = ifp->if_softc;
918 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
921 ms = CSR_READ_2(sc, EP_W4_MEDIA_TYPE);
923 ifmr->ifm_status = IFM_AVALID;
925 ifmr->ifm_status |= IFM_ACTIVE;
926 ifmr->ifm_active = IFM_ETHER | IFM_10_T;
928 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
932 ifmr->ifm_active = sc->ifmedia.ifm_media;
938 epioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
940 struct ep_softc *sc = ifp->if_softc;
941 struct ifreq *ifr = (struct ifreq *) data;
947 if (((ifp->if_flags & IFF_UP) == 0) &&
948 (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
951 /* reinitialize card on any parameter change */
958 * The Etherlink III has no programmable multicast
959 * filter. We always initialize the card to be
960 * promiscuous to multicast, since we're always a
961 * member of the ALL-SYSTEMS group, so there's no
962 * need to process SIOC*MULTI requests.
968 if (!sc->epb.mii_trans)
969 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
974 error = ether_ioctl(ifp, cmd, data);
986 if (sc->tx_timer != 0 && --sc->tx_timer == 0)
988 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
992 epwatchdog(struct ep_softc *sc)
999 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1000 epstart_locked(ifp);
1005 epstop(struct ep_softc *sc)
1008 EP_ASSERT_LOCKED(sc);
1010 CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE);
1011 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
1014 CSR_WRITE_2(sc, EP_COMMAND, TX_DISABLE);
1015 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
1018 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
1020 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
1023 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH);
1024 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK);
1025 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK);
1026 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER);
1028 sc->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1029 callout_stop(&sc->watchdog_timer);