2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Herb Peyerl.
18 * 4. The name of Herb Peyerl may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * Modified from the FreeBSD 1.1.5.1 version by:
39 * INRIA - Sophia Antipolis, France
40 * avega@sophia.inria.fr
44 * Promiscuous mode added and interrupt logic slightly changed
45 * to reduce the number of adapter failures. Transceiver select
46 * logic changed to use value from EEPROM. Autoconfiguration
50 * Chelindbank (Chelyabinsk, Russia)
51 * babkin@hq.icb.chel.su
55 * Pccard support for 3C589 by:
61 * MAINTAINER: Matthew N. Dodd <winter@jurai.net>
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/malloc.h>
70 #include <sys/socket.h>
71 #include <sys/sockio.h>
74 #include <machine/bus.h>
75 #include <machine/resource.h>
79 #include <net/if_var.h>
80 #include <net/if_dl.h>
81 #include <net/if_media.h>
82 #include <net/if_types.h>
83 #include <net/ethernet.h>
86 #include <dev/ep/if_epreg.h>
87 #include <dev/ep/if_epvar.h>
89 /* Exported variables */
90 devclass_t ep_devclass;
92 static int ep_media2if_media[] =
93 {IFM_10_T, IFM_10_5, IFM_NONE, IFM_10_2, IFM_NONE};
96 static void epinit(void *);
97 static int epioctl(struct ifnet *, u_long, caddr_t);
98 static void epstart(struct ifnet *);
100 static void ep_intr_locked(struct ep_softc *);
101 static void epstart_locked(struct ifnet *);
102 static void epinit_locked(struct ep_softc *);
103 static void eptick(void *);
104 static void epwatchdog(struct ep_softc *);
106 /* if_media functions */
107 static int ep_ifmedia_upd(struct ifnet *);
108 static void ep_ifmedia_sts(struct ifnet *, struct ifmediareq *);
110 static void epstop(struct ep_softc *);
111 static void epread(struct ep_softc *);
112 static int eeprom_rdy(struct ep_softc *);
114 #define EP_FTST(sc, f) (sc->stat & (f))
115 #define EP_FSET(sc, f) (sc->stat |= (f))
116 #define EP_FRST(sc, f) (sc->stat &= ~(f))
119 eeprom_rdy(struct ep_softc *sc)
123 for (i = 0; is_eeprom_busy(sc) && i < MAX_EEPROMBUSY; i++)
126 if (i >= MAX_EEPROMBUSY) {
127 device_printf(sc->dev, "eeprom failed to come ready.\n");
135 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
139 ep_get_e(struct ep_softc *sc, uint16_t offset, uint16_t *result)
145 CSR_WRITE_2(sc, EP_W0_EEPROM_COMMAND,
146 (EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
151 (*result) = CSR_READ_2(sc, EP_W0_EEPROM_DATA);
157 ep_get_macaddr(struct ep_softc *sc, u_char *addr)
164 macaddr = (uint16_t *) addr;
167 for (i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
168 error = ep_get_e(sc, i, &result);
171 macaddr[i] = htons(result);
177 ep_alloc(device_t dev)
179 struct ep_softc *sc = device_get_softc(dev);
185 sc->iobase = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
188 device_printf(dev, "No I/O space?!\n");
193 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
195 device_printf(dev, "No irq?!\n");
200 sc->stat = 0; /* 16 bit access */
202 sc->bst = rman_get_bustag(sc->iobase);
203 sc->bsh = rman_get_bushandle(sc->iobase);
205 sc->ep_connectors = 0;
206 sc->ep_connector = 0;
210 error = ep_get_e(sc, EEPROM_PROD_ID, &result);
213 sc->epb.prod_id = result;
215 error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
218 sc->epb.res_cfg = result;
227 ep_get_media(struct ep_softc *sc)
232 config = CSR_READ_2(sc, EP_W0_CONFIG_CTRL);
234 sc->ep_connectors |= AUI;
236 sc->ep_connectors |= BNC;
238 sc->ep_connectors |= UTP;
240 if (!(sc->ep_connectors & 7))
242 device_printf(sc->dev, "no connectors!\n");
245 * This works for most of the cards so we'll do it here.
246 * The cards that require something different can override
249 sc->ep_connector = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
253 ep_free(device_t dev)
255 struct ep_softc *sc = device_get_softc(dev);
258 bus_teardown_intr(dev, sc->irq, sc->ep_intrhand);
260 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->iobase);
262 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
269 ep_setup_station(struct ep_softc *sc, u_char *enaddr)
274 * Setup the station address
277 for (i = 0; i < ETHER_ADDR_LEN; i++)
278 CSR_WRITE_1(sc, EP_W2_ADDR_0 + i, enaddr[i]);
282 ep_attach(struct ep_softc *sc)
284 struct ifnet *ifp = NULL;
285 struct ifmedia *ifm = NULL;
290 if (! (sc->stat & F_ENADDR_SKIP)) {
291 error = ep_get_macaddr(sc, sc->eaddr);
293 device_printf(sc->dev, "Unable to get MAC address!\n");
298 ep_setup_station(sc, sc->eaddr);
299 ifp = sc->ifp = if_alloc(IFT_ETHER);
301 device_printf(sc->dev, "if_alloc() failed\n");
307 if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev));
308 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
309 ifp->if_start = epstart;
310 ifp->if_ioctl = epioctl;
311 ifp->if_init = epinit;
312 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
313 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
314 IFQ_SET_READY(&ifp->if_snd);
316 callout_init_mtx(&sc->watchdog_timer, &sc->sc_mtx, 0);
317 if (!sc->epb.mii_trans) {
318 ifmedia_init(&sc->ifmedia, 0, ep_ifmedia_upd, ep_ifmedia_sts);
320 if (sc->ep_connectors & AUI)
321 ifmedia_add(&sc->ifmedia,
322 IFM_ETHER | IFM_10_5, 0, NULL);
323 if (sc->ep_connectors & UTP)
324 ifmedia_add(&sc->ifmedia,
325 IFM_ETHER | IFM_10_T, 0, NULL);
326 if (sc->ep_connectors & BNC)
327 ifmedia_add(&sc->ifmedia,
328 IFM_ETHER | IFM_10_2, 0, NULL);
329 if (!sc->ep_connectors)
330 ifmedia_add(&sc->ifmedia,
331 IFM_ETHER | IFM_NONE, 0, NULL);
333 ifmedia_set(&sc->ifmedia,
334 IFM_ETHER | ep_media2if_media[sc->ep_connector]);
337 ifm->ifm_media = ifm->ifm_cur->ifm_media;
340 ether_ifattach(ifp, sc->eaddr);
342 #ifdef EP_LOCAL_STATS
343 sc->rx_no_first = sc->rx_no_mbuf = sc->rx_bpf_disc =
344 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
346 EP_FSET(sc, F_RX_FIRST);
347 sc->top = sc->mcur = 0;
353 gone_by_fcp101_dev(sc->dev);
359 ep_detach(device_t dev)
364 sc = device_get_softc(dev);
366 EP_ASSERT_UNLOCKED(sc);
368 if (bus_child_present(dev))
371 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
374 callout_drain(&sc->watchdog_timer);
386 struct ep_softc *sc = xsc;
393 * The order in here seems important. Otherwise we may not receive
397 epinit_locked(struct ep_softc *sc)
399 struct ifnet *ifp = sc->ifp;
405 EP_ASSERT_LOCKED(sc);
409 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
411 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
414 /* Disable the card */
415 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, 0);
417 /* Enable the card */
418 CSR_WRITE_2(sc, EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
421 /* Reload the ether_addr. */
422 ep_setup_station(sc, IF_LLADDR(sc->ifp));
424 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
425 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
428 /* Window 1 is operating window */
430 for (i = 0; i < 31; i++)
431 CSR_READ_1(sc, EP_W1_TX_STATUS);
433 /* get rid of stray intr's */
434 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | 0xff);
436 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
437 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
439 if (ifp->if_flags & IFF_PROMISC)
440 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
441 FIL_MULTICAST | FIL_BRDCST | FIL_PROMISC);
443 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
444 FIL_MULTICAST | FIL_BRDCST);
446 if (!sc->epb.mii_trans)
449 if (sc->stat & F_HAS_TX_PLL)
450 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
451 CSR_WRITE_2(sc, EP_COMMAND, RX_ENABLE);
452 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
454 ifp->if_drv_flags |= IFF_DRV_RUNNING;
455 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; /* just in case */
457 #ifdef EP_LOCAL_STATS
458 sc->rx_no_first = sc->rx_no_mbuf =
459 sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
461 EP_FSET(sc, F_RX_FIRST);
464 sc->top = sc->mcur = 0;
466 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
467 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_START_THRESH | 16);
471 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
475 epstart(struct ifnet *ifp)
485 epstart_locked(struct ifnet *ifp)
495 EP_ASSERT_LOCKED(sc);
497 if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
501 /* Sneak a peek at the next packet */
502 IFQ_DRV_DEQUEUE(&ifp->if_snd, m0);
505 if (!started && (sc->stat & F_HAS_TX_PLL))
506 CSR_WRITE_2(sc, EP_COMMAND, TX_PLL_ENABLE);
508 for (len = 0, m = m0; m != NULL; m = m->m_next)
514 * The 3c509 automatically pads short packets to minimum
515 * ethernet length, but we drop packets that are too large.
516 * Perhaps we should truncate them instead?
518 if (len + pad > ETHER_MAX_LEN) {
519 /* packet is obviously too large: toss it */
520 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
524 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
525 /* no room in FIFO */
526 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
528 if (CSR_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
529 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
530 IFQ_DRV_PREPEND(&ifp->if_snd, m0);
534 CSR_WRITE_2(sc, EP_COMMAND,
535 SET_TX_AVAIL_THRESH | EP_THRESH_DISABLE);
537 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, len);
538 /* Second dword meaningless */
539 CSR_WRITE_2(sc, EP_W1_TX_PIO_WR_1, 0x0);
541 for (m = m0; m != NULL; m = m->m_next) {
543 CSR_WRITE_MULTI_2(sc, EP_W1_TX_PIO_WR_1,
544 mtod(m, uint16_t *), m->m_len / 2);
546 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1,
547 *(mtod(m, uint8_t *)+m->m_len - 1));
551 CSR_WRITE_1(sc, EP_W1_TX_PIO_WR_1, 0); /* Padding */
553 /* XXX and drop splhigh here */
558 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
562 * Is another packet coming in? We don't want to overflow
566 if (CSR_READ_2(sc, EP_W1_RX_STATUS) & RX_BYTES_MASK) {
568 * we check if we have packets left, in that case
569 * we prepare to come back later
571 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
572 CSR_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
585 sc = (struct ep_softc *) arg;
592 ep_intr_locked(struct ep_softc *sc)
597 /* XXX 4.x splbio'd here to reduce interruptability */
600 * quick fix: Try to detect an interrupt when the card goes away.
602 if (sc->gone || CSR_READ_2(sc, EP_STATUS) == 0xffff)
606 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
610 while ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS) {
612 /* first acknowledge all interrupt sources */
613 CSR_WRITE_2(sc, EP_COMMAND, ACK_INTR | (status & S_MASK));
615 if (status & (S_RX_COMPLETE | S_RX_EARLY))
617 if (status & S_TX_AVAIL) {
620 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
622 CSR_READ_2(sc, EP_W1_FREE_TX);
625 if (status & S_CARD_FAILURE) {
627 #ifdef EP_LOCAL_STATS
628 device_printf(sc->dev, "\n\tStatus: %x\n", status);
630 printf("\tFIFO Diagnostic: %x\n",
631 CSR_READ_2(sc, EP_W4_FIFO_DIAG));
632 printf("\tStat: %x\n", sc->stat);
633 printf("\tIpackets=%d, Opackets=%d\n",
634 ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
635 ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS));
636 printf("\tNOF=%d, NOMB=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
637 sc->rx_no_first, sc->rx_no_mbuf, sc->rx_overrunf,
638 sc->rx_overrunl, sc->tx_underrun);
642 device_printf(sc->dev,
643 "Status: %x (input buffer overflow)\n", status);
645 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
652 if (status & S_TX_COMPLETE) {
655 * We need ACK. We do it at the end.
657 * We need to read TX_STATUS until we get a
658 * 0 status in order to turn off the interrupt flag.
660 while ((status = CSR_READ_1(sc, EP_W1_TX_STATUS)) &
662 if (status & TXS_SUCCES_INTR_REQ)
665 (TXS_UNDERRUN | TXS_JABBER |
666 TXS_MAX_COLLISION)) {
667 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
668 if (status & TXS_UNDERRUN) {
669 #ifdef EP_LOCAL_STATS
673 if (status & TXS_MAX_COLLISION) {
675 * TXS_MAX_COLLISION we
678 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1);
680 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
681 CSR_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
683 * To have a tx_avail_int but giving
684 * the chance to the Reception
686 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
687 CSR_WRITE_2(sc, EP_COMMAND,
688 SET_TX_AVAIL_THRESH | 8);
690 /* pops up the next status */
691 CSR_WRITE_1(sc, EP_W1_TX_STATUS, 0x0);
693 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
695 CSR_READ_2(sc, EP_W1_FREE_TX);
697 } /* end TX_COMPLETE */
700 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
702 if ((status = CSR_READ_2(sc, EP_STATUS)) & S_5_INTS)
706 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
710 epread(struct ep_softc *sc)
712 struct mbuf *top, *mcur, *m;
715 short rx_fifo2, status;
718 /* XXX Must be called with sc locked */
721 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
725 if (status & ERR_RX) {
726 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
727 if (status & ERR_RX_OVERRUN) {
729 * We can think the rx latency is actually
730 * greather than we expect
732 #ifdef EP_LOCAL_STATS
733 if (EP_FTST(sc, F_RX_FIRST))
741 rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
743 if (EP_FTST(sc, F_RX_FIRST)) {
744 MGETHDR(m, M_NOWAIT, MT_DATA);
747 if (rx_fifo >= MINCLSIZE)
749 sc->top = sc->mcur = top = m;
750 #define EROUND ((sizeof(struct ether_header) + 3) & ~3)
751 #define EOFF (EROUND - sizeof(struct ether_header))
754 /* Read what should be the header. */
755 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
756 mtod(top, uint16_t *), sizeof(struct ether_header) / 2);
757 top->m_len = sizeof(struct ether_header);
758 rx_fifo -= sizeof(struct ether_header);
759 sc->cur_len = rx_fifo2;
761 /* come here if we didn't have a complete packet last time */
764 sc->cur_len += rx_fifo2;
767 /* Reads what is left in the RX FIFO */
768 while (rx_fifo > 0) {
769 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
770 if (lenthisone == 0) { /* no room in this one */
772 MGET(m, M_NOWAIT, MT_DATA);
775 if (rx_fifo >= MINCLSIZE)
779 lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
781 CSR_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
782 (uint16_t *)(mtod(m, caddr_t)+m->m_len),
784 m->m_len += lenthisone;
786 *(mtod(m, caddr_t)+m->m_len - 1) =
787 CSR_READ_1(sc, EP_W1_RX_PIO_RD_1);
788 rx_fifo -= lenthisone;
791 if (status & ERR_RX_INCOMPLETE) {
792 /* we haven't received the complete packet */
794 #ifdef EP_LOCAL_STATS
795 /* to know how often we come here */
798 EP_FRST(sc, F_RX_FIRST);
799 status = CSR_READ_2(sc, EP_W1_RX_STATUS);
800 if (!(status & ERR_RX_INCOMPLETE)) {
802 * We see if by now, the packet has completly
807 CSR_WRITE_2(sc, EP_COMMAND,
808 SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
811 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
812 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
813 EP_FSET(sc, F_RX_FIRST);
814 top->m_pkthdr.rcvif = sc->ifp;
815 top->m_pkthdr.len = sc->cur_len;
818 * Drop locks before calling if_input() since it may re-enter
819 * ep_start() in the netisr case. This would result in a
820 * lock reversal. Better performance might be obtained by
821 * chaining all packets received, dropping the lock, and then
822 * calling if_input() on each one.
825 (*ifp->if_input) (ifp, top);
829 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
833 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
837 #ifdef EP_LOCAL_STATS
841 EP_FSET(sc, F_RX_FIRST);
843 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
847 ep_ifmedia_upd(struct ifnet *ifp)
849 struct ep_softc *sc = ifp->if_softc;
853 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
855 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
858 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
860 if (sc->ep_connectors & UTP) {
861 i = ACF_CONNECTOR_UTP;
863 CSR_WRITE_2(sc, EP_W4_MEDIA_TYPE, ENABLE_UTP);
867 if (sc->ep_connectors & BNC) {
868 i = ACF_CONNECTOR_BNC;
869 CSR_WRITE_2(sc, EP_COMMAND, START_TRANSCEIVER);
870 DELAY(DELAY_MULTIPLE * 1000);
874 if (sc->ep_connectors & AUI)
875 i = ACF_CONNECTOR_AUI;
878 i = sc->ep_connector;
879 device_printf(sc->dev,
880 "strange connector type in EEPROM: assuming AUI\n");
884 j = CSR_READ_2(sc, EP_W0_ADDRESS_CFG) & 0x3fff;
885 CSR_WRITE_2(sc, EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
891 ep_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
893 struct ep_softc *sc = ifp->if_softc;
896 switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
899 ms = CSR_READ_2(sc, EP_W4_MEDIA_TYPE);
901 ifmr->ifm_status = IFM_AVALID;
903 ifmr->ifm_status |= IFM_ACTIVE;
904 ifmr->ifm_active = IFM_ETHER | IFM_10_T;
906 ifmr->ifm_active = IFM_ETHER | IFM_NONE;
910 ifmr->ifm_active = sc->ifmedia.ifm_media;
916 epioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
918 struct ep_softc *sc = ifp->if_softc;
919 struct ifreq *ifr = (struct ifreq *) data;
925 if (((ifp->if_flags & IFF_UP) == 0) &&
926 (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
929 /* reinitialize card on any parameter change */
936 * The Etherlink III has no programmable multicast
937 * filter. We always initialize the card to be
938 * promiscuous to multicast, since we're always a
939 * member of the ALL-SYSTEMS group, so there's no
940 * need to process SIOC*MULTI requests.
946 if (!sc->epb.mii_trans)
947 error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
952 error = ether_ioctl(ifp, cmd, data);
964 if (sc->tx_timer != 0 && --sc->tx_timer == 0)
966 callout_reset(&sc->watchdog_timer, hz, eptick, sc);
970 epwatchdog(struct ep_softc *sc)
977 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
983 epstop(struct ep_softc *sc)
986 EP_ASSERT_LOCKED(sc);
988 CSR_WRITE_2(sc, EP_COMMAND, RX_DISABLE);
989 CSR_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
992 CSR_WRITE_2(sc, EP_COMMAND, TX_DISABLE);
993 CSR_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
996 CSR_WRITE_2(sc, EP_COMMAND, RX_RESET);
998 CSR_WRITE_2(sc, EP_COMMAND, TX_RESET);
1001 CSR_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH);
1002 CSR_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK);
1003 CSR_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK);
1004 CSR_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER);
1006 sc->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
1007 callout_stop(&sc->watchdog_timer);