smc90cx6.c revision 127135
189099Sfjoe/* $NetBSD: smc90cx6.c,v 1.38 2001/07/07 15:57:53 thorpej Exp $ */ 289099Sfjoe 3119418Sobrien#include <sys/cdefs.h> 4119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/cm/smc90cx6.c 127135 2004-03-17 17:50:55Z njl $"); 5119418Sobrien 689099Sfjoe/*- 789099Sfjoe * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc. 889099Sfjoe * All rights reserved. 989099Sfjoe * 1089099Sfjoe * This code is derived from software contributed to The NetBSD Foundation 1189099Sfjoe * by Ignatios Souvatzis. 1289099Sfjoe * 1389099Sfjoe * Redistribution and use in source and binary forms, with or without 1489099Sfjoe * modification, are permitted provided that the following conditions 1589099Sfjoe * are met: 1689099Sfjoe * 1. Redistributions of source code must retain the above copyright 1789099Sfjoe * notice, this list of conditions and the following disclaimer. 1889099Sfjoe * 2. Redistributions in binary form must reproduce the above copyright 1989099Sfjoe * notice, this list of conditions and the following disclaimer in the 2089099Sfjoe * documentation and/or other materials provided with the distribution. 2189099Sfjoe * 3. All advertising materials mentioning features or use of this software 2289099Sfjoe * must display the following acknowledgement: 2389099Sfjoe * This product includes software developed by the NetBSD 2489099Sfjoe * Foundation, Inc. and its contributors. 2589099Sfjoe * 4. Neither the name of The NetBSD Foundation nor the names of its 2689099Sfjoe * contributors may be used to endorse or promote products derived 2789099Sfjoe * from this software without specific prior written permission. 2889099Sfjoe * 2989099Sfjoe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 3089099Sfjoe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 3189099Sfjoe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3289099Sfjoe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3389099Sfjoe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3489099Sfjoe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3589099Sfjoe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3689099Sfjoe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3789099Sfjoe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3889099Sfjoe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3989099Sfjoe * POSSIBILITY OF SUCH DAMAGE. 4089099Sfjoe */ 4189099Sfjoe 4289099Sfjoe/* 4389099Sfjoe * Chip core driver for the SMC90c26 / SMC90c56 (and SMC90c66 in '56 4489099Sfjoe * compatibility mode) boards 4589099Sfjoe */ 4689099Sfjoe 4789099Sfjoe/* #define CMSOFTCOPY */ 4889099Sfjoe#define CMRETRANSMIT /**/ 49109771Sfjoe/* #define CM_DEBUG */ 5089099Sfjoe 5189099Sfjoe#include <sys/param.h> 5289099Sfjoe#include <sys/systm.h> 5389099Sfjoe#include <sys/sockio.h> 5489099Sfjoe#include <sys/mbuf.h> 5589099Sfjoe#include <sys/module.h> 5689099Sfjoe#include <sys/kernel.h> 5789099Sfjoe#include <sys/socket.h> 5889099Sfjoe#include <sys/syslog.h> 5989099Sfjoe#include <sys/bus.h> 6089099Sfjoe 6189099Sfjoe#include <machine/bus.h> 6289099Sfjoe#include <sys/rman.h> 6389099Sfjoe#include <machine/resource.h> 6489099Sfjoe 6589099Sfjoe#if __FreeBSD_version < 500000 6689099Sfjoe#include <machine/clock.h> 6789099Sfjoe#endif 6889099Sfjoe 6989099Sfjoe#include <net/if.h> 7089099Sfjoe#include <net/if_dl.h> 7189099Sfjoe#include <net/if_types.h> 7289099Sfjoe#include <net/if_arc.h> 7389099Sfjoe 7489099Sfjoe#include <dev/cm/smc90cx6reg.h> 7589099Sfjoe#include <dev/cm/smc90cx6var.h> 7689099Sfjoe 7789099SfjoeMODULE_DEPEND(if_cm, arcnet, 1, 1, 1); 7889099Sfjoe 7989099Sfjoe/* these should be elsewhere */ 8089099Sfjoe 8189099Sfjoe#define ARC_MIN_LEN 1 8289099Sfjoe#define ARC_MIN_FORBID_LEN 254 8389099Sfjoe#define ARC_MAX_FORBID_LEN 256 8489099Sfjoe#define ARC_MAX_LEN 508 8589099Sfjoe#define ARC_ADDR_LEN 1 8689099Sfjoe 8789099Sfjoe/* for watchdog timer. This should be more than enough. */ 8889099Sfjoe#define ARCTIMEOUT (5*IFNET_SLOWHZ) 8989099Sfjoe 9089099Sfjoe/* short notation */ 9189099Sfjoe 9289099Sfjoe#define GETREG(off) \ 9389099Sfjoe bus_space_read_1(rman_get_bustag((sc)->port_res), \ 9489099Sfjoe rman_get_bushandle((sc)->port_res), \ 9589099Sfjoe (off)) 9689099Sfjoe#define PUTREG(off, value) \ 9789099Sfjoe bus_space_write_1(rman_get_bustag((sc)->port_res), \ 9889099Sfjoe rman_get_bushandle((sc)->port_res), \ 9989099Sfjoe (off), (value)) 10089099Sfjoe#define GETMEM(off) \ 10189099Sfjoe bus_space_read_1(rman_get_bustag((sc)->mem_res), \ 10289099Sfjoe rman_get_bushandle((sc)->mem_res), \ 10389099Sfjoe (off)) 10489099Sfjoe#define PUTMEM(off, value) \ 10589099Sfjoe bus_space_write_1(rman_get_bustag((sc)->mem_res), \ 10689099Sfjoe rman_get_bushandle((sc)->mem_res), \ 10789099Sfjoe (off), (value)) 10889099Sfjoe 10989099Sfjoedevclass_t cm_devclass; 11089099Sfjoe 11189099Sfjoe/* 11289099Sfjoe * This currently uses 2 bufs for tx, 2 for rx 11389099Sfjoe * 11489099Sfjoe * New rx protocol: 11589099Sfjoe * 11689099Sfjoe * rx has a fillcount variable. If fillcount > (NRXBUF-1), 11789099Sfjoe * rx can be switched off from rx hard int. 11889099Sfjoe * Else rx is restarted on the other receiver. 11989099Sfjoe * rx soft int counts down. if it is == (NRXBUF-1), it restarts 12089099Sfjoe * the receiver. 12189099Sfjoe * To ensure packet ordering (we need that for 1201 later), we have a counter 12289099Sfjoe * which is incremented modulo 256 on each receive and a per buffer 12389099Sfjoe * variable, which is set to the counter on filling. The soft int can 12489099Sfjoe * compare both values to determine the older packet. 12589099Sfjoe * 12689099Sfjoe * Transmit direction: 12789099Sfjoe * 12889099Sfjoe * cm_start checks tx_fillcount 12989099Sfjoe * case 2: return 13089099Sfjoe * 13189099Sfjoe * else fill tx_act ^ 1 && inc tx_fillcount 13289099Sfjoe * 13389099Sfjoe * check tx_fillcount again. 13489099Sfjoe * case 2: set IFF_OACTIVE to stop arc_output from filling us. 13589099Sfjoe * case 1: start tx 13689099Sfjoe * 13789099Sfjoe * tint clears IFF_OCATIVE, decrements and checks tx_fillcount 13889099Sfjoe * case 1: start tx on tx_act ^ 1, softcall cm_start 13989099Sfjoe * case 0: softcall cm_start 14089099Sfjoe * 14189099Sfjoe * #define fill(i) get mbuf && copy mbuf to chip(i) 14289099Sfjoe */ 14389099Sfjoe 14492739Salfredvoid cm_init(void *); 14592739Salfredvoid cm_reset(struct cm_softc *); 14692739Salfredvoid cm_start(struct ifnet *); 14792739Salfredint cm_ioctl(struct ifnet *, unsigned long, caddr_t); 14892739Salfredvoid cm_watchdog(struct ifnet *); 14992739Salfredvoid cm_srint(void *vsc); 15092739Salfredstatic void cm_tint(struct cm_softc *, int); 15189099Sfjoevoid cm_reconwatch(void *); 15289099Sfjoe 15389099Sfjoeint 15489099Sfjoecm_probe(dev) 15589099Sfjoe device_t dev; 15689099Sfjoe{ 15789099Sfjoe int error; 15889099Sfjoe struct cm_softc *sc = device_get_softc(dev); 15989099Sfjoe 16089099Sfjoe error = cm_alloc_port(dev, 0, CM_IO_PORTS); 16189099Sfjoe if (error) 16289099Sfjoe return error; 16389099Sfjoe 16489099Sfjoe if (GETREG(CMSTAT) == 0xff) 16589099Sfjoe return ENXIO; 16689099Sfjoe 16789099Sfjoe error = cm_alloc_memory(dev, 0, 0x800); 16889099Sfjoe if (error) 16989099Sfjoe return error; 17089099Sfjoe 17189099Sfjoe return 0; 17289099Sfjoe} 17389099Sfjoe 17489099Sfjoe/* 17589099Sfjoe * Allocate a port resource with the given resource id. 17689099Sfjoe */ 17789099Sfjoeint 17889099Sfjoecm_alloc_port(dev, rid, size) 17989099Sfjoe device_t dev; 18089099Sfjoe int rid; 18189099Sfjoe int size; 18289099Sfjoe{ 18389099Sfjoe struct cm_softc *sc = device_get_softc(dev); 18489099Sfjoe struct resource *res; 18589099Sfjoe 18689099Sfjoe res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 18789099Sfjoe 0ul, ~0ul, size, RF_ACTIVE); 18889099Sfjoe if (res) { 18989099Sfjoe sc->port_rid = rid; 19089099Sfjoe sc->port_res = res; 19189099Sfjoe sc->port_used = size; 19289099Sfjoe return (0); 19389099Sfjoe } else { 19489099Sfjoe return (ENOENT); 19589099Sfjoe } 19689099Sfjoe} 19789099Sfjoe 19889099Sfjoe/* 19989099Sfjoe * Allocate a memory resource with the given resource id. 20089099Sfjoe */ 20189099Sfjoeint 20289099Sfjoecm_alloc_memory(dev, rid, size) 20389099Sfjoe device_t dev; 20489099Sfjoe int rid; 20589099Sfjoe int size; 20689099Sfjoe{ 20789099Sfjoe struct cm_softc *sc = device_get_softc(dev); 20889099Sfjoe struct resource *res; 20989099Sfjoe 21089099Sfjoe res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 21189099Sfjoe 0ul, ~0ul, size, RF_ACTIVE); 21289099Sfjoe if (res) { 21389099Sfjoe sc->mem_rid = rid; 21489099Sfjoe sc->mem_res = res; 21589099Sfjoe sc->mem_used = size; 21689099Sfjoe return (0); 21789099Sfjoe } else { 21889099Sfjoe return (ENOENT); 21989099Sfjoe } 22089099Sfjoe} 22189099Sfjoe 22289099Sfjoe/* 22389099Sfjoe * Allocate an irq resource with the given resource id. 22489099Sfjoe */ 22589099Sfjoeint 22689099Sfjoecm_alloc_irq(dev, rid) 22789099Sfjoe device_t dev; 22889099Sfjoe int rid; 22989099Sfjoe{ 23089099Sfjoe struct cm_softc *sc = device_get_softc(dev); 23189099Sfjoe struct resource *res; 23289099Sfjoe 233127135Snjl res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); 23489099Sfjoe if (res) { 23589099Sfjoe sc->irq_rid = rid; 23689099Sfjoe sc->irq_res = res; 23789099Sfjoe return (0); 23889099Sfjoe } else { 23989099Sfjoe return (ENOENT); 24089099Sfjoe } 24189099Sfjoe} 24289099Sfjoe 24389099Sfjoe/* 24489099Sfjoe * Release all resources 24589099Sfjoe */ 24689099Sfjoevoid 24789099Sfjoecm_release_resources(dev) 24889099Sfjoe device_t dev; 24989099Sfjoe{ 25089099Sfjoe struct cm_softc *sc = device_get_softc(dev); 25189099Sfjoe 25289099Sfjoe if (sc->port_res) { 25389099Sfjoe bus_deactivate_resource(dev, SYS_RES_IOPORT, 25489099Sfjoe sc->port_rid, sc->port_res); 25589099Sfjoe bus_release_resource(dev, SYS_RES_IOPORT, 25689099Sfjoe sc->port_rid, sc->port_res); 25789099Sfjoe sc->port_res = 0; 25889099Sfjoe } 25989099Sfjoe if (sc->mem_res) { 26089099Sfjoe bus_deactivate_resource(dev, SYS_RES_MEMORY, 26189099Sfjoe sc->mem_rid, sc->mem_res); 26289099Sfjoe bus_release_resource(dev, SYS_RES_MEMORY, 26389099Sfjoe sc->mem_rid, sc->mem_res); 26489099Sfjoe sc->mem_res = 0; 26589099Sfjoe } 26689099Sfjoe if (sc->irq_res) { 26789099Sfjoe bus_deactivate_resource(dev, SYS_RES_IRQ, 26889099Sfjoe sc->irq_rid, sc->irq_res); 26989099Sfjoe bus_release_resource(dev, SYS_RES_IRQ, 27089099Sfjoe sc->irq_rid, sc->irq_res); 27189099Sfjoe sc->irq_res = 0; 27289099Sfjoe } 27389099Sfjoe} 27489099Sfjoe 27589099Sfjoeint 276121816Sbrookscm_attach(dev) 277121816Sbrooks device_t dev; 27889099Sfjoe{ 279121816Sbrooks struct cm_softc *sc = device_get_softc(dev); 28089099Sfjoe struct ifnet *ifp = &sc->sc_arccom.ac_if; 28189099Sfjoe int s; 28289099Sfjoe u_int8_t linkaddress; 28389099Sfjoe 28489099Sfjoe s = splhigh(); 28589099Sfjoe 28689099Sfjoe /* 28789099Sfjoe * read the arcnet address from the board 28889099Sfjoe */ 28989099Sfjoe 29089099Sfjoe GETREG(CMRESET); 29189099Sfjoe do { 29289099Sfjoe DELAY(200); 29389099Sfjoe } while (!(GETREG(CMSTAT) & CM_POR)); 29489099Sfjoe 29589099Sfjoe linkaddress = GETMEM(CMMACOFF); 29689099Sfjoe 29789099Sfjoe /* clear the int mask... */ 29889099Sfjoe 29989099Sfjoe sc->sc_intmask = 0; 30089099Sfjoe PUTREG(CMSTAT, 0); 30189099Sfjoe 30289099Sfjoe PUTREG(CMCMD, CM_CONF(CONF_LONG)); 30389099Sfjoe PUTREG(CMCMD, CM_CLR(CLR_POR|CLR_RECONFIG)); 30489099Sfjoe sc->sc_recontime = sc->sc_reconcount = 0; 30589099Sfjoe 30689099Sfjoe /* and reenable kernel int level */ 30789099Sfjoe splx(s); 30889099Sfjoe 30989099Sfjoe /* 31089099Sfjoe * set interface to stopped condition (reset) 31189099Sfjoe */ 31289099Sfjoe cm_stop(sc); 31389099Sfjoe 314121752Sbrooks ifp->if_softc = sc; 315121816Sbrooks if_initname(ifp, device_get_name(dev), device_get_unit(dev)); 316121752Sbrooks ifp->if_output = arc_output; 317121752Sbrooks ifp->if_start = cm_start; 318121752Sbrooks ifp->if_ioctl = cm_ioctl; 319121752Sbrooks ifp->if_watchdog = cm_watchdog; 320121752Sbrooks ifp->if_init = cm_init; 321121752Sbrooks /* XXX IFQ_SET_READY(&ifp->if_snd); */ 322121752Sbrooks ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 323121752Sbrooks ifp->if_timer = 0; 324121752Sbrooks ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; 32589099Sfjoe 326121752Sbrooks arc_ifattach(ifp, linkaddress); 32789099Sfjoe 32889099Sfjoe#ifdef CMSOFTCOPY 329121752Sbrooks sc->sc_rxcookie = softintr_establish(IPL_SOFTNET, cm_srint, sc); 330121752Sbrooks sc->sc_txcookie = softintr_establish(IPL_SOFTNET, 331121752Sbrooks (void (*)(void *))cm_start, ifp); 33289099Sfjoe#endif 33389099Sfjoe 33489099Sfjoe#if __FreeBSD_version < 500000 335121752Sbrooks callout_init(&sc->sc_recon_ch); 33689099Sfjoe#else 337121752Sbrooks callout_init(&sc->sc_recon_ch, 0); 33889099Sfjoe#endif 33989099Sfjoe 340109771Sfjoe if_printf(ifp, "link addr 0x%02x (%d)\n", linkaddress, linkaddress); 34189099Sfjoe return 0; 34289099Sfjoe} 34389099Sfjoe 34489099Sfjoe/* 34589099Sfjoe * Initialize device 34689099Sfjoe * 34789099Sfjoe */ 34889099Sfjoevoid 34989099Sfjoecm_init(xsc) 35089099Sfjoe void *xsc; 35189099Sfjoe{ 35289099Sfjoe struct cm_softc *sc = (struct cm_softc *)xsc; 35389099Sfjoe struct ifnet *ifp; 35489099Sfjoe int s; 35589099Sfjoe 35689099Sfjoe ifp = &sc->sc_arccom.ac_if; 35789099Sfjoe 35889099Sfjoe if ((ifp->if_flags & IFF_RUNNING) == 0) { 35989099Sfjoe s = splimp(); 36089099Sfjoe ifp->if_flags |= IFF_RUNNING; 36189099Sfjoe cm_reset(sc); 36289099Sfjoe cm_start(ifp); 36389099Sfjoe splx(s); 36489099Sfjoe } 36589099Sfjoe} 36689099Sfjoe 36789099Sfjoe/* 36889099Sfjoe * Reset the interface... 36989099Sfjoe * 37089099Sfjoe * this assumes that it is called inside a critical section... 37189099Sfjoe * 37289099Sfjoe */ 37389099Sfjoevoid 37489099Sfjoecm_reset(sc) 37589099Sfjoe struct cm_softc *sc; 37689099Sfjoe{ 37789099Sfjoe struct ifnet *ifp; 37889099Sfjoe int linkaddress; 37989099Sfjoe 38089099Sfjoe ifp = &sc->sc_arccom.ac_if; 38189099Sfjoe 38289099Sfjoe#ifdef CM_DEBUG 383104251Sbrooks if_printf(ifp, "reset\n"); 38489099Sfjoe#endif 38589099Sfjoe /* stop and restart hardware */ 38689099Sfjoe 38789099Sfjoe GETREG(CMRESET); 38889099Sfjoe do { 38989099Sfjoe DELAY(200); 39089099Sfjoe } while (!(GETREG(CMSTAT) & CM_POR)); 39189099Sfjoe 39289099Sfjoe linkaddress = GETMEM(CMMACOFF); 39389099Sfjoe 39489099Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 2) 395104251Sbrooks if_printf(ifp, "reset: card reset, link addr = 0x%02x (%d)\n", 396104251Sbrooks linkaddress, linkaddress); 39789099Sfjoe#endif 39889099Sfjoe 39989099Sfjoe /* tell the routing level about the (possibly changed) link address */ 40089099Sfjoe arc_storelladdr(ifp, linkaddress); 40189099Sfjoe arc_frag_init(ifp); 40289099Sfjoe 40389099Sfjoe /* POR is NMI, but we need it below: */ 40489099Sfjoe sc->sc_intmask = CM_RECON|CM_POR; 40589099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 40689099Sfjoe PUTREG(CMCMD, CM_CONF(CONF_LONG)); 40789099Sfjoe 40889099Sfjoe#ifdef CM_DEBUG 409104251Sbrooks if_printf(ifp, "reset: chip configured, status=0x%02x\n", 410104251Sbrooks GETREG(CMSTAT)); 41189099Sfjoe#endif 41289099Sfjoe PUTREG(CMCMD, CM_CLR(CLR_POR|CLR_RECONFIG)); 41389099Sfjoe 41489099Sfjoe#ifdef CM_DEBUG 415104251Sbrooks if_printf(ifp, "reset: bits cleared, status=0x%02x\n", 416104251Sbrooks GETREG(CMSTAT)); 41789099Sfjoe#endif 41889099Sfjoe 41989099Sfjoe sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS; 42089099Sfjoe 42189099Sfjoe /* start receiver */ 42289099Sfjoe 42389099Sfjoe sc->sc_intmask |= CM_RI; 42489099Sfjoe sc->sc_rx_fillcount = 0; 42589099Sfjoe sc->sc_rx_act = 2; 42689099Sfjoe 42789099Sfjoe PUTREG(CMCMD, CM_RXBC(2)); 42889099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 42989099Sfjoe 43089099Sfjoe#ifdef CM_DEBUG 431104251Sbrooks if_printf(ifp, "reset: started receiver, status=0x%02x\n", 432104251Sbrooks GETREG(CMSTAT)); 43389099Sfjoe#endif 43489099Sfjoe 43589099Sfjoe /* and init transmitter status */ 43689099Sfjoe sc->sc_tx_act = 0; 43789099Sfjoe sc->sc_tx_fillcount = 0; 43889099Sfjoe 43989099Sfjoe ifp->if_flags |= IFF_RUNNING; 44089099Sfjoe ifp->if_flags &= ~IFF_OACTIVE; 44189099Sfjoe 44289099Sfjoe cm_start(ifp); 44389099Sfjoe} 44489099Sfjoe 44589099Sfjoe/* 44689099Sfjoe * Take interface offline 44789099Sfjoe */ 44889099Sfjoevoid 44989099Sfjoecm_stop(sc) 45089099Sfjoe struct cm_softc *sc; 45189099Sfjoe{ 45289099Sfjoe /* Stop the interrupts */ 45389099Sfjoe PUTREG(CMSTAT, 0); 45489099Sfjoe 45589099Sfjoe /* Stop the interface */ 45689099Sfjoe GETREG(CMRESET); 45789099Sfjoe 45889099Sfjoe /* Stop watchdog timer */ 45989099Sfjoe sc->sc_arccom.ac_if.if_timer = 0; 46089099Sfjoe} 46189099Sfjoe 46289099Sfjoe/* 46389099Sfjoe * Start output on interface. Get another datagram to send 46489099Sfjoe * off the interface queue, and copy it to the 46589099Sfjoe * interface becore starting the output 46689099Sfjoe * 46789099Sfjoe * this assumes that it is called inside a critical section... 46889099Sfjoe * XXX hm... does it still? 46989099Sfjoe * 47089099Sfjoe */ 47189099Sfjoevoid 47289099Sfjoecm_start(ifp) 47389099Sfjoe struct ifnet *ifp; 47489099Sfjoe{ 47589099Sfjoe struct cm_softc *sc = ifp->if_softc; 47689099Sfjoe struct mbuf *m,*mp; 47789099Sfjoe 47889099Sfjoe int cm_ram_ptr; 47989099Sfjoe int len, tlen, offset, s, buffer; 48089099Sfjoe#ifdef CMTIMINGS 48189099Sfjoe u_long copystart, lencopy, perbyte; 48289099Sfjoe#endif 48389099Sfjoe 48489099Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 3) 485104251Sbrooks if_printf(ifp, "start(%p)\n", ifp); 48689099Sfjoe#endif 48789099Sfjoe 48889099Sfjoe if ((ifp->if_flags & IFF_RUNNING) == 0) 48989099Sfjoe return; 49089099Sfjoe 49189099Sfjoe s = splimp(); 49289099Sfjoe 49389099Sfjoe if (sc->sc_tx_fillcount >= 2) { 49489099Sfjoe splx(s); 49589099Sfjoe return; 49689099Sfjoe } 49789099Sfjoe 49889099Sfjoe m = arc_frag_next(ifp); 49989099Sfjoe buffer = sc->sc_tx_act ^ 1; 50089099Sfjoe 50189099Sfjoe splx(s); 50289099Sfjoe 50389099Sfjoe if (m == 0) 50489099Sfjoe return; 50589099Sfjoe 50689099Sfjoe#ifdef CM_DEBUG 50789099Sfjoe if (m->m_len < ARC_HDRLEN) 50889099Sfjoe m = m_pullup(m, ARC_HDRLEN);/* gcc does structure padding */ 509104251Sbrooks if_printf(ifp, "start: filling %d from %d to %d type %d\n", 510104251Sbrooks buffer, mtod(m, u_char *)[0], 51189099Sfjoe mtod(m, u_char *)[1], mtod(m, u_char *)[2]); 51289099Sfjoe#else 51389099Sfjoe if (m->m_len < 2) 51489099Sfjoe m = m_pullup(m, 2); 51589099Sfjoe#endif 516109771Sfjoe cm_ram_ptr = buffer * 512; 51789099Sfjoe 51889099Sfjoe if (m == 0) 51989099Sfjoe return; 52089099Sfjoe 52189099Sfjoe /* write the addresses to RAM and throw them away */ 52289099Sfjoe 52389099Sfjoe /* 52489099Sfjoe * Hardware does this: Yet Another Microsecond Saved. 52589099Sfjoe * (btw, timing code says usually 2 microseconds) 52689099Sfjoe * PUTMEM(cm_ram_ptr + 0, mtod(m, u_char *)[0]); 52789099Sfjoe */ 52889099Sfjoe 52989099Sfjoe PUTMEM(cm_ram_ptr + 1, mtod(m, u_char *)[1]); 53089099Sfjoe m_adj(m, 2); 53189099Sfjoe 53289099Sfjoe /* get total length left at this point */ 53389099Sfjoe tlen = m->m_pkthdr.len; 53489099Sfjoe if (tlen < ARC_MIN_FORBID_LEN) { 53589099Sfjoe offset = 256 - tlen; 53689099Sfjoe PUTMEM(cm_ram_ptr + 2, offset); 53789099Sfjoe } else { 53889099Sfjoe PUTMEM(cm_ram_ptr + 2, 0); 53989099Sfjoe if (tlen <= ARC_MAX_FORBID_LEN) 54089099Sfjoe offset = 255; /* !!! */ 54189099Sfjoe else { 54289099Sfjoe if (tlen > ARC_MAX_LEN) 54389099Sfjoe tlen = ARC_MAX_LEN; 54489099Sfjoe offset = 512 - tlen; 54589099Sfjoe } 54689099Sfjoe PUTMEM(cm_ram_ptr + 3, offset); 54789099Sfjoe 54889099Sfjoe } 54989099Sfjoe cm_ram_ptr += offset; 55089099Sfjoe 55189099Sfjoe /* lets loop through the mbuf chain */ 55289099Sfjoe 55389099Sfjoe for (mp = m; mp; mp = mp->m_next) { 55489099Sfjoe if ((len = mp->m_len)) { /* YAMS */ 55589099Sfjoe bus_space_write_region_1( 55689099Sfjoe rman_get_bustag(sc->mem_res), 55789099Sfjoe rman_get_bushandle(sc->mem_res), 55889099Sfjoe cm_ram_ptr, mtod(mp, caddr_t), len); 55989099Sfjoe 56089099Sfjoe cm_ram_ptr += len; 56189099Sfjoe } 56289099Sfjoe } 56389099Sfjoe 56489099Sfjoe sc->sc_broadcast[buffer] = (m->m_flags & M_BCAST) != 0; 56589099Sfjoe sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5; 56689099Sfjoe 56789099Sfjoe /* actually transmit the packet */ 56889099Sfjoe s = splimp(); 56989099Sfjoe 57089099Sfjoe if (++sc->sc_tx_fillcount > 1) { 57189099Sfjoe /* 57289099Sfjoe * We are filled up to the rim. No more bufs for the moment, 57389099Sfjoe * please. 57489099Sfjoe */ 57589099Sfjoe ifp->if_flags |= IFF_OACTIVE; 57689099Sfjoe } else { 57789099Sfjoe#ifdef CM_DEBUG 578104251Sbrooks if_printf(ifp, "start: starting transmitter on buffer %d\n", 579104251Sbrooks buffer); 58089099Sfjoe#endif 58189099Sfjoe /* Transmitter was off, start it */ 58289099Sfjoe sc->sc_tx_act = buffer; 58389099Sfjoe 58489099Sfjoe /* 58589099Sfjoe * We still can accept another buf, so don't: 58689099Sfjoe * ifp->if_flags |= IFF_OACTIVE; 58789099Sfjoe */ 58889099Sfjoe sc->sc_intmask |= CM_TA; 58989099Sfjoe PUTREG(CMCMD, CM_TX(buffer)); 59089099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 59189099Sfjoe 59289099Sfjoe sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT; 59389099Sfjoe } 59489099Sfjoe splx(s); 59589099Sfjoe m_freem(m); 59689099Sfjoe 59789099Sfjoe /* 59889099Sfjoe * After 10 times reading the docs, I realized 59989099Sfjoe * that in the case the receiver NAKs the buffer request, 60089099Sfjoe * the hardware retries till shutdown. 60189099Sfjoe * This is integrated now in the code above. 60289099Sfjoe */ 60389099Sfjoe 60489099Sfjoe return; 60589099Sfjoe} 60689099Sfjoe 60789099Sfjoe/* 60889099Sfjoe * Arcnet interface receiver soft interrupt: 60989099Sfjoe * get the stuff out of any filled buffer we find. 61089099Sfjoe */ 61189099Sfjoevoid 61289099Sfjoecm_srint(vsc) 61389099Sfjoe void *vsc; 61489099Sfjoe{ 61589099Sfjoe struct cm_softc *sc = (struct cm_softc *)vsc; 61689099Sfjoe int buffer, len, offset, s, type; 61789099Sfjoe int cm_ram_ptr; 61889099Sfjoe struct mbuf *m; 61989099Sfjoe struct arc_header *ah; 62089099Sfjoe struct ifnet *ifp; 62189099Sfjoe 62289099Sfjoe ifp = &sc->sc_arccom.ac_if; 62389099Sfjoe 62489099Sfjoe s = splimp(); 62589099Sfjoe buffer = sc->sc_rx_act ^ 1; 62689099Sfjoe splx(s); 62789099Sfjoe 62889099Sfjoe /* Allocate header mbuf */ 629111119Simp MGETHDR(m, M_DONTWAIT, MT_DATA); 63089099Sfjoe 63189099Sfjoe if (m == 0) { 63289099Sfjoe /* 63389099Sfjoe * in case s.th. goes wrong with mem, drop it 63489099Sfjoe * to make sure the receiver can be started again 63589099Sfjoe * count it as input error (we dont have any other 63689099Sfjoe * detectable) 63789099Sfjoe */ 63889099Sfjoe ifp->if_ierrors++; 63989099Sfjoe goto cleanup; 64089099Sfjoe } 64189099Sfjoe 64289099Sfjoe m->m_pkthdr.rcvif = ifp; 64389099Sfjoe 64489099Sfjoe /* 64589099Sfjoe * Align so that IP packet will be longword aligned. Here we 64689099Sfjoe * assume that m_data of new packet is longword aligned. 64789099Sfjoe * When implementing PHDS, we might have to change it to 2, 64889099Sfjoe * (2*sizeof(ulong) - CM_HDRNEWLEN)), packet type dependent. 64989099Sfjoe */ 65089099Sfjoe 651109771Sfjoe cm_ram_ptr = buffer * 512; 65289099Sfjoe offset = GETMEM(cm_ram_ptr + 2); 65389099Sfjoe if (offset) 65489099Sfjoe len = 256 - offset; 65589099Sfjoe else { 65689099Sfjoe offset = GETMEM(cm_ram_ptr + 3); 65789099Sfjoe len = 512 - offset; 65889099Sfjoe } 65989099Sfjoe 66089099Sfjoe /* 66189099Sfjoe * first +2 bytes for align fixup below 66289099Sfjoe * second +2 bytes are for src/dst addresses 66389099Sfjoe */ 66489099Sfjoe if ((len + 2 + 2) > MHLEN) { 66589099Sfjoe /* attach an mbuf cluster */ 666111119Simp MCLGET(m, M_DONTWAIT); 66789099Sfjoe 66889099Sfjoe /* Insist on getting a cluster */ 66989099Sfjoe if ((m->m_flags & M_EXT) == 0) { 67089099Sfjoe ifp->if_ierrors++; 67189099Sfjoe goto cleanup; 67289099Sfjoe } 67389099Sfjoe } 67489099Sfjoe 67589099Sfjoe if (m == 0) { 67689099Sfjoe ifp->if_ierrors++; 67789099Sfjoe goto cleanup; 67889099Sfjoe } 67989099Sfjoe 68089099Sfjoe type = GETMEM(cm_ram_ptr + offset); 68189099Sfjoe m->m_data += 1 + arc_isphds(type); 68289099Sfjoe /* mbuf filled with ARCnet addresses */ 68389099Sfjoe m->m_pkthdr.len = m->m_len = len + 2; 68489099Sfjoe 68589099Sfjoe ah = mtod(m, struct arc_header *); 68689099Sfjoe ah->arc_shost = GETMEM(cm_ram_ptr + 0); 68789099Sfjoe ah->arc_dhost = GETMEM(cm_ram_ptr + 1); 68889099Sfjoe 68989099Sfjoe bus_space_read_region_1( 69089099Sfjoe rman_get_bustag(sc->mem_res), rman_get_bushandle(sc->mem_res), 69189099Sfjoe cm_ram_ptr + offset, mtod(m, u_char *) + 2, len); 69289099Sfjoe 69389099Sfjoe arc_input(ifp, m); 69489099Sfjoe 69589099Sfjoe m = NULL; 69689099Sfjoe ifp->if_ipackets++; 69789099Sfjoe 69889099Sfjoecleanup: 69989099Sfjoe 70089099Sfjoe if (m != NULL) 70189099Sfjoe m_freem(m); 70289099Sfjoe 70389099Sfjoe /* mark buffer as invalid by source id 0 */ 70489099Sfjoe PUTMEM(buffer << 9, 0); 70589099Sfjoe s = splimp(); 70689099Sfjoe 70789099Sfjoe if (--sc->sc_rx_fillcount == 2 - 1) { 70889099Sfjoe 70989099Sfjoe /* was off, restart it on buffer just emptied */ 71089099Sfjoe sc->sc_rx_act = buffer; 71189099Sfjoe sc->sc_intmask |= CM_RI; 71289099Sfjoe 71389099Sfjoe /* this also clears the RI flag interupt: */ 71489099Sfjoe PUTREG(CMCMD, CM_RXBC(buffer)); 71589099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 71689099Sfjoe 71789099Sfjoe#ifdef CM_DEBUG 718104251Sbrooks if_printf(ifp, "srint: restarted rx on buf %d\n", buffer); 71989099Sfjoe#endif 72089099Sfjoe } 72189099Sfjoe splx(s); 72289099Sfjoe} 72389099Sfjoe 72489099Sfjoe__inline static void 72589099Sfjoecm_tint(sc, isr) 72689099Sfjoe struct cm_softc *sc; 72789099Sfjoe int isr; 72889099Sfjoe{ 72989099Sfjoe struct ifnet *ifp; 73089099Sfjoe 73189099Sfjoe int buffer; 73289099Sfjoe#ifdef CMTIMINGS 73389099Sfjoe int clknow; 73489099Sfjoe#endif 73589099Sfjoe 73689099Sfjoe ifp = &(sc->sc_arccom.ac_if); 73789099Sfjoe buffer = sc->sc_tx_act; 73889099Sfjoe 73989099Sfjoe /* 74089099Sfjoe * retransmit code: 74189099Sfjoe * Normal situtations first for fast path: 74289099Sfjoe * If acknowledgement received ok or broadcast, we're ok. 74389099Sfjoe * else if 74489099Sfjoe */ 74589099Sfjoe 74689099Sfjoe if (isr & CM_TMA || sc->sc_broadcast[buffer]) 74789099Sfjoe sc->sc_arccom.ac_if.if_opackets++; 74889099Sfjoe#ifdef CMRETRANSMIT 74989099Sfjoe else if (ifp->if_flags & IFF_LINK2 && ifp->if_timer > 0 75089099Sfjoe && --sc->sc_retransmits[buffer] > 0) { 75189099Sfjoe /* retransmit same buffer */ 75289099Sfjoe PUTREG(CMCMD, CM_TX(buffer)); 75389099Sfjoe return; 75489099Sfjoe } 75589099Sfjoe#endif 75689099Sfjoe else 75789099Sfjoe ifp->if_oerrors++; 75889099Sfjoe 75989099Sfjoe 76089099Sfjoe /* We know we can accept another buffer at this point. */ 76189099Sfjoe ifp->if_flags &= ~IFF_OACTIVE; 76289099Sfjoe 76389099Sfjoe if (--sc->sc_tx_fillcount > 0) { 76489099Sfjoe 76589099Sfjoe /* 76689099Sfjoe * start tx on other buffer. 76789099Sfjoe * This also clears the int flag 76889099Sfjoe */ 76989099Sfjoe buffer ^= 1; 77089099Sfjoe sc->sc_tx_act = buffer; 77189099Sfjoe 77289099Sfjoe /* 77389099Sfjoe * already given: 77489099Sfjoe * sc->sc_intmask |= CM_TA; 77589099Sfjoe * PUTREG(CMSTAT, sc->sc_intmask); 77689099Sfjoe */ 77789099Sfjoe PUTREG(CMCMD, CM_TX(buffer)); 77889099Sfjoe /* init watchdog timer */ 77989099Sfjoe ifp->if_timer = ARCTIMEOUT; 78089099Sfjoe 78189099Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 1) 782104251Sbrooks if_printf(ifp, 783104251Sbrooks "tint: starting tx on buffer %d, status 0x%02x\n", 784104251Sbrooks buffer, GETREG(CMSTAT)); 78589099Sfjoe#endif 78689099Sfjoe } else { 78789099Sfjoe /* have to disable TX interrupt */ 78889099Sfjoe sc->sc_intmask &= ~CM_TA; 78989099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 79089099Sfjoe /* ... and watchdog timer */ 79189099Sfjoe ifp->if_timer = 0; 79289099Sfjoe 79389099Sfjoe#ifdef CM_DEBUG 794104251Sbrooks if_printf(ifp, "tint: no more buffers to send, status 0x%02x\n", 795104251Sbrooks GETREG(CMSTAT)); 79689099Sfjoe#endif 79789099Sfjoe } 79889099Sfjoe 79989099Sfjoe /* XXXX TODO */ 80089099Sfjoe#ifdef CMSOFTCOPY 80189099Sfjoe /* schedule soft int to fill a new buffer for us */ 80289099Sfjoe softintr_schedule(sc->sc_txcookie); 80389099Sfjoe#else 80489099Sfjoe /* call it directly */ 80589099Sfjoe cm_start(ifp); 80689099Sfjoe#endif 80789099Sfjoe} 80889099Sfjoe 80989099Sfjoe/* 81089099Sfjoe * Our interrupt routine 81189099Sfjoe */ 81289099Sfjoevoid 81389099Sfjoecmintr(arg) 81489099Sfjoe void *arg; 81589099Sfjoe{ 81689099Sfjoe struct cm_softc *sc = arg; 81789099Sfjoe struct ifnet *ifp = &sc->sc_arccom.ac_if; 81889099Sfjoe 81989099Sfjoe u_char isr, maskedisr; 82089099Sfjoe int buffer; 82189099Sfjoe u_long newsec; 82289099Sfjoe 82389099Sfjoe isr = GETREG(CMSTAT); 82489099Sfjoe maskedisr = isr & sc->sc_intmask; 82589099Sfjoe if (!maskedisr) 82689099Sfjoe return; 82789099Sfjoe do { 82889099Sfjoe 829109771Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 1) 830104251Sbrooks if_printf(ifp, "intr: status 0x%02x, intmask 0x%02x\n", 831104251Sbrooks isr, sc->sc_intmask); 83289099Sfjoe#endif 83389099Sfjoe 83489099Sfjoe if (maskedisr & CM_POR) { 83589099Sfjoe /* 83689099Sfjoe * XXX We should never see this. Don't bother to store 83789099Sfjoe * the address. 83889099Sfjoe * sc->sc_arccom.ac_anaddr = GETMEM(CMMACOFF); 83989099Sfjoe */ 84089099Sfjoe PUTREG(CMCMD, CM_CLR(CLR_POR)); 84189099Sfjoe log(LOG_WARNING, 842121816Sbrooks "%s: intr: got spurious power on reset int\n", 843121816Sbrooks ifp->if_xname); 84489099Sfjoe } 84589099Sfjoe 84689099Sfjoe if (maskedisr & CM_RECON) { 84789099Sfjoe /* 84889099Sfjoe * we dont need to: 84989099Sfjoe * PUTREG(CMCMD, CM_CONF(CONF_LONG)); 85089099Sfjoe */ 85189099Sfjoe PUTREG(CMCMD, CM_CLR(CLR_RECONFIG)); 85289099Sfjoe sc->sc_arccom.ac_if.if_collisions++; 85389099Sfjoe 85489099Sfjoe /* 85589099Sfjoe * If less than 2 seconds per reconfig: 85689099Sfjoe * If ARC_EXCESSIVE_RECONFIGS 85789099Sfjoe * since last burst, complain and set treshold for 85889099Sfjoe * warnings to ARC_EXCESSIVE_RECONS_REWARN. 85989099Sfjoe * 86089099Sfjoe * This allows for, e.g., new stations on the cable, or 86189099Sfjoe * cable switching as long as it is over after 86289099Sfjoe * (normally) 16 seconds. 86389099Sfjoe * 86489099Sfjoe * XXX TODO: check timeout bits in status word and 86589099Sfjoe * double time if necessary. 86689099Sfjoe */ 86789099Sfjoe 86889099Sfjoe callout_stop(&sc->sc_recon_ch); 86989099Sfjoe newsec = time_second; 87089099Sfjoe if ((newsec - sc->sc_recontime <= 2) && 87189099Sfjoe (++sc->sc_reconcount == ARC_EXCESSIVE_RECONS)) { 87289099Sfjoe log(LOG_WARNING, 873121816Sbrooks "%s: excessive token losses, " 87489099Sfjoe "cable problem?\n", 875121816Sbrooks ifp->if_xname); 87689099Sfjoe } 87789099Sfjoe sc->sc_recontime = newsec; 87889099Sfjoe callout_reset(&sc->sc_recon_ch, 15 * hz, 87989099Sfjoe cm_reconwatch, (void *)sc); 88089099Sfjoe } 88189099Sfjoe 88289099Sfjoe if (maskedisr & CM_RI) { 88389099Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 1) 884104251Sbrooks if_printf(ifp, "intr: hard rint, act %d\n", 885104251Sbrooks sc->sc_rx_act); 88689099Sfjoe#endif 88789099Sfjoe 88889099Sfjoe buffer = sc->sc_rx_act; 88989099Sfjoe /* look if buffer is marked invalid: */ 890109771Sfjoe if (GETMEM(buffer * 512) == 0) { 89189099Sfjoe /* 89289099Sfjoe * invalid marked buffer (or illegally 89389099Sfjoe * configured sender) 89489099Sfjoe */ 89589099Sfjoe log(LOG_WARNING, 896121816Sbrooks "%s: spurious RX interupt or sender 0 " 897121816Sbrooks " (ignored)\n", ifp->if_xname); 89889099Sfjoe /* 89989099Sfjoe * restart receiver on same buffer. 90089099Sfjoe * XXX maybe better reset interface? 90189099Sfjoe */ 90289099Sfjoe PUTREG(CMCMD, CM_RXBC(buffer)); 90389099Sfjoe } else { 90489099Sfjoe if (++sc->sc_rx_fillcount > 1) { 90589099Sfjoe sc->sc_intmask &= ~CM_RI; 90689099Sfjoe PUTREG(CMSTAT, sc->sc_intmask); 90789099Sfjoe } else { 90889099Sfjoe buffer ^= 1; 90989099Sfjoe sc->sc_rx_act = buffer; 91089099Sfjoe 91189099Sfjoe /* 91289099Sfjoe * Start receiver on other receive 91389099Sfjoe * buffer. This also clears the RI 91489099Sfjoe * interupt flag. 91589099Sfjoe */ 91689099Sfjoe PUTREG(CMCMD, CM_RXBC(buffer)); 91789099Sfjoe /* in RX intr, so mask is ok for RX */ 91889099Sfjoe 91989099Sfjoe#ifdef CM_DEBUG 920104251Sbrooks if_printf(ifp, "strt rx for buf %d, " 92189099Sfjoe "stat 0x%02x\n", 92289099Sfjoe sc->sc_rx_act, GETREG(CMSTAT)); 92389099Sfjoe#endif 92489099Sfjoe } 92589099Sfjoe 92689099Sfjoe#ifdef CMSOFTCOPY 92789099Sfjoe /* 92889099Sfjoe * this one starts a soft int to copy out 92989099Sfjoe * of the hw 93089099Sfjoe */ 93189099Sfjoe softintr_schedule(sc->sc_rxcookie); 93289099Sfjoe#else 93389099Sfjoe /* this one does the copy here */ 93489099Sfjoe cm_srint(sc); 93589099Sfjoe#endif 93689099Sfjoe } 93789099Sfjoe } 93889099Sfjoe if (maskedisr & CM_TA) { 93989099Sfjoe cm_tint(sc, isr); 94089099Sfjoe } 94189099Sfjoe isr = GETREG(CMSTAT); 94289099Sfjoe maskedisr = isr & sc->sc_intmask; 94389099Sfjoe } while (maskedisr); 944109771Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 1) 945104251Sbrooks if_printf(ifp, "intr (exit): status 0x%02x, intmask 0x%02x\n", 946104251Sbrooks isr, sc->sc_intmask); 94789099Sfjoe#endif 94889099Sfjoe} 94989099Sfjoe 95089099Sfjoevoid 95189099Sfjoecm_reconwatch(arg) 95289099Sfjoe void *arg; 95389099Sfjoe{ 95489099Sfjoe struct cm_softc *sc = arg; 95589099Sfjoe struct ifnet *ifp = &sc->sc_arccom.ac_if; 95689099Sfjoe 95789099Sfjoe if (sc->sc_reconcount >= ARC_EXCESSIVE_RECONS) { 95889099Sfjoe sc->sc_reconcount = 0; 959121816Sbrooks log(LOG_WARNING, "%s: token valid again.\n", 960121816Sbrooks ifp->if_xname); 96189099Sfjoe } 96289099Sfjoe sc->sc_reconcount = 0; 96389099Sfjoe} 96489099Sfjoe 96589099Sfjoe 96689099Sfjoe/* 96789099Sfjoe * Process an ioctl request. 96889099Sfjoe * This code needs some work - it looks pretty ugly. 96989099Sfjoe */ 97089099Sfjoeint 97189099Sfjoecm_ioctl(ifp, command, data) 97289099Sfjoe struct ifnet *ifp; 97389099Sfjoe u_long command; 97489099Sfjoe caddr_t data; 97589099Sfjoe{ 97689099Sfjoe struct cm_softc *sc; 97789099Sfjoe struct ifaddr *ifa; 97889099Sfjoe struct ifreq *ifr; 97989099Sfjoe int s, error; 98089099Sfjoe 98189099Sfjoe error = 0; 98289099Sfjoe sc = ifp->if_softc; 98389099Sfjoe ifa = (struct ifaddr *)data; 98489099Sfjoe ifr = (struct ifreq *)data; 98589099Sfjoe s = splimp(); 98689099Sfjoe 98789099Sfjoe#if defined(CM_DEBUG) && (CM_DEBUG > 2) 988104251Sbrooks if_printf(ifp, "ioctl() called, cmd = 0x%lx\n", command); 98989099Sfjoe#endif 99089099Sfjoe 99189099Sfjoe switch (command) { 99289099Sfjoe case SIOCSIFADDR: 993109771Sfjoe case SIOCGIFADDR: 99489099Sfjoe case SIOCADDMULTI: 99589099Sfjoe case SIOCDELMULTI: 99689099Sfjoe case SIOCSIFMTU: 99789099Sfjoe error = arc_ioctl(ifp, command, data); 99889099Sfjoe break; 99989099Sfjoe 100089099Sfjoe case SIOCSIFFLAGS: 100189099Sfjoe if ((ifp->if_flags & IFF_UP) == 0 && 100289099Sfjoe (ifp->if_flags & IFF_RUNNING) != 0) { 100389099Sfjoe /* 100489099Sfjoe * If interface is marked down and it is running, 100589099Sfjoe * then stop it. 100689099Sfjoe */ 100789099Sfjoe cm_stop(sc); 100889099Sfjoe ifp->if_flags &= ~IFF_RUNNING; 100989099Sfjoe } else if ((ifp->if_flags & IFF_UP) != 0 && 101089099Sfjoe (ifp->if_flags & IFF_RUNNING) == 0) { 101189099Sfjoe /* 101289099Sfjoe * If interface is marked up and it is stopped, then 101389099Sfjoe * start it. 101489099Sfjoe */ 101589099Sfjoe cm_init(sc); 101689099Sfjoe } 101789099Sfjoe break; 101889099Sfjoe 101989099Sfjoe default: 102089099Sfjoe error = EINVAL; 102189099Sfjoe break; 102289099Sfjoe } 102389099Sfjoe 102489099Sfjoe splx(s); 102589099Sfjoe return (error); 102689099Sfjoe} 102789099Sfjoe 102889099Sfjoe/* 102989099Sfjoe * watchdog routine for transmitter. 103089099Sfjoe * 103189099Sfjoe * We need this, because else a receiver whose hardware is alive, but whose 103289099Sfjoe * software has not enabled the Receiver, would make our hardware wait forever 103389099Sfjoe * Discovered this after 20 times reading the docs. 103489099Sfjoe * 1035108470Sschweikh * Only thing we do is disable transmitter. We'll get a transmit timeout, 103689099Sfjoe * and the int handler will have to decide not to retransmit (in case 103789099Sfjoe * retransmission is implemented). 103889099Sfjoe * 103989099Sfjoe * This one assumes being called inside splimp() 104089099Sfjoe */ 104189099Sfjoe 104289099Sfjoevoid 104389099Sfjoecm_watchdog(ifp) 104489099Sfjoe struct ifnet *ifp; 104589099Sfjoe{ 104689099Sfjoe struct cm_softc *sc = ifp->if_softc; 104789099Sfjoe 104889099Sfjoe PUTREG(CMCMD, CM_TXDIS); 104989099Sfjoe return; 105089099Sfjoe} 1051