You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

r8169.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Copyright (c) 2008 Marty Connor <mdc@etherboot.org>
  3. * Copyright (c) 2008 Entity Cyber, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *
  19. * This driver is based on rtl8169 data sheets and work by:
  20. *
  21. * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
  22. * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
  23. * Copyright (c) a lot of people too. Please respect their work.
  24. *
  25. */
  26. #ifndef _R8169_H_
  27. #define _R8169_H_
  28. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  29. /** FIXME: include/linux/pci_regs.h has these PCI regs, maybe
  30. we need such a file in gPXE?
  31. **/
  32. #define PCI_EXP_DEVCTL 8 /* Device Control */
  33. #define PCI_EXP_DEVCTL_READRQ 0x7000 /* Max_Read_Request_Size */
  34. #define PCI_EXP_LNKCTL 16 /* Link Control */
  35. #define PCI_EXP_LNKCTL_CLKREQ_EN 0x100 /* Enable clkreq */
  36. #define PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800 /* Enable No Snoop */
  37. /** FIXME: update mii.h in src/include/mii.h from Linux sources
  38. so we don't have to include these definitiions.
  39. **/
  40. /* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
  41. #define SPEED_10 10
  42. #define SPEED_100 100
  43. #define SPEED_1000 1000
  44. #define SPEED_2500 2500
  45. #define SPEED_10000 10000
  46. /* Duplex, half or full. */
  47. #define DUPLEX_HALF 0x00
  48. #define DUPLEX_FULL 0x01
  49. /* Generic MII registers. */
  50. #define MII_BMCR 0x00 /* Basic mode control register */
  51. #define MII_BMSR 0x01 /* Basic mode status register */
  52. #define MII_PHYSID1 0x02 /* PHYS ID 1 */
  53. #define MII_PHYSID2 0x03 /* PHYS ID 2 */
  54. #define MII_ADVERTISE 0x04 /* Advertisement control reg */
  55. #define MII_LPA 0x05 /* Link partner ability reg */
  56. #define MII_EXPANSION 0x06 /* Expansion register */
  57. #define MII_CTRL1000 0x09 /* 1000BASE-T control */
  58. #define MII_STAT1000 0x0a /* 1000BASE-T status */
  59. #define MII_ESTATUS 0x0f /* Extended Status */
  60. #define MII_DCOUNTER 0x12 /* Disconnect counter */
  61. #define MII_FCSCOUNTER 0x13 /* False carrier counter */
  62. #define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
  63. #define MII_RERRCOUNTER 0x15 /* Receive error counter */
  64. #define MII_SREVISION 0x16 /* Silicon revision */
  65. #define MII_RESV1 0x17 /* Reserved... */
  66. #define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
  67. #define MII_PHYADDR 0x19 /* PHY address */
  68. #define MII_RESV2 0x1a /* Reserved... */
  69. #define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
  70. #define MII_NCONFIG 0x1c /* Network interface config */
  71. /* Basic mode control register. */
  72. #define BMCR_RESV 0x003f /* Unused... */
  73. #define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
  74. #define BMCR_CTST 0x0080 /* Collision test */
  75. #define BMCR_FULLDPLX 0x0100 /* Full duplex */
  76. #define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
  77. #define BMCR_ISOLATE 0x0400 /* Disconnect DP83840 from MII */
  78. #define BMCR_PDOWN 0x0800 /* Powerdown the DP83840 */
  79. #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
  80. #define BMCR_SPEED100 0x2000 /* Select 100Mbps */
  81. #define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
  82. #define BMCR_RESET 0x8000 /* Reset the DP83840 */
  83. /* Basic mode status register. */
  84. #define BMSR_ERCAP 0x0001 /* Ext-reg capability */
  85. #define BMSR_JCD 0x0002 /* Jabber detected */
  86. #define BMSR_LSTATUS 0x0004 /* Link status */
  87. #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
  88. #define BMSR_RFAULT 0x0010 /* Remote fault detected */
  89. #define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
  90. #define BMSR_RESV 0x00c0 /* Unused... */
  91. #define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
  92. #define BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */
  93. #define BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */
  94. #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
  95. #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
  96. #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
  97. #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
  98. #define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
  99. #define AUTONEG_DISABLE 0x00
  100. #define AUTONEG_ENABLE 0x01
  101. #define MII_ADVERTISE 0x04 /* Advertisement control reg */
  102. #define ADVERTISE_SLCT 0x001f /* Selector bits */
  103. #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
  104. #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
  105. #define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
  106. #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
  107. #define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
  108. #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
  109. #define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
  110. #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
  111. #define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
  112. #define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
  113. #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
  114. #define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */
  115. #define ADVERTISE_RESV 0x1000 /* Unused... */
  116. #define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
  117. #define ADVERTISE_LPACK 0x4000 /* Ack link partners response */
  118. #define ADVERTISE_NPAGE 0x8000 /* Next page bit */
  119. #define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
  120. ADVERTISE_CSMA)
  121. #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  122. ADVERTISE_100HALF | ADVERTISE_100FULL)
  123. /* 1000BASE-T Control register */
  124. #define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
  125. #define ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */
  126. /* MAC address length */
  127. #define MAC_ADDR_LEN 6
  128. #define MAX_READ_REQUEST_SHIFT 12
  129. #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
  130. #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  131. #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
  132. #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */
  133. #define RxPacketMaxSize 0x3FE8 /* 16K - 1 - ETH_HLEN - VLAN - CRC... */
  134. #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */
  135. #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
  136. #define R8169_REGS_SIZE 256
  137. #define R8169_NAPI_WEIGHT 64
  138. #define NUM_TX_DESC 8 /* Number of Tx descriptor registers */
  139. #define NUM_RX_DESC 8 /* Number of Rx descriptor registers */
  140. #define RX_BUF_SIZE 1536 /* Rx Buffer size */
  141. #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
  142. #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
  143. #define TX_RING_ALIGN 256
  144. #define RX_RING_ALIGN 256
  145. #define RTL8169_TX_TIMEOUT (6*HZ)
  146. #define RTL8169_PHY_TIMEOUT (10*HZ)
  147. #define RTL_EEPROM_SIG cpu_to_le32(0x8129)
  148. #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff)
  149. #define RTL_EEPROM_SIG_ADDR 0x0000
  150. /* write/read MMIO register */
  151. #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
  152. #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
  153. #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
  154. #define RTL_R8(reg) readb (ioaddr + (reg))
  155. #define RTL_R16(reg) readw (ioaddr + (reg))
  156. #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
  157. enum mac_version {
  158. RTL_GIGA_MAC_VER_01 = 0x01, // 8169
  159. RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
  160. RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
  161. RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB
  162. RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd
  163. RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe
  164. RTL_GIGA_MAC_VER_07 = 0x07, // 8102e
  165. RTL_GIGA_MAC_VER_08 = 0x08, // 8102e
  166. RTL_GIGA_MAC_VER_09 = 0x09, // 8102e
  167. RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e
  168. RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb
  169. RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be
  170. RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb
  171. RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ?
  172. RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ?
  173. RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec
  174. RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf
  175. RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP
  176. RTL_GIGA_MAC_VER_19 = 0x13, // 8168C
  177. RTL_GIGA_MAC_VER_20 = 0x14, // 8168C
  178. RTL_GIGA_MAC_VER_21 = 0x15, // 8168C
  179. RTL_GIGA_MAC_VER_22 = 0x16, // 8168C
  180. RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP
  181. RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP
  182. RTL_GIGA_MAC_VER_25 = 0x19, // 8168D
  183. };
  184. #define _R(NAME,MAC,MASK) \
  185. { .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
  186. static const struct {
  187. const char *name;
  188. u8 mac_version;
  189. u32 RxConfigMask; /* Clears the bits supported by this chip */
  190. } rtl_chip_info[] = {
  191. _R("RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880), // 8169
  192. _R("RTL8169s", RTL_GIGA_MAC_VER_02, 0xff7e1880), // 8169S
  193. _R("RTL8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880), // 8110S
  194. _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880), // 8169SB
  195. _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, 0xff7e1880), // 8110SCd
  196. _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_06, 0xff7e1880), // 8110SCe
  197. _R("RTL8102e", RTL_GIGA_MAC_VER_07, 0xff7e1880), // PCI-E
  198. _R("RTL8102e", RTL_GIGA_MAC_VER_08, 0xff7e1880), // PCI-E
  199. _R("RTL8102e", RTL_GIGA_MAC_VER_09, 0xff7e1880), // PCI-E
  200. _R("RTL8101e", RTL_GIGA_MAC_VER_10, 0xff7e1880), // PCI-E
  201. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E
  202. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E
  203. _R("RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139
  204. _R("RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139
  205. _R("RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880), // PCI-E 8139
  206. _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_17, 0xff7e1880), // PCI-E
  207. _R("RTL8101e", RTL_GIGA_MAC_VER_16, 0xff7e1880), // PCI-E
  208. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, 0xff7e1880), // PCI-E
  209. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_19, 0xff7e1880), // PCI-E
  210. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_20, 0xff7e1880), // PCI-E
  211. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_21, 0xff7e1880), // PCI-E
  212. _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E
  213. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E
  214. _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E
  215. _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880) // PCI-E
  216. };
  217. #undef _R
  218. enum cfg_version {
  219. RTL_CFG_0 = 0x00,
  220. RTL_CFG_1,
  221. RTL_CFG_2
  222. };
  223. #if 0
  224. /** Device Table from Linux Driver **/
  225. static struct pci_device_id rtl8169_pci_tbl[] = {
  226. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
  227. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
  228. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
  229. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
  230. { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
  231. { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 },
  232. { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 },
  233. { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 },
  234. { PCI_VENDOR_ID_LINKSYS, 0x1032,
  235. PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
  236. { 0x0001, 0x8168,
  237. PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
  238. {0,},
  239. };
  240. #endif
  241. enum rtl_registers {
  242. MAC0 = 0, /* Ethernet hardware address. */
  243. MAC4 = 4,
  244. MAR0 = 8, /* Multicast filter. */
  245. CounterAddrLow = 0x10,
  246. CounterAddrHigh = 0x14,
  247. TxDescStartAddrLow = 0x20,
  248. TxDescStartAddrHigh = 0x24,
  249. TxHDescStartAddrLow = 0x28,
  250. TxHDescStartAddrHigh = 0x2c,
  251. FLASH = 0x30,
  252. ERSR = 0x36,
  253. ChipCmd = 0x37,
  254. TxPoll = 0x38,
  255. IntrMask = 0x3c,
  256. IntrStatus = 0x3e,
  257. TxConfig = 0x40,
  258. RxConfig = 0x44,
  259. RxMissed = 0x4c,
  260. Cfg9346 = 0x50,
  261. Config0 = 0x51,
  262. Config1 = 0x52,
  263. Config2 = 0x53,
  264. Config3 = 0x54,
  265. Config4 = 0x55,
  266. Config5 = 0x56,
  267. MultiIntr = 0x5c,
  268. PHYAR = 0x60,
  269. PHYstatus = 0x6c,
  270. RxMaxSize = 0xda,
  271. CPlusCmd = 0xe0,
  272. IntrMitigate = 0xe2,
  273. RxDescAddrLow = 0xe4,
  274. RxDescAddrHigh = 0xe8,
  275. EarlyTxThres = 0xec,
  276. FuncEvent = 0xf0,
  277. FuncEventMask = 0xf4,
  278. FuncPresetState = 0xf8,
  279. FuncForceEvent = 0xfc,
  280. };
  281. enum rtl8110_registers {
  282. TBICSR = 0x64,
  283. TBI_ANAR = 0x68,
  284. TBI_LPAR = 0x6a,
  285. };
  286. enum rtl8168_8101_registers {
  287. CSIDR = 0x64,
  288. CSIAR = 0x68,
  289. #define CSIAR_FLAG 0x80000000
  290. #define CSIAR_WRITE_CMD 0x80000000
  291. #define CSIAR_BYTE_ENABLE 0x0f
  292. #define CSIAR_BYTE_ENABLE_SHIFT 12
  293. #define CSIAR_ADDR_MASK 0x0fff
  294. EPHYAR = 0x80,
  295. #define EPHYAR_FLAG 0x80000000
  296. #define EPHYAR_WRITE_CMD 0x80000000
  297. #define EPHYAR_REG_MASK 0x1f
  298. #define EPHYAR_REG_SHIFT 16
  299. #define EPHYAR_DATA_MASK 0xffff
  300. DBG_REG = 0xd1,
  301. #define FIX_NAK_1 (1 << 4)
  302. #define FIX_NAK_2 (1 << 3)
  303. };
  304. enum rtl_register_content {
  305. /* InterruptStatusBits */
  306. SYSErr = 0x8000,
  307. PCSTimeout = 0x4000,
  308. SWInt = 0x0100,
  309. TxDescUnavail = 0x0080,
  310. RxFIFOOver = 0x0040,
  311. LinkChg = 0x0020,
  312. RxOverflow = 0x0010,
  313. TxErr = 0x0008,
  314. TxOK = 0x0004,
  315. RxErr = 0x0002,
  316. RxOK = 0x0001,
  317. /* RxStatusDesc */
  318. RxFOVF = (1 << 23),
  319. RxRWT = (1 << 22),
  320. RxRES = (1 << 21),
  321. RxRUNT = (1 << 20),
  322. RxCRC = (1 << 19),
  323. /* ChipCmdBits */
  324. CmdReset = 0x10,
  325. CmdRxEnb = 0x08,
  326. CmdTxEnb = 0x04,
  327. RxBufEmpty = 0x01,
  328. /* TXPoll register p.5 */
  329. HPQ = 0x80, /* Poll cmd on the high prio queue */
  330. NPQ = 0x40, /* Poll cmd on the low prio queue */
  331. FSWInt = 0x01, /* Forced software interrupt */
  332. /* Cfg9346Bits */
  333. Cfg9346_Lock = 0x00,
  334. Cfg9346_Unlock = 0xc0,
  335. /* rx_mode_bits */
  336. AcceptErr = 0x20,
  337. AcceptRunt = 0x10,
  338. AcceptBroadcast = 0x08,
  339. AcceptMulticast = 0x04,
  340. AcceptMyPhys = 0x02,
  341. AcceptAllPhys = 0x01,
  342. /* RxConfigBits */
  343. RxCfgFIFOShift = 13,
  344. RxCfgDMAShift = 8,
  345. /* TxConfigBits */
  346. TxInterFrameGapShift = 24,
  347. TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
  348. /* Config1 register p.24 */
  349. LEDS1 = (1 << 7),
  350. LEDS0 = (1 << 6),
  351. MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */
  352. Speed_down = (1 << 4),
  353. MEMMAP = (1 << 3),
  354. IOMAP = (1 << 2),
  355. VPD = (1 << 1),
  356. PMEnable = (1 << 0), /* Power Management Enable */
  357. /* Config2 register p. 25 */
  358. PCI_Clock_66MHz = 0x01,
  359. PCI_Clock_33MHz = 0x00,
  360. /* Config3 register p.25 */
  361. MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */
  362. LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
  363. Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */
  364. /* Config5 register p.27 */
  365. BWF = (1 << 6), /* Accept Broadcast wakeup frame */
  366. MWF = (1 << 5), /* Accept Multicast wakeup frame */
  367. UWF = (1 << 4), /* Accept Unicast wakeup frame */
  368. LanWake = (1 << 1), /* LanWake enable/disable */
  369. PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */
  370. /* TBICSR p.28 */
  371. TBIReset = 0x80000000,
  372. TBILoopback = 0x40000000,
  373. TBINwEnable = 0x20000000,
  374. TBINwRestart = 0x10000000,
  375. TBILinkOk = 0x02000000,
  376. TBINwComplete = 0x01000000,
  377. /* CPlusCmd p.31 */
  378. EnableBist = (1 << 15), // 8168 8101
  379. Mac_dbgo_oe = (1 << 14), // 8168 8101
  380. Normal_mode = (1 << 13), // unused
  381. Force_half_dup = (1 << 12), // 8168 8101
  382. Force_rxflow_en = (1 << 11), // 8168 8101
  383. Force_txflow_en = (1 << 10), // 8168 8101
  384. Cxpl_dbg_sel = (1 << 9), // 8168 8101
  385. ASF = (1 << 8), // 8168 8101
  386. PktCntrDisable = (1 << 7), // 8168 8101
  387. Mac_dbgo_sel = 0x001c, // 8168
  388. RxVlan = (1 << 6),
  389. RxChkSum = (1 << 5),
  390. PCIDAC = (1 << 4),
  391. PCIMulRW = (1 << 3),
  392. INTT_0 = 0x0000, // 8168
  393. INTT_1 = 0x0001, // 8168
  394. INTT_2 = 0x0002, // 8168
  395. INTT_3 = 0x0003, // 8168
  396. /* rtl8169_PHYstatus */
  397. TBI_Enable = 0x80,
  398. TxFlowCtrl = 0x40,
  399. RxFlowCtrl = 0x20,
  400. _1000bpsF = 0x10,
  401. _100bps = 0x08,
  402. _10bps = 0x04,
  403. LinkStatus = 0x02,
  404. FullDup = 0x01,
  405. /* _TBICSRBit */
  406. TBILinkOK = 0x02000000,
  407. /* DumpCounterCommand */
  408. CounterDump = 0x8,
  409. };
  410. enum desc_status_bit {
  411. DescOwn = (1 << 31), /* Descriptor is owned by NIC */
  412. RingEnd = (1 << 30), /* End of descriptor ring */
  413. FirstFrag = (1 << 29), /* First segment of a packet */
  414. LastFrag = (1 << 28), /* Final segment of a packet */
  415. /* Tx private */
  416. LargeSend = (1 << 27), /* TCP Large Send Offload (TSO) */
  417. MSSShift = 16, /* MSS value position */
  418. MSSMask = 0xfff, /* MSS value + LargeSend bit: 12 bits */
  419. IPCS = (1 << 18), /* Calculate IP checksum */
  420. UDPCS = (1 << 17), /* Calculate UDP/IP checksum */
  421. TCPCS = (1 << 16), /* Calculate TCP/IP checksum */
  422. TxVlanTag = (1 << 17), /* Add VLAN tag */
  423. /* Rx private */
  424. PID1 = (1 << 18), /* Protocol ID bit 1/2 */
  425. PID0 = (1 << 17), /* Protocol ID bit 2/2 */
  426. #define RxProtoUDP (PID1)
  427. #define RxProtoTCP (PID0)
  428. #define RxProtoIP (PID1 | PID0)
  429. #define RxProtoMask RxProtoIP
  430. IPFail = (1 << 16), /* IP checksum failed */
  431. UDPFail = (1 << 15), /* UDP/IP checksum failed */
  432. TCPFail = (1 << 14), /* TCP/IP checksum failed */
  433. RxVlanTag = (1 << 16), /* VLAN tag available */
  434. };
  435. #define RsvdMask 0x3fffc000
  436. struct TxDesc {
  437. volatile uint32_t opts1;
  438. volatile uint32_t opts2;
  439. volatile uint32_t addr_lo;
  440. volatile uint32_t addr_hi;
  441. };
  442. struct RxDesc {
  443. volatile uint32_t opts1;
  444. volatile uint32_t opts2;
  445. volatile uint32_t addr_lo;
  446. volatile uint32_t addr_hi;
  447. };
  448. enum features {
  449. RTL_FEATURE_WOL = (1 << 0),
  450. RTL_FEATURE_MSI = (1 << 1),
  451. RTL_FEATURE_GMII = (1 << 2),
  452. };
  453. static void rtl_hw_start_8169(struct net_device *);
  454. static void rtl_hw_start_8168(struct net_device *);
  455. static void rtl_hw_start_8101(struct net_device *);
  456. struct rtl8169_private {
  457. struct pci_device *pci_dev;
  458. struct net_device *netdev;
  459. uint8_t *hw_addr;
  460. void *mmio_addr;
  461. uint32_t irqno;
  462. int chipset;
  463. int mac_version;
  464. int cfg_index;
  465. u16 intr_event;
  466. struct io_buffer *tx_iobuf[NUM_TX_DESC];
  467. struct io_buffer *rx_iobuf[NUM_RX_DESC];
  468. struct TxDesc *tx_base;
  469. struct RxDesc *rx_base;
  470. uint32_t tx_curr;
  471. uint32_t rx_curr;
  472. uint32_t tx_tail;
  473. uint32_t tx_fill_ctr;
  474. u16 cp_cmd;
  475. int phy_auto_nego_reg;
  476. int phy_1000_ctrl_reg;
  477. int ( *set_speed ) (struct net_device *, u8 autoneg, u16 speed, u8 duplex );
  478. void ( *phy_reset_enable ) ( void *ioaddr );
  479. void ( *hw_start ) ( struct net_device * );
  480. unsigned int ( *phy_reset_pending ) ( void *ioaddr );
  481. unsigned int ( *link_ok ) ( void *ioaddr );
  482. int pcie_cap;
  483. unsigned features;
  484. };
  485. static const unsigned int rtl8169_rx_config =
  486. (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
  487. #endif /* _R8169_H_ */
  488. /*
  489. * Local variables:
  490. * c-basic-offset: 8
  491. * c-indent-level: 8
  492. * tab-width: 8
  493. * End:
  494. */