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>
67 #include <sys/socket.h>
68 #include <sys/sockio.h>
71 #include <machine/bus.h>
72 #include <machine/resource.h>
76 #include <net/if_var.h>
77 #include <net/if_dl.h>
78 #include <net/if_media.h>
79 #include <net/if_types.h>
80 #include <net/ethernet.h>
83 #include <dev/ep/if_epreg.h>
84 #include <dev/ep/if_epvar.h>
86 /* Exported variables */
87 devclass_t ep_devclass;
89 static int ep_media2if_media[] =
90 {IFM_10_T, IFM_10_5, IFM_NONE, IFM_10_2, IFM_NONE};
93 static void epinit(void *);
94 static int epioctl(struct ifnet *, u_long, caddr_t);
95 static void epstart(struct ifnet *);
97 static void ep_intr_locked(struct ep_softc *);
98 static void epstart_locked(struct ifnet *);
99 static void epinit_locked(struct ep_softc *);
100 static void eptick(void *);
101 static void epwatchdog(struct ep_softc *);
103 /* if_media functions */
104 static int ep_ifmedia_upd(struct ifnet *);
105 static void ep_ifmedia_sts(struct ifnet *, struct ifmediareq *);
107 static void epstop(struct ep_softc *);
108 static void epread(struct ep_softc *);
109 static int eeprom_rdy(struct ep_softc *);
111 #define EP_FTST(sc, f) (sc->stat & (f))
112 #define EP_FSET(sc, f) (sc->stat |= (f))
113 #define EP_FRST(sc, f) (sc->stat &= ~(f))
116 eeprom_rdy(struct ep_softc *sc)
120 for (i = 0; is_eeprom_busy(sc) && i < MAX_EEPROMBUSY; i++)
123 if (i >= MAX_EEPROMBUSY) {
124 device_printf(sc->dev, "eeprom failed to come ready.\n");
132 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
136 ep_get_e(struct ep_softc *sc, uint16_t offset, uint16_t *result)
142 CSR_WRITE_2(sc, EP_W0_EEPROM_COMMAND,
143 (EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
148 (*result) = CSR_READ_2(sc, EP_W0_EEPROM_DATA);
154 ep_get_macaddr(struct ep_softc *sc, u_char *addr)
161 macaddr = (uint16_t *) addr;
164 for (i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
165 error = ep_get_e(sc, i, &result);
168 macaddr[i] = htons(result);
174 ep_alloc(device_t dev)
176 struct ep_softc *sc = device_get_softc(dev);
182 sc->iobase = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
185 device_printf(dev, "No I/O space?!\n");
190 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
192 device_printf(dev, "No irq?!\n");
197 sc->stat = 0; /* 16 bit access */
199 sc->bst = rman_get_bustag(sc->iobase);
200 sc->bsh = rman_get_bushandle(sc->iobase);
202 sc->ep_connectors = 0;
203 sc->ep_connector = 0;
207 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
210 sc->epb.prod_id = result;
212 error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
215 sc->epb.res_cfg = result;
224 ep_get_media(struct ep_softc *sc)
229 config = CSR_READ_2(sc, EP_W0_CONFIG_CTRL);
231 sc->ep_connectors |= AUI;
233 sc->ep_connectors |= BNC;
235 sc->ep_connectors |= UTP;
237 if (!(sc->ep_connectors & 7))
239 device_printf(sc->dev, "no connectors!\n");
242 * This works for most of the cards so we'll do it here.
243 * The cards that require something different can override
246 sc->ep_connector = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
250 ep_free(device_t dev)
252 struct ep_softc *sc = device_get_softc(dev);
255 bus_teardown_intr(dev, sc->irq, sc->ep_intrhand);
257 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->iobase);
259 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
266 ep_setup_station(struct ep_softc *sc, u_char *enaddr)
271 * Setup the station address
274 for (i = 0; i < ETHER_ADDR_LEN; i++)
275 CSR_WRITE_1(sc, EP_W2_ADDR_0 + i, enaddr[i]);
279 ep_attach(struct ep_softc *sc)
281 struct ifnet *ifp = NULL;
282 struct ifmedia *ifm = NULL;
287 if (! (sc->stat & F_ENADDR_SKIP)) {
288 error = ep_get_macaddr(sc, sc->eaddr);
290 device_printf(sc->dev, "Unable to get MAC address!\n");
295 ep_setup_station(sc, sc->eaddr);
296 ifp = sc->ifp = if_alloc(IFT_ETHER);
298 device_printf(sc->dev, "if_alloc() failed\n");
304 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
305 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
306 ifp->if_start = epstart;
307 ifp->if_ioctl = epioctl;
308 ifp->if_init = epinit;
309 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
310 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
311 IFQ_SET_READY(&ifp->if_snd);
313 callout_init_mtx(&sc->watchdog_timer, &sc->sc_mtx, 0);
314 if (!sc->epb.mii_trans) {
315 ifmedia_init(&sc->ifmedia, 0, ep_ifmedia_upd, ep_ifmedia_sts);
317 if (sc->ep_connectors & AUI)
318 ifmedia_add(&sc->ifmedia,
319 IFM_ETHER | IFM_10_5, 0, NULL);
320 if (sc->ep_connectors & UTP)
321 ifmedia_add(&sc->ifmedia,
322 IFM_ETHER | IFM_10_T, 0, NULL);
323 if (sc->ep_connectors & BNC)
324 ifmedia_add(&sc->ifmedia,
325 IFM_ETHER | IFM_10_2, 0, NULL);
326 if (!sc->ep_connectors)
327 ifmedia_add(&sc->ifmedia,
328 IFM_ETHER | IFM_NONE, 0, NULL);
330 ifmedia_set(&sc->ifmedia,
331 IFM_ETHER | ep_media2if_media[sc->ep_connector]);
334 ifm->ifm_media = ifm->ifm_cur->ifm_media;
337 ether_ifattach(ifp, sc->eaddr);
339 #ifdef EP_LOCAL_STATS
340 sc->rx_no_first = sc->rx_no_mbuf = sc->rx_bpf_disc =
341 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
343 EP_FSET(sc, F_RX_FIRST);
344 sc->top = sc->mcur = 0;
354 ep_detach(device_t dev)
359 sc = device_get_softc(dev);
361 EP_ASSERT_UNLOCKED(sc);
363 if (bus_child_present(dev))
366 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
369 callout_drain(&sc->watchdog_timer);
381 struct ep_softc *sc = xsc;
388 * The order in here seems important. Otherwise we may not receive
392 epinit_locked(struct ep_softc *sc)
394 struct ifnet *ifp = sc->ifp;
400 EP_ASSERT_LOCKED(sc);
404 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
406 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
409 /* Disable the card */
410 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, 0);
412 /* Enable the card */
413 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
416 /* Reload the ether_addr. */
417 ep_setup_station(sc, IF_LLADDR(sc->ifp));
419 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
420 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
423 /* Window 1 is operating window */
425 for (i = 0; i < 31; i++)
426 CSR_READ_1(sc, EP_W1_TX_STATUS);
428 /* get rid of stray intr's */
429 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | 0xff);
431 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
432 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
434 if (ifp->if_flags & IFF_PROMISC)
435 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
436 FIL_MULTICAST | FIL_BRDCST | FIL_PROMISC);
438 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
439 FIL_MULTICAST | FIL_BRDCST);
441 if (!sc->epb.mii_trans)
444 if (sc->stat & F_HAS_TX_PLL)
445 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
446 CSR_WRITE_2(sc, EP_COMMAND, RX_ENABLE);
447 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
449 ifp->if_drv_flags |= IFF_DRV_RUNNING;
450 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; /* just in case */
452 #ifdef EP_LOCAL_STATS
453 sc->rx_no_first = sc->rx_no_mbuf =
454 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
456 EP_FSET(sc, F_RX_FIRST);
459 sc->top = sc->mcur = 0;
461 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
462 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_START_THRESH | 16);
466 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
470 epstart(struct ifnet *ifp)
480 epstart_locked(struct ifnet *ifp)
490 EP_ASSERT_LOCKED(sc);
492 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
496 /* Sneak a peek at the next packet */
497 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
500 if (!started && (sc->stat & F_HAS_TX_PLL))
501 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
503 for (len = 0, m = m0; m != NULL; m = m->m_next)
509 * The 3c509 automatically pads short packets to minimum
510 * ethernet length, but we drop packets that are too large.
511 * Perhaps we should truncate them instead?
513 if (len + pad > ETHER_MAX_LEN) {
514 /* packet is obviously too large: toss it */
515 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
519 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
520 /* no room in FIFO */
521 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
523 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
524 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
525 IFQ_DRV_PREPEND(&ifp->if_snd, m0);
529 CSR_WRITE_2(sc, EP_COMMAND,
530 SET_TX_AVAIL_THRESH | EP_THRESH_DISABLE);
532 /* XXX 4.x and earlier would splhigh here */
534 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, len);
535 /* Second dword meaningless */
536 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, 0x0);
538 if (EP_FTST(sc, F_ACCESS_32_BITS)) {
539 for (m = m0; m != NULL; m = m->m_next) {
541 CSR_WRITE_MULTI_4(sc, EP_W1_TX_PIO_WR_1,
542 mtod(m, uint32_t *), m->m_len / 4);
544 CSR_WRITE_MULTI_1(sc, EP_W1_TX_PIO_WR_1,
545 mtod(m, uint8_t *)+(m->m_len & (~3)),
549 for (m = m0; m != NULL; m = m->m_next) {
551 CSR_WRITE_MULTI_2(sc, EP_W1_TX_PIO_WR_1,
552 mtod(m, uint16_t *), m->m_len / 2);
554 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1,
555 *(mtod(m, uint8_t *)+m->m_len - 1));
560 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1, 0); /* Padding */
562 /* XXX and drop splhigh here */
567 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
571 * Is another packet coming in? We don't want to overflow
575 if (CSR_READ_2(sc, EP_W1_RX_STATUS) & RX_BYTES_MASK) {
577 * we check if we have packets left, in that case
578 * we prepare to come back later
580 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
581 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
594 sc = (struct ep_softc *) arg;
601 ep_intr_locked(struct ep_softc *sc)
606 /* XXX 4.x splbio'd here to reduce interruptability */
609 * quick fix: Try to detect an interrupt when the card goes away.
611 if (sc->gone || CSR_READ_2(sc, EP_STATUS) == 0xffff)
615 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
619 while ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS) {
621 /* first acknowledge all interrupt sources */
622 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | (status & S_MASK));
624 if (status & (S_RX_COMPLETE | S_RX_EARLY))
626 if (status & S_TX_AVAIL) {
629 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
631 CSR_READ_2(sc, EP_W1_FREE_TX);
634 if (status & S_CARD_FAILURE) {
636 #ifdef EP_LOCAL_STATS
637 device_printf(sc->dev, "\n\tStatus: %x\n", status);
639 printf("\tFIFO Diagnostic: %x\n",
640 CSR_READ_2(sc, EP_W4_FIFO_DIAG));
641 printf("\tStat: %x\n", sc->stat);
642 printf("\tIpackets=%d, Opackets=%d\n",
643 ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
644 ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS));
645 printf("\tNOF=%d, NOMB=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
646 sc->rx_no_first, sc->rx_no_mbuf, sc->rx_overrunf,
647 sc->rx_overrunl, sc->tx_underrun);
651 device_printf(sc->dev,
652 "Status: %x (input buffer overflow)\n", status);
654 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
661 if (status & S_TX_COMPLETE) {
664 * We need ACK. We do it at the end.
666 * We need to read TX_STATUS until we get a
667 * 0 status in order to turn off the interrupt flag.
669 while ((status = CSR_READ_1(sc, EP_W1_TX_STATUS)) &
671 if (status & TXS_SUCCES_INTR_REQ)
674 (TXS_UNDERRUN | TXS_JABBER |
675 TXS_MAX_COLLISION)) {
676 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
677 if (status & TXS_UNDERRUN) {
678 #ifdef EP_LOCAL_STATS
682 if (status & TXS_MAX_COLLISION) {
684 * TXS_MAX_COLLISION we
687 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
689 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
690 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
692 * To have a tx_avail_int but giving
693 * the chance to the Reception
695 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
696 CSR_WRITE_2(sc, EP_COMMAND,
697 SET_TX_AVAIL_THRESH | 8);
699 /* pops up the next status */
700 CSR_WRITE_1(sc, EP_W1_TX_STATUS, 0x0);
702 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
704 CSR_READ_2(sc, EP_W1_FREE_TX);
706 } /* end TX_COMPLETE */
709 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
711 if ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS)
715 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
719 epread(struct ep_softc *sc)
721 struct mbuf *top, *mcur, *m;
724 short rx_fifo2, status;
727 /* XXX Must be called with sc locked */
730 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
734 if (status & ERR_RX) {
735 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
736 if (status & ERR_RX_OVERRUN) {
738 * We can think the rx latency is actually
739 * greather than we expect
741 #ifdef EP_LOCAL_STATS
742 if (EP_FTST(sc, F_RX_FIRST))
750 rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
752 if (EP_FTST(sc, F_RX_FIRST)) {
753 MGETHDR(m, M_NOWAIT, MT_DATA);
756 if (rx_fifo >= MINCLSIZE)
758 sc->top = sc->mcur = top = m;
759 #define EROUND ((sizeof(struct ether_header) + 3) & ~3)
760 #define EOFF (EROUND - sizeof(struct ether_header))
763 /* Read what should be the header. */
764 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
765 mtod(top, uint16_t *), sizeof(struct ether_header) / 2);
766 top->m_len = sizeof(struct ether_header);
767 rx_fifo -= sizeof(struct ether_header);
768 sc->cur_len = rx_fifo2;
770 /* come here if we didn't have a complete packet last time */
773 sc->cur_len += rx_fifo2;
776 /* Reads what is left in the RX FIFO */
777 while (rx_fifo > 0) {
778 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
779 if (lenthisone == 0) { /* no room in this one */
781 MGET(m, M_NOWAIT, MT_DATA);
784 if (rx_fifo >= MINCLSIZE)
788 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
790 if (EP_FTST(sc, F_ACCESS_32_BITS)) {
791 /* default for EISA configured cards */
792 CSR_READ_MULTI_4(sc, EP_W1_RX_PIO_RD_1,
793 (uint32_t *)(mtod(m, caddr_t)+m->m_len),
795 m->m_len += (lenthisone & ~3);
797 CSR_READ_MULTI_1(sc, EP_W1_RX_PIO_RD_1,
798 mtod(m, caddr_t)+m->m_len, lenthisone & 3);
799 m->m_len += (lenthisone & 3);
801 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
802 (uint16_t *)(mtod(m, caddr_t)+m->m_len),
804 m->m_len += lenthisone;
806 *(mtod(m, caddr_t)+m->m_len - 1) =
807 CSR_READ_1(sc, EP_W1_RX_PIO_RD_1);
809 rx_fifo -= lenthisone;
812 if (status & ERR_RX_INCOMPLETE) {
813 /* we haven't received the complete packet */
815 #ifdef EP_LOCAL_STATS
816 /* to know how often we come here */
819 EP_FRST(sc, F_RX_FIRST);
820 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
821 if (!(status & ERR_RX_INCOMPLETE)) {
823 * We see if by now, the packet has completly
828 CSR_WRITE_2(sc, EP_COMMAND,
829 SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
832 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
833 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
834 EP_FSET(sc, F_RX_FIRST);
835 top->m_pkthdr.rcvif = sc->ifp;
836 top->m_pkthdr.len = sc->cur_len;
839 * Drop locks before calling if_input() since it may re-enter
840 * ep_start() in the netisr case. This would result in a
841 * lock reversal. Better performance might be obtained by
842 * chaining all packets received, dropping the lock, and then
843 * calling if_input() on each one.
846 (*ifp->if_input) (ifp, top);
850 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
854 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
858 #ifdef EP_LOCAL_STATS
862 EP_FSET(sc, F_RX_FIRST);
864 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
868 ep_ifmedia_upd(struct ifnet *ifp)
870 struct ep_softc *sc = ifp->if_softc;
874 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
876 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
879 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
881 if (sc->ep_connectors & UTP) {
882 i = ACF_CONNECTOR_UTP;
884 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, ENABLE_UTP);
888 if (sc->ep_connectors & BNC) {
889 i = ACF_CONNECTOR_BNC;
890 CSR_WRITE_2(sc, EP_COMMAND, START_TRANSCEIVER);
891 DELAY(DELAY_MULTIPLE * 1000);
895 if (sc->ep_connectors & AUI)
896 i = ACF_CONNECTOR_AUI;
899 i = sc->ep_connector;
900 device_printf(sc->dev,
901 "strange connector type in EEPROM: assuming AUI\n");
905 j = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) & 0x3fff;
906 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
912 ep_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
914 struct ep_softc *sc = ifp->if_softc;
917 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
920 ms = CSR_READ_2(sc, EP_W4_MEDIA_TYPE);
922 ifmr->ifm_status = IFM_AVALID;
924 ifmr->ifm_status |= IFM_ACTIVE;
925 ifmr->ifm_active = IFM_ETHER | IFM_10_T;
927 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
931 ifmr->ifm_active = sc->ifmedia.ifm_media;
937 epioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
939 struct ep_softc *sc = ifp->if_softc;
940 struct ifreq *ifr = (struct ifreq *) data;
946 if (((ifp->if_flags & IFF_UP) == 0) &&
947 (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
950 /* reinitialize card on any parameter change */
957 * The Etherlink III has no programmable multicast
958 * filter. We always initialize the card to be
959 * promiscuous to multicast, since we're always a
960 * member of the ALL-SYSTEMS group, so there's no
961 * need to process SIOC*MULTI requests.
967 if (!sc->epb.mii_trans)
968 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
973 error = ether_ioctl(ifp, cmd, data);
985 if (sc->tx_timer != 0 && --sc->tx_timer == 0)
987 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
991 epwatchdog(struct ep_softc *sc)
998 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
1004 epstop(struct ep_softc *sc)
1007 EP_ASSERT_LOCKED(sc);
1009 CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE);
1010 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
1013 CSR_WRITE_2(sc, EP_COMMAND, TX_DISABLE);
1014 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
1017 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
1019 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
1022 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH);
1023 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK);
1024 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK);
1025 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER);
1027 sc->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1028 callout_stop(&sc->watchdog_timer);