if_rlreg.h revision 185542
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 185542 2008-12-02 03:39:34Z 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 */ 134117388Swpaul#define RL_MAXRXPKTLEN 0x00DA /* 16 bits, chip multiplies by 8 */ 135175337Syongari#define RL_GTXSTART 0x0038 /* 8 bits */ 136117388Swpaul 137117388Swpaul/* 13840516Swpaul * TX config register bits 13940516Swpaul */ 14040516Swpaul#define RL_TXCFG_CLRABRT 0x00000001 /* retransmit aborted pkt */ 14145633Swpaul#define RL_TXCFG_MAXDMA 0x00000700 /* max DMA burst size */ 14240516Swpaul#define RL_TXCFG_CRCAPPEND 0x00010000 /* CRC append (0 = yes) */ 14345633Swpaul#define RL_TXCFG_LOOPBKTST 0x00060000 /* loopback test */ 144119868Swpaul#define RL_TXCFG_IFG2 0x00080000 /* 8169 only */ 14545633Swpaul#define RL_TXCFG_IFG 0x03000000 /* interframe gap */ 146117388Swpaul#define RL_TXCFG_HWREV 0x7CC00000 14740516Swpaul 148119868Swpaul#define RL_LOOPTEST_OFF 0x00000000 149119868Swpaul#define RL_LOOPTEST_ON 0x00020000 150119981Swpaul#define RL_LOOPTEST_ON_CPLUS 0x00060000 151119868Swpaul 152159962Swpaul/* Known revision codes. */ 153117388Swpaul 154160843Swpaul#define RL_HWREV_8169 0x00000000 155160843Swpaul#define RL_HWREV_8110S 0x00800000 156160843Swpaul#define RL_HWREV_8169S 0x04000000 157160843Swpaul#define RL_HWREV_8169_8110SB 0x10000000 158160843Swpaul#define RL_HWREV_8169_8110SC 0x18000000 159180377Syongari#define RL_HWREV_8102EL 0x24800000 160185542Syongari#define RL_HWREV_8168D 0x28000000 161160843Swpaul#define RL_HWREV_8168_SPIN1 0x30000000 162160843Swpaul#define RL_HWREV_8100E 0x30800000 163160843Swpaul#define RL_HWREV_8101E 0x34000000 164180377Syongari#define RL_HWREV_8102E 0x34800000 165160843Swpaul#define RL_HWREV_8168_SPIN2 0x38000000 166174428Syongari#define RL_HWREV_8168_SPIN3 0x38400000 167180176Syongari#define RL_HWREV_8168C 0x3C000000 168180176Syongari#define RL_HWREV_8168C_SPIN2 0x3C400000 169180176Syongari#define RL_HWREV_8168CP 0x3C800000 170160843Swpaul#define RL_HWREV_8139 0x60000000 171160843Swpaul#define RL_HWREV_8139A 0x70000000 172160843Swpaul#define RL_HWREV_8139AG 0x70800000 173160843Swpaul#define RL_HWREV_8139B 0x78000000 174160843Swpaul#define RL_HWREV_8130 0x7C000000 175160843Swpaul#define RL_HWREV_8139C 0x74000000 176160843Swpaul#define RL_HWREV_8139D 0x74400000 177160843Swpaul#define RL_HWREV_8139CPLUS 0x74800000 178160843Swpaul#define RL_HWREV_8101 0x74c00000 179160843Swpaul#define RL_HWREV_8100 0x78800000 180180177Syongari#define RL_HWREV_8169_8110SBL 0x7CC00000 181159962Swpaul 18245633Swpaul#define RL_TXDMA_16BYTES 0x00000000 18345633Swpaul#define RL_TXDMA_32BYTES 0x00000100 18445633Swpaul#define RL_TXDMA_64BYTES 0x00000200 18545633Swpaul#define RL_TXDMA_128BYTES 0x00000300 18645633Swpaul#define RL_TXDMA_256BYTES 0x00000400 18745633Swpaul#define RL_TXDMA_512BYTES 0x00000500 18845633Swpaul#define RL_TXDMA_1024BYTES 0x00000600 18945633Swpaul#define RL_TXDMA_2048BYTES 0x00000700 19045633Swpaul 19140516Swpaul/* 19240516Swpaul * Transmit descriptor status register bits. 19340516Swpaul */ 19440516Swpaul#define RL_TXSTAT_LENMASK 0x00001FFF 19540516Swpaul#define RL_TXSTAT_OWN 0x00002000 19640516Swpaul#define RL_TXSTAT_TX_UNDERRUN 0x00004000 19740516Swpaul#define RL_TXSTAT_TX_OK 0x00008000 19840516Swpaul#define RL_TXSTAT_EARLY_THRESH 0x003F0000 19940516Swpaul#define RL_TXSTAT_COLLCNT 0x0F000000 20040516Swpaul#define RL_TXSTAT_CARR_HBEAT 0x10000000 20140516Swpaul#define RL_TXSTAT_OUTOFWIN 0x20000000 20240516Swpaul#define RL_TXSTAT_TXABRT 0x40000000 20340516Swpaul#define RL_TXSTAT_CARRLOSS 0x80000000 20440516Swpaul 20540516Swpaul/* 20640516Swpaul * Interrupt status register bits. 20740516Swpaul */ 20840516Swpaul#define RL_ISR_RX_OK 0x0001 20940516Swpaul#define RL_ISR_RX_ERR 0x0002 21040516Swpaul#define RL_ISR_TX_OK 0x0004 21140516Swpaul#define RL_ISR_TX_ERR 0x0008 21240516Swpaul#define RL_ISR_RX_OVERRUN 0x0010 21340516Swpaul#define RL_ISR_PKT_UNDERRUN 0x0020 214119868Swpaul#define RL_ISR_LINKCHG 0x0020 /* 8169 only */ 21540516Swpaul#define RL_ISR_FIFO_OFLOW 0x0040 /* 8139 only */ 216117388Swpaul#define RL_ISR_TX_DESC_UNAVAIL 0x0080 /* C+ only */ 217117388Swpaul#define RL_ISR_SWI 0x0100 /* C+ only */ 218117388Swpaul#define RL_ISR_CABLE_LEN_CHGD 0x2000 21940516Swpaul#define RL_ISR_PCS_TIMEOUT 0x4000 /* 8129 only */ 220117388Swpaul#define RL_ISR_TIMEOUT_EXPIRED 0x4000 22140516Swpaul#define RL_ISR_SYSTEM_ERR 0x8000 22240516Swpaul 22340516Swpaul#define RL_INTRS \ 22440516Swpaul (RL_ISR_TX_OK|RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \ 22540516Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 22640516Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR) 22740516Swpaul 228159962Swpaul#ifdef RE_TX_MODERATION 229117388Swpaul#define RL_INTRS_CPLUS \ 230119868Swpaul (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR| \ 231117388Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 232117388Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED) 233159962Swpaul#else 234159962Swpaul#define RL_INTRS_CPLUS \ 235159962Swpaul (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_TX_ERR|RL_ISR_TX_OK| \ 236159962Swpaul RL_ISR_RX_OVERRUN|RL_ISR_PKT_UNDERRUN|RL_ISR_FIFO_OFLOW| \ 237159962Swpaul RL_ISR_PCS_TIMEOUT|RL_ISR_SYSTEM_ERR|RL_ISR_TIMEOUT_EXPIRED) 238159962Swpaul#endif 239117388Swpaul 24040516Swpaul/* 24140516Swpaul * Media status register. (8139 only) 24240516Swpaul */ 24340516Swpaul#define RL_MEDIASTAT_RXPAUSE 0x01 24440516Swpaul#define RL_MEDIASTAT_TXPAUSE 0x02 24540516Swpaul#define RL_MEDIASTAT_LINK 0x04 24640516Swpaul#define RL_MEDIASTAT_SPEED10 0x08 24740516Swpaul#define RL_MEDIASTAT_RXFLOWCTL 0x40 /* duplex mode */ 24840516Swpaul#define RL_MEDIASTAT_TXFLOWCTL 0x80 /* duplex mode */ 24940516Swpaul 25040516Swpaul/* 25140516Swpaul * Receive config register. 25240516Swpaul */ 25340516Swpaul#define RL_RXCFG_RX_ALLPHYS 0x00000001 /* accept all nodes */ 25440516Swpaul#define RL_RXCFG_RX_INDIV 0x00000002 /* match filter */ 25540516Swpaul#define RL_RXCFG_RX_MULTI 0x00000004 /* accept all multicast */ 25640516Swpaul#define RL_RXCFG_RX_BROAD 0x00000008 /* accept all broadcast */ 25740516Swpaul#define RL_RXCFG_RX_RUNT 0x00000010 25840516Swpaul#define RL_RXCFG_RX_ERRPKT 0x00000020 25940516Swpaul#define RL_RXCFG_WRAP 0x00000080 26045633Swpaul#define RL_RXCFG_MAXDMA 0x00000700 26145633Swpaul#define RL_RXCFG_BUFSZ 0x00001800 26245633Swpaul#define RL_RXCFG_FIFOTHRESH 0x0000E000 26345633Swpaul#define RL_RXCFG_EARLYTHRESH 0x07000000 26440516Swpaul 26545633Swpaul#define RL_RXDMA_16BYTES 0x00000000 26645633Swpaul#define RL_RXDMA_32BYTES 0x00000100 26745633Swpaul#define RL_RXDMA_64BYTES 0x00000200 26845633Swpaul#define RL_RXDMA_128BYTES 0x00000300 26945633Swpaul#define RL_RXDMA_256BYTES 0x00000400 27045633Swpaul#define RL_RXDMA_512BYTES 0x00000500 27145633Swpaul#define RL_RXDMA_1024BYTES 0x00000600 27245633Swpaul#define RL_RXDMA_UNLIMITED 0x00000700 27345633Swpaul 27440516Swpaul#define RL_RXBUF_8 0x00000000 27540516Swpaul#define RL_RXBUF_16 0x00000800 27640516Swpaul#define RL_RXBUF_32 0x00001000 27745633Swpaul#define RL_RXBUF_64 0x00001800 27840516Swpaul 27945633Swpaul#define RL_RXFIFO_16BYTES 0x00000000 28045633Swpaul#define RL_RXFIFO_32BYTES 0x00002000 28145633Swpaul#define RL_RXFIFO_64BYTES 0x00004000 28245633Swpaul#define RL_RXFIFO_128BYTES 0x00006000 28345633Swpaul#define RL_RXFIFO_256BYTES 0x00008000 28445633Swpaul#define RL_RXFIFO_512BYTES 0x0000A000 28545633Swpaul#define RL_RXFIFO_1024BYTES 0x0000C000 28645633Swpaul#define RL_RXFIFO_NOTHRESH 0x0000E000 28745633Swpaul 28840516Swpaul/* 28940516Swpaul * Bits in RX status header (included with RX'ed packet 29040516Swpaul * in ring buffer). 29140516Swpaul */ 29240516Swpaul#define RL_RXSTAT_RXOK 0x00000001 29340516Swpaul#define RL_RXSTAT_ALIGNERR 0x00000002 29440516Swpaul#define RL_RXSTAT_CRCERR 0x00000004 29540516Swpaul#define RL_RXSTAT_GIANT 0x00000008 29640516Swpaul#define RL_RXSTAT_RUNT 0x00000010 29740516Swpaul#define RL_RXSTAT_BADSYM 0x00000020 29840516Swpaul#define RL_RXSTAT_BROAD 0x00002000 29940516Swpaul#define RL_RXSTAT_INDIV 0x00004000 30040516Swpaul#define RL_RXSTAT_MULTI 0x00008000 30140516Swpaul#define RL_RXSTAT_LENMASK 0xFFFF0000 30240516Swpaul 30340516Swpaul#define RL_RXSTAT_UNFINISHED 0xFFF0 /* DMA still in progress */ 30440516Swpaul/* 30540516Swpaul * Command register. 30640516Swpaul */ 30740516Swpaul#define RL_CMD_EMPTY_RXBUF 0x0001 30840516Swpaul#define RL_CMD_TX_ENB 0x0004 30940516Swpaul#define RL_CMD_RX_ENB 0x0008 31040516Swpaul#define RL_CMD_RESET 0x0010 31140516Swpaul 31240516Swpaul/* 313184515Simp * Twister register values. These are completely undocumented and derived 314184515Simp * from public sources. 315184515Simp */ 316184515Simp#define RL_CSCFG_LINK_OK 0x0400 317184515Simp#define RL_CSCFG_CHANGE 0x0800 318184515Simp#define RL_CSCFG_STATUS 0xf000 319184515Simp#define RL_CSCFG_ROW3 0x7000 320184515Simp#define RL_CSCFG_ROW2 0x3000 321184515Simp#define RL_CSCFG_ROW1 0x1000 322184515Simp#define RL_CSCFG_LINK_DOWN_OFF_CMD 0x03c0 323184515Simp#define RL_CSCFG_LINK_DOWN_CMD 0xf3c0 324184515Simp 325184515Simp#define RL_NWAYTST_RESET 0 326184515Simp#define RL_NWAYTST_CBL_TEST 0x20 327184515Simp 328184515Simp#define RL_PARA78 0x78 329184515Simp#define RL_PARA78_DEF 0x78fa8388 330184515Simp#define RL_PARA7C 0x7C 331184515Simp#define RL_PARA7C_DEF 0xcb38de43 332184515Simp#define RL_PARA7C_RETUNE 0xfb38de03 333184515Simp/* 33440516Swpaul * EEPROM control register 33540516Swpaul */ 33640516Swpaul#define RL_EE_DATAOUT 0x01 /* Data out */ 33740516Swpaul#define RL_EE_DATAIN 0x02 /* Data in */ 33840516Swpaul#define RL_EE_CLK 0x04 /* clock */ 33940516Swpaul#define RL_EE_SEL 0x08 /* chip select */ 34040516Swpaul#define RL_EE_MODE (0x40|0x80) 34140516Swpaul 34240516Swpaul#define RL_EEMODE_OFF 0x00 34340516Swpaul#define RL_EEMODE_AUTOLOAD 0x40 34440516Swpaul#define RL_EEMODE_PROGRAM 0x80 34540516Swpaul#define RL_EEMODE_WRITECFG (0x80|0x40) 34640516Swpaul 34740516Swpaul/* 9346 EEPROM commands */ 348171263Syongari#define RL_9346_ADDR_LEN 6 /* 93C46 1K: 128x16 */ 349171263Syongari#define RL_9356_ADDR_LEN 8 /* 93C56 2K: 256x16 */ 350159962Swpaul 351159962Swpaul#define RL_9346_WRITE 0x5 352159962Swpaul#define RL_9346_READ 0x6 353159962Swpaul#define RL_9346_ERASE 0x7 354159962Swpaul#define RL_9346_EWEN 0x4 355159962Swpaul#define RL_9346_EWEN_ADDR 0x30 356159962Swpaul#define RL_9456_EWDS 0x4 357159962Swpaul#define RL_9346_EWDS_ADDR 0x00 358159962Swpaul 35940516Swpaul#define RL_EECMD_WRITE 0x140 36067931Swpaul#define RL_EECMD_READ_6BIT 0x180 36167931Swpaul#define RL_EECMD_READ_8BIT 0x600 36240516Swpaul#define RL_EECMD_ERASE 0x1c0 36340516Swpaul 36440516Swpaul#define RL_EE_ID 0x00 36540516Swpaul#define RL_EE_PCI_VID 0x01 36640516Swpaul#define RL_EE_PCI_DID 0x02 36740516Swpaul/* Location of station address inside EEPROM */ 36840516Swpaul#define RL_EE_EADDR 0x07 36940516Swpaul 37040516Swpaul/* 37140516Swpaul * MII register (8129 only) 37240516Swpaul */ 37340516Swpaul#define RL_MII_CLK 0x01 37440516Swpaul#define RL_MII_DATAIN 0x02 37540516Swpaul#define RL_MII_DATAOUT 0x04 37640516Swpaul#define RL_MII_DIR 0x80 /* 0 == input, 1 == output */ 37740516Swpaul 37840516Swpaul/* 37940516Swpaul * Config 0 register 38040516Swpaul */ 38140516Swpaul#define RL_CFG0_ROM0 0x01 38240516Swpaul#define RL_CFG0_ROM1 0x02 38340516Swpaul#define RL_CFG0_ROM2 0x04 38440516Swpaul#define RL_CFG0_PL0 0x08 38540516Swpaul#define RL_CFG0_PL1 0x10 38640516Swpaul#define RL_CFG0_10MBPS 0x20 /* 10 Mbps internal mode */ 38740516Swpaul#define RL_CFG0_PCS 0x40 38840516Swpaul#define RL_CFG0_SCR 0x80 38940516Swpaul 39040516Swpaul/* 39140516Swpaul * Config 1 register 39240516Swpaul */ 39340516Swpaul#define RL_CFG1_PWRDWN 0x01 394176754Syongari#define RL_CFG1_PME 0x01 39540516Swpaul#define RL_CFG1_SLEEP 0x02 396176754Syongari#define RL_CFG1_VPDEN 0x02 39740516Swpaul#define RL_CFG1_IOMAP 0x04 39840516Swpaul#define RL_CFG1_MEMMAP 0x08 39940516Swpaul#define RL_CFG1_RSVD 0x10 400176754Syongari#define RL_CFG1_LWACT 0x10 40140516Swpaul#define RL_CFG1_DRVLOAD 0x20 40240516Swpaul#define RL_CFG1_LED0 0x40 40340516Swpaul#define RL_CFG1_FULLDUPLEX 0x40 /* 8129 only */ 40440516Swpaul#define RL_CFG1_LED1 0x80 40540516Swpaul 40640516Swpaul/* 407176754Syongari * Config 2 register 408176754Syongari */ 409176754Syongari#define RL_CFG2_PCI33MHZ 0x00 410176754Syongari#define RL_CFG2_PCI66MHZ 0x01 411176754Syongari#define RL_CFG2_PCI64BIT 0x08 412176754Syongari#define RL_CFG2_AUXPWR 0x10 413177522Syongari#define RL_CFG2_MSI 0x20 414176754Syongari 415176754Syongari/* 416176754Syongari * Config 3 register 417176754Syongari */ 418176754Syongari#define RL_CFG3_GRANTSEL 0x80 419176754Syongari#define RL_CFG3_WOL_MAGIC 0x20 420176754Syongari#define RL_CFG3_WOL_LINK 0x10 421176754Syongari#define RL_CFG3_FAST_B2B 0x01 422176754Syongari 423176754Syongari/* 424176754Syongari * Config 4 register 425176754Syongari */ 426176754Syongari#define RL_CFG4_LWPTN 0x04 427176754Syongari#define RL_CFG4_LWPME 0x10 428176754Syongari 429176754Syongari/* 430176754Syongari * Config 5 register 431176754Syongari */ 432176754Syongari#define RL_CFG5_WOL_BCAST 0x40 433176754Syongari#define RL_CFG5_WOL_MCAST 0x20 434176754Syongari#define RL_CFG5_WOL_UCAST 0x10 435176754Syongari#define RL_CFG5_WOL_LANWAKE 0x02 436176754Syongari#define RL_CFG5_PME_STS 0x01 437176754Syongari 438176754Syongari/* 439117388Swpaul * 8139C+ register definitions 440117388Swpaul */ 441117388Swpaul 442117388Swpaul/* RL_DUMPSTATS_LO register */ 443117388Swpaul 444117388Swpaul#define RL_DUMPSTATS_START 0x00000008 445117388Swpaul 446117388Swpaul/* Transmit start register */ 447117388Swpaul 448117388Swpaul#define RL_TXSTART_SWI 0x01 /* generate TX interrupt */ 449117388Swpaul#define RL_TXSTART_START 0x40 /* start normal queue transmit */ 450117388Swpaul#define RL_TXSTART_HPRIO_START 0x80 /* start hi prio queue transmit */ 451117388Swpaul 452120043Swpaul/* 453120043Swpaul * Config 2 register, 8139C+/8169/8169S/8110S only 454120043Swpaul */ 455120043Swpaul#define RL_CFG2_BUSFREQ 0x07 456120043Swpaul#define RL_CFG2_BUSWIDTH 0x08 457120043Swpaul#define RL_CFG2_AUXPWRSTS 0x10 458120043Swpaul 459120043Swpaul#define RL_BUSFREQ_33MHZ 0x00 460120043Swpaul#define RL_BUSFREQ_66MHZ 0x01 461120043Swpaul 462120043Swpaul#define RL_BUSWIDTH_32BITS 0x00 463120043Swpaul#define RL_BUSWIDTH_64BITS 0x08 464120043Swpaul 465117388Swpaul/* C+ mode command register */ 466117388Swpaul 467117388Swpaul#define RL_CPLUSCMD_TXENB 0x0001 /* enable C+ transmit mode */ 468117388Swpaul#define RL_CPLUSCMD_RXENB 0x0002 /* enable C+ receive mode */ 469117388Swpaul#define RL_CPLUSCMD_PCI_MRW 0x0008 /* enable PCI multi-read/write */ 470117388Swpaul#define RL_CPLUSCMD_PCI_DAC 0x0010 /* PCI dual-address cycle only */ 471117388Swpaul#define RL_CPLUSCMD_RXCSUM_ENB 0x0020 /* enable RX checksum offload */ 472117388Swpaul#define RL_CPLUSCMD_VLANSTRIP 0x0040 /* enable VLAN tag stripping */ 473180176Syongari#define RL_CPLUSCMD_MACSTAT_DIS 0x0080 /* 8168B/C/CP */ 474180176Syongari#define RL_CPLUSCMD_ASF 0x0100 /* 8168C/CP */ 475180176Syongari#define RL_CPLUSCMD_DBG_SEL 0x0200 /* 8168C/CP */ 476180176Syongari#define RL_CPLUSCMD_FORCE_TXFC 0x0400 /* 8168C/CP */ 477180176Syongari#define RL_CPLUSCMD_FORCE_RXFC 0x0800 /* 8168C/CP */ 478180176Syongari#define RL_CPLUSCMD_FORCE_HDPX 0x1000 /* 8168C/CP */ 479180176Syongari#define RL_CPLUSCMD_NORMAL_MODE 0x2000 /* 8168C/CP */ 480180176Syongari#define RL_CPLUSCMD_DBG_ENB 0x4000 /* 8168C/CP */ 481180176Syongari#define RL_CPLUSCMD_BIST_ENB 0x8000 /* 8168C/CP */ 482117388Swpaul 483117388Swpaul/* C+ early transmit threshold */ 484117388Swpaul 485117388Swpaul#define RL_EARLYTXTHRESH_CNT 0x003F /* byte count times 8 */ 486117388Swpaul 487117388Swpaul/* 488117388Swpaul * Gigabit PHY access register (8169 only) 489117388Swpaul */ 490117388Swpaul 491117388Swpaul#define RL_PHYAR_PHYDATA 0x0000FFFF 492117388Swpaul#define RL_PHYAR_PHYREG 0x001F0000 493117388Swpaul#define RL_PHYAR_BUSY 0x80000000 494117388Swpaul 495117388Swpaul/* 496117388Swpaul * Gigabit media status (8169 only) 497117388Swpaul */ 498117388Swpaul#define RL_GMEDIASTAT_FDX 0x01 /* full duplex */ 499117388Swpaul#define RL_GMEDIASTAT_LINK 0x02 /* link up */ 500117388Swpaul#define RL_GMEDIASTAT_10MBPS 0x04 /* 10mps link */ 501117388Swpaul#define RL_GMEDIASTAT_100MBPS 0x08 /* 100mbps link */ 502119976Swpaul#define RL_GMEDIASTAT_1000MBPS 0x10 /* gigE link */ 503117388Swpaul#define RL_GMEDIASTAT_RXFLOW 0x20 /* RX flow control on */ 504117388Swpaul#define RL_GMEDIASTAT_TXFLOW 0x40 /* TX flow control on */ 505117388Swpaul#define RL_GMEDIASTAT_TBI 0x80 /* TBI enabled */ 506117388Swpaul 507117388Swpaul/* 50840516Swpaul * The RealTek doesn't use a fragment-based descriptor mechanism. 50940516Swpaul * Instead, there are only four register sets, each or which represents 51040516Swpaul * one 'descriptor.' Basically, each TX descriptor is just a contiguous 51140516Swpaul * packet buffer (32-bit aligned!) and we place the buffer addresses in 51240516Swpaul * the registers so the chip knows where they are. 51340516Swpaul * 51440516Swpaul * We can sort of kludge together the same kind of buffer management 51540516Swpaul * used in previous drivers, but we have to do buffer copies almost all 51640516Swpaul * the time, so it doesn't really buy us much. 51740516Swpaul * 51840516Swpaul * For reception, there's just one large buffer where the chip stores 51940516Swpaul * all received packets. 52040516Swpaul */ 52140516Swpaul 52240516Swpaul#define RL_RX_BUF_SZ RL_RXBUF_64 52340516Swpaul#define RL_RXBUFLEN (1 << ((RL_RX_BUF_SZ >> 11) + 13)) 52440516Swpaul#define RL_TX_LIST_CNT 4 52540516Swpaul#define RL_MIN_FRAMELEN 60 526184240Syongari#define RL_TX_8139_BUF_ALIGN 4 527184240Syongari#define RL_RX_8139_BUF_ALIGN 8 528184240Syongari#define RL_RX_8139_BUF_RESERVE sizeof(int64_t) 529184240Syongari#define RL_RX_8139_BUF_GUARD_SZ \ 530184240Syongari (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN + RL_RX_8139_BUF_RESERVE) 53152426Swpaul#define RL_TXTHRESH(x) ((x) << 11) 53252426Swpaul#define RL_TX_THRESH_INIT 96 533119868Swpaul#define RL_RX_FIFOTHRESH RL_RXFIFO_NOTHRESH 534119868Swpaul#define RL_RX_MAXDMA RL_RXDMA_UNLIMITED 53550703Swpaul#define RL_TX_MAXDMA RL_TXDMA_2048BYTES 53640516Swpaul 53745633Swpaul#define RL_RXCFG_CONFIG (RL_RX_FIFOTHRESH|RL_RX_MAXDMA|RL_RX_BUF_SZ) 53845633Swpaul#define RL_TXCFG_CONFIG (RL_TXCFG_IFG|RL_TX_MAXDMA) 53940516Swpaul 54048028Swpaul#define RL_ETHER_ALIGN 2 54148028Swpaul 542177771Syongari/* 543177771Syongari * re(4) hardware ip4csum-tx could be mangled with 28 bytes or less IP packets. 544177771Syongari */ 545177771Syongari#define RL_IP4CSUMTX_MINLEN 28 546177771Syongari#define RL_IP4CSUMTX_PADLEN (ETHER_HDR_LEN + RL_IP4CSUMTX_MINLEN) 547177771Syongari 54840516Swpaulstruct rl_chain_data { 549131605Sbms uint16_t cur_rx; 550131605Sbms uint8_t *rl_rx_buf; 551131605Sbms uint8_t *rl_rx_buf_ptr; 55240516Swpaul 55345633Swpaul struct mbuf *rl_tx_chain[RL_TX_LIST_CNT]; 55481713Swpaul bus_dmamap_t rl_tx_dmamap[RL_TX_LIST_CNT]; 555184240Syongari bus_dma_tag_t rl_tx_tag; 556184240Syongari bus_dma_tag_t rl_rx_tag; 557184240Syongari bus_dmamap_t rl_rx_dmamap; 558184240Syongari bus_addr_t rl_rx_buf_paddr; 559131605Sbms uint8_t last_tx; 560131605Sbms uint8_t cur_tx; 56140516Swpaul}; 56240516Swpaul 56345633Swpaul#define RL_INC(x) (x = (x + 1) % RL_TX_LIST_CNT) 56445633Swpaul#define RL_CUR_TXADDR(x) ((x->rl_cdata.cur_tx * 4) + RL_TXADDR0) 56545633Swpaul#define RL_CUR_TXSTAT(x) ((x->rl_cdata.cur_tx * 4) + RL_TXSTAT0) 56645633Swpaul#define RL_CUR_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.cur_tx]) 56781713Swpaul#define RL_CUR_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.cur_tx]) 56845633Swpaul#define RL_LAST_TXADDR(x) ((x->rl_cdata.last_tx * 4) + RL_TXADDR0) 56945633Swpaul#define RL_LAST_TXSTAT(x) ((x->rl_cdata.last_tx * 4) + RL_TXSTAT0) 57045633Swpaul#define RL_LAST_TXMBUF(x) (x->rl_cdata.rl_tx_chain[x->rl_cdata.last_tx]) 57181713Swpaul#define RL_LAST_DMAMAP(x) (x->rl_cdata.rl_tx_dmamap[x->rl_cdata.last_tx]) 57245633Swpaul 57340516Swpaulstruct rl_type { 574131605Sbms uint16_t rl_vid; 575131605Sbms uint16_t rl_did; 576117388Swpaul int rl_basetype; 57740516Swpaul char *rl_name; 57840516Swpaul}; 57940516Swpaul 580117388Swpaulstruct rl_hwrev { 581131605Sbms uint32_t rl_rev; 582117388Swpaul int rl_type; 583117388Swpaul char *rl_desc; 584117388Swpaul}; 585117388Swpaul 58640516Swpaulstruct rl_mii_frame { 587131605Sbms uint8_t mii_stdelim; 588131605Sbms uint8_t mii_opcode; 589131605Sbms uint8_t mii_phyaddr; 590131605Sbms uint8_t mii_regaddr; 591131605Sbms uint8_t mii_turnaround; 592131605Sbms uint16_t mii_data; 59340516Swpaul}; 59440516Swpaul 59540516Swpaul/* 59640516Swpaul * MII constants 59740516Swpaul */ 59840516Swpaul#define RL_MII_STARTDELIM 0x01 59940516Swpaul#define RL_MII_READOP 0x02 60040516Swpaul#define RL_MII_WRITEOP 0x01 60140516Swpaul#define RL_MII_TURNAROUND 0x02 60240516Swpaul 60340516Swpaul#define RL_8129 1 60440516Swpaul#define RL_8139 2 605117388Swpaul#define RL_8139CPLUS 3 606117388Swpaul#define RL_8169 4 60740516Swpaul 608117388Swpaul#define RL_ISCPLUS(x) ((x)->rl_type == RL_8139CPLUS || \ 609117388Swpaul (x)->rl_type == RL_8169) 610117388Swpaul 611117388Swpaul/* 612117388Swpaul * The 8139C+ and 8160 gigE chips support descriptor-based TX 613117388Swpaul * and RX. In fact, they even support TCP large send. Descriptors 614117388Swpaul * must be allocated in contiguous blocks that are aligned on a 615117388Swpaul * 256-byte boundary. The rings can hold a maximum of 64 descriptors. 616117388Swpaul */ 617117388Swpaul 618117388Swpaul/* 619117388Swpaul * RX/TX descriptor definition. When large send mode is enabled, the 620117388Swpaul * lower 11 bits of the TX rl_cmd word are used to hold the MSS, and 621117388Swpaul * the checksum offload bits are disabled. The structure layout is 622117388Swpaul * the same for RX and TX descriptors 623117388Swpaul */ 624117388Swpaul 625117388Swpaulstruct rl_desc { 626131605Sbms uint32_t rl_cmdstat; 627131605Sbms uint32_t rl_vlanctl; 628131605Sbms uint32_t rl_bufaddr_lo; 629131605Sbms uint32_t rl_bufaddr_hi; 630117388Swpaul}; 631117388Swpaul 632117388Swpaul#define RL_TDESC_CMD_FRAGLEN 0x0000FFFF 633117388Swpaul#define RL_TDESC_CMD_TCPCSUM 0x00010000 /* TCP checksum enable */ 634117388Swpaul#define RL_TDESC_CMD_UDPCSUM 0x00020000 /* UDP checksum enable */ 635117388Swpaul#define RL_TDESC_CMD_IPCSUM 0x00040000 /* IP header checksum enable */ 636117388Swpaul#define RL_TDESC_CMD_MSSVAL 0x07FF0000 /* Large send MSS value */ 637164463Syongari#define RL_TDESC_CMD_MSSVAL_SHIFT 16 /* Large send MSS value shift */ 638117388Swpaul#define RL_TDESC_CMD_LGSEND 0x08000000 /* TCP large send enb */ 639117388Swpaul#define RL_TDESC_CMD_EOF 0x10000000 /* end of frame marker */ 640117388Swpaul#define RL_TDESC_CMD_SOF 0x20000000 /* start of frame marker */ 641117388Swpaul#define RL_TDESC_CMD_EOR 0x40000000 /* end of ring marker */ 642117388Swpaul#define RL_TDESC_CMD_OWN 0x80000000 /* chip owns descriptor */ 643117388Swpaul 644117388Swpaul#define RL_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */ 645117388Swpaul#define RL_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */ 646180176Syongari/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */ 647180176Syongari#define RL_TDESC_CMD_UDPCSUMV2 0x80000000 648180176Syongari#define RL_TDESC_CMD_TCPCSUMV2 0x40000000 649180176Syongari#define RL_TDESC_CMD_IPCSUMV2 0x20000000 650117388Swpaul 651117388Swpaul/* 652117388Swpaul * Error bits are valid only on the last descriptor of a frame 653117388Swpaul * (i.e. RL_TDESC_CMD_EOF == 1) 654117388Swpaul */ 655117388Swpaul 656117388Swpaul#define RL_TDESC_STAT_COLCNT 0x000F0000 /* collision count */ 657117388Swpaul#define RL_TDESC_STAT_EXCESSCOL 0x00100000 /* excessive collisions */ 658117388Swpaul#define RL_TDESC_STAT_LINKFAIL 0x00200000 /* link faulure */ 659117388Swpaul#define RL_TDESC_STAT_OWINCOL 0x00400000 /* out-of-window collision */ 660117388Swpaul#define RL_TDESC_STAT_TXERRSUM 0x00800000 /* transmit error summary */ 661117388Swpaul#define RL_TDESC_STAT_UNDERRUN 0x02000000 /* TX underrun occured */ 662117388Swpaul#define RL_TDESC_STAT_OWN 0x80000000 663117388Swpaul 664117388Swpaul/* 665117388Swpaul * RX descriptor cmd/vlan definitions 666117388Swpaul */ 667117388Swpaul 668117388Swpaul#define RL_RDESC_CMD_EOR 0x40000000 669117388Swpaul#define RL_RDESC_CMD_OWN 0x80000000 670119981Swpaul#define RL_RDESC_CMD_BUFLEN 0x00001FFF 671117388Swpaul 672117388Swpaul#define RL_RDESC_STAT_OWN 0x80000000 673117388Swpaul#define RL_RDESC_STAT_EOR 0x40000000 674117388Swpaul#define RL_RDESC_STAT_SOF 0x20000000 675117388Swpaul#define RL_RDESC_STAT_EOF 0x10000000 676117388Swpaul#define RL_RDESC_STAT_FRALIGN 0x08000000 /* frame alignment error */ 677117388Swpaul#define RL_RDESC_STAT_MCAST 0x04000000 /* multicast pkt received */ 678117388Swpaul#define RL_RDESC_STAT_UCAST 0x02000000 /* unicast pkt received */ 679117388Swpaul#define RL_RDESC_STAT_BCAST 0x01000000 /* broadcast pkt received */ 680117388Swpaul#define RL_RDESC_STAT_BUFOFLOW 0x00800000 /* out of buffer space */ 681117388Swpaul#define RL_RDESC_STAT_FIFOOFLOW 0x00400000 /* FIFO overrun */ 682117388Swpaul#define RL_RDESC_STAT_GIANT 0x00200000 /* pkt > 4096 bytes */ 683117388Swpaul#define RL_RDESC_STAT_RXERRSUM 0x00100000 /* RX error summary */ 684117388Swpaul#define RL_RDESC_STAT_RUNT 0x00080000 /* runt packet received */ 685117388Swpaul#define RL_RDESC_STAT_CRCERR 0x00040000 /* CRC error */ 686117388Swpaul#define RL_RDESC_STAT_PROTOID 0x00030000 /* Protocol type */ 687180176Syongari#define RL_RDESC_STAT_UDP 0x00020000 /* UDP, 8168C/CP, 8111C/CP */ 688180176Syongari#define RL_RDESC_STAT_TCP 0x00010000 /* TCP, 8168C/CP, 8111C/CP */ 689117388Swpaul#define RL_RDESC_STAT_IPSUMBAD 0x00008000 /* IP header checksum bad */ 690117388Swpaul#define RL_RDESC_STAT_UDPSUMBAD 0x00004000 /* UDP checksum bad */ 691117388Swpaul#define RL_RDESC_STAT_TCPSUMBAD 0x00002000 /* TCP checksum bad */ 692119981Swpaul#define RL_RDESC_STAT_FRAGLEN 0x00001FFF /* RX'ed frame/frag len */ 693119981Swpaul#define RL_RDESC_STAT_GFRAGLEN 0x00003FFF /* RX'ed frame/frag len */ 694135896Sjmg#define RL_RDESC_STAT_ERRS (RL_RDESC_STAT_GIANT|RL_RDESC_STAT_RUNT| \ 695135896Sjmg RL_RDESC_STAT_CRCERR) 696117388Swpaul 697117388Swpaul#define RL_RDESC_VLANCTL_TAG 0x00010000 /* VLAN tag available 698117388Swpaul (rl_vlandata valid)*/ 699117388Swpaul#define RL_RDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */ 700180176Syongari/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */ 701180176Syongari#define RL_RDESC_IPV6 0x80000000 702180176Syongari#define RL_RDESC_IPV4 0x40000000 703117388Swpaul 704117388Swpaul#define RL_PROTOID_NONIP 0x00000000 705117388Swpaul#define RL_PROTOID_TCPIP 0x00010000 706117388Swpaul#define RL_PROTOID_UDPIP 0x00020000 707117388Swpaul#define RL_PROTOID_IP 0x00030000 708117388Swpaul#define RL_TCPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \ 709117388Swpaul RL_PROTOID_TCPIP) 710117388Swpaul#define RL_UDPPKT(x) (((x) & RL_RDESC_STAT_PROTOID) == \ 711117388Swpaul RL_PROTOID_UDPIP) 712117388Swpaul 713117388Swpaul/* 714117388Swpaul * Statistics counter structure (8139C+ and 8169 only) 715117388Swpaul */ 716117388Swpaulstruct rl_stats { 717131605Sbms uint32_t rl_tx_pkts_lo; 718131605Sbms uint32_t rl_tx_pkts_hi; 719131605Sbms uint32_t rl_tx_errs_lo; 720131605Sbms uint32_t rl_tx_errs_hi; 721131605Sbms uint32_t rl_tx_errs; 722131605Sbms uint16_t rl_missed_pkts; 723131605Sbms uint16_t rl_rx_framealign_errs; 724131605Sbms uint32_t rl_tx_onecoll; 725131605Sbms uint32_t rl_tx_multicolls; 726131605Sbms uint32_t rl_rx_ucasts_hi; 727131605Sbms uint32_t rl_rx_ucasts_lo; 728131605Sbms uint32_t rl_rx_bcasts_lo; 729131605Sbms uint32_t rl_rx_bcasts_hi; 730131605Sbms uint32_t rl_rx_mcasts; 731131605Sbms uint16_t rl_tx_aborts; 732131605Sbms uint16_t rl_rx_underruns; 733117388Swpaul}; 734117388Swpaul 735135467Sjmg/* 736135467Sjmg * Rx/Tx descriptor parameters (8139C+ and 8169 only) 737135467Sjmg * 738175337Syongari * 8139C+ 739175337Syongari * Number of descriptors supported : up to 64 740175337Syongari * Descriptor alignment : 256 bytes 741175337Syongari * Tx buffer : At least 4 bytes in length. 742175337Syongari * Rx buffer : At least 8 bytes in length and 8 bytes alignment required. 743175337Syongari * 744175337Syongari * 8169 745175337Syongari * Number of descriptors supported : up to 1024 746175337Syongari * Descriptor alignment : 256 bytes 747175337Syongari * Tx buffer : At least 4 bytes in length. 748175337Syongari * Rx buffer : At least 8 bytes in length and 8 bytes alignment required. 749135467Sjmg */ 750164460Syongari#ifndef __NO_STRICT_ALIGNMENT 751135896Sjmg#define RE_FIXUP_RX 1 752135896Sjmg#endif 753135896Sjmg 754175337Syongari#define RL_8169_TX_DESC_CNT 256 755175337Syongari#define RL_8169_RX_DESC_CNT 256 756175337Syongari#define RL_8139_TX_DESC_CNT 64 757175337Syongari#define RL_8139_RX_DESC_CNT 64 758175337Syongari#define RL_TX_DESC_CNT RL_8169_TX_DESC_CNT 759175337Syongari#define RL_RX_DESC_CNT RL_8169_RX_DESC_CNT 760175337Syongari#define RL_NTXSEGS 32 761159962Swpaul 762117388Swpaul#define RL_RING_ALIGN 256 763117388Swpaul#define RL_IFQ_MAXLEN 512 764175337Syongari#define RL_TX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1)) 765175337Syongari#define RL_TX_DESC_PRV(sc,x) ((x - 1) & ((sc)->rl_ldata.rl_tx_desc_cnt - 1)) 766175337Syongari#define RL_RX_DESC_NXT(sc,x) ((x + 1) & ((sc)->rl_ldata.rl_rx_desc_cnt - 1)) 767117388Swpaul#define RL_OWN(x) (le32toh((x)->rl_cmdstat) & RL_RDESC_STAT_OWN) 768119981Swpaul#define RL_RXBYTES(x) (le32toh((x)->rl_cmdstat) & sc->rl_rxlenmask) 769119868Swpaul#define RL_PKTSZ(x) ((x)/* >> 3*/) 770135896Sjmg#ifdef RE_FIXUP_RX 771135896Sjmg#define RE_ETHER_ALIGN sizeof(uint64_t) 772135896Sjmg#define RE_RX_DESC_BUFLEN (MCLBYTES - RE_ETHER_ALIGN) 773135896Sjmg#else 774135896Sjmg#define RE_ETHER_ALIGN 0 775135896Sjmg#define RE_RX_DESC_BUFLEN MCLBYTES 776135896Sjmg#endif 777117388Swpaul 778171560Syongari#define RL_MSI_MESSAGES 2 779171560Syongari 780135467Sjmg#define RL_ADDR_LO(y) ((uint64_t) (y) & 0xFFFFFFFF) 781135467Sjmg#define RL_ADDR_HI(y) ((uint64_t) (y) >> 32) 782118712Swpaul 783181270Syongari/* 784181270Syongari * The number of bits reserved for MSS in RealTek controllers is 785181270Syongari * 11bits. This limits the maximum interface MTU size in TSO case 786181270Syongari * as upper stack should not generate TCP segments with MSS greater 787181270Syongari * than the limit. 788181270Syongari */ 789181270Syongari#define RL_TSO_MTU (2047 - ETHER_HDR_LEN - ETHER_CRC_LEN) 790181270Syongari 791135896Sjmg/* see comment in dev/re/if_re.c */ 792135896Sjmg#define RL_JUMBO_FRAMELEN 7440 793119868Swpaul#define RL_JUMBO_MTU (RL_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN) 794176756Syongari#define RL_MAX_FRAMELEN \ 795176756Syongari (ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) 796119868Swpaul 797175337Syongaristruct rl_txdesc { 798175337Syongari struct mbuf *tx_m; 799175337Syongari bus_dmamap_t tx_dmamap; 800175337Syongari}; 801117388Swpaul 802175337Syongaristruct rl_rxdesc { 803175337Syongari struct mbuf *rx_m; 804175337Syongari bus_dmamap_t rx_dmamap; 805175337Syongari bus_size_t rx_size; 806117388Swpaul}; 807117388Swpaul 808117388Swpaulstruct rl_list_data { 809175337Syongari struct rl_txdesc rl_tx_desc[RL_TX_DESC_CNT]; 810175337Syongari struct rl_rxdesc rl_rx_desc[RL_RX_DESC_CNT]; 811175337Syongari int rl_tx_desc_cnt; 812175337Syongari int rl_rx_desc_cnt; 813117388Swpaul int rl_tx_prodidx; 814117388Swpaul int rl_rx_prodidx; 815117388Swpaul int rl_tx_considx; 816117388Swpaul int rl_tx_free; 817175337Syongari bus_dma_tag_t rl_tx_mtag; /* mbuf TX mapping tag */ 818175337Syongari bus_dma_tag_t rl_rx_mtag; /* mbuf RX mapping tag */ 819175337Syongari bus_dmamap_t rl_rx_sparemap; 820117388Swpaul bus_dma_tag_t rl_stag; /* stats mapping tag */ 821117388Swpaul bus_dmamap_t rl_smap; /* stats map */ 822117388Swpaul struct rl_stats *rl_stats; 823118712Swpaul bus_addr_t rl_stats_addr; 824117388Swpaul bus_dma_tag_t rl_rx_list_tag; 825117388Swpaul bus_dmamap_t rl_rx_list_map; 826117388Swpaul struct rl_desc *rl_rx_list; 827118712Swpaul bus_addr_t rl_rx_list_addr; 828117388Swpaul bus_dma_tag_t rl_tx_list_tag; 829117388Swpaul bus_dmamap_t rl_tx_list_map; 830117388Swpaul struct rl_desc *rl_tx_list; 831118712Swpaul bus_addr_t rl_tx_list_addr; 832117388Swpaul}; 833117388Swpaul 834184515Simpenum rl_twist { DONE, CHK_LINK, FIND_ROW, SET_PARAM, RECHK_LONG, RETUNE }; 835184515Simp 83640516Swpaulstruct rl_softc { 837147256Sbrooks struct ifnet *rl_ifp; /* interface info */ 83841569Swpaul bus_space_handle_t rl_bhandle; /* bus space handle */ 83941569Swpaul bus_space_tag_t rl_btag; /* bus space tag */ 840159962Swpaul device_t rl_dev; 84150703Swpaul struct resource *rl_res; 842180169Syongari int rl_res_id; 843180169Syongari int rl_res_type; 844171560Syongari struct resource *rl_irq[RL_MSI_MESSAGES]; 845171560Syongari void *rl_intrhand[RL_MSI_MESSAGES]; 84650703Swpaul device_t rl_miibus; 84781713Swpaul bus_dma_tag_t rl_parent_tag; 848131605Sbms uint8_t rl_type; 84967931Swpaul int rl_eecmd_read; 850159962Swpaul int rl_eewidth; 851131605Sbms uint8_t rl_stats_no_timeout; 85252426Swpaul int rl_txthresh; 85340516Swpaul struct rl_chain_data rl_cdata; 854117388Swpaul struct rl_list_data rl_ldata; 855150720Sjhb struct callout rl_stat_callout; 856164811Sru int rl_watchdog_timer; 85767087Swpaul struct mtx rl_mtx; 858119868Swpaul struct mbuf *rl_head; 859119868Swpaul struct mbuf *rl_tail; 860131605Sbms uint32_t rl_hwrev; 861131605Sbms uint32_t rl_rxlenmask; 862119868Swpaul int rl_testmode; 863168828Syongari int rl_if_flags; 864184559Simp int rl_twister_enable; 865184515Simp enum rl_twist rl_twister; 866184515Simp int rl_twist_row; 867184515Simp int rl_twist_col; 86886822Siwasaki int suspended; /* 0 = normal 1 = suspended */ 86994883Sluigi#ifdef DEVICE_POLLING 87094883Sluigi int rxcycles; 87194883Sluigi#endif 872159962Swpaul 873159962Swpaul struct task rl_txtask; 874159962Swpaul struct task rl_inttask; 875159962Swpaul 876159962Swpaul int rl_txstart; 877180171Syongari uint32_t rl_flags; 878180171Syongari#define RL_FLAG_MSI 0x0001 879180171Syongari#define RL_FLAG_INVMAR 0x0004 880180171Syongari#define RL_FLAG_PHYWAKE 0x0008 881180171Syongari#define RL_FLAG_NOJUMBO 0x0010 882180176Syongari#define RL_FLAG_PAR 0x0020 883180176Syongari#define RL_FLAG_DESCV2 0x0040 884180176Syongari#define RL_FLAG_MACSTAT 0x0080 885180171Syongari#define RL_FLAG_LINK 0x8000 88640516Swpaul}; 88740516Swpaul 88872200Sbmilekic#define RL_LOCK(_sc) mtx_lock(&(_sc)->rl_mtx) 88972200Sbmilekic#define RL_UNLOCK(_sc) mtx_unlock(&(_sc)->rl_mtx) 890122689Ssam#define RL_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->rl_mtx, MA_OWNED) 89167087Swpaul 89240516Swpaul/* 89340516Swpaul * register space access macros 89440516Swpaul */ 895119868Swpaul#define CSR_WRITE_STREAM_4(sc, reg, val) \ 896119738Stmm bus_space_write_stream_4(sc->rl_btag, sc->rl_bhandle, reg, val) 89740516Swpaul#define CSR_WRITE_4(sc, reg, val) \ 89841569Swpaul bus_space_write_4(sc->rl_btag, sc->rl_bhandle, reg, val) 89940516Swpaul#define CSR_WRITE_2(sc, reg, val) \ 90041569Swpaul bus_space_write_2(sc->rl_btag, sc->rl_bhandle, reg, val) 90140516Swpaul#define CSR_WRITE_1(sc, reg, val) \ 90241569Swpaul bus_space_write_1(sc->rl_btag, sc->rl_bhandle, reg, val) 90340516Swpaul 90441569Swpaul#define CSR_READ_4(sc, reg) \ 90541569Swpaul bus_space_read_4(sc->rl_btag, sc->rl_bhandle, reg) 90641569Swpaul#define CSR_READ_2(sc, reg) \ 90741569Swpaul bus_space_read_2(sc->rl_btag, sc->rl_bhandle, reg) 90841569Swpaul#define CSR_READ_1(sc, reg) \ 90941569Swpaul bus_space_read_1(sc->rl_btag, sc->rl_bhandle, reg) 91040516Swpaul 911159962Swpaul#define CSR_SETBIT_1(sc, offset, val) \ 912159962Swpaul CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) | (val)) 913159962Swpaul 914159962Swpaul#define CSR_CLRBIT_1(sc, offset, val) \ 915159962Swpaul CSR_WRITE_1(sc, offset, CSR_READ_1(sc, offset) & ~(val)) 916159962Swpaul 917159962Swpaul#define CSR_SETBIT_2(sc, offset, val) \ 918159962Swpaul CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) | (val)) 919159962Swpaul 920159962Swpaul#define CSR_CLRBIT_2(sc, offset, val) \ 921159962Swpaul CSR_WRITE_2(sc, offset, CSR_READ_2(sc, offset) & ~(val)) 922159962Swpaul 923159962Swpaul#define CSR_SETBIT_4(sc, offset, val) \ 924159962Swpaul CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) | (val)) 925159962Swpaul 926159962Swpaul#define CSR_CLRBIT_4(sc, offset, val) \ 927159962Swpaul CSR_WRITE_4(sc, offset, CSR_READ_4(sc, offset) & ~(val)) 928159962Swpaul 92940516Swpaul#define RL_TIMEOUT 1000 93040516Swpaul 93140516Swpaul/* 93240516Swpaul * General constants that are fun to know. 93340516Swpaul * 93440516Swpaul * RealTek PCI vendor ID 93540516Swpaul */ 93640516Swpaul#define RT_VENDORID 0x10EC 93740516Swpaul 93840516Swpaul/* 93940516Swpaul * RealTek chip device IDs. 94040516Swpaul */ 941179831Sremko#define RT_DEVICEID_8139D 0x8039 94240516Swpaul#define RT_DEVICEID_8129 0x8129 943159962Swpaul#define RT_DEVICEID_8101E 0x8136 94467771Swpaul#define RT_DEVICEID_8138 0x8138 94540516Swpaul#define RT_DEVICEID_8139 0x8139 946159962Swpaul#define RT_DEVICEID_8169SC 0x8167 947159962Swpaul#define RT_DEVICEID_8168 0x8168 948117388Swpaul#define RT_DEVICEID_8169 0x8169 949118978Swpaul#define RT_DEVICEID_8100 0x8100 95040516Swpaul 951117388Swpaul#define RT_REVID_8139CPLUS 0x20 952117388Swpaul 95340516Swpaul/* 95444238Swpaul * Accton PCI vendor ID 95544238Swpaul */ 95644238Swpaul#define ACCTON_VENDORID 0x1113 95744238Swpaul 95844238Swpaul/* 95941243Swpaul * Accton MPX 5030/5038 device ID. 96041243Swpaul */ 96141243Swpaul#define ACCTON_DEVICEID_5030 0x1211 96241243Swpaul 96341243Swpaul/* 96494400Swpaul * Nortel PCI vendor ID 96594400Swpaul */ 96694400Swpaul#define NORTEL_VENDORID 0x126C 96794400Swpaul 96894400Swpaul/* 96944238Swpaul * Delta Electronics Vendor ID. 97044238Swpaul */ 97144238Swpaul#define DELTA_VENDORID 0x1500 97244238Swpaul 97344238Swpaul/* 97444238Swpaul * Delta device IDs. 97544238Swpaul */ 97644238Swpaul#define DELTA_DEVICEID_8139 0x1360 97744238Swpaul 97844238Swpaul/* 97944238Swpaul * Addtron vendor ID. 98044238Swpaul */ 98144238Swpaul#define ADDTRON_VENDORID 0x4033 98244238Swpaul 98344238Swpaul/* 98444238Swpaul * Addtron device IDs. 98544238Swpaul */ 98644238Swpaul#define ADDTRON_DEVICEID_8139 0x1360 98744238Swpaul 98844238Swpaul/* 98972813Swpaul * D-Link vendor ID. 99072813Swpaul */ 99172813Swpaul#define DLINK_VENDORID 0x1186 99272813Swpaul 99372813Swpaul/* 99472813Swpaul * D-Link DFE-530TX+ device ID 99572813Swpaul */ 99672813Swpaul#define DLINK_DEVICEID_530TXPLUS 0x1300 99772813Swpaul 99872813Swpaul/* 999148722Stobez * D-Link DFE-5280T device ID 1000148722Stobez */ 1001148722Stobez#define DLINK_DEVICEID_528T 0x4300 1002148722Stobez 1003148722Stobez/* 100496112Sjhb * D-Link DFE-690TXD device ID 100596112Sjhb */ 100696112Sjhb#define DLINK_DEVICEID_690TXD 0x1340 100796112Sjhb 100896112Sjhb/* 1009103020Siwasaki * Corega K.K vendor ID 1010103020Siwasaki */ 1011103020Siwasaki#define COREGA_VENDORID 0x1259 1012103020Siwasaki 1013103020Siwasaki/* 1014109095Ssanpei * Corega FEther CB-TXD device ID 1015103020Siwasaki */ 1016151341Sjhb#define COREGA_DEVICEID_FETHERCBTXD 0xa117 1017103020Siwasaki 1018103020Siwasaki/* 1019109095Ssanpei * Corega FEtherII CB-TXD device ID 1020109095Ssanpei */ 1021151341Sjhb#define COREGA_DEVICEID_FETHERIICBTXD 0xa11e 1022109095Ssanpei 1023111381Sdan/* 1024134433Ssanpei * Corega CG-LAPCIGT device ID 1025134433Ssanpei */ 1026134433Ssanpei#define COREGA_DEVICEID_CGLAPCIGT 0xc107 1027134433Ssanpei 1028134433Ssanpei/* 1029151341Sjhb * Linksys vendor ID 1030151341Sjhb */ 1031151341Sjhb#define LINKSYS_VENDORID 0x1737 1032151341Sjhb 1033151341Sjhb/* 1034151341Sjhb * Linksys EG1032 device ID 1035151341Sjhb */ 1036151341Sjhb#define LINKSYS_DEVICEID_EG1032 0x1032 1037151341Sjhb 1038151341Sjhb/* 1039151341Sjhb * Linksys EG1032 rev 3 sub-device ID 1040151341Sjhb */ 1041151341Sjhb#define LINKSYS_SUBDEVICE_EG1032_REV3 0x0024 1042151341Sjhb 1043151341Sjhb/* 1044111381Sdan * Peppercon vendor ID 1045111381Sdan */ 1046111381Sdan#define PEPPERCON_VENDORID 0x1743 1047109095Ssanpei 1048111381Sdan/* 1049111381Sdan * Peppercon ROL-F device ID 1050111381Sdan */ 1051111381Sdan#define PEPPERCON_DEVICEID_ROLF 0x8139 1052109095Ssanpei 1053109095Ssanpei/* 1054112379Ssanpei * Planex Communications, Inc. vendor ID 1055112379Ssanpei */ 1056117388Swpaul#define PLANEX_VENDORID 0x14ea 1057112379Ssanpei 1058112379Ssanpei/* 1059173948Sremko * Planex FNW-3603-TX device ID 1060173948Sremko */ 1061173948Sremko#define PLANEX_DEVICEID_FNW3603TX 0xab06 1062173948Sremko 1063173948Sremko/* 1064112379Ssanpei * Planex FNW-3800-TX device ID 1065112379Ssanpei */ 1066117388Swpaul#define PLANEX_DEVICEID_FNW3800TX 0xab07 1067112379Ssanpei 1068112379Ssanpei/* 1069117388Swpaul * LevelOne vendor ID 1070117388Swpaul */ 1071117388Swpaul#define LEVEL1_VENDORID 0x018A 1072117388Swpaul 1073117388Swpaul/* 1074117388Swpaul * LevelOne FPC-0106TX devide ID 1075117388Swpaul */ 1076117388Swpaul#define LEVEL1_DEVICEID_FPC0106TX 0x0106 1077117388Swpaul 1078117388Swpaul/* 1079117388Swpaul * Compaq vendor ID 1080117388Swpaul */ 1081117388Swpaul#define CP_VENDORID 0x021B 1082117388Swpaul 1083117388Swpaul/* 1084117388Swpaul * Edimax vendor ID 1085117388Swpaul */ 1086117388Swpaul#define EDIMAX_VENDORID 0x13D1 1087117388Swpaul 1088117388Swpaul/* 1089117388Swpaul * Edimax EP-4103DL cardbus device ID 1090117388Swpaul */ 1091117388Swpaul#define EDIMAX_DEVICEID_EP4103DL 0xAB06 1092117388Swpaul 1093160883Swpaul/* US Robotics vendor ID */ 1094160883Swpaul 1095160883Swpaul#define USR_VENDORID 0x16EC 1096160883Swpaul 1097160883Swpaul/* US Robotics 997902 device ID */ 1098160883Swpaul 1099160883Swpaul#define USR_DEVICEID_997902 0x0116 1100160883Swpaul 1101117388Swpaul/* 110240516Swpaul * PCI low memory base and low I/O base register, and 110350703Swpaul * other PCI registers. 110440516Swpaul */ 110540516Swpaul 110640516Swpaul#define RL_PCI_VENDOR_ID 0x00 110740516Swpaul#define RL_PCI_DEVICE_ID 0x02 110840516Swpaul#define RL_PCI_COMMAND 0x04 110940516Swpaul#define RL_PCI_STATUS 0x06 111040516Swpaul#define RL_PCI_CLASSCODE 0x09 111140516Swpaul#define RL_PCI_LATENCY_TIMER 0x0D 111240516Swpaul#define RL_PCI_HEADER_TYPE 0x0E 111340516Swpaul#define RL_PCI_LOIO 0x10 111440516Swpaul#define RL_PCI_LOMEM 0x14 111540516Swpaul#define RL_PCI_BIOSROM 0x30 111640516Swpaul#define RL_PCI_INTLINE 0x3C 111740516Swpaul#define RL_PCI_INTPIN 0x3D 111840516Swpaul#define RL_PCI_MINGNT 0x3E 111940516Swpaul#define RL_PCI_MINLAT 0x0F 112040516Swpaul#define RL_PCI_RESETOPT 0x48 112140516Swpaul#define RL_PCI_EEPROM_DATA 0x4C 112240516Swpaul 112350097Swpaul#define RL_PCI_CAPID 0x50 /* 8 bits */ 112450097Swpaul#define RL_PCI_NEXTPTR 0x51 /* 8 bits */ 112550097Swpaul#define RL_PCI_PWRMGMTCAP 0x52 /* 16 bits */ 112650097Swpaul#define RL_PCI_PWRMGMTCTRL 0x54 /* 16 bits */ 112740516Swpaul 112840516Swpaul#define RL_PSTATE_MASK 0x0003 112940516Swpaul#define RL_PSTATE_D0 0x0000 113040516Swpaul#define RL_PSTATE_D1 0x0002 113140516Swpaul#define RL_PSTATE_D2 0x0002 113240516Swpaul#define RL_PSTATE_D3 0x0003 113340516Swpaul#define RL_PME_EN 0x0010 113440516Swpaul#define RL_PME_STATUS 0x8000 1135