if_ti.c revision 64837
145386Swpaul/* 245386Swpaul * Copyright (c) 1997, 1998, 1999 345386Swpaul * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 445386Swpaul * 545386Swpaul * Redistribution and use in source and binary forms, with or without 645386Swpaul * modification, are permitted provided that the following conditions 745386Swpaul * are met: 845386Swpaul * 1. Redistributions of source code must retain the above copyright 945386Swpaul * notice, this list of conditions and the following disclaimer. 1045386Swpaul * 2. Redistributions in binary form must reproduce the above copyright 1145386Swpaul * notice, this list of conditions and the following disclaimer in the 1245386Swpaul * documentation and/or other materials provided with the distribution. 1345386Swpaul * 3. All advertising materials mentioning features or use of this software 1445386Swpaul * must display the following acknowledgement: 1545386Swpaul * This product includes software developed by Bill Paul. 1645386Swpaul * 4. Neither the name of the author nor the names of any co-contributors 1745386Swpaul * may be used to endorse or promote products derived from this software 1845386Swpaul * without specific prior written permission. 1945386Swpaul * 2045386Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2145386Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2245386Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2345386Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2445386Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2545386Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2645386Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2745386Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2845386Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2945386Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3045386Swpaul * THE POSSIBILITY OF SUCH DAMAGE. 3145386Swpaul * 3250477Speter * $FreeBSD: head/sys/dev/ti/if_ti.c 64837 2000-08-19 08:32:59Z dwmalone $ 3345386Swpaul */ 3445386Swpaul 3545386Swpaul/* 3645386Swpaul * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD. 3745386Swpaul * Manuals, sample driver and firmware source kits are available 3845386Swpaul * from http://www.alteon.com/support/openkits. 3945386Swpaul * 4045386Swpaul * Written by Bill Paul <wpaul@ctr.columbia.edu> 4145386Swpaul * Electrical Engineering Department 4245386Swpaul * Columbia University, New York City 4345386Swpaul */ 4445386Swpaul 4545386Swpaul/* 4645386Swpaul * The Alteon Networks Tigon chip contains an embedded R4000 CPU, 4745386Swpaul * gigabit MAC, dual DMA channels and a PCI interface unit. NICs 4845386Swpaul * using the Tigon may have anywhere from 512K to 2MB of SRAM. The 4945386Swpaul * Tigon supports hardware IP, TCP and UCP checksumming, multicast 5045386Swpaul * filtering and jumbo (9014 byte) frames. The hardware is largely 5145386Swpaul * controlled by firmware, which must be loaded into the NIC during 5245386Swpaul * initialization. 5345386Swpaul * 5445386Swpaul * The Tigon 2 contains 2 R4000 CPUs and requires a newer firmware 5545386Swpaul * revision, which supports new features such as extended commands, 5645386Swpaul * extended jumbo receive ring desciptors and a mini receive ring. 5745386Swpaul * 5845386Swpaul * Alteon Networks is to be commended for releasing such a vast amount 5945386Swpaul * of development material for the Tigon NIC without requiring an NDA 6045386Swpaul * (although they really should have done it a long time ago). With 6145386Swpaul * any luck, the other vendors will finally wise up and follow Alteon's 6245386Swpaul * stellar example. 6345386Swpaul * 6445386Swpaul * The firmware for the Tigon 1 and 2 NICs is compiled directly into 6545386Swpaul * this driver by #including it as a C header file. This bloats the 6645386Swpaul * driver somewhat, but it's the easiest method considering that the 6745386Swpaul * driver code and firmware code need to be kept in sync. The source 6845386Swpaul * for the firmware is not provided with the FreeBSD distribution since 6945386Swpaul * compiling it requires a GNU toolchain targeted for mips-sgi-irix5.3. 7045386Swpaul * 7145386Swpaul * The following people deserve special thanks: 7245386Swpaul * - Terry Murphy of 3Com, for providing a 3c985 Tigon 1 board 7345386Swpaul * for testing 7445386Swpaul * - Raymond Lee of Netgear, for providing a pair of Netgear 7545386Swpaul * GA620 Tigon 2 boards for testing 7645386Swpaul * - Ulf Zimmermann, for bringing the GA260 to my attention and 7745386Swpaul * convincing me to write this driver. 7845386Swpaul * - Andrew Gallatin for providing FreeBSD/Alpha support. 7945386Swpaul */ 8045386Swpaul 8145386Swpaul#include "vlan.h" 8245386Swpaul 8345386Swpaul#include <sys/param.h> 8445386Swpaul#include <sys/systm.h> 8545386Swpaul#include <sys/sockio.h> 8645386Swpaul#include <sys/mbuf.h> 8745386Swpaul#include <sys/malloc.h> 8845386Swpaul#include <sys/kernel.h> 8945386Swpaul#include <sys/socket.h> 9045386Swpaul#include <sys/queue.h> 9145386Swpaul 9245386Swpaul#include <net/if.h> 9345386Swpaul#include <net/if_arp.h> 9445386Swpaul#include <net/ethernet.h> 9545386Swpaul#include <net/if_dl.h> 9645386Swpaul#include <net/if_media.h> 9745386Swpaul 9845386Swpaul#include <net/bpf.h> 9945386Swpaul 10045386Swpaul#if NVLAN > 0 10145386Swpaul#include <net/if_types.h> 10245386Swpaul#include <net/if_vlan_var.h> 10345386Swpaul#endif 10445386Swpaul 10545386Swpaul#include <netinet/in_systm.h> 10645386Swpaul#include <netinet/in.h> 10745386Swpaul#include <netinet/ip.h> 10845386Swpaul 10945386Swpaul#include <vm/vm.h> /* for vtophys */ 11045386Swpaul#include <vm/pmap.h> /* for vtophys */ 11145386Swpaul#include <machine/clock.h> /* for DELAY */ 11245386Swpaul#include <machine/bus_memio.h> 11345386Swpaul#include <machine/bus.h> 11449011Swpaul#include <machine/resource.h> 11549011Swpaul#include <sys/bus.h> 11649011Swpaul#include <sys/rman.h> 11745386Swpaul 11845386Swpaul#include <pci/pcireg.h> 11945386Swpaul#include <pci/pcivar.h> 12045386Swpaul 12145386Swpaul#include <pci/if_tireg.h> 12245386Swpaul#include <pci/ti_fw.h> 12345386Swpaul#include <pci/ti_fw2.h> 12445386Swpaul 12558698Sjlemon#define TI_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_IP_FRAGS) 12645386Swpaul 12745386Swpaul#if !defined(lint) 12845386Swpaulstatic const char rcsid[] = 12950477Speter "$FreeBSD: head/sys/dev/ti/if_ti.c 64837 2000-08-19 08:32:59Z dwmalone $"; 13045386Swpaul#endif 13145386Swpaul 13245386Swpaul/* 13345386Swpaul * Various supported device vendors/types and their names. 13445386Swpaul */ 13545386Swpaul 13645386Swpaulstatic struct ti_type ti_devs[] = { 13745386Swpaul { ALT_VENDORID, ALT_DEVICEID_ACENIC, 13863702Swpaul "Alteon AceNIC 1000baseSX Gigabit Ethernet" }, 13963699Swpaul { ALT_VENDORID, ALT_DEVICEID_ACENIC_COPPER, 14063702Swpaul "Alteon AceNIC 1000baseT Gigabit Ethernet" }, 14145386Swpaul { TC_VENDORID, TC_DEVICEID_3C985, 14245386Swpaul "3Com 3c985-SX Gigabit Ethernet" }, 14345386Swpaul { NG_VENDORID, NG_DEVICEID_GA620, 14464139Swpaul "Netgear GA620 1000baseSX Gigabit Ethernet" }, 14564139Swpaul { NG_VENDORID, NG_DEVICEID_GA620T, 14664139Swpaul "Netgear GA620 1000baseT Gigabit Ethernet" }, 14745386Swpaul { SGI_VENDORID, SGI_DEVICEID_TIGON, 14845386Swpaul "Silicon Graphics Gigabit Ethernet" }, 14956206Swpaul { DEC_VENDORID, DEC_DEVICEID_FARALLON_PN9000SX, 15056206Swpaul "Farallon PN9000SX Gigabit Ethernet" }, 15145386Swpaul { 0, 0, NULL } 15245386Swpaul}; 15345386Swpaul 15449011Swpaulstatic int ti_probe __P((device_t)); 15549011Swpaulstatic int ti_attach __P((device_t)); 15649011Swpaulstatic int ti_detach __P((device_t)); 15745386Swpaulstatic void ti_txeof __P((struct ti_softc *)); 15845386Swpaulstatic void ti_rxeof __P((struct ti_softc *)); 15945386Swpaul 16045386Swpaulstatic void ti_stats_update __P((struct ti_softc *)); 16145386Swpaulstatic int ti_encap __P((struct ti_softc *, struct mbuf *, 16245386Swpaul u_int32_t *)); 16345386Swpaul 16445386Swpaulstatic void ti_intr __P((void *)); 16545386Swpaulstatic void ti_start __P((struct ifnet *)); 16645386Swpaulstatic int ti_ioctl __P((struct ifnet *, u_long, caddr_t)); 16745386Swpaulstatic void ti_init __P((void *)); 16845386Swpaulstatic void ti_init2 __P((struct ti_softc *)); 16945386Swpaulstatic void ti_stop __P((struct ti_softc *)); 17045386Swpaulstatic void ti_watchdog __P((struct ifnet *)); 17149011Swpaulstatic void ti_shutdown __P((device_t)); 17245386Swpaulstatic int ti_ifmedia_upd __P((struct ifnet *)); 17345386Swpaulstatic void ti_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); 17445386Swpaul 17545386Swpaulstatic u_int32_t ti_eeprom_putbyte __P((struct ti_softc *, int)); 17645386Swpaulstatic u_int8_t ti_eeprom_getbyte __P((struct ti_softc *, 17745386Swpaul int, u_int8_t *)); 17845386Swpaulstatic int ti_read_eeprom __P((struct ti_softc *, caddr_t, int, int)); 17945386Swpaul 18045386Swpaulstatic void ti_add_mcast __P((struct ti_softc *, struct ether_addr *)); 18145386Swpaulstatic void ti_del_mcast __P((struct ti_softc *, struct ether_addr *)); 18245386Swpaulstatic void ti_setmulti __P((struct ti_softc *)); 18345386Swpaul 18445386Swpaulstatic void ti_mem __P((struct ti_softc *, u_int32_t, 18545386Swpaul u_int32_t, caddr_t)); 18645386Swpaulstatic void ti_loadfw __P((struct ti_softc *)); 18745386Swpaulstatic void ti_cmd __P((struct ti_softc *, struct ti_cmd_desc *)); 18845386Swpaulstatic void ti_cmd_ext __P((struct ti_softc *, struct ti_cmd_desc *, 18945386Swpaul caddr_t, int)); 19045386Swpaulstatic void ti_handle_events __P((struct ti_softc *)); 19145386Swpaulstatic int ti_alloc_jumbo_mem __P((struct ti_softc *)); 19245386Swpaulstatic void *ti_jalloc __P((struct ti_softc *)); 19364837Sdwmalonestatic void ti_jfree __P((caddr_t, void *)); 19445386Swpaulstatic int ti_newbuf_std __P((struct ti_softc *, int, struct mbuf *)); 19545386Swpaulstatic int ti_newbuf_mini __P((struct ti_softc *, int, struct mbuf *)); 19645386Swpaulstatic int ti_newbuf_jumbo __P((struct ti_softc *, int, struct mbuf *)); 19745386Swpaulstatic int ti_init_rx_ring_std __P((struct ti_softc *)); 19845386Swpaulstatic void ti_free_rx_ring_std __P((struct ti_softc *)); 19945386Swpaulstatic int ti_init_rx_ring_jumbo __P((struct ti_softc *)); 20045386Swpaulstatic void ti_free_rx_ring_jumbo __P((struct ti_softc *)); 20145386Swpaulstatic int ti_init_rx_ring_mini __P((struct ti_softc *)); 20245386Swpaulstatic void ti_free_rx_ring_mini __P((struct ti_softc *)); 20345386Swpaulstatic void ti_free_tx_ring __P((struct ti_softc *)); 20445386Swpaulstatic int ti_init_tx_ring __P((struct ti_softc *)); 20545386Swpaul 20645386Swpaulstatic int ti_64bitslot_war __P((struct ti_softc *)); 20745386Swpaulstatic int ti_chipinit __P((struct ti_softc *)); 20845386Swpaulstatic int ti_gibinit __P((struct ti_softc *)); 20945386Swpaul 21049011Swpaulstatic device_method_t ti_methods[] = { 21149011Swpaul /* Device interface */ 21249011Swpaul DEVMETHOD(device_probe, ti_probe), 21349011Swpaul DEVMETHOD(device_attach, ti_attach), 21449011Swpaul DEVMETHOD(device_detach, ti_detach), 21549011Swpaul DEVMETHOD(device_shutdown, ti_shutdown), 21649011Swpaul { 0, 0 } 21749011Swpaul}; 21849011Swpaul 21949011Swpaulstatic driver_t ti_driver = { 22051455Swpaul "ti", 22149011Swpaul ti_methods, 22249011Swpaul sizeof(struct ti_softc) 22349011Swpaul}; 22449011Swpaul 22549011Swpaulstatic devclass_t ti_devclass; 22649011Swpaul 22751533SwpaulDRIVER_MODULE(if_ti, pci, ti_driver, ti_devclass, 0, 0); 22849011Swpaul 22945386Swpaul/* 23045386Swpaul * Send an instruction or address to the EEPROM, check for ACK. 23145386Swpaul */ 23245386Swpaulstatic u_int32_t ti_eeprom_putbyte(sc, byte) 23345386Swpaul struct ti_softc *sc; 23445386Swpaul int byte; 23545386Swpaul{ 23645386Swpaul register int i, ack = 0; 23745386Swpaul 23845386Swpaul /* 23945386Swpaul * Make sure we're in TX mode. 24045386Swpaul */ 24145386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); 24245386Swpaul 24345386Swpaul /* 24445386Swpaul * Feed in each bit and stobe the clock. 24545386Swpaul */ 24645386Swpaul for (i = 0x80; i; i >>= 1) { 24745386Swpaul if (byte & i) { 24845386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); 24945386Swpaul } else { 25045386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_DOUT); 25145386Swpaul } 25245386Swpaul DELAY(1); 25345386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 25445386Swpaul DELAY(1); 25545386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 25645386Swpaul } 25745386Swpaul 25845386Swpaul /* 25945386Swpaul * Turn off TX mode. 26045386Swpaul */ 26145386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); 26245386Swpaul 26345386Swpaul /* 26445386Swpaul * Check for ack. 26545386Swpaul */ 26645386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 26745386Swpaul ack = CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN; 26845386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 26945386Swpaul 27045386Swpaul return(ack); 27145386Swpaul} 27245386Swpaul 27345386Swpaul/* 27445386Swpaul * Read a byte of data stored in the EEPROM at address 'addr.' 27545386Swpaul * We have to send two address bytes since the EEPROM can hold 27645386Swpaul * more than 256 bytes of data. 27745386Swpaul */ 27845386Swpaulstatic u_int8_t ti_eeprom_getbyte(sc, addr, dest) 27945386Swpaul struct ti_softc *sc; 28045386Swpaul int addr; 28145386Swpaul u_int8_t *dest; 28245386Swpaul{ 28345386Swpaul register int i; 28445386Swpaul u_int8_t byte = 0; 28545386Swpaul 28645386Swpaul EEPROM_START; 28745386Swpaul 28845386Swpaul /* 28945386Swpaul * Send write control code to EEPROM. 29045386Swpaul */ 29145386Swpaul if (ti_eeprom_putbyte(sc, EEPROM_CTL_WRITE)) { 29245386Swpaul printf("ti%d: failed to send write command, status: %x\n", 29345386Swpaul sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL)); 29445386Swpaul return(1); 29545386Swpaul } 29645386Swpaul 29745386Swpaul /* 29845386Swpaul * Send first byte of address of byte we want to read. 29945386Swpaul */ 30045386Swpaul if (ti_eeprom_putbyte(sc, (addr >> 8) & 0xFF)) { 30145386Swpaul printf("ti%d: failed to send address, status: %x\n", 30245386Swpaul sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL)); 30345386Swpaul return(1); 30445386Swpaul } 30545386Swpaul /* 30645386Swpaul * Send second byte address of byte we want to read. 30745386Swpaul */ 30845386Swpaul if (ti_eeprom_putbyte(sc, addr & 0xFF)) { 30945386Swpaul printf("ti%d: failed to send address, status: %x\n", 31045386Swpaul sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL)); 31145386Swpaul return(1); 31245386Swpaul } 31345386Swpaul 31445386Swpaul EEPROM_STOP; 31545386Swpaul EEPROM_START; 31645386Swpaul /* 31745386Swpaul * Send read control code to EEPROM. 31845386Swpaul */ 31945386Swpaul if (ti_eeprom_putbyte(sc, EEPROM_CTL_READ)) { 32045386Swpaul printf("ti%d: failed to send read command, status: %x\n", 32145386Swpaul sc->ti_unit, CSR_READ_4(sc, TI_MISC_LOCAL_CTL)); 32245386Swpaul return(1); 32345386Swpaul } 32445386Swpaul 32545386Swpaul /* 32645386Swpaul * Start reading bits from EEPROM. 32745386Swpaul */ 32845386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_TXEN); 32945386Swpaul for (i = 0x80; i; i >>= 1) { 33045386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 33145386Swpaul DELAY(1); 33245386Swpaul if (CSR_READ_4(sc, TI_MISC_LOCAL_CTL) & TI_MLC_EE_DIN) 33345386Swpaul byte |= i; 33445386Swpaul TI_CLRBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_EE_CLK); 33545386Swpaul DELAY(1); 33645386Swpaul } 33745386Swpaul 33845386Swpaul EEPROM_STOP; 33945386Swpaul 34045386Swpaul /* 34145386Swpaul * No ACK generated for read, so just return byte. 34245386Swpaul */ 34345386Swpaul 34445386Swpaul *dest = byte; 34545386Swpaul 34645386Swpaul return(0); 34745386Swpaul} 34845386Swpaul 34945386Swpaul/* 35045386Swpaul * Read a sequence of bytes from the EEPROM. 35145386Swpaul */ 35245386Swpaulstatic int ti_read_eeprom(sc, dest, off, cnt) 35345386Swpaul struct ti_softc *sc; 35445386Swpaul caddr_t dest; 35545386Swpaul int off; 35645386Swpaul int cnt; 35745386Swpaul{ 35845386Swpaul int err = 0, i; 35945386Swpaul u_int8_t byte = 0; 36045386Swpaul 36145386Swpaul for (i = 0; i < cnt; i++) { 36245386Swpaul err = ti_eeprom_getbyte(sc, off + i, &byte); 36345386Swpaul if (err) 36445386Swpaul break; 36545386Swpaul *(dest + i) = byte; 36645386Swpaul } 36745386Swpaul 36845386Swpaul return(err ? 1 : 0); 36945386Swpaul} 37045386Swpaul 37145386Swpaul/* 37245386Swpaul * NIC memory access function. Can be used to either clear a section 37345386Swpaul * of NIC local memory or (if buf is non-NULL) copy data into it. 37445386Swpaul */ 37545386Swpaulstatic void ti_mem(sc, addr, len, buf) 37645386Swpaul struct ti_softc *sc; 37745386Swpaul u_int32_t addr, len; 37845386Swpaul caddr_t buf; 37945386Swpaul{ 38045386Swpaul int segptr, segsize, cnt; 38145386Swpaul caddr_t ti_winbase, ptr; 38245386Swpaul 38345386Swpaul segptr = addr; 38445386Swpaul cnt = len; 38549133Swpaul ti_winbase = (caddr_t)(sc->ti_vhandle + TI_WINDOW); 38645386Swpaul ptr = buf; 38745386Swpaul 38845386Swpaul while(cnt) { 38945386Swpaul if (cnt < TI_WINLEN) 39045386Swpaul segsize = cnt; 39145386Swpaul else 39245386Swpaul segsize = TI_WINLEN - (segptr % TI_WINLEN); 39345386Swpaul CSR_WRITE_4(sc, TI_WINBASE, (segptr & ~(TI_WINLEN - 1))); 39445386Swpaul if (buf == NULL) 39545386Swpaul bzero((char *)ti_winbase + (segptr & 39645386Swpaul (TI_WINLEN - 1)), segsize); 39745386Swpaul else { 39845386Swpaul bcopy((char *)ptr, (char *)ti_winbase + 39945386Swpaul (segptr & (TI_WINLEN - 1)), segsize); 40045386Swpaul ptr += segsize; 40145386Swpaul } 40245386Swpaul segptr += segsize; 40345386Swpaul cnt -= segsize; 40445386Swpaul } 40545386Swpaul 40645386Swpaul return; 40745386Swpaul} 40845386Swpaul 40945386Swpaul/* 41045386Swpaul * Load firmware image into the NIC. Check that the firmware revision 41145386Swpaul * is acceptable and see if we want the firmware for the Tigon 1 or 41245386Swpaul * Tigon 2. 41345386Swpaul */ 41445386Swpaulstatic void ti_loadfw(sc) 41545386Swpaul struct ti_softc *sc; 41645386Swpaul{ 41745386Swpaul switch(sc->ti_hwrev) { 41845386Swpaul case TI_HWREV_TIGON: 41945386Swpaul if (tigonFwReleaseMajor != TI_FIRMWARE_MAJOR || 42045386Swpaul tigonFwReleaseMinor != TI_FIRMWARE_MINOR || 42145386Swpaul tigonFwReleaseFix != TI_FIRMWARE_FIX) { 42245386Swpaul printf("ti%d: firmware revision mismatch; want " 42345386Swpaul "%d.%d.%d, got %d.%d.%d\n", sc->ti_unit, 42445386Swpaul TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR, 42545386Swpaul TI_FIRMWARE_FIX, tigonFwReleaseMajor, 42645386Swpaul tigonFwReleaseMinor, tigonFwReleaseFix); 42745386Swpaul return; 42845386Swpaul } 42945386Swpaul ti_mem(sc, tigonFwTextAddr, tigonFwTextLen, 43045386Swpaul (caddr_t)tigonFwText); 43145386Swpaul ti_mem(sc, tigonFwDataAddr, tigonFwDataLen, 43245386Swpaul (caddr_t)tigonFwData); 43345386Swpaul ti_mem(sc, tigonFwRodataAddr, tigonFwRodataLen, 43445386Swpaul (caddr_t)tigonFwRodata); 43545386Swpaul ti_mem(sc, tigonFwBssAddr, tigonFwBssLen, NULL); 43645386Swpaul ti_mem(sc, tigonFwSbssAddr, tigonFwSbssLen, NULL); 43745386Swpaul CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigonFwStartAddr); 43845386Swpaul break; 43945386Swpaul case TI_HWREV_TIGON_II: 44045386Swpaul if (tigon2FwReleaseMajor != TI_FIRMWARE_MAJOR || 44145386Swpaul tigon2FwReleaseMinor != TI_FIRMWARE_MINOR || 44245386Swpaul tigon2FwReleaseFix != TI_FIRMWARE_FIX) { 44345386Swpaul printf("ti%d: firmware revision mismatch; want " 44445386Swpaul "%d.%d.%d, got %d.%d.%d\n", sc->ti_unit, 44545386Swpaul TI_FIRMWARE_MAJOR, TI_FIRMWARE_MINOR, 44645386Swpaul TI_FIRMWARE_FIX, tigon2FwReleaseMajor, 44745386Swpaul tigon2FwReleaseMinor, tigon2FwReleaseFix); 44845386Swpaul return; 44945386Swpaul } 45045386Swpaul ti_mem(sc, tigon2FwTextAddr, tigon2FwTextLen, 45145386Swpaul (caddr_t)tigon2FwText); 45245386Swpaul ti_mem(sc, tigon2FwDataAddr, tigon2FwDataLen, 45345386Swpaul (caddr_t)tigon2FwData); 45445386Swpaul ti_mem(sc, tigon2FwRodataAddr, tigon2FwRodataLen, 45545386Swpaul (caddr_t)tigon2FwRodata); 45645386Swpaul ti_mem(sc, tigon2FwBssAddr, tigon2FwBssLen, NULL); 45745386Swpaul ti_mem(sc, tigon2FwSbssAddr, tigon2FwSbssLen, NULL); 45845386Swpaul CSR_WRITE_4(sc, TI_CPU_PROGRAM_COUNTER, tigon2FwStartAddr); 45945386Swpaul break; 46045386Swpaul default: 46145386Swpaul printf("ti%d: can't load firmware: unknown hardware rev\n", 46245386Swpaul sc->ti_unit); 46345386Swpaul break; 46445386Swpaul } 46545386Swpaul 46645386Swpaul return; 46745386Swpaul} 46845386Swpaul 46945386Swpaul/* 47045386Swpaul * Send the NIC a command via the command ring. 47145386Swpaul */ 47245386Swpaulstatic void ti_cmd(sc, cmd) 47345386Swpaul struct ti_softc *sc; 47445386Swpaul struct ti_cmd_desc *cmd; 47545386Swpaul{ 47645386Swpaul u_int32_t index; 47745386Swpaul 47845386Swpaul if (sc->ti_rdata->ti_cmd_ring == NULL) 47945386Swpaul return; 48045386Swpaul 48145386Swpaul index = sc->ti_cmd_saved_prodidx; 48245386Swpaul CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd)); 48345386Swpaul TI_INC(index, TI_CMD_RING_CNT); 48445386Swpaul CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index); 48545386Swpaul sc->ti_cmd_saved_prodidx = index; 48645386Swpaul 48745386Swpaul return; 48845386Swpaul} 48945386Swpaul 49045386Swpaul/* 49145386Swpaul * Send the NIC an extended command. The 'len' parameter specifies the 49245386Swpaul * number of command slots to include after the initial command. 49345386Swpaul */ 49445386Swpaulstatic void ti_cmd_ext(sc, cmd, arg, len) 49545386Swpaul struct ti_softc *sc; 49645386Swpaul struct ti_cmd_desc *cmd; 49745386Swpaul caddr_t arg; 49845386Swpaul int len; 49945386Swpaul{ 50045386Swpaul u_int32_t index; 50145386Swpaul register int i; 50245386Swpaul 50345386Swpaul if (sc->ti_rdata->ti_cmd_ring == NULL) 50445386Swpaul return; 50545386Swpaul 50645386Swpaul index = sc->ti_cmd_saved_prodidx; 50745386Swpaul CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), *(u_int32_t *)(cmd)); 50845386Swpaul TI_INC(index, TI_CMD_RING_CNT); 50945386Swpaul for (i = 0; i < len; i++) { 51045386Swpaul CSR_WRITE_4(sc, TI_GCR_CMDRING + (index * 4), 51145386Swpaul *(u_int32_t *)(&arg[i * 4])); 51245386Swpaul TI_INC(index, TI_CMD_RING_CNT); 51345386Swpaul } 51445386Swpaul CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, index); 51545386Swpaul sc->ti_cmd_saved_prodidx = index; 51645386Swpaul 51745386Swpaul return; 51845386Swpaul} 51945386Swpaul 52045386Swpaul/* 52145386Swpaul * Handle events that have triggered interrupts. 52245386Swpaul */ 52345386Swpaulstatic void ti_handle_events(sc) 52445386Swpaul struct ti_softc *sc; 52545386Swpaul{ 52645386Swpaul struct ti_event_desc *e; 52745386Swpaul 52845386Swpaul if (sc->ti_rdata->ti_event_ring == NULL) 52945386Swpaul return; 53045386Swpaul 53145386Swpaul while (sc->ti_ev_saved_considx != sc->ti_ev_prodidx.ti_idx) { 53245386Swpaul e = &sc->ti_rdata->ti_event_ring[sc->ti_ev_saved_considx]; 53345386Swpaul switch(e->ti_event) { 53445386Swpaul case TI_EV_LINKSTAT_CHANGED: 53545386Swpaul sc->ti_linkstat = e->ti_code; 53645386Swpaul if (e->ti_code == TI_EV_CODE_LINK_UP) 53745386Swpaul printf("ti%d: 10/100 link up\n", sc->ti_unit); 53845386Swpaul else if (e->ti_code == TI_EV_CODE_GIG_LINK_UP) 53945386Swpaul printf("ti%d: gigabit link up\n", sc->ti_unit); 54045386Swpaul else if (e->ti_code == TI_EV_CODE_LINK_DOWN) 54145386Swpaul printf("ti%d: link down\n", sc->ti_unit); 54245386Swpaul break; 54345386Swpaul case TI_EV_ERROR: 54445386Swpaul if (e->ti_code == TI_EV_CODE_ERR_INVAL_CMD) 54545386Swpaul printf("ti%d: invalid command\n", sc->ti_unit); 54645386Swpaul else if (e->ti_code == TI_EV_CODE_ERR_UNIMP_CMD) 54745386Swpaul printf("ti%d: unknown command\n", sc->ti_unit); 54845386Swpaul else if (e->ti_code == TI_EV_CODE_ERR_BADCFG) 54945386Swpaul printf("ti%d: bad config data\n", sc->ti_unit); 55045386Swpaul break; 55145386Swpaul case TI_EV_FIRMWARE_UP: 55245386Swpaul ti_init2(sc); 55345386Swpaul break; 55445386Swpaul case TI_EV_STATS_UPDATED: 55545386Swpaul ti_stats_update(sc); 55645386Swpaul break; 55745386Swpaul case TI_EV_RESET_JUMBO_RING: 55845386Swpaul case TI_EV_MCAST_UPDATED: 55945386Swpaul /* Who cares. */ 56045386Swpaul break; 56145386Swpaul default: 56245386Swpaul printf("ti%d: unknown event: %d\n", 56345386Swpaul sc->ti_unit, e->ti_event); 56445386Swpaul break; 56545386Swpaul } 56645386Swpaul /* Advance the consumer index. */ 56745386Swpaul TI_INC(sc->ti_ev_saved_considx, TI_EVENT_RING_CNT); 56845386Swpaul CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, sc->ti_ev_saved_considx); 56945386Swpaul } 57045386Swpaul 57145386Swpaul return; 57245386Swpaul} 57345386Swpaul 57445386Swpaul/* 57545386Swpaul * Memory management for the jumbo receive ring is a pain in the 57645386Swpaul * butt. We need to allocate at least 9018 bytes of space per frame, 57745386Swpaul * _and_ it has to be contiguous (unless you use the extended 57845386Swpaul * jumbo descriptor format). Using malloc() all the time won't 57945386Swpaul * work: malloc() allocates memory in powers of two, which means we 58045386Swpaul * would end up wasting a considerable amount of space by allocating 58145386Swpaul * 9K chunks. We don't have a jumbo mbuf cluster pool. Thus, we have 58245386Swpaul * to do our own memory management. 58345386Swpaul * 58445386Swpaul * The driver needs to allocate a contiguous chunk of memory at boot 58545386Swpaul * time. We then chop this up ourselves into 9K pieces and use them 58645386Swpaul * as external mbuf storage. 58745386Swpaul * 58845386Swpaul * One issue here is how much memory to allocate. The jumbo ring has 58945386Swpaul * 256 slots in it, but at 9K per slot than can consume over 2MB of 59045386Swpaul * RAM. This is a bit much, especially considering we also need 59145386Swpaul * RAM for the standard ring and mini ring (on the Tigon 2). To 59245386Swpaul * save space, we only actually allocate enough memory for 64 slots 59345386Swpaul * by default, which works out to between 500 and 600K. This can 59445386Swpaul * be tuned by changing a #define in if_tireg.h. 59545386Swpaul */ 59645386Swpaul 59745386Swpaulstatic int ti_alloc_jumbo_mem(sc) 59845386Swpaul struct ti_softc *sc; 59945386Swpaul{ 60045386Swpaul caddr_t ptr; 60145386Swpaul register int i; 60245386Swpaul struct ti_jpool_entry *entry; 60345386Swpaul 60445386Swpaul /* Grab a big chunk o' storage. */ 60545386Swpaul sc->ti_cdata.ti_jumbo_buf = contigmalloc(TI_JMEM, M_DEVBUF, 60650548Sbde M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 60745386Swpaul 60845386Swpaul if (sc->ti_cdata.ti_jumbo_buf == NULL) { 60945386Swpaul printf("ti%d: no memory for jumbo buffers!\n", sc->ti_unit); 61045386Swpaul return(ENOBUFS); 61145386Swpaul } 61245386Swpaul 61345386Swpaul SLIST_INIT(&sc->ti_jfree_listhead); 61445386Swpaul SLIST_INIT(&sc->ti_jinuse_listhead); 61545386Swpaul 61645386Swpaul /* 61745386Swpaul * Now divide it up into 9K pieces and save the addresses 61845386Swpaul * in an array. Note that we play an evil trick here by using 61945386Swpaul * the first few bytes in the buffer to hold the the address 62045386Swpaul * of the softc structure for this interface. This is because 62145386Swpaul * ti_jfree() needs it, but it is called by the mbuf management 62245386Swpaul * code which will not pass it to us explicitly. 62345386Swpaul */ 62445386Swpaul ptr = sc->ti_cdata.ti_jumbo_buf; 62545386Swpaul for (i = 0; i < TI_JSLOTS; i++) { 62645386Swpaul u_int64_t **aptr; 62745386Swpaul aptr = (u_int64_t **)ptr; 62845386Swpaul aptr[0] = (u_int64_t *)sc; 62945386Swpaul ptr += sizeof(u_int64_t); 63045386Swpaul sc->ti_cdata.ti_jslots[i].ti_buf = ptr; 63145386Swpaul ptr += (TI_JLEN - sizeof(u_int64_t)); 63245386Swpaul entry = malloc(sizeof(struct ti_jpool_entry), 63345386Swpaul M_DEVBUF, M_NOWAIT); 63445386Swpaul if (entry == NULL) { 63562793Sgallatin contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, 63662793Sgallatin M_DEVBUF); 63745386Swpaul sc->ti_cdata.ti_jumbo_buf = NULL; 63845386Swpaul printf("ti%d: no memory for jumbo " 63945386Swpaul "buffer queue!\n", sc->ti_unit); 64045386Swpaul return(ENOBUFS); 64145386Swpaul } 64245386Swpaul entry->slot = i; 64345386Swpaul SLIST_INSERT_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries); 64445386Swpaul } 64545386Swpaul 64645386Swpaul return(0); 64745386Swpaul} 64845386Swpaul 64945386Swpaul/* 65045386Swpaul * Allocate a jumbo buffer. 65145386Swpaul */ 65245386Swpaulstatic void *ti_jalloc(sc) 65345386Swpaul struct ti_softc *sc; 65445386Swpaul{ 65545386Swpaul struct ti_jpool_entry *entry; 65645386Swpaul 65745386Swpaul entry = SLIST_FIRST(&sc->ti_jfree_listhead); 65845386Swpaul 65945386Swpaul if (entry == NULL) { 66045386Swpaul printf("ti%d: no free jumbo buffers\n", sc->ti_unit); 66145386Swpaul return(NULL); 66245386Swpaul } 66345386Swpaul 66445386Swpaul SLIST_REMOVE_HEAD(&sc->ti_jfree_listhead, jpool_entries); 66545386Swpaul SLIST_INSERT_HEAD(&sc->ti_jinuse_listhead, entry, jpool_entries); 66645386Swpaul return(sc->ti_cdata.ti_jslots[entry->slot].ti_buf); 66745386Swpaul} 66845386Swpaul 66945386Swpaul/* 67045386Swpaul * Release a jumbo buffer. 67145386Swpaul */ 67264837Sdwmalonestatic void ti_jfree(buf, args) 67345386Swpaul caddr_t buf; 67464837Sdwmalone void *args; 67545386Swpaul{ 67645386Swpaul struct ti_softc *sc; 67745386Swpaul u_int64_t **aptr; 67845386Swpaul int i; 67945386Swpaul struct ti_jpool_entry *entry; 68045386Swpaul 68145386Swpaul /* Extract the softc struct pointer. */ 68245386Swpaul aptr = (u_int64_t **)(buf - sizeof(u_int64_t)); 68345386Swpaul sc = (struct ti_softc *)(aptr[0]); 68445386Swpaul 68545386Swpaul if (sc == NULL) 68645386Swpaul panic("ti_jfree: can't find softc pointer!"); 68745386Swpaul 68845386Swpaul /* calculate the slot this buffer belongs to */ 68945386Swpaul i = ((vm_offset_t)aptr 69045386Swpaul - (vm_offset_t)sc->ti_cdata.ti_jumbo_buf) / TI_JLEN; 69145386Swpaul 69245386Swpaul if ((i < 0) || (i >= TI_JSLOTS)) 69345386Swpaul panic("ti_jfree: asked to free buffer that we don't manage!"); 69445386Swpaul 69564837Sdwmalone entry = SLIST_FIRST(&sc->ti_jinuse_listhead); 69664837Sdwmalone if (entry == NULL) 69764837Sdwmalone panic("ti_jfree: buffer not in use!"); 69864837Sdwmalone entry->slot = i; 69964837Sdwmalone SLIST_REMOVE_HEAD(&sc->ti_jinuse_listhead, jpool_entries); 70064837Sdwmalone SLIST_INSERT_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries); 70164837Sdwmalone 70245386Swpaul return; 70345386Swpaul} 70445386Swpaul 70545386Swpaul 70645386Swpaul/* 70745386Swpaul * Intialize a standard receive ring descriptor. 70845386Swpaul */ 70945386Swpaulstatic int ti_newbuf_std(sc, i, m) 71045386Swpaul struct ti_softc *sc; 71145386Swpaul int i; 71245386Swpaul struct mbuf *m; 71345386Swpaul{ 71445386Swpaul struct mbuf *m_new = NULL; 71545386Swpaul struct ti_rx_desc *r; 71645386Swpaul 71749036Swpaul if (m == NULL) { 71845386Swpaul MGETHDR(m_new, M_DONTWAIT, MT_DATA); 71945386Swpaul if (m_new == NULL) { 72045386Swpaul printf("ti%d: mbuf allocation failed " 72145386Swpaul "-- packet dropped!\n", sc->ti_unit); 72245386Swpaul return(ENOBUFS); 72345386Swpaul } 72445386Swpaul 72545386Swpaul MCLGET(m_new, M_DONTWAIT); 72645386Swpaul if (!(m_new->m_flags & M_EXT)) { 72745386Swpaul printf("ti%d: cluster allocation failed " 72845386Swpaul "-- packet dropped!\n", sc->ti_unit); 72945386Swpaul m_freem(m_new); 73045386Swpaul return(ENOBUFS); 73145386Swpaul } 73249036Swpaul m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 73349036Swpaul } else { 73449036Swpaul m_new = m; 73549036Swpaul m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 73649036Swpaul m_new->m_data = m_new->m_ext.ext_buf; 73745386Swpaul } 73845386Swpaul 73948597Swpaul m_adj(m_new, ETHER_ALIGN); 74045386Swpaul sc->ti_cdata.ti_rx_std_chain[i] = m_new; 74145386Swpaul r = &sc->ti_rdata->ti_rx_std_ring[i]; 74245386Swpaul TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t)); 74345386Swpaul r->ti_type = TI_BDTYPE_RECV_BD; 74445386Swpaul r->ti_flags = 0; 74558698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 74658698Sjlemon r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM; 74749036Swpaul r->ti_len = m_new->m_len; 74845386Swpaul r->ti_idx = i; 74945386Swpaul 75045386Swpaul return(0); 75145386Swpaul} 75245386Swpaul 75345386Swpaul/* 75445386Swpaul * Intialize a mini receive ring descriptor. This only applies to 75545386Swpaul * the Tigon 2. 75645386Swpaul */ 75745386Swpaulstatic int ti_newbuf_mini(sc, i, m) 75845386Swpaul struct ti_softc *sc; 75945386Swpaul int i; 76045386Swpaul struct mbuf *m; 76145386Swpaul{ 76245386Swpaul struct mbuf *m_new = NULL; 76345386Swpaul struct ti_rx_desc *r; 76445386Swpaul 76549036Swpaul if (m == NULL) { 76645386Swpaul MGETHDR(m_new, M_DONTWAIT, MT_DATA); 76745386Swpaul if (m_new == NULL) { 76845386Swpaul printf("ti%d: mbuf allocation failed " 76945386Swpaul "-- packet dropped!\n", sc->ti_unit); 77045386Swpaul return(ENOBUFS); 77145386Swpaul } 77249036Swpaul m_new->m_len = m_new->m_pkthdr.len = MHLEN; 77349036Swpaul } else { 77449036Swpaul m_new = m; 77549036Swpaul m_new->m_data = m_new->m_pktdat; 77649036Swpaul m_new->m_len = m_new->m_pkthdr.len = MHLEN; 77745386Swpaul } 77849036Swpaul 77948597Swpaul m_adj(m_new, ETHER_ALIGN); 78045386Swpaul r = &sc->ti_rdata->ti_rx_mini_ring[i]; 78145386Swpaul sc->ti_cdata.ti_rx_mini_chain[i] = m_new; 78245386Swpaul TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t)); 78345386Swpaul r->ti_type = TI_BDTYPE_RECV_BD; 78445386Swpaul r->ti_flags = TI_BDFLAG_MINI_RING; 78558698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 78658698Sjlemon r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM; 78749036Swpaul r->ti_len = m_new->m_len; 78845386Swpaul r->ti_idx = i; 78945386Swpaul 79045386Swpaul return(0); 79145386Swpaul} 79245386Swpaul 79345386Swpaul/* 79445386Swpaul * Initialize a jumbo receive ring descriptor. This allocates 79545386Swpaul * a jumbo buffer from the pool managed internally by the driver. 79645386Swpaul */ 79745386Swpaulstatic int ti_newbuf_jumbo(sc, i, m) 79845386Swpaul struct ti_softc *sc; 79945386Swpaul int i; 80045386Swpaul struct mbuf *m; 80145386Swpaul{ 80245386Swpaul struct mbuf *m_new = NULL; 80345386Swpaul struct ti_rx_desc *r; 80445386Swpaul 80549036Swpaul if (m == NULL) { 80645386Swpaul caddr_t *buf = NULL; 80745386Swpaul 80845386Swpaul /* Allocate the mbuf. */ 80945386Swpaul MGETHDR(m_new, M_DONTWAIT, MT_DATA); 81045386Swpaul if (m_new == NULL) { 81145386Swpaul printf("ti%d: mbuf allocation failed " 81245386Swpaul "-- packet dropped!\n", sc->ti_unit); 81345386Swpaul return(ENOBUFS); 81445386Swpaul } 81545386Swpaul 81645386Swpaul /* Allocate the jumbo buffer */ 81745386Swpaul buf = ti_jalloc(sc); 81845386Swpaul if (buf == NULL) { 81945386Swpaul m_freem(m_new); 82045386Swpaul printf("ti%d: jumbo allocation failed " 82145386Swpaul "-- packet dropped!\n", sc->ti_unit); 82245386Swpaul return(ENOBUFS); 82345386Swpaul } 82445386Swpaul 82545386Swpaul /* Attach the buffer to the mbuf. */ 82664837Sdwmalone m_new->m_data = (void *) buf; 82764837Sdwmalone m_new->m_len = m_new->m_pkthdr.len = TI_JUMBO_FRAMELEN; 82864837Sdwmalone MEXTADD(m_new, buf, TI_JUMBO_FRAMELEN, ti_jfree, NULL); 82949036Swpaul } else { 83049036Swpaul m_new = m; 83149036Swpaul m_new->m_data = m_new->m_ext.ext_buf; 83249036Swpaul m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN; 83345386Swpaul } 83445386Swpaul 83549780Swpaul m_adj(m_new, ETHER_ALIGN); 83645386Swpaul /* Set up the descriptor. */ 83745386Swpaul r = &sc->ti_rdata->ti_rx_jumbo_ring[i]; 83845386Swpaul sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new; 83945386Swpaul TI_HOSTADDR(r->ti_addr) = vtophys(mtod(m_new, caddr_t)); 84045386Swpaul r->ti_type = TI_BDTYPE_RECV_JUMBO_BD; 84145386Swpaul r->ti_flags = TI_BDFLAG_JUMBO_RING; 84258698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 84358698Sjlemon r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM | TI_BDFLAG_IP_CKSUM; 84449036Swpaul r->ti_len = m_new->m_len; 84545386Swpaul r->ti_idx = i; 84645386Swpaul 84745386Swpaul return(0); 84845386Swpaul} 84945386Swpaul 85045386Swpaul/* 85145386Swpaul * The standard receive ring has 512 entries in it. At 2K per mbuf cluster, 85245386Swpaul * that's 1MB or memory, which is a lot. For now, we fill only the first 85345386Swpaul * 256 ring entries and hope that our CPU is fast enough to keep up with 85445386Swpaul * the NIC. 85545386Swpaul */ 85645386Swpaulstatic int ti_init_rx_ring_std(sc) 85745386Swpaul struct ti_softc *sc; 85845386Swpaul{ 85945386Swpaul register int i; 86045386Swpaul struct ti_cmd_desc cmd; 86145386Swpaul 86245386Swpaul for (i = 0; i < TI_SSLOTS; i++) { 86345386Swpaul if (ti_newbuf_std(sc, i, NULL) == ENOBUFS) 86445386Swpaul return(ENOBUFS); 86545386Swpaul }; 86645386Swpaul 86745386Swpaul TI_UPDATE_STDPROD(sc, i - 1); 86848597Swpaul sc->ti_std = i - 1; 86945386Swpaul 87045386Swpaul return(0); 87145386Swpaul} 87245386Swpaul 87345386Swpaulstatic void ti_free_rx_ring_std(sc) 87445386Swpaul struct ti_softc *sc; 87545386Swpaul{ 87645386Swpaul register int i; 87745386Swpaul 87845386Swpaul for (i = 0; i < TI_STD_RX_RING_CNT; i++) { 87945386Swpaul if (sc->ti_cdata.ti_rx_std_chain[i] != NULL) { 88045386Swpaul m_freem(sc->ti_cdata.ti_rx_std_chain[i]); 88145386Swpaul sc->ti_cdata.ti_rx_std_chain[i] = NULL; 88245386Swpaul } 88345386Swpaul bzero((char *)&sc->ti_rdata->ti_rx_std_ring[i], 88445386Swpaul sizeof(struct ti_rx_desc)); 88545386Swpaul } 88645386Swpaul 88745386Swpaul return; 88845386Swpaul} 88945386Swpaul 89045386Swpaulstatic int ti_init_rx_ring_jumbo(sc) 89145386Swpaul struct ti_softc *sc; 89245386Swpaul{ 89345386Swpaul register int i; 89445386Swpaul struct ti_cmd_desc cmd; 89545386Swpaul 89663699Swpaul for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) { 89745386Swpaul if (ti_newbuf_jumbo(sc, i, NULL) == ENOBUFS) 89845386Swpaul return(ENOBUFS); 89945386Swpaul }; 90045386Swpaul 90145386Swpaul TI_UPDATE_JUMBOPROD(sc, i - 1); 90248597Swpaul sc->ti_jumbo = i - 1; 90345386Swpaul 90445386Swpaul return(0); 90545386Swpaul} 90645386Swpaul 90745386Swpaulstatic void ti_free_rx_ring_jumbo(sc) 90845386Swpaul struct ti_softc *sc; 90945386Swpaul{ 91045386Swpaul register int i; 91145386Swpaul 91245386Swpaul for (i = 0; i < TI_JUMBO_RX_RING_CNT; i++) { 91345386Swpaul if (sc->ti_cdata.ti_rx_jumbo_chain[i] != NULL) { 91445386Swpaul m_freem(sc->ti_cdata.ti_rx_jumbo_chain[i]); 91545386Swpaul sc->ti_cdata.ti_rx_jumbo_chain[i] = NULL; 91645386Swpaul } 91745386Swpaul bzero((char *)&sc->ti_rdata->ti_rx_jumbo_ring[i], 91845386Swpaul sizeof(struct ti_rx_desc)); 91945386Swpaul } 92045386Swpaul 92145386Swpaul return; 92245386Swpaul} 92345386Swpaul 92445386Swpaulstatic int ti_init_rx_ring_mini(sc) 92545386Swpaul struct ti_softc *sc; 92645386Swpaul{ 92745386Swpaul register int i; 92845386Swpaul 92945386Swpaul for (i = 0; i < TI_MSLOTS; i++) { 93045386Swpaul if (ti_newbuf_mini(sc, i, NULL) == ENOBUFS) 93145386Swpaul return(ENOBUFS); 93245386Swpaul }; 93345386Swpaul 93445386Swpaul TI_UPDATE_MINIPROD(sc, i - 1); 93548597Swpaul sc->ti_mini = i - 1; 93645386Swpaul 93745386Swpaul return(0); 93845386Swpaul} 93945386Swpaul 94045386Swpaulstatic void ti_free_rx_ring_mini(sc) 94145386Swpaul struct ti_softc *sc; 94245386Swpaul{ 94345386Swpaul register int i; 94445386Swpaul 94545386Swpaul for (i = 0; i < TI_MINI_RX_RING_CNT; i++) { 94645386Swpaul if (sc->ti_cdata.ti_rx_mini_chain[i] != NULL) { 94745386Swpaul m_freem(sc->ti_cdata.ti_rx_mini_chain[i]); 94845386Swpaul sc->ti_cdata.ti_rx_mini_chain[i] = NULL; 94945386Swpaul } 95045386Swpaul bzero((char *)&sc->ti_rdata->ti_rx_mini_ring[i], 95145386Swpaul sizeof(struct ti_rx_desc)); 95245386Swpaul } 95345386Swpaul 95445386Swpaul return; 95545386Swpaul} 95645386Swpaul 95745386Swpaulstatic void ti_free_tx_ring(sc) 95845386Swpaul struct ti_softc *sc; 95945386Swpaul{ 96045386Swpaul register int i; 96145386Swpaul 96245386Swpaul if (sc->ti_rdata->ti_tx_ring == NULL) 96345386Swpaul return; 96445386Swpaul 96545386Swpaul for (i = 0; i < TI_TX_RING_CNT; i++) { 96645386Swpaul if (sc->ti_cdata.ti_tx_chain[i] != NULL) { 96745386Swpaul m_freem(sc->ti_cdata.ti_tx_chain[i]); 96845386Swpaul sc->ti_cdata.ti_tx_chain[i] = NULL; 96945386Swpaul } 97045386Swpaul bzero((char *)&sc->ti_rdata->ti_tx_ring[i], 97145386Swpaul sizeof(struct ti_tx_desc)); 97245386Swpaul } 97345386Swpaul 97445386Swpaul return; 97545386Swpaul} 97645386Swpaul 97745386Swpaulstatic int ti_init_tx_ring(sc) 97845386Swpaul struct ti_softc *sc; 97945386Swpaul{ 98048011Swpaul sc->ti_txcnt = 0; 98145386Swpaul sc->ti_tx_saved_considx = 0; 98245386Swpaul CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, 0); 98345386Swpaul return(0); 98445386Swpaul} 98545386Swpaul 98645386Swpaul/* 98745386Swpaul * The Tigon 2 firmware has a new way to add/delete multicast addresses, 98845386Swpaul * but we have to support the old way too so that Tigon 1 cards will 98945386Swpaul * work. 99045386Swpaul */ 99145386Swpaulvoid ti_add_mcast(sc, addr) 99245386Swpaul struct ti_softc *sc; 99345386Swpaul struct ether_addr *addr; 99445386Swpaul{ 99545386Swpaul struct ti_cmd_desc cmd; 99645386Swpaul u_int16_t *m; 99745386Swpaul u_int32_t ext[2] = {0, 0}; 99845386Swpaul 99945386Swpaul m = (u_int16_t *)&addr->octet[0]; 100045386Swpaul 100145386Swpaul switch(sc->ti_hwrev) { 100245386Swpaul case TI_HWREV_TIGON: 100345386Swpaul CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0])); 100445386Swpaul CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2])); 100545386Swpaul TI_DO_CMD(TI_CMD_ADD_MCAST_ADDR, 0, 0); 100645386Swpaul break; 100745386Swpaul case TI_HWREV_TIGON_II: 100845386Swpaul ext[0] = htons(m[0]); 100945386Swpaul ext[1] = (htons(m[1]) << 16) | htons(m[2]); 101045386Swpaul TI_DO_CMD_EXT(TI_CMD_EXT_ADD_MCAST, 0, 0, (caddr_t)&ext, 2); 101145386Swpaul break; 101245386Swpaul default: 101345386Swpaul printf("ti%d: unknown hwrev\n", sc->ti_unit); 101445386Swpaul break; 101545386Swpaul } 101645386Swpaul 101745386Swpaul return; 101845386Swpaul} 101945386Swpaul 102045386Swpaulvoid ti_del_mcast(sc, addr) 102145386Swpaul struct ti_softc *sc; 102245386Swpaul struct ether_addr *addr; 102345386Swpaul{ 102445386Swpaul struct ti_cmd_desc cmd; 102545386Swpaul u_int16_t *m; 102645386Swpaul u_int32_t ext[2] = {0, 0}; 102745386Swpaul 102845386Swpaul m = (u_int16_t *)&addr->octet[0]; 102945386Swpaul 103045386Swpaul switch(sc->ti_hwrev) { 103145386Swpaul case TI_HWREV_TIGON: 103245386Swpaul CSR_WRITE_4(sc, TI_GCR_MAR0, htons(m[0])); 103345386Swpaul CSR_WRITE_4(sc, TI_GCR_MAR1, (htons(m[1]) << 16) | htons(m[2])); 103445386Swpaul TI_DO_CMD(TI_CMD_DEL_MCAST_ADDR, 0, 0); 103545386Swpaul break; 103645386Swpaul case TI_HWREV_TIGON_II: 103745386Swpaul ext[0] = htons(m[0]); 103845386Swpaul ext[1] = (htons(m[1]) << 16) | htons(m[2]); 103945386Swpaul TI_DO_CMD_EXT(TI_CMD_EXT_DEL_MCAST, 0, 0, (caddr_t)&ext, 2); 104045386Swpaul break; 104145386Swpaul default: 104245386Swpaul printf("ti%d: unknown hwrev\n", sc->ti_unit); 104345386Swpaul break; 104445386Swpaul } 104545386Swpaul 104645386Swpaul return; 104745386Swpaul} 104845386Swpaul 104945386Swpaul/* 105045386Swpaul * Configure the Tigon's multicast address filter. 105145386Swpaul * 105245386Swpaul * The actual multicast table management is a bit of a pain, thanks to 105345386Swpaul * slight brain damage on the part of both Alteon and us. With our 105445386Swpaul * multicast code, we are only alerted when the multicast address table 105545386Swpaul * changes and at that point we only have the current list of addresses: 105645386Swpaul * we only know the current state, not the previous state, so we don't 105745386Swpaul * actually know what addresses were removed or added. The firmware has 105845386Swpaul * state, but we can't get our grubby mits on it, and there is no 'delete 105945386Swpaul * all multicast addresses' command. Hence, we have to maintain our own 106045386Swpaul * state so we know what addresses have been programmed into the NIC at 106145386Swpaul * any given time. 106245386Swpaul */ 106345386Swpaulstatic void ti_setmulti(sc) 106445386Swpaul struct ti_softc *sc; 106545386Swpaul{ 106645386Swpaul struct ifnet *ifp; 106745386Swpaul struct ifmultiaddr *ifma; 106845386Swpaul struct ti_cmd_desc cmd; 106945386Swpaul struct ti_mc_entry *mc; 107045386Swpaul u_int32_t intrs; 107145386Swpaul 107245386Swpaul ifp = &sc->arpcom.ac_if; 107345386Swpaul 107445386Swpaul if (ifp->if_flags & IFF_ALLMULTI) { 107545386Swpaul TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_ENB, 0); 107645386Swpaul return; 107745386Swpaul } else { 107845386Swpaul TI_DO_CMD(TI_CMD_SET_ALLMULTI, TI_CMD_CODE_ALLMULTI_DIS, 0); 107945386Swpaul } 108045386Swpaul 108145386Swpaul /* Disable interrupts. */ 108245386Swpaul intrs = CSR_READ_4(sc, TI_MB_HOSTINTR); 108345386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1); 108445386Swpaul 108545386Swpaul /* First, zot all the existing filters. */ 108645386Swpaul while (sc->ti_mc_listhead.slh_first != NULL) { 108745386Swpaul mc = sc->ti_mc_listhead.slh_first; 108845386Swpaul ti_del_mcast(sc, &mc->mc_addr); 108945386Swpaul SLIST_REMOVE_HEAD(&sc->ti_mc_listhead, mc_entries); 109045386Swpaul free(mc, M_DEVBUF); 109145386Swpaul } 109245386Swpaul 109345386Swpaul /* Now program new ones. */ 109445386Swpaul for (ifma = ifp->if_multiaddrs.lh_first; 109545386Swpaul ifma != NULL; ifma = ifma->ifma_link.le_next) { 109645386Swpaul if (ifma->ifma_addr->sa_family != AF_LINK) 109745386Swpaul continue; 109845386Swpaul mc = malloc(sizeof(struct ti_mc_entry), M_DEVBUF, M_NOWAIT); 109945386Swpaul bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 110045386Swpaul (char *)&mc->mc_addr, ETHER_ADDR_LEN); 110145386Swpaul SLIST_INSERT_HEAD(&sc->ti_mc_listhead, mc, mc_entries); 110245386Swpaul ti_add_mcast(sc, &mc->mc_addr); 110345386Swpaul } 110445386Swpaul 110545386Swpaul /* Re-enable interrupts. */ 110645386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, intrs); 110745386Swpaul 110845386Swpaul return; 110945386Swpaul} 111045386Swpaul 111145386Swpaul/* 111245386Swpaul * Check to see if the BIOS has configured us for a 64 bit slot when 111345386Swpaul * we aren't actually in one. If we detect this condition, we can work 111445386Swpaul * around it on the Tigon 2 by setting a bit in the PCI state register, 111545386Swpaul * but for the Tigon 1 we must give up and abort the interface attach. 111645386Swpaul */ 111745386Swpaulstatic int ti_64bitslot_war(sc) 111845386Swpaul struct ti_softc *sc; 111945386Swpaul{ 112045386Swpaul if (!(CSR_READ_4(sc, TI_PCI_STATE) & TI_PCISTATE_32BIT_BUS)) { 112145386Swpaul CSR_WRITE_4(sc, 0x600, 0); 112245386Swpaul CSR_WRITE_4(sc, 0x604, 0); 112345386Swpaul CSR_WRITE_4(sc, 0x600, 0x5555AAAA); 112445386Swpaul if (CSR_READ_4(sc, 0x604) == 0x5555AAAA) { 112545386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 112645386Swpaul return(EINVAL); 112745386Swpaul else { 112845386Swpaul TI_SETBIT(sc, TI_PCI_STATE, 112945386Swpaul TI_PCISTATE_32BIT_BUS); 113045386Swpaul return(0); 113145386Swpaul } 113245386Swpaul } 113345386Swpaul } 113445386Swpaul 113545386Swpaul return(0); 113645386Swpaul} 113745386Swpaul 113845386Swpaul/* 113945386Swpaul * Do endian, PCI and DMA initialization. Also check the on-board ROM 114045386Swpaul * self-test results. 114145386Swpaul */ 114245386Swpaulstatic int ti_chipinit(sc) 114345386Swpaul struct ti_softc *sc; 114445386Swpaul{ 114545386Swpaul u_int32_t cacheline; 114645386Swpaul u_int32_t pci_writemax = 0; 114745386Swpaul 114845386Swpaul /* Initialize link to down state. */ 114945386Swpaul sc->ti_linkstat = TI_EV_CODE_LINK_DOWN; 115045386Swpaul 115158698Sjlemon sc->arpcom.ac_if.if_hwassist = TI_CSUM_FEATURES; 115258698Sjlemon 115345386Swpaul /* Set endianness before we access any non-PCI registers. */ 115445386Swpaul#if BYTE_ORDER == BIG_ENDIAN 115545386Swpaul CSR_WRITE_4(sc, TI_MISC_HOST_CTL, 115645386Swpaul TI_MHC_BIGENDIAN_INIT | (TI_MHC_BIGENDIAN_INIT << 24)); 115745386Swpaul#else 115845386Swpaul CSR_WRITE_4(sc, TI_MISC_HOST_CTL, 115945386Swpaul TI_MHC_LITTLEENDIAN_INIT | (TI_MHC_LITTLEENDIAN_INIT << 24)); 116045386Swpaul#endif 116145386Swpaul 116245386Swpaul /* Check the ROM failed bit to see if self-tests passed. */ 116345386Swpaul if (CSR_READ_4(sc, TI_CPU_STATE) & TI_CPUSTATE_ROMFAIL) { 116445386Swpaul printf("ti%d: board self-diagnostics failed!\n", sc->ti_unit); 116545386Swpaul return(ENODEV); 116645386Swpaul } 116745386Swpaul 116845386Swpaul /* Halt the CPU. */ 116945386Swpaul TI_SETBIT(sc, TI_CPU_STATE, TI_CPUSTATE_HALT); 117045386Swpaul 117145386Swpaul /* Figure out the hardware revision. */ 117245386Swpaul switch(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_CHIP_REV_MASK) { 117345386Swpaul case TI_REV_TIGON_I: 117445386Swpaul sc->ti_hwrev = TI_HWREV_TIGON; 117545386Swpaul break; 117645386Swpaul case TI_REV_TIGON_II: 117745386Swpaul sc->ti_hwrev = TI_HWREV_TIGON_II; 117845386Swpaul break; 117945386Swpaul default: 118045386Swpaul printf("ti%d: unsupported chip revision\n", sc->ti_unit); 118145386Swpaul return(ENODEV); 118245386Swpaul } 118345386Swpaul 118445386Swpaul /* Do special setup for Tigon 2. */ 118545386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON_II) { 118645386Swpaul TI_SETBIT(sc, TI_CPU_CTL_B, TI_CPUSTATE_HALT); 118745386Swpaul TI_SETBIT(sc, TI_MISC_LOCAL_CTL, TI_MLC_SRAM_BANK_256K); 118845386Swpaul TI_SETBIT(sc, TI_MISC_CONF, TI_MCR_SRAM_SYNCHRONOUS); 118945386Swpaul } 119045386Swpaul 119145386Swpaul /* Set up the PCI state register. */ 119245386Swpaul CSR_WRITE_4(sc, TI_PCI_STATE, TI_PCI_READ_CMD|TI_PCI_WRITE_CMD); 119345386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON_II) { 119445386Swpaul TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_USE_MEM_RD_MULT); 119545386Swpaul } 119645386Swpaul 119745386Swpaul /* Clear the read/write max DMA parameters. */ 119845386Swpaul TI_CLRBIT(sc, TI_PCI_STATE, (TI_PCISTATE_WRITE_MAXDMA| 119945386Swpaul TI_PCISTATE_READ_MAXDMA)); 120045386Swpaul 120145386Swpaul /* Get cache line size. */ 120245386Swpaul cacheline = CSR_READ_4(sc, TI_PCI_BIST) & 0xFF; 120345386Swpaul 120445386Swpaul /* 120545386Swpaul * If the system has set enabled the PCI memory write 120645386Swpaul * and invalidate command in the command register, set 120745386Swpaul * the write max parameter accordingly. This is necessary 120845386Swpaul * to use MWI with the Tigon 2. 120945386Swpaul */ 121045386Swpaul if (CSR_READ_4(sc, TI_PCI_CMDSTAT) & PCIM_CMD_MWIEN) { 121145386Swpaul switch(cacheline) { 121245386Swpaul case 1: 121345386Swpaul case 4: 121445386Swpaul case 8: 121545386Swpaul case 16: 121645386Swpaul case 32: 121745386Swpaul case 64: 121845386Swpaul break; 121945386Swpaul default: 122045386Swpaul /* Disable PCI memory write and invalidate. */ 122145386Swpaul if (bootverbose) 122245386Swpaul printf("ti%d: cache line size %d not " 122345386Swpaul "supported; disabling PCI MWI\n", 122445386Swpaul sc->ti_unit, cacheline); 122545386Swpaul CSR_WRITE_4(sc, TI_PCI_CMDSTAT, CSR_READ_4(sc, 122645386Swpaul TI_PCI_CMDSTAT) & ~PCIM_CMD_MWIEN); 122745386Swpaul break; 122845386Swpaul } 122945386Swpaul } 123045386Swpaul 123145386Swpaul#ifdef __brokenalpha__ 123245386Swpaul /* 123345386Swpaul * From the Alteon sample driver: 123445386Swpaul * Must insure that we do not cross an 8K (bytes) boundary 123545386Swpaul * for DMA reads. Our highest limit is 1K bytes. This is a 123645386Swpaul * restriction on some ALPHA platforms with early revision 123745386Swpaul * 21174 PCI chipsets, such as the AlphaPC 164lx 123845386Swpaul */ 123945386Swpaul TI_SETBIT(sc, TI_PCI_STATE, pci_writemax|TI_PCI_READMAX_1024); 124045386Swpaul#else 124145386Swpaul TI_SETBIT(sc, TI_PCI_STATE, pci_writemax); 124245386Swpaul#endif 124345386Swpaul 124445386Swpaul /* This sets the min dma param all the way up (0xff). */ 124545386Swpaul TI_SETBIT(sc, TI_PCI_STATE, TI_PCISTATE_MINDMA); 124645386Swpaul 124745386Swpaul /* Configure DMA variables. */ 124845386Swpaul#if BYTE_ORDER == BIG_ENDIAN 124945386Swpaul CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_BD | 125045386Swpaul TI_OPMODE_BYTESWAP_DATA | TI_OPMODE_WORDSWAP_BD | 125145386Swpaul TI_OPMODE_WARN_ENB | TI_OPMODE_FATAL_ENB | 125245386Swpaul TI_OPMODE_DONT_FRAG_JUMBO); 125345386Swpaul#else 125445386Swpaul CSR_WRITE_4(sc, TI_GCR_OPMODE, TI_OPMODE_BYTESWAP_DATA| 125545386Swpaul TI_OPMODE_WORDSWAP_BD|TI_OPMODE_DONT_FRAG_JUMBO| 125645386Swpaul TI_OPMODE_WARN_ENB|TI_OPMODE_FATAL_ENB); 125745386Swpaul#endif 125845386Swpaul 125945386Swpaul /* 126045386Swpaul * Only allow 1 DMA channel to be active at a time. 126145386Swpaul * I don't think this is a good idea, but without it 126245386Swpaul * the firmware racks up lots of nicDmaReadRingFull 126358698Sjlemon * errors. This is not compatible with hardware checksums. 126445386Swpaul */ 126558698Sjlemon if (sc->arpcom.ac_if.if_hwassist == 0) 126658698Sjlemon TI_SETBIT(sc, TI_GCR_OPMODE, TI_OPMODE_1_DMA_ACTIVE); 126745386Swpaul 126845386Swpaul /* Recommended settings from Tigon manual. */ 126945386Swpaul CSR_WRITE_4(sc, TI_GCR_DMA_WRITECFG, TI_DMA_STATE_THRESH_8W); 127045386Swpaul CSR_WRITE_4(sc, TI_GCR_DMA_READCFG, TI_DMA_STATE_THRESH_8W); 127145386Swpaul 127245386Swpaul if (ti_64bitslot_war(sc)) { 127345386Swpaul printf("ti%d: bios thinks we're in a 64 bit slot, " 127445386Swpaul "but we aren't", sc->ti_unit); 127545386Swpaul return(EINVAL); 127645386Swpaul } 127745386Swpaul 127845386Swpaul return(0); 127945386Swpaul} 128045386Swpaul 128145386Swpaul/* 128245386Swpaul * Initialize the general information block and firmware, and 128345386Swpaul * start the CPU(s) running. 128445386Swpaul */ 128545386Swpaulstatic int ti_gibinit(sc) 128645386Swpaul struct ti_softc *sc; 128745386Swpaul{ 128845386Swpaul struct ti_rcb *rcb; 128945386Swpaul int i; 129045386Swpaul struct ifnet *ifp; 129145386Swpaul 129245386Swpaul ifp = &sc->arpcom.ac_if; 129345386Swpaul 129445386Swpaul /* Disable interrupts for now. */ 129545386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1); 129645386Swpaul 129745386Swpaul /* Tell the chip where to find the general information block. */ 129845386Swpaul CSR_WRITE_4(sc, TI_GCR_GENINFO_HI, 0); 129945386Swpaul CSR_WRITE_4(sc, TI_GCR_GENINFO_LO, vtophys(&sc->ti_rdata->ti_info)); 130045386Swpaul 130145386Swpaul /* Load the firmware into SRAM. */ 130245386Swpaul ti_loadfw(sc); 130345386Swpaul 130445386Swpaul /* Set up the contents of the general info and ring control blocks. */ 130545386Swpaul 130645386Swpaul /* Set up the event ring and producer pointer. */ 130745386Swpaul rcb = &sc->ti_rdata->ti_info.ti_ev_rcb; 130845386Swpaul 130945386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = vtophys(&sc->ti_rdata->ti_event_ring); 131045386Swpaul rcb->ti_flags = 0; 131145386Swpaul TI_HOSTADDR(sc->ti_rdata->ti_info.ti_ev_prodidx_ptr) = 131245386Swpaul vtophys(&sc->ti_ev_prodidx); 131345386Swpaul sc->ti_ev_prodidx.ti_idx = 0; 131445386Swpaul CSR_WRITE_4(sc, TI_GCR_EVENTCONS_IDX, 0); 131545386Swpaul sc->ti_ev_saved_considx = 0; 131645386Swpaul 131745386Swpaul /* Set up the command ring and producer mailbox. */ 131845386Swpaul rcb = &sc->ti_rdata->ti_info.ti_cmd_rcb; 131945386Swpaul 132045386Swpaul sc->ti_rdata->ti_cmd_ring = 132149133Swpaul (struct ti_cmd_desc *)(sc->ti_vhandle + TI_GCR_CMDRING); 132245386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = TI_GCR_NIC_ADDR(TI_GCR_CMDRING); 132345386Swpaul rcb->ti_flags = 0; 132445386Swpaul rcb->ti_max_len = 0; 132545386Swpaul for (i = 0; i < TI_CMD_RING_CNT; i++) { 132645386Swpaul CSR_WRITE_4(sc, TI_GCR_CMDRING + (i * 4), 0); 132745386Swpaul } 132845386Swpaul CSR_WRITE_4(sc, TI_GCR_CMDCONS_IDX, 0); 132945386Swpaul CSR_WRITE_4(sc, TI_MB_CMDPROD_IDX, 0); 133045386Swpaul sc->ti_cmd_saved_prodidx = 0; 133145386Swpaul 133245386Swpaul /* 133345386Swpaul * Assign the address of the stats refresh buffer. 133445386Swpaul * We re-use the current stats buffer for this to 133545386Swpaul * conserve memory. 133645386Swpaul */ 133745386Swpaul TI_HOSTADDR(sc->ti_rdata->ti_info.ti_refresh_stats_ptr) = 133845386Swpaul vtophys(&sc->ti_rdata->ti_info.ti_stats); 133945386Swpaul 134045386Swpaul /* Set up the standard receive ring. */ 134145386Swpaul rcb = &sc->ti_rdata->ti_info.ti_std_rx_rcb; 134245386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = vtophys(&sc->ti_rdata->ti_rx_std_ring); 134345386Swpaul rcb->ti_max_len = TI_FRAMELEN; 134445386Swpaul rcb->ti_flags = 0; 134558698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 134658698Sjlemon rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM | 134758698Sjlemon TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM; 134845386Swpaul#if NVLAN > 0 134945386Swpaul rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST; 135045386Swpaul#endif 135145386Swpaul 135245386Swpaul /* Set up the jumbo receive ring. */ 135345386Swpaul rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb; 135445386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = 135545386Swpaul vtophys(&sc->ti_rdata->ti_rx_jumbo_ring); 135649036Swpaul rcb->ti_max_len = TI_JUMBO_FRAMELEN; 135745386Swpaul rcb->ti_flags = 0; 135858698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 135958698Sjlemon rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM | 136058698Sjlemon TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM; 136145386Swpaul#if NVLAN > 0 136245386Swpaul rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST; 136345386Swpaul#endif 136445386Swpaul 136545386Swpaul /* 136645386Swpaul * Set up the mini ring. Only activated on the 136745386Swpaul * Tigon 2 but the slot in the config block is 136845386Swpaul * still there on the Tigon 1. 136945386Swpaul */ 137045386Swpaul rcb = &sc->ti_rdata->ti_info.ti_mini_rx_rcb; 137145386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = 137245386Swpaul vtophys(&sc->ti_rdata->ti_rx_mini_ring); 137351352Swpaul rcb->ti_max_len = MHLEN - ETHER_ALIGN; 137445386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 137545386Swpaul rcb->ti_flags = TI_RCB_FLAG_RING_DISABLED; 137645386Swpaul else 137745386Swpaul rcb->ti_flags = 0; 137858698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 137958698Sjlemon rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM | 138058698Sjlemon TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM; 138145386Swpaul#if NVLAN > 0 138245386Swpaul rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST; 138345386Swpaul#endif 138445386Swpaul 138545386Swpaul /* 138645386Swpaul * Set up the receive return ring. 138745386Swpaul */ 138845386Swpaul rcb = &sc->ti_rdata->ti_info.ti_return_rcb; 138945386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = 139045386Swpaul vtophys(&sc->ti_rdata->ti_rx_return_ring); 139145386Swpaul rcb->ti_flags = 0; 139245386Swpaul rcb->ti_max_len = TI_RETURN_RING_CNT; 139345386Swpaul TI_HOSTADDR(sc->ti_rdata->ti_info.ti_return_prodidx_ptr) = 139445386Swpaul vtophys(&sc->ti_return_prodidx); 139545386Swpaul 139645386Swpaul /* 139745386Swpaul * Set up the tx ring. Note: for the Tigon 2, we have the option 139845386Swpaul * of putting the transmit ring in the host's address space and 139945386Swpaul * letting the chip DMA it instead of leaving the ring in the NIC's 140045386Swpaul * memory and accessing it through the shared memory region. We 140145386Swpaul * do this for the Tigon 2, but it doesn't work on the Tigon 1, 140245386Swpaul * so we have to revert to the shared memory scheme if we detect 140345386Swpaul * a Tigon 1 chip. 140445386Swpaul */ 140545386Swpaul CSR_WRITE_4(sc, TI_WINBASE, TI_TX_RING_BASE); 140645386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) { 140745386Swpaul sc->ti_rdata->ti_tx_ring_nic = 140849133Swpaul (struct ti_tx_desc *)(sc->ti_vhandle + TI_WINDOW); 140945386Swpaul } 141045386Swpaul bzero((char *)sc->ti_rdata->ti_tx_ring, 141145386Swpaul TI_TX_RING_CNT * sizeof(struct ti_tx_desc)); 141245386Swpaul rcb = &sc->ti_rdata->ti_info.ti_tx_rcb; 141345386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 141445386Swpaul rcb->ti_flags = 0; 141545386Swpaul else 141645386Swpaul rcb->ti_flags = TI_RCB_FLAG_HOST_RING; 141745386Swpaul#if NVLAN > 0 141845386Swpaul rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST; 141945386Swpaul#endif 142058698Sjlemon if (sc->arpcom.ac_if.if_hwassist) 142158698Sjlemon rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM | 142258698Sjlemon TI_RCB_FLAG_IP_CKSUM | TI_RCB_FLAG_NO_PHDR_CKSUM; 142345386Swpaul rcb->ti_max_len = TI_TX_RING_CNT; 142445386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 142545386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE; 142645386Swpaul else 142745386Swpaul TI_HOSTADDR(rcb->ti_hostaddr) = 142845386Swpaul vtophys(&sc->ti_rdata->ti_tx_ring); 142945386Swpaul TI_HOSTADDR(sc->ti_rdata->ti_info.ti_tx_considx_ptr) = 143045386Swpaul vtophys(&sc->ti_tx_considx); 143145386Swpaul 143245386Swpaul /* Set up tuneables */ 143345386Swpaul if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) 143445386Swpaul CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS, 143545386Swpaul (sc->ti_rx_coal_ticks / 10)); 143645386Swpaul else 143745386Swpaul CSR_WRITE_4(sc, TI_GCR_RX_COAL_TICKS, sc->ti_rx_coal_ticks); 143845386Swpaul CSR_WRITE_4(sc, TI_GCR_TX_COAL_TICKS, sc->ti_tx_coal_ticks); 143945386Swpaul CSR_WRITE_4(sc, TI_GCR_STAT_TICKS, sc->ti_stat_ticks); 144045386Swpaul CSR_WRITE_4(sc, TI_GCR_RX_MAX_COAL_BD, sc->ti_rx_max_coal_bds); 144145386Swpaul CSR_WRITE_4(sc, TI_GCR_TX_MAX_COAL_BD, sc->ti_tx_max_coal_bds); 144245386Swpaul CSR_WRITE_4(sc, TI_GCR_TX_BUFFER_RATIO, sc->ti_tx_buf_ratio); 144345386Swpaul 144445386Swpaul /* Turn interrupts on. */ 144545386Swpaul CSR_WRITE_4(sc, TI_GCR_MASK_INTRS, 0); 144645386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0); 144745386Swpaul 144845386Swpaul /* Start CPU. */ 144945386Swpaul TI_CLRBIT(sc, TI_CPU_STATE, (TI_CPUSTATE_HALT|TI_CPUSTATE_STEP)); 145045386Swpaul 145145386Swpaul return(0); 145245386Swpaul} 145345386Swpaul 145445386Swpaul/* 145545386Swpaul * Probe for a Tigon chip. Check the PCI vendor and device IDs 145645386Swpaul * against our list and return its name if we find a match. 145745386Swpaul */ 145849011Swpaulstatic int ti_probe(dev) 145949011Swpaul device_t dev; 146045386Swpaul{ 146145386Swpaul struct ti_type *t; 146245386Swpaul 146345386Swpaul t = ti_devs; 146445386Swpaul 146545386Swpaul while(t->ti_name != NULL) { 146649011Swpaul if ((pci_get_vendor(dev) == t->ti_vid) && 146749011Swpaul (pci_get_device(dev) == t->ti_did)) { 146849011Swpaul device_set_desc(dev, t->ti_name); 146949011Swpaul return(0); 147049011Swpaul } 147145386Swpaul t++; 147245386Swpaul } 147345386Swpaul 147449011Swpaul return(ENXIO); 147545386Swpaul} 147645386Swpaul 147749011Swpaulstatic int ti_attach(dev) 147849011Swpaul device_t dev; 147945386Swpaul{ 148045386Swpaul int s; 148145386Swpaul u_int32_t command; 148245386Swpaul struct ifnet *ifp; 148345386Swpaul struct ti_softc *sc; 148449011Swpaul int unit, error = 0, rid; 148545386Swpaul 148645386Swpaul s = splimp(); 148745386Swpaul 148849011Swpaul sc = device_get_softc(dev); 148949011Swpaul unit = device_get_unit(dev); 149045386Swpaul bzero(sc, sizeof(struct ti_softc)); 149145386Swpaul 149245386Swpaul /* 149345386Swpaul * Map control/status registers. 149445386Swpaul */ 149561041Speter command = pci_read_config(dev, PCIR_COMMAND, 4); 149645386Swpaul command |= (PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN); 149761041Speter pci_write_config(dev, PCIR_COMMAND, command, 4); 149861041Speter command = pci_read_config(dev, PCIR_COMMAND, 4); 149945386Swpaul 150045386Swpaul if (!(command & PCIM_CMD_MEMEN)) { 150145386Swpaul printf("ti%d: failed to enable memory mapping!\n", unit); 150249011Swpaul error = ENXIO; 150345386Swpaul goto fail; 150445386Swpaul } 150545386Swpaul 150649011Swpaul rid = TI_PCI_LOMEM; 150749011Swpaul sc->ti_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 150849011Swpaul 0, ~0, 1, RF_ACTIVE); 150949011Swpaul 151049011Swpaul if (sc->ti_res == NULL) { 151145386Swpaul printf ("ti%d: couldn't map memory\n", unit); 151249011Swpaul error = ENXIO; 151345386Swpaul goto fail; 151445386Swpaul } 151545386Swpaul 151649035Swpaul sc->ti_btag = rman_get_bustag(sc->ti_res); 151749035Swpaul sc->ti_bhandle = rman_get_bushandle(sc->ti_res); 151849133Swpaul sc->ti_vhandle = (vm_offset_t)rman_get_virtual(sc->ti_res); 151949035Swpaul 152049133Swpaul /* 152149133Swpaul * XXX FIXME: rman_get_virtual() on the alpha is currently 152249133Swpaul * broken and returns a physical address instead of a kernel 152349133Swpaul * virtual address. Consequently, we need to do a little 152449133Swpaul * extra mangling of the vhandle on the alpha. This should 152549133Swpaul * eventually be fixed! The whole idea here is to get rid 152649133Swpaul * of platform dependencies. 152749133Swpaul */ 152849133Swpaul#ifdef __alpha__ 152949133Swpaul if (pci_cvt_to_bwx(sc->ti_vhandle)) 153049133Swpaul sc->ti_vhandle = pci_cvt_to_bwx(sc->ti_vhandle); 153149133Swpaul else 153249133Swpaul sc->ti_vhandle = pci_cvt_to_dense(sc->ti_vhandle); 153349133Swpaul sc->ti_vhandle = ALPHA_PHYS_TO_K0SEG(sc->ti_vhandle); 153449133Swpaul#endif 153549133Swpaul 153649011Swpaul /* Allocate interrupt */ 153749011Swpaul rid = 0; 153849133Swpaul 153949011Swpaul sc->ti_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, 154049011Swpaul RF_SHAREABLE | RF_ACTIVE); 154145386Swpaul 154249011Swpaul if (sc->ti_irq == NULL) { 154349011Swpaul printf("ti%d: couldn't map interrupt\n", unit); 154449011Swpaul error = ENXIO; 154545386Swpaul goto fail; 154645386Swpaul } 154745386Swpaul 154849011Swpaul error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET, 154949011Swpaul ti_intr, sc, &sc->ti_intrhand); 155049011Swpaul 155149011Swpaul if (error) { 155249011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 155349011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 155449011Swpaul TI_PCI_LOMEM, sc->ti_res); 155549011Swpaul printf("ti%d: couldn't set up irq\n", unit); 155645386Swpaul goto fail; 155745386Swpaul } 155845386Swpaul 155945386Swpaul sc->ti_unit = unit; 156045386Swpaul 156145386Swpaul if (ti_chipinit(sc)) { 156245386Swpaul printf("ti%d: chip initialization failed\n", sc->ti_unit); 156349011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 156449011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 156549011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 156649011Swpaul TI_PCI_LOMEM, sc->ti_res); 156749011Swpaul error = ENXIO; 156845386Swpaul goto fail; 156945386Swpaul } 157045386Swpaul 157145386Swpaul /* Zero out the NIC's on-board SRAM. */ 157245386Swpaul ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL); 157345386Swpaul 157445386Swpaul /* Init again -- zeroing memory may have clobbered some registers. */ 157545386Swpaul if (ti_chipinit(sc)) { 157645386Swpaul printf("ti%d: chip initialization failed\n", sc->ti_unit); 157749011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 157849011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 157949011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 158049011Swpaul TI_PCI_LOMEM, sc->ti_res); 158149011Swpaul error = ENXIO; 158245386Swpaul goto fail; 158345386Swpaul } 158445386Swpaul 158545386Swpaul /* 158645386Swpaul * Get station address from the EEPROM. Note: the manual states 158745386Swpaul * that the MAC address is at offset 0x8c, however the data is 158845386Swpaul * stored as two longwords (since that's how it's loaded into 158945386Swpaul * the NIC). This means the MAC address is actually preceeded 159045386Swpaul * by two zero bytes. We need to skip over those. 159145386Swpaul */ 159245386Swpaul if (ti_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr, 159345386Swpaul TI_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) { 159445386Swpaul printf("ti%d: failed to read station address\n", unit); 159549011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 159649011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 159749011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 159849011Swpaul TI_PCI_LOMEM, sc->ti_res); 159949011Swpaul error = ENXIO; 160045386Swpaul goto fail; 160145386Swpaul } 160245386Swpaul 160345386Swpaul /* 160445386Swpaul * A Tigon chip was detected. Inform the world. 160545386Swpaul */ 160645386Swpaul printf("ti%d: Ethernet address: %6D\n", unit, 160745386Swpaul sc->arpcom.ac_enaddr, ":"); 160845386Swpaul 160945386Swpaul /* Allocate the general information block and ring buffers. */ 161049011Swpaul sc->ti_rdata = contigmalloc(sizeof(struct ti_ring_data), M_DEVBUF, 161150548Sbde M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0); 161245386Swpaul 161349011Swpaul if (sc->ti_rdata == NULL) { 161449011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 161549011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 161649011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 161749011Swpaul TI_PCI_LOMEM, sc->ti_res); 161849011Swpaul error = ENXIO; 161945386Swpaul printf("ti%d: no memory for list buffers!\n", sc->ti_unit); 162045386Swpaul goto fail; 162145386Swpaul } 162245386Swpaul 162345386Swpaul bzero(sc->ti_rdata, sizeof(struct ti_ring_data)); 162445386Swpaul 162545386Swpaul /* Try to allocate memory for jumbo buffers. */ 162645386Swpaul if (ti_alloc_jumbo_mem(sc)) { 162745386Swpaul printf("ti%d: jumbo buffer allocation failed\n", sc->ti_unit); 162849011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 162949011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 163049011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, 163149011Swpaul TI_PCI_LOMEM, sc->ti_res); 163262793Sgallatin contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), 163362793Sgallatin M_DEVBUF); 163449011Swpaul error = ENXIO; 163545386Swpaul goto fail; 163645386Swpaul } 163745386Swpaul 163863699Swpaul /* 163963699Swpaul * We really need a better way to tell a 1000baseTX card 164063699Swpaul * from a 1000baseSX one, since in theory there could be 164163699Swpaul * OEMed 1000baseTX cards from lame vendors who aren't 164263699Swpaul * clever enough to change the PCI ID. For the moment 164363699Swpaul * though, the AceNIC is the only copper card available. 164463699Swpaul */ 164563699Swpaul if (pci_get_vendor(dev) == ALT_VENDORID && 164663699Swpaul pci_get_device(dev) == ALT_DEVICEID_ACENIC_COPPER) 164763699Swpaul sc->ti_copper = 1; 164864139Swpaul /* Ok, it's not the only copper card available. */ 164964139Swpaul if (pci_get_vendor(dev) == NG_VENDORID && 165064139Swpaul pci_get_device(dev) == NG_DEVICEID_GA620T) 165164139Swpaul sc->ti_copper = 1; 165263699Swpaul 165345386Swpaul /* Set default tuneable values. */ 165445386Swpaul sc->ti_stat_ticks = 2 * TI_TICKS_PER_SEC; 165545386Swpaul sc->ti_rx_coal_ticks = TI_TICKS_PER_SEC / 5000; 165645386Swpaul sc->ti_tx_coal_ticks = TI_TICKS_PER_SEC / 500; 165745386Swpaul sc->ti_rx_max_coal_bds = 64; 165845386Swpaul sc->ti_tx_max_coal_bds = 128; 165945386Swpaul sc->ti_tx_buf_ratio = 21; 166045386Swpaul 166145386Swpaul /* Set up ifnet structure */ 166245386Swpaul ifp = &sc->arpcom.ac_if; 166345386Swpaul ifp->if_softc = sc; 166445386Swpaul ifp->if_unit = sc->ti_unit; 166545386Swpaul ifp->if_name = "ti"; 166645386Swpaul ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 166745386Swpaul ifp->if_ioctl = ti_ioctl; 166845386Swpaul ifp->if_output = ether_output; 166945386Swpaul ifp->if_start = ti_start; 167045386Swpaul ifp->if_watchdog = ti_watchdog; 167145386Swpaul ifp->if_init = ti_init; 167245386Swpaul ifp->if_mtu = ETHERMTU; 167345386Swpaul ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1; 167445386Swpaul 167545386Swpaul /* Set up ifmedia support. */ 167645386Swpaul ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts); 167763699Swpaul if (sc->ti_copper) { 167863699Swpaul /* 167963699Swpaul * Copper cards allow manual 10/100 mode selection, 168063699Swpaul * but not manual 1000baseTX mode selection. Why? 168163699Swpaul * Becuase currently there's no way to specify the 168263699Swpaul * master/slave setting through the firmware interface, 168363699Swpaul * so Alteon decided to just bag it and handle it 168463699Swpaul * via autonegotiation. 168563699Swpaul */ 168663699Swpaul ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL); 168763699Swpaul ifmedia_add(&sc->ifmedia, 168863699Swpaul IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL); 168963699Swpaul ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL); 169063699Swpaul ifmedia_add(&sc->ifmedia, 169163699Swpaul IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); 169263699Swpaul ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_TX, 0, NULL); 169363699Swpaul ifmedia_add(&sc->ifmedia, 169463699Swpaul IFM_ETHER|IFM_1000_TX|IFM_FDX, 0, NULL); 169563699Swpaul } else { 169663699Swpaul /* Fiber cards don't support 10/100 modes. */ 169763699Swpaul ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL); 169863699Swpaul ifmedia_add(&sc->ifmedia, 169963699Swpaul IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL); 170063699Swpaul } 170145386Swpaul ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL); 170245386Swpaul ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO); 170345386Swpaul 170445386Swpaul /* 170563090Sarchie * Call MI attach routine. 170645386Swpaul */ 170763090Sarchie ether_ifattach(ifp, ETHER_BPF_SUPPORTED); 170845386Swpaul 170945386Swpaulfail: 171045386Swpaul splx(s); 171145386Swpaul 171249011Swpaul return(error); 171345386Swpaul} 171445386Swpaul 171549011Swpaulstatic int ti_detach(dev) 171649011Swpaul device_t dev; 171749011Swpaul{ 171849011Swpaul struct ti_softc *sc; 171949011Swpaul struct ifnet *ifp; 172049011Swpaul int s; 172149011Swpaul 172249011Swpaul s = splimp(); 172349011Swpaul 172449011Swpaul sc = device_get_softc(dev); 172549011Swpaul ifp = &sc->arpcom.ac_if; 172649011Swpaul 172763090Sarchie ether_ifdetach(ifp, ETHER_BPF_SUPPORTED); 172849011Swpaul ti_stop(sc); 172949011Swpaul 173049011Swpaul bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); 173149011Swpaul bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq); 173249011Swpaul bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM, sc->ti_res); 173349011Swpaul 173462793Sgallatin contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF); 173562793Sgallatin contigfree(sc->ti_rdata, sizeof(struct ti_ring_data), M_DEVBUF); 173649011Swpaul ifmedia_removeall(&sc->ifmedia); 173749011Swpaul 173849011Swpaul splx(s); 173949011Swpaul 174049011Swpaul return(0); 174149011Swpaul} 174249011Swpaul 174345386Swpaul/* 174445386Swpaul * Frame reception handling. This is called if there's a frame 174545386Swpaul * on the receive return list. 174645386Swpaul * 174745386Swpaul * Note: we have to be able to handle three possibilities here: 174845386Swpaul * 1) the frame is from the mini receive ring (can only happen) 174945386Swpaul * on Tigon 2 boards) 175045386Swpaul * 2) the frame is from the jumbo recieve ring 175145386Swpaul * 3) the frame is from the standard receive ring 175245386Swpaul */ 175345386Swpaul 175445386Swpaulstatic void ti_rxeof(sc) 175545386Swpaul struct ti_softc *sc; 175645386Swpaul{ 175745386Swpaul struct ifnet *ifp; 175848597Swpaul struct ti_cmd_desc cmd; 175945386Swpaul 176045386Swpaul ifp = &sc->arpcom.ac_if; 176145386Swpaul 176245386Swpaul while(sc->ti_rx_saved_considx != sc->ti_return_prodidx.ti_idx) { 176345386Swpaul struct ti_rx_desc *cur_rx; 176445386Swpaul u_int32_t rxidx; 176545386Swpaul struct ether_header *eh; 176645386Swpaul struct mbuf *m = NULL; 176745386Swpaul#if NVLAN > 0 176845386Swpaul u_int16_t vlan_tag = 0; 176945386Swpaul int have_tag = 0; 177045386Swpaul#endif 177145386Swpaul 177245386Swpaul cur_rx = 177345386Swpaul &sc->ti_rdata->ti_rx_return_ring[sc->ti_rx_saved_considx]; 177445386Swpaul rxidx = cur_rx->ti_idx; 177545386Swpaul TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT); 177645386Swpaul 177745386Swpaul#if NVLAN > 0 177845386Swpaul if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) { 177945386Swpaul have_tag = 1; 178045386Swpaul vlan_tag = cur_rx->ti_vlan_tag; 178145386Swpaul } 178245386Swpaul#endif 178345386Swpaul 178445386Swpaul if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) { 178545386Swpaul TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT); 178645386Swpaul m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx]; 178745386Swpaul sc->ti_cdata.ti_rx_jumbo_chain[rxidx] = NULL; 178845386Swpaul if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { 178945386Swpaul ifp->if_ierrors++; 179045386Swpaul ti_newbuf_jumbo(sc, sc->ti_jumbo, m); 179145386Swpaul continue; 179245386Swpaul } 179348597Swpaul if (ti_newbuf_jumbo(sc, sc->ti_jumbo, NULL) == ENOBUFS) { 179448597Swpaul ifp->if_ierrors++; 179548597Swpaul ti_newbuf_jumbo(sc, sc->ti_jumbo, m); 179648597Swpaul continue; 179748597Swpaul } 179845386Swpaul } else if (cur_rx->ti_flags & TI_BDFLAG_MINI_RING) { 179945386Swpaul TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT); 180045386Swpaul m = sc->ti_cdata.ti_rx_mini_chain[rxidx]; 180145386Swpaul sc->ti_cdata.ti_rx_mini_chain[rxidx] = NULL; 180245386Swpaul if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { 180345386Swpaul ifp->if_ierrors++; 180445386Swpaul ti_newbuf_mini(sc, sc->ti_mini, m); 180545386Swpaul continue; 180645386Swpaul } 180748597Swpaul if (ti_newbuf_mini(sc, sc->ti_mini, NULL) == ENOBUFS) { 180848597Swpaul ifp->if_ierrors++; 180948597Swpaul ti_newbuf_mini(sc, sc->ti_mini, m); 181048597Swpaul continue; 181148597Swpaul } 181245386Swpaul } else { 181345386Swpaul TI_INC(sc->ti_std, TI_STD_RX_RING_CNT); 181445386Swpaul m = sc->ti_cdata.ti_rx_std_chain[rxidx]; 181545386Swpaul sc->ti_cdata.ti_rx_std_chain[rxidx] = NULL; 181645386Swpaul if (cur_rx->ti_flags & TI_BDFLAG_ERROR) { 181745386Swpaul ifp->if_ierrors++; 181845386Swpaul ti_newbuf_std(sc, sc->ti_std, m); 181945386Swpaul continue; 182045386Swpaul } 182148597Swpaul if (ti_newbuf_std(sc, sc->ti_std, NULL) == ENOBUFS) { 182248597Swpaul ifp->if_ierrors++; 182348597Swpaul ti_newbuf_std(sc, sc->ti_std, m); 182448597Swpaul continue; 182548597Swpaul } 182645386Swpaul } 182745386Swpaul 182845386Swpaul m->m_pkthdr.len = m->m_len = cur_rx->ti_len; 182945386Swpaul ifp->if_ipackets++; 183045386Swpaul eh = mtod(m, struct ether_header *); 183145386Swpaul m->m_pkthdr.rcvif = ifp; 183245386Swpaul 183345386Swpaul /* Remove header from mbuf and pass it on. */ 183445386Swpaul m_adj(m, sizeof(struct ether_header)); 183545386Swpaul 183658698Sjlemon if (ifp->if_hwassist) { 183758698Sjlemon m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED | 183858698Sjlemon CSUM_DATA_VALID; 183958698Sjlemon if ((cur_rx->ti_ip_cksum ^ 0xffff) == 0) 184058698Sjlemon m->m_pkthdr.csum_flags |= CSUM_IP_VALID; 184158698Sjlemon m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum; 184258698Sjlemon } 184345386Swpaul 184445386Swpaul#if NVLAN > 0 184545386Swpaul /* 184645386Swpaul * If we received a packet with a vlan tag, pass it 184745386Swpaul * to vlan_input() instead of ether_input(). 184845386Swpaul */ 184945386Swpaul if (have_tag) { 185045386Swpaul vlan_input_tag(eh, m, vlan_tag); 185145386Swpaul have_tag = vlan_tag = 0; 185245386Swpaul continue; 185345386Swpaul } 185445386Swpaul#endif 185545386Swpaul ether_input(ifp, eh, m); 185645386Swpaul } 185745386Swpaul 185845386Swpaul /* Only necessary on the Tigon 1. */ 185945386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 186045386Swpaul CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 186145386Swpaul sc->ti_rx_saved_considx); 186245386Swpaul 186348597Swpaul TI_UPDATE_STDPROD(sc, sc->ti_std); 186448597Swpaul TI_UPDATE_MINIPROD(sc, sc->ti_mini); 186548597Swpaul TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo); 186645386Swpaul 186745386Swpaul return; 186845386Swpaul} 186945386Swpaul 187045386Swpaulstatic void ti_txeof(sc) 187145386Swpaul struct ti_softc *sc; 187245386Swpaul{ 187345386Swpaul struct ti_tx_desc *cur_tx = NULL; 187445386Swpaul struct ifnet *ifp; 187545386Swpaul 187645386Swpaul ifp = &sc->arpcom.ac_if; 187745386Swpaul 187845386Swpaul /* 187945386Swpaul * Go through our tx ring and free mbufs for those 188045386Swpaul * frames that have been sent. 188145386Swpaul */ 188245386Swpaul while (sc->ti_tx_saved_considx != sc->ti_tx_considx.ti_idx) { 188345386Swpaul u_int32_t idx = 0; 188445386Swpaul 188545386Swpaul idx = sc->ti_tx_saved_considx; 188645386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) { 188745386Swpaul if (idx > 383) 188845386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 188945386Swpaul TI_TX_RING_BASE + 6144); 189045386Swpaul else if (idx > 255) 189145386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 189245386Swpaul TI_TX_RING_BASE + 4096); 189345386Swpaul else if (idx > 127) 189445386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 189545386Swpaul TI_TX_RING_BASE + 2048); 189645386Swpaul else 189745386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 189845386Swpaul TI_TX_RING_BASE); 189945386Swpaul cur_tx = &sc->ti_rdata->ti_tx_ring_nic[idx % 128]; 190045386Swpaul } else 190145386Swpaul cur_tx = &sc->ti_rdata->ti_tx_ring[idx]; 190245386Swpaul if (cur_tx->ti_flags & TI_BDFLAG_END) 190345386Swpaul ifp->if_opackets++; 190445386Swpaul if (sc->ti_cdata.ti_tx_chain[idx] != NULL) { 190545386Swpaul m_freem(sc->ti_cdata.ti_tx_chain[idx]); 190645386Swpaul sc->ti_cdata.ti_tx_chain[idx] = NULL; 190745386Swpaul } 190848011Swpaul sc->ti_txcnt--; 190945386Swpaul TI_INC(sc->ti_tx_saved_considx, TI_TX_RING_CNT); 191045386Swpaul ifp->if_timer = 0; 191145386Swpaul } 191245386Swpaul 191345386Swpaul if (cur_tx != NULL) 191445386Swpaul ifp->if_flags &= ~IFF_OACTIVE; 191545386Swpaul 191645386Swpaul return; 191745386Swpaul} 191845386Swpaul 191945386Swpaulstatic void ti_intr(xsc) 192045386Swpaul void *xsc; 192145386Swpaul{ 192245386Swpaul struct ti_softc *sc; 192345386Swpaul struct ifnet *ifp; 192445386Swpaul 192545386Swpaul sc = xsc; 192645386Swpaul ifp = &sc->arpcom.ac_if; 192745386Swpaul 192845386Swpaul#ifdef notdef 192945386Swpaul /* Avoid this for now -- checking this register is expensive. */ 193045386Swpaul /* Make sure this is really our interrupt. */ 193145386Swpaul if (!(CSR_READ_4(sc, TI_MISC_HOST_CTL) & TI_MHC_INTSTATE)) 193245386Swpaul return; 193345386Swpaul#endif 193445386Swpaul 193545386Swpaul /* Ack interrupt and stop others from occuring. */ 193645386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1); 193745386Swpaul 193845386Swpaul if (ifp->if_flags & IFF_RUNNING) { 193945386Swpaul /* Check RX return ring producer/consumer */ 194045386Swpaul ti_rxeof(sc); 194145386Swpaul 194245386Swpaul /* Check TX ring producer/consumer */ 194345386Swpaul ti_txeof(sc); 194445386Swpaul } 194545386Swpaul 194645386Swpaul ti_handle_events(sc); 194745386Swpaul 194845386Swpaul /* Re-enable interrupts. */ 194945386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0); 195045386Swpaul 195145386Swpaul if (ifp->if_flags & IFF_RUNNING && ifp->if_snd.ifq_head != NULL) 195245386Swpaul ti_start(ifp); 195345386Swpaul 195445386Swpaul return; 195545386Swpaul} 195645386Swpaul 195745386Swpaulstatic void ti_stats_update(sc) 195845386Swpaul struct ti_softc *sc; 195945386Swpaul{ 196045386Swpaul struct ifnet *ifp; 196145386Swpaul 196245386Swpaul ifp = &sc->arpcom.ac_if; 196345386Swpaul 196445386Swpaul ifp->if_collisions += 196545386Swpaul (sc->ti_rdata->ti_info.ti_stats.dot3StatsSingleCollisionFrames + 196645386Swpaul sc->ti_rdata->ti_info.ti_stats.dot3StatsMultipleCollisionFrames + 196745386Swpaul sc->ti_rdata->ti_info.ti_stats.dot3StatsExcessiveCollisions + 196845386Swpaul sc->ti_rdata->ti_info.ti_stats.dot3StatsLateCollisions) - 196945386Swpaul ifp->if_collisions; 197045386Swpaul 197145386Swpaul return; 197245386Swpaul} 197345386Swpaul 197445386Swpaul/* 197545386Swpaul * Encapsulate an mbuf chain in the tx ring by coupling the mbuf data 197645386Swpaul * pointers to descriptors. 197745386Swpaul */ 197845386Swpaulstatic int ti_encap(sc, m_head, txidx) 197945386Swpaul struct ti_softc *sc; 198045386Swpaul struct mbuf *m_head; 198145386Swpaul u_int32_t *txidx; 198245386Swpaul{ 198345386Swpaul struct ti_tx_desc *f = NULL; 198445386Swpaul struct mbuf *m; 198548011Swpaul u_int32_t frag, cur, cnt = 0; 198658698Sjlemon u_int16_t csum_flags = 0; 198745386Swpaul#if NVLAN > 0 198845386Swpaul struct ifvlan *ifv = NULL; 198945386Swpaul 199045386Swpaul if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) && 199145386Swpaul m_head->m_pkthdr.rcvif != NULL && 199245386Swpaul m_head->m_pkthdr.rcvif->if_type == IFT_8021_VLAN) 199345386Swpaul ifv = m_head->m_pkthdr.rcvif->if_softc; 199445386Swpaul#endif 199545386Swpaul 199645386Swpaul m = m_head; 199745386Swpaul cur = frag = *txidx; 199845386Swpaul 199958698Sjlemon if (m_head->m_pkthdr.csum_flags) { 200058698Sjlemon if (m_head->m_pkthdr.csum_flags & CSUM_IP) 200158698Sjlemon csum_flags |= TI_BDFLAG_IP_CKSUM; 200258698Sjlemon if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP)) 200358698Sjlemon csum_flags |= TI_BDFLAG_TCP_UDP_CKSUM; 200458698Sjlemon if (m_head->m_flags & M_LASTFRAG) 200558698Sjlemon csum_flags |= TI_BDFLAG_IP_FRAG_END; 200658698Sjlemon else if (m_head->m_flags & M_FRAG) 200758698Sjlemon csum_flags |= TI_BDFLAG_IP_FRAG; 200858698Sjlemon } 200945386Swpaul /* 201045386Swpaul * Start packing the mbufs in this chain into 201145386Swpaul * the fragment pointers. Stop when we run out 201245386Swpaul * of fragments or hit the end of the mbuf chain. 201345386Swpaul */ 201445386Swpaul for (m = m_head; m != NULL; m = m->m_next) { 201545386Swpaul if (m->m_len != 0) { 201645386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) { 201745386Swpaul if (frag > 383) 201845386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 201945386Swpaul TI_TX_RING_BASE + 6144); 202045386Swpaul else if (frag > 255) 202145386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 202245386Swpaul TI_TX_RING_BASE + 4096); 202345386Swpaul else if (frag > 127) 202445386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 202545386Swpaul TI_TX_RING_BASE + 2048); 202645386Swpaul else 202745386Swpaul CSR_WRITE_4(sc, TI_WINBASE, 202845386Swpaul TI_TX_RING_BASE); 202945386Swpaul f = &sc->ti_rdata->ti_tx_ring_nic[frag % 128]; 203045386Swpaul } else 203145386Swpaul f = &sc->ti_rdata->ti_tx_ring[frag]; 203245386Swpaul if (sc->ti_cdata.ti_tx_chain[frag] != NULL) 203345386Swpaul break; 203445386Swpaul TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t)); 203545386Swpaul f->ti_len = m->m_len; 203658698Sjlemon f->ti_flags = csum_flags; 203745386Swpaul#if NVLAN > 0 203845386Swpaul if (ifv != NULL) { 203945386Swpaul f->ti_flags |= TI_BDFLAG_VLAN_TAG; 204045386Swpaul f->ti_vlan_tag = ifv->ifv_tag; 204145386Swpaul } else { 204245386Swpaul f->ti_vlan_tag = 0; 204345386Swpaul } 204445386Swpaul#endif 204548011Swpaul /* 204648011Swpaul * Sanity check: avoid coming within 16 descriptors 204748011Swpaul * of the end of the ring. 204848011Swpaul */ 204948011Swpaul if ((TI_TX_RING_CNT - (sc->ti_txcnt + cnt)) < 16) 205048011Swpaul return(ENOBUFS); 205145386Swpaul cur = frag; 205245386Swpaul TI_INC(frag, TI_TX_RING_CNT); 205348011Swpaul cnt++; 205445386Swpaul } 205545386Swpaul } 205645386Swpaul 205745386Swpaul if (m != NULL) 205845386Swpaul return(ENOBUFS); 205945386Swpaul 206046177Swpaul if (frag == sc->ti_tx_saved_considx) 206146177Swpaul return(ENOBUFS); 206246177Swpaul 206345386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) 206445386Swpaul sc->ti_rdata->ti_tx_ring_nic[cur % 128].ti_flags |= 206545386Swpaul TI_BDFLAG_END; 206645386Swpaul else 206745386Swpaul sc->ti_rdata->ti_tx_ring[cur].ti_flags |= TI_BDFLAG_END; 206847458Swpaul sc->ti_cdata.ti_tx_chain[cur] = m_head; 206948011Swpaul sc->ti_txcnt += cnt; 207045386Swpaul 207145386Swpaul *txidx = frag; 207245386Swpaul 207345386Swpaul return(0); 207445386Swpaul} 207545386Swpaul 207645386Swpaul/* 207745386Swpaul * Main transmit routine. To avoid having to do mbuf copies, we put pointers 207845386Swpaul * to the mbuf data regions directly in the transmit descriptors. 207945386Swpaul */ 208045386Swpaulstatic void ti_start(ifp) 208145386Swpaul struct ifnet *ifp; 208245386Swpaul{ 208345386Swpaul struct ti_softc *sc; 208445386Swpaul struct mbuf *m_head = NULL; 208545386Swpaul u_int32_t prodidx = 0; 208645386Swpaul 208745386Swpaul sc = ifp->if_softc; 208845386Swpaul 208945386Swpaul prodidx = CSR_READ_4(sc, TI_MB_SENDPROD_IDX); 209045386Swpaul 209145386Swpaul while(sc->ti_cdata.ti_tx_chain[prodidx] == NULL) { 209245386Swpaul IF_DEQUEUE(&ifp->if_snd, m_head); 209345386Swpaul if (m_head == NULL) 209445386Swpaul break; 209545386Swpaul 209645386Swpaul /* 209758698Sjlemon * XXX 209858698Sjlemon * safety overkill. If this is a fragmented packet chain 209958698Sjlemon * with delayed TCP/UDP checksums, then only encapsulate 210058698Sjlemon * it if we have enough descriptors to handle the entire 210158698Sjlemon * chain at once. 210258698Sjlemon * (paranoia -- may not actually be needed) 210358698Sjlemon */ 210458698Sjlemon if (m_head->m_flags & M_FIRSTFRAG && 210558698Sjlemon m_head->m_pkthdr.csum_flags & (CSUM_DELAY_DATA)) { 210658698Sjlemon if ((TI_TX_RING_CNT - sc->ti_txcnt) < 210758698Sjlemon m_head->m_pkthdr.csum_data + 16) { 210858698Sjlemon IF_PREPEND(&ifp->if_snd, m_head); 210958698Sjlemon ifp->if_flags |= IFF_OACTIVE; 211058698Sjlemon break; 211158698Sjlemon } 211258698Sjlemon } 211358698Sjlemon 211458698Sjlemon /* 211545386Swpaul * Pack the data into the transmit ring. If we 211645386Swpaul * don't have room, set the OACTIVE flag and wait 211745386Swpaul * for the NIC to drain the ring. 211845386Swpaul */ 211945386Swpaul if (ti_encap(sc, m_head, &prodidx)) { 212045386Swpaul IF_PREPEND(&ifp->if_snd, m_head); 212145386Swpaul ifp->if_flags |= IFF_OACTIVE; 212245386Swpaul break; 212345386Swpaul } 212445386Swpaul 212545386Swpaul /* 212645386Swpaul * If there's a BPF listener, bounce a copy of this frame 212745386Swpaul * to him. 212845386Swpaul */ 212945386Swpaul if (ifp->if_bpf) 213045386Swpaul bpf_mtap(ifp, m_head); 213145386Swpaul } 213245386Swpaul 213345386Swpaul /* Transmit */ 213445386Swpaul CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, prodidx); 213545386Swpaul 213645386Swpaul /* 213745386Swpaul * Set a timeout in case the chip goes out to lunch. 213845386Swpaul */ 213945386Swpaul ifp->if_timer = 5; 214045386Swpaul 214145386Swpaul return; 214245386Swpaul} 214345386Swpaul 214445386Swpaulstatic void ti_init(xsc) 214545386Swpaul void *xsc; 214645386Swpaul{ 214745386Swpaul struct ti_softc *sc = xsc; 214845386Swpaul int s; 214945386Swpaul 215045386Swpaul s = splimp(); 215145386Swpaul 215245386Swpaul /* Cancel pending I/O and flush buffers. */ 215345386Swpaul ti_stop(sc); 215445386Swpaul 215545386Swpaul /* Init the gen info block, ring control blocks and firmware. */ 215645386Swpaul if (ti_gibinit(sc)) { 215745386Swpaul printf("ti%d: initialization failure\n", sc->ti_unit); 215845386Swpaul splx(s); 215945386Swpaul return; 216045386Swpaul } 216145386Swpaul 216245386Swpaul splx(s); 216345386Swpaul 216445386Swpaul return; 216545386Swpaul} 216645386Swpaul 216745386Swpaulstatic void ti_init2(sc) 216845386Swpaul struct ti_softc *sc; 216945386Swpaul{ 217045386Swpaul struct ti_cmd_desc cmd; 217145386Swpaul struct ifnet *ifp; 217245386Swpaul u_int16_t *m; 217345386Swpaul struct ifmedia *ifm; 217445386Swpaul int tmp; 217545386Swpaul 217645386Swpaul ifp = &sc->arpcom.ac_if; 217745386Swpaul 217845386Swpaul /* Specify MTU and interface index. */ 217945386Swpaul CSR_WRITE_4(sc, TI_GCR_IFINDEX, ifp->if_unit); 218045386Swpaul CSR_WRITE_4(sc, TI_GCR_IFMTU, ifp->if_mtu + 218145386Swpaul ETHER_HDR_LEN + ETHER_CRC_LEN); 218245386Swpaul TI_DO_CMD(TI_CMD_UPDATE_GENCOM, 0, 0); 218345386Swpaul 218445386Swpaul /* Load our MAC address. */ 218545386Swpaul m = (u_int16_t *)&sc->arpcom.ac_enaddr[0]; 218645386Swpaul CSR_WRITE_4(sc, TI_GCR_PAR0, htons(m[0])); 218745386Swpaul CSR_WRITE_4(sc, TI_GCR_PAR1, (htons(m[1]) << 16) | htons(m[2])); 218845386Swpaul TI_DO_CMD(TI_CMD_SET_MAC_ADDR, 0, 0); 218945386Swpaul 219045386Swpaul /* Enable or disable promiscuous mode as needed. */ 219145386Swpaul if (ifp->if_flags & IFF_PROMISC) { 219245386Swpaul TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_ENB, 0); 219345386Swpaul } else { 219445386Swpaul TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, TI_CMD_CODE_PROMISC_DIS, 0); 219545386Swpaul } 219645386Swpaul 219745386Swpaul /* Program multicast filter. */ 219845386Swpaul ti_setmulti(sc); 219945386Swpaul 220045386Swpaul /* 220145386Swpaul * If this is a Tigon 1, we should tell the 220245386Swpaul * firmware to use software packet filtering. 220345386Swpaul */ 220445386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON) { 220545386Swpaul TI_DO_CMD(TI_CMD_FDR_FILTERING, TI_CMD_CODE_FILT_ENB, 0); 220645386Swpaul } 220745386Swpaul 220845386Swpaul /* Init RX ring. */ 220945386Swpaul ti_init_rx_ring_std(sc); 221045386Swpaul 221145386Swpaul /* Init jumbo RX ring. */ 221245386Swpaul if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) 221345386Swpaul ti_init_rx_ring_jumbo(sc); 221445386Swpaul 221545386Swpaul /* 221645386Swpaul * If this is a Tigon 2, we can also configure the 221745386Swpaul * mini ring. 221845386Swpaul */ 221945386Swpaul if (sc->ti_hwrev == TI_HWREV_TIGON_II) 222045386Swpaul ti_init_rx_ring_mini(sc); 222145386Swpaul 222245386Swpaul CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 0); 222345386Swpaul sc->ti_rx_saved_considx = 0; 222445386Swpaul 222545386Swpaul /* Init TX ring. */ 222645386Swpaul ti_init_tx_ring(sc); 222745386Swpaul 222845386Swpaul /* Tell firmware we're alive. */ 222945386Swpaul TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0); 223045386Swpaul 223145386Swpaul /* Enable host interrupts. */ 223245386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0); 223345386Swpaul 223445386Swpaul ifp->if_flags |= IFF_RUNNING; 223545386Swpaul ifp->if_flags &= ~IFF_OACTIVE; 223645386Swpaul 223745386Swpaul /* 223845386Swpaul * Make sure to set media properly. We have to do this 223945386Swpaul * here since we have to issue commands in order to set 224045386Swpaul * the link negotiation and we can't issue commands until 224145386Swpaul * the firmware is running. 224245386Swpaul */ 224345386Swpaul ifm = &sc->ifmedia; 224445386Swpaul tmp = ifm->ifm_media; 224545386Swpaul ifm->ifm_media = ifm->ifm_cur->ifm_media; 224645386Swpaul ti_ifmedia_upd(ifp); 224745386Swpaul ifm->ifm_media = tmp; 224845386Swpaul 224945386Swpaul return; 225045386Swpaul} 225145386Swpaul 225245386Swpaul/* 225345386Swpaul * Set media options. 225445386Swpaul */ 225545386Swpaulstatic int ti_ifmedia_upd(ifp) 225645386Swpaul struct ifnet *ifp; 225745386Swpaul{ 225845386Swpaul struct ti_softc *sc; 225945386Swpaul struct ifmedia *ifm; 226045386Swpaul struct ti_cmd_desc cmd; 226145386Swpaul 226245386Swpaul sc = ifp->if_softc; 226345386Swpaul ifm = &sc->ifmedia; 226445386Swpaul 226545386Swpaul if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) 226645386Swpaul return(EINVAL); 226745386Swpaul 226845386Swpaul switch(IFM_SUBTYPE(ifm->ifm_media)) { 226945386Swpaul case IFM_AUTO: 227045386Swpaul CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB| 227145386Swpaul TI_GLNK_FULL_DUPLEX|TI_GLNK_RX_FLOWCTL_Y| 227245386Swpaul TI_GLNK_AUTONEGENB|TI_GLNK_ENB); 227345386Swpaul CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_100MB|TI_LNK_10MB| 227445386Swpaul TI_LNK_FULL_DUPLEX|TI_LNK_HALF_DUPLEX| 227545386Swpaul TI_LNK_AUTONEGENB|TI_LNK_ENB); 227645386Swpaul TI_DO_CMD(TI_CMD_LINK_NEGOTIATION, 227745386Swpaul TI_CMD_CODE_NEGOTIATE_BOTH, 0); 227845386Swpaul break; 227945386Swpaul case IFM_1000_SX: 228063699Swpaul case IFM_1000_TX: 228145386Swpaul CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB| 228263699Swpaul TI_GLNK_RX_FLOWCTL_Y|TI_GLNK_ENB); 228345386Swpaul CSR_WRITE_4(sc, TI_GCR_LINK, 0); 228463699Swpaul if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 228563699Swpaul TI_SETBIT(sc, TI_GCR_GLINK, TI_GLNK_FULL_DUPLEX); 228663699Swpaul } 228745386Swpaul TI_DO_CMD(TI_CMD_LINK_NEGOTIATION, 228845386Swpaul TI_CMD_CODE_NEGOTIATE_GIGABIT, 0); 228945386Swpaul break; 229045386Swpaul case IFM_100_FX: 229145386Swpaul case IFM_10_FL: 229263699Swpaul case IFM_100_TX: 229363699Swpaul case IFM_10_T: 229445386Swpaul CSR_WRITE_4(sc, TI_GCR_GLINK, 0); 229545386Swpaul CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_ENB|TI_LNK_PREF); 229663699Swpaul if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX || 229763699Swpaul IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) { 229845386Swpaul TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_100MB); 229945386Swpaul } else { 230045386Swpaul TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_10MB); 230145386Swpaul } 230245386Swpaul if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) { 230345386Swpaul TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_FULL_DUPLEX); 230445386Swpaul } else { 230545386Swpaul TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_HALF_DUPLEX); 230645386Swpaul } 230745386Swpaul TI_DO_CMD(TI_CMD_LINK_NEGOTIATION, 230845386Swpaul TI_CMD_CODE_NEGOTIATE_10_100, 0); 230945386Swpaul break; 231045386Swpaul } 231145386Swpaul 231245386Swpaul return(0); 231345386Swpaul} 231445386Swpaul 231545386Swpaul/* 231645386Swpaul * Report current media status. 231745386Swpaul */ 231845386Swpaulstatic void ti_ifmedia_sts(ifp, ifmr) 231945386Swpaul struct ifnet *ifp; 232045386Swpaul struct ifmediareq *ifmr; 232145386Swpaul{ 232245386Swpaul struct ti_softc *sc; 232363699Swpaul u_int32_t media = 0; 232445386Swpaul 232545386Swpaul sc = ifp->if_softc; 232645386Swpaul 232745386Swpaul ifmr->ifm_status = IFM_AVALID; 232845386Swpaul ifmr->ifm_active = IFM_ETHER; 232945386Swpaul 233045386Swpaul if (sc->ti_linkstat == TI_EV_CODE_LINK_DOWN) 233145386Swpaul return; 233245386Swpaul 233345386Swpaul ifmr->ifm_status |= IFM_ACTIVE; 233445386Swpaul 233563699Swpaul if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP) { 233663699Swpaul media = CSR_READ_4(sc, TI_GCR_GLINK_STAT); 233763699Swpaul if (sc->ti_copper) 233863699Swpaul ifmr->ifm_active |= IFM_1000_TX; 233963699Swpaul else 234063699Swpaul ifmr->ifm_active |= IFM_1000_SX; 234163699Swpaul if (media & TI_GLNK_FULL_DUPLEX) 234263699Swpaul ifmr->ifm_active |= IFM_FDX; 234363699Swpaul else 234463699Swpaul ifmr->ifm_active |= IFM_HDX; 234563699Swpaul } else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) { 234645386Swpaul media = CSR_READ_4(sc, TI_GCR_LINK_STAT); 234763699Swpaul if (sc->ti_copper) { 234863699Swpaul if (media & TI_LNK_100MB) 234963699Swpaul ifmr->ifm_active |= IFM_100_TX; 235063699Swpaul if (media & TI_LNK_10MB) 235163699Swpaul ifmr->ifm_active |= IFM_10_T; 235263699Swpaul } else { 235363699Swpaul if (media & TI_LNK_100MB) 235463699Swpaul ifmr->ifm_active |= IFM_100_FX; 235563699Swpaul if (media & TI_LNK_10MB) 235663699Swpaul ifmr->ifm_active |= IFM_10_FL; 235763699Swpaul } 235845386Swpaul if (media & TI_LNK_FULL_DUPLEX) 235945386Swpaul ifmr->ifm_active |= IFM_FDX; 236045386Swpaul if (media & TI_LNK_HALF_DUPLEX) 236145386Swpaul ifmr->ifm_active |= IFM_HDX; 236245386Swpaul } 236345386Swpaul 236445386Swpaul return; 236545386Swpaul} 236645386Swpaul 236745386Swpaulstatic int ti_ioctl(ifp, command, data) 236845386Swpaul struct ifnet *ifp; 236945386Swpaul u_long command; 237045386Swpaul caddr_t data; 237145386Swpaul{ 237245386Swpaul struct ti_softc *sc = ifp->if_softc; 237345386Swpaul struct ifreq *ifr = (struct ifreq *) data; 237445386Swpaul int s, error = 0; 237545386Swpaul struct ti_cmd_desc cmd; 237645386Swpaul 237745386Swpaul s = splimp(); 237845386Swpaul 237945386Swpaul switch(command) { 238045386Swpaul case SIOCSIFADDR: 238145386Swpaul case SIOCGIFADDR: 238245386Swpaul error = ether_ioctl(ifp, command, data); 238345386Swpaul break; 238445386Swpaul case SIOCSIFMTU: 238545386Swpaul if (ifr->ifr_mtu > TI_JUMBO_MTU) 238645386Swpaul error = EINVAL; 238745386Swpaul else { 238845386Swpaul ifp->if_mtu = ifr->ifr_mtu; 238945386Swpaul ti_init(sc); 239045386Swpaul } 239145386Swpaul break; 239245386Swpaul case SIOCSIFFLAGS: 239345386Swpaul if (ifp->if_flags & IFF_UP) { 239445386Swpaul /* 239545386Swpaul * If only the state of the PROMISC flag changed, 239645386Swpaul * then just use the 'set promisc mode' command 239745386Swpaul * instead of reinitializing the entire NIC. Doing 239845386Swpaul * a full re-init means reloading the firmware and 239945386Swpaul * waiting for it to start up, which may take a 240045386Swpaul * second or two. 240145386Swpaul */ 240245386Swpaul if (ifp->if_flags & IFF_RUNNING && 240345386Swpaul ifp->if_flags & IFF_PROMISC && 240445386Swpaul !(sc->ti_if_flags & IFF_PROMISC)) { 240545386Swpaul TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, 240645386Swpaul TI_CMD_CODE_PROMISC_ENB, 0); 240745386Swpaul } else if (ifp->if_flags & IFF_RUNNING && 240845386Swpaul !(ifp->if_flags & IFF_PROMISC) && 240945386Swpaul sc->ti_if_flags & IFF_PROMISC) { 241045386Swpaul TI_DO_CMD(TI_CMD_SET_PROMISC_MODE, 241145386Swpaul TI_CMD_CODE_PROMISC_DIS, 0); 241245386Swpaul } else 241345386Swpaul ti_init(sc); 241445386Swpaul } else { 241545386Swpaul if (ifp->if_flags & IFF_RUNNING) { 241645386Swpaul ti_stop(sc); 241745386Swpaul } 241845386Swpaul } 241945386Swpaul sc->ti_if_flags = ifp->if_flags; 242045386Swpaul error = 0; 242145386Swpaul break; 242245386Swpaul case SIOCADDMULTI: 242345386Swpaul case SIOCDELMULTI: 242445386Swpaul if (ifp->if_flags & IFF_RUNNING) { 242545386Swpaul ti_setmulti(sc); 242645386Swpaul error = 0; 242745386Swpaul } 242845386Swpaul break; 242945386Swpaul case SIOCSIFMEDIA: 243045386Swpaul case SIOCGIFMEDIA: 243145386Swpaul error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, command); 243245386Swpaul break; 243345386Swpaul default: 243445386Swpaul error = EINVAL; 243545386Swpaul break; 243645386Swpaul } 243745386Swpaul 243845386Swpaul (void)splx(s); 243945386Swpaul 244045386Swpaul return(error); 244145386Swpaul} 244245386Swpaul 244345386Swpaulstatic void ti_watchdog(ifp) 244445386Swpaul struct ifnet *ifp; 244545386Swpaul{ 244645386Swpaul struct ti_softc *sc; 244745386Swpaul 244845386Swpaul sc = ifp->if_softc; 244945386Swpaul 245045386Swpaul printf("ti%d: watchdog timeout -- resetting\n", sc->ti_unit); 245145386Swpaul ti_stop(sc); 245245386Swpaul ti_init(sc); 245345386Swpaul 245445386Swpaul ifp->if_oerrors++; 245545386Swpaul 245645386Swpaul return; 245745386Swpaul} 245845386Swpaul 245945386Swpaul/* 246045386Swpaul * Stop the adapter and free any mbufs allocated to the 246145386Swpaul * RX and TX lists. 246245386Swpaul */ 246345386Swpaulstatic void ti_stop(sc) 246445386Swpaul struct ti_softc *sc; 246545386Swpaul{ 246645386Swpaul struct ifnet *ifp; 246745386Swpaul struct ti_cmd_desc cmd; 246845386Swpaul 246945386Swpaul ifp = &sc->arpcom.ac_if; 247045386Swpaul 247145386Swpaul /* Disable host interrupts. */ 247245386Swpaul CSR_WRITE_4(sc, TI_MB_HOSTINTR, 1); 247345386Swpaul /* 247445386Swpaul * Tell firmware we're shutting down. 247545386Swpaul */ 247645386Swpaul TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_DOWN, 0); 247745386Swpaul 247845386Swpaul /* Halt and reinitialize. */ 247945386Swpaul ti_chipinit(sc); 248045386Swpaul ti_mem(sc, 0x2000, 0x100000 - 0x2000, NULL); 248145386Swpaul ti_chipinit(sc); 248245386Swpaul 248345386Swpaul /* Free the RX lists. */ 248445386Swpaul ti_free_rx_ring_std(sc); 248545386Swpaul 248645386Swpaul /* Free jumbo RX list. */ 248745386Swpaul ti_free_rx_ring_jumbo(sc); 248845386Swpaul 248945386Swpaul /* Free mini RX list. */ 249045386Swpaul ti_free_rx_ring_mini(sc); 249145386Swpaul 249245386Swpaul /* Free TX buffers. */ 249345386Swpaul ti_free_tx_ring(sc); 249445386Swpaul 249545386Swpaul sc->ti_ev_prodidx.ti_idx = 0; 249645386Swpaul sc->ti_return_prodidx.ti_idx = 0; 249745386Swpaul sc->ti_tx_considx.ti_idx = 0; 249845386Swpaul sc->ti_tx_saved_considx = TI_TXCONS_UNSET; 249945386Swpaul 250045386Swpaul ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 250145386Swpaul 250245386Swpaul return; 250345386Swpaul} 250445386Swpaul 250545386Swpaul/* 250645386Swpaul * Stop all chip I/O so that the kernel's probe routines don't 250745386Swpaul * get confused by errant DMAs when rebooting. 250845386Swpaul */ 250949011Swpaulstatic void ti_shutdown(dev) 251049011Swpaul device_t dev; 251145386Swpaul{ 251245386Swpaul struct ti_softc *sc; 251345386Swpaul 251449011Swpaul sc = device_get_softc(dev); 251545386Swpaul 251645386Swpaul ti_chipinit(sc); 251745386Swpaul 251845386Swpaul return; 251945386Swpaul} 2520