11 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/netdevice.h>
17 #include <linux/ethtool.h>
18 #include <linux/mii.h>
19 #include <linux/if_vlan.h>
23 #include <linux/tcp.h>
30 #include <linux/prefetch.h>
35 #define RTL8169_VERSION "2.3LK-NAPI"
36 #define MODULENAME "r8169"
37 #define PFX MODULENAME ": "
39 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw"
40 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw"
41 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw"
42 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw"
43 #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw"
44 #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw"
45 #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw"
46 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw"
47 #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw"
48 #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw"
49 #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw"
50 #define FIRMWARE_8168G_1 "rtl_nic/rtl8168g-1.fw"
53 #define assert(expr) \
55 printk( "Assertion failed! %s,%s,%s,line=%d\n", \
56 #expr,__FILE__,__func__,__LINE__); \
58 #define dprintk(fmt, args...) \
59 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0)
61 #define assert(expr) do {} while (0)
62 #define dprintk(fmt, args...) do {} while (0)
65 #define R8169_MSG_DEFAULT \
66 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
68 #define TX_SLOTS_AVAIL(tp) \
69 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
72 #define TX_FRAGS_READY_FOR(tp,nr_frags) \
73 (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
77 static const int multicast_filter_limit = 32;
79 #define MAX_READ_REQUEST_SHIFT 12
80 #define TX_DMA_BURST 7
81 #define SafeMtu 0x1c20
82 #define InterFrameGap 0x03
84 #define R8169_REGS_SIZE 256
85 #define R8169_NAPI_WEIGHT 64
86 #define NUM_TX_DESC 64
87 #define NUM_RX_DESC 256
88 #define RX_BUF_SIZE 1536
89 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
90 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
92 #define RTL8169_TX_TIMEOUT (6*HZ)
93 #define RTL8169_PHY_TIMEOUT (10*HZ)
95 #define RTL_EEPROM_SIG cpu_to_le32(0x8129)
96 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff)
97 #define RTL_EEPROM_SIG_ADDR 0x0000
100 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
101 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
102 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
103 #define RTL_R8(reg) readb (ioaddr + (reg))
104 #define RTL_R16(reg) readw (ioaddr + (reg))
105 #define RTL_R32(reg) readl (ioaddr + (reg))
157 #define JUMBO_1K ETH_DATA_LEN
158 #define JUMBO_4K (4*1024 - ETH_HLEN - 2)
159 #define JUMBO_6K (6*1024 - ETH_HLEN - 2)
160 #define JUMBO_7K (7*1024 - ETH_HLEN - 2)
161 #define JUMBO_9K (9*1024 - ETH_HLEN - 2)
163 #define _R(NAME,TD,FW,SZ,B) { \
171 static const struct {
177 } rtl_chip_infos[] = {
305 static int rx_buf_sz = 16383;
329 #define TXCFG_AUTO_FIFO (1 << 7)
330 #define TXCFG_EMPTY (1 << 11)
333 #define RX128_INT_EN (1 << 15)
334 #define RX_MULTI_EN (1 << 14)
335 #define RXCFG_FIFO_SHIFT 13
337 #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)
338 #define RXCFG_DMA_SHIFT 8
340 #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)
347 #define PME_SIGNAL (1 << 5)
362 #define NoEarlyTx 0x3f
366 #define TxPacketMax (8064 >> 7)
367 #define EarlySize 0x27
384 #define CSIAR_FLAG 0x80000000
385 #define CSIAR_WRITE_CMD 0x80000000
386 #define CSIAR_BYTE_ENABLE 0x0f
387 #define CSIAR_BYTE_ENABLE_SHIFT 12
388 #define CSIAR_ADDR_MASK 0x0fff
389 #define CSIAR_FUNC_CARD 0x00000000
390 #define CSIAR_FUNC_SDIO 0x00010000
391 #define CSIAR_FUNC_NIC 0x00020000
394 #define EPHYAR_FLAG 0x80000000
395 #define EPHYAR_WRITE_CMD 0x80000000
396 #define EPHYAR_REG_MASK 0x1f
397 #define EPHYAR_REG_SHIFT 16
398 #define EPHYAR_DATA_MASK 0xffff
400 #define PFM_EN (1 << 6)
402 #define FIX_NAK_1 (1 << 4)
403 #define FIX_NAK_2 (1 << 3)
406 #define NOW_IS_OOB (1 << 7)
407 #define TX_EMPTY (1 << 5)
408 #define RX_EMPTY (1 << 4)
409 #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY)
410 #define EN_NDP (1 << 3)
411 #define EN_OOB_RESET (1 << 2)
412 #define LINK_LIST_RDY (1 << 1)
414 #define EFUSEAR_FLAG 0x80000000
415 #define EFUSEAR_WRITE_CMD 0x80000000
416 #define EFUSEAR_READ_CMD 0x00000000
417 #define EFUSEAR_REG_MASK 0x03ff
418 #define EFUSEAR_REG_SHIFT 8
419 #define EFUSEAR_DATA_MASK 0xff
427 #define ERIAR_FLAG 0x80000000
428 #define ERIAR_WRITE_CMD 0x80000000
429 #define ERIAR_READ_CMD 0x00000000
430 #define ERIAR_ADDR_BYTE_ALIGN 4
431 #define ERIAR_TYPE_SHIFT 16
432 #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT)
433 #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT)
434 #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT)
435 #define ERIAR_MASK_SHIFT 12
436 #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT)
437 #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT)
438 #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT)
439 #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT)
442 #define OCPDR_WRITE_CMD 0x80000000
443 #define OCPDR_READ_CMD 0x00000000
444 #define OCPDR_REG_MASK 0x7f
445 #define OCPDR_GPHY_REG_SHIFT 16
446 #define OCPDR_DATA_MASK 0xffff
448 #define OCPAR_FLAG 0x80000000
449 #define OCPAR_GPHY_WRITE_CMD 0x8000f060
450 #define OCPAR_GPHY_READ_CMD 0x0000f060
454 #define TXPLA_RST (1 << 29)
455 #define DISABLE_LAN_EN (1 << 23)
456 #define PWM_EN (1 << 22)
457 #define RXDV_GATED_EN (1 << 19)
458 #define EARLY_TALLY_EN (1 << 16)
506 #define RX_CONFIG_ACCEPT_MASK 0x3f
609 #define TD0_MSS_SHIFT 16
618 #define TD1_MSS_SHIFT 18
624 static const struct rtl_tx_desc_info {
631 } tx_desc_info [] = {
655 #define RxProtoUDP (PID1)
656 #define RxProtoTCP (PID0)
657 #define RxProtoIP (PID1 | PID0)
658 #define RxProtoMask RxProtoIP
666 #define RsvdMask 0x3fffc000
791 #define RTL_VER_SIZE 32
800 #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN)
847 static void rtl_udelay(
unsigned int d)
853 void (*
delay)(
unsigned int),
unsigned int d,
int n,
858 for (i = 0; i <
n; i++) {
863 netif_err(tp, drv, tp->
dev,
"%s == %d (loop: %d, delay: %d).\n",
864 c->
msg, !high, n, d);
870 unsigned int d,
int n)
872 return rtl_loop_wait(tp, c, rtl_udelay, d, n,
true);
877 unsigned int d,
int n)
879 return rtl_loop_wait(tp, c, rtl_udelay, d, n,
false);
884 unsigned int d,
int n)
886 return rtl_loop_wait(tp, c, msleep, d, n,
true);
891 unsigned int d,
int n)
893 return rtl_loop_wait(tp, c, msleep, d, n,
false);
896 #define DECLARE_RTL_COND(name) \
897 static bool name ## _check(struct rtl8169_private *); \
899 static const struct rtl_cond name = { \
900 .check = name ## _check, \
904 static bool name ## _check(struct rtl8169_private *tp)
919 return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ?
930 rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20);
948 if (!rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 5))
951 ocp_write(tp, 0x1, 0x30, 0x00000001);
954 #define OOB_CMD_RESET 0x00
955 #define OOB_CMD_DRIVER_START 0x05
956 #define OOB_CMD_DRIVER_STOP 0x06
967 reg = rtl8168_get_ocp_reg(tp);
969 return ocp_read(tp, 0x0f, reg) & 0x00000800;
976 rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10);
983 rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10);
988 u16 reg = rtl8168_get_ocp_reg(tp);
990 return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0;
995 if (reg & 0xffff0001) {
996 netif_err(tp, drv, tp->
dev,
"Invalid ocp reg %x!\n", reg);
1013 if (rtl_ocp_reg_failure(tp, reg))
1018 rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10);
1025 if (rtl_ocp_reg_failure(tp, reg))
1030 return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ?
1038 val = r8168_phy_ocp_read(tp, reg);
1039 r8168_phy_ocp_write(tp, reg, (val | p) & ~m);
1046 if (rtl_ocp_reg_failure(tp, reg))
1056 if (rtl_ocp_reg_failure(tp, reg))
1064 #define OCP_STD_PHY_BASE 0xa400
1076 r8168_phy_ocp_write(tp, tp->
ocp_base + reg * 2, value);
1084 return r8168_phy_ocp_read(tp, tp->
ocp_base + reg * 2);
1098 RTL_W32(
PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff));
1100 rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20);
1115 value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ?
1135 rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100);
1138 static void r8168dp_1_mdio_write(
struct rtl8169_private *tp,
int reg,
int value)
1140 r8168dp_1_mdio_access(tp, reg,
1154 return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ?
1158 #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000
1160 static void r8168dp_2_mdio_start(
void __iomem *ioaddr)
1165 static void r8168dp_2_mdio_stop(
void __iomem *ioaddr)
1170 static void r8168dp_2_mdio_write(
struct rtl8169_private *tp,
int reg,
int value)
1174 r8168dp_2_mdio_start(ioaddr);
1176 r8169_mdio_write(tp, reg, value);
1178 r8168dp_2_mdio_stop(ioaddr);
1186 r8168dp_2_mdio_start(ioaddr);
1188 value = r8169_mdio_read(tp, reg);
1190 r8168dp_2_mdio_stop(ioaddr);
1197 tp->
mdio_ops.write(tp, location, val);
1202 return tp->
mdio_ops.read(tp, location);
1207 rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value);
1210 static void rtl_w1w0_phy(
struct rtl8169_private *tp,
int reg_addr,
int p,
int m)
1214 val = rtl_readphy(tp, reg_addr);
1215 rtl_writephy(tp, reg_addr, (val | p) & ~m);
1223 rtl_writephy(tp, location, val);
1230 return rtl_readphy(tp, location);
1240 static void rtl_ephy_write(
struct rtl8169_private *tp,
int reg_addr,
int value)
1247 rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100);
1258 return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ?
1267 BUG_ON((addr & 3) || (mask == 0));
1271 rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100);
1280 return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ?
1289 val = rtl_eri_read(tp, addr, type);
1290 rtl_eri_write(tp, addr, mask, (val & ~m) | p, type);
1321 return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ?
1355 #define RTL_EVENT_NAPI_RX (RxOK | RxErr)
1356 #define RTL_EVENT_NAPI_TX (TxOK | TxErr)
1357 #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX)
1368 rtl_irq_disable(tp);
1373 static unsigned int rtl8169_tbi_reset_pending(
struct rtl8169_private *tp)
1380 static unsigned int rtl8169_xmii_reset_pending(
struct rtl8169_private *tp)
1385 static unsigned int rtl8169_tbi_link_ok(
void __iomem *ioaddr)
1390 static unsigned int rtl8169_xmii_link_ok(
void __iomem *ioaddr)
1407 rtl_writephy(tp,
MII_BMCR, val & 0xffff);
1415 if (!netif_running(dev))
1467 static void __rtl8169_check_link_status(
struct net_device *dev,
1472 rtl_link_chg_patch(tp);
1475 pm_request_resume(&tp->
pci_dev->dev);
1487 static void rtl8169_check_link_status(
struct net_device *dev,
1491 __rtl8169_check_link_status(dev, tp, ioaddr,
false);
1494 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
1530 wol->
wolopts = __rtl8169_get_wol(tp);
1532 rtl_unlock_work(tp);
1539 static const struct {
1557 if (wolopts &
cfg[i].
opt)
1558 options |=
cfg[
i].mask;
1590 __rtl8169_set_wol(tp, wol->
wolopts);
1592 rtl_unlock_work(tp);
1599 static const char *rtl_lookup_firmware_name(
struct rtl8169_private *tp)
1604 static void rtl8169_get_drvinfo(
struct net_device *dev,
1608 struct rtl_fw *rtl_fw = tp->
rtl_fw;
1614 if (!IS_ERR_OR_NULL(rtl_fw))
1619 static int rtl8169_get_regs_len(
struct net_device *dev)
1624 static int rtl8169_set_speed_tbi(
struct net_device *dev,
1640 "incorrect speed setting refused in TBI mode\n");
1647 static int rtl8169_set_speed_xmii(
struct net_device *dev,
1651 int giga_ctrl, bmcr;
1654 rtl_writephy(tp, 0x1f, 0x0000);
1678 if (tp->
mii.supports_gmii) {
1683 }
else if (adv & (ADVERTISED_1000baseT_Half |
1686 "PHY does not support 1000Mbps\n");
1713 rtl_writephy(tp, 0x17, 0x2138);
1714 rtl_writephy(tp, 0x0e, 0x0260);
1716 rtl_writephy(tp, 0x17, 0x2108);
1717 rtl_writephy(tp, 0x0e, 0x0000);
1726 static int rtl8169_set_speed(
struct net_device *dev,
1727 u8 autoneg,
u16 speed,
u8 duplex,
u32 advertising)
1732 ret = tp->
set_speed(dev, autoneg, speed, duplex, advertising);
1752 ret = rtl8169_set_speed(dev, cmd->
autoneg, ethtool_cmd_speed(cmd),
1754 rtl_unlock_work(tp);
1774 static void __rtl8169_set_features(
struct net_device *dev,
1800 if (features & NETIF_F_RXALL)
1806 static int rtl8169_set_features(
struct net_device *dev,
1812 __rtl8169_set_features(dev, features);
1813 rtl_unlock_work(tp);
1831 __vlan_hwaccel_put_tag(skb,
swab16(opts2 & 0xffff));
1871 rtl_unlock_work(tp);
1886 rtl_unlock_work(tp);
1896 static void rtl8169_set_msglevel(
struct net_device *dev,
u32 value)
1910 "tx_single_collisions",
1911 "tx_multi_collisions",
1919 static int rtl8169_get_sset_count(
struct net_device *dev,
int sset)
1936 static void rtl8169_update_counters(
struct net_device *dev)
1961 if (rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000))
1970 static void rtl8169_get_ethtool_stats(
struct net_device *dev,
1977 rtl8169_update_counters(dev);
1994 static void rtl8169_get_strings(
struct net_device *dev,
u32 stringset,
u8 *data)
1998 memcpy(data, *rtl8169_gstrings,
sizeof(rtl8169_gstrings));
2003 static const struct ethtool_ops rtl8169_ethtool_ops = {
2004 .get_drvinfo = rtl8169_get_drvinfo,
2005 .get_regs_len = rtl8169_get_regs_len,
2007 .get_settings = rtl8169_get_settings,
2008 .set_settings = rtl8169_set_settings,
2009 .get_msglevel = rtl8169_get_msglevel,
2010 .set_msglevel = rtl8169_set_msglevel,
2011 .get_regs = rtl8169_get_regs,
2012 .get_wol = rtl8169_get_wol,
2013 .set_wol = rtl8169_set_wol,
2014 .get_strings = rtl8169_get_strings,
2015 .get_sset_count = rtl8169_get_sset_count,
2016 .get_ethtool_stats = rtl8169_get_ethtool_stats,
2035 static const struct rtl_mac_info {
2117 const struct rtl_mac_info *p =
mac_info;
2121 while ((reg & p->mask) != p->val)
2127 "unknown MAC, using family default\n");
2143 const struct phy_reg *regs,
int len)
2146 rtl_writephy(tp, regs->
reg, regs->
val);
2151 #define PHY_READ 0x00000000
2152 #define PHY_DATA_OR 0x10000000
2153 #define PHY_DATA_AND 0x20000000
2154 #define PHY_BJMPN 0x30000000
2155 #define PHY_READ_EFUSE 0x40000000
2156 #define PHY_READ_MAC_BYTE 0x50000000
2157 #define PHY_WRITE_MAC_BYTE 0x60000000
2158 #define PHY_CLEAR_READCOUNT 0x70000000
2159 #define PHY_WRITE 0x80000000
2160 #define PHY_READCOUNT_EQ_SKIP 0x90000000
2161 #define PHY_COMP_EQ_SKIPN 0xa0000000
2162 #define PHY_COMP_NEQ_SKIPN 0xb0000000
2163 #define PHY_WRITE_PREVIOUS 0xc0000000
2164 #define PHY_SKIPN 0xd0000000
2165 #define PHY_DELAY_MS 0xe0000000
2166 #define PHY_WRITE_ERI_WORD 0xf0000000
2176 #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code))
2178 static bool rtl_fw_format_ok(
struct rtl8169_private *tp,
struct rtl_fw *rtl_fw)
2182 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
2183 char *
version = rtl_fw->version;
2189 if (!fw_info->
magic) {
2193 if (fw->
size <
sizeof(*fw_info))
2196 for (i = 0; i < fw->
size; i++)
2197 checksum += fw->
data[i];
2202 if (start > fw->
size)
2230 struct rtl_fw_phy_action *pa)
2235 for (index = 0; index < pa->size; index++) {
2237 u32 regno = (action & 0x0fff0000) >> 16;
2239 switch(action & 0xf0000000) {
2251 if (regno > index) {
2253 "Out of range of firmware\n");
2258 if (index + 2 >= pa->size) {
2260 "Out of range of firmware\n");
2267 if (index + 1 + regno >= pa->size) {
2269 "Out of range of firmware\n");
2279 "Invalid action 0x%08x\n", action);
2288 static int rtl_check_firmware(
struct rtl8169_private *tp,
struct rtl_fw *rtl_fw)
2293 if (!rtl_fw_format_ok(tp, rtl_fw)) {
2294 netif_err(tp, ifup, dev,
"invalid firwmare\n");
2298 if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action))
2304 static void rtl_phy_write_fw(
struct rtl8169_private *tp,
struct rtl_fw *rtl_fw)
2306 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
2310 predata = count = 0;
2312 for (index = 0; index < pa->size; ) {
2314 u32 data = action & 0x0000ffff;
2315 u32 regno = (action & 0x0fff0000) >> 16;
2320 switch(action & 0xf0000000) {
2322 predata = rtl_readphy(tp, regno);
2338 predata = rtl8168d_efuse_read(tp, regno);
2346 rtl_writephy(tp, regno, data);
2350 index += (count ==
data) ? 2 : 1;
2353 if (predata == data)
2358 if (predata != data)
2363 rtl_writephy(tp, regno, predata);
2385 if (!IS_ERR_OR_NULL(tp->
rtl_fw)) {
2394 struct rtl_fw *rtl_fw = tp->
rtl_fw;
2397 if (!IS_ERR_OR_NULL(rtl_fw))
2398 rtl_phy_write_fw(tp, rtl_fw);
2403 if (rtl_readphy(tp, reg) != val)
2406 rtl_apply_firmware(tp);
2411 static const struct phy_reg phy_reg_init[] = {
2473 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2478 static const struct phy_reg phy_reg_init[] = {
2484 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2487 static void rtl8169scd_hw_phy_config_quirk(
struct rtl8169_private *tp)
2495 rtl_writephy(tp, 0x1f, 0x0001);
2496 rtl_writephy(tp, 0x10, 0xf01b);
2497 rtl_writephy(tp, 0x1f, 0x0000);
2502 static const struct phy_reg phy_reg_init[] = {
2542 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2544 rtl8169scd_hw_phy_config_quirk(tp);
2549 static const struct phy_reg phy_reg_init[] = {
2597 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2602 static const struct phy_reg phy_reg_init[] = {
2607 rtl_writephy(tp, 0x1f, 0x0001);
2608 rtl_patchphy(tp, 0x16, 1 << 0);
2610 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2615 static const struct phy_reg phy_reg_init[] = {
2621 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2626 static const struct phy_reg phy_reg_init[] = {
2634 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2639 static const struct phy_reg phy_reg_init[] = {
2645 rtl_writephy(tp, 0x1f, 0x0000);
2646 rtl_patchphy(tp, 0x14, 1 << 5);
2647 rtl_patchphy(tp, 0x0d, 1 << 5);
2649 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2654 static const struct phy_reg phy_reg_init[] = {
2674 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2676 rtl_patchphy(tp, 0x14, 1 << 5);
2677 rtl_patchphy(tp, 0x0d, 1 << 5);
2678 rtl_writephy(tp, 0x1f, 0x0000);
2683 static const struct phy_reg phy_reg_init[] = {
2701 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2703 rtl_patchphy(tp, 0x16, 1 << 0);
2704 rtl_patchphy(tp, 0x14, 1 << 5);
2705 rtl_patchphy(tp, 0x0d, 1 << 5);
2706 rtl_writephy(tp, 0x1f, 0x0000);
2711 static const struct phy_reg phy_reg_init[] = {
2723 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2725 rtl_patchphy(tp, 0x16, 1 << 0);
2726 rtl_patchphy(tp, 0x14, 1 << 5);
2727 rtl_patchphy(tp, 0x0d, 1 << 5);
2728 rtl_writephy(tp, 0x1f, 0x0000);
2733 rtl8168c_3_hw_phy_config(tp);
2738 static const struct phy_reg phy_reg_init_0[] = {
2779 rtl_writephy_batch(tp, phy_reg_init_0,
ARRAY_SIZE(phy_reg_init_0));
2785 rtl_writephy(tp, 0x1f, 0x0002);
2786 rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef);
2787 rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00);
2789 if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
2790 static const struct phy_reg phy_reg_init[] = {
2800 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2802 val = rtl_readphy(tp, 0x0d);
2804 if ((val & 0x00ff) != 0x006c) {
2805 static const u32 set[] = {
2806 0x0065, 0x0066, 0x0067, 0x0068,
2807 0x0069, 0x006a, 0x006b, 0x006c
2811 rtl_writephy(tp, 0x1f, 0x0002);
2815 rtl_writephy(tp, 0x0d, val |
set[i]);
2818 static const struct phy_reg phy_reg_init[] = {
2826 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2830 rtl_writephy(tp, 0x1f, 0x0002);
2831 rtl_patchphy(tp, 0x0d, 0x0300);
2832 rtl_patchphy(tp, 0x0f, 0x0010);
2835 rtl_writephy(tp, 0x1f, 0x0002);
2836 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600);
2837 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000);
2839 rtl_writephy(tp, 0x1f, 0x0005);
2840 rtl_writephy(tp, 0x05, 0x001b);
2844 rtl_writephy(tp, 0x1f, 0x0000);
2849 static const struct phy_reg phy_reg_init_0[] = {
2890 rtl_writephy_batch(tp, phy_reg_init_0,
ARRAY_SIZE(phy_reg_init_0));
2892 if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
2893 static const struct phy_reg phy_reg_init[] = {
2904 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2906 val = rtl_readphy(tp, 0x0d);
2907 if ((val & 0x00ff) != 0x006c) {
2908 static const u32 set[] = {
2909 0x0065, 0x0066, 0x0067, 0x0068,
2910 0x0069, 0x006a, 0x006b, 0x006c
2914 rtl_writephy(tp, 0x1f, 0x0002);
2918 rtl_writephy(tp, 0x0d, val |
set[i]);
2921 static const struct phy_reg phy_reg_init[] = {
2929 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
2933 rtl_writephy(tp, 0x1f, 0x0002);
2934 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600);
2935 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000);
2938 rtl_writephy(tp, 0x1f, 0x0002);
2939 rtl_patchphy(tp, 0x0f, 0x0017);
2941 rtl_writephy(tp, 0x1f, 0x0005);
2942 rtl_writephy(tp, 0x05, 0x001b);
2946 rtl_writephy(tp, 0x1f, 0x0000);
2951 static const struct phy_reg phy_reg_init[] = {
3007 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3012 static const struct phy_reg phy_reg_init[] = {
3022 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3023 rtl_patchphy(tp, 0x0d, 1 << 5);
3028 static const struct phy_reg phy_reg_init[] = {
3056 rtl_apply_firmware(tp);
3058 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3061 rtl_writephy(tp, 0x1f, 0x0007);
3062 rtl_writephy(tp, 0x1e, 0x0023);
3063 rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000);
3064 rtl_writephy(tp, 0x1f, 0x0000);
3067 rtl_writephy(tp, 0x1f, 0x0002);
3068 rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00);
3069 rtl_writephy(tp, 0x1f, 0x0000);
3072 rtl_writephy(tp, 0x1f, 0x0007);
3073 rtl_writephy(tp, 0x1e, 0x002d);
3074 rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000);
3075 rtl_writephy(tp, 0x1f, 0x0000);
3076 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000);
3078 rtl_writephy(tp, 0x1f, 0x0005);
3079 rtl_writephy(tp, 0x05, 0x8b86);
3080 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000);
3081 rtl_writephy(tp, 0x1f, 0x0000);
3083 rtl_writephy(tp, 0x1f, 0x0005);
3084 rtl_writephy(tp, 0x05, 0x8b85);
3085 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000);
3086 rtl_writephy(tp, 0x1f, 0x0007);
3087 rtl_writephy(tp, 0x1e, 0x0020);
3088 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100);
3089 rtl_writephy(tp, 0x1f, 0x0006);
3090 rtl_writephy(tp, 0x00, 0x5a00);
3091 rtl_writephy(tp, 0x1f, 0x0000);
3092 rtl_writephy(tp, 0x0d, 0x0007);
3093 rtl_writephy(tp, 0x0e, 0x003c);
3094 rtl_writephy(tp, 0x0d, 0x4007);
3095 rtl_writephy(tp, 0x0e, 0x0000);
3096 rtl_writephy(tp, 0x0d, 0x0000);
3101 static const struct phy_reg phy_reg_init[] = {
3128 rtl_apply_firmware(tp);
3130 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3133 rtl_writephy(tp, 0x1f, 0x0005);
3134 rtl_writephy(tp, 0x05, 0x8b80);
3135 rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000);
3136 rtl_writephy(tp, 0x1f, 0x0000);
3139 rtl_writephy(tp, 0x1f, 0x0004);
3140 rtl_writephy(tp, 0x1f, 0x0007);
3141 rtl_writephy(tp, 0x1e, 0x002d);
3142 rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000);
3143 rtl_writephy(tp, 0x1f, 0x0002);
3144 rtl_writephy(tp, 0x1f, 0x0000);
3145 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000);
3148 rtl_writephy(tp, 0x1f, 0x0005);
3149 rtl_writephy(tp, 0x05, 0x8b86);
3150 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000);
3151 rtl_writephy(tp, 0x1f, 0x0000);
3154 rtl_writephy(tp, 0x1f, 0x0005);
3155 rtl_writephy(tp, 0x05, 0x8b85);
3156 rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000);
3157 rtl_writephy(tp, 0x1f, 0x0000);
3161 rtl_writephy(tp, 0x1f, 0x0005);
3162 rtl_writephy(tp, 0x05, 0x8b85);
3163 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000);
3164 rtl_writephy(tp, 0x1f, 0x0004);
3165 rtl_writephy(tp, 0x1f, 0x0007);
3166 rtl_writephy(tp, 0x1e, 0x0020);
3167 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100);
3168 rtl_writephy(tp, 0x1f, 0x0002);
3169 rtl_writephy(tp, 0x1f, 0x0000);
3170 rtl_writephy(tp, 0x0d, 0x0007);
3171 rtl_writephy(tp, 0x0e, 0x003c);
3172 rtl_writephy(tp, 0x0d, 0x4007);
3173 rtl_writephy(tp, 0x0e, 0x0000);
3174 rtl_writephy(tp, 0x0d, 0x0000);
3177 rtl_writephy(tp, 0x1f, 0x0003);
3178 rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001);
3179 rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400);
3180 rtl_writephy(tp, 0x1f, 0x0000);
3186 rtl_writephy(tp, 0x1f, 0x0005);
3187 rtl_writephy(tp, 0x05, 0x8b80);
3188 rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000);
3189 rtl_writephy(tp, 0x1f, 0x0000);
3192 rtl_writephy(tp, 0x1f, 0x0007);
3193 rtl_writephy(tp, 0x1e, 0x002d);
3194 rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000);
3195 rtl_writephy(tp, 0x1f, 0x0000);
3196 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000);
3199 rtl_writephy(tp, 0x1f, 0x0005);
3200 rtl_writephy(tp, 0x05, 0x8b86);
3201 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000);
3202 rtl_writephy(tp, 0x1f, 0x0000);
3207 static const struct phy_reg phy_reg_init[] = {
3242 rtl_apply_firmware(tp);
3244 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3246 rtl8168f_hw_phy_config(tp);
3249 rtl_writephy(tp, 0x1f, 0x0005);
3250 rtl_writephy(tp, 0x05, 0x8b85);
3251 rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000);
3252 rtl_writephy(tp, 0x1f, 0x0000);
3257 rtl_apply_firmware(tp);
3259 rtl8168f_hw_phy_config(tp);
3264 static const struct phy_reg phy_reg_init[] = {
3300 rtl_apply_firmware(tp);
3302 rtl8168f_hw_phy_config(tp);
3305 rtl_writephy(tp, 0x1f, 0x0005);
3306 rtl_writephy(tp, 0x05, 0x8b85);
3307 rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000);
3308 rtl_writephy(tp, 0x1f, 0x0000);
3310 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3313 rtl_writephy(tp, 0x1f, 0x0005);
3314 rtl_writephy(tp, 0x05, 0x8b54);
3315 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0800);
3316 rtl_writephy(tp, 0x05, 0x8b5d);
3317 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0800);
3318 rtl_writephy(tp, 0x05, 0x8a7c);
3319 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100);
3320 rtl_writephy(tp, 0x05, 0x8a7f);
3321 rtl_w1w0_phy(tp, 0x06, 0x0100, 0x0000);
3322 rtl_writephy(tp, 0x05, 0x8a82);
3323 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100);
3324 rtl_writephy(tp, 0x05, 0x8a85);
3325 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100);
3326 rtl_writephy(tp, 0x05, 0x8a88);
3327 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100);
3328 rtl_writephy(tp, 0x1f, 0x0000);
3331 rtl_writephy(tp, 0x1f, 0x0005);
3332 rtl_writephy(tp, 0x05, 0x8b85);
3333 rtl_w1w0_phy(tp, 0x06, 0x8000, 0x0000);
3334 rtl_writephy(tp, 0x1f, 0x0000);
3338 rtl_writephy(tp, 0x1f, 0x0005);
3339 rtl_writephy(tp, 0x05, 0x8b85);
3340 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000);
3341 rtl_writephy(tp, 0x1f, 0x0004);
3342 rtl_writephy(tp, 0x1f, 0x0007);
3343 rtl_writephy(tp, 0x1e, 0x0020);
3344 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100);
3345 rtl_writephy(tp, 0x1f, 0x0000);
3346 rtl_writephy(tp, 0x0d, 0x0007);
3347 rtl_writephy(tp, 0x0e, 0x003c);
3348 rtl_writephy(tp, 0x0d, 0x4007);
3349 rtl_writephy(tp, 0x0e, 0x0000);
3350 rtl_writephy(tp, 0x0d, 0x0000);
3353 rtl_writephy(tp, 0x1f, 0x0003);
3354 rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001);
3355 rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400);
3356 rtl_writephy(tp, 0x1f, 0x0000);
3361 static const u16 mac_ocp_patch[] = {
3362 0xe008, 0xe01b, 0xe01d, 0xe01f,
3363 0xe021, 0xe023, 0xe025, 0xe027,
3364 0x49d2, 0xf10d, 0x766c, 0x49e2,
3365 0xf00a, 0x1ec0, 0x8ee1, 0xc60a,
3367 0x77c0, 0x4870, 0x9fc0, 0x1ea0,
3368 0xc707, 0x8ee1, 0x9d6c, 0xc603,
3369 0xbe00, 0xb416, 0x0076, 0xe86c,
3370 0xc602, 0xbe00, 0x0000, 0xc602,
3372 0xbe00, 0x0000, 0xc602, 0xbe00,
3373 0x0000, 0xc602, 0xbe00, 0x0000,
3374 0xc602, 0xbe00, 0x0000, 0xc602,
3375 0xbe00, 0x0000, 0xc602, 0xbe00,
3377 0x0000, 0x0000, 0x0000, 0x0000
3382 for (i = 0; i <
ARRAY_SIZE(mac_ocp_patch); i++)
3383 r8168_mac_ocp_write(tp, 0xf800 + 2*i, mac_ocp_patch[i]);
3384 r8168_mac_ocp_write(tp, 0xfc26, 0x8000);
3385 r8168_mac_ocp_write(tp, 0xfc28, 0x0075);
3387 rtl_apply_firmware(tp);
3389 if (r8168_phy_ocp_read(tp, 0xa460) & 0x0100)
3390 rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x0000, 0x8000);
3392 rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x8000, 0x0000);
3394 if (r8168_phy_ocp_read(tp, 0xa466) & 0x0100)
3395 rtl_w1w0_phy_ocp(tp, 0xc41a, 0x0002, 0x0000);
3397 rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x0000, 0x0002);
3399 rtl_w1w0_phy_ocp(tp, 0xa442, 0x000c, 0x0000);
3400 rtl_w1w0_phy_ocp(tp, 0xa4b2, 0x0004, 0x0000);
3402 r8168_phy_ocp_write(tp, 0xa436, 0x8012);
3403 rtl_w1w0_phy_ocp(tp, 0xa438, 0x8000, 0x0000);
3405 rtl_w1w0_phy_ocp(tp, 0xc422, 0x4000, 0x2000);
3410 static const struct phy_reg phy_reg_init[] = {
3417 rtl_writephy(tp, 0x1f, 0x0000);
3418 rtl_patchphy(tp, 0x11, 1 << 12);
3419 rtl_patchphy(tp, 0x19, 1 << 13);
3420 rtl_patchphy(tp, 0x10, 1 << 15);
3422 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3427 static const struct phy_reg phy_reg_init[] = {
3442 rtl_writephy(tp, 0x1f, 0x0000);
3443 rtl_writephy(tp, 0x18, 0x0310);
3446 rtl_apply_firmware(tp);
3448 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3454 rtl_writephy(tp, 0x1f, 0x0000);
3455 rtl_writephy(tp, 0x18, 0x0310);
3458 rtl_apply_firmware(tp);
3462 rtl_writephy(tp, 0x1f, 0x0004);
3463 rtl_writephy(tp, 0x10, 0x401f);
3464 rtl_writephy(tp, 0x19, 0x7030);
3465 rtl_writephy(tp, 0x1f, 0x0000);
3470 static const struct phy_reg phy_reg_init[] = {
3478 rtl_writephy(tp, 0x1f, 0x0000);
3479 rtl_writephy(tp, 0x18, 0x0310);
3482 rtl_apply_firmware(tp);
3485 rtl_writephy_batch(tp, phy_reg_init,
ARRAY_SIZE(phy_reg_init));
3490 static void rtl_hw_phy_config(
struct net_device *dev)
3494 rtl8169_print_mac_version(tp);
3501 rtl8169s_hw_phy_config(tp);
3504 rtl8169sb_hw_phy_config(tp);
3507 rtl8169scd_hw_phy_config(tp);
3510 rtl8169sce_hw_phy_config(tp);
3515 rtl8102e_hw_phy_config(tp);
3518 rtl8168bb_hw_phy_config(tp);
3521 rtl8168bef_hw_phy_config(tp);
3524 rtl8168bef_hw_phy_config(tp);
3527 rtl8168cp_1_hw_phy_config(tp);
3530 rtl8168c_1_hw_phy_config(tp);
3533 rtl8168c_2_hw_phy_config(tp);
3536 rtl8168c_3_hw_phy_config(tp);
3539 rtl8168c_4_hw_phy_config(tp);
3543 rtl8168cp_2_hw_phy_config(tp);
3546 rtl8168d_1_hw_phy_config(tp);
3549 rtl8168d_2_hw_phy_config(tp);
3552 rtl8168d_3_hw_phy_config(tp);
3555 rtl8168d_4_hw_phy_config(tp);
3559 rtl8105e_hw_phy_config(tp);
3566 rtl8168e_1_hw_phy_config(tp);
3569 rtl8168e_2_hw_phy_config(tp);
3572 rtl8168f_1_hw_phy_config(tp);
3575 rtl8168f_2_hw_phy_config(tp);
3579 rtl8402_hw_phy_config(tp);
3583 rtl8411_hw_phy_config(tp);
3587 rtl8106e_hw_phy_config(tp);
3591 rtl8168g_1_hw_phy_config(tp);
3634 static void rtl8169_phy_timer(
unsigned long __opaque)
3657 static void rtl8169_phy_reset(
struct net_device *dev,
3661 rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100);
3676 rtl_hw_phy_config(dev);
3679 dprintk(
"Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
3689 dprintk(
"Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
3691 dprintk(
"Set PHY Reg 0x0bh = 0x00h\n");
3692 rtl_writephy(tp, 0x0b, 0x0000);
3695 rtl8169_phy_reset(dev, tp);
3698 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3699 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
3700 (tp->
mii.supports_gmii ?
3701 ADVERTISED_1000baseT_Half |
3704 if (rtl_tbi_enabled(tp))
3714 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24);
3715 high = addr[4] | (addr[5] << 8);
3736 rtl_write_exgmac_batch(tp, e,
ARRAY_SIZE(e));
3741 rtl_unlock_work(tp);
3744 static int rtl_set_mac_address(
struct net_device *dev,
void *p)
3749 if (!is_valid_ether_addr(addr->
sa_data))
3759 static int rtl8169_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
3764 return netif_running(dev) ? tp->
do_ioctl(tp, data, cmd) : -
ENODEV;
3805 ops->
write = r8168dp_1_mdio_write;
3806 ops->
read = r8168dp_1_mdio_read;
3810 ops->
write = r8168dp_2_mdio_write;
3811 ops->
read = r8168dp_2_mdio_read;
3815 ops->
write = r8168g_mdio_write;
3816 ops->
read = r8168g_mdio_read;
3819 ops->
write = r8169_mdio_write;
3820 ops->
read = r8169_mdio_read;
3852 if (!(__rtl8169_get_wol(tp) &
WAKE_ANY))
3855 rtl_writephy(tp, 0x1f, 0x0000);
3856 rtl_writephy(tp,
MII_BMCR, 0x0000);
3858 rtl_wol_suspend_quirk(tp);
3865 rtl_writephy(tp, 0x1f, 0x0000);
3871 rtl_writephy(tp, 0x1f, 0x0000);
3879 if (rtl_wol_pll_power_down(tp))
3882 r810x_phy_power_down(tp);
3902 r810x_phy_power_up(tp);
3920 rtl_writephy(tp, 0x1f, 0x0000);
3937 rtl_writephy(tp, 0x0e, 0x0000);
3947 rtl_writephy(tp, 0x1f, 0x0000);
3969 rtl_writephy(tp, 0x0e, 0x0200);
3983 r8168dp_check_dash(tp)) {
3995 rtl_ephy_write(tp, 0x19, 0xff64);
3997 if (rtl_wol_pll_power_down(tp))
4000 r8168_phy_power_down(tp);
4031 r8168_phy_power_up(tp);
4065 ops->down = r810x_pll_power_down;
4066 ops->up = r810x_pll_power_up;
4092 ops->down = r8168_pll_power_down;
4093 ops->up = r8168_pll_power_up;
4150 rtl_generic_op(tp, tp->
jumbo_ops.enable);
4159 rtl_generic_op(tp, tp->
jumbo_ops.disable);
4217 rtl_tx_performance_tweak(tp->
pci_dev,
4223 rtl_tx_performance_tweak(tp->
pci_dev,
4231 r8168b_0_hw_jumbo_enable(tp);
4240 r8168b_0_hw_jumbo_disable(tp);
4251 ops->disable = r8168b_0_hw_jumbo_disable;
4252 ops->enable = r8168b_0_hw_jumbo_enable;
4256 ops->disable = r8168b_1_hw_jumbo_disable;
4257 ops->enable = r8168b_1_hw_jumbo_enable;
4268 ops->disable = r8168c_hw_jumbo_disable;
4269 ops->enable = r8168c_hw_jumbo_enable;
4273 ops->disable = r8168dp_hw_jumbo_disable;
4274 ops->enable = r8168dp_hw_jumbo_enable;
4280 ops->disable = r8168e_hw_jumbo_disable;
4281 ops->enable = r8168e_hw_jumbo_enable;
4291 ops->disable =
NULL;
4310 rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100);
4315 struct rtl_fw *rtl_fw;
4319 name = rtl_lookup_firmware_name(tp);
4321 goto out_no_firmware;
4323 rtl_fw = kzalloc(
sizeof(*rtl_fw),
GFP_KERNEL);
4331 rc = rtl_check_firmware(tp, rtl_fw);
4333 goto err_release_firmware;
4339 err_release_firmware:
4344 netif_warn(tp, ifup, tp->
dev,
"unable to load firmware patch %s (%d)\n",
4354 rtl_request_uncached_firmware(tp);
4383 rtl8169_irq_mask_and_ack(tp);
4390 rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42);
4399 rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666);
4408 static void rtl_set_rx_tx_config_registers(
struct rtl8169_private *tp)
4417 static void rtl_hw_start(
struct net_device *dev)
4423 rtl_irq_enable_all(tp);
4440 static u16 rtl_rw_cpluscmd(
void __iomem *ioaddr)
4449 static void rtl_set_rx_max_size(
void __iomem *ioaddr,
unsigned int rx_buf_sz)
4457 static const struct rtl_cfg2_info {
4467 const struct rtl_cfg2_info *p = cfg2_info;
4472 for (i = 0; i <
ARRAY_SIZE(cfg2_info); i++, p++) {
4473 if ((p->mac_version == mac_version) && (p->clk == clk)) {
4480 static void rtl_set_rx_mode(
struct net_device *dev)
4494 mc_filter[1] = mc_filter[0] = 0xffffffff;
4499 mc_filter[1] = mc_filter[0] = 0xffffffff;
4504 mc_filter[1] = mc_filter[0] = 0;
4507 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
4518 u32 data = mc_filter[0];
4520 mc_filter[0] =
swab32(mc_filter[1]);
4521 mc_filter[1] =
swab32(data);
4525 mc_filter[1] = mc_filter[0] = 0xffffffff;
4533 static void rtl_hw_start_8169(
struct net_device *dev)
4555 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
4561 rtl_set_rx_tx_config_registers(tp);
4567 dprintk(
"Set MAC Reg C+CR Offset 0xE0. "
4568 "Bit-3 and bit-14 MUST be 1\n");
4582 rtl_set_rx_tx_desc_registers(tp, ioaddr);
4589 rtl_set_rx_tx_config_registers(tp);
4599 rtl_set_rx_mode(dev);
4605 static void rtl_csi_write(
struct rtl8169_private *tp,
int addr,
int value)
4608 tp->
csi_ops.write(tp, addr, value);
4620 csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff;
4621 rtl_csi_write(tp, 0x070c, csi | bits);
4626 rtl_csi_access_enable(tp, 0x17000000);
4631 rtl_csi_access_enable(tp, 0x27000000);
4641 static void r8169_csi_write(
struct rtl8169_private *tp,
int addr,
int value)
4649 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100);
4659 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
4663 static void r8402_csi_write(
struct rtl8169_private *tp,
int addr,
int value)
4672 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100);
4682 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
4688 struct csi_ops *ops = &tp->
csi_ops;
4711 ops->write = r8402_csi_write;
4712 ops->read = r8402_csi_read;
4716 ops->write = r8169_csi_write;
4717 ops->read = r8169_csi_read;
4735 rtl_ephy_write(tp, e->
offset, w);
4740 static void rtl_disable_clock_request(
struct pci_dev *pdev)
4746 static void rtl_enable_clock_request(
struct pci_dev *pdev)
4752 #define R8168_CPCMD_QUIRK_MASK (\
4772 rtl_tx_performance_tweak(pdev,
4780 rtl_hw_start_8168bb(tp);
4798 rtl_disable_clock_request(pdev);
4805 static const struct ephy_info e_info_8168cp[] = {
4806 { 0x01, 0, 0x0001 },
4807 { 0x02, 0x0800, 0x1000 },
4808 { 0x03, 0, 0x0042 },
4809 { 0x06, 0x0080, 0x0000 },
4813 rtl_csi_access_enable_2(tp);
4815 rtl_ephy_init(tp, e_info_8168cp,
ARRAY_SIZE(e_info_8168cp));
4817 __rtl_hw_start_8168cp(tp);
4825 rtl_csi_access_enable_2(tp);
4839 rtl_csi_access_enable_2(tp);
4856 static const struct ephy_info e_info_8168c_1[] = {
4857 { 0x02, 0x0800, 0x1000 },
4858 { 0x03, 0, 0x0002 },
4859 { 0x06, 0x0080, 0x0000 }
4862 rtl_csi_access_enable_2(tp);
4866 rtl_ephy_init(tp, e_info_8168c_1,
ARRAY_SIZE(e_info_8168c_1));
4868 __rtl_hw_start_8168cp(tp);
4873 static const struct ephy_info e_info_8168c_2[] = {
4874 { 0x01, 0, 0x0001 },
4875 { 0x03, 0x0400, 0x0220 }
4878 rtl_csi_access_enable_2(tp);
4880 rtl_ephy_init(tp, e_info_8168c_2,
ARRAY_SIZE(e_info_8168c_2));
4882 __rtl_hw_start_8168cp(tp);
4887 rtl_hw_start_8168c_2(tp);
4892 rtl_csi_access_enable_2(tp);
4894 __rtl_hw_start_8168cp(tp);
4902 rtl_csi_access_enable_2(tp);
4904 rtl_disable_clock_request(pdev);
4918 rtl_csi_access_enable_1(tp);
4924 rtl_disable_clock_request(pdev);
4931 static const struct ephy_info e_info_8168d_4[] = {
4933 { 0x19, 0x20, 0x50 },
4938 rtl_csi_access_enable_1(tp);
4944 for (i = 0; i <
ARRAY_SIZE(e_info_8168d_4); i++) {
4948 w = rtl_ephy_read(tp, e->
offset);
4949 rtl_ephy_write(tp, 0x03, (w & e->
mask) | e->
bits);
4952 rtl_enable_clock_request(pdev);
4959 static const struct ephy_info e_info_8168e_1[] = {
4960 { 0x00, 0x0200, 0x0100 },
4961 { 0x00, 0x0000, 0x0004 },
4962 { 0x06, 0x0002, 0x0001 },
4963 { 0x06, 0x0000, 0x0030 },
4964 { 0x07, 0x0000, 0x2000 },
4965 { 0x00, 0x0000, 0x0020 },
4966 { 0x03, 0x5800, 0x2000 },
4967 { 0x03, 0x0000, 0x0001 },
4968 { 0x01, 0x0800, 0x1000 },
4969 { 0x07, 0x0000, 0x4000 },
4970 { 0x1e, 0x0000, 0x2000 },
4971 { 0x19, 0xffff, 0xfe6c },
4972 { 0x0a, 0x0000, 0x0040 }
4975 rtl_csi_access_enable_2(tp);
4977 rtl_ephy_init(tp, e_info_8168e_1,
ARRAY_SIZE(e_info_8168e_1));
4983 rtl_disable_clock_request(pdev);
4996 static const struct ephy_info e_info_8168e_2[] = {
4997 { 0x09, 0x0000, 0x0080 },
4998 { 0x19, 0x0000, 0x0224 }
5001 rtl_csi_access_enable_1(tp);
5003 rtl_ephy_init(tp, e_info_8168e_2,
ARRAY_SIZE(e_info_8168e_2));
5018 rtl_disable_clock_request(pdev);
5036 rtl_csi_access_enable_2(tp);
5053 rtl_disable_clock_request(pdev);
5065 static const struct ephy_info e_info_8168f_1[] = {
5066 { 0x06, 0x00c0, 0x0020 },
5067 { 0x08, 0x0001, 0x0002 },
5068 { 0x09, 0x0000, 0x0080 },
5069 { 0x19, 0x0000, 0x0224 }
5072 rtl_hw_start_8168f(tp);
5074 rtl_ephy_init(tp, e_info_8168f_1,
ARRAY_SIZE(e_info_8168f_1));
5084 static const struct ephy_info e_info_8168f_1[] = {
5085 { 0x06, 0x00c0, 0x0020 },
5086 { 0x0f, 0xffff, 0x5200 },
5087 { 0x1e, 0x0000, 0x4000 },
5088 { 0x19, 0x0000, 0x0224 }
5091 rtl_hw_start_8168f(tp);
5093 rtl_ephy_init(tp, e_info_8168f_1,
ARRAY_SIZE(e_info_8168f_1));
5108 rtl_csi_access_enable_1(tp);
5128 static void rtl_hw_start_8168(
struct net_device *dev)
5137 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
5151 rtl_set_rx_tx_desc_registers(tp, ioaddr);
5153 rtl_set_rx_mode(dev);
5162 rtl_hw_start_8168bb(tp);
5167 rtl_hw_start_8168bef(tp);
5171 rtl_hw_start_8168cp_1(tp);
5175 rtl_hw_start_8168c_1(tp);
5179 rtl_hw_start_8168c_2(tp);
5183 rtl_hw_start_8168c_3(tp);
5187 rtl_hw_start_8168c_4(tp);
5191 rtl_hw_start_8168cp_2(tp);
5195 rtl_hw_start_8168cp_3(tp);
5201 rtl_hw_start_8168d(tp);
5205 rtl_hw_start_8168d_4(tp);
5209 rtl_hw_start_8168dp(tp);
5214 rtl_hw_start_8168e_1(tp);
5217 rtl_hw_start_8168e_2(tp);
5222 rtl_hw_start_8168f_1(tp);
5226 rtl_hw_start_8411(tp);
5231 rtl_hw_start_8168g_1(tp);
5247 #define R810X_CPCMD_QUIRK_MASK (\
5262 static const struct ephy_info e_info_8102e_1[] = {
5263 { 0x01, 0, 0x6e65 },
5264 { 0x02, 0, 0x091f },
5265 { 0x03, 0, 0xc2f9 },
5266 { 0x06, 0, 0xafb5 },
5267 { 0x07, 0, 0x0e00 },
5268 { 0x19, 0, 0xec80 },
5269 { 0x01, 0, 0x2e65 },
5274 rtl_csi_access_enable_2(tp);
5288 rtl_ephy_init(tp, e_info_8102e_1,
ARRAY_SIZE(e_info_8102e_1));
5296 rtl_csi_access_enable_2(tp);
5306 rtl_hw_start_8102e_2(tp);
5308 rtl_ephy_write(tp, 0x03, 0xc2f9);
5314 static const struct ephy_info e_info_8105e_1[] = {
5315 { 0x07, 0, 0x4000 },
5316 { 0x19, 0, 0x0200 },
5317 { 0x19, 0, 0x0020 },
5318 { 0x1e, 0, 0x2000 },
5319 { 0x03, 0, 0x0001 },
5320 { 0x19, 0, 0x0100 },
5321 { 0x19, 0, 0x0004 },
5334 rtl_ephy_init(tp, e_info_8105e_1,
ARRAY_SIZE(e_info_8105e_1));
5339 rtl_hw_start_8105e_1(tp);
5340 rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000);
5346 static const struct ephy_info e_info_8402[] = {
5347 { 0x19, 0xffff, 0xff64 },
5351 rtl_csi_access_enable_2(tp);
5359 rtl_ephy_init(tp, e_info_8402,
ARRAY_SIZE(e_info_8402));
5384 static void rtl_hw_start_8101(
struct net_device *dev)
5402 rtl_hw_start_8102e_1(tp);
5406 rtl_hw_start_8102e_3(tp);
5410 rtl_hw_start_8102e_2(tp);
5414 rtl_hw_start_8105e_1(tp);
5417 rtl_hw_start_8105e_2(tp);
5421 rtl_hw_start_8402(tp);
5425 rtl_hw_start_8106(tp);
5433 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
5440 rtl_set_rx_tx_desc_registers(tp, ioaddr);
5443 rtl_set_rx_tx_config_registers(tp);
5447 rtl_set_rx_mode(dev);
5452 static int rtl8169_change_mtu(
struct net_device *dev,
int new_mtu)
5457 new_mtu > rtl_chip_infos[tp->
mac_version].jumbo_max)
5461 rtl_hw_jumbo_enable(tp);
5463 rtl_hw_jumbo_disable(tp);
5471 static inline void rtl8169_make_unusable_by_asic(
struct RxDesc *desc)
5478 void **data_buff,
struct RxDesc *desc)
5485 rtl8169_make_unusable_by_asic(desc);
5488 static inline void rtl8169_mark_to_asic(
struct RxDesc *desc,
u32 rx_buf_sz)
5500 rtl8169_mark_to_asic(desc, rx_buf_sz);
5503 static inline void *rtl8169_align(
void *data)
5505 return (
void *)
ALIGN((
long)data, 16);
5515 int node = dev->
dev.parent ? dev_to_node(dev->
dev.parent) : -1;
5517 data = kmalloc_node(rx_buf_sz,
GFP_KERNEL, node);
5521 if (rtl8169_align(data) != data) {
5523 data = kmalloc_node(rx_buf_sz + 15,
GFP_KERNEL, node);
5532 netif_err(tp, drv, tp->
dev,
"Failed to map RX DMA!\n");
5536 rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
5556 static inline void rtl8169_mark_as_last_descriptor(
struct RxDesc *desc)
5571 data = rtl8169_alloc_rx_data(tp, tp->
RxDescArray + i);
5573 rtl8169_make_unusable_by_asic(tp->
RxDescArray + i);
5579 rtl8169_mark_as_last_descriptor(tp->
RxDescArray + NUM_RX_DESC - 1);
5583 rtl8169_rx_clear(tp);
5587 static int rtl8169_init_ring(
struct net_device *dev)
5591 rtl8169_init_ring_indexes(tp);
5596 return rtl8169_rx_fill(tp);
5602 unsigned int len = tx_skb->
len;
5617 for (i = 0; i <
n; i++) {
5620 unsigned int len = tx_skb->
len;
5625 rtl8169_unmap_tx_skb(&tp->
pci_dev->dev, tx_skb,
5628 tp->
dev->stats.tx_dropped++;
5647 napi_disable(&tp->
napi);
5648 netif_stop_queue(dev);
5651 rtl8169_hw_reset(tp);
5654 rtl8169_mark_to_asic(tp->
RxDescArray + i, rx_buf_sz);
5656 rtl8169_tx_clear(tp);
5657 rtl8169_init_ring_indexes(tp);
5659 napi_enable(&tp->
napi);
5661 netif_wake_queue(dev);
5662 rtl8169_check_link_status(dev, tp, tp->
mmio_addr);
5665 static void rtl8169_tx_timeout(
struct net_device *dev)
5676 unsigned int cur_frag,
entry;
5681 for (cur_frag = 0; cur_frag < info->
nr_frags; cur_frag++) {
5690 len = skb_frag_size(frag);
5691 addr = skb_frag_address(frag);
5696 "Failed to map TX fragments DMA!\n");
5701 status = opts[0] | len |
5719 rtl8169_tx_clear_range(tp, tp->
cur_tx + 1, cur_frag);
5726 const struct rtl_tx_desc_info *info = tx_desc_info + tp->
txd_version;
5727 u32 mss = skb_shinfo(skb)->gso_size;
5728 int offset = info->opts_offset;
5734 const struct iphdr *
ip = ip_hdr(skb);
5737 opts[
offset] |= info->checksum.tcp;
5739 opts[
offset] |= info->checksum.udp;
5759 netif_err(tp, drv, dev,
"BUG! Tx Ring full when queue awake!\n");
5766 len = skb_headlen(skb);
5770 netif_err(tp, drv, dev,
"Failed to map TX DMA!\n");
5777 opts[1] =
cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
5780 rtl8169_tso_csum(tp, skb, opts);
5782 frags = rtl8169_xmit_frags(tp, skb, opts);
5794 skb_tx_timestamp(skb);
5815 netif_stop_queue(dev);
5825 netif_wake_queue(dev);
5831 rtl8169_unmap_tx_skb(d, tp->
tx_skb + entry, txd);
5834 dev->
stats.tx_dropped++;
5838 netif_stop_queue(dev);
5839 dev->
stats.tx_dropped++;
5843 static void rtl8169_pcierr_interrupt(
struct net_device *dev)
5847 u16 pci_status, pci_cmd;
5849 pci_read_config_word(pdev,
PCI_COMMAND, &pci_cmd);
5850 pci_read_config_word(pdev,
PCI_STATUS, &pci_status);
5852 netif_err(tp,
intr, dev,
"PCI error (cmd = 0x%04x, status = 0x%04x)\n",
5853 pci_cmd, pci_status);
5868 pci_write_config_word(pdev,
PCI_COMMAND, pci_cmd);
5885 rtl8169_hw_reset(tp);
5892 unsigned int dirty_tx, tx_left;
5896 tx_left = tp->
cur_tx - dirty_tx;
5898 while (tx_left > 0) {
5908 rtl8169_unmap_tx_skb(&tp->
pci_dev->dev, tx_skb,
5911 u64_stats_update_begin(&tp->
tx_stats.syncp);
5914 u64_stats_update_end(&tp->
tx_stats.syncp);
5915 dev_kfree_skb(tx_skb->
skb);
5932 if (netif_queue_stopped(dev) &&
5934 netif_wake_queue(dev);
5942 if (tp->
cur_tx != dirty_tx) {
5950 static inline int rtl8169_fragmented_frame(
u32 status)
5955 static inline void rtl8169_rx_csum(
struct sk_buff *skb,
u32 opts1)
5963 skb_checksum_none_assert(skb);
5966 static struct sk_buff *rtl8169_try_rx_copy(
void *data,
5974 data = rtl8169_align(data);
5977 skb = netdev_alloc_skb_ip_align(tp->
dev, pkt_size);
5987 unsigned int cur_rx, rx_left;
5991 rx_left = NUM_RX_DESC + tp->
dirty_rx - cur_rx;
5992 rx_left =
min(rx_left, budget);
5994 for (; rx_left > 0; rx_left--, cur_rx++) {
6002 if (status & DescOwn)
6005 netif_info(tp, rx_err, dev,
"Rx ERROR. status = %08x\n",
6007 dev->
stats.rx_errors++;
6009 dev->
stats.rx_length_errors++;
6011 dev->
stats.rx_crc_errors++;
6014 dev->
stats.rx_fifo_errors++;
6016 if ((status & (
RxRUNT | RxCRC)) &&
6017 !(status & (
RxRWT | RxFOVF)) &&
6021 rtl8169_mark_to_asic(desc, rx_buf_sz);
6030 pkt_size = (status & 0x00003fff) - 4;
6032 pkt_size = status & 0x00003fff;
6039 if (
unlikely(rtl8169_fragmented_frame(status))) {
6040 dev->
stats.rx_dropped++;
6041 dev->
stats.rx_length_errors++;
6042 rtl8169_mark_to_asic(desc, rx_buf_sz);
6047 tp, pkt_size, addr);
6048 rtl8169_mark_to_asic(desc, rx_buf_sz);
6050 dev->
stats.rx_dropped++;
6054 rtl8169_rx_csum(skb, status);
6058 rtl8169_rx_vlan_tag(desc, skb);
6062 u64_stats_update_begin(&tp->
rx_stats.syncp);
6065 u64_stats_update_end(&tp->
rx_stats.syncp);
6076 count = cur_rx - tp->
cur_rx;
6084 static irqreturn_t rtl8169_interrupt(
int irq,
void *dev_instance)
6091 status = rtl_get_events(tp);
6092 if (status && status != 0xffff) {
6097 rtl_irq_disable(tp);
6098 napi_schedule(&tp->
napi);
6112 status = rtl_get_events(tp) & tp->
event_slow;
6113 rtl_ack_events(tp, status);
6119 netif_stop_queue(dev);
6128 rtl8169_pcierr_interrupt(dev);
6131 __rtl8169_check_link_status(dev, tp, tp->
mmio_addr,
true);
6133 rtl_irq_enable_all(tp);
6138 static const struct {
6154 if (!netif_running(dev) ||
6163 rtl_work[
i].action(tp);
6167 rtl_unlock_work(tp);
6178 status = rtl_get_events(tp);
6179 rtl_ack_events(tp, status & ~tp->
event_slow);
6182 work_done = rtl_rx(dev, tp, (
u32) budget);
6193 if (work_done < budget) {
6196 rtl_irq_enable(tp, enable_mask);
6214 static void rtl8169_down(
struct net_device *dev)
6221 napi_disable(&tp->
napi);
6222 netif_stop_queue(dev);
6224 rtl8169_hw_reset(tp);
6230 rtl8169_rx_missed(dev, ioaddr);
6235 rtl8169_tx_clear(tp);
6237 rtl8169_rx_clear(tp);
6239 rtl_pll_power_down(tp);
6242 static int rtl8169_close(
struct net_device *dev)
6247 pm_runtime_get_sync(&pdev->
dev);
6250 rtl8169_update_counters(dev);
6256 rtl_unlock_work(tp);
6267 pm_runtime_put_sync(&pdev->
dev);
6272 #ifdef CONFIG_NET_POLL_CONTROLLER
6273 static void rtl8169_netpoll(
struct net_device *dev)
6277 rtl8169_interrupt(tp->
pci_dev->irq, dev);
6288 pm_runtime_get_sync(&pdev->
dev);
6297 goto err_pm_runtime_put;
6304 retval = rtl8169_init_ring(dev);
6312 rtl_request_firmware(tp);
6318 goto err_release_fw_2;
6324 napi_enable(&tp->
napi);
6326 rtl8169_init_phy(dev, tp);
6328 __rtl8169_set_features(dev, dev->
features);
6330 rtl_pll_power_up(tp);
6334 netif_start_queue(dev);
6336 rtl_unlock_work(tp);
6339 pm_runtime_put_noidle(&pdev->
dev);
6341 rtl8169_check_link_status(dev, tp, ioaddr);
6346 rtl_release_firmware(tp);
6347 rtl8169_rx_clear(tp);
6357 pm_runtime_put_noidle(&pdev->
dev);
6368 if (netif_running(dev))
6369 rtl8169_rx_missed(dev, ioaddr);
6372 start = u64_stats_fetch_begin_bh(&tp->
rx_stats.syncp);
6375 }
while (u64_stats_fetch_retry_bh(&tp->
rx_stats.syncp, start));
6379 start = u64_stats_fetch_begin_bh(&tp->
tx_stats.syncp);
6382 }
while (u64_stats_fetch_retry_bh(&tp->
tx_stats.syncp, start));
6395 static void rtl8169_net_suspend(
struct net_device *dev)
6399 if (!netif_running(dev))
6403 netif_stop_queue(dev);
6406 napi_disable(&tp->
napi);
6408 rtl_unlock_work(tp);
6410 rtl_pll_power_down(tp);
6418 struct net_device *dev = pci_get_drvdata(pdev);
6420 rtl8169_net_suspend(dev);
6425 static void __rtl8169_resume(
struct net_device *dev)
6431 rtl_pll_power_up(tp);
6434 napi_enable(&tp->
napi);
6436 rtl_unlock_work(tp);
6444 struct net_device *dev = pci_get_drvdata(pdev);
6447 rtl8169_init_phy(dev, tp);
6449 if (netif_running(dev))
6450 __rtl8169_resume(dev);
6455 static int rtl8169_runtime_suspend(
struct device *device)
6458 struct net_device *dev = pci_get_drvdata(pdev);
6467 rtl_unlock_work(tp);
6469 rtl8169_net_suspend(dev);
6474 static int rtl8169_runtime_resume(
struct device *device)
6477 struct net_device *dev = pci_get_drvdata(pdev);
6486 rtl_unlock_work(tp);
6488 rtl8169_init_phy(dev, tp);
6490 __rtl8169_resume(dev);
6495 static int rtl8169_runtime_idle(
struct device *device)
6498 struct net_device *dev = pci_get_drvdata(pdev);
6504 static const struct dev_pm_ops rtl8169_pm_ops = {
6506 .resume = rtl8169_resume,
6507 .freeze = rtl8169_suspend,
6508 .thaw = rtl8169_resume,
6509 .poweroff = rtl8169_suspend,
6510 .restore = rtl8169_resume,
6511 .runtime_suspend = rtl8169_runtime_suspend,
6512 .runtime_resume = rtl8169_runtime_resume,
6513 .runtime_idle = rtl8169_runtime_idle,
6516 #define RTL8169_PM_OPS (&rtl8169_pm_ops)
6520 #define RTL8169_PM_OPS NULL
6544 static void rtl_shutdown(
struct pci_dev *pdev)
6546 struct net_device *dev = pci_get_drvdata(pdev);
6548 struct device *d = &pdev->
dev;
6550 pm_runtime_get_sync(d);
6552 rtl8169_net_suspend(dev);
6557 rtl8169_hw_reset(tp);
6560 if (__rtl8169_get_wol(tp) &
WAKE_ANY) {
6561 rtl_wol_suspend_quirk(tp);
6562 rtl_wol_shutdown_quirk(tp);
6569 pm_runtime_put_noidle(d);
6574 struct net_device *dev = pci_get_drvdata(pdev);
6580 rtl8168_driver_stop(tp);
6589 rtl_release_firmware(tp);
6592 pm_runtime_get_noresume(&pdev->
dev);
6597 rtl_disable_msi(pdev, tp);
6598 rtl8169_release_board(pdev, dev, tp->
mmio_addr);
6599 pci_set_drvdata(pdev,
NULL);
6603 .ndo_open = rtl_open,
6604 .ndo_stop = rtl8169_close,
6605 .ndo_get_stats64 = rtl8169_get_stats64,
6606 .ndo_start_xmit = rtl8169_start_xmit,
6607 .ndo_tx_timeout = rtl8169_tx_timeout,
6609 .ndo_change_mtu = rtl8169_change_mtu,
6610 .ndo_fix_features = rtl8169_fix_features,
6611 .ndo_set_features = rtl8169_set_features,
6612 .ndo_set_mac_address = rtl_set_mac_address,
6613 .ndo_do_ioctl = rtl8169_ioctl,
6614 .ndo_set_rx_mode = rtl_set_rx_mode,
6615 #ifdef CONFIG_NET_POLL_CONTROLLER
6616 .ndo_poll_controller = rtl8169_netpoll,
6621 static const struct rtl_cfg_info {
6628 } rtl_cfg_infos [] = {
6630 .hw_start = rtl_hw_start_8169,
6638 .hw_start = rtl_hw_start_8168,
6646 .hw_start = rtl_hw_start_8101,
6658 const struct rtl_cfg_info *
cfg)
6666 if (pci_enable_msi(tp->
pci_dev)) {
6701 if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42))
6704 if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
6711 data = r8168_mac_ocp_read(tp, 0xe8de);
6713 r8168_mac_ocp_write(tp, 0xe8de, data);
6715 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
6718 data = r8168_mac_ocp_read(tp, 0xe8de);
6720 r8168_mac_ocp_write(tp, 0xe8de, data);
6722 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
6731 rtl_hw_init_8168g(tp);
6742 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->
driver_data;
6743 const unsigned int region = cfg->region;
6756 dev = alloc_etherdev(
sizeof (*tp));
6764 tp = netdev_priv(dev);
6785 netif_err(tp, probe, dev,
"enable failure\n");
6786 goto err_out_free_dev_1;
6790 netif_info(tp, probe, dev,
"Mem-Wr-Inval unavailable\n");
6795 "region #%d not an MMIO resource, aborting\n",
6804 "Invalid PCI region size(s), aborting\n");
6811 netif_err(tp, probe, dev,
"could not request regions\n");
6824 netif_err(tp, probe, dev,
"DMA configuration failed\n");
6825 goto err_out_free_res_3;
6832 netif_err(tp, probe, dev,
"cannot remap MMIO, aborting\n");
6834 goto err_out_free_res_3;
6838 if (!pci_is_pcie(pdev))
6839 netif_info(tp, probe, dev,
"not PCI Express\n");
6842 rtl8169_get_mac_version(tp, dev, cfg->default_ver);
6846 rtl_irq_disable(tp);
6848 rtl_hw_initialize(tp);
6852 rtl_ack_events(tp, 0xffff);
6863 rtl_init_mdio_ops(tp);
6864 rtl_init_pll_power_ops(tp);
6865 rtl_init_jumbo_ops(tp);
6866 rtl_init_csi_ops(tp);
6868 rtl8169_print_mac_version(tp);
6880 tp->
features |= rtl_try_msi(tp, cfg);
6883 if (rtl_tbi_enabled(tp)) {
6888 tp->
link_ok = rtl8169_tbi_link_ok;
6895 tp->
link_ok = rtl8169_xmii_link_ok;
6936 tp->
timer.function = rtl8169_phy_timer;
6944 pci_set_drvdata(pdev, dev);
6946 netif_info(tp, probe, dev,
"%s at 0x%p, %pM, XID %08x IRQ %d\n",
6947 rtl_chip_infos[chipset].name, ioaddr, dev->
dev_addr,
6950 netif_info(tp, probe, dev,
"jumbo features [frames: %d bytes, "
6951 "tx checksumming: %s]\n",
6959 rtl8168_driver_start(tp);
6965 pm_runtime_put_noidle(&pdev->
dev);
6974 rtl_disable_msi(pdev, tp);
6986 static struct pci_driver rtl8169_pci_driver = {
6988 .id_table = rtl8169_pci_tbl,
6989 .probe = rtl_init_one,
6991 .shutdown = rtl_shutdown,
6995 static int __init rtl8169_init_module(
void)
6997 return pci_register_driver(&rtl8169_pci_driver);
7000 static void __exit rtl8169_cleanup_module(
void)