00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 FILE_LICENCE ( GPL2_OR_LATER );
00028
00029 #ifndef _R8169_H_
00030 #define _R8169_H_
00031
00032 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
00033
00034
00035
00036
00037 #define PCI_EXP_DEVCTL 8
00038 #define PCI_EXP_DEVCTL_READRQ 0x7000
00039 #define PCI_EXP_LNKCTL 16
00040 #define PCI_EXP_LNKCTL_CLKREQ_EN 0x100
00041 #define PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800
00042
00043
00044
00045
00046
00047 #define SPEED_10 10
00048 #define SPEED_100 100
00049 #define SPEED_1000 1000
00050 #define SPEED_2500 2500
00051 #define SPEED_10000 10000
00052
00053
00054 #define DUPLEX_HALF 0x00
00055 #define DUPLEX_FULL 0x01
00056
00057 #define AUTONEG_DISABLE 0x00
00058 #define AUTONEG_ENABLE 0x01
00059
00060
00061 #define MAC_ADDR_LEN 6
00062
00063 #define MAX_READ_REQUEST_SHIFT 12
00064 #define RX_FIFO_THRESH 7
00065 #define RX_DMA_BURST 6
00066 #define TX_DMA_BURST 6
00067 #define EarlyTxThld 0x3F
00068 #define RxPacketMaxSize 0x3FE8
00069 #define SafeMtu 0x1c20
00070 #define InterFrameGap 0x03
00071
00072 #define R8169_REGS_SIZE 256
00073 #define R8169_NAPI_WEIGHT 64
00074 #define NUM_TX_DESC 8
00075 #define NUM_RX_DESC 8
00076 #define RX_BUF_SIZE 1536
00077 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
00078 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
00079
00080 #define TX_RING_ALIGN 256
00081 #define RX_RING_ALIGN 256
00082
00083 #define RTL8169_TX_TIMEOUT (6*HZ)
00084 #define RTL8169_PHY_TIMEOUT (10*HZ)
00085
00086 #define RTL_EEPROM_SIG cpu_to_le32(0x8129)
00087 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff)
00088 #define RTL_EEPROM_SIG_ADDR 0x0000
00089
00090
00091 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
00092 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
00093 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
00094 #define RTL_R8(reg) readb (ioaddr + (reg))
00095 #define RTL_R16(reg) readw (ioaddr + (reg))
00096 #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
00097
00098 enum mac_version {
00099 RTL_GIGA_MAC_VER_01 = 0x01,
00100 RTL_GIGA_MAC_VER_02 = 0x02,
00101 RTL_GIGA_MAC_VER_03 = 0x03,
00102 RTL_GIGA_MAC_VER_04 = 0x04,
00103 RTL_GIGA_MAC_VER_05 = 0x05,
00104 RTL_GIGA_MAC_VER_06 = 0x06,
00105 RTL_GIGA_MAC_VER_07 = 0x07,
00106 RTL_GIGA_MAC_VER_08 = 0x08,
00107 RTL_GIGA_MAC_VER_09 = 0x09,
00108 RTL_GIGA_MAC_VER_10 = 0x0a,
00109 RTL_GIGA_MAC_VER_11 = 0x0b,
00110 RTL_GIGA_MAC_VER_12 = 0x0c,
00111 RTL_GIGA_MAC_VER_13 = 0x0d,
00112 RTL_GIGA_MAC_VER_14 = 0x0e,
00113 RTL_GIGA_MAC_VER_15 = 0x0f,
00114 RTL_GIGA_MAC_VER_16 = 0x11,
00115 RTL_GIGA_MAC_VER_17 = 0x10,
00116 RTL_GIGA_MAC_VER_18 = 0x12,
00117 RTL_GIGA_MAC_VER_19 = 0x13,
00118 RTL_GIGA_MAC_VER_20 = 0x14,
00119 RTL_GIGA_MAC_VER_21 = 0x15,
00120 RTL_GIGA_MAC_VER_22 = 0x16,
00121 RTL_GIGA_MAC_VER_23 = 0x17,
00122 RTL_GIGA_MAC_VER_24 = 0x18,
00123 RTL_GIGA_MAC_VER_25 = 0x19,
00124 };
00125
00126 #define _R(NAME,MAC,MASK) \
00127 { .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
00128
00129 static const struct {
00130 const char *name;
00131 u8 mac_version;
00132 u32 RxConfigMask;
00133 } rtl_chip_info[] = {
00134 _R("RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880),
00135 _R("RTL8169s", RTL_GIGA_MAC_VER_02, 0xff7e1880),
00136 _R("RTL8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880),
00137 _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880),
00138 _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, 0xff7e1880),
00139 _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_06, 0xff7e1880),
00140 _R("RTL8102e", RTL_GIGA_MAC_VER_07, 0xff7e1880),
00141 _R("RTL8102e", RTL_GIGA_MAC_VER_08, 0xff7e1880),
00142 _R("RTL8102e", RTL_GIGA_MAC_VER_09, 0xff7e1880),
00143 _R("RTL8101e", RTL_GIGA_MAC_VER_10, 0xff7e1880),
00144 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880),
00145 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880),
00146 _R("RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880),
00147 _R("RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880),
00148 _R("RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880),
00149 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_17, 0xff7e1880),
00150 _R("RTL8101e", RTL_GIGA_MAC_VER_16, 0xff7e1880),
00151 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, 0xff7e1880),
00152 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_19, 0xff7e1880),
00153 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_20, 0xff7e1880),
00154 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_21, 0xff7e1880),
00155 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880),
00156 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880),
00157 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880),
00158 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880)
00159 };
00160 #undef _R
00161
00162 enum cfg_version {
00163 RTL_CFG_0 = 0x00,
00164 RTL_CFG_1,
00165 RTL_CFG_2
00166 };
00167
00168 #if 0
00169
00170 static struct pci_device_id rtl8169_pci_tbl[] = {
00171 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
00172 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
00173 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
00174 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
00175 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
00176 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 },
00177 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 },
00178 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 },
00179 { PCI_VENDOR_ID_LINKSYS, 0x1032,
00180 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
00181 { 0x0001, 0x8168,
00182 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
00183 {0,},
00184 };
00185 #endif
00186
00187 enum rtl_registers {
00188 MAC0 = 0,
00189 MAC4 = 4,
00190 MAR0 = 8,
00191 CounterAddrLow = 0x10,
00192 CounterAddrHigh = 0x14,
00193 TxDescStartAddrLow = 0x20,
00194 TxDescStartAddrHigh = 0x24,
00195 TxHDescStartAddrLow = 0x28,
00196 TxHDescStartAddrHigh = 0x2c,
00197 FLASH = 0x30,
00198 ERSR = 0x36,
00199 ChipCmd = 0x37,
00200 TxPoll = 0x38,
00201 IntrMask = 0x3c,
00202 IntrStatus = 0x3e,
00203 TxConfig = 0x40,
00204 RxConfig = 0x44,
00205 RxMissed = 0x4c,
00206 Cfg9346 = 0x50,
00207 Config0 = 0x51,
00208 Config1 = 0x52,
00209 Config2 = 0x53,
00210 Config3 = 0x54,
00211 Config4 = 0x55,
00212 Config5 = 0x56,
00213 MultiIntr = 0x5c,
00214 PHYAR = 0x60,
00215 PHYstatus = 0x6c,
00216 RxMaxSize = 0xda,
00217 CPlusCmd = 0xe0,
00218 IntrMitigate = 0xe2,
00219 RxDescAddrLow = 0xe4,
00220 RxDescAddrHigh = 0xe8,
00221 EarlyTxThres = 0xec,
00222 FuncEvent = 0xf0,
00223 FuncEventMask = 0xf4,
00224 FuncPresetState = 0xf8,
00225 FuncForceEvent = 0xfc,
00226 };
00227
00228 enum rtl8110_registers {
00229 TBICSR = 0x64,
00230 TBI_ANAR = 0x68,
00231 TBI_LPAR = 0x6a,
00232 };
00233
00234 enum rtl8168_8101_registers {
00235 CSIDR = 0x64,
00236 CSIAR = 0x68,
00237 #define CSIAR_FLAG 0x80000000
00238 #define CSIAR_WRITE_CMD 0x80000000
00239 #define CSIAR_BYTE_ENABLE 0x0f
00240 #define CSIAR_BYTE_ENABLE_SHIFT 12
00241 #define CSIAR_ADDR_MASK 0x0fff
00242
00243 EPHYAR = 0x80,
00244 #define EPHYAR_FLAG 0x80000000
00245 #define EPHYAR_WRITE_CMD 0x80000000
00246 #define EPHYAR_REG_MASK 0x1f
00247 #define EPHYAR_REG_SHIFT 16
00248 #define EPHYAR_DATA_MASK 0xffff
00249 DBG_REG = 0xd1,
00250 #define FIX_NAK_1 (1 << 4)
00251 #define FIX_NAK_2 (1 << 3)
00252 };
00253
00254 enum rtl_register_content {
00255
00256 SYSErr = 0x8000,
00257 PCSTimeout = 0x4000,
00258 SWInt = 0x0100,
00259 TxDescUnavail = 0x0080,
00260 RxFIFOOver = 0x0040,
00261 LinkChg = 0x0020,
00262 RxOverflow = 0x0010,
00263 TxErr = 0x0008,
00264 TxOK = 0x0004,
00265 RxErr = 0x0002,
00266 RxOK = 0x0001,
00267
00268
00269 RxFOVF = (1 << 23),
00270 RxRWT = (1 << 22),
00271 RxRES = (1 << 21),
00272 RxRUNT = (1 << 20),
00273 RxCRC = (1 << 19),
00274
00275
00276 CmdReset = 0x10,
00277 CmdRxEnb = 0x08,
00278 CmdTxEnb = 0x04,
00279 RxBufEmpty = 0x01,
00280
00281
00282 HPQ = 0x80,
00283 NPQ = 0x40,
00284 FSWInt = 0x01,
00285
00286
00287 Cfg9346_Lock = 0x00,
00288 Cfg9346_Unlock = 0xc0,
00289
00290
00291 AcceptErr = 0x20,
00292 AcceptRunt = 0x10,
00293 AcceptBroadcast = 0x08,
00294 AcceptMulticast = 0x04,
00295 AcceptMyPhys = 0x02,
00296 AcceptAllPhys = 0x01,
00297
00298
00299 RxCfgFIFOShift = 13,
00300 RxCfgDMAShift = 8,
00301
00302
00303 TxInterFrameGapShift = 24,
00304 TxDMAShift = 8,
00305
00306
00307 LEDS1 = (1 << 7),
00308 LEDS0 = (1 << 6),
00309 MSIEnable = (1 << 5),
00310 Speed_down = (1 << 4),
00311 MEMMAP = (1 << 3),
00312 IOMAP = (1 << 2),
00313 VPD = (1 << 1),
00314 PMEnable = (1 << 0),
00315
00316
00317 PCI_Clock_66MHz = 0x01,
00318 PCI_Clock_33MHz = 0x00,
00319
00320
00321 MagicPacket = (1 << 5),
00322 LinkUp = (1 << 4),
00323 Beacon_en = (1 << 0),
00324
00325
00326 BWF = (1 << 6),
00327 MWF = (1 << 5),
00328 UWF = (1 << 4),
00329 LanWake = (1 << 1),
00330 PMEStatus = (1 << 0),
00331
00332
00333 TBIReset = 0x80000000,
00334 TBILoopback = 0x40000000,
00335 TBINwEnable = 0x20000000,
00336 TBINwRestart = 0x10000000,
00337 TBILinkOk = 0x02000000,
00338 TBINwComplete = 0x01000000,
00339
00340
00341 EnableBist = (1 << 15),
00342 Mac_dbgo_oe = (1 << 14),
00343 Normal_mode = (1 << 13),
00344 Force_half_dup = (1 << 12),
00345 Force_rxflow_en = (1 << 11),
00346 Force_txflow_en = (1 << 10),
00347 Cxpl_dbg_sel = (1 << 9),
00348 ASF = (1 << 8),
00349 PktCntrDisable = (1 << 7),
00350 Mac_dbgo_sel = 0x001c,
00351 RxVlan = (1 << 6),
00352 RxChkSum = (1 << 5),
00353 PCIDAC = (1 << 4),
00354 PCIMulRW = (1 << 3),
00355 INTT_0 = 0x0000,
00356 INTT_1 = 0x0001,
00357 INTT_2 = 0x0002,
00358 INTT_3 = 0x0003,
00359
00360
00361 TBI_Enable = 0x80,
00362 TxFlowCtrl = 0x40,
00363 RxFlowCtrl = 0x20,
00364 _1000bpsF = 0x10,
00365 _100bps = 0x08,
00366 _10bps = 0x04,
00367 LinkStatus = 0x02,
00368 FullDup = 0x01,
00369
00370
00371 TBILinkOK = 0x02000000,
00372
00373
00374 CounterDump = 0x8,
00375 };
00376
00377 enum desc_status_bit {
00378 DescOwn = (1 << 31),
00379 RingEnd = (1 << 30),
00380 FirstFrag = (1 << 29),
00381 LastFrag = (1 << 28),
00382
00383
00384 LargeSend = (1 << 27),
00385 MSSShift = 16,
00386 MSSMask = 0xfff,
00387 IPCS = (1 << 18),
00388 UDPCS = (1 << 17),
00389 TCPCS = (1 << 16),
00390 TxVlanTag = (1 << 17),
00391
00392
00393 PID1 = (1 << 18),
00394 PID0 = (1 << 17),
00395
00396 #define RxProtoUDP (PID1)
00397 #define RxProtoTCP (PID0)
00398 #define RxProtoIP (PID1 | PID0)
00399 #define RxProtoMask RxProtoIP
00400
00401 IPFail = (1 << 16),
00402 UDPFail = (1 << 15),
00403 TCPFail = (1 << 14),
00404 RxVlanTag = (1 << 16),
00405 };
00406
00407 #define RsvdMask 0x3fffc000
00408
00409 struct TxDesc {
00410 volatile uint32_t opts1;
00411 volatile uint32_t opts2;
00412 volatile uint32_t addr_lo;
00413 volatile uint32_t addr_hi;
00414 };
00415
00416 struct RxDesc {
00417 volatile uint32_t opts1;
00418 volatile uint32_t opts2;
00419 volatile uint32_t addr_lo;
00420 volatile uint32_t addr_hi;
00421 };
00422
00423 enum features {
00424 RTL_FEATURE_WOL = (1 << 0),
00425 RTL_FEATURE_MSI = (1 << 1),
00426 RTL_FEATURE_GMII = (1 << 2),
00427 };
00428
00429 static void rtl_hw_start_8169(struct net_device *);
00430 static void rtl_hw_start_8168(struct net_device *);
00431 static void rtl_hw_start_8101(struct net_device *);
00432
00433 struct rtl8169_private {
00434
00435 struct pci_device *pci_dev;
00436 struct net_device *netdev;
00437 uint8_t *hw_addr;
00438 void *mmio_addr;
00439 uint32_t irqno;
00440
00441 int chipset;
00442 int mac_version;
00443 int cfg_index;
00444 u16 intr_event;
00445
00446 struct io_buffer *tx_iobuf[NUM_TX_DESC];
00447 struct io_buffer *rx_iobuf[NUM_RX_DESC];
00448
00449 struct TxDesc *tx_base;
00450 struct RxDesc *rx_base;
00451
00452 uint32_t tx_curr;
00453 uint32_t rx_curr;
00454
00455 uint32_t tx_tail;
00456
00457 uint32_t tx_fill_ctr;
00458
00459 u16 cp_cmd;
00460
00461 int phy_auto_nego_reg;
00462 int phy_1000_ctrl_reg;
00463
00464 int ( *set_speed ) (struct net_device *, u8 autoneg, u16 speed, u8 duplex );
00465 void ( *phy_reset_enable ) ( void *ioaddr );
00466 void ( *hw_start ) ( struct net_device * );
00467 unsigned int ( *phy_reset_pending ) ( void *ioaddr );
00468 unsigned int ( *link_ok ) ( void *ioaddr );
00469
00470 int pcie_cap;
00471
00472 unsigned features;
00473
00474 };
00475
00476 static const unsigned int rtl8169_rx_config =
00477 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
00478
00479 #endif
00480
00481
00482
00483
00484
00485
00486
00487