if_rlreg.h revision 187417
1139825Simp/*- 2117388Swpaul * Copyright (c) 1997, 1998-2003 340516Swpaul * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 440516Swpaul * 540516Swpaul * Redistribution and use in source and binary forms, with or without 640516Swpaul * modification, are permitted provided that the following conditions 740516Swpaul * are met: 840516Swpaul * 1. Redistributions of source code must retain the above copyright 940516Swpaul * notice, this list of conditions and the following disclaimer. 1040516Swpaul * 2. Redistributions in binary form must reproduce the above copyright 1140516Swpaul * notice, this list of conditions and the following disclaimer in the 1240516Swpaul * documentation and/or other materials provided with the distribution. 1340516Swpaul * 3. All advertising materials mentioning features or use of this software 1440516Swpaul * must display the following acknowledgement: 1540516Swpaul * This product includes software developed by Bill Paul. 1640516Swpaul * 4. Neither the name of the author nor the names of any co-contributors 1740516Swpaul * may be used to endorse or promote products derived from this software 1840516Swpaul * without specific prior written permission. 1940516Swpaul * 2040516Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2140516Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2240516Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2340516Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2440516Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2540516Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2640516Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2740516Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2840516Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2940516Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3040516Swpaul * THE POSSIBILITY OF SUCH DAMAGE. 3140516Swpaul * 3250477Speter * $FreeBSD: head/sys/pci/if_rlreg.h 187417 2009-01-19 02:31:27Z yongari $ 3340516Swpaul */ 3440516Swpaul 3540516Swpaul/* 3640516Swpaul * RealTek 8129/8139 register offsets 3740516Swpaul */ 3840516Swpaul#define RL_IDR0 0x0000 /* ID register 0 (station addr) */ 3940516Swpaul#define RL_IDR1 0x0001 /* Must use 32-bit accesses (?) */ 4040516Swpaul#define RL_IDR2 0x0002 4140516Swpaul#define RL_IDR3 0x0003 4240516Swpaul#define RL_IDR4 0x0004 4340516Swpaul#define RL_IDR5 0x0005 4440516Swpaul /* 0006-0007 reserved */ 4540516Swpaul#define RL_MAR0 0x0008 /* Multicast hash table */ 4640516Swpaul#define RL_MAR1 0x0009 4740516Swpaul#define RL_MAR2 0x000A 4840516Swpaul#define RL_MAR3 0x000B 4940516Swpaul#define RL_MAR4 0x000C 5040516Swpaul#define RL_MAR5 0x000D 5140516Swpaul#define RL_MAR6 0x000E 5240516Swpaul#define RL_MAR7 0x000F 5340516Swpaul 5440516Swpaul#define RL_TXSTAT0 0x0010 /* status of TX descriptor 0 */ 5540516Swpaul#define RL_TXSTAT1 0x0014 /* status of TX descriptor 1 */ 5640516Swpaul#define RL_TXSTAT2 0x0018 /* status of TX descriptor 2 */ 5740516Swpaul#define RL_TXSTAT3 0x001C /* status of TX descriptor 3 */ 5840516Swpaul 5940516Swpaul#define RL_TXADDR0 0x0020 /* address of TX descriptor 0 */ 6040516Swpaul#define RL_TXADDR1 0x0024 /* address of TX descriptor 1 */ 6140516Swpaul#define RL_TXADDR2 0x0028 /* address of TX descriptor 2 */ 6240516Swpaul#define RL_TXADDR3 0x002C /* address of TX descriptor 3 */ 6340516Swpaul 6440516Swpaul#define RL_RXADDR 0x0030 /* RX ring start address */ 6540516Swpaul#define RL_RX_EARLY_BYTES 0x0034 /* RX early byte count */ 6640516Swpaul#define RL_RX_EARLY_STAT 0x0036 /* RX early status */ 6740516Swpaul#define RL_COMMAND 0x0037 /* command register */ 6840516Swpaul#define RL_CURRXADDR 0x0038 /* current address of packet read */ 6940516Swpaul#define RL_CURRXBUF 0x003A /* current RX buffer address */ 7040516Swpaul#define RL_IMR 0x003C /* interrupt mask register */ 7140516Swpaul#define RL_ISR 0x003E /* interrupt status register */ 7240516Swpaul#define RL_TXCFG 0x0040 /* transmit config */ 7340516Swpaul#define RL_RXCFG 0x0044 /* receive config */ 7440516Swpaul#define RL_TIMERCNT 0x0048 /* timer count register */ 7540516Swpaul#define RL_MISSEDPKT 0x004C /* missed packet counter */ 7640516Swpaul#define RL_EECMD 0x0050 /* EEPROM command register */ 7740516Swpaul#define RL_CFG0 0x0051 /* config register #0 */ 7840516Swpaul#define RL_CFG1 0x0052 /* config register #1 */ 79176754Syongari#define RL_CFG2 0x0053 /* config register #2 */ 80176754Syongari#define RL_CFG3 0x0054 /* config register #3 */ 81176754Syongari#define RL_CFG4 0x0055 /* config register #4 */ 82176754Syongari#define RL_CFG5 0x0056 /* config register #5 */ 83176754Syongari /* 0057 reserved */ 8440516Swpaul#define RL_MEDIASTAT 0x0058 /* media status register (8139) */ 8540516Swpaul /* 0059-005A reserved */ 8640516Swpaul#define RL_MII 0x005A /* 8129 chip only */ 8740516Swpaul#define RL_HALTCLK 0x005B 8840516Swpaul#define RL_MULTIINTR 0x005C /* multiple interrupt */ 8940516Swpaul#define RL_PCIREV 0x005E /* PCI revision value */ 9040516Swpaul /* 005F reserved */ 9140516Swpaul#define RL_TXSTAT_ALL 0x0060 /* TX status of all descriptors */ 9240516Swpaul 9340516Swpaul/* Direct PHY access registers only available on 8139 */ 9440516Swpaul#define RL_BMCR 0x0062 /* PHY basic mode control */ 9540516Swpaul#define RL_BMSR 0x0064 /* PHY basic mode status */ 9640516Swpaul#define RL_ANAR 0x0066 /* PHY autoneg advert */ 9740516Swpaul#define RL_LPAR 0x0068 /* PHY link partner ability */ 9840516Swpaul#define RL_ANER 0x006A /* PHY autoneg expansion */ 9940516Swpaul 10040516Swpaul#define RL_DISCCNT 0x006C /* disconnect counter */ 10140516Swpaul#define RL_FALSECAR 0x006E /* false carrier counter */ 10240516Swpaul#define RL_NWAYTST 0x0070 /* NWAY test register */ 10340516Swpaul#define RL_RX_ER 0x0072 /* RX_ER counter */ 10440516Swpaul#define RL_CSCFG 0x0074 /* CS configuration register */ 10540516Swpaul 106117388Swpaul/* 107117388Swpaul * When operating in special C+ mode, some of the registers in an 108117388Swpaul * 8139C+ chip have different definitions. These are also used for 109117388Swpaul * the 8169 gigE chip. 110117388Swpaul */ 111117388Swpaul#define RL_DUMPSTATS_LO 0x0010 /* counter dump command register */ 112117388Swpaul#define RL_DUMPSTATS_HI 0x0014 /* counter dump command register */ 113117388Swpaul#define RL_TXLIST_ADDR_LO 0x0020 /* 64 bits, 256 byte alignment */ 114117388Swpaul#define RL_TXLIST_ADDR_HI 0x0024 /* 64 bits, 256 byte alignment */ 115117388Swpaul#define RL_TXLIST_ADDR_HPRIO_LO 0x0028 /* 64 bits, 256 byte alignment */ 116117388Swpaul#define RL_TXLIST_ADDR_HPRIO_HI 0x002C /* 64 bits, 256 byte alignment */ 117120043Swpaul#define RL_CFG2 0x0053 118117388Swpaul#define RL_TIMERINT 0x0054 /* interrupt on timer expire */ 119117388Swpaul#define RL_TXSTART 0x00D9 /* 8 bits */ 120117388Swpaul#define RL_CPLUS_CMD 0x00E0 /* 16 bits */ 121117388Swpaul#define RL_RXLIST_ADDR_LO 0x00E4 /* 64 bits, 256 byte alignment */ 122117388Swpaul#define RL_RXLIST_ADDR_HI 0x00E8 /* 64 bits, 256 byte alignment */ 123117388Swpaul#define RL_EARLY_TX_THRESH 0x00EC /* 8 bits */ 12440516Swpaul 12540516Swpaul/* 126117388Swpaul * Registers specific to the 8169 gigE chip 127117388Swpaul */ 128118586Swpaul#define RL_TIMERINT_8169 0x0058 /* different offset than 8139 */ 129117388Swpaul#define RL_PHYAR 0x0060 130117388Swpaul#define RL_TBICSR 0x0064 131117388Swpaul#define RL_TBI_ANAR 0x0068 132117388Swpaul#define RL_TBI_LPAR 0x006A 133117388Swpaul#define RL_GMEDIASTAT 0x006C /* 8 bits */ 134186210Syongari#define RL_MACDBG 0x006D /* 8 bits, 8168C SPIN2 only */ 135186210Syongari#define RL_GPIO 0x006E /* 8 bits, 8168C SPIN2 only */ 136117388Swpaul#define RL_MAXRXPKTLEN 0x00DA /* 16 bits, chip multiplies by 8 */ 137175337Syongari#define RL_GTXSTART 0x0038 /* 8 bits */ 138117388Swpaul 139117388Swpaul/* 14040516Swpaul * TX config register bits 14140516Swpaul */ 14240516Swpaul#define RL_TXCFG_CLRABRT 0x00000001 /* retransmit aborted pkt */ 14345633Swpaul#define RL_TXCFG_MAXDMA 0x00000700 /* max DMA burst size */ 14440516Swpaul#define RL_TXCFG_CRCAPPEND 0x00010000 /* CRC append (0 = yes) */ 14545633Swpaul#define RL_TXCFG_LOOPBKTST 0x00060000 /* loopback test */ 146119868Swpaul#define RL_TXCFG_IFG2 0x00080000 /* 8169 only */ 14745633Swpaul#define RL_TXCFG_IFG 0x03000000 /* interframe gap */ 148117388Swpaul#define RL_TXCFG_HWREV 0x7CC00000 14940516Swpaul 150119868Swpaul#define RL_LOOPTEST_OFF 0x00000000 151119868Swpaul#define RL_LOOPTEST_ON 0x00020000 152119981Swpaul#define RL_LOOPTEST_ON_CPLUS 0x00060000 153119868Swpaul 154159962Swpaul/* Known revision codes. */ 155117388Swpaul 156160843Swpaul#define RL_HWREV_8169 0x00000000 157160843Swpaul#define RL_HWREV_8110S 0x00800000 158160843Swpaul#define RL_HWREV_8169S 0x04000000 159160843Swpaul#define RL_HWREV_8169_8110SB 0x10000000 160160843Swpaul#define RL_HWREV_8169_8110SC 0x18000000 161180377Syongari#define RL_HWREV_8102EL 0x24800000 162185542Syongari#define RL_HWREV_8168D 0x28000000 163160843Swpaul#define RL_HWREV_8168_SPIN1 0x30000000 164160843Swpaul#define RL_HWREV_8100E 0x30800000 165160843Swpaul#define RL_HWREV_8101E 0x34000000 166180377Syongari#define RL_HWREV_8102E 0x34800000 167160843Swpaul#define RL_HWREV_8168_SPIN2 0x38000000 168174428Syongari#define RL_HWREV_8168_SPIN3 0x38400000 169180176Syongari#define RL_HWREV_8168C 0x3C000000 170180176Syongari#define RL_HWREV_8168C_SPIN2 0x3C400000 171180176Syongari#define RL_HWREV_8168CP 0x3C800000 172160843Swpaul#define RL_HWREV_8139 0x60000000 173160843Swpaul#define RL_HWREV_8139A 0x70000000 174160843Swpaul#define RL_HWREV_8139AG 0x70800000 175160843Swpaul#define RL_HWREV_8139B 0x78000000 176160843Swpaul#define RL_HWREV_8130 0x7C000000 177160843Swpaul#define RL_HWREV_8139C 0x74000000 178160843Swpaul#define RL_HWREV_8139D 0x74400000 179160843Swpaul#define RL_HWREV_8139CPLUS 0x74800000 180160843Swpaul#define RL_HWREV_8101 0x74c00000 181160843Swpaul#define RL_HWREV_8100 0x78800000 182180177Syongari#define RL_HWREV_8169_8110SBL 0x7CC00000 183159962Swpaul 18445633Swpaul#define RL_TXDMA_16BYTES 0x00000000 18545633Swpaul#define RL_TXDMA_32BYTES 0x00000100 18645633Swpaul#define RL_TXDMA_64BYTES 0x00000200 18745633Swpaul#define RL_TXDMA_128BYTES 0x00000300 18845633Swpaul#define RL_TXDMA_256BYTES 0x00000400 18945633Swpaul#define RL_TXDMA_512BYTES 0x00000500 19045633Swpaul#define RL_TXDMA_1024BYTES 0x00000600 19145633Swpaul#define RL_TXDMA_2048BYTES 0x00000700 19245633Swpaul 19340516Swpaul/* 19440516Swpaul * Transmit descriptor status register bits. 19540516Swpaul */ 19640516Swpaul#define RL_TXSTAT_LENMASK 0x00001FFF 19740516Swpaul#define RL_TXSTAT_OWN 0x00002000 19840516Swpaul#define RL_TXSTAT_TX_UNDERRUN 0x00004000 19940516Swpaul#define RL_TXSTAT_TX_OK 0x00008000 20040516Swpaul#define RL_TXSTAT_EARLY_THRESH 0x003F0000 20140516Swpaul#define RL_TXSTAT_COLLCNT 0x0F000000 20240516Swpaul#define RL_TXSTAT_CARR_HBEAT 0x10000000 20340516Swpaul#define RL_TXSTAT_OUTOFWIN 0x20000000 20440516Swpaul#define RL_TXSTAT_TXABRT 0x40000000 20540516Swpaul#define RL_TXSTAT_CARRLOSS 0x80000000 20640516Swpaul 20740516Swpaul/* 20840516Swpaul * Interrupt status register bits. 20940516Swpaul */ 21040516Swpaul#define RL_ISR_RX_OK 0x0001 21140516Swpaul#define RL_ISR_RX_ERR 0x0002 21240516Swpaul#define RL_ISR_TX_OK 0x0004 21340516Swpaul#define RL_ISR_TX_ERR 0x0008 21440516Swpaul#define RL_ISR_RX_OVERRUN 0x0010 21540516Swpaul#define RL_ISR_PKT_UNDERRUN 0x0020 216119868Swpaul#define RL_ISR_LINKCHG 0x0020 /* 8169 only */ 21740516Swpaul#define RL_ISR_FIFO_OFLOW 0x0040 /* 8139 only */ 218117388Swpaul#define RL_ISR_TX_DESC_UNAVAIL 0x0080 /* C+ only */ 219117388Swpaul#define RL_ISR_SWI 0x0100 /* C+ only */ 220117388Swpaul#define RL_ISR_CABLE_LEN_CHGD 0x2000 22140516Swpaul#define RL_ISR_PCS_TIMEOUT 0x4000 /* 8129 only */ 222117388Swpaul#define RL_ISR_TIMEOUT_EXPIRED 0x4000 22340516Swpaul#define RL_ISR_SYSTEM_ERR 0x8000 22440516Swpaul 22540516Swpaul#define RL_INTRS \ 22640516Swpaul (RL_ISR_TX_OK|RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \ 22740516Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 22840516Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR) 22940516Swpaul 230159962Swpaul#ifdef RE_TX_MODERATION 231117388Swpaul#define RL_INTRS_CPLUS \ 232119868Swpaul (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \ 233117388Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 234117388Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED) 235159962Swpaul#else 236159962Swpaul#define RL_INTRS_CPLUS \ 237159962Swpaul (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR|RL_ISR_TX_OK| \ 238159962Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 239159962Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED) 240159962Swpaul#endif 241117388Swpaul 24240516Swpaul/* 24340516Swpaul * Media status register. (8139 only) 24440516Swpaul */ 24540516Swpaul#define RL_MEDIASTAT_RXPAUSE 0x01 24640516Swpaul#define RL_MEDIASTAT_TXPAUSE 0x02 24740516Swpaul#define RL_MEDIASTAT_LINK 0x04 24840516Swpaul#define RL_MEDIASTAT_SPEED10 0x08 24940516Swpaul#define RL_MEDIASTAT_RXFLOWCTL 0x40 /* duplex mode */ 25040516Swpaul#define RL_MEDIASTAT_TXFLOWCTL 0x80 /* duplex mode */ 25140516Swpaul 25240516Swpaul/* 25340516Swpaul * Receive config register. 25440516Swpaul */ 25540516Swpaul#define RL_RXCFG_RX_ALLPHYS 0x00000001 /* accept all nodes */ 25640516Swpaul#define RL_RXCFG_RX_INDIV 0x00000002 /* match filter */ 25740516Swpaul#define RL_RXCFG_RX_MULTI 0x00000004 /* accept all multicast */ 25840516Swpaul#define RL_RXCFG_RX_BROAD 0x00000008 /* accept all broadcast */ 25940516Swpaul#define RL_RXCFG_RX_RUNT 0x00000010 26040516Swpaul#define RL_RXCFG_RX_ERRPKT 0x00000020 26140516Swpaul#define RL_RXCFG_WRAP 0x00000080 26245633Swpaul#define RL_RXCFG_MAXDMA 0x00000700 26345633Swpaul#define RL_RXCFG_BUFSZ 0x00001800 26445633Swpaul#define RL_RXCFG_FIFOTHRESH 0x0000E000 26545633Swpaul#define RL_RXCFG_EARLYTHRESH 0x07000000 26640516Swpaul 26745633Swpaul#define RL_RXDMA_16BYTES 0x00000000 26845633Swpaul#define RL_RXDMA_32BYTES 0x00000100 26945633Swpaul#define RL_RXDMA_64BYTES 0x00000200 27045633Swpaul#define RL_RXDMA_128BYTES 0x00000300 27145633Swpaul#define RL_RXDMA_256BYTES 0x00000400 27245633Swpaul#define RL_RXDMA_512BYTES 0x00000500 27345633Swpaul#define RL_RXDMA_1024BYTES 0x00000600 27445633Swpaul#define RL_RXDMA_UNLIMITED 0x00000700 27545633Swpaul 27640516Swpaul#define RL_RXBUF_8 0x00000000 27740516Swpaul#define RL_RXBUF_16 0x00000800 27840516Swpaul#define RL_RXBUF_32 0x00001000 27945633Swpaul#define RL_RXBUF_64 0x00001800 28040516Swpaul 28145633Swpaul#define RL_RXFIFO_16BYTES 0x00000000 28245633Swpaul#define RL_RXFIFO_32BYTES 0x00002000 28345633Swpaul#define RL_RXFIFO_64BYTES 0x00004000 28445633Swpaul#define RL_RXFIFO_128BYTES 0x00006000 28545633Swpaul#define RL_RXFIFO_256BYTES 0x00008000 28645633Swpaul#define RL_RXFIFO_512BYTES 0x0000A000 28745633Swpaul#define RL_RXFIFO_1024BYTES 0x0000C000 28845633Swpaul#define RL_RXFIFO_NOTHRESH 0x0000E000 28945633Swpaul 29040516Swpaul/* 29140516Swpaul * Bits in RX status header (included with RX'ed packet 29240516Swpaul * in ring buffer). 29340516Swpaul */ 29440516Swpaul#define RL_RXSTAT_RXOK 0x00000001 29540516Swpaul#define RL_RXSTAT_ALIGNERR 0x00000002 29640516Swpaul#define RL_RXSTAT_CRCERR 0x00000004 29740516Swpaul#define RL_RXSTAT_GIANT 0x00000008 29840516Swpaul#define RL_RXSTAT_RUNT 0x00000010 29940516Swpaul#define RL_RXSTAT_BADSYM 0x00000020 30040516Swpaul#define RL_RXSTAT_BROAD 0x00002000 30140516Swpaul#define RL_RXSTAT_INDIV 0x00004000 30240516Swpaul#define RL_RXSTAT_MULTI 0x00008000 30340516Swpaul#define RL_RXSTAT_LENMASK 0xFFFF0000 30440516Swpaul 30540516Swpaul#define RL_RXSTAT_UNFINISHED 0xFFF0 /* DMA still in progress */ 30640516Swpaul/* 30740516Swpaul * Command register. 30840516Swpaul */ 30940516Swpaul#define RL_CMD_EMPTY_RXBUF 0x0001 31040516Swpaul#define RL_CMD_TX_ENB 0x0004 31140516Swpaul#define RL_CMD_RX_ENB 0x0008 31240516Swpaul#define RL_CMD_RESET 0x0010 313185900Syongari#define RL_CMD_STOPREQ 0x0080 31440516Swpaul 31540516Swpaul/* 316184515Simp * Twister register values. These are completely undocumented and derived 317184515Simp * from public sources. 318184515Simp */ 319184515Simp#define RL_CSCFG_LINK_OK 0x0400 320184515Simp#define RL_CSCFG_CHANGE 0x0800 321184515Simp#define RL_CSCFG_STATUS 0xf000 322184515Simp#define RL_CSCFG_ROW3 0x7000 323184515Simp#define RL_CSCFG_ROW2 0x3000 324184515Simp#define RL_CSCFG_ROW1 0x1000 325184515Simp#define RL_CSCFG_LINK_DOWN_OFF_CMD 0x03c0 326184515Simp#define RL_CSCFG_LINK_DOWN_CMD 0xf3c0 327184515Simp 328184515Simp#define RL_NWAYTST_RESET 0 329184515Simp#define RL_NWAYTST_CBL_TEST 0x20 330184515Simp 331184515Simp#define RL_PARA78 0x78 332184515Simp#define RL_PARA78_DEF 0x78fa8388 333184515Simp#define RL_PARA7C 0x7C 334184515Simp#define RL_PARA7C_DEF 0xcb38de43 335184515Simp#define RL_PARA7C_RETUNE 0xfb38de03 336184515Simp/* 33740516Swpaul * EEPROM control register 33840516Swpaul */ 33940516Swpaul#define RL_EE_DATAOUT 0x01 /* Data out */ 34040516Swpaul#define RL_EE_DATAIN 0x02 /* Data in */ 34140516Swpaul#define RL_EE_CLK 0x04 /* clock */ 34240516Swpaul#define RL_EE_SEL 0x08 /* chip select */ 34340516Swpaul#define RL_EE_MODE (0x40|0x80) 34440516Swpaul 34540516Swpaul#define RL_EEMODE_OFF 0x00 34640516Swpaul#define RL_EEMODE_AUTOLOAD 0x40 34740516Swpaul#define RL_EEMODE_PROGRAM 0x80 34840516Swpaul#define RL_EEMODE_WRITECFG (0x80|0x40) 34940516Swpaul 35040516Swpaul/* 9346 EEPROM commands */ 351171263Syongari#define RL_9346_ADDR_LEN 6 /* 93C46 1K: 128x16 */ 352171263Syongari#define RL_9356_ADDR_LEN 8 /* 93C56 2K: 256x16 */ 353159962Swpaul 354159962Swpaul#define RL_9346_WRITE 0x5 355159962Swpaul#define RL_9346_READ 0x6 356159962Swpaul#define RL_9346_ERASE 0x7 357159962Swpaul#define RL_9346_EWEN 0x4 358159962Swpaul#define RL_9346_EWEN_ADDR 0x30 359159962Swpaul#define RL_9456_EWDS 0x4 360159962Swpaul#define RL_9346_EWDS_ADDR 0x00 361159962Swpaul 36240516Swpaul#define RL_EECMD_WRITE 0x140 36367931Swpaul#define RL_EECMD_READ_6BIT 0x180 36467931Swpaul#define RL_EECMD_READ_8BIT 0x600 36540516Swpaul#define RL_EECMD_ERASE 0x1c0 36640516Swpaul 36740516Swpaul#define RL_EE_ID 0x00 36840516Swpaul#define RL_EE_PCI_VID 0x01 36940516Swpaul#define RL_EE_PCI_DID 0x02 37040516Swpaul/* Location of station address inside EEPROM */ 37140516Swpaul#define RL_EE_EADDR 0x07 37240516Swpaul 37340516Swpaul/* 37440516Swpaul * MII register (8129 only) 37540516Swpaul */ 37640516Swpaul#define RL_MII_CLK 0x01 37740516Swpaul#define RL_MII_DATAIN 0x02 37840516Swpaul#define RL_MII_DATAOUT 0x04 37940516Swpaul#define RL_MII_DIR 0x80 /* 0 == input, 1 == output */ 38040516Swpaul 38140516Swpaul/* 38240516Swpaul * Config 0 register 38340516Swpaul */ 38440516Swpaul#define RL_CFG0_ROM0 0x01 38540516Swpaul#define RL_CFG0_ROM1 0x02 38640516Swpaul#define RL_CFG0_ROM2 0x04 38740516Swpaul#define RL_CFG0_PL0 0x08 38840516Swpaul#define RL_CFG0_PL1 0x10 38940516Swpaul#define RL_CFG0_10MBPS 0x20 /* 10 Mbps internal mode */ 39040516Swpaul#define RL_CFG0_PCS 0x40 39140516Swpaul#define RL_CFG0_SCR 0x80 39240516Swpaul 39340516Swpaul/* 39440516Swpaul * Config 1 register 39540516Swpaul */ 39640516Swpaul#define RL_CFG1_PWRDWN 0x01 397176754Syongari#define RL_CFG1_PME 0x01 39840516Swpaul#define RL_CFG1_SLEEP 0x02 399176754Syongari#define RL_CFG1_VPDEN 0x02 40040516Swpaul#define RL_CFG1_IOMAP 0x04 40140516Swpaul#define RL_CFG1_MEMMAP 0x08 40240516Swpaul#define RL_CFG1_RSVD 0x10 403176754Syongari#define RL_CFG1_LWACT 0x10 40440516Swpaul#define RL_CFG1_DRVLOAD 0x20 40540516Swpaul#define RL_CFG1_LED0 0x40 40640516Swpaul#define RL_CFG1_FULLDUPLEX 0x40 /* 8129 only */ 40740516Swpaul#define RL_CFG1_LED1 0x80 40840516Swpaul 40940516Swpaul/* 410176754Syongari * Config 2 register 411176754Syongari */ 412176754Syongari#define RL_CFG2_PCI33MHZ 0x00 413176754Syongari#define RL_CFG2_PCI66MHZ 0x01 414176754Syongari#define RL_CFG2_PCI64BIT 0x08 415176754Syongari#define RL_CFG2_AUXPWR 0x10 416177522Syongari#define RL_CFG2_MSI 0x20 417176754Syongari 418176754Syongari/* 419176754Syongari * Config 3 register 420176754Syongari */ 421176754Syongari#define RL_CFG3_GRANTSEL 0x80 422176754Syongari#define RL_CFG3_WOL_MAGIC 0x20 423176754Syongari#define RL_CFG3_WOL_LINK 0x10 424176754Syongari#define RL_CFG3_FAST_B2B 0x01 425176754Syongari 426176754Syongari/* 427176754Syongari * Config 4 register 428176754Syongari */ 429176754Syongari#define RL_CFG4_LWPTN 0x04 430176754Syongari#define RL_CFG4_LWPME 0x10 431176754Syongari 432176754Syongari/* 433176754Syongari * Config 5 register 434176754Syongari */ 435176754Syongari#define RL_CFG5_WOL_BCAST 0x40 436176754Syongari#define RL_CFG5_WOL_MCAST 0x20 437176754Syongari#define RL_CFG5_WOL_UCAST 0x10 438176754Syongari#define RL_CFG5_WOL_LANWAKE 0x02 439176754Syongari#define RL_CFG5_PME_STS 0x01 440176754Syongari 441176754Syongari/* 442117388Swpaul * 8139C+ register definitions 443117388Swpaul */ 444117388Swpaul 445117388Swpaul/* RL_DUMPSTATS_LO register */ 446117388Swpaul 447117388Swpaul#define RL_DUMPSTATS_START 0x00000008 448117388Swpaul 449117388Swpaul/* Transmit start register */ 450117388Swpaul 451117388Swpaul#define RL_TXSTART_SWI 0x01 /* generate TX interrupt */ 452117388Swpaul#define RL_TXSTART_START 0x40 /* start normal queue transmit */ 453117388Swpaul#define RL_TXSTART_HPRIO_START 0x80 /* start hi prio queue transmit */ 454117388Swpaul 455120043Swpaul/* 456120043Swpaul * Config 2 register, 8139C+/8169/8169S/8110S only 457120043Swpaul */ 458120043Swpaul#define RL_CFG2_BUSFREQ 0x07 459120043Swpaul#define RL_CFG2_BUSWIDTH 0x08 460120043Swpaul#define RL_CFG2_AUXPWRSTS 0x10 461120043Swpaul 462120043Swpaul#define RL_BUSFREQ_33MHZ 0x00 463120043Swpaul#define RL_BUSFREQ_66MHZ 0x01 464120043Swpaul 465120043Swpaul#define RL_BUSWIDTH_32BITS 0x00 466120043Swpaul#define RL_BUSWIDTH_64BITS 0x08 467120043Swpaul 468117388Swpaul/* C+ mode command register */ 469117388Swpaul 470117388Swpaul#define RL_CPLUSCMD_TXENB 0x0001 /* enable C+ transmit mode */ 471117388Swpaul#define RL_CPLUSCMD_RXENB 0x0002 /* enable C+ receive mode */ 472117388Swpaul#define RL_CPLUSCMD_PCI_MRW 0x0008 /* enable PCI multi-read/write */ 473117388Swpaul#define RL_CPLUSCMD_PCI_DAC 0x0010 /* PCI dual-address cycle only */ 474117388Swpaul#define RL_CPLUSCMD_RXCSUM_ENB 0x0020 /* enable RX checksum offload */ 475117388Swpaul#define RL_CPLUSCMD_VLANSTRIP 0x0040 /* enable VLAN tag stripping */ 476180176Syongari#define RL_CPLUSCMD_MACSTAT_DIS 0x0080 /* 8168B/C/CP */ 477180176Syongari#define RL_CPLUSCMD_ASF 0x0100 /* 8168C/CP */ 478180176Syongari#define RL_CPLUSCMD_DBG_SEL 0x0200 /* 8168C/CP */ 479180176Syongari#define RL_CPLUSCMD_FORCE_TXFC 0x0400 /* 8168C/CP */ 480180176Syongari#define RL_CPLUSCMD_FORCE_RXFC 0x0800 /* 8168C/CP */ 481180176Syongari#define RL_CPLUSCMD_FORCE_HDPX 0x1000 /* 8168C/CP */ 482180176Syongari#define RL_CPLUSCMD_NORMAL_MODE 0x2000 /* 8168C/CP */ 483180176Syongari#define RL_CPLUSCMD_DBG_ENB 0x4000 /* 8168C/CP */ 484180176Syongari#define RL_CPLUSCMD_BIST_ENB 0x8000 /* 8168C/CP */ 485117388Swpaul 486117388Swpaul/* C+ early transmit threshold */ 487117388Swpaul 488117388Swpaul#define RL_EARLYTXTHRESH_CNT 0x003F /* byte count times 8 */ 489117388Swpaul 490117388Swpaul/* 491117388Swpaul * Gigabit PHY access register (8169 only) 492117388Swpaul */ 493117388Swpaul 494117388Swpaul#define RL_PHYAR_PHYDATA 0x0000FFFF 495117388Swpaul#define RL_PHYAR_PHYREG 0x001F0000 496117388Swpaul#define RL_PHYAR_BUSY 0x80000000 497117388Swpaul 498117388Swpaul/* 499117388Swpaul * Gigabit media status (8169 only) 500117388Swpaul */ 501117388Swpaul#define RL_GMEDIASTAT_FDX 0x01 /* full duplex */ 502117388Swpaul#define RL_GMEDIASTAT_LINK 0x02 /* link up */ 503117388Swpaul#define RL_GMEDIASTAT_10MBPS 0x04 /* 10mps link */ 504117388Swpaul#define RL_GMEDIASTAT_100MBPS 0x08 /* 100mbps link */ 505119976Swpaul#define RL_GMEDIASTAT_1000MBPS 0x10 /* gigE link */ 506117388Swpaul#define RL_GMEDIASTAT_RXFLOW 0x20 /* RX flow control on */ 507117388Swpaul#define RL_GMEDIASTAT_TXFLOW 0x40 /* TX flow control on */ 508117388Swpaul#define RL_GMEDIASTAT_TBI 0x80 /* TBI enabled */ 509117388Swpaul 510117388Swpaul/* 51140516Swpaul * The RealTek doesn't use a fragment-based descriptor mechanism. 51240516Swpaul * Instead, there are only four register sets, each or which represents 51340516Swpaul * one 'descriptor.' Basically, each TX descriptor is just a contiguous 51440516Swpaul * packet buffer (32-bit aligned!) and we place the buffer addresses in 51540516Swpaul * the registers so the chip knows where they are. 51640516Swpaul * 51740516Swpaul * We can sort of kludge together the same kind of buffer management 51840516Swpaul * used in previous drivers, but we have to do buffer copies almost all 51940516Swpaul * the time, so it doesn't really buy us much. 52040516Swpaul * 52140516Swpaul * For reception, there's just one large buffer where the chip stores 52240516Swpaul * all received packets. 52340516Swpaul */ 52440516Swpaul 52540516Swpaul#define RL_RX_BUF_SZ RL_RXBUF_64 52640516Swpaul#define RL_RXBUFLEN (1 << ((RL_RX_BUF_SZ >> 11) + 13)) 52740516Swpaul#define RL_TX_LIST_CNT 4 52840516Swpaul#define RL_MIN_FRAMELEN 60 529184240Syongari#define RL_TX_8139_BUF_ALIGN 4 530184240Syongari#define RL_RX_8139_BUF_ALIGN 8 531184240Syongari#define RL_RX_8139_BUF_RESERVE sizeof(int64_t) 532184240Syongari#define RL_RX_8139_BUF_GUARD_SZ \ 533184240Syongari (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN + RL_RX_8139_BUF_RESERVE) 53452426Swpaul#define RL_TXTHRESH(x) ((x) << 11) 53552426Swpaul#define RL_TX_THRESH_INIT 96 536119868Swpaul#define RL_RX_FIFOTHRESH RL_RXFIFO_NOTHRESH 537119868Swpaul#define RL_RX_MAXDMA RL_RXDMA_UNLIMITED 53850703Swpaul#define RL_TX_MAXDMA RL_TXDMA_2048BYTES 53940516Swpaul 54045633Swpaul#define RL_RXCFG_CONFIG (RL_RX_FIFOTHRESH|RL_RX_MAXDMA|RL_RX_BUF_SZ) 54145633Swpaul#define RL_TXCFG_CONFIG (RL_TXCFG_IFG|RL_TX_MAXDMA) 54240516Swpaul 54348028Swpaul#define RL_ETHER_ALIGN 2 54448028Swpaul 545177771Syongari/* 546177771Syongari * re(4) hardware ip4csum-tx could be mangled with 28 bytes or less IP packets. 547177771Syongari */ 548177771Syongari#define RL_IP4CSUMTX_MINLEN 28 549177771Syongari#define RL_IP4CSUMTX_PADLEN (ETHER_HDR_LEN + RL_IP4CSUMTX_MINLEN) 550177771Syongari 55140516Swpaulstruct rl_chain_data { 552131605Sbms uint16_t cur_rx; 553131605Sbms uint8_t *rl_rx_buf; 554131605Sbms uint8_t *rl_rx_buf_ptr; 55540516Swpaul 55645633Swpaul struct mbuf *rl_tx_chain[RL_TX_LIST_CNT]; 55781713Swpaul bus_dmamap_t rl_tx_dmamap[RL_TX_LIST_CNT]; 558184240Syongari bus_dma_tag_t rl_tx_tag; 559184240Syongari bus_dma_tag_t rl_rx_tag; 560184240Syongari bus_dmamap_t rl_rx_dmamap; 561184240Syongari bus_addr_t rl_rx_buf_paddr; 562131605Sbms uint8_t last_tx; 563131605Sbms uint8_t cur_tx; 56440516Swpaul}; 56540516Swpaul 56645633Swpaul#define RL_INC(x) (x = (x + 1) % RL_TX_LIST_CNT) 56745633Swpaul#define RL_CUR_TXADDR(x) ((x->rl_cdata.cur_tx * 4) + RL_TXADDR0) 56845633Swpaul#define RL_CUR_TXSTAT(x) ((x->rl_cdata.cur_tx * 4) + RL_TXSTAT0) 56945633Swpaul#define RL_CUR_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.cur_tx]) 57081713Swpaul#define RL_CUR_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.cur_tx]) 57145633Swpaul#define RL_LAST_TXADDR(x) ((x->rl_cdata.last_tx * 4) + RL_TXADDR0) 57245633Swpaul#define RL_LAST_TXSTAT(x) ((x->rl_cdata.last_tx * 4) + RL_TXSTAT0) 57345633Swpaul#define RL_LAST_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.last_tx]) 57481713Swpaul#define RL_LAST_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.last_tx]) 57545633Swpaul 57640516Swpaulstruct rl_type { 577131605Sbms uint16_t rl_vid; 578131605Sbms uint16_t rl_did; 579117388Swpaul int rl_basetype; 58040516Swpaul char *rl_name; 58140516Swpaul}; 58240516Swpaul 583117388Swpaulstruct rl_hwrev { 584131605Sbms uint32_t rl_rev; 585117388Swpaul int rl_type; 586117388Swpaul char *rl_desc; 587117388Swpaul}; 588117388Swpaul 58940516Swpaulstruct rl_mii_frame { 590131605Sbms uint8_t mii_stdelim; 591131605Sbms uint8_t mii_opcode; 592131605Sbms uint8_t mii_phyaddr; 593131605Sbms uint8_t mii_regaddr; 594131605Sbms uint8_t mii_turnaround; 595131605Sbms uint16_t mii_data; 59640516Swpaul}; 59740516Swpaul 59840516Swpaul/* 59940516Swpaul * MII constants 60040516Swpaul */ 60140516Swpaul#define RL_MII_STARTDELIM 0x01 60240516Swpaul#define RL_MII_READOP 0x02 60340516Swpaul#define RL_MII_WRITEOP 0x01 60440516Swpaul#define RL_MII_TURNAROUND 0x02 60540516Swpaul 60640516Swpaul#define RL_8129 1 60740516Swpaul#define RL_8139 2 608117388Swpaul#define RL_8139CPLUS 3 609117388Swpaul#define RL_8169 4 61040516Swpaul 611117388Swpaul#define RL_ISCPLUS(x) ((x)->rl_type == RL_8139CPLUS || \ 612117388Swpaul (x)->rl_type == RL_8169) 613117388Swpaul 614117388Swpaul/* 615117388Swpaul * The 8139C+ and 8160 gigE chips support descriptor-based TX 616117388Swpaul * and RX. In fact, they even support TCP large send. Descriptors 617117388Swpaul * must be allocated in contiguous blocks that are aligned on a 618117388Swpaul * 256-byte boundary. The rings can hold a maximum of 64 descriptors. 619117388Swpaul */ 620117388Swpaul 621117388Swpaul/* 622117388Swpaul * RX/TX descriptor definition. When large send mode is enabled, the 623117388Swpaul * lower 11 bits of the TX rl_cmd word are used to hold the MSS, and 624117388Swpaul * the checksum offload bits are disabled. The structure layout is 625117388Swpaul * the same for RX and TX descriptors 626117388Swpaul */ 627117388Swpaul 628117388Swpaulstruct rl_desc { 629131605Sbms uint32_t rl_cmdstat; 630131605Sbms uint32_t rl_vlanctl; 631131605Sbms uint32_t rl_bufaddr_lo; 632131605Sbms uint32_t rl_bufaddr_hi; 633117388Swpaul}; 634117388Swpaul 635117388Swpaul#define RL_TDESC_CMD_FRAGLEN 0x0000FFFF 636117388Swpaul#define RL_TDESC_CMD_TCPCSUM 0x00010000 /* TCP checksum enable */ 637117388Swpaul#define RL_TDESC_CMD_UDPCSUM 0x00020000 /* UDP checksum enable */ 638117388Swpaul#define RL_TDESC_CMD_IPCSUM 0x00040000 /* IP header checksum enable */ 639117388Swpaul#define RL_TDESC_CMD_MSSVAL 0x07FF0000 /* Large send MSS value */ 640164463Syongari#define RL_TDESC_CMD_MSSVAL_SHIFT 16 /* Large send MSS value shift */ 641117388Swpaul#define RL_TDESC_CMD_LGSEND 0x08000000 /* TCP large send enb */ 642117388Swpaul#define RL_TDESC_CMD_EOF 0x10000000 /* end of frame marker */ 643117388Swpaul#define RL_TDESC_CMD_SOF 0x20000000 /* start of frame marker */ 644117388Swpaul#define RL_TDESC_CMD_EOR 0x40000000 /* end of ring marker */ 645117388Swpaul#define RL_TDESC_CMD_OWN 0x80000000 /* chip owns descriptor */ 646117388Swpaul 647117388Swpaul#define RL_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */ 648117388Swpaul#define RL_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */ 649180176Syongari/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */ 650180176Syongari#define RL_TDESC_CMD_UDPCSUMV2 0x80000000 651180176Syongari#define RL_TDESC_CMD_TCPCSUMV2 0x40000000 652180176Syongari#define RL_TDESC_CMD_IPCSUMV2 0x20000000 653117388Swpaul 654117388Swpaul/* 655117388Swpaul * Error bits are valid only on the last descriptor of a frame 656117388Swpaul * (i.e. RL_TDESC_CMD_EOF == 1) 657117388Swpaul */ 658117388Swpaul 659117388Swpaul#define RL_TDESC_STAT_COLCNT 0x000F0000 /* collision count */ 660117388Swpaul#define RL_TDESC_STAT_EXCESSCOL 0x00100000 /* excessive collisions */ 661117388Swpaul#define RL_TDESC_STAT_LINKFAIL 0x00200000 /* link faulure */ 662117388Swpaul#define RL_TDESC_STAT_OWINCOL 0x00400000 /* out-of-window collision */ 663117388Swpaul#define RL_TDESC_STAT_TXERRSUM 0x00800000 /* transmit error summary */ 664117388Swpaul#define RL_TDESC_STAT_UNDERRUN 0x02000000 /* TX underrun occured */ 665117388Swpaul#define RL_TDESC_STAT_OWN 0x80000000 666117388Swpaul 667117388Swpaul/* 668117388Swpaul * RX descriptor cmd/vlan definitions 669117388Swpaul */ 670117388Swpaul 671117388Swpaul#define RL_RDESC_CMD_EOR 0x40000000 672117388Swpaul#define RL_RDESC_CMD_OWN 0x80000000 673119981Swpaul#define RL_RDESC_CMD_BUFLEN 0x00001FFF 674117388Swpaul 675117388Swpaul#define RL_RDESC_STAT_OWN 0x80000000 676117388Swpaul#define RL_RDESC_STAT_EOR 0x40000000 677117388Swpaul#define RL_RDESC_STAT_SOF 0x20000000 678117388Swpaul#define RL_RDESC_STAT_EOF 0x10000000 679117388Swpaul#define RL_RDESC_STAT_FRALIGN 0x08000000 /* frame alignment error */ 680117388Swpaul#define RL_RDESC_STAT_MCAST 0x04000000 /* multicast pkt received */ 681117388Swpaul#define RL_RDESC_STAT_UCAST 0x02000000 /* unicast pkt received */ 682117388Swpaul#define RL_RDESC_STAT_BCAST 0x01000000 /* broadcast pkt received */ 683117388Swpaul#define RL_RDESC_STAT_BUFOFLOW 0x00800000 /* out of buffer space */ 684117388Swpaul#define RL_RDESC_STAT_FIFOOFLOW 0x00400000 /* FIFO overrun */ 685117388Swpaul#define RL_RDESC_STAT_GIANT 0x00200000 /* pkt > 4096 bytes */ 686117388Swpaul#define RL_RDESC_STAT_RXERRSUM 0x00100000 /* RX error summary */ 687117388Swpaul#define RL_RDESC_STAT_RUNT 0x00080000 /* runt packet received */ 688117388Swpaul#define RL_RDESC_STAT_CRCERR 0x00040000 /* CRC error */ 689117388Swpaul#define RL_RDESC_STAT_PROTOID 0x00030000 /* Protocol type */ 690180176Syongari#define RL_RDESC_STAT_UDP 0x00020000 /* UDP, 8168C/CP, 8111C/CP */ 691180176Syongari#define RL_RDESC_STAT_TCP 0x00010000 /* TCP, 8168C/CP, 8111C/CP */ 692117388Swpaul#define RL_RDESC_STAT_IPSUMBAD 0x00008000 /* IP header checksum bad */ 693117388Swpaul#define RL_RDESC_STAT_UDPSUMBAD 0x00004000 /* UDP checksum bad */ 694117388Swpaul#define RL_RDESC_STAT_TCPSUMBAD 0x00002000 /* TCP checksum bad */ 695119981Swpaul#define RL_RDESC_STAT_FRAGLEN 0x00001FFF /* RX'ed frame/frag len */ 696119981Swpaul#define RL_RDESC_STAT_GFRAGLEN 0x00003FFF /* RX'ed frame/frag len */ 697135896Sjmg#define RL_RDESC_STAT_ERRS (RL_RDESC_STAT_GIANT|RL_RDESC_STAT_RUNT| \ 698135896Sjmg RL_RDESC_STAT_CRCERR) 699117388Swpaul 700117388Swpaul#define RL_RDESC_VLANCTL_TAG 0x00010000 /* VLAN tag available 701117388Swpaul (rl_vlandata valid)*/ 702117388Swpaul#define RL_RDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */ 703180176Syongari/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */ 704180176Syongari#define RL_RDESC_IPV6 0x80000000 705180176Syongari#define RL_RDESC_IPV4 0x40000000 706117388Swpaul 707117388Swpaul#define RL_PROTOID_NONIP 0x00000000 708117388Swpaul#define RL_PROTOID_TCPIP 0x00010000 709117388Swpaul#define RL_PROTOID_UDPIP 0x00020000 710117388Swpaul#define RL_PROTOID_IP 0x00030000 711117388Swpaul#define RL_TCPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \ 712117388Swpaul RL_PROTOID_TCPIP) 713117388Swpaul#define RL_UDPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \ 714117388Swpaul RL_PROTOID_UDPIP) 715117388Swpaul 716117388Swpaul/* 717117388Swpaul * Statistics counter structure (8139C+ and 8169 only) 718117388Swpaul */ 719117388Swpaulstruct rl_stats { 720131605Sbms uint32_t rl_tx_pkts_lo; 721131605Sbms uint32_t rl_tx_pkts_hi; 722131605Sbms uint32_t rl_tx_errs_lo; 723131605Sbms uint32_t rl_tx_errs_hi; 724131605Sbms uint32_t rl_tx_errs; 725131605Sbms uint16_t rl_missed_pkts; 726131605Sbms uint16_t rl_rx_framealign_errs; 727131605Sbms uint32_t rl_tx_onecoll; 728131605Sbms uint32_t rl_tx_multicolls; 729131605Sbms uint32_t rl_rx_ucasts_hi; 730131605Sbms uint32_t rl_rx_ucasts_lo; 731131605Sbms uint32_t rl_rx_bcasts_lo; 732131605Sbms uint32_t rl_rx_bcasts_hi; 733131605Sbms uint32_t rl_rx_mcasts; 734131605Sbms uint16_t rl_tx_aborts; 735131605Sbms uint16_t rl_rx_underruns; 736117388Swpaul}; 737117388Swpaul 738135467Sjmg/* 739135467Sjmg * Rx/Tx descriptor parameters (8139C+ and 8169 only) 740135467Sjmg * 741175337Syongari * 8139C+ 742175337Syongari * Number of descriptors supported : up to 64 743175337Syongari * Descriptor alignment : 256 bytes 744175337Syongari * Tx buffer : At least 4 bytes in length. 745175337Syongari * Rx buffer : At least 8 bytes in length and 8 bytes alignment required. 746175337Syongari * 747175337Syongari * 8169 748175337Syongari * Number of descriptors supported : up to 1024 749175337Syongari * Descriptor alignment : 256 bytes 750175337Syongari * Tx buffer : At least 4 bytes in length. 751175337Syongari * Rx buffer : At least 8 bytes in length and 8 bytes alignment required. 752135467Sjmg */ 753164460Syongari#ifndef __NO_STRICT_ALIGNMENT 754135896Sjmg#define RE_FIXUP_RX 1 755135896Sjmg#endif 756135896Sjmg 757175337Syongari#define RL_8169_TX_DESC_CNT 256 758175337Syongari#define RL_8169_RX_DESC_CNT 256 759175337Syongari#define RL_8139_TX_DESC_CNT 64 760175337Syongari#define RL_8139_RX_DESC_CNT 64 761175337Syongari#define RL_TX_DESC_CNT RL_8169_TX_DESC_CNT 762175337Syongari#define RL_RX_DESC_CNT RL_8169_RX_DESC_CNT 763175337Syongari#define RL_NTXSEGS 32 764159962Swpaul 765117388Swpaul#define RL_RING_ALIGN 256 766117388Swpaul#define RL_IFQ_MAXLEN 512 767175337Syongari#define RL_TX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1)) 768175337Syongari#define RL_TX_DESC_PRV(sc,x) ((x - 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1)) 769175337Syongari#define RL_RX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_rx_desc_cnt - 1)) 770117388Swpaul#define RL_OWN(x) (le32toh((x)->rl_cmdstat) & RL_RDESC_STAT_OWN) 771119981Swpaul#define RL_RXBYTES(x) (le32toh((x)->rl_cmdstat) & sc->rl_rxlenmask) 772119868Swpaul#define RL_PKTSZ(x) ((x)/* >> 3*/) 773135896Sjmg#ifdef RE_FIXUP_RX 774135896Sjmg#define RE_ETHER_ALIGN sizeof(uint64_t) 775135896Sjmg#define RE_RX_DESC_BUFLEN (MCLBYTES - RE_ETHER_ALIGN) 776135896Sjmg#else 777135896Sjmg#define RE_ETHER_ALIGN 0 778135896Sjmg#define RE_RX_DESC_BUFLEN MCLBYTES 779135896Sjmg#endif 780117388Swpaul 781171560Syongari#define RL_MSI_MESSAGES 2 782171560Syongari 783135467Sjmg#define RL_ADDR_LO(y) ((uint64_t) (y) & 0xFFFFFFFF) 784135467Sjmg#define RL_ADDR_HI(y) ((uint64_t) (y) >> 32) 785118712Swpaul 786181270Syongari/* 787181270Syongari * The number of bits reserved for MSS in RealTek controllers is 788181270Syongari * 11bits. This limits the maximum interface MTU size in TSO case 789181270Syongari * as upper stack should not generate TCP segments with MSS greater 790181270Syongari * than the limit. 791181270Syongari */ 792181270Syongari#define RL_TSO_MTU (2047 - ETHER_HDR_LEN - ETHER_CRC_LEN) 793181270Syongari 794135896Sjmg/* see comment in dev/re/if_re.c */ 795135896Sjmg#define RL_JUMBO_FRAMELEN 7440 796119868Swpaul#define RL_JUMBO_MTU (RL_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN) 797176756Syongari#define RL_MAX_FRAMELEN \ 798176756Syongari (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) 799119868Swpaul 800175337Syongaristruct rl_txdesc { 801175337Syongari struct mbuf *tx_m; 802175337Syongari bus_dmamap_t tx_dmamap; 803175337Syongari}; 804117388Swpaul 805175337Syongaristruct rl_rxdesc { 806175337Syongari struct mbuf *rx_m; 807175337Syongari bus_dmamap_t rx_dmamap; 808175337Syongari bus_size_t rx_size; 809117388Swpaul}; 810117388Swpaul 811117388Swpaulstruct rl_list_data { 812175337Syongari struct rl_txdesc rl_tx_desc[RL_TX_DESC_CNT]; 813175337Syongari struct rl_rxdesc rl_rx_desc[RL_RX_DESC_CNT]; 814175337Syongari int rl_tx_desc_cnt; 815175337Syongari int rl_rx_desc_cnt; 816117388Swpaul int rl_tx_prodidx; 817117388Swpaul int rl_rx_prodidx; 818117388Swpaul int rl_tx_considx; 819117388Swpaul int rl_tx_free; 820175337Syongari bus_dma_tag_t rl_tx_mtag; /* mbuf TX mapping tag */ 821175337Syongari bus_dma_tag_t rl_rx_mtag; /* mbuf RX mapping tag */ 822175337Syongari bus_dmamap_t rl_rx_sparemap; 823117388Swpaul bus_dma_tag_t rl_stag; /* stats mapping tag */ 824117388Swpaul bus_dmamap_t rl_smap; /* stats map */ 825117388Swpaul struct rl_stats *rl_stats; 826118712Swpaul bus_addr_t rl_stats_addr; 827117388Swpaul bus_dma_tag_t rl_rx_list_tag; 828117388Swpaul bus_dmamap_t rl_rx_list_map; 829117388Swpaul struct rl_desc *rl_rx_list; 830118712Swpaul bus_addr_t rl_rx_list_addr; 831117388Swpaul bus_dma_tag_t rl_tx_list_tag; 832117388Swpaul bus_dmamap_t rl_tx_list_map; 833117388Swpaul struct rl_desc *rl_tx_list; 834118712Swpaul bus_addr_t rl_tx_list_addr; 835117388Swpaul}; 836117388Swpaul 837184515Simpenum rl_twist { DONE, CHK_LINK, FIND_ROW, SET_PARAM, RECHK_LONG, RETUNE }; 838184515Simp 83940516Swpaulstruct rl_softc { 840147256Sbrooks struct ifnet *rl_ifp; /* interface info */ 84141569Swpaul bus_space_handle_t rl_bhandle; /* bus space handle */ 84241569Swpaul bus_space_tag_t rl_btag; /* bus space tag */ 843159962Swpaul device_t rl_dev; 84450703Swpaul struct resource *rl_res; 845180169Syongari int rl_res_id; 846180169Syongari int rl_res_type; 847171560Syongari struct resource *rl_irq[RL_MSI_MESSAGES]; 848171560Syongari void *rl_intrhand[RL_MSI_MESSAGES]; 84950703Swpaul device_t rl_miibus; 85081713Swpaul bus_dma_tag_t rl_parent_tag; 851131605Sbms uint8_t rl_type; 85267931Swpaul int rl_eecmd_read; 853159962Swpaul int rl_eewidth; 854131605Sbms uint8_t rl_stats_no_timeout; 85552426Swpaul int rl_txthresh; 85640516Swpaul struct rl_chain_data rl_cdata; 857117388Swpaul struct rl_list_data rl_ldata; 858150720Sjhb struct callout rl_stat_callout; 859164811Sru int rl_watchdog_timer; 86067087Swpaul struct mtx rl_mtx; 861119868Swpaul struct mbuf *rl_head; 862119868Swpaul struct mbuf *rl_tail; 863131605Sbms uint32_t rl_hwrev; 864131605Sbms uint32_t rl_rxlenmask; 865119868Swpaul int rl_testmode; 866168828Syongari int rl_if_flags; 867184559Simp int rl_twister_enable; 868184515Simp enum rl_twist rl_twister; 869184515Simp int rl_twist_row; 870184515Simp int rl_twist_col; 87186822Siwasaki int suspended; /* 0 = normal 1 = suspended */ 87294883Sluigi#ifdef DEVICE_POLLING 87394883Sluigi int rxcycles; 87494883Sluigi#endif 875159962Swpaul 876159962Swpaul struct task rl_txtask; 877159962Swpaul struct task rl_inttask; 878159962Swpaul 879159962Swpaul int rl_txstart; 880180171Syongari uint32_t rl_flags; 881180171Syongari#define RL_FLAG_MSI 0x0001 882180171Syongari#define RL_FLAG_INVMAR 0x0004 883180171Syongari#define RL_FLAG_PHYWAKE 0x0008 884180171Syongari#define RL_FLAG_NOJUMBO 0x0010 885180176Syongari#define RL_FLAG_PAR 0x0020 886180176Syongari#define RL_FLAG_DESCV2 0x0040 887180176Syongari#define RL_FLAG_MACSTAT 0x0080 888185753Syongari#define RL_FLAG_FASTETHER 0x0100 889185900Syongari#define RL_FLAG_CMDSTOP 0x0200 890185901Syongari#define RL_FLAG_PHY8169 0x0400 891185901Syongari#define RL_FLAG_PHY8110S 0x0800 892185903Syongari#define RL_FLAG_WOLRXENB 0x1000 893186210Syongari#define RL_FLAG_MACSLEEP 0x2000 894186214Syongari#define RL_FLAG_PCIE 0x4000 895180171Syongari#define RL_FLAG_LINK 0x8000 89640516Swpaul}; 89740516Swpaul 89872200Sbmilekic#define RL_LOCK(_sc) mtx_lock(&(_sc)->rl_mtx) 89972200Sbmilekic#define RL_UNLOCK(_sc) mtx_unlock(&(_sc)->rl_mtx) 900122689Ssam#define RL_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->rl_mtx, MA_OWNED) 90167087Swpaul 90240516Swpaul/* 90340516Swpaul * register space access macros 90440516Swpaul */ 905119868Swpaul#define CSR_WRITE_STREAM_4(sc, reg, val) \ 906119738Stmm bus_space_write_stream_4(sc->rl_btag, sc->rl_bhandle, reg, val) 90740516Swpaul#define CSR_WRITE_4(sc, reg, val) \ 90841569Swpaul bus_space_write_4(sc->rl_btag, sc->rl_bhandle, reg, val) 90940516Swpaul#define CSR_WRITE_2(sc, reg, val) \ 91041569Swpaul bus_space_write_2(sc->rl_btag, sc->rl_bhandle, reg, val) 91140516Swpaul#define CSR_WRITE_1(sc, reg, val) \ 91241569Swpaul bus_space_write_1(sc->rl_btag, sc->rl_bhandle, reg, val) 91340516Swpaul 91441569Swpaul#define CSR_READ_4(sc, reg) \ 91541569Swpaul bus_space_read_4(sc->rl_btag, sc->rl_bhandle, reg) 91641569Swpaul#define CSR_READ_2(sc, reg) \ 91741569Swpaul bus_space_read_2(sc->rl_btag, sc->rl_bhandle, reg) 91841569Swpaul#define CSR_READ_1(sc, reg) \ 91941569Swpaul bus_space_read_1(sc->rl_btag, sc->rl_bhandle, reg) 92040516Swpaul 921159962Swpaul#define CSR_SETBIT_1(sc, offset, val) \ 922159962Swpaul CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) | (val)) 923159962Swpaul 924159962Swpaul#define CSR_CLRBIT_1(sc, offset, val) \ 925159962Swpaul CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) & ~(val)) 926159962Swpaul 927159962Swpaul#define CSR_SETBIT_2(sc, offset, val) \ 928159962Swpaul CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) | (val)) 929159962Swpaul 930159962Swpaul#define CSR_CLRBIT_2(sc, offset, val) \ 931159962Swpaul CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) & ~(val)) 932159962Swpaul 933159962Swpaul#define CSR_SETBIT_4(sc, offset, val) \ 934159962Swpaul CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) | (val)) 935159962Swpaul 936159962Swpaul#define CSR_CLRBIT_4(sc, offset, val) \ 937159962Swpaul CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) & ~(val)) 938159962Swpaul 93940516Swpaul#define RL_TIMEOUT 1000 940187417Syongari#define RL_PHY_TIMEOUT 2000 94140516Swpaul 94240516Swpaul/* 94340516Swpaul * General constants that are fun to know. 94440516Swpaul * 94540516Swpaul * RealTek PCI vendor ID 94640516Swpaul */ 94740516Swpaul#define RT_VENDORID 0x10EC 94840516Swpaul 94940516Swpaul/* 95040516Swpaul * RealTek chip device IDs. 95140516Swpaul */ 952179831Sremko#define RT_DEVICEID_8139D 0x8039 95340516Swpaul#define RT_DEVICEID_8129 0x8129 954159962Swpaul#define RT_DEVICEID_8101E 0x8136 95567771Swpaul#define RT_DEVICEID_8138 0x8138 95640516Swpaul#define RT_DEVICEID_8139 0x8139 957159962Swpaul#define RT_DEVICEID_8169SC 0x8167 958159962Swpaul#define RT_DEVICEID_8168 0x8168 959117388Swpaul#define RT_DEVICEID_8169 0x8169 960118978Swpaul#define RT_DEVICEID_8100 0x8100 96140516Swpaul 962117388Swpaul#define RT_REVID_8139CPLUS 0x20 963117388Swpaul 96440516Swpaul/* 96544238Swpaul * Accton PCI vendor ID 96644238Swpaul */ 96744238Swpaul#define ACCTON_VENDORID 0x1113 96844238Swpaul 96944238Swpaul/* 97041243Swpaul * Accton MPX 5030/5038 device ID. 97141243Swpaul */ 97241243Swpaul#define ACCTON_DEVICEID_5030 0x1211 97341243Swpaul 97441243Swpaul/* 97594400Swpaul * Nortel PCI vendor ID 97694400Swpaul */ 97794400Swpaul#define NORTEL_VENDORID 0x126C 97894400Swpaul 97994400Swpaul/* 98044238Swpaul * Delta Electronics Vendor ID. 98144238Swpaul */ 98244238Swpaul#define DELTA_VENDORID 0x1500 98344238Swpaul 98444238Swpaul/* 98544238Swpaul * Delta device IDs. 98644238Swpaul */ 98744238Swpaul#define DELTA_DEVICEID_8139 0x1360 98844238Swpaul 98944238Swpaul/* 99044238Swpaul * Addtron vendor ID. 99144238Swpaul */ 99244238Swpaul#define ADDTRON_VENDORID 0x4033 99344238Swpaul 99444238Swpaul/* 99544238Swpaul * Addtron device IDs. 99644238Swpaul */ 99744238Swpaul#define ADDTRON_DEVICEID_8139 0x1360 99844238Swpaul 99944238Swpaul/* 100072813Swpaul * D-Link vendor ID. 100172813Swpaul */ 100272813Swpaul#define DLINK_VENDORID 0x1186 100372813Swpaul 100472813Swpaul/* 100572813Swpaul * D-Link DFE-530TX+ device ID 100672813Swpaul */ 100772813Swpaul#define DLINK_DEVICEID_530TXPLUS 0x1300 100872813Swpaul 100972813Swpaul/* 1010148722Stobez * D-Link DFE-5280T device ID 1011148722Stobez */ 1012148722Stobez#define DLINK_DEVICEID_528T 0x4300 1013148722Stobez 1014148722Stobez/* 101596112Sjhb * D-Link DFE-690TXD device ID 101696112Sjhb */ 101796112Sjhb#define DLINK_DEVICEID_690TXD 0x1340 101896112Sjhb 101996112Sjhb/* 1020103020Siwasaki * Corega K.K vendor ID 1021103020Siwasaki */ 1022103020Siwasaki#define COREGA_VENDORID 0x1259 1023103020Siwasaki 1024103020Siwasaki/* 1025109095Ssanpei * Corega FEther CB-TXD device ID 1026103020Siwasaki */ 1027151341Sjhb#define COREGA_DEVICEID_FETHERCBTXD 0xa117 1028103020Siwasaki 1029103020Siwasaki/* 1030109095Ssanpei * Corega FEtherII CB-TXD device ID 1031109095Ssanpei */ 1032151341Sjhb#define COREGA_DEVICEID_FETHERIICBTXD 0xa11e 1033109095Ssanpei 1034111381Sdan/* 1035134433Ssanpei * Corega CG-LAPCIGT device ID 1036134433Ssanpei */ 1037134433Ssanpei#define COREGA_DEVICEID_CGLAPCIGT 0xc107 1038134433Ssanpei 1039134433Ssanpei/* 1040151341Sjhb * Linksys vendor ID 1041151341Sjhb */ 1042151341Sjhb#define LINKSYS_VENDORID 0x1737 1043151341Sjhb 1044151341Sjhb/* 1045151341Sjhb * Linksys EG1032 device ID 1046151341Sjhb */ 1047151341Sjhb#define LINKSYS_DEVICEID_EG1032 0x1032 1048151341Sjhb 1049151341Sjhb/* 1050151341Sjhb * Linksys EG1032 rev 3 sub-device ID 1051151341Sjhb */ 1052151341Sjhb#define LINKSYS_SUBDEVICE_EG1032_REV3 0x0024 1053151341Sjhb 1054151341Sjhb/* 1055111381Sdan * Peppercon vendor ID 1056111381Sdan */ 1057111381Sdan#define PEPPERCON_VENDORID 0x1743 1058109095Ssanpei 1059111381Sdan/* 1060111381Sdan * Peppercon ROL-F device ID 1061111381Sdan */ 1062111381Sdan#define PEPPERCON_DEVICEID_ROLF 0x8139 1063109095Ssanpei 1064109095Ssanpei/* 1065112379Ssanpei * Planex Communications, Inc. vendor ID 1066112379Ssanpei */ 1067117388Swpaul#define PLANEX_VENDORID 0x14ea 1068112379Ssanpei 1069112379Ssanpei/* 1070173948Sremko * Planex FNW-3603-TX device ID 1071173948Sremko */ 1072173948Sremko#define PLANEX_DEVICEID_FNW3603TX 0xab06 1073173948Sremko 1074173948Sremko/* 1075112379Ssanpei * Planex FNW-3800-TX device ID 1076112379Ssanpei */ 1077117388Swpaul#define PLANEX_DEVICEID_FNW3800TX 0xab07 1078112379Ssanpei 1079112379Ssanpei/* 1080117388Swpaul * LevelOne vendor ID 1081117388Swpaul */ 1082117388Swpaul#define LEVEL1_VENDORID 0x018A 1083117388Swpaul 1084117388Swpaul/* 1085117388Swpaul * LevelOne FPC-0106TX devide ID 1086117388Swpaul */ 1087117388Swpaul#define LEVEL1_DEVICEID_FPC0106TX 0x0106 1088117388Swpaul 1089117388Swpaul/* 1090117388Swpaul * Compaq vendor ID 1091117388Swpaul */ 1092117388Swpaul#define CP_VENDORID 0x021B 1093117388Swpaul 1094117388Swpaul/* 1095117388Swpaul * Edimax vendor ID 1096117388Swpaul */ 1097117388Swpaul#define EDIMAX_VENDORID 0x13D1 1098117388Swpaul 1099117388Swpaul/* 1100117388Swpaul * Edimax EP-4103DL cardbus device ID 1101117388Swpaul */ 1102117388Swpaul#define EDIMAX_DEVICEID_EP4103DL 0xAB06 1103117388Swpaul 1104160883Swpaul/* US Robotics vendor ID */ 1105160883Swpaul 1106160883Swpaul#define USR_VENDORID 0x16EC 1107160883Swpaul 1108160883Swpaul/* US Robotics 997902 device ID */ 1109160883Swpaul 1110160883Swpaul#define USR_DEVICEID_997902 0x0116 1111160883Swpaul 1112117388Swpaul/* 111340516Swpaul * PCI low memory base and low I/O base register, and 111450703Swpaul * other PCI registers. 111540516Swpaul */ 111640516Swpaul 111740516Swpaul#define RL_PCI_VENDOR_ID 0x00 111840516Swpaul#define RL_PCI_DEVICE_ID 0x02 111940516Swpaul#define RL_PCI_COMMAND 0x04 112040516Swpaul#define RL_PCI_STATUS 0x06 112140516Swpaul#define RL_PCI_CLASSCODE 0x09 112240516Swpaul#define RL_PCI_LATENCY_TIMER 0x0D 112340516Swpaul#define RL_PCI_HEADER_TYPE 0x0E 112440516Swpaul#define RL_PCI_LOIO 0x10 112540516Swpaul#define RL_PCI_LOMEM 0x14 112640516Swpaul#define RL_PCI_BIOSROM 0x30 112740516Swpaul#define RL_PCI_INTLINE 0x3C 112840516Swpaul#define RL_PCI_INTPIN 0x3D 112940516Swpaul#define RL_PCI_MINGNT 0x3E 113040516Swpaul#define RL_PCI_MINLAT 0x0F 113140516Swpaul#define RL_PCI_RESETOPT 0x48 113240516Swpaul#define RL_PCI_EEPROM_DATA 0x4C 113340516Swpaul 113450097Swpaul#define RL_PCI_CAPID 0x50 /* 8 bits */ 113550097Swpaul#define RL_PCI_NEXTPTR 0x51 /* 8 bits */ 113650097Swpaul#define RL_PCI_PWRMGMTCAP 0x52 /* 16 bits */ 113750097Swpaul#define RL_PCI_PWRMGMTCTRL 0x54 /* 16 bits */ 113840516Swpaul 113940516Swpaul#define RL_PSTATE_MASK 0x0003 114040516Swpaul#define RL_PSTATE_D0 0x0000 114140516Swpaul#define RL_PSTATE_D1 0x0002 114240516Swpaul#define RL_PSTATE_D2 0x0002 114340516Swpaul#define RL_PSTATE_D3 0x0003 114440516Swpaul#define RL_PME_EN 0x0010 114540516Swpaul#define RL_PME_STATUS 0x8000 1146