if_ex.c revision 112731
121769Sjkh/* 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 * 2750477Speter * $FreeBSD: head/sys/dev/ex/if_ex.c 112731 2003-03-28 02:15:01Z mdodd $ 2852286Smdodd * 2952286Smdodd * MAINTAINER: Matthew N. Dodd <winter@jurai.net> 3052286Smdodd * <mdodd@FreeBSD.org> 3121769Sjkh */ 3221769Sjkh 3321769Sjkh/* 3429877Smsmith * Intel EtherExpress Pro/10, Pro/10+ Ethernet driver 3521769Sjkh * 3621769Sjkh * Revision history: 3721769Sjkh * 38112731Smdodd * dd-mmm-yyyy: Multicast support ported from NetBSD's if_iy driver. 3921769Sjkh * 30-Oct-1996: first beta version. Inet and BPF supported, but no multicast. 4021769Sjkh */ 4121769Sjkh 4221769Sjkh#include <sys/param.h> 4321769Sjkh#include <sys/systm.h> 4452286Smdodd#include <sys/kernel.h> 4524204Sbde#include <sys/sockio.h> 4621769Sjkh#include <sys/mbuf.h> 4721769Sjkh#include <sys/socket.h> 4821769Sjkh 4952286Smdodd#include <sys/module.h> 5052286Smdodd#include <sys/bus.h> 5152286Smdodd 5252286Smdodd#include <machine/bus.h> 5352286Smdodd#include <machine/resource.h> 5452286Smdodd#include <sys/rman.h> 5552286Smdodd 5657987Smdodd#include <net/if.h> 5757987Smdodd#include <net/if_arp.h> 58112731Smdodd#include <net/if_dl.h> 5957987Smdodd#include <net/if_media.h> 6050026Smdodd#include <net/ethernet.h> 6157987Smdodd#include <net/bpf.h> 6221769Sjkh 6350026Smdodd#include <netinet/in.h> 6450026Smdodd#include <netinet/if_ether.h> 6550026Smdodd 6621769Sjkh 6752286Smdodd#include <isa/isavar.h> 6852286Smdodd#include <isa/pnpvar.h> 6952286Smdodd 7055953Speter#include <dev/ex/if_exreg.h> 7159816Smdodd#include <dev/ex/if_exvar.h> 7221769Sjkh 7321769Sjkh#ifdef EXDEBUG 7452286Smdodd# define Start_End 1 7552286Smdodd# define Rcvd_Pkts 2 7652286Smdodd# define Sent_Pkts 4 7752286Smdodd# define Status 8 7821769Sjkhstatic int debug_mask = 0; 7921769Sjkhstatic int exintr_count = 0; 8052286Smdodd# define DODEBUG(level, action) if (level & debug_mask) action 8121769Sjkh#else 8252286Smdodd# define DODEBUG(level, action) 8321769Sjkh#endif 8421769Sjkh 8559816Smdoddchar irq2eemap[] = 8652286Smdodd { -1, -1, 0, 1, -1, 2, -1, -1, -1, 0, 3, 4, -1, -1, -1, -1 }; 8759816Smdoddu_char ee2irqmap[] = 8852286Smdodd { 9, 3, 5, 10, 11, 0, 0, 0 }; 8959816Smdodd 9059816Smdoddchar plus_irq2eemap[] = 9152286Smdodd { -1, -1, -1, 0, 1, 2, -1, 3, -1, 4, 5, 6, 7, -1, -1, -1 }; 9259816Smdoddu_char plus_ee2irqmap[] = 9352286Smdodd { 3, 4, 5, 7, 9, 10, 11, 12 }; 9421769Sjkh 9552286Smdodd/* Network Interface Functions */ 9692739Salfredstatic void ex_init (void *); 9792739Salfredstatic void ex_start (struct ifnet *); 9892739Salfredstatic int ex_ioctl (struct ifnet *, u_long, caddr_t); 9992739Salfredstatic void ex_watchdog (struct ifnet *); 10021769Sjkh 10157987Smdodd/* ifmedia Functions */ 10292739Salfredstatic int ex_ifmedia_upd (struct ifnet *); 10392739Salfredstatic void ex_ifmedia_sts (struct ifnet *, struct ifmediareq *); 10457987Smdodd 10592739Salfredstatic int ex_get_media (u_int32_t iobase); 10659816Smdodd 10792739Salfredstatic void ex_reset (struct ex_softc *); 108112731Smdoddstatic void ex_setmulti (struct ex_softc *); 10952286Smdodd 11092739Salfredstatic void ex_tx_intr (struct ex_softc *); 11192739Salfredstatic void ex_rx_intr (struct ex_softc *); 11252286Smdodd 11359816Smdoddint 11459816Smdoddlook_for_card (u_int32_t iobase) 11521769Sjkh{ 11621769Sjkh int count1, count2; 11721769Sjkh 11821769Sjkh /* 11921769Sjkh * Check for the i82595 signature, and check that the round robin 12021769Sjkh * counter actually advances. 12121769Sjkh */ 12221769Sjkh if (((count1 = inb(iobase + ID_REG)) & Id_Mask) != Id_Sig) 12321769Sjkh return(0); 12421769Sjkh count2 = inb(iobase + ID_REG); 12521769Sjkh count2 = inb(iobase + ID_REG); 12621769Sjkh count2 = inb(iobase + ID_REG); 12752286Smdodd 12821769Sjkh return((count2 & Counter_bits) == ((count1 + 0xc0) & Counter_bits)); 12921769Sjkh} 13021769Sjkh 13159816Smdoddvoid 13252286Smdoddex_get_address (u_int32_t iobase, u_char *enaddr) 13321769Sjkh{ 13452286Smdodd u_int16_t eaddr_tmp; 13521769Sjkh 13652286Smdodd eaddr_tmp = eeprom_read(iobase, EE_Eth_Addr_Lo); 13752286Smdodd enaddr[5] = eaddr_tmp & 0xff; 13852286Smdodd enaddr[4] = eaddr_tmp >> 8; 13952286Smdodd eaddr_tmp = eeprom_read(iobase, EE_Eth_Addr_Mid); 14052286Smdodd enaddr[3] = eaddr_tmp & 0xff; 14152286Smdodd enaddr[2] = eaddr_tmp >> 8; 14252286Smdodd eaddr_tmp = eeprom_read(iobase, EE_Eth_Addr_Hi); 14352286Smdodd enaddr[1] = eaddr_tmp & 0xff; 14452286Smdodd enaddr[0] = eaddr_tmp >> 8; 14552286Smdodd 14652286Smdodd return; 14752286Smdodd} 14821769Sjkh 14959816Smdoddint 15052286Smdoddex_card_type (u_char *enaddr) 15152286Smdodd{ 15252286Smdodd if ((enaddr[0] == 0x00) && (enaddr[1] == 0xA0) && (enaddr[2] == 0xC9)) 15352286Smdodd return (CARD_TYPE_EX_10_PLUS); 15452286Smdodd 15552286Smdodd return (CARD_TYPE_EX_10); 15652286Smdodd} 15752286Smdodd 15855882Smdodd/* 15959816Smdodd * Caller is responsible for eventually calling 16059816Smdodd * ex_release_resources() on failure. 16155882Smdodd */ 16259816Smdoddint 16359816Smdoddex_alloc_resources (device_t dev) 16455882Smdodd{ 16559816Smdodd struct ex_softc * sc = device_get_softc(dev); 16659816Smdodd int error = 0; 16755882Smdodd 16859816Smdodd sc->ioport = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->ioport_rid, 16959816Smdodd 0, ~0, 1, RF_ACTIVE); 17059816Smdodd if (!sc->ioport) { 17159816Smdodd device_printf(dev, "No I/O space?!\n"); 17259816Smdodd error = ENOMEM; 17359816Smdodd goto bad; 17459816Smdodd } 17557989Smdodd 17659816Smdodd sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid, 17759816Smdodd 0, ~0, 1, RF_ACTIVE); 17855882Smdodd 17959816Smdodd if (!sc->irq) { 18059816Smdodd device_printf(dev, "No IRQ?!\n"); 18159816Smdodd error = ENOMEM; 18259816Smdodd goto bad; 18355882Smdodd } 18455882Smdodd 18559816Smdoddbad: 18659816Smdodd return (error); 18755882Smdodd} 18855882Smdodd 18959816Smdoddvoid 19059816Smdoddex_release_resources (device_t dev) 19152286Smdodd{ 19259816Smdodd struct ex_softc * sc = device_get_softc(dev); 19352286Smdodd 19459816Smdodd if (sc->ih) { 19559816Smdodd bus_teardown_intr(dev, sc->irq, sc->ih); 19659816Smdodd sc->ih = NULL; 19752286Smdodd } 19852286Smdodd 19959816Smdodd if (sc->ioport) { 20059816Smdodd bus_release_resource(dev, SYS_RES_IOPORT, 20159816Smdodd sc->ioport_rid, sc->ioport); 20259816Smdodd sc->ioport = NULL; 20352286Smdodd } 20452286Smdodd 20559816Smdodd if (sc->irq) { 20659816Smdodd bus_release_resource(dev, SYS_RES_IRQ, 20759816Smdodd sc->irq_rid, sc->irq); 20859816Smdodd sc->irq = NULL; 20957989Smdodd } 21057989Smdodd 21159816Smdodd return; 21252286Smdodd} 21352286Smdodd 21459816Smdoddint 21559816Smdoddex_attach(device_t dev) 21652286Smdodd{ 21752286Smdodd struct ex_softc * sc = device_get_softc(dev); 21852286Smdodd struct ifnet * ifp = &sc->arpcom.ac_if; 21957987Smdodd struct ifmedia * ifm; 22052286Smdodd int unit = device_get_unit(dev); 22157987Smdodd u_int16_t temp; 22252286Smdodd 22329877Smsmith /* work out which set of irq <-> internal tables to use */ 22452286Smdodd if (ex_card_type(sc->arpcom.ac_enaddr) == CARD_TYPE_EX_10_PLUS) { 22529877Smsmith sc->irq2ee = plus_irq2eemap; 22629877Smsmith sc->ee2irq = plus_ee2irqmap; 22752286Smdodd } else { 22829877Smsmith sc->irq2ee = irq2eemap; 22929877Smsmith sc->ee2irq = ee2irqmap; 23029877Smsmith } 23129877Smsmith 23221769Sjkh sc->mem_size = CARD_RAM_SIZE; /* XXX This should be read from the card itself. */ 23321769Sjkh 23421769Sjkh /* 23521769Sjkh * Initialize the ifnet structure. 23621769Sjkh */ 23721769Sjkh ifp->if_softc = sc; 23821769Sjkh ifp->if_unit = unit; 23921769Sjkh ifp->if_name = "ex"; 24055883Smdodd ifp->if_mtu = ETHERMTU; 241112731Smdodd ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST; 24221769Sjkh ifp->if_output = ether_output; 24321769Sjkh ifp->if_start = ex_start; 24421769Sjkh ifp->if_ioctl = ex_ioctl; 24521769Sjkh ifp->if_watchdog = ex_watchdog; 24655883Smdodd ifp->if_init = ex_init; 24755883Smdodd ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 24821769Sjkh 24957987Smdodd ifmedia_init(&sc->ifmedia, 0, ex_ifmedia_upd, ex_ifmedia_sts); 25057987Smdodd 25157987Smdodd temp = eeprom_read(sc->iobase, EE_W5); 25257987Smdodd if (temp & EE_W5_PORT_TPE) 25357987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL); 25457987Smdodd if (temp & EE_W5_PORT_BNC) 25557987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL); 25657987Smdodd if (temp & EE_W5_PORT_AUI) 25757987Smdodd ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL); 25857987Smdodd 25957987Smdodd ifmedia_set(&sc->ifmedia, ex_get_media(sc->iobase)); 26057987Smdodd 26157987Smdodd ifm = &sc->ifmedia; 26257987Smdodd ifm->ifm_media = ifm->ifm_cur->ifm_media; 26357987Smdodd ex_ifmedia_upd(ifp); 26457987Smdodd 26521769Sjkh /* 26621769Sjkh * Attach the interface. 26721769Sjkh */ 268106937Ssam ether_ifattach(ifp, sc->arpcom.ac_enaddr); 26921769Sjkh 27055883Smdodd device_printf(sc->dev, "Ethernet address %6D\n", 27155883Smdodd sc->arpcom.ac_enaddr, ":"); 27252286Smdodd 27352286Smdodd return(0); 27421769Sjkh} 27521769Sjkh 27655883Smdoddstatic void 27755883Smdoddex_init(void *xsc) 27821769Sjkh{ 27952286Smdodd struct ex_softc * sc = (struct ex_softc *) xsc; 28052286Smdodd struct ifnet * ifp = &sc->arpcom.ac_if; 28152286Smdodd int s; 28252286Smdodd int i; 28352286Smdodd register int iobase = sc->iobase; 28452286Smdodd unsigned short temp_reg; 28521769Sjkh 28621769Sjkh DODEBUG(Start_End, printf("ex_init%d: start\n", ifp->if_unit);); 28721769Sjkh 28871999Sphk if (TAILQ_FIRST(&ifp->if_addrhead) == NULL) { 28952286Smdodd return; 29052286Smdodd } 29121769Sjkh s = splimp(); 29259816Smdodd ifp->if_timer = 0; 29321769Sjkh 29421769Sjkh /* 29521769Sjkh * Load the ethernet address into the card. 29621769Sjkh */ 29721769Sjkh outb(iobase + CMD_REG, Bank2_Sel); 29821769Sjkh temp_reg = inb(iobase + EEPROM_REG); 29952286Smdodd if (temp_reg & Trnoff_Enable) { 30052286Smdodd outb(iobase + EEPROM_REG, temp_reg & ~Trnoff_Enable); 30152286Smdodd } 30252286Smdodd for (i = 0; i < ETHER_ADDR_LEN; i++) { 30352286Smdodd outb(iobase + I_ADDR_REG0 + i, sc->arpcom.ac_enaddr[i]); 30452286Smdodd } 30521769Sjkh /* 30621769Sjkh * - Setup transmit chaining and discard bad received frames. 30721769Sjkh * - Match broadcast. 30821769Sjkh * - Clear test mode. 30921769Sjkh * - Set receiving mode. 31021769Sjkh * - Set IRQ number. 31121769Sjkh */ 31221769Sjkh outb(iobase + REG1, inb(iobase + REG1) | Tx_Chn_Int_Md | Tx_Chn_ErStp | Disc_Bad_Fr); 31321769Sjkh outb(iobase + REG2, inb(iobase + REG2) | No_SA_Ins | RX_CRC_InMem); 31426545Sgibbs outb(iobase + REG3, inb(iobase + REG3) & 0x3f /* XXX constants. */ ); 31521769Sjkh outb(iobase + CMD_REG, Bank1_Sel); 31629877Smsmith outb(iobase + INT_NO_REG, (inb(iobase + INT_NO_REG) & 0xf8) | sc->irq2ee[sc->irq_no]); 31721769Sjkh 31821769Sjkh /* 31921769Sjkh * Divide the available memory in the card into rcv and xmt buffers. 32021769Sjkh * By default, I use the first 3/4 of the memory for the rcv buffer, 32121769Sjkh * and the remaining 1/4 of the memory for the xmt buffer. 32221769Sjkh */ 32321769Sjkh sc->rx_mem_size = sc->mem_size * 3 / 4; 32421769Sjkh sc->tx_mem_size = sc->mem_size - sc->rx_mem_size; 32521769Sjkh sc->rx_lower_limit = 0x0000; 32621769Sjkh sc->rx_upper_limit = sc->rx_mem_size - 2; 32721769Sjkh sc->tx_lower_limit = sc->rx_mem_size; 32821769Sjkh sc->tx_upper_limit = sc->mem_size - 2; 32921769Sjkh outb(iobase + RCV_LOWER_LIMIT_REG, sc->rx_lower_limit >> 8); 33021769Sjkh outb(iobase + RCV_UPPER_LIMIT_REG, sc->rx_upper_limit >> 8); 33121769Sjkh outb(iobase + XMT_LOWER_LIMIT_REG, sc->tx_lower_limit >> 8); 33221769Sjkh outb(iobase + XMT_UPPER_LIMIT_REG, sc->tx_upper_limit >> 8); 33321769Sjkh 33421769Sjkh /* 33521769Sjkh * Enable receive and transmit interrupts, and clear any pending int. 33621769Sjkh */ 33721769Sjkh outb(iobase + REG1, inb(iobase + REG1) | TriST_INT); 33821769Sjkh outb(iobase + CMD_REG, Bank0_Sel); 33921769Sjkh outb(iobase + MASK_REG, All_Int & ~(Rx_Int | Tx_Int)); 34021769Sjkh outb(iobase + STATUS_REG, All_Int); 34121769Sjkh 34221769Sjkh /* 34321769Sjkh * Initialize receive and transmit ring buffers. 34421769Sjkh */ 34521769Sjkh outw(iobase + RCV_BAR, sc->rx_lower_limit); 34621769Sjkh sc->rx_head = sc->rx_lower_limit; 34726545Sgibbs outw(iobase + RCV_STOP_REG, sc->rx_upper_limit | 0xfe); 34821769Sjkh outw(iobase + XMT_BAR, sc->tx_lower_limit); 34921769Sjkh sc->tx_head = sc->tx_tail = sc->tx_lower_limit; 35021769Sjkh 35121769Sjkh ifp->if_flags |= IFF_RUNNING; 35221769Sjkh ifp->if_flags &= ~IFF_OACTIVE; 35321769Sjkh DODEBUG(Status, printf("OIDLE init\n");); 35421769Sjkh 355112731Smdodd ex_setmulti(sc); 356112731Smdodd 35721769Sjkh /* 35821769Sjkh * Final reset of the board, and enable operation. 35921769Sjkh */ 36021769Sjkh outb(iobase + CMD_REG, Sel_Reset_CMD); 36121769Sjkh DELAY(2); 36221769Sjkh outb(iobase + CMD_REG, Rcv_Enable_CMD); 36321769Sjkh 36421769Sjkh ex_start(ifp); 36521769Sjkh splx(s); 36621769Sjkh 36721769Sjkh DODEBUG(Start_End, printf("ex_init%d: finish\n", ifp->if_unit);); 36821769Sjkh} 36921769Sjkh 37021769Sjkh 37155883Smdoddstatic void 37252286Smdoddex_start(struct ifnet *ifp) 37321769Sjkh{ 37452286Smdodd struct ex_softc * sc = ifp->if_softc; 37552286Smdodd int iobase = sc->iobase; 37652286Smdodd int i, s, len, data_len, avail, dest, next; 37752286Smdodd unsigned char tmp16[2]; 37852286Smdodd struct mbuf * opkt; 37952286Smdodd struct mbuf * m; 38021769Sjkh 38152286Smdodd DODEBUG(Start_End, printf("ex_start%d: start\n", unit);); 38221769Sjkh 38352286Smdodd s = splimp(); 38421769Sjkh 38552286Smdodd /* 38652286Smdodd * Main loop: send outgoing packets to network card until there are no 38752286Smdodd * more packets left, or the card cannot accept any more yet. 38852286Smdodd */ 38952286Smdodd while (((opkt = ifp->if_snd.ifq_head) != NULL) && 39052286Smdodd !(ifp->if_flags & IFF_OACTIVE)) { 39121769Sjkh 39252286Smdodd /* 39352286Smdodd * Ensure there is enough free transmit buffer space for 39452286Smdodd * this packet, including its header. Note: the header 39552286Smdodd * cannot wrap around the end of the transmit buffer and 39652286Smdodd * must be kept together, so we allow space for twice the 39752286Smdodd * length of the header, just in case. 39852286Smdodd */ 39921769Sjkh 40052286Smdodd for (len = 0, m = opkt; m != NULL; m = m->m_next) { 40152286Smdodd len += m->m_len; 40252286Smdodd } 40352286Smdodd 40452286Smdodd data_len = len; 40552286Smdodd 40652286Smdodd DODEBUG(Sent_Pkts, printf("1. Sending packet with %d data bytes. ", data_len);); 40752286Smdodd 40852286Smdodd if (len & 1) { 40952286Smdodd len += XMT_HEADER_LEN + 1; 41052286Smdodd } else { 41152286Smdodd len += XMT_HEADER_LEN; 41252286Smdodd } 41352286Smdodd 41452286Smdodd if ((i = sc->tx_tail - sc->tx_head) >= 0) { 41552286Smdodd avail = sc->tx_mem_size - i; 41652286Smdodd } else { 41752286Smdodd avail = -i; 41852286Smdodd } 41952286Smdodd 42052286Smdodd DODEBUG(Sent_Pkts, printf("i=%d, avail=%d\n", i, avail);); 42152286Smdodd 42252286Smdodd if (avail >= len + XMT_HEADER_LEN) { 42352286Smdodd IF_DEQUEUE(&ifp->if_snd, opkt); 42452286Smdodd 42521769Sjkh#ifdef EX_PSA_INTR 42652286Smdodd /* 42752286Smdodd * Disable rx and tx interrupts, to avoid corruption 42852286Smdodd * of the host address register by interrupt service 42952286Smdodd * routines. 43052286Smdodd * XXX Is this necessary with splimp() enabled? 43152286Smdodd */ 43252286Smdodd outb(iobase + MASK_REG, All_Int); 43321769Sjkh#endif 43421769Sjkh 43552286Smdodd /* 43652286Smdodd * Compute the start and end addresses of this 43752286Smdodd * frame in the tx buffer. 43852286Smdodd */ 43952286Smdodd dest = sc->tx_tail; 44052286Smdodd next = dest + len; 44121769Sjkh 44252286Smdodd if (next > sc->tx_upper_limit) { 44352286Smdodd if ((sc->tx_upper_limit + 2 - sc->tx_tail) <= 44452286Smdodd XMT_HEADER_LEN) { 44552286Smdodd dest = sc->tx_lower_limit; 44652286Smdodd next = dest + len; 44755881Smdodd } else { 44855881Smdodd next = sc->tx_lower_limit + 44955881Smdodd next - sc->tx_upper_limit - 2; 45052286Smdodd } 45152286Smdodd } 45221769Sjkh 45352286Smdodd /* 45452286Smdodd * Build the packet frame in the card's ring buffer. 45552286Smdodd */ 45652286Smdodd DODEBUG(Sent_Pkts, printf("2. dest=%d, next=%d. ", dest, next);); 45721769Sjkh 45852286Smdodd outw(iobase + HOST_ADDR_REG, dest); 45952286Smdodd outw(iobase + IO_PORT_REG, Transmit_CMD); 46052286Smdodd outw(iobase + IO_PORT_REG, 0); 46152286Smdodd outw(iobase + IO_PORT_REG, next); 46252286Smdodd outw(iobase + IO_PORT_REG, data_len); 46321769Sjkh 46452286Smdodd /* 46552286Smdodd * Output the packet data to the card. Ensure all 46652286Smdodd * transfers are 16-bit wide, even if individual 46752286Smdodd * mbufs have odd length. 46852286Smdodd */ 46921769Sjkh 47052286Smdodd for (m = opkt, i = 0; m != NULL; m = m->m_next) { 47152286Smdodd DODEBUG(Sent_Pkts, printf("[%d]", m->m_len);); 47252286Smdodd if (i) { 47352286Smdodd tmp16[1] = *(mtod(m, caddr_t)); 47452286Smdodd outsw(iobase + IO_PORT_REG, tmp16, 1); 47552286Smdodd } 47652286Smdodd outsw(iobase + IO_PORT_REG, 47752286Smdodd mtod(m, caddr_t) + i, (m->m_len - i) / 2); 47852286Smdodd 47952286Smdodd if ((i = (m->m_len - i) & 1) != 0) { 48052286Smdodd tmp16[0] = *(mtod(m, caddr_t) + 48152286Smdodd m->m_len - 1); 48252286Smdodd } 48352286Smdodd } 48452286Smdodd if (i) { 48552286Smdodd outsw(iobase + IO_PORT_REG, tmp16, 1); 48655881Smdodd } 48752286Smdodd 48855881Smdodd /* 48955881Smdodd * If there were other frames chained, update the 49055881Smdodd * chain in the last one. 49155881Smdodd */ 49255881Smdodd if (sc->tx_head != sc->tx_tail) { 49355881Smdodd if (sc->tx_tail != dest) { 49452286Smdodd outw(iobase + HOST_ADDR_REG, 49555881Smdodd sc->tx_last + XMT_Chain_Point); 49655881Smdodd outw(iobase + IO_PORT_REG, dest); 49752286Smdodd } 49855881Smdodd outw(iobase + HOST_ADDR_REG, 49955881Smdodd sc->tx_last + XMT_Byte_Count); 50055881Smdodd i = inw(iobase + IO_PORT_REG); 50155881Smdodd outw(iobase + HOST_ADDR_REG, 50255881Smdodd sc->tx_last + XMT_Byte_Count); 50355881Smdodd outw(iobase + IO_PORT_REG, i | Ch_bit); 50455881Smdodd } 50555881Smdodd 50655881Smdodd /* 50755881Smdodd * Resume normal operation of the card: 50855881Smdodd * - Make a dummy read to flush the DRAM write 50955881Smdodd * pipeline. 51055881Smdodd * - Enable receive and transmit interrupts. 51155881Smdodd * - Send Transmit or Resume_XMT command, as 51255881Smdodd * appropriate. 51355881Smdodd */ 51455881Smdodd inw(iobase + IO_PORT_REG); 51521769Sjkh#ifdef EX_PSA_INTR 51655881Smdodd outb(iobase + MASK_REG, All_Int & ~(Rx_Int | Tx_Int)); 51721769Sjkh#endif 51855881Smdodd if (sc->tx_head == sc->tx_tail) { 51955881Smdodd outw(iobase + XMT_BAR, dest); 52055881Smdodd outb(iobase + CMD_REG, Transmit_CMD); 52155881Smdodd sc->tx_head = dest; 52255881Smdodd DODEBUG(Sent_Pkts, printf("Transmit\n");); 52352286Smdodd } else { 52455881Smdodd outb(iobase + CMD_REG, Resume_XMT_List_CMD); 52555881Smdodd DODEBUG(Sent_Pkts, printf("Resume\n");); 52652286Smdodd } 52755881Smdodd 52855881Smdodd sc->tx_last = dest; 52955881Smdodd sc->tx_tail = next; 53055881Smdodd 531106937Ssam BPF_MTAP(ifp, opkt); 53255881Smdodd 53355881Smdodd ifp->if_timer = 2; 53455881Smdodd ifp->if_opackets++; 53555881Smdodd m_freem(opkt); 53655881Smdodd } else { 53755881Smdodd ifp->if_flags |= IFF_OACTIVE; 53855881Smdodd DODEBUG(Status, printf("OACTIVE start\n");); 53952286Smdodd } 54021769Sjkh } 54121769Sjkh 54252286Smdodd splx(s); 54321769Sjkh 54452286Smdodd DODEBUG(Start_End, printf("ex_start%d: finish\n", unit);); 54521769Sjkh} 54621769Sjkh 54766440Simpvoid 54852286Smdoddex_stop(struct ex_softc *sc) 54921769Sjkh{ 55052286Smdodd int iobase = sc->iobase; 55121769Sjkh 55252286Smdodd DODEBUG(Start_End, printf("ex_stop%d: start\n", unit);); 55321769Sjkh 55452286Smdodd /* 55552286Smdodd * Disable card operation: 55652286Smdodd * - Disable the interrupt line. 55752286Smdodd * - Flush transmission and disable reception. 55852286Smdodd * - Mask and clear all interrupts. 55952286Smdodd * - Reset the 82595. 56052286Smdodd */ 56152286Smdodd outb(iobase + CMD_REG, Bank1_Sel); 56252286Smdodd outb(iobase + REG1, inb(iobase + REG1) & ~TriST_INT); 56352286Smdodd outb(iobase + CMD_REG, Bank0_Sel); 56452286Smdodd outb(iobase + CMD_REG, Rcv_Stop); 56552286Smdodd sc->tx_head = sc->tx_tail = sc->tx_lower_limit; 56652286Smdodd 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. */ 56752286Smdodd outb(iobase + MASK_REG, All_Int); 56852286Smdodd outb(iobase + STATUS_REG, All_Int); 56952286Smdodd outb(iobase + CMD_REG, Reset_CMD); 57052286Smdodd DELAY(200); 57121769Sjkh 57252286Smdodd DODEBUG(Start_End, printf("ex_stop%d: finish\n", unit);); 57352286Smdodd 57452286Smdodd return; 57521769Sjkh} 57621769Sjkh 57759816Smdoddvoid 57855883Smdoddex_intr(void *arg) 57921769Sjkh{ 58052286Smdodd struct ex_softc * sc = (struct ex_softc *)arg; 58152286Smdodd struct ifnet * ifp = &sc->arpcom.ac_if; 58252286Smdodd int iobase = sc->iobase; 58352286Smdodd int int_status, send_pkts; 58421769Sjkh 58555883Smdodd DODEBUG(Start_End, printf("ex_intr%d: start\n", unit);); 58621769Sjkh 58721769Sjkh#ifdef EXDEBUG 58821769Sjkh if (++exintr_count != 1) 58921769Sjkh printf("WARNING: nested interrupt (%d). Mail the author.\n", exintr_count); 59021769Sjkh#endif 59121769Sjkh 59252286Smdodd send_pkts = 0; 59352286Smdodd while ((int_status = inb(iobase + STATUS_REG)) & (Tx_Int | Rx_Int)) { 59452286Smdodd if (int_status & Rx_Int) { 59552286Smdodd outb(iobase + STATUS_REG, Rx_Int); 59621769Sjkh 59752286Smdodd ex_rx_intr(sc); 59852286Smdodd } else if (int_status & Tx_Int) { 59952286Smdodd outb(iobase + STATUS_REG, Tx_Int); 60021769Sjkh 60152286Smdodd ex_tx_intr(sc); 60252286Smdodd send_pkts = 1; 60352286Smdodd } 60452286Smdodd } 60521769Sjkh 60652286Smdodd /* 60752286Smdodd * If any packet has been transmitted, and there are queued packets to 60852286Smdodd * be sent, attempt to send more packets to the network card. 60952286Smdodd */ 61052286Smdodd 61152286Smdodd if (send_pkts && (ifp->if_snd.ifq_head != NULL)) { 61252286Smdodd ex_start(ifp); 61352286Smdodd } 61452286Smdodd 61521769Sjkh#ifdef EXDEBUG 61621769Sjkh exintr_count--; 61721769Sjkh#endif 61821769Sjkh 61955883Smdodd DODEBUG(Start_End, printf("ex_intr%d: finish\n", unit);); 62052286Smdodd 62152286Smdodd return; 62221769Sjkh} 62321769Sjkh 62452286Smdoddstatic void 62552286Smdoddex_tx_intr(struct ex_softc *sc) 62621769Sjkh{ 62752286Smdodd struct ifnet * ifp = &sc->arpcom.ac_if; 62852286Smdodd int iobase = sc->iobase; 62952286Smdodd int tx_status; 63021769Sjkh 63152286Smdodd DODEBUG(Start_End, printf("ex_tx_intr%d: start\n", unit);); 63221769Sjkh 63352286Smdodd /* 63452286Smdodd * - Cancel the watchdog. 63552286Smdodd * For all packets transmitted since last transmit interrupt: 63652286Smdodd * - Advance chain pointer to next queued packet. 63752286Smdodd * - Update statistics. 63852286Smdodd */ 63921769Sjkh 64052286Smdodd ifp->if_timer = 0; 64121769Sjkh 64252286Smdodd while (sc->tx_head != sc->tx_tail) { 64352286Smdodd outw(iobase + HOST_ADDR_REG, sc->tx_head); 64421769Sjkh 64552286Smdodd if (! inw(iobase + IO_PORT_REG) & Done_bit) 64652286Smdodd break; 64721769Sjkh 64852286Smdodd tx_status = inw(iobase + IO_PORT_REG); 64952286Smdodd sc->tx_head = inw(iobase + IO_PORT_REG); 65052286Smdodd 65152286Smdodd if (tx_status & TX_OK_bit) { 65252286Smdodd ifp->if_opackets++; 65352286Smdodd } else { 65452286Smdodd ifp->if_oerrors++; 65552286Smdodd } 65652286Smdodd 65752286Smdodd ifp->if_collisions += tx_status & No_Collisions_bits; 65852286Smdodd } 65952286Smdodd 66052286Smdodd /* 66152286Smdodd * The card should be ready to accept more packets now. 66252286Smdodd */ 66352286Smdodd 66452286Smdodd ifp->if_flags &= ~IFF_OACTIVE; 66552286Smdodd 66652286Smdodd DODEBUG(Status, printf("OIDLE tx_intr\n");); 66752286Smdodd DODEBUG(Start_End, printf("ex_tx_intr%d: finish\n", unit);); 66852286Smdodd 66952286Smdodd return; 67021769Sjkh} 67121769Sjkh 67252286Smdoddstatic void 67352286Smdoddex_rx_intr(struct ex_softc *sc) 67421769Sjkh{ 67552286Smdodd struct ifnet * ifp = &sc->arpcom.ac_if; 67652286Smdodd int iobase = sc->iobase; 67752286Smdodd int rx_status; 67852286Smdodd int pkt_len; 67952286Smdodd int QQQ; 68052286Smdodd struct mbuf * m; 68152286Smdodd struct mbuf * ipkt; 68252286Smdodd struct ether_header * eh; 68321769Sjkh 68452286Smdodd DODEBUG(Start_End, printf("ex_rx_intr%d: start\n", unit);); 68521769Sjkh 68652286Smdodd /* 68752286Smdodd * For all packets received since last receive interrupt: 68852286Smdodd * - If packet ok, read it into a new mbuf and queue it to interface, 68952286Smdodd * updating statistics. 69052286Smdodd * - If packet bad, just discard it, and update statistics. 69152286Smdodd * Finally, advance receive stop limit in card's memory to new location. 69252286Smdodd */ 69321769Sjkh 69452286Smdodd outw(iobase + HOST_ADDR_REG, sc->rx_head); 69521769Sjkh 69652286Smdodd while (inw(iobase + IO_PORT_REG) == RCV_Done) { 69752286Smdodd 69852286Smdodd rx_status = inw(iobase + IO_PORT_REG); 69952286Smdodd sc->rx_head = inw(iobase + IO_PORT_REG); 70052286Smdodd QQQ = pkt_len = inw(iobase + IO_PORT_REG); 70152286Smdodd 70252286Smdodd if (rx_status & RCV_OK_bit) { 703111119Simp MGETHDR(m, M_DONTWAIT, MT_DATA); 70452286Smdodd ipkt = m; 70552286Smdodd if (ipkt == NULL) { 70652286Smdodd ifp->if_iqdrops++; 70752286Smdodd } else { 70852286Smdodd ipkt->m_pkthdr.rcvif = ifp; 70952286Smdodd ipkt->m_pkthdr.len = pkt_len; 71052286Smdodd ipkt->m_len = MHLEN; 71152286Smdodd 71252286Smdodd while (pkt_len > 0) { 71352286Smdodd if (pkt_len > MINCLSIZE) { 714111119Simp MCLGET(m, M_DONTWAIT); 71552286Smdodd if (m->m_flags & M_EXT) { 71652286Smdodd m->m_len = MCLBYTES; 71752286Smdodd } else { 71852286Smdodd m_freem(ipkt); 71952286Smdodd ifp->if_iqdrops++; 72052286Smdodd goto rx_another; 72152286Smdodd } 72252286Smdodd } 72352286Smdodd m->m_len = min(m->m_len, pkt_len); 72452286Smdodd 72521769Sjkh /* 72621769Sjkh * NOTE: I'm assuming that all mbufs allocated are of even length, 72721769Sjkh * except for the last one in an odd-length packet. 72821769Sjkh */ 72952286Smdodd 73052286Smdodd insw(iobase + IO_PORT_REG, 73152286Smdodd mtod(m, caddr_t), m->m_len / 2); 73252286Smdodd 73352286Smdodd if (m->m_len & 1) { 73452286Smdodd *(mtod(m, caddr_t) + m->m_len - 1) = inb(iobase + IO_PORT_REG); 73552286Smdodd } 73652286Smdodd pkt_len -= m->m_len; 73752286Smdodd 73852286Smdodd if (pkt_len > 0) { 739111119Simp MGET(m->m_next, M_DONTWAIT, MT_DATA); 74052286Smdodd if (m->m_next == NULL) { 74152286Smdodd m_freem(ipkt); 74252286Smdodd ifp->if_iqdrops++; 74352286Smdodd goto rx_another; 74452286Smdodd } 74552286Smdodd m = m->m_next; 74652286Smdodd m->m_len = MLEN; 74752286Smdodd } 74852286Smdodd } 74952286Smdodd eh = mtod(ipkt, struct ether_header *); 75052286Smdodd#ifdef EXDEBUG 75152286Smdodd if (debug_mask & Rcvd_Pkts) { 75252286Smdodd if ((eh->ether_dhost[5] != 0xff) || (eh->ether_dhost[0] != 0xff)) { 75352286Smdodd printf("Receive packet with %d data bytes: %6D -> ", QQQ, eh->ether_shost, ":"); 75452286Smdodd printf("%6D\n", eh->ether_dhost, ":"); 75552286Smdodd } /* QQQ */ 75621769Sjkh } 75721769Sjkh#endif 758106937Ssam (*ifp->if_input)(ifp, ipkt); 75952286Smdodd ifp->if_ipackets++; 76052286Smdodd } 76152286Smdodd } else { 76252286Smdodd ifp->if_ierrors++; 76321769Sjkh } 76452286Smdodd outw(iobase + HOST_ADDR_REG, sc->rx_head); 76552286Smdoddrx_another: ; 76621769Sjkh } 76721769Sjkh 76852286Smdodd if (sc->rx_head < sc->rx_lower_limit + 2) 76952286Smdodd outw(iobase + RCV_STOP_REG, sc->rx_upper_limit); 77052286Smdodd else 77152286Smdodd outw(iobase + RCV_STOP_REG, sc->rx_head - 2); 77252286Smdodd 77352286Smdodd DODEBUG(Start_End, printf("ex_rx_intr%d: finish\n", unit);); 77452286Smdodd 77552286Smdodd return; 77621769Sjkh} 77721769Sjkh 77821769Sjkh 77955883Smdoddstatic int 78055883Smdoddex_ioctl(register struct ifnet *ifp, u_long cmd, caddr_t data) 78121769Sjkh{ 78252286Smdodd struct ex_softc * sc = ifp->if_softc; 78357987Smdodd struct ifreq * ifr = (struct ifreq *)data; 78452286Smdodd int s; 78552286Smdodd int error = 0; 78621769Sjkh 78752286Smdodd DODEBUG(Start_End, printf("ex_ioctl%d: start ", ifp->if_unit);); 78821769Sjkh 78952286Smdodd s = splimp(); 79021769Sjkh 79152286Smdodd switch(cmd) { 79252286Smdodd case SIOCSIFADDR: 79352286Smdodd case SIOCGIFADDR: 79452286Smdodd case SIOCSIFMTU: 79552286Smdodd error = ether_ioctl(ifp, cmd, data); 79652286Smdodd break; 79721769Sjkh 79852286Smdodd case SIOCSIFFLAGS: 79952286Smdodd DODEBUG(Start_End, printf("SIOCSIFFLAGS");); 80052286Smdodd if ((ifp->if_flags & IFF_UP) == 0 && 80152286Smdodd (ifp->if_flags & IFF_RUNNING)) { 80252286Smdodd 80352286Smdodd ifp->if_flags &= ~IFF_RUNNING; 80452286Smdodd ex_stop(sc); 80552286Smdodd } else { 80652286Smdodd ex_init(sc); 80752286Smdodd } 80852286Smdodd break; 80921769Sjkh#ifdef NODEF 81052286Smdodd case SIOCGHWADDR: 81152286Smdodd DODEBUG(Start_End, printf("SIOCGHWADDR");); 81252286Smdodd bcopy((caddr_t)sc->sc_addr, (caddr_t)&ifr->ifr_data, 81352286Smdodd sizeof(sc->sc_addr)); 81452286Smdodd break; 81521769Sjkh#endif 81652286Smdodd case SIOCADDMULTI: 81752286Smdodd case SIOCDELMULTI: 818112731Smdodd ex_init(sc); 819112731Smdodd error = 0; 82052286Smdodd break; 82157987Smdodd case SIOCSIFMEDIA: 82257987Smdodd case SIOCGIFMEDIA: 82357987Smdodd error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd); 82457987Smdodd break; 82552286Smdodd default: 82652286Smdodd DODEBUG(Start_End, printf("unknown");); 82752286Smdodd error = EINVAL; 82852286Smdodd } 82921769Sjkh 83052286Smdodd splx(s); 83121769Sjkh 83252286Smdodd DODEBUG(Start_End, printf("\nex_ioctl%d: finish\n", ifp->if_unit);); 83352286Smdodd 83452286Smdodd return(error); 83521769Sjkh} 83621769Sjkh 837112731Smdoddstatic void 838112731Smdoddex_setmulti(struct ex_softc *sc) 839112731Smdodd{ 840112731Smdodd struct ifnet *ifp; 841112731Smdodd struct ifmultiaddr *maddr; 842112731Smdodd u_int16_t *addr; 843112731Smdodd int iobase = sc->iobase; 844112731Smdodd int count; 845112731Smdodd int timeout, status; 846112731Smdodd 847112731Smdodd ifp = &sc->arpcom.ac_if; 84821769Sjkh 849112731Smdodd count = 0; 850112731Smdodd TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) { 851112731Smdodd if (maddr->ifma_addr->sa_family != AF_LINK) 852112731Smdodd continue; 853112731Smdodd count++; 854112731Smdodd } 855112731Smdodd 856112731Smdodd if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI) 857112731Smdodd || count > 63) { 858112731Smdodd /* Interface is in promiscuous mode or there are too many 859112731Smdodd * multicast addresses for the card to handle */ 860112731Smdodd outb(iobase + CMD_REG, Bank2_Sel); 861112731Smdodd outb(iobase + REG2, inb(iobase + REG2) | Promisc_Mode); 862112731Smdodd outb(iobase + REG3, inb(iobase + REG3)); 863112731Smdodd outb(iobase + CMD_REG, Bank0_Sel); 864112731Smdodd } 865112731Smdodd else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) { 866112731Smdodd /* Program multicast addresses plus our MAC address 867112731Smdodd * into the filter */ 868112731Smdodd outb(iobase + CMD_REG, Bank2_Sel); 869112731Smdodd outb(iobase + REG2, inb(iobase + REG2) | Multi_IA); 870112731Smdodd outb(iobase + REG3, inb(iobase + REG3)); 871112731Smdodd outb(iobase + CMD_REG, Bank0_Sel); 872112731Smdodd 873112731Smdodd /* Borrow space from TX buffer; this should be safe 874112731Smdodd * as this is only called from ex_init */ 875112731Smdodd 876112731Smdodd outw(iobase + HOST_ADDR_REG, sc->tx_lower_limit); 877112731Smdodd outw(iobase + IO_PORT_REG, MC_Setup_CMD); 878112731Smdodd outw(iobase + IO_PORT_REG, 0); 879112731Smdodd outw(iobase + IO_PORT_REG, 0); 880112731Smdodd outw(iobase + IO_PORT_REG, (count + 1) * 6); 881112731Smdodd 882112731Smdodd TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) { 883112731Smdodd if (maddr->ifma_addr->sa_family != AF_LINK) 884112731Smdodd continue; 885112731Smdodd 886112731Smdodd addr = (u_int16_t*)LLADDR((struct sockaddr_dl *) 887112731Smdodd maddr->ifma_addr); 888112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 889112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 890112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 891112731Smdodd } 892112731Smdodd 893112731Smdodd /* Program our MAC address as well */ 894112731Smdodd /* XXX: Is this necessary? The Linux driver does this 895112731Smdodd * but the NetBSD driver does not */ 896112731Smdodd addr = (u_int16_t*)(&sc->arpcom.ac_enaddr); 897112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 898112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 899112731Smdodd outw(iobase + IO_PORT_REG, *addr++); 900112731Smdodd 901112731Smdodd inw(iobase + IO_PORT_REG); 902112731Smdodd outw(iobase + XMT_BAR, sc->tx_lower_limit); 903112731Smdodd outb(iobase + CMD_REG, MC_Setup_CMD); 904112731Smdodd 905112731Smdodd sc->tx_head = sc->tx_lower_limit; 906112731Smdodd sc->tx_tail = sc->tx_head + XMT_HEADER_LEN + (count + 1) * 6; 907112731Smdodd 908112731Smdodd for (timeout=0; timeout<100; timeout++) { 909112731Smdodd DELAY(2); 910112731Smdodd if ((inb(iobase + STATUS_REG) & Exec_Int) == 0) 911112731Smdodd continue; 912112731Smdodd 913112731Smdodd status = inb(iobase + CMD_REG); 914112731Smdodd outb(iobase + STATUS_REG, Exec_Int); 915112731Smdodd break; 916112731Smdodd } 917112731Smdodd 918112731Smdodd sc->tx_head = sc->tx_tail; 919112731Smdodd } 920112731Smdodd else 921112731Smdodd { 922112731Smdodd /* No multicast or promiscuous mode */ 923112731Smdodd outb(iobase + CMD_REG, Bank2_Sel); 924112731Smdodd outb(iobase + REG2, inb(iobase + REG2) & 0xDE); 925112731Smdodd /* ~(Multi_IA | Promisc_Mode) */ 926112731Smdodd outb(iobase + REG3, inb(iobase + REG3)); 927112731Smdodd outb(iobase + CMD_REG, Bank0_Sel); 928112731Smdodd } 929112731Smdodd} 930112731Smdodd 93152286Smdoddstatic void 93252286Smdoddex_reset(struct ex_softc *sc) 93321769Sjkh{ 93452286Smdodd int s; 93521769Sjkh 93652286Smdodd DODEBUG(Start_End, printf("ex_reset%d: start\n", unit);); 93721769Sjkh 93852286Smdodd s = splimp(); 93921769Sjkh 94052286Smdodd ex_stop(sc); 94152286Smdodd ex_init(sc); 94221769Sjkh 94352286Smdodd splx(s); 94421769Sjkh 94552286Smdodd DODEBUG(Start_End, printf("ex_reset%d: finish\n", unit);); 94652286Smdodd 94752286Smdodd return; 94821769Sjkh} 94921769Sjkh 95052286Smdoddstatic void 95152286Smdoddex_watchdog(struct ifnet *ifp) 95221769Sjkh{ 95352286Smdodd struct ex_softc * sc = ifp->if_softc; 95421769Sjkh 95552286Smdodd DODEBUG(Start_End, printf("ex_watchdog%d: start\n", ifp->if_unit);); 95621769Sjkh 95752286Smdodd ifp->if_flags &= ~IFF_OACTIVE; 95821769Sjkh 95952286Smdodd DODEBUG(Status, printf("OIDLE watchdog\n");); 96052286Smdodd 96152286Smdodd ifp->if_oerrors++; 96252286Smdodd ex_reset(sc); 96352286Smdodd ex_start(ifp); 96452286Smdodd 96552286Smdodd DODEBUG(Start_End, printf("ex_watchdog%d: finish\n", ifp->if_unit);); 96652286Smdodd 96752286Smdodd return; 96821769Sjkh} 96921769Sjkh 97057987Smdoddstatic int 97159816Smdoddex_get_media (u_int32_t iobase) 97259816Smdodd{ 97359816Smdodd int tmp; 97459816Smdodd 97559816Smdodd outb(iobase + CMD_REG, Bank2_Sel); 97659816Smdodd tmp = inb(iobase + REG3); 97759816Smdodd outb(iobase + CMD_REG, Bank0_Sel); 97859816Smdodd 97959816Smdodd if (tmp & TPE_bit) 98059816Smdodd return(IFM_ETHER|IFM_10_T); 98159816Smdodd if (tmp & BNC_bit) 98259816Smdodd return(IFM_ETHER|IFM_10_2); 98359816Smdodd 98459816Smdodd return (IFM_ETHER|IFM_10_5); 98559816Smdodd} 98659816Smdodd 98759816Smdoddstatic int 98857987Smdoddex_ifmedia_upd (ifp) 98957987Smdodd struct ifnet * ifp; 99057987Smdodd{ 99121769Sjkh 99257987Smdodd return (0); 99357987Smdodd} 99457987Smdodd 99557987Smdoddstatic void 99657987Smdoddex_ifmedia_sts(ifp, ifmr) 99757987Smdodd struct ifnet * ifp; 99857987Smdodd struct ifmediareq * ifmr; 99957987Smdodd{ 100057987Smdodd struct ex_softc * sc = ifp->if_softc; 100157987Smdodd 100257987Smdodd ifmr->ifm_active = ex_get_media(sc->iobase); 100357987Smdodd 100457987Smdodd return; 100557987Smdodd} 100657987Smdodd 100759816Smdoddu_short 100859816Smdoddeeprom_read(u_int32_t iobase, int location) 100921769Sjkh{ 101021769Sjkh int i; 101121769Sjkh u_short data = 0; 101221769Sjkh int ee_addr; 101321769Sjkh int read_cmd = location | EE_READ_CMD; 101421769Sjkh short ctrl_val = EECS; 101521769Sjkh 101621769Sjkh ee_addr = iobase + EEPROM_REG; 101721769Sjkh outb(iobase + CMD_REG, Bank2_Sel); 101821769Sjkh outb(ee_addr, EECS); 101921769Sjkh for (i = 8; i >= 0; i--) { 102021769Sjkh short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI : ctrl_val; 102121769Sjkh outb(ee_addr, outval); 102221769Sjkh outb(ee_addr, outval | EESK); 102321769Sjkh DELAY(3); 102421769Sjkh outb(ee_addr, outval); 102521769Sjkh DELAY(2); 102621769Sjkh } 102721769Sjkh outb(ee_addr, ctrl_val); 102821769Sjkh 102921769Sjkh for (i = 16; i > 0; i--) { 103021769Sjkh outb(ee_addr, ctrl_val | EESK); 103121769Sjkh DELAY(3); 103221769Sjkh data = (data << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0); 103321769Sjkh outb(ee_addr, ctrl_val); 103421769Sjkh DELAY(2); 103521769Sjkh } 103621769Sjkh 103721769Sjkh ctrl_val &= ~EECS; 103821769Sjkh outb(ee_addr, ctrl_val | EESK); 103921769Sjkh DELAY(3); 104021769Sjkh outb(ee_addr, ctrl_val); 104121769Sjkh DELAY(2); 104221769Sjkh outb(iobase + CMD_REG, Bank0_Sel); 104321769Sjkh return(data); 104421769Sjkh} 1045