if_de.c revision 8296
13278Swollman/*- 27689Sdg * Copyright (c) 1994, 1995 Matt Thomas (matt@lkg.dec.com) 33278Swollman * All rights reserved. 43278Swollman * 53278Swollman * Redistribution and use in source and binary forms, with or without 63278Swollman * modification, are permitted provided that the following conditions 73278Swollman * are met: 83278Swollman * 1. Redistributions of source code must retain the above copyright 93278Swollman * notice, this list of conditions and the following disclaimer. 103278Swollman * 2. The name of the author may not be used to endorse or promote products 113278Swollman * derived from this software withough specific prior written permission 123278Swollman * 133278Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 143278Swollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 153278Swollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 163278Swollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 173278Swollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 183278Swollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 193278Swollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 203278Swollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 213278Swollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 223278Swollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 233278Swollman * 248296Sdg * $Id: if_de.c,v 1.12 1995/05/05 19:44:06 thomas Exp $ 253278Swollman * 263278Swollman */ 273278Swollman 283278Swollman/* 293278Swollman * DEC DC21040 PCI Ethernet Controller 303278Swollman * 313278Swollman * Written by Matt Thomas 323278Swollman * BPF support code stolen directly from if_ec.c 333278Swollman * 343278Swollman * This driver supports the DEC DE435 or any other PCI 358296Sdg * board which support DC21040 or DC21140 (mostly). 363278Swollman */ 373278Swollman 387229Sse#define __IF_DE_C__ "pl2 95/03/21" 398296Sdg#ifndef __bsdi__ 404772Sdg#include "de.h" 418296Sdg#endif 428296Sdg#if NDE > 0 || defined(__bsdi__) 433278Swollman 444772Sdg#include <sys/param.h> 454772Sdg#include <sys/systm.h> 464772Sdg#include <sys/mbuf.h> 474772Sdg#include <sys/protosw.h> 484772Sdg#include <sys/socket.h> 494772Sdg#include <sys/ioctl.h> 504772Sdg#include <sys/errno.h> 514772Sdg#include <sys/malloc.h> 526132Sdg#include <sys/kernel.h> 537089Sse#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */ 548296Sdg#if defined(__FreeBSD__) 557104Sdg#include <sys/devconf.h> 566132Sdg#include <machine/clock.h> 578296Sdg#endif 588296Sdg#if defined(__bsdi__) 598296Sdg#include <sys/device.h> 608296Sdg#endif 613278Swollman 623278Swollman#include <net/if.h> 633278Swollman#include <net/if_types.h> 643278Swollman#include <net/if_dl.h> 653278Swollman#include <net/route.h> 663278Swollman 674772Sdg#include "bpfilter.h" 683278Swollman#if NBPFILTER > 0 693278Swollman#include <net/bpf.h> 703278Swollman#include <net/bpfdesc.h> 713278Swollman#endif 723278Swollman 733278Swollman#ifdef INET 743278Swollman#include <netinet/in.h> 753278Swollman#include <netinet/in_systm.h> 763278Swollman#include <netinet/in_var.h> 773278Swollman#include <netinet/ip.h> 783278Swollman#include <netinet/if_ether.h> 793278Swollman#endif 803278Swollman 813278Swollman#ifdef NS 823278Swollman#include <netns/ns.h> 833278Swollman#include <netns/ns_if.h> 843278Swollman#endif 853278Swollman 863278Swollman#include <vm/vm.h> 873278Swollman#include <vm/vm_kern.h> 883278Swollman#include <vm/vm_param.h> 893278Swollman 908296Sdg#if defined(__FreeBSD__) 913278Swollman#include <pci.h> 923278Swollman#if NPCI > 0 936132Sdg#include <pci/pcivar.h> 948296Sdg#include <pci/dc21040.h> 953278Swollman#endif 968296Sdg#endif 976132Sdg 988296Sdg#if defined(__bsdi__) 998296Sdg#include <i386/pci/pci.h> 1008296Sdg#include <i386/pci/dc21040.h> 1018296Sdg#include <i386/isa/isa.h> 1028296Sdg#include <i386/isa/icu.h> 1038296Sdg#include <i386/isa/dma.h> 1048296Sdg#include <i386/isa/isavar.h> 1058296Sdg#endif 1063278Swollman 1073278Swollman/* 1087689Sdg * This module supports 1097689Sdg * the DEC DC21040 PCI Ethernet Controller. 1107689Sdg * the DEC DC21140 PCI Fast Ethernet Controller. 1113278Swollman */ 1123278Swollman 1133278Swollmantypedef struct { 1143278Swollman unsigned long addr; 1153278Swollman unsigned long length; 1163278Swollman} tulip_addrvec_t; 1173278Swollman 1183278Swollmantypedef struct { 1193278Swollman tulip_desc_t *ri_first; 1203278Swollman tulip_desc_t *ri_last; 1213278Swollman tulip_desc_t *ri_nextin; 1223278Swollman tulip_desc_t *ri_nextout; 1233278Swollman int ri_max; 1243278Swollman int ri_free; 1253278Swollman} tulip_ringinfo_t; 1263278Swollman 1273278Swollmantypedef struct { 1283278Swollman volatile tulip_uint32_t *csr_busmode; /* CSR0 */ 1293278Swollman volatile tulip_uint32_t *csr_txpoll; /* CSR1 */ 1303278Swollman volatile tulip_uint32_t *csr_rxpoll; /* CSR2 */ 1313278Swollman volatile tulip_uint32_t *csr_rxlist; /* CSR3 */ 1323278Swollman volatile tulip_uint32_t *csr_txlist; /* CSR4 */ 1333278Swollman volatile tulip_uint32_t *csr_status; /* CSR5 */ 1343278Swollman volatile tulip_uint32_t *csr_command; /* CSR6 */ 1353278Swollman volatile tulip_uint32_t *csr_intr; /* CSR7 */ 1363278Swollman volatile tulip_uint32_t *csr_missed_frame; /* CSR8 */ 1377689Sdg 1387689Sdg /* DC21040 specific registers */ 1397689Sdg 1403278Swollman volatile tulip_sint32_t *csr_enetrom; /* CSR9 */ 1413278Swollman volatile tulip_uint32_t *csr_reserved; /* CSR10 */ 1423278Swollman volatile tulip_uint32_t *csr_full_duplex; /* CSR11 */ 1433278Swollman volatile tulip_uint32_t *csr_sia_status; /* CSR12 */ 1443278Swollman volatile tulip_uint32_t *csr_sia_connectivity; /* CSR13 */ 1453278Swollman volatile tulip_uint32_t *csr_sia_tx_rx; /* CSR14 */ 1463278Swollman volatile tulip_uint32_t *csr_sia_general; /* CSR15 */ 1477689Sdg 1487689Sdg /* DC21140/DC21041 specific registers */ 1497689Sdg 1507689Sdg volatile tulip_uint32_t *csr_srom_mii; /* CSR9 */ 1517689Sdg volatile tulip_uint32_t *csr_gp_timer; /* CSR11 */ 1527689Sdg volatile tulip_uint32_t *csr_gp; /* CSR12 */ 1537689Sdg volatile tulip_uint32_t *csr_watchdog; /* CSR15 */ 1543278Swollman} tulip_regfile_t; 1553278Swollman 1563278Swollman/* 1573278Swollman * The DC21040 has a stupid restriction in that the receive 1583278Swollman * buffers must be longword aligned. But since Ethernet 1593278Swollman * headers are not a multiple of longwords in size this forces 1603278Swollman * the data to non-longword aligned. Since IP requires the 1614772Sdg * data to be longword aligned, we need to copy it after it has 1623278Swollman * been DMA'ed in our memory. 1633278Swollman * 1643278Swollman * Since we have to copy it anyways, we might as well as allocate 1653278Swollman * dedicated receive space for the input. This allows to use a 1663278Swollman * small receive buffer size and more ring entries to be able to 1674772Sdg * better keep with a flood of tiny Ethernet packets. 1683278Swollman * 1693278Swollman * The receive space MUST ALWAYS be a multiple of the page size. 1703278Swollman * And the number of receive descriptors multiplied by the size 1713278Swollman * of the receive buffers must equal the recevive space. This 1724772Sdg * is so that we can manipulate the page tables so that even if a 1733278Swollman * packet wraps around the end of the receive space, we can 1743278Swollman * treat it as virtually contiguous. 1757689Sdg * 1767689Sdg * The above used to be true (the stupid restriction is still true) 1777689Sdg * but we gone to directly DMA'ing into MBUFs because with 100Mb 1787689Sdg * cards the copying is just too much of a hit. 1793278Swollman */ 1807689Sdg#define TULIP_RXDESCS 16 1813278Swollman#define TULIP_TXDESCS 128 1827689Sdg#define TULIP_RXQ_TARGET 8 1833278Swollman 1847791Sdgtypedef enum { 1857791Sdg TULIP_DC21040_GENERIC, 1867791Sdg TULIP_DC21140_DEC_EB, 1878296Sdg TULIP_DC21140_DEC_DE500, 1888296Sdg TULIP_DC21140_COGENT_EM100 1897791Sdg} tulip_board_t; 1907791Sdg 1917791Sdgtypedef struct _tulip_softc_t tulip_softc_t; 1927791Sdg 1933278Swollmantypedef struct { 1947791Sdg tulip_board_t bd_type; 1957791Sdg const char *bd_description; 1967791Sdg int (*bd_media_probe)(tulip_softc_t *sc); 1977791Sdg void (*bd_media_select)(tulip_softc_t *sc); 1987791Sdg} tulip_boardsw_t; 1997791Sdg 2008296Sdgtypedef enum { TULIP_DC21040, TULIP_DC21140, TULIP_DC21041 } tulip_chipid_t; 2017791Sdg 2027791Sdgstruct _tulip_softc_t { 2038296Sdg#if defined(__bsdi__) 2048296Sdg struct device tulip_dev; /* base device */ 2058296Sdg struct isadev tulip_id; /* ISA device */ 2068296Sdg struct intrhand tulip_ih; /* intrrupt vectoring */ 2078296Sdg struct atshutdown tulip_ats; /* shutdown routine */ 2088296Sdg#endif 2093278Swollman struct arpcom tulip_ac; 2103278Swollman tulip_regfile_t tulip_csrs; 2113278Swollman unsigned tulip_flags; 2123278Swollman#define TULIP_WANTSETUP 0x01 2133278Swollman#define TULIP_WANTHASH 0x02 2143278Swollman#define TULIP_DOINGSETUP 0x04 2153278Swollman#define TULIP_ALTPHYS 0x08 /* use AUI */ 2167689Sdg unsigned char tulip_rombuf[128]; 2173278Swollman tulip_uint32_t tulip_setupbuf[192/sizeof(tulip_uint32_t)]; 2183278Swollman tulip_uint32_t tulip_setupdata[192/sizeof(tulip_uint32_t)]; 2193278Swollman tulip_uint32_t tulip_intrmask; 2203278Swollman tulip_uint32_t tulip_cmdmode; 2213278Swollman tulip_uint32_t tulip_revinfo; 2228296Sdg tulip_chipid_t tulip_chipid; 2237791Sdg const tulip_boardsw_t *tulip_boardsw; 2248296Sdg#if NBPFILTER > 0 && !defined(__bsdi__) && !defined(__FreeBSD__) 2253278Swollman caddr_t tulip_bpf; /* BPF context */ 2263278Swollman#endif 2273278Swollman struct ifqueue tulip_txq; 2287689Sdg struct ifqueue tulip_rxq; 2293278Swollman tulip_ringinfo_t tulip_rxinfo; 2303278Swollman tulip_ringinfo_t tulip_txinfo; 2317791Sdg}; 2323278Swollman 2333278Swollman#ifndef IFF_ALTPHYS 2348296Sdg#define IFF_ALTPHYS IFF_LINK0 /* In case it isn't defined */ 2353278Swollman#endif 2363543Sseconst char *tulip_chipdescs[] = { 2373543Sse "DC21040 [10Mb/s]", 2387791Sdg "DC21140 [10-100Mb/s]", 2397689Sdg "DC21041 [10Mb/s]" 2403543Sse}; 2413543Sse 2428296Sdg#if defined(__FreeBSD__) 2438296Sdgtypedef void ifnet_ret_t; 2443278Swollmantulip_softc_t *tulips[NDE]; 2458296Sdg#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit]) 2468296Sdg#define tulip_bpf tulip_ac.ac_if.if_bpf 2478296Sdg#endif 2488296Sdg#if defined(__bsdi__) 2498296Sdgtypedef int ifnet_ret_t; 2508296Sdgextern struct cfdriver decd; 2518296Sdg#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) 2528296Sdg#define tulip_bpf tulip_ac.ac_if.if_bpf 2538296Sdg#endif 2543278Swollman 2553278Swollman#define tulip_if tulip_ac.ac_if 2563278Swollman#define tulip_unit tulip_ac.ac_if.if_unit 2573278Swollman#define tulip_name tulip_ac.ac_if.if_name 2583278Swollman#define tulip_hwaddr tulip_ac.ac_enaddr 2593278Swollman 2603278Swollman#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ 2613278Swollman#define TULIP_CHECK_RXCRC 0 2624772Sdg#define TULIP_MAX_TXSEG 30 2633278Swollman 2643278Swollman#define TULIP_ADDREQUAL(a1, a2) \ 2653278Swollman (((u_short *)a1)[0] == ((u_short *)a2)[0] \ 2664772Sdg && ((u_short *)a1)[1] == ((u_short *)a2)[1] \ 2674772Sdg && ((u_short *)a1)[2] == ((u_short *)a2)[2]) 2683278Swollman#define TULIP_ADDRBRDCST(a1) \ 2693278Swollman (((u_short *)a1)[0] == 0xFFFFU \ 2704772Sdg && ((u_short *)a1)[1] == 0xFFFFU \ 2714772Sdg && ((u_short *)a1)[2] == 0xFFFFU) 2723278Swollman 2738296Sdgstatic ifnet_ret_t tulip_start(struct ifnet *ifp); 2747689Sdgstatic void tulip_rx_intr(tulip_softc_t *sc); 2753278Swollmanstatic void tulip_addr_filter(tulip_softc_t *sc); 2763278Swollman 2778296Sdg#if __FreeBSD__ > 1 || defined(__bsdi__) 2783278Swollman#define TULIP_IFRESET_ARGS int unit 2793278Swollman#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit) 2803278Swollman#else 2813278Swollman#define TULIP_IFRESET_ARGS int unit, int uban 2823278Swollman#define TULIP_RESET(sc) tulip_reset((sc)->tulip_unit, 0) 2833278Swollman#endif 2843278Swollman 2857791Sdg 2867791Sdgstatic int 2877791Sdgtulip_dc21040_media_probe( 2887791Sdg tulip_softc_t *sc) 2897791Sdg{ 2907791Sdg int cnt; 2917791Sdg 2927791Sdg *sc->tulip_csrs.csr_sia_connectivity = 0; 2937791Sdg *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 2947791Sdg for (cnt = 0; cnt < 2400; cnt++) { 2957791Sdg if ((*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) == 0) 2967791Sdg break; 2977791Sdg DELAY(1000); 2987791Sdg } 2997791Sdg return (*sc->tulip_csrs.csr_sia_status & TULIP_SIASTS_LINKFAIL) != 0; 3007791Sdg} 3017791Sdg 3023278Swollmanstatic void 3037791Sdgtulip_dc21040_media_select( 3047791Sdg tulip_softc_t *sc) 3057791Sdg{ 3067791Sdg sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT; 3077791Sdg *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_RESET; 3087791Sdg if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 3097791Sdg if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 3107791Sdg printf("%s%d: enabling Thinwire/AUI port\n", 3117791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 3127791Sdg *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_AUI; 3137791Sdg sc->tulip_flags |= TULIP_ALTPHYS; 3147791Sdg } else { 3157791Sdg if (sc->tulip_flags & TULIP_ALTPHYS) 3167791Sdg printf("%s%d: enabling 10baseT/UTP port\n", 3177791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 3187791Sdg *sc->tulip_csrs.csr_sia_connectivity = TULIP_SIACONN_10BASET; 3197791Sdg sc->tulip_flags &= ~TULIP_ALTPHYS; 3207791Sdg } 3217791Sdg} 3227791Sdg 3237791Sdgstatic const tulip_boardsw_t tulip_dc21040_boardsw = { 3247791Sdg TULIP_DC21040_GENERIC, 3257791Sdg "", 3267791Sdg tulip_dc21040_media_probe, 3277791Sdg tulip_dc21040_media_select 3287791Sdg}; 3297791Sdg 3307791Sdgstatic int 3317791Sdgtulip_dc21140_evalboard_media_probe( 3327791Sdg tulip_softc_t *sc) 3337791Sdg{ 3347791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EB_PINS; 3357791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EB_INIT; 3367791Sdg *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 3377791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 3387791Sdg *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 3397791Sdg DELAY(1000000); 3407791Sdg return (*sc->tulip_csrs.csr_gp & TULIP_GP_EB_OK100) != 0; 3417791Sdg} 3427791Sdg 3437791Sdgstatic void 3447791Sdgtulip_dc21140_evalboard_media_select( 3457791Sdg tulip_softc_t *sc) 3467791Sdg{ 3477791Sdg sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 3487791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EB_PINS; 3497791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EB_INIT; 3507791Sdg if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 3517791Sdg if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 3527791Sdg printf("%s%d: enabling 100baseTX UTP port\n", 3537791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 3547791Sdg sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 3557791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 3567791Sdg sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 3577791Sdg sc->tulip_flags |= TULIP_ALTPHYS; 3587791Sdg } else { 3597791Sdg if (sc->tulip_flags & TULIP_ALTPHYS) 3607791Sdg printf("%s%d: enabling 10baseT UTP port\n", 3617791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 3627791Sdg sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 3637791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 3647791Sdg sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 3657791Sdg sc->tulip_flags &= ~TULIP_ALTPHYS; 3667791Sdg } 3677791Sdg} 3687791Sdg 3697791Sdgstatic const tulip_boardsw_t tulip_dc21140_eb_boardsw = { 3707791Sdg TULIP_DC21140_DEC_EB, 3717791Sdg "", 3727791Sdg tulip_dc21140_evalboard_media_probe, 3737791Sdg tulip_dc21140_evalboard_media_select 3747791Sdg}; 3757791Sdg 3768296Sdg 3777791Sdgstatic int 3788296Sdgtulip_dc21140_cogent_em100_media_probe( 3798296Sdg tulip_softc_t *sc) 3808296Sdg{ 3818296Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_PINS; 3828296Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_INIT; 3838296Sdg *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 3848296Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 3858296Sdg *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 3868296Sdg return 1; 3878296Sdg} 3888296Sdg 3898296Sdgstatic void 3908296Sdgtulip_dc21140_cogent_em100_media_select( 3918296Sdg tulip_softc_t *sc) 3928296Sdg{ 3938296Sdg sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 3948296Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_PINS; 3958296Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_EM100_INIT; 3968296Sdg if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 3978296Sdg printf("%s%d: enabling 100baseTX UTP port\n", 3988296Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 3998296Sdg sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 4008296Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 4018296Sdg sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 4028296Sdg sc->tulip_flags |= TULIP_ALTPHYS; 4038296Sdg} 4048296Sdg 4058296Sdgstatic const tulip_boardsw_t tulip_dc21140_cogent_em100_boardsw = { 4068296Sdg TULIP_DC21140_COGENT_EM100, 4078296Sdg "Cogent EM100", 4088296Sdg tulip_dc21140_cogent_em100_media_probe, 4098296Sdg tulip_dc21140_cogent_em100_media_select 4108296Sdg}; 4118296Sdg 4128296Sdgstatic int 4137791Sdgtulip_dc21140_de500_media_probe( 4147791Sdg tulip_softc_t *sc) 4157791Sdg{ 4167791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_PINS; 4178296Sdg DELAY(1000); 4187791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX; 4197791Sdg if ((*sc->tulip_csrs.csr_gp & (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) != (TULIP_GP_DE500_NOTOK_100|TULIP_GP_DE500_NOTOK_10)) 4208296Sdg return (*sc->tulip_csrs.csr_gp & TULIP_GP_DE500_NOTOK_100) != 0; 4217791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX|TULIP_GP_DE500_FORCE_100; 4227791Sdg *sc->tulip_csrs.csr_command |= TULIP_CMD_PORTSELECT 4237791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_MUSTBEONE; 4247791Sdg *sc->tulip_csrs.csr_command &= ~TULIP_CMD_TXTHRSHLDCTL; 4257791Sdg DELAY(1000000); 4268296Sdg return (*sc->tulip_csrs.csr_gp & TULIP_GP_DE500_NOTOK_100) != 0; 4277791Sdg} 4287791Sdg 4297791Sdgstatic void 4307791Sdgtulip_dc21140_de500_media_select( 4317791Sdg tulip_softc_t *sc) 4327791Sdg{ 4337791Sdg sc->tulip_cmdmode |= TULIP_CMD_STOREFWD|TULIP_CMD_MUSTBEONE; 4347791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_PINS; 4357791Sdg if (sc->tulip_if.if_flags & IFF_ALTPHYS) { 4367791Sdg if ((sc->tulip_flags & TULIP_ALTPHYS) == 0) 4377791Sdg printf("%s%d: enabling 100baseTX UTP port\n", 4387791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 4397791Sdg sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT 4407791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER; 4417791Sdg sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; 4427791Sdg sc->tulip_flags |= TULIP_ALTPHYS; 4437791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX 4447791Sdg |TULIP_GP_DE500_FORCE_100; 4457791Sdg } else { 4467791Sdg if (sc->tulip_flags & TULIP_ALTPHYS) 4477791Sdg printf("%s%d: enabling 10baseT UTP port\n", 4487791Sdg sc->tulip_if.if_name, sc->tulip_if.if_unit); 4497791Sdg sc->tulip_cmdmode &= ~(TULIP_CMD_PORTSELECT 4507791Sdg |TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER); 4517791Sdg sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; 4527791Sdg sc->tulip_flags &= ~TULIP_ALTPHYS; 4537791Sdg *sc->tulip_csrs.csr_gp = TULIP_GP_DE500_HALFDUPLEX; 4547791Sdg } 4557791Sdg} 4567791Sdg 4577791Sdgstatic const tulip_boardsw_t tulip_dc21140_de500_boardsw = { 4587791Sdg TULIP_DC21140_DEC_DE500, "Digital DE500 ", 4597791Sdg tulip_dc21140_de500_media_probe, 4607791Sdg tulip_dc21140_de500_media_select 4617791Sdg}; 4627791Sdg 4638296Sdgstatic ifnet_ret_t 4643278Swollmantulip_reset( 4653278Swollman TULIP_IFRESET_ARGS) 4663278Swollman{ 4678296Sdg tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(unit); 4683278Swollman tulip_ringinfo_t *ri; 4693278Swollman tulip_desc_t *di; 4703278Swollman 4713278Swollman *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 4723278Swollman DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 4733278Swollman 33MHz that comes to two microseconds but wait a 4743278Swollman bit longer anyways) */ 4753278Swollman 4767791Sdg (*sc->tulip_boardsw->bd_media_select)(sc); 4777791Sdg 4783278Swollman *sc->tulip_csrs.csr_txlist = vtophys(&sc->tulip_txinfo.ri_first[0]); 4793278Swollman *sc->tulip_csrs.csr_rxlist = vtophys(&sc->tulip_rxinfo.ri_first[0]); 4803278Swollman *sc->tulip_csrs.csr_intr = 0; 4817689Sdg *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_BURSTLEN_8LW 4827689Sdg |TULIP_BUSMODE_CACHE_ALIGN8 4837689Sdg |(BYTE_ORDER != LITTLE_ENDIAN 4847689Sdg ? TULIP_BUSMODE_BIGENDIAN 4857689Sdg : 0); 4863278Swollman 4873278Swollman sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; 4883278Swollman /* 4893278Swollman * Free all the mbufs that were on the transmit ring. 4903278Swollman */ 4913278Swollman for (;;) { 4923278Swollman struct mbuf *m; 4933278Swollman IF_DEQUEUE(&sc->tulip_txq, m); 4943278Swollman if (m == NULL) 4953278Swollman break; 4963278Swollman m_freem(m); 4973278Swollman } 4983278Swollman 4993278Swollman ri = &sc->tulip_txinfo; 5003278Swollman ri->ri_nextin = ri->ri_nextout = ri->ri_first; 5013278Swollman ri->ri_free = ri->ri_max; 5023278Swollman for (di = ri->ri_first; di < ri->ri_last; di++) 5033278Swollman di->d_status = 0; 5043278Swollman 5053278Swollman /* 5063278Swollman * We need to collect all the mbufs were on the 5073278Swollman * receive ring before we reinit it either to put 5083278Swollman * them back on or to know if we have to allocate 5093278Swollman * more. 5103278Swollman */ 5113278Swollman ri = &sc->tulip_rxinfo; 5123278Swollman ri->ri_nextin = ri->ri_nextout = ri->ri_first; 5133278Swollman ri->ri_free = ri->ri_max; 5147689Sdg for (di = ri->ri_first; di < ri->ri_last; di++) { 5157689Sdg di->d_status = 0; 5167689Sdg di->d_length1 = 0; di->d_addr1 = 0; 5173278Swollman di->d_length2 = 0; di->d_addr2 = 0; 5183278Swollman } 5197689Sdg for (;;) { 5207689Sdg struct mbuf *m; 5217689Sdg IF_DEQUEUE(&sc->tulip_rxq, m); 5227689Sdg if (m == NULL) 5237689Sdg break; 5247689Sdg m_freem(m); 5257689Sdg } 5263278Swollman 5273278Swollman sc->tulip_intrmask = TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR 5283278Swollman |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED 5293278Swollman |TULIP_STS_TXBABBLE|TULIP_STS_LINKFAIL|TULIP_STS_RXSTOPPED; 5303278Swollman sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP); 5313278Swollman tulip_addr_filter(sc); 5323278Swollman} 5333278Swollman 5348296Sdgstatic ifnet_ret_t 5353278Swollmantulip_init( 5363278Swollman int unit) 5373278Swollman{ 5388296Sdg tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(unit); 5393278Swollman 5403278Swollman if (sc->tulip_if.if_flags & IFF_UP) { 5413278Swollman sc->tulip_if.if_flags |= IFF_RUNNING; 5423278Swollman if (sc->tulip_if.if_flags & IFF_PROMISC) { 5433278Swollman sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; 5443278Swollman } else { 5453278Swollman sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; 5463278Swollman if (sc->tulip_if.if_flags & IFF_ALLMULTI) { 5473278Swollman sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; 5483278Swollman } else { 5493278Swollman sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; 5503278Swollman } 5513278Swollman } 5523278Swollman sc->tulip_cmdmode |= TULIP_CMD_TXRUN; 5533278Swollman if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 5547689Sdg tulip_rx_intr(sc); 5553278Swollman sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 5563278Swollman sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 5573278Swollman } else { 5583278Swollman sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 5593278Swollman tulip_start(&sc->tulip_if); 5603278Swollman } 5613533Sse sc->tulip_cmdmode |= TULIP_CMD_THRSHLD160; 5623278Swollman *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 5633278Swollman *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 5643278Swollman } else { 5653278Swollman TULIP_RESET(sc); 5663278Swollman sc->tulip_if.if_flags &= ~IFF_RUNNING; 5673278Swollman } 5683278Swollman} 5693278Swollman 5703278Swollman 5713278Swollman#if TULIP_CHECK_RXCRC 5723278Swollmanstatic unsigned 5733278Swollmantulip_crc32( 5743278Swollman u_char *addr, 5753278Swollman int len) 5763278Swollman{ 5773278Swollman unsigned int crc = 0xFFFFFFFF; 5783278Swollman static unsigned int crctbl[256]; 5793278Swollman int idx; 5803278Swollman static int done; 5813278Swollman /* 5823278Swollman * initialize the multicast address CRC table 5833278Swollman */ 5843278Swollman for (idx = 0; !done && idx < 256; idx++) { 5853278Swollman unsigned int tmp = idx; 5863278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5873278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5883278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5893278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5903278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5913278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5923278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5933278Swollman tmp = (tmp >> 1) ^ (tmp & 1 ? TULIP_CRC32_POLY : 0); /* XOR */ 5943278Swollman crctbl[idx] = tmp; 5953278Swollman } 5963278Swollman done = 1; 5973278Swollman 5983278Swollman while (len-- > 0) 5993278Swollman crc = (crc >> 8) ^ crctbl[*addr++] ^ crctbl[crc & 0xFF]; 6003278Swollman 6013278Swollman return crc; 6023278Swollman} 6033278Swollman#endif 6043278Swollman 6053278Swollmanstatic void 6063278Swollmantulip_rx_intr( 6073278Swollman tulip_softc_t *sc) 6083278Swollman{ 6093278Swollman tulip_ringinfo_t *ri = &sc->tulip_rxinfo; 6104322Sdg struct ifnet *ifp = &sc->tulip_if; 6113278Swollman 6124322Sdg for (;;) { 6137689Sdg struct ether_header eh; 6147689Sdg tulip_desc_t *eop = ri->ri_nextin; 6157689Sdg int total_len = 0; 6167689Sdg struct mbuf *m = NULL; 6177689Sdg int accept = 0; 6183278Swollman 6197689Sdg if (sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) 6207689Sdg goto queue_mbuf; 6217689Sdg 6227689Sdg if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) 6237689Sdg break; 6243278Swollman 6253278Swollman total_len = ((eop->d_status >> 16) & 0x7FF) - 4; 6267689Sdg IF_DEQUEUE(&sc->tulip_rxq, m); 6273278Swollman if ((eop->d_status & TULIP_DSTS_ERRSUM) == 0) { 6283278Swollman 6293278Swollman#if TULIP_CHECK_RXCRC 6307689Sdg unsigned crc = tulip_crc32(mtod(m, unsigned char *), total_len); 6313278Swollman if (~crc != *((unsigned *) &bufaddr[total_len])) { 6324322Sdg printf("de0: bad rx crc: %08x [rx] != %08x\n", 6333278Swollman *((unsigned *) &bufaddr[total_len]), ~crc); 6343278Swollman goto next; 6353278Swollman } 6363278Swollman#endif 6377689Sdg eh = *mtod(m, struct ether_header *); 6383278Swollman#if NBPFILTER > 0 6393278Swollman if (sc->tulip_bpf != NULL) { 6407689Sdg bpf_tap(sc->tulip_bpf, mtod(m, caddr_t), total_len); 6413278Swollman if ((eh.ether_dhost[0] & 1) == 0 && 6423278Swollman !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr)) 6433278Swollman goto next; 6443278Swollman } else if (!TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_ac.ac_enaddr) 6453278Swollman && !TULIP_ADDRBRDCST(eh.ether_dhost)) { 6463278Swollman goto next; 6473278Swollman } 6483278Swollman#endif 6497689Sdg accept = 1; 6503278Swollman } else { 6514322Sdg ifp->if_ierrors++; 6523278Swollman } 6537689Sdg next: 6544322Sdg ifp->if_ipackets++; 6557689Sdg if (++ri->ri_nextin == ri->ri_last) 6567689Sdg ri->ri_nextin = ri->ri_first; 6577689Sdg queue_mbuf: 6587689Sdg /* 6597689Sdg * Either we are priming the TULIP with mbufs (m == NULL) 6607689Sdg * or we are about to accept an mbuf for the upper layers 6617689Sdg * so we need to allocate an mbuf to replace it. If we 6627689Sdg * can't replace, then count it as an input error and reuse 6637689Sdg * the mbuf. 6647689Sdg */ 6657689Sdg if (accept || m == NULL) { 6667689Sdg struct mbuf *m0; 6677689Sdg MGETHDR(m0, M_DONTWAIT, MT_DATA); 6687689Sdg if (m0 != NULL) { 6697689Sdg MCLGET(m0, M_DONTWAIT); 6707689Sdg if ((m0->m_flags & M_EXT) == 0) { 6717689Sdg m_freem(m0); 6727689Sdg m0 = NULL; 6737689Sdg } 6747689Sdg } 6757689Sdg if (accept) { 6767689Sdg if (m0 != NULL) { 6777689Sdg m->m_pkthdr.rcvif = ifp; 6787689Sdg m->m_data += sizeof(struct ether_header); 6797689Sdg m->m_len = m->m_pkthdr.len = total_len; 6808296Sdg#if defined(__bsdi__) 6818296Sdg eh.ether_type = ntohs(eh.ether_type); 6828296Sdg#endif 6837689Sdg ether_input(ifp, &eh, m); 6847689Sdg m = m0; 6857689Sdg } else { 6867689Sdg ifp->if_ierrors++; 6877689Sdg } 6887689Sdg } else { 6897689Sdg m = m0; 6907689Sdg } 6913278Swollman } 6927689Sdg if (m == NULL) 6937689Sdg break; 6947689Sdg /* 6957689Sdg * Now give the buffer to the TULIP and save in our 6967689Sdg * receive queue. 6977689Sdg */ 6987689Sdg ri->ri_nextout->d_length1 = MCLBYTES - 4; 6997689Sdg ri->ri_nextout->d_addr1 = vtophys(mtod(m, caddr_t)); 7007689Sdg ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 7017689Sdg if (++ri->ri_nextout == ri->ri_last) 7027689Sdg ri->ri_nextout = ri->ri_first; 7037689Sdg IF_ENQUEUE(&sc->tulip_rxq, m); 7043278Swollman } 7053278Swollman} 7063278Swollman 7073278Swollmanstatic int 7083278Swollmantulip_tx_intr( 7093278Swollman tulip_softc_t *sc) 7103278Swollman{ 7113278Swollman tulip_ringinfo_t *ri = &sc->tulip_txinfo; 7123278Swollman struct mbuf *m; 7133278Swollman int xmits = 0; 7143278Swollman 7153278Swollman while (ri->ri_free < ri->ri_max) { 7163278Swollman if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) 7173278Swollman break; 7183278Swollman 7193278Swollman if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxLASTSEG) { 7203278Swollman if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxSETUPPKT) { 7213278Swollman /* 7223278Swollman * We've just finished processing a setup packet. 7233278Swollman * Mark that we can finished it. If there's not 7243278Swollman * another pending, startup the TULIP receiver. 7254772Sdg * Make sure we ack the RXSTOPPED so we won't get 7264772Sdg * an abormal interrupt indication. 7273278Swollman */ 7283278Swollman sc->tulip_flags &= ~TULIP_DOINGSETUP; 7293278Swollman if ((sc->tulip_flags & TULIP_WANTSETUP) == 0) { 7307689Sdg tulip_rx_intr(sc); 7313278Swollman sc->tulip_cmdmode |= TULIP_CMD_RXRUN; 7323278Swollman sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; 7334772Sdg *sc->tulip_csrs.csr_status = TULIP_STS_RXSTOPPED; 7343278Swollman *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 7353278Swollman *sc->tulip_csrs.csr_intr = sc->tulip_intrmask; 7363278Swollman } 7373278Swollman } else { 7383278Swollman IF_DEQUEUE(&sc->tulip_txq, m); 7393278Swollman m_freem(m); 7403278Swollman sc->tulip_if.if_collisions += 7413278Swollman (ri->ri_nextin->d_status & TULIP_DSTS_TxCOLLMASK) 7423278Swollman >> TULIP_DSTS_V_TxCOLLCNT; 7433278Swollman if (ri->ri_nextin->d_status & TULIP_DSTS_ERRSUM) 7443278Swollman sc->tulip_if.if_oerrors++; 7453278Swollman xmits++; 7463278Swollman } 7473278Swollman } 7483278Swollman 7493278Swollman if (++ri->ri_nextin == ri->ri_last) 7503278Swollman ri->ri_nextin = ri->ri_first; 7513278Swollman ri->ri_free++; 7523278Swollman sc->tulip_if.if_flags &= ~IFF_OACTIVE; 7533278Swollman } 7543278Swollman sc->tulip_if.if_opackets += xmits; 7553278Swollman return xmits; 7563278Swollman} 7573278Swollman 7583278Swollmanstatic int 7593278Swollmantulip_txsegment( 7603278Swollman tulip_softc_t *sc, 7613278Swollman struct mbuf *m, 7623278Swollman tulip_addrvec_t *avp, 7633278Swollman size_t maxseg) 7643278Swollman{ 7653278Swollman int segcnt; 7663278Swollman 7673278Swollman for (segcnt = 0; m; m = m->m_next) { 7683278Swollman int len = m->m_len; 7693278Swollman caddr_t addr = mtod(m, caddr_t); 7703278Swollman unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); 7713278Swollman 7723278Swollman while (len > 0) { 7733278Swollman unsigned slen = min(len, clsize); 7743278Swollman if (segcnt < maxseg) { 7753278Swollman avp->addr = vtophys(addr); 7763278Swollman avp->length = slen; 7773278Swollman } 7783278Swollman len -= slen; 7793278Swollman addr += slen; 7803278Swollman clsize = CLBYTES; 7813278Swollman avp++; 7823278Swollman segcnt++; 7833278Swollman } 7843278Swollman } 7853278Swollman if (segcnt >= maxseg) { 7864772Sdg printf("%s%d: tulip_txsegment: extremely fragmented packet encountered (%d segments)\n", 7873278Swollman sc->tulip_name, sc->tulip_unit, segcnt); 7883278Swollman return -1; 7893278Swollman } 7903278Swollman avp->addr = 0; 7913278Swollman avp->length = 0; 7923278Swollman return segcnt; 7933278Swollman} 7943278Swollman 7958296Sdgstatic ifnet_ret_t 7963278Swollmantulip_start( 7973278Swollman struct ifnet *ifp) 7983278Swollman{ 7998296Sdg tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit); 8003278Swollman struct ifqueue *ifq = &ifp->if_snd; 8013278Swollman tulip_ringinfo_t *ri = &sc->tulip_txinfo; 8023278Swollman tulip_desc_t *sop, *eop; 8033278Swollman struct mbuf *m; 8043278Swollman tulip_addrvec_t addrvec[TULIP_MAX_TXSEG+1], *avp; 8053278Swollman int segcnt; 8063278Swollman tulip_uint32_t d_status; 8073278Swollman 8083278Swollman if ((ifp->if_flags & IFF_RUNNING) == 0) 8093278Swollman return; 8103278Swollman 8113278Swollman for (;;) { 8123278Swollman if (sc->tulip_flags & TULIP_WANTSETUP) { 8133278Swollman if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { 8143278Swollman ifp->if_flags |= IFF_OACTIVE; 8153278Swollman return; 8163278Swollman } 8173278Swollman bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, 8183278Swollman sizeof(sc->tulip_setupbuf)); 8193278Swollman sc->tulip_flags &= ~TULIP_WANTSETUP; 8203278Swollman sc->tulip_flags |= TULIP_DOINGSETUP; 8213278Swollman ri->ri_free--; 8223278Swollman ri->ri_nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 8233278Swollman ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG 8243278Swollman |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; 8253278Swollman if (sc->tulip_flags & TULIP_WANTHASH) 8263278Swollman ri->ri_nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; 8273278Swollman ri->ri_nextout->d_length1 = sizeof(sc->tulip_setupbuf); 8283278Swollman ri->ri_nextout->d_addr1 = vtophys(sc->tulip_setupbuf); 8293278Swollman ri->ri_nextout->d_length2 = 0; 8303278Swollman ri->ri_nextout->d_addr2 = 0; 8313278Swollman ri->ri_nextout->d_status = TULIP_DSTS_OWNER; 8323278Swollman *sc->tulip_csrs.csr_txpoll = 1; 8333278Swollman /* 8343278Swollman * Advance the ring for the next transmit packet. 8353278Swollman */ 8363278Swollman if (++ri->ri_nextout == ri->ri_last) 8373278Swollman ri->ri_nextout = ri->ri_first; 8383278Swollman } 8393278Swollman 8403278Swollman IF_DEQUEUE(ifq, m); 8413278Swollman if (m == NULL) 8423278Swollman break; 8433278Swollman 8443278Swollman /* 8453278Swollman * First find out how many and which different pages 8463278Swollman * the mbuf data occupies. Then check to see if we 8473278Swollman * have enough descriptor space in our transmit ring 8483278Swollman * to actually send it. 8493278Swollman */ 8503278Swollman segcnt = tulip_txsegment(sc, m, addrvec, 8513278Swollman min(ri->ri_max - 1, TULIP_MAX_TXSEG)); 8523278Swollman if (segcnt < 0) { 8533278Swollman struct mbuf *m0; 8543278Swollman MGETHDR(m0, M_DONTWAIT, MT_DATA); 8553278Swollman if (m0 != NULL) { 8563278Swollman if (m->m_pkthdr.len > MHLEN) { 8573278Swollman MCLGET(m0, M_DONTWAIT); 8583278Swollman if ((m0->m_flags & M_EXT) == 0) { 8593278Swollman m_freem(m); 8608296Sdg m_freem(m0); 8613278Swollman continue; 8623278Swollman } 8633278Swollman } 8648296Sdg m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); 8653278Swollman m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; 8663278Swollman m_freem(m); 8673278Swollman IF_PREPEND(ifq, m0); 8683278Swollman continue; 8693278Swollman } else { 8703278Swollman m_freem(m); 8713278Swollman continue; 8723278Swollman } 8733278Swollman } 8744322Sdg if (ri->ri_free - 2 <= (segcnt + 1) >> 1) 8753278Swollman break; 8763278Swollman 8774322Sdg ri->ri_free -= (segcnt + 1) >> 1; 8783278Swollman /* 8793278Swollman * Now we fill in our transmit descriptors. This is 8803278Swollman * a bit reminiscent of going on the Ark two by two 8813278Swollman * since each descriptor for the TULIP can describe 8823278Swollman * two buffers. So we advance through the address 8833278Swollman * vector two entries at a time to to fill each 8843278Swollman * descriptor. Clear the first and last segment bits 8853278Swollman * in each descriptor (actually just clear everything 8863278Swollman * but the end-of-ring or chain bits) to make sure 8873278Swollman * we don't get messed up by previously sent packets. 8883278Swollman */ 8893278Swollman sop = ri->ri_nextout; 8903278Swollman d_status = 0; 8913278Swollman avp = addrvec; 8923278Swollman do { 8933278Swollman eop = ri->ri_nextout; 8943278Swollman eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; 8953278Swollman eop->d_status = d_status; 8963278Swollman eop->d_addr1 = avp->addr; eop->d_length1 = avp->length; avp++; 8973278Swollman eop->d_addr2 = avp->addr; eop->d_length2 = avp->length; avp++; 8983278Swollman d_status = TULIP_DSTS_OWNER; 8993278Swollman if (++ri->ri_nextout == ri->ri_last) 9003278Swollman ri->ri_nextout = ri->ri_first; 9013278Swollman } while ((segcnt -= 2) > 0); 9024772Sdg#if NBPFILTER > 0 9034772Sdg if (sc->tulip_bpf != NULL) 9044772Sdg bpf_mtap(sc->tulip_bpf, m); 9054772Sdg#endif 9063278Swollman /* 9073278Swollman * The descriptors have been filled in. Mark the first 9083278Swollman * and last segments, indicate we want a transmit complete 9093278Swollman * interrupt, give the descriptors to the TULIP, and tell 9103278Swollman * it to transmit! 9113278Swollman */ 9124772Sdg 9133278Swollman IF_ENQUEUE(&sc->tulip_txq, m); 9143278Swollman eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; 9153278Swollman sop->d_flag |= TULIP_DFLAG_TxFIRSTSEG; 9163278Swollman sop->d_status = TULIP_DSTS_OWNER; 9173278Swollman 9183278Swollman *sc->tulip_csrs.csr_txpoll = 1; 9193278Swollman } 9203278Swollman if (m != NULL) { 9213278Swollman ifp->if_flags |= IFF_OACTIVE; 9223278Swollman IF_PREPEND(ifq, m); 9233278Swollman } 9243278Swollman} 9253278Swollman 9263278Swollmanstatic int 9273278Swollmantulip_intr( 9283533Sse tulip_softc_t *sc) 9293278Swollman{ 9303278Swollman tulip_uint32_t csr; 9317229Sse int progress=0; 9323278Swollman 9333278Swollman while ((csr = *sc->tulip_csrs.csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR)) { 9347229Sse progress = 1; 9353278Swollman *sc->tulip_csrs.csr_status = csr & sc->tulip_intrmask; 9363278Swollman 9373278Swollman if (csr & TULIP_STS_SYSERROR) { 9383278Swollman if ((csr & TULIP_STS_ERRORMASK) == TULIP_STS_ERR_PARITY) { 9393278Swollman TULIP_RESET(sc); 9403278Swollman tulip_init(sc->tulip_unit); 9417229Sse break; 9423278Swollman } 9433278Swollman } 9444772Sdg if (csr & TULIP_STS_ABNRMLINTR) { 9454772Sdg printf("%s%d: abnormal interrupt: 0x%05x [0x%05x]\n", 9464772Sdg sc->tulip_name, sc->tulip_unit, csr, csr & sc->tulip_intrmask); 9474772Sdg *sc->tulip_csrs.csr_command = sc->tulip_cmdmode; 9484772Sdg } 9493278Swollman if (csr & TULIP_STS_RXINTR) 9503278Swollman tulip_rx_intr(sc); 9513278Swollman if (sc->tulip_txinfo.ri_free < sc->tulip_txinfo.ri_max) { 9523278Swollman tulip_tx_intr(sc); 9533278Swollman tulip_start(&sc->tulip_if); 9543278Swollman } 9553278Swollman } 9567229Sse return (progress); 9573278Swollman} 9583278Swollman 9593278Swollman/* 9607689Sdg * 9617689Sdg */ 9627689Sdg 9637689Sdgvoid 9647689Sdgtulip_delay_300ns( 9657689Sdg tulip_softc_t *sc) 9667689Sdg{ 9677689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9687689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9697689Sdg 9707689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9717689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9727689Sdg 9737689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9747689Sdg *sc->tulip_csrs.csr_busmode; *sc->tulip_csrs.csr_busmode; 9757689Sdg} 9767689Sdg 9777689Sdg#define EMIT do { *sc->tulip_csrs.csr_srom_mii = csr; tulip_delay_300ns(sc); } while (0) 9787689Sdg 9797689Sdg 9807689Sdgvoid 9817689Sdgtulip_idle_srom( 9827689Sdg tulip_softc_t *sc) 9837689Sdg{ 9847689Sdg unsigned bit, csr; 9857689Sdg 9867689Sdg csr = SROMSEL | SROMRD; EMIT; 9877689Sdg csr ^= SROMCS; EMIT; 9887689Sdg csr ^= SROMCLKON; EMIT; 9897689Sdg 9907689Sdg /* 9917689Sdg * Write 25 cycles of 0 which will force the SROM to be idle. 9927689Sdg */ 9937689Sdg for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { 9947689Sdg csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 9957689Sdg csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 9967689Sdg } 9977689Sdg csr ^= SROMCLKOFF; EMIT; 9987689Sdg csr ^= SROMCS; EMIT; EMIT; 9997689Sdg csr = 0; EMIT; 10007689Sdg} 10017689Sdg 10027689Sdg 10037689Sdgvoid 10047689Sdgtulip_read_srom( 10057689Sdg tulip_softc_t *sc) 10067689Sdg{ 10077689Sdg int idx; 10087689Sdg const unsigned bitwidth = SROM_BITWIDTH; 10097689Sdg const unsigned cmdmask = (SROMCMD_RD << bitwidth); 10107689Sdg const unsigned msb = 1 << (bitwidth + 3 - 1); 10117689Sdg unsigned lastidx = (1 << bitwidth) - 1; 10127689Sdg int lowbit = 0; 10137689Sdg 10147689Sdg tulip_idle_srom(sc); 10157689Sdg 10167689Sdg for (idx = 0; idx <= lastidx; idx++) { 10177689Sdg unsigned lastbit, data, bits, bit, csr; 10187689Sdg csr = SROMSEL | SROMRD; EMIT; 10197689Sdg csr ^= SROMCSON; EMIT; 10207689Sdg csr ^= SROMCLKON; EMIT; 10217689Sdg 10227689Sdg lastbit = 0; 10237689Sdg for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { 10247689Sdg const unsigned thisbit = bits & msb; 10257689Sdg csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 10267689Sdg if (thisbit != lastbit) { 10277689Sdg csr ^= SROMDOUT; EMIT; /* clock low; invert data */ 10287689Sdg } 10297689Sdg csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 10307689Sdg lastbit = thisbit; 10317689Sdg } 10327689Sdg csr ^= SROMCLKOFF; EMIT; 10337689Sdg 10347689Sdg for (data = 0, bits = 0; bits < 16; bits++) { 10357689Sdg data <<= 1; 10367689Sdg csr ^= SROMCLKON; EMIT; /* clock high; data valid */ 10377689Sdg data |= *sc->tulip_csrs.csr_srom_mii & SROMDIN ? 1 : 0; 10387689Sdg csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ 10397689Sdg } 10407689Sdg sc->tulip_rombuf[idx*2] = data & 0xFF; 10417689Sdg sc->tulip_rombuf[idx*2+1] = data >> 8; 10427689Sdg csr = SROMSEL | SROMRD; EMIT; 10437689Sdg csr = 0; EMIT; 10447689Sdg } 10457689Sdg} 10467791Sdg 10477791Sdg#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF) 10487791Sdg#define tulip_srom_crcok(databuf) ( \ 10497791Sdg (tulip_crc32(databuf, 126) & 0xFFFF) == \ 10507791Sdg ((databuf)[126] | ((databuf)[127] << 8))) 10517689Sdg 10527791Sdgstatic unsigned 10537791Sdgtulip_crc32( 10547791Sdg const unsigned char *databuf, 10557791Sdg size_t datalen) 10567791Sdg{ 10577791Sdg u_int idx, bit, data, crc = 0xFFFFFFFFUL; 10587791Sdg 10597791Sdg for (idx = 0; idx < datalen; idx++) 10607791Sdg for (data = *databuf++, bit = 0; bit < 8; bit++, data >>= 1) 10617791Sdg crc = (crc >> 1) ^ (((crc ^ data) & 1) ? TULIP_CRC32_POLY : 0); 10627791Sdg return crc; 10637791Sdg} 10647791Sdg 10657791Sdg 10667689Sdg/* 10673278Swollman * This is the standard method of reading the DEC Address ROMS. 10683278Swollman */ 10693278Swollmanstatic int 10703278Swollmantulip_read_macaddr( 10713278Swollman tulip_softc_t *sc) 10723278Swollman{ 10733278Swollman int cksum, rom_cksum, idx; 10743278Swollman tulip_sint32_t csr; 10753278Swollman unsigned char tmpbuf[8]; 10763278Swollman static u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; 10773278Swollman 10788296Sdg if (sc->tulip_chipid == TULIP_DC21040) { 10797689Sdg *sc->tulip_csrs.csr_enetrom = 1; 10807791Sdg sc->tulip_boardsw = &tulip_dc21040_boardsw; 10817689Sdg for (idx = 0; idx < 32; idx++) { 10827689Sdg int cnt = 0; 10837689Sdg while ((csr = *sc->tulip_csrs.csr_enetrom) < 0 && cnt < 10000) 10847689Sdg cnt++; 10857689Sdg sc->tulip_rombuf[idx] = csr & 0xFF; 10867689Sdg } 10877689Sdg } else { 10887791Sdg /* 10897791Sdg * Assume all DC21140 board are compatible with the 10907791Sdg * DEC 10/100 evaluation board. Not really valid but ... 10917791Sdg */ 10928296Sdg if (sc->tulip_chipid == TULIP_DC21140) 10937791Sdg sc->tulip_boardsw = &tulip_dc21140_eb_boardsw; 10947689Sdg tulip_read_srom(sc); 10957791Sdg if (tulip_srom_crcok(sc->tulip_rombuf)) { 10967791Sdg /* 10977791Sdg * New SROM format. Copy out the Ethernet address. 10987791Sdg * If it contains a DE500-XA string, then it must be 10997791Sdg * a DE500-XA. 11007791Sdg */ 11017791Sdg bcopy(sc->tulip_rombuf + 20, sc->tulip_hwaddr, 6); 11027791Sdg if (bcmp(sc->tulip_rombuf + 29, "DE500-XA", 8) == 0) 11037791Sdg sc->tulip_boardsw = &tulip_dc21140_de500_boardsw; 11047791Sdg if (sc->tulip_boardsw == NULL) 11057791Sdg return -6; 11067791Sdg return 0; 11077791Sdg } 11083278Swollman } 11093278Swollman 11107791Sdg 11114772Sdg if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { 11124772Sdg /* 11134772Sdg * Some folks don't use the standard ethernet rom format 11144772Sdg * but instead just put the address in the first 6 bytes 11154772Sdg * of the rom and let the rest be all 0xffs. (Can we say 11164772Sdg * ZNYX???) 11174772Sdg */ 11184772Sdg for (idx = 6; idx < 32; idx++) { 11194772Sdg if (sc->tulip_rombuf[idx] != 0xFF) 11204772Sdg return -4; 11214772Sdg } 11224772Sdg /* 11234772Sdg * Make sure the address is not multicast or locally assigned 11244772Sdg * that the OUI is not 00-00-00. 11254772Sdg */ 11264772Sdg if ((sc->tulip_rombuf[0] & 3) != 0) 11274772Sdg return -4; 11284772Sdg if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 11294772Sdg && sc->tulip_rombuf[2] == 0) 11304772Sdg return -4; 11314772Sdg bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 11324772Sdg return 0; 11334772Sdg } 11343278Swollman if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) 11353278Swollman return -3; 11363278Swollman 11373278Swollman tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; 11383278Swollman tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; 11393278Swollman tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; 11403278Swollman tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; 11413278Swollman if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) 11423278Swollman return -2; 11433278Swollman 11443278Swollman bcopy(sc->tulip_rombuf, sc->tulip_hwaddr, 6); 11453278Swollman 11463278Swollman cksum = *(u_short *) &sc->tulip_hwaddr[0]; 11473278Swollman cksum *= 2; 11483278Swollman if (cksum > 65535) cksum -= 65535; 11493278Swollman cksum += *(u_short *) &sc->tulip_hwaddr[2]; 11503278Swollman if (cksum > 65535) cksum -= 65535; 11513278Swollman cksum *= 2; 11523278Swollman if (cksum > 65535) cksum -= 65535; 11533278Swollman cksum += *(u_short *) &sc->tulip_hwaddr[4]; 11543278Swollman if (cksum >= 65535) cksum -= 65535; 11553278Swollman 11563278Swollman rom_cksum = *(u_short *) &sc->tulip_rombuf[6]; 11573278Swollman 11583278Swollman if (cksum != rom_cksum) 11593278Swollman return -1; 11608296Sdg 11618296Sdg if (sc->tulip_chipid == TULIP_DC21140) { 11628296Sdg if (sc->tulip_hwaddr[0] == TULIP_OUI_COGENT_0 11638296Sdg && sc->tulip_hwaddr[1] == TULIP_OUI_COGENT_1 11648296Sdg && sc->tulip_hwaddr[2] == TULIP_OUI_COGENT_2) { 11658296Sdg if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100_ID) 11668296Sdg sc->tulip_boardsw = &tulip_dc21140_cogent_em100_boardsw; 11678296Sdg } 11688296Sdg } 11698296Sdg 11703278Swollman return 0; 11713278Swollman} 11723278Swollman 11733278Swollmanstatic void 11743278Swollmantulip_addr_filter( 11753278Swollman tulip_softc_t *sc) 11763278Swollman{ 11773278Swollman tulip_uint32_t *sp = sc->tulip_setupdata; 11783278Swollman struct ether_multistep step; 11793278Swollman struct ether_multi *enm; 11803278Swollman int i; 11813278Swollman 11823278Swollman sc->tulip_flags &= ~TULIP_WANTHASH; 11833278Swollman sc->tulip_flags |= TULIP_WANTSETUP; 11843278Swollman sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; 11853278Swollman sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; 11863278Swollman if (sc->tulip_ac.ac_multicnt > 14) { 11873278Swollman unsigned hash; 11883278Swollman /* 11893278Swollman * If we have more than 14 multicasts, we have 11903278Swollman * go into hash perfect mode (512 bit multicast 11913278Swollman * hash and one perfect hardware). 11923278Swollman */ 11933278Swollman 11943278Swollman bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); 11953278Swollman hash = tulip_mchash(etherbroadcastaddr); 11963278Swollman sp[hash >> 4] |= 1 << (hash & 0xF); 11973278Swollman ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 11983278Swollman while (enm != NULL) { 11993278Swollman hash = tulip_mchash(enm->enm_addrlo); 12003278Swollman sp[hash >> 4] |= 1 << (hash & 0xF); 12013278Swollman ETHER_NEXT_MULTI(step, enm); 12023278Swollman } 12033278Swollman sc->tulip_cmdmode |= TULIP_WANTHASH; 12047689Sdg sp[39] = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 12057689Sdg sp[40] = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 12067689Sdg sp[41] = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 12073278Swollman } else { 12083278Swollman /* 12093278Swollman * Else can get perfect filtering for 16 addresses. 12103278Swollman */ 12113278Swollman i = 0; 12123278Swollman ETHER_FIRST_MULTI(step, &sc->tulip_ac, enm); 12133278Swollman for (; enm != NULL; i++) { 12143278Swollman *sp++ = ((u_short *) enm->enm_addrlo)[0]; 12153278Swollman *sp++ = ((u_short *) enm->enm_addrlo)[1]; 12163278Swollman *sp++ = ((u_short *) enm->enm_addrlo)[2]; 12173278Swollman ETHER_NEXT_MULTI(step, enm); 12183278Swollman } 12193278Swollman /* 12203278Swollman * If an IP address is enabled, turn on broadcast 12213278Swollman */ 12223278Swollman if (sc->tulip_ac.ac_ipaddr.s_addr != 0) { 12233278Swollman i++; 12243278Swollman *sp++ = 0xFFFF; 12253278Swollman *sp++ = 0xFFFF; 12263278Swollman *sp++ = 0xFFFF; 12273278Swollman } 12283278Swollman /* 12293278Swollman * Pad the rest with our hardware address 12303278Swollman */ 12313278Swollman for (; i < 16; i++) { 12323278Swollman *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[0]; 12333278Swollman *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[1]; 12343278Swollman *sp++ = ((u_short *) sc->tulip_ac.ac_enaddr)[2]; 12353278Swollman } 12363278Swollman } 12373278Swollman} 12383278Swollman 12396132Sdg/*extern void arp_ifinit(struct arpcom *, struct ifaddr*);*/ 12406132Sdg 12413278Swollmanstatic int 12423278Swollmantulip_ioctl( 12433278Swollman struct ifnet *ifp, 12443278Swollman int cmd, 12453278Swollman caddr_t data) 12463278Swollman{ 12478296Sdg tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(ifp->if_unit); 12484437Sdg struct ifaddr *ifa = (struct ifaddr *)data; 12494437Sdg struct ifreq *ifr = (struct ifreq *) data; 12503278Swollman int s, error = 0; 12513278Swollman 12523278Swollman s = splimp(); 12533278Swollman 12543278Swollman switch (cmd) { 12553278Swollman case SIOCSIFADDR: { 12563278Swollman 12573278Swollman ifp->if_flags |= IFF_UP; 12583278Swollman switch(ifa->ifa_addr->sa_family) { 12593278Swollman#ifdef INET 12603278Swollman case AF_INET: { 12613278Swollman ((struct arpcom *)ifp)->ac_ipaddr = IA_SIN(ifa)->sin_addr; 12624772Sdg tulip_addr_filter(sc); /* reset multicast filtering */ 12633278Swollman (*ifp->if_init)(ifp->if_unit); 12648296Sdg#if defined(__FreeBSD__) 12655195Swollman arp_ifinit((struct arpcom *)ifp, ifa); 12668296Sdg#endif 12678296Sdg arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 12683278Swollman break; 12693278Swollman } 12703278Swollman#endif /* INET */ 12713278Swollman 12723278Swollman#ifdef NS 12733278Swollman /* This magic copied from if_is.c; I don't use XNS, 12743278Swollman * so I have no way of telling if this actually 12753278Swollman * works or not. 12763278Swollman */ 12773278Swollman case AF_NS: { 12783278Swollman struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 12793278Swollman if (ns_nullhost(*ina)) { 12803278Swollman ina->x_host = *(union ns_host *)(sc->tulip_ac.ac_enaddr); 12813278Swollman } else { 12823278Swollman ifp->if_flags &= ~IFF_RUNNING; 12833278Swollman bcopy((caddr_t)ina->x_host.c_host, 12843278Swollman (caddr_t)sc->tulip_ac.ac_enaddr, 12853278Swollman sizeof sc->tulip_ac.ac_enaddr); 12863278Swollman } 12873278Swollman 12883278Swollman (*ifp->if_init)(ifp->if_unit); 12893278Swollman break; 12903278Swollman } 12913278Swollman#endif /* NS */ 12923278Swollman 12933278Swollman default: { 12943278Swollman (*ifp->if_init)(ifp->if_unit); 12953278Swollman break; 12963278Swollman } 12973278Swollman } 12983278Swollman break; 12993278Swollman } 13003278Swollman 13013278Swollman case SIOCSIFFLAGS: { 13023278Swollman /* 13033278Swollman * Changing the connection forces a reset. 13043278Swollman */ 13053278Swollman if (sc->tulip_flags & TULIP_ALTPHYS) { 13063278Swollman if ((ifp->if_flags & IFF_ALTPHYS) == 0) 13073278Swollman TULIP_RESET(sc); 13083278Swollman } else { 13093278Swollman if (ifp->if_flags & IFF_ALTPHYS) 13103278Swollman TULIP_RESET(sc); 13113278Swollman } 13123278Swollman (*ifp->if_init)(ifp->if_unit); 13133278Swollman break; 13143278Swollman } 13153278Swollman 13163278Swollman case SIOCADDMULTI: 13173278Swollman case SIOCDELMULTI: { 13183278Swollman /* 13193278Swollman * Update multicast listeners 13203278Swollman */ 13213278Swollman if (cmd == SIOCADDMULTI) 13224437Sdg error = ether_addmulti(ifr, &sc->tulip_ac); 13233278Swollman else 13244437Sdg error = ether_delmulti(ifr, &sc->tulip_ac); 13253278Swollman 13263278Swollman if (error == ENETRESET) { 13273278Swollman tulip_addr_filter(sc); /* reset multicast filtering */ 13283278Swollman (*ifp->if_init)(ifp->if_unit); 13293278Swollman error = 0; 13303278Swollman } 13313278Swollman break; 13323278Swollman } 13338296Sdg#if defined(SIOCSIFMTU) 13344437Sdg case SIOCSIFMTU: 13354437Sdg /* 13364437Sdg * Set the interface MTU. 13374437Sdg */ 13384437Sdg if (ifr->ifr_mtu > ETHERMTU) { 13394437Sdg error = EINVAL; 13404437Sdg } else { 13414437Sdg ifp->if_mtu = ifr->ifr_mtu; 13424437Sdg } 13434437Sdg break; 13448296Sdg#endif 13453278Swollman 13463278Swollman default: { 13473278Swollman error = EINVAL; 13483278Swollman break; 13493278Swollman } 13503278Swollman } 13513278Swollman 13523278Swollman splx(s); 13533278Swollman return error; 13543278Swollman} 13553278Swollman 13563278Swollmanstatic void 13573278Swollmantulip_attach( 13583278Swollman tulip_softc_t *sc) 13593278Swollman{ 13603278Swollman struct ifnet *ifp = &sc->tulip_if; 13613278Swollman 13627791Sdg ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; 13633278Swollman ifp->if_init = tulip_init; 13643278Swollman ifp->if_ioctl = tulip_ioctl; 13653278Swollman ifp->if_output = ether_output; 13663278Swollman ifp->if_start = tulip_start; 13673278Swollman 13688296Sdg#ifndef __bsdi__ 13698296Sdg printf("%s%d", sc->tulip_name, sc->tulip_unit); 13708296Sdg#endif 13718296Sdg printf(": %s%s pass %d.%d Ethernet address %s\n", 13727791Sdg sc->tulip_boardsw->bd_description, 13738296Sdg tulip_chipdescs[sc->tulip_chipid], 13743278Swollman (sc->tulip_revinfo & 0xF0) >> 4, 13753278Swollman sc->tulip_revinfo & 0x0F, 13763278Swollman ether_sprintf(sc->tulip_hwaddr)); 13773278Swollman 13788296Sdg if ((*sc->tulip_boardsw->bd_media_probe)(sc)) { 13798296Sdg ifp->if_flags |= IFF_ALTPHYS; 13808296Sdg } else { 13818296Sdg sc->tulip_flags |= TULIP_ALTPHYS; 13828296Sdg } 13838296Sdg 13848296Sdg TULIP_RESET(sc); 13858296Sdg 13864322Sdg if_attach(ifp); 13874322Sdg 13883278Swollman#if NBPFILTER > 0 13893278Swollman bpfattach(&sc->tulip_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 13903278Swollman#endif 13913278Swollman} 13923278Swollman 13933278Swollmanstatic void 13943278Swollmantulip_initcsrs( 13953278Swollman tulip_softc_t *sc, 13963278Swollman volatile tulip_uint32_t *va_csrs, 13973278Swollman size_t csr_size) 13983278Swollman{ 13993278Swollman sc->tulip_csrs.csr_busmode = va_csrs + 0 * csr_size; 14003278Swollman sc->tulip_csrs.csr_txpoll = va_csrs + 1 * csr_size; 14013278Swollman sc->tulip_csrs.csr_rxpoll = va_csrs + 2 * csr_size; 14023278Swollman sc->tulip_csrs.csr_rxlist = va_csrs + 3 * csr_size; 14033278Swollman sc->tulip_csrs.csr_txlist = va_csrs + 4 * csr_size; 14043278Swollman sc->tulip_csrs.csr_status = va_csrs + 5 * csr_size; 14053278Swollman sc->tulip_csrs.csr_command = va_csrs + 6 * csr_size; 14063278Swollman sc->tulip_csrs.csr_intr = va_csrs + 7 * csr_size; 14073278Swollman sc->tulip_csrs.csr_missed_frame = va_csrs + 8 * csr_size; 14088296Sdg if (sc->tulip_chipid == TULIP_DC21040) { 14098296Sdg sc->tulip_csrs.csr_enetrom = (tulip_sint32_t *) va_csrs + 9 * csr_size; 14107689Sdg sc->tulip_csrs.csr_reserved = va_csrs + 10 * csr_size; 14117689Sdg sc->tulip_csrs.csr_full_duplex = va_csrs + 11 * csr_size; 14127689Sdg sc->tulip_csrs.csr_sia_status = va_csrs + 12 * csr_size; 14137689Sdg sc->tulip_csrs.csr_sia_connectivity = va_csrs + 13 * csr_size; 14147689Sdg sc->tulip_csrs.csr_sia_tx_rx = va_csrs + 14 * csr_size; 14157689Sdg sc->tulip_csrs.csr_sia_general = va_csrs + 15 * csr_size; 14168296Sdg } else if (sc->tulip_chipid == TULIP_DC21140 || sc->tulip_chipid == TULIP_DC21041) { 14178296Sdg sc->tulip_csrs.csr_srom_mii = va_csrs + 9 * csr_size; 14187689Sdg sc->tulip_csrs.csr_gp_timer = va_csrs + 11 * csr_size; 14197689Sdg sc->tulip_csrs.csr_gp = va_csrs + 12 * csr_size; 14207689Sdg sc->tulip_csrs.csr_watchdog = va_csrs + 15 * csr_size; 14217689Sdg } 14223278Swollman} 14233278Swollman 14243278Swollmanstatic void 14253278Swollmantulip_initring( 14263278Swollman tulip_softc_t *sc, 14273278Swollman tulip_ringinfo_t *ri, 14283278Swollman tulip_desc_t *descs, 14293278Swollman int ndescs) 14303278Swollman{ 14313278Swollman ri->ri_max = ndescs; 14323278Swollman ri->ri_first = descs; 14333278Swollman ri->ri_last = ri->ri_first + ri->ri_max; 14343278Swollman bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); 14353278Swollman ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; 14363278Swollman} 14373278Swollman 14383278Swollman/* 14393278Swollman * This is the PCI configuration support. Since the DC21040 is available 14403278Swollman * on both EISA and PCI boards, one must be careful in how defines the 14413278Swollman * DC21040 in the config file. 14423278Swollman */ 14433278Swollman 14443278Swollman#define PCI_CFID 0x00 /* Configuration ID */ 14453278Swollman#define PCI_CFCS 0x04 /* Configurtion Command/Status */ 14463278Swollman#define PCI_CFRV 0x08 /* Configuration Revision */ 14473278Swollman#define PCI_CFLT 0x0c /* Configuration Latency Timer */ 14483278Swollman#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 14493278Swollman#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ 14503278Swollman#define PCI_CFIT 0x3c /* Configuration Interrupt */ 14513278Swollman#define PCI_CFDA 0x40 /* Configuration Driver Area */ 14523278Swollman 14533278Swollman#define TULIP_PCI_CSRSIZE (8 / sizeof(tulip_uint32_t)) 14548296Sdg 14558296Sdg#if defined(__FreeBSD__) 14568296Sdg 14578296Sdg#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit 14588296Sdg 14598296Sdgstatic int 14608296Sdgtulip_pci_shutdown( 14618296Sdg struct kern_devconf *kdc, 14628296Sdg int force) 14638296Sdg{ 14648296Sdg if (kdc->kdc_unit < NDE) { 14658296Sdg tulip_softc_t *sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit); 14668296Sdg *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 14678296Sdg DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 14688296Sdg 33MHz that comes to two microseconds but wait a 14698296Sdg bit longer anyways) */ 14708296Sdg } 14718296Sdg (void) dev_detach(kdc); 14728296Sdg return 0; 14738296Sdg} 14748296Sdg 14753533Ssestatic char* 14763278Swollmantulip_pci_probe( 14773533Sse pcici_t config_id, 14783533Sse pcidi_t device_id) 14793278Swollman{ 14808296Sdg if (device_id == 0x00021011ul) 14817689Sdg return "Digital DC21040 Ethernet"; 14828296Sdg if (device_id == 0x00141011ul) 14837689Sdg return "Digital DC21041 Ethernet"; 14848296Sdg if (device_id == 0x00091011ul) 14857689Sdg return "Digital DC21140 Fast Ethernet"; 14863543Sse return NULL; 14873278Swollman} 14883278Swollman 14898296Sdgstatic void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 14908296Sdgstatic u_long tulip_pci_count; 14918296Sdg 14928296Sdgstruct pci_device dedevice = { 14938296Sdg "de", 14948296Sdg tulip_pci_probe, 14958296Sdg tulip_pci_attach, 14968296Sdg &tulip_pci_count, 14978296Sdg tulip_pci_shutdown, 14988296Sdg}; 14998296Sdg 15008296SdgDATA_SET (pcidevice_set, dedevice); 15018296Sdg#endif /* __FreeBSD__ */ 15028296Sdg 15038296Sdg#if defined(__bsdi__) 15048296Sdg#define TULIP_PCI_ATTACH_ARGS struct device *parent, struct device *self, void *aux 15058296Sdg 15063533Ssestatic void 15078296Sdgtulip_pci_shutdown( 15088296Sdg void *arg) 15098296Sdg{ 15108296Sdg tulip_softc_t *sc = (tulip_softc_t *) arg; 15118296Sdg *sc->tulip_csrs.csr_busmode = TULIP_BUSMODE_SWRESET; 15128296Sdg DELAY(10); /* Wait 10 microsends (actually 50 PCI cycles but at 15138296Sdg 33MHz that comes to two microseconds but wait a 15148296Sdg bit longer anyways) */ 15158296Sdg} 15168296Sdg 15178296Sdgstatic int 15188296Sdgtulip_pci_match( 15198296Sdg pci_devaddr_t *pa) 15208296Sdg{ 15218296Sdg int irq; 15228296Sdg unsigned id; 15238296Sdg 15248296Sdg id = pci_inl(pa, PCI_VENDOR_ID); 15258296Sdg if ((id & 0xFFFF) != 0x1011) 15268296Sdg return 0; 15278296Sdg id >>= 16; 15288296Sdg if (id != 2 && id != 9 && id != 0x14) 15298296Sdg return 0; 15308296Sdg irq = pci_inl(pa, PCI_I_PIN) & 0xFF; 15318296Sdg if (irq == 0 || irq >= 16) 15328296Sdg return 0; 15338296Sdg 15348296Sdg return 1; 15358296Sdg} 15368296Sdg 15378296Sdgint 15388296Sdgtulip_pci_probe( 15398296Sdg struct device *parent, 15408296Sdg struct cfdata *cf, 15418296Sdg void *aux) 15428296Sdg{ 15438296Sdg struct isa_attach_args *ia = (struct isa_attach_args *) aux; 15448296Sdg unsigned irq; 15458296Sdg pci_devaddr_t *pa; 15468296Sdg 15478296Sdg pa = pci_scan(tulip_pci_match); 15488296Sdg if (pa == NULL) 15498296Sdg return 0; 15508296Sdg 15518296Sdg irq = (1 << (pci_inl(pa, PCI_I_PIN) & 0xFF)); 15528296Sdg 15538296Sdg if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) { 15548296Sdg printf("fpa%d: error: desired IRQ of %d does not match device's actual IRQ of %d,\n", 15558296Sdg cf->cf_unit, 15568296Sdg ffs(ia->ia_irq) - 1, ffs(irq) - 1); 15578296Sdg return 0; 15588296Sdg } 15598296Sdg if (ia->ia_irq == IRQUNK) { 15608296Sdg if ((irq = isa_irqalloc(irq)) == 0) 15618296Sdg return 0; 15628296Sdg ia->ia_irq = irq; 15638296Sdg } 15648296Sdg 15658296Sdg /* PCI bus masters don't use host DMA channels */ 15668296Sdg ia->ia_drq = DRQNONE; 15678296Sdg 15688296Sdg /* Get the memory base address; assume the BIOS set it up correctly */ 15698296Sdg ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7); 15708296Sdg pci_outl(pa, PCI_CBMA, 0xFFFFFFFF); 15718296Sdg ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1; 15728296Sdg pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr); 15738296Sdg 15748296Sdg /* Disable I/O space access */ 15758296Sdg pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1); 15768296Sdg ia->ia_iobase = 0; 15778296Sdg ia->ia_iosize = 0; 15788296Sdg 15798296Sdg ia->ia_aux = (void *) pa; 15808296Sdg return 1; 15818296Sdg} 15828296Sdg 15838296Sdgstatic void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); 15848296Sdg 15858296Sdgstruct cfdriver decd = { 15868296Sdg 0, "de", tulip_pci_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t) 15878296Sdg}; 15888296Sdg 15898296Sdg#endif /* __bsdi__ */ 15908296Sdg 15918296Sdgstatic void 15923278Swollmantulip_pci_attach( 15938296Sdg TULIP_PCI_ATTACH_ARGS) 15943278Swollman{ 15958296Sdg#if defined(__FreeBSD__) 15963278Swollman tulip_softc_t *sc; 15978296Sdg#endif 15988296Sdg#if defined(__bsdi__) 15998296Sdg tulip_softc_t *sc = (tulip_softc_t *) self; 16008296Sdg struct isa_attach_args *ia = (struct isa_attach_args *) aux; 16018296Sdg pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux; 16028296Sdg int unit = sc->tulip_dev.dv_unit; 16038296Sdg#endif 16048296Sdg int retval, idx, revinfo, id; 16053278Swollman vm_offset_t va_csrs, pa_csrs; 16063278Swollman tulip_desc_t *rxdescs, *txdescs; 16078296Sdg tulip_chipid_t chipid; 16083278Swollman 16098296Sdg#if defined(__FreeBSD__) 16107689Sdg if (unit >= NDE) { 16117689Sdg printf("de%d: not configured; kernel is built for only %d device%s.\n", 16127689Sdg unit, NDE, NDE == 1 ? "" : "s"); 16137689Sdg return; 16147689Sdg } 16158296Sdg#endif 16167689Sdg 16178296Sdg#if defined(__FreeBSD__) 16187791Sdg revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF; 16198296Sdg id = pci_conf_read(config_id, PCI_CFID); 16208296Sdg#endif 16218296Sdg#if defined(__bsdi__) 16228296Sdg revinfo = pci_inl(pa, PCI_CFRV) & 0xFF; 16238296Sdg id = pci_inl(pa, PCI_CFID); 16248296Sdg#endif 16258296Sdg 16268296Sdg if (id == 0x00021011ul) chipid = TULIP_DC21040; 16278296Sdg else if (id == 0x00091011) chipid = TULIP_DC21140; 16288296Sdg else if (id == 0x00141011) chipid = TULIP_DC21041; 16298296Sdg else return; 16308296Sdg 16318296Sdg if (chipid == TULIP_DC21040 && revinfo < 0x20) { 16328296Sdg printf("de%d: not configured; DC21040 pass 2.3 required (%d.%d found)\n", 16337791Sdg unit, revinfo >> 4, revinfo & 0x0f); 16347791Sdg return; 16358296Sdg } else if (chipid == TULIP_DC21140 && revinfo < 0x11) { 16367791Sdg printf("de%d: not configured; DC21140 pass 1.1 required (%d.%d found)\n", 16377791Sdg unit, revinfo >> 4, revinfo & 0x0f); 16387791Sdg return; 16397791Sdg } 16407791Sdg 16418296Sdg#if defined(__FreeBSD__) 16423278Swollman sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); 16433278Swollman if (sc == NULL) 16443533Sse return; 16458296Sdg bzero(sc, sizeof(*sc)); /* Zero out the softc*/ 16468296Sdg#endif 16473278Swollman 16483278Swollman rxdescs = (tulip_desc_t *) 16493278Swollman malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS, M_DEVBUF, M_NOWAIT); 16503278Swollman if (rxdescs == NULL) { 16518296Sdg#if defined(__FreeBSD__) 16523278Swollman free((caddr_t) sc, M_DEVBUF); 16538296Sdg#endif 16543533Sse return; 16553278Swollman } 16563278Swollman 16573278Swollman txdescs = (tulip_desc_t *) 16583278Swollman malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS, M_DEVBUF, M_NOWAIT); 16593278Swollman if (txdescs == NULL) { 16603278Swollman free((caddr_t) rxdescs, M_DEVBUF); 16618296Sdg#if defined(__FreeBSD__) 16623278Swollman free((caddr_t) sc, M_DEVBUF); 16638296Sdg#endif 16643533Sse return; 16653278Swollman } 16663278Swollman 16678296Sdg sc->tulip_chipid = chipid; 16683278Swollman sc->tulip_unit = unit; 16693278Swollman sc->tulip_name = "de"; 16708296Sdg#if defined(__FreeBSD__) 16713278Swollman retval = pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs); 16723533Sse if (!retval) { 16733278Swollman free((caddr_t) txdescs, M_DEVBUF); 16743278Swollman free((caddr_t) rxdescs, M_DEVBUF); 16753278Swollman free((caddr_t) sc, M_DEVBUF); 16763533Sse return; 16773278Swollman } 16783278Swollman tulips[unit] = sc; 16798296Sdg#endif 16808296Sdg#if defined(__bsdi__) 16818296Sdg va_csrs = (vm_offset_t) mapphys((vm_offset_t) ia->ia_maddr, ia->ia_msize); 16828296Sdg#endif 16838296Sdg sc->tulip_revinfo = revinfo; 16843278Swollman tulip_initcsrs(sc, (volatile tulip_uint32_t *) va_csrs, TULIP_PCI_CSRSIZE); 16853278Swollman tulip_initring(sc, &sc->tulip_rxinfo, rxdescs, TULIP_RXDESCS); 16863278Swollman tulip_initring(sc, &sc->tulip_txinfo, txdescs, TULIP_TXDESCS); 16873278Swollman if ((retval = tulip_read_macaddr(sc)) < 0) { 16883278Swollman printf("de%d: can't read ENET ROM (why=%d) (", sc->tulip_unit, retval); 16893278Swollman for (idx = 0; idx < 32; idx++) 16903278Swollman printf("%02x", sc->tulip_rombuf[idx]); 16913278Swollman printf("\n"); 16927791Sdg printf("%s%d: %s%s pass %d.%d Ethernet address %s\n", 16933278Swollman sc->tulip_name, sc->tulip_unit, 16947791Sdg (sc->tulip_boardsw != NULL ? sc->tulip_boardsw->bd_description : ""), 16958296Sdg tulip_chipdescs[sc->tulip_chipid], 16963278Swollman (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F, 16973278Swollman "unknown"); 16983278Swollman } else { 16993278Swollman TULIP_RESET(sc); 17003278Swollman tulip_attach(sc); 17018296Sdg#if defined(__FreeBSD__) 17024437Sdg pci_map_int (config_id, tulip_intr, (void*) sc, &net_imask); 17038296Sdg#endif 17048296Sdg#if defined(__bsdi__) 17058296Sdg isa_establish(&sc->tulip_id, &sc->tulip_dev); 17067104Sdg 17078296Sdg sc->tulip_ih.ih_fun = tulip_intr; 17088296Sdg sc->tulip_ih.ih_arg = (void *)sc; 17098296Sdg intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET); 17108296Sdg 17118296Sdg sc->tulip_ats.func = tulip_pci_shutdown; 17128296Sdg sc->tulip_ats.arg = (void *) sc; 17138296Sdg atshutdown(&sc->tulip_ats, ATSH_ADD); 17148296Sdg#endif 17157689Sdg } 17167104Sdg} 17173278Swollman#endif /* NDE > 0 */ 1718