if_ex.c revision 148887
1139749Simp/*- 221769Sjkh * Copyright (c) 1996, Javier Mart�n Rueda (jmrueda@diatel.upm.es) 321769Sjkh * All rights reserved. 421769Sjkh * 521769Sjkh * Redistribution and use in source and binary forms, with or without 621769Sjkh * modification, are permitted provided that the following conditions 721769Sjkh * are met: 821769Sjkh * 1. Redistributions of source code must retain the above copyright 921769Sjkh * notice unmodified, this list of conditions, and the following 1021769Sjkh * disclaimer. 1121769Sjkh * 2. Redistributions in binary form must reproduce the above copyright 1221769Sjkh * notice, this list of conditions and the following disclaimer in the 1321769Sjkh * documentation and/or other materials provided with the distribution. 1421769Sjkh * 1521769Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1621769Sjkh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1721769Sjkh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1821769Sjkh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1921769Sjkh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2021769Sjkh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2121769Sjkh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2221769Sjkh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2321769Sjkh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2421769Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2521769Sjkh * SUCH DAMAGE. 2629877Smsmith * 2752286Smdodd * 2852286Smdodd * MAINTAINER: Matthew N. Dodd <winter@jurai.net> 2952286Smdodd * <mdodd@FreeBSD.org> 3021769Sjkh */ 3121769Sjkh 32119418Sobrien#include <sys/cdefs.h> 33119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/ex/if_ex.c 148887 2005-08-09 10:20:02Z rwatson $"); 34119418Sobrien 3521769Sjkh/* 3629877Smsmith * Intel EtherExpress Pro/10, Pro/10+ Ethernet driver 3721769Sjkh * 3821769Sjkh * Revision history: 3921769Sjkh * 40112731Smdodd * dd-mmm-yyyy: Multicast support ported from NetBSD's if_iy driver. 4121769Sjkh * 30-Oct-1996: first beta version. Inet and BPF supported, but no multicast. 4221769Sjkh */ 4321769Sjkh 4421769Sjkh#include <sys/param.h> 4521769Sjkh#include <sys/systm.h> 4652286Smdodd#include <sys/kernel.h> 4724204Sbde#include <sys/sockio.h> 4821769Sjkh#include <sys/mbuf.h> 4921769Sjkh#include <sys/socket.h> 5021769Sjkh 5152286Smdodd#include <sys/module.h> 5252286Smdodd#include <sys/bus.h> 5352286Smdodd 5452286Smdodd#include <machine/bus.h> 5552286Smdodd#include <machine/resource.h> 5652286Smdodd#include <sys/rman.h> 5752286Smdodd 5857987Smdodd#include <net/if.h> 5957987Smdodd#include <net/if_arp.h> 60112731Smdodd#include <net/if_dl.h> 6157987Smdodd#include <net/if_media.h> 62147256Sbrooks#include <net/if_types.h> 6350026Smdodd#include <net/ethernet.h> 6457987Smdodd#include <net/bpf.h> 6521769Sjkh 6650026Smdodd#include <netinet/in.h> 6750026Smdodd#include <netinet/if_ether.h> 6850026Smdodd 6921769Sjkh 7052286Smdodd#include <isa/isavar.h> 7152286Smdodd#include <isa/pnpvar.h> 7252286Smdodd 7355953Speter#include <dev/ex/if_exreg.h> 7459816Smdodd#include <dev/ex/if_exvar.h> 7521769Sjkh 7621769Sjkh#ifdef EXDEBUG 7752286Smdodd# define Start_End 1 7852286Smdodd# define Rcvd_Pkts 2 7952286Smdodd# define Sent_Pkts 4 8052286Smdodd# define Status 8 8121769Sjkhstatic int debug_mask = 0; 8252286Smdodd# define DODEBUG(level, action) if (level & debug_mask) action 8321769Sjkh#else 8452286Smdodd# define DODEBUG(level, action) 8521769Sjkh#endif 8621769Sjkh 87112801Smdodddevclass_t ex_devclass; 88112801Smdodd 8959816Smdoddchar irq2eemap[] = 9052286Smdodd { -1, -1, 0, 1, -1, 2, -1, -1, -1, 0, 3, 4, -1, -1, -1, -1 }; 9159816Smdoddu_char ee2irqmap[] = 9252286Smdodd { 9, 3, 5, 10, 11, 0, 0, 0 }; 9359816Smdodd 9459816Smdoddchar plus_irq2eemap[] = 9552286Smdodd { -1, -1, -1, 0, 1, 2, -1, 3, -1, 4, 5, 6, 7, -1, -1, -1 }; 9659816Smdoddu_char plus_ee2irqmap[] = 9752286Smdodd { 3, 4, 5, 7, 9, 10, 11, 12 }; 9821769Sjkh 9952286Smdodd/* Network Interface Functions */ 100131192Simpstatic void ex_init(void *); 101131192Simpstatic void ex_start(struct ifnet *); 102131192Simpstatic int ex_ioctl(struct ifnet *, u_long, caddr_t); 103131192Simpstatic void ex_watchdog(struct ifnet *); 10421769Sjkh 10557987Smdodd/* ifmedia Functions */ 106131192Simpstatic int ex_ifmedia_upd(struct ifnet *); 107131192Simpstatic void ex_ifmedia_sts(struct ifnet *, struct ifmediareq *); 10857987Smdodd 109131192Simpstatic int ex_get_media(struct ex_softc *); 11059816Smdodd 111131192Simpstatic void ex_reset(struct ex_softc *); 112131192Simpstatic void ex_setmulti(struct ex_softc *); 11352286Smdodd 114131192Simpstatic void ex_tx_intr(struct ex_softc *); 115131192Simpstatic void ex_rx_intr(struct ex_softc *); 11652286Smdodd 11759816Smdoddvoid 118131192Simpex_get_address(struct ex_softc *sc, u_char *enaddr) 11921769Sjkh{ 120131192Simp uint16_t eaddr_tmp; 12121769Sjkh 122131192Simp eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Lo); 12352286Smdodd enaddr[5] = eaddr_tmp & 0xff; 12452286Smdodd enaddr[4] = eaddr_tmp >> 8; 125131192Simp eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Mid); 12652286Smdodd enaddr[3] = eaddr_tmp & 0xff; 12752286Smdodd enaddr[2] = eaddr_tmp >> 8; 128131192Simp eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Hi); 12952286Smdodd enaddr[1] = eaddr_tmp & 0xff; 13052286Smdodd enaddr[0] = eaddr_tmp >> 8; 13152286Smdodd 13252286Smdodd return; 13352286Smdodd} 13421769Sjkh 13559816Smdoddint 136131192Simpex_card_type(u_char *enaddr) 13752286Smdodd{ 13852286Smdodd if ((enaddr[0] == 0x00) && (enaddr[1] == 0xA0) && (enaddr[2] == 0xC9)) 13952286Smdodd return (CARD_TYPE_EX_10_PLUS); 14052286Smdodd 14152286Smdodd return (CARD_TYPE_EX_10); 14252286Smdodd} 14352286Smdodd 14455882Smdodd/* 14559816Smdodd * Caller is responsible for eventually calling 14659816Smdodd * ex_release_resources() on failure. 14755882Smdodd */ 14859816Smdoddint 149131192Simpex_alloc_resources(device_t dev) 15055882Smdodd{ 15159816Smdodd struct ex_softc * sc = device_get_softc(dev); 15259816Smdodd int error = 0; 15355882Smdodd 154127135Snjl sc->ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT, 155127135Snjl &sc->ioport_rid, RF_ACTIVE); 15659816Smdodd if (!sc->ioport) { 15759816Smdodd device_printf(dev, "No I/O space?!\n"); 15859816Smdodd error = ENOMEM; 15959816Smdodd goto bad; 16059816Smdodd } 161131192Simp sc->bst = rman_get_bustag(sc->ioport); 162131192Simp sc->bsh = rman_get_bushandle(sc->ioport); 16357989Smdodd 164127135Snjl sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, 165127135Snjl RF_ACTIVE); 16655882Smdodd 16759816Smdodd if (!sc->irq) { 16859816Smdodd device_printf(dev, "No IRQ?!\n"); 16959816Smdodd error = ENOMEM; 17059816Smdodd goto bad; 17155882Smdodd } 17255882Smdodd 17359816Smdoddbad: 17459816Smdodd return (error); 17555882Smdodd} 17655882Smdodd 17759816Smdoddvoid 178131192Simpex_release_resources(device_t dev) 17952286Smdodd{ 18059816Smdodd struct ex_softc * sc = device_get_softc(dev); 18152286Smdodd 18259816Smdodd if (sc->ih) { 18359816Smdodd bus_teardown_intr(dev, sc->irq, sc->ih); 18459816Smdodd sc->ih = NULL; 18552286Smdodd } 18652286Smdodd 18759816Smdodd if (sc->ioport) { 18859816Smdodd bus_release_resource(dev, SYS_RES_IOPORT, 18959816Smdodd sc->ioport_rid, sc->ioport); 19059816Smdodd sc->ioport = NULL; 19152286Smdodd } 19252286Smdodd 19359816Smdodd if (sc->irq) { 19459816Smdodd bus_release_resource(dev, SYS_RES_IRQ, 19559816Smdodd sc->irq_rid, sc->irq); 19659816Smdodd sc->irq = NULL; 19757989Smdodd } 19857989Smdodd 19959816Smdodd return; 20052286Smdodd} 20152286Smdodd 20259816Smdoddint 20359816Smdoddex_attach(device_t dev) 20452286Smdodd{ 20552286Smdodd struct ex_softc * sc = device_get_softc(dev); 206147256Sbrooks struct ifnet * ifp; 20757987Smdodd struct ifmedia * ifm; 208131192Simp uint16_t temp; 20952286Smdodd 210147256Sbrooks ifp = sc->ifp = if_alloc(IFT_ETHER); 211147256Sbrooks if (ifp == NULL) { 212147256Sbrooks device_printf(dev, "can not if_alloc()\n"); 213147256Sbrooks return (ENOSPC); 214147256Sbrooks } 21529877Smsmith /* work out which set of irq <-> internal tables to use */ 216147256Sbrooks if (ex_card_type(sc->enaddr) == CARD_TYPE_EX_10_PLUS) { 21729877Smsmith sc->irq2ee = plus_irq2eemap; 21829877Smsmith sc->ee2irq = plus_ee2irqmap; 21952286Smdodd } else { 22029877Smsmith sc->irq2ee = irq2eemap; 22129877Smsmith sc->ee2irq = ee2irqmap; 22229877Smsmith } 22329877Smsmith 22421769Sjkh sc->mem_size = CARD_RAM_SIZE; /* XXX This should be read from the card itself. */ 22521769Sjkh 22621769Sjkh /* 22721769Sjkh * Initialize the ifnet structure. 22821769Sjkh */ 22921769Sjkh ifp->if_softc = sc; 230121816Sbrooks if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 23155883Smdodd ifp->if_mtu = ETHERMTU; 232133684Srwatson ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST | 233133684Srwatson IFF_NEEDSGIANT; 23421769Sjkh ifp->if_start = ex_start; 23521769Sjkh ifp->if_ioctl = ex_ioctl; 23621769Sjkh ifp->if_watchdog = ex_watchdog; 23755883Smdodd ifp->if_init = ex_init; 23855883Smdodd ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 23921769Sjkh 24057987Smdodd ifmedia_init(&sc->ifmedia, 0, ex_ifmedia_upd, ex_ifmedia_sts); 24157987Smdodd 242131192Simp temp = ex_eeprom_read(sc, EE_W5); 24357987Smdodd if (temp & EE_W5_PORT_TPE) 24457987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL); 24557987Smdodd if (temp & EE_W5_PORT_BNC) 24657987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL); 24757987Smdodd if (temp & EE_W5_PORT_AUI) 24857987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL); 24957987Smdodd 250112764Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 251112764Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_NONE, 0, NULL); 252131192Simp ifmedia_set(&sc->ifmedia, ex_get_media(sc)); 25357987Smdodd 25457987Smdodd ifm = &sc->ifmedia; 25557987Smdodd ifm->ifm_media = ifm->ifm_cur->ifm_media; 25657987Smdodd ex_ifmedia_upd(ifp); 25757987Smdodd 25821769Sjkh /* 25921769Sjkh * Attach the interface. 26021769Sjkh */ 261147256Sbrooks ether_ifattach(ifp, sc->enaddr); 26221769Sjkh 26352286Smdodd return(0); 26421769Sjkh} 26521769Sjkh 266112800Smdoddint 267131192Simpex_detach(device_t dev) 268112800Smdodd{ 269112800Smdodd struct ex_softc *sc; 270112800Smdodd struct ifnet *ifp; 271112800Smdodd 272112800Smdodd sc = device_get_softc(dev); 273147256Sbrooks ifp = sc->ifp; 274112800Smdodd 275112800Smdodd ex_stop(sc); 276112800Smdodd 277148887Srwatson ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 278112800Smdodd ether_ifdetach(ifp); 279147256Sbrooks if_free(ifp); 280112800Smdodd 281112800Smdodd ex_release_resources(dev); 282112800Smdodd 283112800Smdodd return (0); 284112800Smdodd} 285112800Smdodd 28655883Smdoddstatic void 28755883Smdoddex_init(void *xsc) 28821769Sjkh{ 28952286Smdodd struct ex_softc * sc = (struct ex_softc *) xsc; 290147256Sbrooks struct ifnet * ifp = sc->ifp; 29152286Smdodd int s; 29252286Smdodd int i; 29352286Smdodd unsigned short temp_reg; 29421769Sjkh 295121816Sbrooks DODEBUG(Start_End, printf("%s: ex_init: start\n", ifp->if_xname);); 29621769Sjkh 29721769Sjkh s = splimp(); 29859816Smdodd ifp->if_timer = 0; 29921769Sjkh 30021769Sjkh /* 30121769Sjkh * Load the ethernet address into the card. 30221769Sjkh */ 303131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 304131192Simp temp_reg = CSR_READ_1(sc, EEPROM_REG); 30552286Smdodd if (temp_reg & Trnoff_Enable) { 306131192Simp CSR_WRITE_1(sc, EEPROM_REG, temp_reg & ~Trnoff_Enable); 30752286Smdodd } 30852286Smdodd for (i = 0; i < ETHER_ADDR_LEN; i++) { 309147256Sbrooks CSR_WRITE_1(sc, I_ADDR_REG0 + i, IFP2ENADDR(sc->ifp)[i]); 31052286Smdodd } 31121769Sjkh /* 31221769Sjkh * - Setup transmit chaining and discard bad received frames. 31321769Sjkh * - Match broadcast. 31421769Sjkh * - Clear test mode. 31521769Sjkh * - Set receiving mode. 31621769Sjkh * - Set IRQ number. 31721769Sjkh */ 318131192Simp CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) | Tx_Chn_Int_Md | Tx_Chn_ErStp | Disc_Bad_Fr); 319131192Simp CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | No_SA_Ins | RX_CRC_InMem); 320131192Simp CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3) & 0x3f /* XXX constants. */ ); 321131192Simp CSR_WRITE_1(sc, CMD_REG, Bank1_Sel); 322131192Simp CSR_WRITE_1(sc, INT_NO_REG, (CSR_READ_1(sc, INT_NO_REG) & 0xf8) | sc->irq2ee[sc->irq_no]); 32321769Sjkh 32421769Sjkh /* 32521769Sjkh * Divide the available memory in the card into rcv and xmt buffers. 32621769Sjkh * By default, I use the first 3/4 of the memory for the rcv buffer, 32721769Sjkh * and the remaining 1/4 of the memory for the xmt buffer. 32821769Sjkh */ 32921769Sjkh sc->rx_mem_size = sc->mem_size * 3 / 4; 33021769Sjkh sc->tx_mem_size = sc->mem_size - sc->rx_mem_size; 33121769Sjkh sc->rx_lower_limit = 0x0000; 33221769Sjkh sc->rx_upper_limit = sc->rx_mem_size - 2; 33321769Sjkh sc->tx_lower_limit = sc->rx_mem_size; 33421769Sjkh sc->tx_upper_limit = sc->mem_size - 2; 335131192Simp CSR_WRITE_1(sc, RCV_LOWER_LIMIT_REG, sc->rx_lower_limit >> 8); 336131192Simp CSR_WRITE_1(sc, RCV_UPPER_LIMIT_REG, sc->rx_upper_limit >> 8); 337131192Simp CSR_WRITE_1(sc, XMT_LOWER_LIMIT_REG, sc->tx_lower_limit >> 8); 338131192Simp CSR_WRITE_1(sc, XMT_UPPER_LIMIT_REG, sc->tx_upper_limit >> 8); 33921769Sjkh 34021769Sjkh /* 34121769Sjkh * Enable receive and transmit interrupts, and clear any pending int. 34221769Sjkh */ 343131192Simp CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) | TriST_INT); 344131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 345131192Simp CSR_WRITE_1(sc, MASK_REG, All_Int & ~(Rx_Int | Tx_Int)); 346131192Simp CSR_WRITE_1(sc, STATUS_REG, All_Int); 34721769Sjkh 34821769Sjkh /* 34921769Sjkh * Initialize receive and transmit ring buffers. 35021769Sjkh */ 351131192Simp CSR_WRITE_2(sc, RCV_BAR, sc->rx_lower_limit); 35221769Sjkh sc->rx_head = sc->rx_lower_limit; 353131192Simp CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_upper_limit | 0xfe); 354131192Simp CSR_WRITE_2(sc, XMT_BAR, sc->tx_lower_limit); 35521769Sjkh sc->tx_head = sc->tx_tail = sc->tx_lower_limit; 35621769Sjkh 357148887Srwatson ifp->if_drv_flags |= IFF_DRV_RUNNING; 358148887Srwatson ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 35921769Sjkh DODEBUG(Status, printf("OIDLE init\n");); 36021769Sjkh 361112731Smdodd ex_setmulti(sc); 362112731Smdodd 36321769Sjkh /* 36421769Sjkh * Final reset of the board, and enable operation. 36521769Sjkh */ 366131192Simp CSR_WRITE_1(sc, CMD_REG, Sel_Reset_CMD); 36721769Sjkh DELAY(2); 368131192Simp CSR_WRITE_1(sc, CMD_REG, Rcv_Enable_CMD); 36921769Sjkh 37021769Sjkh ex_start(ifp); 37121769Sjkh splx(s); 37221769Sjkh 373121816Sbrooks DODEBUG(Start_End, printf("%s: ex_init: finish\n", ifp->if_xname);); 37421769Sjkh} 37521769Sjkh 37621769Sjkh 37755883Smdoddstatic void 37852286Smdoddex_start(struct ifnet *ifp) 37921769Sjkh{ 38052286Smdodd struct ex_softc * sc = ifp->if_softc; 38152286Smdodd int i, s, len, data_len, avail, dest, next; 38252286Smdodd unsigned char tmp16[2]; 38352286Smdodd struct mbuf * opkt; 38452286Smdodd struct mbuf * m; 38521769Sjkh 38652286Smdodd DODEBUG(Start_End, printf("ex_start%d: start\n", unit);); 38721769Sjkh 38852286Smdodd s = splimp(); 38921769Sjkh 39052286Smdodd /* 39152286Smdodd * Main loop: send outgoing packets to network card until there are no 39252286Smdodd * more packets left, or the card cannot accept any more yet. 39352286Smdodd */ 39452286Smdodd while (((opkt = ifp->if_snd.ifq_head) != NULL) && 395148887Srwatson !(ifp->if_drv_flags & IFF_DRV_OACTIVE)) { 39621769Sjkh 39752286Smdodd /* 39852286Smdodd * Ensure there is enough free transmit buffer space for 39952286Smdodd * this packet, including its header. Note: the header 40052286Smdodd * cannot wrap around the end of the transmit buffer and 40152286Smdodd * must be kept together, so we allow space for twice the 40252286Smdodd * length of the header, just in case. 40352286Smdodd */ 40421769Sjkh 40552286Smdodd for (len = 0, m = opkt; m != NULL; m = m->m_next) { 40652286Smdodd len += m->m_len; 40752286Smdodd } 40852286Smdodd 40952286Smdodd data_len = len; 41052286Smdodd 41152286Smdodd DODEBUG(Sent_Pkts, printf("1. Sending packet with %d data bytes. ", data_len);); 41252286Smdodd 41352286Smdodd if (len & 1) { 41452286Smdodd len += XMT_HEADER_LEN + 1; 41552286Smdodd } else { 41652286Smdodd len += XMT_HEADER_LEN; 41752286Smdodd } 41852286Smdodd 41952286Smdodd if ((i = sc->tx_tail - sc->tx_head) >= 0) { 42052286Smdodd avail = sc->tx_mem_size - i; 42152286Smdodd } else { 42252286Smdodd avail = -i; 42352286Smdodd } 42452286Smdodd 42552286Smdodd DODEBUG(Sent_Pkts, printf("i=%d, avail=%d\n", i, avail);); 42652286Smdodd 42752286Smdodd if (avail >= len + XMT_HEADER_LEN) { 42852286Smdodd IF_DEQUEUE(&ifp->if_snd, opkt); 42952286Smdodd 43021769Sjkh#ifdef EX_PSA_INTR 43152286Smdodd /* 43252286Smdodd * Disable rx and tx interrupts, to avoid corruption 43352286Smdodd * of the host address register by interrupt service 43452286Smdodd * routines. 43552286Smdodd * XXX Is this necessary with splimp() enabled? 43652286Smdodd */ 437131192Simp CSR_WRITE_1(sc, MASK_REG, All_Int); 43821769Sjkh#endif 43921769Sjkh 44052286Smdodd /* 44152286Smdodd * Compute the start and end addresses of this 44252286Smdodd * frame in the tx buffer. 44352286Smdodd */ 44452286Smdodd dest = sc->tx_tail; 44552286Smdodd next = dest + len; 44621769Sjkh 44752286Smdodd if (next > sc->tx_upper_limit) { 44852286Smdodd if ((sc->tx_upper_limit + 2 - sc->tx_tail) <= 44952286Smdodd XMT_HEADER_LEN) { 45052286Smdodd dest = sc->tx_lower_limit; 45152286Smdodd next = dest + len; 45255881Smdodd } else { 45355881Smdodd next = sc->tx_lower_limit + 45455881Smdodd next - sc->tx_upper_limit - 2; 45552286Smdodd } 45652286Smdodd } 45721769Sjkh 45852286Smdodd /* 45952286Smdodd * Build the packet frame in the card's ring buffer. 46052286Smdodd */ 46152286Smdodd DODEBUG(Sent_Pkts, printf("2. dest=%d, next=%d. ", dest, next);); 46221769Sjkh 463131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, dest); 464131192Simp CSR_WRITE_2(sc, IO_PORT_REG, Transmit_CMD); 465131192Simp CSR_WRITE_2(sc, IO_PORT_REG, 0); 466131192Simp CSR_WRITE_2(sc, IO_PORT_REG, next); 467131192Simp CSR_WRITE_2(sc, IO_PORT_REG, data_len); 46821769Sjkh 46952286Smdodd /* 47052286Smdodd * Output the packet data to the card. Ensure all 47152286Smdodd * transfers are 16-bit wide, even if individual 47252286Smdodd * mbufs have odd length. 47352286Smdodd */ 47452286Smdodd for (m = opkt, i = 0; m != NULL; m = m->m_next) { 47552286Smdodd DODEBUG(Sent_Pkts, printf("[%d]", m->m_len);); 47652286Smdodd if (i) { 47752286Smdodd tmp16[1] = *(mtod(m, caddr_t)); 478131192Simp CSR_WRITE_MULTI_2(sc, IO_PORT_REG, 479131192Simp (uint16_t *) tmp16, 1); 48052286Smdodd } 481131192Simp CSR_WRITE_MULTI_2(sc, IO_PORT_REG, 482131192Simp (uint16_t *) (mtod(m, caddr_t) + i), 483131192Simp (m->m_len - i) / 2); 48452286Smdodd if ((i = (m->m_len - i) & 1) != 0) { 48552286Smdodd tmp16[0] = *(mtod(m, caddr_t) + 48652286Smdodd m->m_len - 1); 48752286Smdodd } 48852286Smdodd } 489131192Simp if (i) 490131192Simp CSR_WRITE_MULTI_2(sc, IO_PORT_REG, 491131192Simp (uint16_t *) tmp16, 1); 49255881Smdodd /* 49355881Smdodd * If there were other frames chained, update the 49455881Smdodd * chain in the last one. 49555881Smdodd */ 49655881Smdodd if (sc->tx_head != sc->tx_tail) { 49755881Smdodd if (sc->tx_tail != dest) { 498131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, 49955881Smdodd sc->tx_last + XMT_Chain_Point); 500131192Simp CSR_WRITE_2(sc, IO_PORT_REG, dest); 50152286Smdodd } 502131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, 50355881Smdodd sc->tx_last + XMT_Byte_Count); 504131192Simp i = CSR_READ_2(sc, IO_PORT_REG); 505131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, 50655881Smdodd sc->tx_last + XMT_Byte_Count); 507131192Simp CSR_WRITE_2(sc, IO_PORT_REG, i | Ch_bit); 50855881Smdodd } 50955881Smdodd 51055881Smdodd /* 51155881Smdodd * Resume normal operation of the card: 51255881Smdodd * - Make a dummy read to flush the DRAM write 51355881Smdodd * pipeline. 51455881Smdodd * - Enable receive and transmit interrupts. 51555881Smdodd * - Send Transmit or Resume_XMT command, as 51655881Smdodd * appropriate. 51755881Smdodd */ 518131192Simp CSR_READ_2(sc, IO_PORT_REG); 51921769Sjkh#ifdef EX_PSA_INTR 520131192Simp CSR_WRITE_1(sc, MASK_REG, All_Int & ~(Rx_Int | Tx_Int)); 52121769Sjkh#endif 52255881Smdodd if (sc->tx_head == sc->tx_tail) { 523131192Simp CSR_WRITE_2(sc, XMT_BAR, dest); 524131192Simp CSR_WRITE_1(sc, CMD_REG, Transmit_CMD); 52555881Smdodd sc->tx_head = dest; 52655881Smdodd DODEBUG(Sent_Pkts, printf("Transmit\n");); 52752286Smdodd } else { 528131192Simp CSR_WRITE_1(sc, CMD_REG, Resume_XMT_List_CMD); 52955881Smdodd DODEBUG(Sent_Pkts, printf("Resume\n");); 53052286Smdodd } 53155881Smdodd 53255881Smdodd sc->tx_last = dest; 53355881Smdodd sc->tx_tail = next; 53455881Smdodd 535106937Ssam BPF_MTAP(ifp, opkt); 53655881Smdodd 53755881Smdodd ifp->if_timer = 2; 53855881Smdodd ifp->if_opackets++; 53955881Smdodd m_freem(opkt); 54055881Smdodd } else { 541148887Srwatson ifp->if_drv_flags |= IFF_DRV_OACTIVE; 54255881Smdodd DODEBUG(Status, printf("OACTIVE start\n");); 54352286Smdodd } 54421769Sjkh } 54521769Sjkh 54652286Smdodd splx(s); 54721769Sjkh 54852286Smdodd DODEBUG(Start_End, printf("ex_start%d: finish\n", unit);); 54921769Sjkh} 55021769Sjkh 55166440Simpvoid 55252286Smdoddex_stop(struct ex_softc *sc) 55321769Sjkh{ 554131192Simp 55552286Smdodd DODEBUG(Start_End, printf("ex_stop%d: start\n", unit);); 55621769Sjkh 55752286Smdodd /* 55852286Smdodd * Disable card operation: 55952286Smdodd * - Disable the interrupt line. 56052286Smdodd * - Flush transmission and disable reception. 56152286Smdodd * - Mask and clear all interrupts. 56252286Smdodd * - Reset the 82595. 56352286Smdodd */ 564131192Simp CSR_WRITE_1(sc, CMD_REG, Bank1_Sel); 565131192Simp CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) & ~TriST_INT); 566131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 567131192Simp CSR_WRITE_1(sc, CMD_REG, Rcv_Stop); 56852286Smdodd sc->tx_head = sc->tx_tail = sc->tx_lower_limit; 56952286Smdodd sc->tx_last = 0; /* XXX I think these two lines are not necessary, because ex_init will always be called again to reinit the interface. */ 570131192Simp CSR_WRITE_1(sc, MASK_REG, All_Int); 571131192Simp CSR_WRITE_1(sc, STATUS_REG, All_Int); 572131192Simp CSR_WRITE_1(sc, CMD_REG, Reset_CMD); 57352286Smdodd DELAY(200); 57421769Sjkh 57552286Smdodd DODEBUG(Start_End, printf("ex_stop%d: finish\n", unit);); 57652286Smdodd 57752286Smdodd return; 57821769Sjkh} 57921769Sjkh 58059816Smdoddvoid 58155883Smdoddex_intr(void *arg) 58221769Sjkh{ 583131192Simp struct ex_softc *sc = (struct ex_softc *)arg; 584147256Sbrooks struct ifnet *ifp = sc->ifp; 585131192Simp int int_status, send_pkts; 586131192Simp int loops = 100; 58721769Sjkh 58855883Smdodd DODEBUG(Start_End, printf("ex_intr%d: start\n", unit);); 58921769Sjkh 59052286Smdodd send_pkts = 0; 591131192Simp while (loops-- > 0 && 592131192Simp (int_status = CSR_READ_1(sc, STATUS_REG)) & (Tx_Int | Rx_Int)) { 593131192Simp /* don't loop forever */ 594131192Simp if (int_status == 0xff) 595131192Simp break; 59652286Smdodd if (int_status & Rx_Int) { 597131192Simp CSR_WRITE_1(sc, STATUS_REG, Rx_Int); 59852286Smdodd ex_rx_intr(sc); 59952286Smdodd } else if (int_status & Tx_Int) { 600131192Simp CSR_WRITE_1(sc, STATUS_REG, Tx_Int); 60152286Smdodd ex_tx_intr(sc); 60252286Smdodd send_pkts = 1; 60352286Smdodd } 60452286Smdodd } 605131192Simp if (loops == 0) 606131192Simp printf("100 loops are not enough\n"); 60721769Sjkh 60852286Smdodd /* 60952286Smdodd * If any packet has been transmitted, and there are queued packets to 61052286Smdodd * be sent, attempt to send more packets to the network card. 61152286Smdodd */ 612131192Simp if (send_pkts && (ifp->if_snd.ifq_head != NULL)) 61352286Smdodd ex_start(ifp); 61452286Smdodd 61555883Smdodd DODEBUG(Start_End, printf("ex_intr%d: finish\n", unit);); 61652286Smdodd 61752286Smdodd return; 61821769Sjkh} 61921769Sjkh 62052286Smdoddstatic void 62152286Smdoddex_tx_intr(struct ex_softc *sc) 62221769Sjkh{ 623147256Sbrooks struct ifnet * ifp = sc->ifp; 62452286Smdodd int tx_status; 62521769Sjkh 62652286Smdodd DODEBUG(Start_End, printf("ex_tx_intr%d: start\n", unit);); 62721769Sjkh 62852286Smdodd /* 62952286Smdodd * - Cancel the watchdog. 63052286Smdodd * For all packets transmitted since last transmit interrupt: 63152286Smdodd * - Advance chain pointer to next queued packet. 63252286Smdodd * - Update statistics. 63352286Smdodd */ 63421769Sjkh 63552286Smdodd ifp->if_timer = 0; 63621769Sjkh 63752286Smdodd while (sc->tx_head != sc->tx_tail) { 638131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, sc->tx_head); 63921769Sjkh 640131192Simp if (! CSR_READ_2(sc, IO_PORT_REG) & Done_bit) 64152286Smdodd break; 64221769Sjkh 643131192Simp tx_status = CSR_READ_2(sc, IO_PORT_REG); 644131192Simp sc->tx_head = CSR_READ_2(sc, IO_PORT_REG); 64552286Smdodd 64652286Smdodd if (tx_status & TX_OK_bit) { 64752286Smdodd ifp->if_opackets++; 64852286Smdodd } else { 64952286Smdodd ifp->if_oerrors++; 65052286Smdodd } 65152286Smdodd 65252286Smdodd ifp->if_collisions += tx_status & No_Collisions_bits; 65352286Smdodd } 65452286Smdodd 65552286Smdodd /* 65652286Smdodd * The card should be ready to accept more packets now. 65752286Smdodd */ 65852286Smdodd 659148887Srwatson ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 66052286Smdodd 66152286Smdodd DODEBUG(Status, printf("OIDLE tx_intr\n");); 66252286Smdodd DODEBUG(Start_End, printf("ex_tx_intr%d: finish\n", unit);); 66352286Smdodd 66452286Smdodd return; 66521769Sjkh} 66621769Sjkh 66752286Smdoddstatic void 66852286Smdoddex_rx_intr(struct ex_softc *sc) 66921769Sjkh{ 670147256Sbrooks struct ifnet * ifp = sc->ifp; 67152286Smdodd int rx_status; 67252286Smdodd int pkt_len; 67352286Smdodd int QQQ; 67452286Smdodd struct mbuf * m; 67552286Smdodd struct mbuf * ipkt; 67652286Smdodd struct ether_header * eh; 67721769Sjkh 67852286Smdodd DODEBUG(Start_End, printf("ex_rx_intr%d: start\n", unit);); 67921769Sjkh 68052286Smdodd /* 68152286Smdodd * For all packets received since last receive interrupt: 68252286Smdodd * - If packet ok, read it into a new mbuf and queue it to interface, 68352286Smdodd * updating statistics. 68452286Smdodd * - If packet bad, just discard it, and update statistics. 68552286Smdodd * Finally, advance receive stop limit in card's memory to new location. 68652286Smdodd */ 68721769Sjkh 688131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, sc->rx_head); 68921769Sjkh 690131192Simp while (CSR_READ_2(sc, IO_PORT_REG) == RCV_Done) { 69152286Smdodd 692131192Simp rx_status = CSR_READ_2(sc, IO_PORT_REG); 693131192Simp sc->rx_head = CSR_READ_2(sc, IO_PORT_REG); 694131192Simp QQQ = pkt_len = CSR_READ_2(sc, IO_PORT_REG); 69552286Smdodd 69652286Smdodd if (rx_status & RCV_OK_bit) { 697111119Simp MGETHDR(m, M_DONTWAIT, MT_DATA); 69852286Smdodd ipkt = m; 69952286Smdodd if (ipkt == NULL) { 70052286Smdodd ifp->if_iqdrops++; 70152286Smdodd } else { 70252286Smdodd ipkt->m_pkthdr.rcvif = ifp; 70352286Smdodd ipkt->m_pkthdr.len = pkt_len; 70452286Smdodd ipkt->m_len = MHLEN; 70552286Smdodd 70652286Smdodd while (pkt_len > 0) { 707136625Sglebius if (pkt_len >= MINCLSIZE) { 708111119Simp MCLGET(m, M_DONTWAIT); 70952286Smdodd if (m->m_flags & M_EXT) { 71052286Smdodd m->m_len = MCLBYTES; 71152286Smdodd } else { 71252286Smdodd m_freem(ipkt); 71352286Smdodd ifp->if_iqdrops++; 71452286Smdodd goto rx_another; 71552286Smdodd } 71652286Smdodd } 71752286Smdodd m->m_len = min(m->m_len, pkt_len); 71852286Smdodd 71921769Sjkh /* 72021769Sjkh * NOTE: I'm assuming that all mbufs allocated are of even length, 72121769Sjkh * except for the last one in an odd-length packet. 72221769Sjkh */ 72352286Smdodd 724131192Simp CSR_READ_MULTI_2(sc, IO_PORT_REG, 725131192Simp mtod(m, uint16_t *), m->m_len / 2); 72652286Smdodd 72752286Smdodd if (m->m_len & 1) { 728131192Simp *(mtod(m, caddr_t) + m->m_len - 1) = CSR_READ_1(sc, IO_PORT_REG); 72952286Smdodd } 73052286Smdodd pkt_len -= m->m_len; 73152286Smdodd 73252286Smdodd if (pkt_len > 0) { 733111119Simp MGET(m->m_next, M_DONTWAIT, MT_DATA); 73452286Smdodd if (m->m_next == NULL) { 73552286Smdodd m_freem(ipkt); 73652286Smdodd ifp->if_iqdrops++; 73752286Smdodd goto rx_another; 73852286Smdodd } 73952286Smdodd m = m->m_next; 74052286Smdodd m->m_len = MLEN; 74152286Smdodd } 74252286Smdodd } 74352286Smdodd eh = mtod(ipkt, struct ether_header *); 74452286Smdodd#ifdef EXDEBUG 74552286Smdodd if (debug_mask & Rcvd_Pkts) { 74652286Smdodd if ((eh->ether_dhost[5] != 0xff) || (eh->ether_dhost[0] != 0xff)) { 74752286Smdodd printf("Receive packet with %d data bytes: %6D -> ", QQQ, eh->ether_shost, ":"); 74852286Smdodd printf("%6D\n", eh->ether_dhost, ":"); 74952286Smdodd } /* QQQ */ 75021769Sjkh } 75121769Sjkh#endif 752106937Ssam (*ifp->if_input)(ifp, ipkt); 75352286Smdodd ifp->if_ipackets++; 75452286Smdodd } 75552286Smdodd } else { 75652286Smdodd ifp->if_ierrors++; 75721769Sjkh } 758131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, sc->rx_head); 75952286Smdoddrx_another: ; 76021769Sjkh } 76121769Sjkh 76252286Smdodd if (sc->rx_head < sc->rx_lower_limit + 2) 763131192Simp CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_upper_limit); 76452286Smdodd else 765131192Simp CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_head - 2); 76652286Smdodd 76752286Smdodd DODEBUG(Start_End, printf("ex_rx_intr%d: finish\n", unit);); 76852286Smdodd 76952286Smdodd return; 77021769Sjkh} 77121769Sjkh 77221769Sjkh 77355883Smdoddstatic int 77455883Smdoddex_ioctl(register struct ifnet *ifp, u_long cmd, caddr_t data) 77521769Sjkh{ 77652286Smdodd struct ex_softc * sc = ifp->if_softc; 77757987Smdodd struct ifreq * ifr = (struct ifreq *)data; 77852286Smdodd int s; 77952286Smdodd int error = 0; 78021769Sjkh 781121816Sbrooks DODEBUG(Start_End, printf("%s: ex_ioctl: start ", ifp->if_xname);); 78221769Sjkh 78352286Smdodd s = splimp(); 78421769Sjkh 78552286Smdodd switch(cmd) { 78652286Smdodd case SIOCSIFADDR: 78752286Smdodd case SIOCGIFADDR: 78852286Smdodd case SIOCSIFMTU: 78952286Smdodd error = ether_ioctl(ifp, cmd, data); 79052286Smdodd break; 79121769Sjkh 79252286Smdodd case SIOCSIFFLAGS: 79352286Smdodd DODEBUG(Start_End, printf("SIOCSIFFLAGS");); 79452286Smdodd if ((ifp->if_flags & IFF_UP) == 0 && 795148887Srwatson (ifp->if_drv_flags & IFF_DRV_RUNNING)) { 79652286Smdodd 797148887Srwatson ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 79852286Smdodd ex_stop(sc); 79952286Smdodd } else { 80052286Smdodd ex_init(sc); 80152286Smdodd } 80252286Smdodd break; 80321769Sjkh#ifdef NODEF 80452286Smdodd case SIOCGHWADDR: 80552286Smdodd DODEBUG(Start_End, printf("SIOCGHWADDR");); 80652286Smdodd bcopy((caddr_t)sc->sc_addr, (caddr_t)&ifr->ifr_data, 80752286Smdodd sizeof(sc->sc_addr)); 80852286Smdodd break; 80921769Sjkh#endif 81052286Smdodd case SIOCADDMULTI: 81152286Smdodd case SIOCDELMULTI: 812112731Smdodd ex_init(sc); 813112731Smdodd error = 0; 81452286Smdodd break; 81557987Smdodd case SIOCSIFMEDIA: 81657987Smdodd case SIOCGIFMEDIA: 81757987Smdodd error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd); 81857987Smdodd break; 81952286Smdodd default: 82052286Smdodd DODEBUG(Start_End, printf("unknown");); 82152286Smdodd error = EINVAL; 82252286Smdodd } 82321769Sjkh 82452286Smdodd splx(s); 82521769Sjkh 826121816Sbrooks DODEBUG(Start_End, printf("\n%s: ex_ioctl: finish\n", ifp->if_xname);); 82752286Smdodd 82852286Smdodd return(error); 82921769Sjkh} 83021769Sjkh 831112731Smdoddstatic void 832112731Smdoddex_setmulti(struct ex_softc *sc) 833112731Smdodd{ 834112731Smdodd struct ifnet *ifp; 835112731Smdodd struct ifmultiaddr *maddr; 836131192Simp uint16_t *addr; 837112731Smdodd int count; 838112731Smdodd int timeout, status; 839112731Smdodd 840147256Sbrooks ifp = sc->ifp; 84121769Sjkh 842112731Smdodd count = 0; 843148654Srwatson IF_ADDR_LOCK(ifp); 844112731Smdodd TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) { 845112731Smdodd if (maddr->ifma_addr->sa_family != AF_LINK) 846112731Smdodd continue; 847112731Smdodd count++; 848112731Smdodd } 849148654Srwatson IF_ADDR_UNLOCK(ifp); 850112731Smdodd 851112731Smdodd if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI) 852112731Smdodd || count > 63) { 853112731Smdodd /* Interface is in promiscuous mode or there are too many 854112731Smdodd * multicast addresses for the card to handle */ 855131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 856131192Simp CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | Promisc_Mode); 857131192Simp CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3)); 858131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 859112731Smdodd } 860112731Smdodd else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) { 861112731Smdodd /* Program multicast addresses plus our MAC address 862112731Smdodd * into the filter */ 863131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 864131192Simp CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | Multi_IA); 865131192Simp CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3)); 866131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 867112731Smdodd 868112731Smdodd /* Borrow space from TX buffer; this should be safe 869112731Smdodd * as this is only called from ex_init */ 870112731Smdodd 871131192Simp CSR_WRITE_2(sc, HOST_ADDR_REG, sc->tx_lower_limit); 872131192Simp CSR_WRITE_2(sc, IO_PORT_REG, MC_Setup_CMD); 873131192Simp CSR_WRITE_2(sc, IO_PORT_REG, 0); 874131192Simp CSR_WRITE_2(sc, IO_PORT_REG, 0); 875131192Simp CSR_WRITE_2(sc, IO_PORT_REG, (count + 1) * 6); 876148654Srwatson 877148654Srwatson IF_ADDR_LOCK(ifp); 878112731Smdodd TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) { 879112731Smdodd if (maddr->ifma_addr->sa_family != AF_LINK) 880112731Smdodd continue; 881112731Smdodd 882131192Simp addr = (uint16_t*)LLADDR((struct sockaddr_dl *) 883112731Smdodd maddr->ifma_addr); 884131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 885131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 886131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 887112731Smdodd } 888148654Srwatson IF_ADDR_UNLOCK(ifp); 889112731Smdodd 890112731Smdodd /* Program our MAC address as well */ 891112731Smdodd /* XXX: Is this necessary? The Linux driver does this 892112731Smdodd * but the NetBSD driver does not */ 893147256Sbrooks addr = (uint16_t*)(&IFP2ENADDR(sc->ifp)); 894131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 895131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 896131192Simp CSR_WRITE_2(sc, IO_PORT_REG, *addr++); 897112731Smdodd 898131192Simp CSR_READ_2(sc, IO_PORT_REG); 899131192Simp CSR_WRITE_2(sc, XMT_BAR, sc->tx_lower_limit); 900131192Simp CSR_WRITE_1(sc, CMD_REG, MC_Setup_CMD); 901112731Smdodd 902112731Smdodd sc->tx_head = sc->tx_lower_limit; 903112731Smdodd sc->tx_tail = sc->tx_head + XMT_HEADER_LEN + (count + 1) * 6; 904112731Smdodd 905112731Smdodd for (timeout=0; timeout<100; timeout++) { 906112731Smdodd DELAY(2); 907131192Simp if ((CSR_READ_1(sc, STATUS_REG) & Exec_Int) == 0) 908112731Smdodd continue; 909112731Smdodd 910131192Simp status = CSR_READ_1(sc, CMD_REG); 911131192Simp CSR_WRITE_1(sc, STATUS_REG, Exec_Int); 912112731Smdodd break; 913112731Smdodd } 914112731Smdodd 915112731Smdodd sc->tx_head = sc->tx_tail; 916112731Smdodd } 917112731Smdodd else 918112731Smdodd { 919112731Smdodd /* No multicast or promiscuous mode */ 920131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 921131192Simp CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) & 0xDE); 922112731Smdodd /* ~(Multi_IA | Promisc_Mode) */ 923131192Simp CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3)); 924131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 925112731Smdodd } 926112731Smdodd} 927112731Smdodd 92852286Smdoddstatic void 92952286Smdoddex_reset(struct ex_softc *sc) 93021769Sjkh{ 93152286Smdodd int s; 93221769Sjkh 93352286Smdodd DODEBUG(Start_End, printf("ex_reset%d: start\n", unit);); 93421769Sjkh 93552286Smdodd s = splimp(); 93621769Sjkh 93752286Smdodd ex_stop(sc); 93852286Smdodd ex_init(sc); 93921769Sjkh 94052286Smdodd splx(s); 94121769Sjkh 94252286Smdodd DODEBUG(Start_End, printf("ex_reset%d: finish\n", unit);); 94352286Smdodd 94452286Smdodd return; 94521769Sjkh} 94621769Sjkh 94752286Smdoddstatic void 94852286Smdoddex_watchdog(struct ifnet *ifp) 94921769Sjkh{ 95052286Smdodd struct ex_softc * sc = ifp->if_softc; 95121769Sjkh 952121816Sbrooks DODEBUG(Start_End, printf("%s: ex_watchdog: start\n", ifp->if_xname);); 95321769Sjkh 954148887Srwatson ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 95521769Sjkh 95652286Smdodd DODEBUG(Status, printf("OIDLE watchdog\n");); 95752286Smdodd 95852286Smdodd ifp->if_oerrors++; 95952286Smdodd ex_reset(sc); 96052286Smdodd ex_start(ifp); 96152286Smdodd 962121816Sbrooks DODEBUG(Start_End, printf("%s: ex_watchdog: finish\n", ifp->if_xname);); 96352286Smdodd 96452286Smdodd return; 96521769Sjkh} 96621769Sjkh 96757987Smdoddstatic int 968131192Simpex_get_media(struct ex_softc *sc) 96959816Smdodd{ 970112764Smdodd int current; 971112764Smdodd int media; 97259816Smdodd 973131192Simp media = ex_eeprom_read(sc, EE_W5); 974112764Smdodd 975131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 976131192Simp current = CSR_READ_1(sc, REG3); 977131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 97859816Smdodd 979112764Smdodd if ((current & TPE_bit) && (media & EE_W5_PORT_TPE)) 98059816Smdodd return(IFM_ETHER|IFM_10_T); 981112764Smdodd if ((current & BNC_bit) && (media & EE_W5_PORT_BNC)) 98259816Smdodd return(IFM_ETHER|IFM_10_2); 98359816Smdodd 984112764Smdodd if (media & EE_W5_PORT_AUI) 985112764Smdodd return (IFM_ETHER|IFM_10_5); 986112764Smdodd 987112764Smdodd return (IFM_ETHER|IFM_AUTO); 98859816Smdodd} 98959816Smdodd 99059816Smdoddstatic int 991131192Simpex_ifmedia_upd(ifp) 99257987Smdodd struct ifnet * ifp; 99357987Smdodd{ 994112764Smdodd struct ex_softc * sc = ifp->if_softc; 99521769Sjkh 996112764Smdodd if (IFM_TYPE(sc->ifmedia.ifm_media) != IFM_ETHER) 997112764Smdodd return EINVAL; 998112764Smdodd 99957987Smdodd return (0); 100057987Smdodd} 100157987Smdodd 100257987Smdoddstatic void 100357987Smdoddex_ifmedia_sts(ifp, ifmr) 100457987Smdodd struct ifnet * ifp; 100557987Smdodd struct ifmediareq * ifmr; 100657987Smdodd{ 100757987Smdodd struct ex_softc * sc = ifp->if_softc; 100857987Smdodd 1009131192Simp ifmr->ifm_active = ex_get_media(sc); 1010112764Smdodd ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE; 101157987Smdodd 101257987Smdodd return; 101357987Smdodd} 101457987Smdodd 101559816Smdoddu_short 1016131192Simpex_eeprom_read(struct ex_softc *sc, int location) 101721769Sjkh{ 101821769Sjkh int i; 101921769Sjkh u_short data = 0; 102021769Sjkh int read_cmd = location | EE_READ_CMD; 102121769Sjkh short ctrl_val = EECS; 102221769Sjkh 1023131192Simp CSR_WRITE_1(sc, CMD_REG, Bank2_Sel); 1024131192Simp CSR_WRITE_1(sc, EEPROM_REG, EECS); 102521769Sjkh for (i = 8; i >= 0; i--) { 102621769Sjkh short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI : ctrl_val; 1027131192Simp CSR_WRITE_1(sc, EEPROM_REG, outval); 1028131192Simp CSR_WRITE_1(sc, EEPROM_REG, outval | EESK); 102921769Sjkh DELAY(3); 1030131192Simp CSR_WRITE_1(sc, EEPROM_REG, outval); 103121769Sjkh DELAY(2); 103221769Sjkh } 1033131192Simp CSR_WRITE_1(sc, EEPROM_REG, ctrl_val); 103421769Sjkh 103521769Sjkh for (i = 16; i > 0; i--) { 1036131192Simp CSR_WRITE_1(sc, EEPROM_REG, ctrl_val | EESK); 103721769Sjkh DELAY(3); 1038131192Simp data = (data << 1) | 1039131192Simp ((CSR_READ_1(sc, EEPROM_REG) & EEDO) ? 1 : 0); 1040131192Simp CSR_WRITE_1(sc, EEPROM_REG, ctrl_val); 104121769Sjkh DELAY(2); 104221769Sjkh } 104321769Sjkh 104421769Sjkh ctrl_val &= ~EECS; 1045131192Simp CSR_WRITE_1(sc, EEPROM_REG, ctrl_val | EESK); 104621769Sjkh DELAY(3); 1047131192Simp CSR_WRITE_1(sc, EEPROM_REG, ctrl_val); 104821769Sjkh DELAY(2); 1049131192Simp CSR_WRITE_1(sc, CMD_REG, Bank0_Sel); 105021769Sjkh return(data); 105121769Sjkh} 1052