2 * r8169.c: RealTek 8169/8168/8101 ethernet driver.
4 * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
5 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
6 * Copyright (c) a lot of people too. Please respect their work.
8 * See MAINTAINERS file for support contact information.
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/pci.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/delay.h>
17 #include <linux/ethtool.h>
18 #include <linux/mii.h>
19 #include <linux/if_vlan.h>
20 #include <linux/crc32.h>
23 #include <linux/tcp.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/firmware.h>
29 #include <linux/pci-aspm.h>
30 #include <linux/prefetch.h>
32 #include <asm/system.h>
36 #define RTL8169_VERSION "2.3LK-NAPI"
37 #define MODULENAME "r8169"
38 #define PFX MODULENAME ": "
40 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw"
41 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw"
42 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw"
43 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw"
44 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw"
47 #define assert(expr) \
49 printk( "Assertion failed! %s,%s,%s,line=%d\n", \
50 #expr,__FILE__,__func__,__LINE__); \
52 #define dprintk(fmt, args...) \
53 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0)
55 #define assert(expr) do {} while (0)
56 #define dprintk(fmt, args...) do {} while (0)
57 #endif /* RTL8169_DEBUG */
59 #define R8169_MSG_DEFAULT \
60 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
62 #define TX_BUFFS_AVAIL(tp) \
63 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
65 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
66 The RTL chips use a 64 element hash table based on the Ethernet CRC. */
67 static const int multicast_filter_limit = 32;
69 /* MAC address length */
70 #define MAC_ADDR_LEN 6
72 #define MAX_READ_REQUEST_SHIFT 12
73 #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */
74 #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
75 #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */
76 #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */
77 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
79 #define R8169_REGS_SIZE 256
80 #define R8169_NAPI_WEIGHT 64
81 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */
82 #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */
83 #define RX_BUF_SIZE 1536 /* Rx Buffer size */
84 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
85 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
87 #define RTL8169_TX_TIMEOUT (6*HZ)
88 #define RTL8169_PHY_TIMEOUT (10*HZ)
90 #define RTL_EEPROM_SIG cpu_to_le32(0x8129)
91 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff)
92 #define RTL_EEPROM_SIG_ADDR 0x0000
94 /* write/read MMIO register */
95 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg))
96 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg))
97 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg))
98 #define RTL_R8(reg) readb (ioaddr + (reg))
99 #define RTL_R16(reg) readw (ioaddr + (reg))
100 #define RTL_R32(reg) readl (ioaddr + (reg))
103 RTL_GIGA_MAC_VER_01 = 0,
136 RTL_GIGA_MAC_NONE = 0xff,
139 enum rtl_tx_desc_version {
144 #define _R(NAME,TD,FW) \
145 { .name = NAME, .txd_version = TD, .fw_name = FW }
147 static const struct {
149 enum rtl_tx_desc_version txd_version;
151 } rtl_chip_infos[] = {
153 [RTL_GIGA_MAC_VER_01] =
154 _R("RTL8169", RTL_TD_0, NULL),
155 [RTL_GIGA_MAC_VER_02] =
156 _R("RTL8169s", RTL_TD_0, NULL),
157 [RTL_GIGA_MAC_VER_03] =
158 _R("RTL8110s", RTL_TD_0, NULL),
159 [RTL_GIGA_MAC_VER_04] =
160 _R("RTL8169sb/8110sb", RTL_TD_0, NULL),
161 [RTL_GIGA_MAC_VER_05] =
162 _R("RTL8169sc/8110sc", RTL_TD_0, NULL),
163 [RTL_GIGA_MAC_VER_06] =
164 _R("RTL8169sc/8110sc", RTL_TD_0, NULL),
166 [RTL_GIGA_MAC_VER_07] =
167 _R("RTL8102e", RTL_TD_1, NULL),
168 [RTL_GIGA_MAC_VER_08] =
169 _R("RTL8102e", RTL_TD_1, NULL),
170 [RTL_GIGA_MAC_VER_09] =
171 _R("RTL8102e", RTL_TD_1, NULL),
172 [RTL_GIGA_MAC_VER_10] =
173 _R("RTL8101e", RTL_TD_0, NULL),
174 [RTL_GIGA_MAC_VER_11] =
175 _R("RTL8168b/8111b", RTL_TD_0, NULL),
176 [RTL_GIGA_MAC_VER_12] =
177 _R("RTL8168b/8111b", RTL_TD_0, NULL),
178 [RTL_GIGA_MAC_VER_13] =
179 _R("RTL8101e", RTL_TD_0, NULL),
180 [RTL_GIGA_MAC_VER_14] =
181 _R("RTL8100e", RTL_TD_0, NULL),
182 [RTL_GIGA_MAC_VER_15] =
183 _R("RTL8100e", RTL_TD_0, NULL),
184 [RTL_GIGA_MAC_VER_16] =
185 _R("RTL8101e", RTL_TD_0, NULL),
186 [RTL_GIGA_MAC_VER_17] =
187 _R("RTL8168b/8111b", RTL_TD_0, NULL),
188 [RTL_GIGA_MAC_VER_18] =
189 _R("RTL8168cp/8111cp", RTL_TD_1, NULL),
190 [RTL_GIGA_MAC_VER_19] =
191 _R("RTL8168c/8111c", RTL_TD_1, NULL),
192 [RTL_GIGA_MAC_VER_20] =
193 _R("RTL8168c/8111c", RTL_TD_1, NULL),
194 [RTL_GIGA_MAC_VER_21] =
195 _R("RTL8168c/8111c", RTL_TD_1, NULL),
196 [RTL_GIGA_MAC_VER_22] =
197 _R("RTL8168c/8111c", RTL_TD_1, NULL),
198 [RTL_GIGA_MAC_VER_23] =
199 _R("RTL8168cp/8111cp", RTL_TD_1, NULL),
200 [RTL_GIGA_MAC_VER_24] =
201 _R("RTL8168cp/8111cp", RTL_TD_1, NULL),
202 [RTL_GIGA_MAC_VER_25] =
203 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1),
204 [RTL_GIGA_MAC_VER_26] =
205 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2),
206 [RTL_GIGA_MAC_VER_27] =
207 _R("RTL8168dp/8111dp", RTL_TD_1, NULL),
208 [RTL_GIGA_MAC_VER_28] =
209 _R("RTL8168dp/8111dp", RTL_TD_1, NULL),
210 [RTL_GIGA_MAC_VER_29] =
211 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1),
212 [RTL_GIGA_MAC_VER_30] =
213 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1),
214 [RTL_GIGA_MAC_VER_31] =
215 _R("RTL8168dp/8111dp", RTL_TD_1, NULL),
216 [RTL_GIGA_MAC_VER_32] =
217 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1),
218 [RTL_GIGA_MAC_VER_33] =
219 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2)
229 static void rtl_hw_start_8169(struct net_device *);
230 static void rtl_hw_start_8168(struct net_device *);
231 static void rtl_hw_start_8101(struct net_device *);
233 static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = {
234 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
235 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
236 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
237 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
238 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
239 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 },
240 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 },
241 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 },
242 { PCI_VENDOR_ID_LINKSYS, 0x1032,
243 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
245 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
249 MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
251 static int rx_buf_sz = 16383;
258 MAC0 = 0, /* Ethernet hardware address. */
260 MAR0 = 8, /* Multicast filter. */
261 CounterAddrLow = 0x10,
262 CounterAddrHigh = 0x14,
263 TxDescStartAddrLow = 0x20,
264 TxDescStartAddrHigh = 0x24,
265 TxHDescStartAddrLow = 0x28,
266 TxHDescStartAddrHigh = 0x2c,
276 #define RTL_RX_CONFIG_MASK 0xff7e1880u
292 RxDescAddrLow = 0xe4,
293 RxDescAddrHigh = 0xe8,
294 EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */
296 #define NoEarlyTx 0x3f /* Max value : no early transmit. */
298 MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */
300 #define TxPacketMax (8064 >> 7)
303 FuncEventMask = 0xf4,
304 FuncPresetState = 0xf8,
305 FuncForceEvent = 0xfc,
308 enum rtl8110_registers {
314 enum rtl8168_8101_registers {
317 #define CSIAR_FLAG 0x80000000
318 #define CSIAR_WRITE_CMD 0x80000000
319 #define CSIAR_BYTE_ENABLE 0x0f
320 #define CSIAR_BYTE_ENABLE_SHIFT 12
321 #define CSIAR_ADDR_MASK 0x0fff
324 #define EPHYAR_FLAG 0x80000000
325 #define EPHYAR_WRITE_CMD 0x80000000
326 #define EPHYAR_REG_MASK 0x1f
327 #define EPHYAR_REG_SHIFT 16
328 #define EPHYAR_DATA_MASK 0xffff
330 #define PM_SWITCH (1 << 6)
332 #define FIX_NAK_1 (1 << 4)
333 #define FIX_NAK_2 (1 << 3)
336 #define EN_NDP (1 << 3)
337 #define EN_OOB_RESET (1 << 2)
339 #define EFUSEAR_FLAG 0x80000000
340 #define EFUSEAR_WRITE_CMD 0x80000000
341 #define EFUSEAR_READ_CMD 0x00000000
342 #define EFUSEAR_REG_MASK 0x03ff
343 #define EFUSEAR_REG_SHIFT 8
344 #define EFUSEAR_DATA_MASK 0xff
347 enum rtl8168_registers {
350 #define ERIAR_FLAG 0x80000000
351 #define ERIAR_WRITE_CMD 0x80000000
352 #define ERIAR_READ_CMD 0x00000000
353 #define ERIAR_ADDR_BYTE_ALIGN 4
354 #define ERIAR_EXGMAC 0
357 #define ERIAR_TYPE_SHIFT 16
358 #define ERIAR_BYTEEN 0x0f
359 #define ERIAR_BYTEEN_SHIFT 12
360 EPHY_RXER_NUM = 0x7c,
361 OCPDR = 0xb0, /* OCP GPHY access */
362 #define OCPDR_WRITE_CMD 0x80000000
363 #define OCPDR_READ_CMD 0x00000000
364 #define OCPDR_REG_MASK 0x7f
365 #define OCPDR_GPHY_REG_SHIFT 16
366 #define OCPDR_DATA_MASK 0xffff
368 #define OCPAR_FLAG 0x80000000
369 #define OCPAR_GPHY_WRITE_CMD 0x8000f060
370 #define OCPAR_GPHY_READ_CMD 0x0000f060
371 RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */
372 MISC = 0xf0, /* 8168e only. */
373 #define TXPLA_RST (1 << 29)
376 enum rtl_register_content {
377 /* InterruptStatusBits */
381 TxDescUnavail = 0x0080,
403 /* TXPoll register p.5 */
404 HPQ = 0x80, /* Poll cmd on the high prio queue */
405 NPQ = 0x40, /* Poll cmd on the low prio queue */
406 FSWInt = 0x01, /* Forced software interrupt */
410 Cfg9346_Unlock = 0xc0,
415 AcceptBroadcast = 0x08,
416 AcceptMulticast = 0x04,
418 AcceptAllPhys = 0x01,
425 TxInterFrameGapShift = 24,
426 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
428 /* Config1 register p.24 */
431 MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */
432 Speed_down = (1 << 4),
436 PMEnable = (1 << 0), /* Power Management Enable */
438 /* Config2 register p. 25 */
439 PCI_Clock_66MHz = 0x01,
440 PCI_Clock_33MHz = 0x00,
442 /* Config3 register p.25 */
443 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */
444 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
445 Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */
447 /* Config5 register p.27 */
448 BWF = (1 << 6), /* Accept Broadcast wakeup frame */
449 MWF = (1 << 5), /* Accept Multicast wakeup frame */
450 UWF = (1 << 4), /* Accept Unicast wakeup frame */
452 LanWake = (1 << 1), /* LanWake enable/disable */
453 PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */
456 TBIReset = 0x80000000,
457 TBILoopback = 0x40000000,
458 TBINwEnable = 0x20000000,
459 TBINwRestart = 0x10000000,
460 TBILinkOk = 0x02000000,
461 TBINwComplete = 0x01000000,
464 EnableBist = (1 << 15), // 8168 8101
465 Mac_dbgo_oe = (1 << 14), // 8168 8101
466 Normal_mode = (1 << 13), // unused
467 Force_half_dup = (1 << 12), // 8168 8101
468 Force_rxflow_en = (1 << 11), // 8168 8101
469 Force_txflow_en = (1 << 10), // 8168 8101
470 Cxpl_dbg_sel = (1 << 9), // 8168 8101
471 ASF = (1 << 8), // 8168 8101
472 PktCntrDisable = (1 << 7), // 8168 8101
473 Mac_dbgo_sel = 0x001c, // 8168
478 INTT_0 = 0x0000, // 8168
479 INTT_1 = 0x0001, // 8168
480 INTT_2 = 0x0002, // 8168
481 INTT_3 = 0x0003, // 8168
483 /* rtl8169_PHYstatus */
494 TBILinkOK = 0x02000000,
496 /* DumpCounterCommand */
501 /* First doubleword. */
502 DescOwn = (1 << 31), /* Descriptor is owned by NIC */
503 RingEnd = (1 << 30), /* End of descriptor ring */
504 FirstFrag = (1 << 29), /* First segment of a packet */
505 LastFrag = (1 << 28), /* Final segment of a packet */
509 enum rtl_tx_desc_bit {
510 /* First doubleword. */
511 TD_LSO = (1 << 27), /* Large Send Offload */
512 #define TD_MSS_MAX 0x07ffu /* MSS value */
514 /* Second doubleword. */
515 TxVlanTag = (1 << 17), /* Add VLAN tag */
518 /* 8169, 8168b and 810x except 8102e. */
519 enum rtl_tx_desc_bit_0 {
520 /* First doubleword. */
521 #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */
522 TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */
523 TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */
524 TD0_IP_CS = (1 << 18), /* Calculate IP checksum */
527 /* 8102e, 8168c and beyond. */
528 enum rtl_tx_desc_bit_1 {
529 /* Second doubleword. */
530 #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */
531 TD1_IP_CS = (1 << 29), /* Calculate IP checksum */
532 TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */
533 TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */
536 static const struct rtl_tx_desc_info {
543 } tx_desc_info [] = {
546 .udp = TD0_IP_CS | TD0_UDP_CS,
547 .tcp = TD0_IP_CS | TD0_TCP_CS
549 .mss_shift = TD0_MSS_SHIFT,
554 .udp = TD1_IP_CS | TD1_UDP_CS,
555 .tcp = TD1_IP_CS | TD1_TCP_CS
557 .mss_shift = TD1_MSS_SHIFT,
562 enum rtl_rx_desc_bit {
564 PID1 = (1 << 18), /* Protocol ID bit 1/2 */
565 PID0 = (1 << 17), /* Protocol ID bit 2/2 */
567 #define RxProtoUDP (PID1)
568 #define RxProtoTCP (PID0)
569 #define RxProtoIP (PID1 | PID0)
570 #define RxProtoMask RxProtoIP
572 IPFail = (1 << 16), /* IP checksum failed */
573 UDPFail = (1 << 15), /* UDP/IP checksum failed */
574 TCPFail = (1 << 14), /* TCP/IP checksum failed */
575 RxVlanTag = (1 << 16), /* VLAN tag available */
578 #define RsvdMask 0x3fffc000
595 u8 __pad[sizeof(void *) - sizeof(u32)];
599 RTL_FEATURE_WOL = (1 << 0),
600 RTL_FEATURE_MSI = (1 << 1),
601 RTL_FEATURE_GMII = (1 << 2),
604 struct rtl8169_counters {
611 __le32 tx_one_collision;
612 __le32 tx_multi_collision;
620 struct rtl8169_private {
621 void __iomem *mmio_addr; /* memory map physical address */
622 struct pci_dev *pci_dev;
623 struct net_device *dev;
624 struct napi_struct napi;
629 u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
630 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
633 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
634 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
635 dma_addr_t TxPhyAddr;
636 dma_addr_t RxPhyAddr;
637 void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */
638 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
639 struct timer_list timer;
646 void (*write)(void __iomem *, int, int);
647 int (*read)(void __iomem *, int);
650 struct pll_power_ops {
651 void (*down)(struct rtl8169_private *);
652 void (*up)(struct rtl8169_private *);
655 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
656 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
657 void (*phy_reset_enable)(struct rtl8169_private *tp);
658 void (*hw_start)(struct net_device *);
659 unsigned int (*phy_reset_pending)(struct rtl8169_private *tp);
660 unsigned int (*link_ok)(void __iomem *);
661 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd);
663 struct delayed_work task;
666 struct mii_if_info mii;
667 struct rtl8169_counters counters;
671 const struct firmware *fw;
673 #define RTL_VER_SIZE 32
675 char version[RTL_VER_SIZE];
677 struct rtl_fw_phy_action {
682 #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN);
685 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
686 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
687 module_param(use_dac, int, 0);
688 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
689 module_param_named(debug, debug.msg_enable, int, 0);
690 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
691 MODULE_LICENSE("GPL");
692 MODULE_VERSION(RTL8169_VERSION);
693 MODULE_FIRMWARE(FIRMWARE_8168D_1);
694 MODULE_FIRMWARE(FIRMWARE_8168D_2);
695 MODULE_FIRMWARE(FIRMWARE_8168E_1);
696 MODULE_FIRMWARE(FIRMWARE_8168E_2);
697 MODULE_FIRMWARE(FIRMWARE_8105E_1);
699 static int rtl8169_open(struct net_device *dev);
700 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
701 struct net_device *dev);
702 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance);
703 static int rtl8169_init_ring(struct net_device *dev);
704 static void rtl_hw_start(struct net_device *dev);
705 static int rtl8169_close(struct net_device *dev);
706 static void rtl_set_rx_mode(struct net_device *dev);
707 static void rtl8169_tx_timeout(struct net_device *dev);
708 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev);
709 static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *,
710 void __iomem *, u32 budget);
711 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu);
712 static void rtl8169_down(struct net_device *dev);
713 static void rtl8169_rx_clear(struct rtl8169_private *tp);
714 static int rtl8169_poll(struct napi_struct *napi, int budget);
716 static const unsigned int rtl8169_rx_config =
717 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
719 static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
721 void __iomem *ioaddr = tp->mmio_addr;
724 RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
725 for (i = 0; i < 20; i++) {
727 if (RTL_R32(OCPAR) & OCPAR_FLAG)
730 return RTL_R32(OCPDR);
733 static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data)
735 void __iomem *ioaddr = tp->mmio_addr;
738 RTL_W32(OCPDR, data);
739 RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
740 for (i = 0; i < 20; i++) {
742 if ((RTL_R32(OCPAR) & OCPAR_FLAG) == 0)
747 static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd)
749 void __iomem *ioaddr = tp->mmio_addr;
753 RTL_W32(ERIAR, 0x800010e8);
755 for (i = 0; i < 5; i++) {
757 if (!(RTL_R32(ERIDR) & ERIAR_FLAG))
761 ocp_write(tp, 0x1, 0x30, 0x00000001);
764 #define OOB_CMD_RESET 0x00
765 #define OOB_CMD_DRIVER_START 0x05
766 #define OOB_CMD_DRIVER_STOP 0x06
768 static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp)
770 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10;
773 static void rtl8168_driver_start(struct rtl8169_private *tp)
778 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START);
780 reg = rtl8168_get_ocp_reg(tp);
782 for (i = 0; i < 10; i++) {
784 if (ocp_read(tp, 0x0f, reg) & 0x00000800)
789 static void rtl8168_driver_stop(struct rtl8169_private *tp)
794 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP);
796 reg = rtl8168_get_ocp_reg(tp);
798 for (i = 0; i < 10; i++) {
800 if ((ocp_read(tp, 0x0f, reg) & 0x00000800) == 0)
805 static int r8168dp_check_dash(struct rtl8169_private *tp)
807 u16 reg = rtl8168_get_ocp_reg(tp);
809 return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0;
812 static void r8169_mdio_write(void __iomem *ioaddr, int reg_addr, int value)
816 RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff));
818 for (i = 20; i > 0; i--) {
820 * Check if the RTL8169 has completed writing to the specified
823 if (!(RTL_R32(PHYAR) & 0x80000000))
828 * According to hardware specs a 20us delay is required after write
829 * complete indication, but before sending next command.
834 static int r8169_mdio_read(void __iomem *ioaddr, int reg_addr)
838 RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16);
840 for (i = 20; i > 0; i--) {
842 * Check if the RTL8169 has completed retrieving data from
843 * the specified MII register.
845 if (RTL_R32(PHYAR) & 0x80000000) {
846 value = RTL_R32(PHYAR) & 0xffff;
852 * According to hardware specs a 20us delay is required after read
853 * complete indication, but before sending next command.
860 static void r8168dp_1_mdio_access(void __iomem *ioaddr, int reg_addr, u32 data)
864 RTL_W32(OCPDR, data |
865 ((reg_addr & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT));
866 RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD);
867 RTL_W32(EPHY_RXER_NUM, 0);
869 for (i = 0; i < 100; i++) {
871 if (!(RTL_R32(OCPAR) & OCPAR_FLAG))
876 static void r8168dp_1_mdio_write(void __iomem *ioaddr, int reg_addr, int value)
878 r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_WRITE_CMD |
879 (value & OCPDR_DATA_MASK));
882 static int r8168dp_1_mdio_read(void __iomem *ioaddr, int reg_addr)
886 r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_READ_CMD);
889 RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD);
890 RTL_W32(EPHY_RXER_NUM, 0);
892 for (i = 0; i < 100; i++) {
894 if (RTL_R32(OCPAR) & OCPAR_FLAG)
898 return RTL_R32(OCPDR) & OCPDR_DATA_MASK;
901 #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000
903 static void r8168dp_2_mdio_start(void __iomem *ioaddr)
905 RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT);
908 static void r8168dp_2_mdio_stop(void __iomem *ioaddr)
910 RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT);
913 static void r8168dp_2_mdio_write(void __iomem *ioaddr, int reg_addr, int value)
915 r8168dp_2_mdio_start(ioaddr);
917 r8169_mdio_write(ioaddr, reg_addr, value);
919 r8168dp_2_mdio_stop(ioaddr);
922 static int r8168dp_2_mdio_read(void __iomem *ioaddr, int reg_addr)
926 r8168dp_2_mdio_start(ioaddr);
928 value = r8169_mdio_read(ioaddr, reg_addr);
930 r8168dp_2_mdio_stop(ioaddr);
935 static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val)
937 tp->mdio_ops.write(tp->mmio_addr, location, val);
940 static int rtl_readphy(struct rtl8169_private *tp, int location)
942 return tp->mdio_ops.read(tp->mmio_addr, location);
945 static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value)
947 rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value);
950 static void rtl_w1w0_phy(struct rtl8169_private *tp, int reg_addr, int p, int m)
954 val = rtl_readphy(tp, reg_addr);
955 rtl_writephy(tp, reg_addr, (val | p) & ~m);
958 static void rtl_mdio_write(struct net_device *dev, int phy_id, int location,
961 struct rtl8169_private *tp = netdev_priv(dev);
963 rtl_writephy(tp, location, val);
966 static int rtl_mdio_read(struct net_device *dev, int phy_id, int location)
968 struct rtl8169_private *tp = netdev_priv(dev);
970 return rtl_readphy(tp, location);
973 static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value)
977 RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
978 (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
980 for (i = 0; i < 100; i++) {
981 if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG))
987 static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr)
992 RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
994 for (i = 0; i < 100; i++) {
995 if (RTL_R32(EPHYAR) & EPHYAR_FLAG) {
996 value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK;
1005 static void rtl_csi_write(void __iomem *ioaddr, int addr, int value)
1009 RTL_W32(CSIDR, value);
1010 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
1011 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
1013 for (i = 0; i < 100; i++) {
1014 if (!(RTL_R32(CSIAR) & CSIAR_FLAG))
1020 static u32 rtl_csi_read(void __iomem *ioaddr, int addr)
1025 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) |
1026 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT);
1028 for (i = 0; i < 100; i++) {
1029 if (RTL_R32(CSIAR) & CSIAR_FLAG) {
1030 value = RTL_R32(CSIDR);
1039 static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr)
1044 RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
1046 for (i = 0; i < 300; i++) {
1047 if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) {
1048 value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK;
1057 static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr)
1059 RTL_W16(IntrMask, 0x0000);
1061 RTL_W16(IntrStatus, 0xffff);
1064 static void rtl8169_asic_down(void __iomem *ioaddr)
1066 RTL_W8(ChipCmd, 0x00);
1067 rtl8169_irq_mask_and_ack(ioaddr);
1071 static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp)
1073 void __iomem *ioaddr = tp->mmio_addr;
1075 return RTL_R32(TBICSR) & TBIReset;
1078 static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp)
1080 return rtl_readphy(tp, MII_BMCR) & BMCR_RESET;
1083 static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr)
1085 return RTL_R32(TBICSR) & TBILinkOk;
1088 static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr)
1090 return RTL_R8(PHYstatus) & LinkStatus;
1093 static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp)
1095 void __iomem *ioaddr = tp->mmio_addr;
1097 RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset);
1100 static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp)
1104 val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET;
1105 rtl_writephy(tp, MII_BMCR, val & 0xffff);
1108 static void __rtl8169_check_link_status(struct net_device *dev,
1109 struct rtl8169_private *tp,
1110 void __iomem *ioaddr, bool pm)
1112 unsigned long flags;
1114 spin_lock_irqsave(&tp->lock, flags);
1115 if (tp->link_ok(ioaddr)) {
1116 /* This is to cancel a scheduled suspend if there's one. */
1118 pm_request_resume(&tp->pci_dev->dev);
1119 netif_carrier_on(dev);
1120 if (net_ratelimit())
1121 netif_info(tp, ifup, dev, "link up\n");
1123 netif_carrier_off(dev);
1124 netif_info(tp, ifdown, dev, "link down\n");
1126 pm_schedule_suspend(&tp->pci_dev->dev, 100);
1128 spin_unlock_irqrestore(&tp->lock, flags);
1131 static void rtl8169_check_link_status(struct net_device *dev,
1132 struct rtl8169_private *tp,
1133 void __iomem *ioaddr)
1135 __rtl8169_check_link_status(dev, tp, ioaddr, false);
1138 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
1140 static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
1142 void __iomem *ioaddr = tp->mmio_addr;
1146 options = RTL_R8(Config1);
1147 if (!(options & PMEnable))
1150 options = RTL_R8(Config3);
1151 if (options & LinkUp)
1152 wolopts |= WAKE_PHY;
1153 if (options & MagicPacket)
1154 wolopts |= WAKE_MAGIC;
1156 options = RTL_R8(Config5);
1158 wolopts |= WAKE_UCAST;
1160 wolopts |= WAKE_BCAST;
1162 wolopts |= WAKE_MCAST;
1167 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1169 struct rtl8169_private *tp = netdev_priv(dev);
1171 spin_lock_irq(&tp->lock);
1173 wol->supported = WAKE_ANY;
1174 wol->wolopts = __rtl8169_get_wol(tp);
1176 spin_unlock_irq(&tp->lock);
1179 static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
1181 void __iomem *ioaddr = tp->mmio_addr;
1183 static const struct {
1188 { WAKE_ANY, Config1, PMEnable },
1189 { WAKE_PHY, Config3, LinkUp },
1190 { WAKE_MAGIC, Config3, MagicPacket },
1191 { WAKE_UCAST, Config5, UWF },
1192 { WAKE_BCAST, Config5, BWF },
1193 { WAKE_MCAST, Config5, MWF },
1194 { WAKE_ANY, Config5, LanWake }
1197 RTL_W8(Cfg9346, Cfg9346_Unlock);
1199 for (i = 0; i < ARRAY_SIZE(cfg); i++) {
1200 u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask;
1201 if (wolopts & cfg[i].opt)
1202 options |= cfg[i].mask;
1203 RTL_W8(cfg[i].reg, options);
1206 RTL_W8(Cfg9346, Cfg9346_Lock);
1209 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1211 struct rtl8169_private *tp = netdev_priv(dev);
1213 spin_lock_irq(&tp->lock);
1216 tp->features |= RTL_FEATURE_WOL;
1218 tp->features &= ~RTL_FEATURE_WOL;
1219 __rtl8169_set_wol(tp, wol->wolopts);
1220 spin_unlock_irq(&tp->lock);
1222 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
1227 static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp)
1229 return rtl_chip_infos[tp->mac_version].fw_name;
1232 static void rtl8169_get_drvinfo(struct net_device *dev,
1233 struct ethtool_drvinfo *info)
1235 struct rtl8169_private *tp = netdev_priv(dev);
1236 struct rtl_fw *rtl_fw = tp->rtl_fw;
1238 strcpy(info->driver, MODULENAME);
1239 strcpy(info->version, RTL8169_VERSION);
1240 strcpy(info->bus_info, pci_name(tp->pci_dev));
1241 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version));
1242 strcpy(info->fw_version, IS_ERR_OR_NULL(rtl_fw) ? "N/A" :
1246 static int rtl8169_get_regs_len(struct net_device *dev)
1248 return R8169_REGS_SIZE;
1251 static int rtl8169_set_speed_tbi(struct net_device *dev,
1252 u8 autoneg, u16 speed, u8 duplex, u32 ignored)
1254 struct rtl8169_private *tp = netdev_priv(dev);
1255 void __iomem *ioaddr = tp->mmio_addr;
1259 reg = RTL_R32(TBICSR);
1260 if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) &&
1261 (duplex == DUPLEX_FULL)) {
1262 RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart));
1263 } else if (autoneg == AUTONEG_ENABLE)
1264 RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart);
1266 netif_warn(tp, link, dev,
1267 "incorrect speed setting refused in TBI mode\n");
1274 static int rtl8169_set_speed_xmii(struct net_device *dev,
1275 u8 autoneg, u16 speed, u8 duplex, u32 adv)
1277 struct rtl8169_private *tp = netdev_priv(dev);
1278 int giga_ctrl, bmcr;
1281 rtl_writephy(tp, 0x1f, 0x0000);
1283 if (autoneg == AUTONEG_ENABLE) {
1286 auto_nego = rtl_readphy(tp, MII_ADVERTISE);
1287 auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
1288 ADVERTISE_100HALF | ADVERTISE_100FULL);
1290 if (adv & ADVERTISED_10baseT_Half)
1291 auto_nego |= ADVERTISE_10HALF;
1292 if (adv & ADVERTISED_10baseT_Full)
1293 auto_nego |= ADVERTISE_10FULL;
1294 if (adv & ADVERTISED_100baseT_Half)
1295 auto_nego |= ADVERTISE_100HALF;
1296 if (adv & ADVERTISED_100baseT_Full)
1297 auto_nego |= ADVERTISE_100FULL;
1299 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
1301 giga_ctrl = rtl_readphy(tp, MII_CTRL1000);
1302 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
1304 /* The 8100e/8101e/8102e do Fast Ethernet only. */
1305 if (tp->mii.supports_gmii) {
1306 if (adv & ADVERTISED_1000baseT_Half)
1307 giga_ctrl |= ADVERTISE_1000HALF;
1308 if (adv & ADVERTISED_1000baseT_Full)
1309 giga_ctrl |= ADVERTISE_1000FULL;
1310 } else if (adv & (ADVERTISED_1000baseT_Half |
1311 ADVERTISED_1000baseT_Full)) {
1312 netif_info(tp, link, dev,
1313 "PHY does not support 1000Mbps\n");
1317 bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
1319 rtl_writephy(tp, MII_ADVERTISE, auto_nego);
1320 rtl_writephy(tp, MII_CTRL1000, giga_ctrl);
1324 if (speed == SPEED_10)
1326 else if (speed == SPEED_100)
1327 bmcr = BMCR_SPEED100;
1331 if (duplex == DUPLEX_FULL)
1332 bmcr |= BMCR_FULLDPLX;
1335 rtl_writephy(tp, MII_BMCR, bmcr);
1337 if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
1338 tp->mac_version == RTL_GIGA_MAC_VER_03) {
1339 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) {
1340 rtl_writephy(tp, 0x17, 0x2138);
1341 rtl_writephy(tp, 0x0e, 0x0260);
1343 rtl_writephy(tp, 0x17, 0x2108);
1344 rtl_writephy(tp, 0x0e, 0x0000);
1353 static int rtl8169_set_speed(struct net_device *dev,
1354 u8 autoneg, u16 speed, u8 duplex, u32 advertising)
1356 struct rtl8169_private *tp = netdev_priv(dev);
1359 ret = tp->set_speed(dev, autoneg, speed, duplex, advertising);
1363 if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) &&
1364 (advertising & ADVERTISED_1000baseT_Full)) {
1365 mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT);
1371 static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1373 struct rtl8169_private *tp = netdev_priv(dev);
1374 unsigned long flags;
1377 del_timer_sync(&tp->timer);
1379 spin_lock_irqsave(&tp->lock, flags);
1380 ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd),
1381 cmd->duplex, cmd->advertising);
1382 spin_unlock_irqrestore(&tp->lock, flags);
1387 static u32 rtl8169_fix_features(struct net_device *dev, u32 features)
1389 if (dev->mtu > TD_MSS_MAX)
1390 features &= ~NETIF_F_ALL_TSO;
1395 static int rtl8169_set_features(struct net_device *dev, u32 features)
1397 struct rtl8169_private *tp = netdev_priv(dev);
1398 void __iomem *ioaddr = tp->mmio_addr;
1399 unsigned long flags;
1401 spin_lock_irqsave(&tp->lock, flags);
1403 if (features & NETIF_F_RXCSUM)
1404 tp->cp_cmd |= RxChkSum;
1406 tp->cp_cmd &= ~RxChkSum;
1408 if (dev->features & NETIF_F_HW_VLAN_RX)
1409 tp->cp_cmd |= RxVlan;
1411 tp->cp_cmd &= ~RxVlan;
1413 RTL_W16(CPlusCmd, tp->cp_cmd);
1416 spin_unlock_irqrestore(&tp->lock, flags);
1421 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp,
1422 struct sk_buff *skb)
1424 return (vlan_tx_tag_present(skb)) ?
1425 TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00;
1428 static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb)
1430 u32 opts2 = le32_to_cpu(desc->opts2);
1432 if (opts2 & RxVlanTag)
1433 __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff));
1438 static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd)
1440 struct rtl8169_private *tp = netdev_priv(dev);
1441 void __iomem *ioaddr = tp->mmio_addr;
1445 SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE;
1446 cmd->port = PORT_FIBRE;
1447 cmd->transceiver = XCVR_INTERNAL;
1449 status = RTL_R32(TBICSR);
1450 cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0;
1451 cmd->autoneg = !!(status & TBINwEnable);
1453 ethtool_cmd_speed_set(cmd, SPEED_1000);
1454 cmd->duplex = DUPLEX_FULL; /* Always set */
1459 static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd)
1461 struct rtl8169_private *tp = netdev_priv(dev);
1463 return mii_ethtool_gset(&tp->mii, cmd);
1466 static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1468 struct rtl8169_private *tp = netdev_priv(dev);
1469 unsigned long flags;
1472 spin_lock_irqsave(&tp->lock, flags);
1474 rc = tp->get_settings(dev, cmd);
1476 spin_unlock_irqrestore(&tp->lock, flags);
1480 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1483 struct rtl8169_private *tp = netdev_priv(dev);
1484 unsigned long flags;
1486 if (regs->len > R8169_REGS_SIZE)
1487 regs->len = R8169_REGS_SIZE;
1489 spin_lock_irqsave(&tp->lock, flags);
1490 memcpy_fromio(p, tp->mmio_addr, regs->len);
1491 spin_unlock_irqrestore(&tp->lock, flags);
1494 static u32 rtl8169_get_msglevel(struct net_device *dev)
1496 struct rtl8169_private *tp = netdev_priv(dev);
1498 return tp->msg_enable;
1501 static void rtl8169_set_msglevel(struct net_device *dev, u32 value)
1503 struct rtl8169_private *tp = netdev_priv(dev);
1505 tp->msg_enable = value;
1508 static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = {
1515 "tx_single_collisions",
1516 "tx_multi_collisions",
1524 static int rtl8169_get_sset_count(struct net_device *dev, int sset)
1528 return ARRAY_SIZE(rtl8169_gstrings);
1534 static void rtl8169_update_counters(struct net_device *dev)
1536 struct rtl8169_private *tp = netdev_priv(dev);
1537 void __iomem *ioaddr = tp->mmio_addr;
1538 struct device *d = &tp->pci_dev->dev;
1539 struct rtl8169_counters *counters;
1545 * Some chips are unable to dump tally counters when the receiver
1548 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
1551 counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL);
1555 RTL_W32(CounterAddrHigh, (u64)paddr >> 32);
1556 cmd = (u64)paddr & DMA_BIT_MASK(32);
1557 RTL_W32(CounterAddrLow, cmd);
1558 RTL_W32(CounterAddrLow, cmd | CounterDump);
1561 if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) {
1562 memcpy(&tp->counters, counters, sizeof(*counters));
1568 RTL_W32(CounterAddrLow, 0);
1569 RTL_W32(CounterAddrHigh, 0);
1571 dma_free_coherent(d, sizeof(*counters), counters, paddr);
1574 static void rtl8169_get_ethtool_stats(struct net_device *dev,
1575 struct ethtool_stats *stats, u64 *data)
1577 struct rtl8169_private *tp = netdev_priv(dev);
1581 rtl8169_update_counters(dev);
1583 data[0] = le64_to_cpu(tp->counters.tx_packets);
1584 data[1] = le64_to_cpu(tp->counters.rx_packets);
1585 data[2] = le64_to_cpu(tp->counters.tx_errors);
1586 data[3] = le32_to_cpu(tp->counters.rx_errors);
1587 data[4] = le16_to_cpu(tp->counters.rx_missed);
1588 data[5] = le16_to_cpu(tp->counters.align_errors);
1589 data[6] = le32_to_cpu(tp->counters.tx_one_collision);
1590 data[7] = le32_to_cpu(tp->counters.tx_multi_collision);
1591 data[8] = le64_to_cpu(tp->counters.rx_unicast);
1592 data[9] = le64_to_cpu(tp->counters.rx_broadcast);
1593 data[10] = le32_to_cpu(tp->counters.rx_multicast);
1594 data[11] = le16_to_cpu(tp->counters.tx_aborted);
1595 data[12] = le16_to_cpu(tp->counters.tx_underun);
1598 static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1602 memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings));
1607 static const struct ethtool_ops rtl8169_ethtool_ops = {
1608 .get_drvinfo = rtl8169_get_drvinfo,
1609 .get_regs_len = rtl8169_get_regs_len,
1610 .get_link = ethtool_op_get_link,
1611 .get_settings = rtl8169_get_settings,
1612 .set_settings = rtl8169_set_settings,
1613 .get_msglevel = rtl8169_get_msglevel,
1614 .set_msglevel = rtl8169_set_msglevel,
1615 .get_regs = rtl8169_get_regs,
1616 .get_wol = rtl8169_get_wol,
1617 .set_wol = rtl8169_set_wol,
1618 .get_strings = rtl8169_get_strings,
1619 .get_sset_count = rtl8169_get_sset_count,
1620 .get_ethtool_stats = rtl8169_get_ethtool_stats,
1623 static void rtl8169_get_mac_version(struct rtl8169_private *tp,
1624 struct net_device *dev, u8 default_version)
1626 void __iomem *ioaddr = tp->mmio_addr;
1628 * The driver currently handles the 8168Bf and the 8168Be identically
1629 * but they can be identified more specifically through the test below
1632 * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
1634 * Same thing for the 8101Eb and the 8101Ec:
1636 * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
1638 static const struct rtl_mac_info {
1644 { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 },
1645 { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 },
1646 { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 },
1649 { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 },
1650 { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 },
1651 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 },
1653 /* 8168DP family. */
1654 { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 },
1655 { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 },
1656 { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 },
1659 { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 },
1660 { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 },
1661 { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 },
1662 { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 },
1663 { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 },
1664 { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 },
1665 { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 },
1666 { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 },
1667 { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 },
1670 { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 },
1671 { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 },
1672 { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 },
1673 { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 },
1676 { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 },
1677 { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 },
1678 { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 },
1679 { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 },
1680 { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 },
1681 { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 },
1682 { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 },
1683 { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 },
1684 { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 },
1685 { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 },
1686 { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 },
1687 { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 },
1688 { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 },
1689 { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 },
1690 { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 },
1691 { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 },
1692 /* FIXME: where did these entries come from ? -- FR */
1693 { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 },
1694 { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 },
1697 { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 },
1698 { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 },
1699 { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 },
1700 { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 },
1701 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
1702 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
1705 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE }
1707 const struct rtl_mac_info *p = mac_info;
1710 reg = RTL_R32(TxConfig);
1711 while ((reg & p->mask) != p->val)
1713 tp->mac_version = p->mac_version;
1715 if (tp->mac_version == RTL_GIGA_MAC_NONE) {
1716 netif_notice(tp, probe, dev,
1717 "unknown MAC, using family default\n");
1718 tp->mac_version = default_version;
1722 static void rtl8169_print_mac_version(struct rtl8169_private *tp)
1724 dprintk("mac_version = 0x%02x\n", tp->mac_version);
1732 static void rtl_writephy_batch(struct rtl8169_private *tp,
1733 const struct phy_reg *regs, int len)
1736 rtl_writephy(tp, regs->reg, regs->val);
1741 #define PHY_READ 0x00000000
1742 #define PHY_DATA_OR 0x10000000
1743 #define PHY_DATA_AND 0x20000000
1744 #define PHY_BJMPN 0x30000000
1745 #define PHY_READ_EFUSE 0x40000000
1746 #define PHY_READ_MAC_BYTE 0x50000000
1747 #define PHY_WRITE_MAC_BYTE 0x60000000
1748 #define PHY_CLEAR_READCOUNT 0x70000000
1749 #define PHY_WRITE 0x80000000
1750 #define PHY_READCOUNT_EQ_SKIP 0x90000000
1751 #define PHY_COMP_EQ_SKIPN 0xa0000000
1752 #define PHY_COMP_NEQ_SKIPN 0xb0000000
1753 #define PHY_WRITE_PREVIOUS 0xc0000000
1754 #define PHY_SKIPN 0xd0000000
1755 #define PHY_DELAY_MS 0xe0000000
1756 #define PHY_WRITE_ERI_WORD 0xf0000000
1760 char version[RTL_VER_SIZE];
1766 #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code))
1768 static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
1770 const struct firmware *fw = rtl_fw->fw;
1771 struct fw_info *fw_info = (struct fw_info *)fw->data;
1772 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
1773 char *version = rtl_fw->version;
1776 if (fw->size < FW_OPCODE_SIZE)
1779 if (!fw_info->magic) {
1780 size_t i, size, start;
1783 if (fw->size < sizeof(*fw_info))
1786 for (i = 0; i < fw->size; i++)
1787 checksum += fw->data[i];
1791 start = le32_to_cpu(fw_info->fw_start);
1792 if (start > fw->size)
1795 size = le32_to_cpu(fw_info->fw_len);
1796 if (size > (fw->size - start) / FW_OPCODE_SIZE)
1799 memcpy(version, fw_info->version, RTL_VER_SIZE);
1801 pa->code = (__le32 *)(fw->data + start);
1804 if (fw->size % FW_OPCODE_SIZE)
1807 strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE);
1809 pa->code = (__le32 *)fw->data;
1810 pa->size = fw->size / FW_OPCODE_SIZE;
1812 version[RTL_VER_SIZE - 1] = 0;
1819 static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev,
1820 struct rtl_fw_phy_action *pa)
1825 for (index = 0; index < pa->size; index++) {
1826 u32 action = le32_to_cpu(pa->code[index]);
1827 u32 regno = (action & 0x0fff0000) >> 16;
1829 switch(action & 0xf0000000) {
1833 case PHY_READ_EFUSE:
1834 case PHY_CLEAR_READCOUNT:
1836 case PHY_WRITE_PREVIOUS:
1841 if (regno > index) {
1842 netif_err(tp, ifup, tp->dev,
1843 "Out of range of firmware\n");
1847 case PHY_READCOUNT_EQ_SKIP:
1848 if (index + 2 >= pa->size) {
1849 netif_err(tp, ifup, tp->dev,
1850 "Out of range of firmware\n");
1854 case PHY_COMP_EQ_SKIPN:
1855 case PHY_COMP_NEQ_SKIPN:
1857 if (index + 1 + regno >= pa->size) {
1858 netif_err(tp, ifup, tp->dev,
1859 "Out of range of firmware\n");
1864 case PHY_READ_MAC_BYTE:
1865 case PHY_WRITE_MAC_BYTE:
1866 case PHY_WRITE_ERI_WORD:
1868 netif_err(tp, ifup, tp->dev,
1869 "Invalid action 0x%08x\n", action);
1878 static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
1880 struct net_device *dev = tp->dev;
1883 if (!rtl_fw_format_ok(tp, rtl_fw)) {
1884 netif_err(tp, ifup, dev, "invalid firwmare\n");
1888 if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action))
1894 static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
1896 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
1900 predata = count = 0;
1902 for (index = 0; index < pa->size; ) {
1903 u32 action = le32_to_cpu(pa->code[index]);
1904 u32 data = action & 0x0000ffff;
1905 u32 regno = (action & 0x0fff0000) >> 16;
1910 switch(action & 0xf0000000) {
1912 predata = rtl_readphy(tp, regno);
1927 case PHY_READ_EFUSE:
1928 predata = rtl8168d_efuse_read(tp->mmio_addr, regno);
1931 case PHY_CLEAR_READCOUNT:
1936 rtl_writephy(tp, regno, data);
1939 case PHY_READCOUNT_EQ_SKIP:
1940 index += (count == data) ? 2 : 1;
1942 case PHY_COMP_EQ_SKIPN:
1943 if (predata == data)
1947 case PHY_COMP_NEQ_SKIPN:
1948 if (predata != data)
1952 case PHY_WRITE_PREVIOUS:
1953 rtl_writephy(tp, regno, predata);
1964 case PHY_READ_MAC_BYTE:
1965 case PHY_WRITE_MAC_BYTE:
1966 case PHY_WRITE_ERI_WORD:
1973 static void rtl_release_firmware(struct rtl8169_private *tp)
1975 if (!IS_ERR_OR_NULL(tp->rtl_fw)) {
1976 release_firmware(tp->rtl_fw->fw);
1979 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
1982 static void rtl_apply_firmware(struct rtl8169_private *tp)
1984 struct rtl_fw *rtl_fw = tp->rtl_fw;
1986 /* TODO: release firmware once rtl_phy_write_fw signals failures. */
1987 if (!IS_ERR_OR_NULL(rtl_fw))
1988 rtl_phy_write_fw(tp, rtl_fw);
1991 static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val)
1993 if (rtl_readphy(tp, reg) != val)
1994 netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n");
1996 rtl_apply_firmware(tp);
1999 static void rtl8169s_hw_phy_config(struct rtl8169_private *tp)
2001 static const struct phy_reg phy_reg_init[] = {
2063 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2066 static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp)
2068 static const struct phy_reg phy_reg_init[] = {
2074 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2077 static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp)
2079 struct pci_dev *pdev = tp->pci_dev;
2080 u16 vendor_id, device_id;
2082 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &vendor_id);
2083 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &device_id);
2085 if ((vendor_id != PCI_VENDOR_ID_GIGABYTE) || (device_id != 0xe000))
2088 rtl_writephy(tp, 0x1f, 0x0001);
2089 rtl_writephy(tp, 0x10, 0xf01b);
2090 rtl_writephy(tp, 0x1f, 0x0000);
2093 static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp)
2095 static const struct phy_reg phy_reg_init[] = {
2135 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2137 rtl8169scd_hw_phy_config_quirk(tp);
2140 static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp)
2142 static const struct phy_reg phy_reg_init[] = {
2190 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2193 static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp)
2195 static const struct phy_reg phy_reg_init[] = {
2200 rtl_writephy(tp, 0x1f, 0x0001);
2201 rtl_patchphy(tp, 0x16, 1 << 0);
2203 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2206 static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp)
2208 static const struct phy_reg phy_reg_init[] = {
2214 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2217 static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp)
2219 static const struct phy_reg phy_reg_init[] = {
2227 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2230 static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp)
2232 static const struct phy_reg phy_reg_init[] = {
2238 rtl_writephy(tp, 0x1f, 0x0000);
2239 rtl_patchphy(tp, 0x14, 1 << 5);
2240 rtl_patchphy(tp, 0x0d, 1 << 5);
2242 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2245 static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp)
2247 static const struct phy_reg phy_reg_init[] = {
2267 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2269 rtl_patchphy(tp, 0x14, 1 << 5);
2270 rtl_patchphy(tp, 0x0d, 1 << 5);
2271 rtl_writephy(tp, 0x1f, 0x0000);
2274 static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp)
2276 static const struct phy_reg phy_reg_init[] = {
2294 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2296 rtl_patchphy(tp, 0x16, 1 << 0);
2297 rtl_patchphy(tp, 0x14, 1 << 5);
2298 rtl_patchphy(tp, 0x0d, 1 << 5);
2299 rtl_writephy(tp, 0x1f, 0x0000);
2302 static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp)
2304 static const struct phy_reg phy_reg_init[] = {
2316 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2318 rtl_patchphy(tp, 0x16, 1 << 0);
2319 rtl_patchphy(tp, 0x14, 1 << 5);
2320 rtl_patchphy(tp, 0x0d, 1 << 5);
2321 rtl_writephy(tp, 0x1f, 0x0000);
2324 static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp)
2326 rtl8168c_3_hw_phy_config(tp);
2329 static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp)
2331 static const struct phy_reg phy_reg_init_0[] = {
2332 /* Channel Estimation */
2353 * Enhance line driver power
2362 * Can not link to 1Gbps with bad cable
2363 * Decrease SNR threshold form 21.07dB to 19.04dB
2371 void __iomem *ioaddr = tp->mmio_addr;
2373 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
2377 * Fine Tune Switching regulator parameter
2379 rtl_writephy(tp, 0x1f, 0x0002);
2380 rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef);
2381 rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00);
2383 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
2384 static const struct phy_reg phy_reg_init[] = {
2394 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2396 val = rtl_readphy(tp, 0x0d);
2398 if ((val & 0x00ff) != 0x006c) {
2399 static const u32 set[] = {
2400 0x0065, 0x0066, 0x0067, 0x0068,
2401 0x0069, 0x006a, 0x006b, 0x006c
2405 rtl_writephy(tp, 0x1f, 0x0002);
2408 for (i = 0; i < ARRAY_SIZE(set); i++)
2409 rtl_writephy(tp, 0x0d, val | set[i]);
2412 static const struct phy_reg phy_reg_init[] = {
2420 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2423 /* RSET couple improve */
2424 rtl_writephy(tp, 0x1f, 0x0002);
2425 rtl_patchphy(tp, 0x0d, 0x0300);
2426 rtl_patchphy(tp, 0x0f, 0x0010);
2428 /* Fine tune PLL performance */
2429 rtl_writephy(tp, 0x1f, 0x0002);
2430 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600);
2431 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000);
2433 rtl_writephy(tp, 0x1f, 0x0005);
2434 rtl_writephy(tp, 0x05, 0x001b);
2436 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00);
2438 rtl_writephy(tp, 0x1f, 0x0000);
2441 static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp)
2443 static const struct phy_reg phy_reg_init_0[] = {
2444 /* Channel Estimation */
2465 * Enhance line driver power
2474 * Can not link to 1Gbps with bad cable
2475 * Decrease SNR threshold form 21.07dB to 19.04dB
2483 void __iomem *ioaddr = tp->mmio_addr;
2485 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
2487 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) {
2488 static const struct phy_reg phy_reg_init[] = {
2499 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2501 val = rtl_readphy(tp, 0x0d);
2502 if ((val & 0x00ff) != 0x006c) {
2503 static const u32 set[] = {
2504 0x0065, 0x0066, 0x0067, 0x0068,
2505 0x0069, 0x006a, 0x006b, 0x006c
2509 rtl_writephy(tp, 0x1f, 0x0002);
2512 for (i = 0; i < ARRAY_SIZE(set); i++)
2513 rtl_writephy(tp, 0x0d, val | set[i]);
2516 static const struct phy_reg phy_reg_init[] = {
2524 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2527 /* Fine tune PLL performance */
2528 rtl_writephy(tp, 0x1f, 0x0002);
2529 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600);
2530 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000);
2532 /* Switching regulator Slew rate */
2533 rtl_writephy(tp, 0x1f, 0x0002);
2534 rtl_patchphy(tp, 0x0f, 0x0017);
2536 rtl_writephy(tp, 0x1f, 0x0005);
2537 rtl_writephy(tp, 0x05, 0x001b);
2539 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300);
2541 rtl_writephy(tp, 0x1f, 0x0000);
2544 static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp)
2546 static const struct phy_reg phy_reg_init[] = {
2602 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2605 static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp)
2607 static const struct phy_reg phy_reg_init[] = {
2617 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2618 rtl_patchphy(tp, 0x0d, 1 << 5);
2621 static void rtl8168e_hw_phy_config(struct rtl8169_private *tp)
2623 static const struct phy_reg phy_reg_init[] = {
2624 /* Enable Delay cap */
2630 /* Channel estimation fine tune */
2639 /* Update PFM & 10M TX idle timer */
2651 rtl_apply_firmware(tp);
2653 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2655 /* DCO enable for 10M IDLE Power */
2656 rtl_writephy(tp, 0x1f, 0x0007);
2657 rtl_writephy(tp, 0x1e, 0x0023);
2658 rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000);
2659 rtl_writephy(tp, 0x1f, 0x0000);
2661 /* For impedance matching */
2662 rtl_writephy(tp, 0x1f, 0x0002);
2663 rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00);
2664 rtl_writephy(tp, 0x1f, 0x0000);
2666 /* PHY auto speed down */
2667 rtl_writephy(tp, 0x1f, 0x0007);
2668 rtl_writephy(tp, 0x1e, 0x002d);
2669 rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000);
2670 rtl_writephy(tp, 0x1f, 0x0000);
2671 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000);
2673 rtl_writephy(tp, 0x1f, 0x0005);
2674 rtl_writephy(tp, 0x05, 0x8b86);
2675 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000);
2676 rtl_writephy(tp, 0x1f, 0x0000);
2678 rtl_writephy(tp, 0x1f, 0x0005);
2679 rtl_writephy(tp, 0x05, 0x8b85);
2680 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000);
2681 rtl_writephy(tp, 0x1f, 0x0007);
2682 rtl_writephy(tp, 0x1e, 0x0020);
2683 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100);
2684 rtl_writephy(tp, 0x1f, 0x0006);
2685 rtl_writephy(tp, 0x00, 0x5a00);
2686 rtl_writephy(tp, 0x1f, 0x0000);
2687 rtl_writephy(tp, 0x0d, 0x0007);
2688 rtl_writephy(tp, 0x0e, 0x003c);
2689 rtl_writephy(tp, 0x0d, 0x4007);
2690 rtl_writephy(tp, 0x0e, 0x0000);
2691 rtl_writephy(tp, 0x0d, 0x0000);
2694 static void rtl8102e_hw_phy_config(struct rtl8169_private *tp)
2696 static const struct phy_reg phy_reg_init[] = {
2703 rtl_writephy(tp, 0x1f, 0x0000);
2704 rtl_patchphy(tp, 0x11, 1 << 12);
2705 rtl_patchphy(tp, 0x19, 1 << 13);
2706 rtl_patchphy(tp, 0x10, 1 << 15);
2708 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2711 static void rtl8105e_hw_phy_config(struct rtl8169_private *tp)
2713 static const struct phy_reg phy_reg_init[] = {
2727 /* Disable ALDPS before ram code */
2728 rtl_writephy(tp, 0x1f, 0x0000);
2729 rtl_writephy(tp, 0x18, 0x0310);
2732 rtl_apply_firmware(tp);
2734 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2737 static void rtl_hw_phy_config(struct net_device *dev)
2739 struct rtl8169_private *tp = netdev_priv(dev);
2741 rtl8169_print_mac_version(tp);
2743 switch (tp->mac_version) {
2744 case RTL_GIGA_MAC_VER_01:
2746 case RTL_GIGA_MAC_VER_02:
2747 case RTL_GIGA_MAC_VER_03:
2748 rtl8169s_hw_phy_config(tp);
2750 case RTL_GIGA_MAC_VER_04:
2751 rtl8169sb_hw_phy_config(tp);
2753 case RTL_GIGA_MAC_VER_05:
2754 rtl8169scd_hw_phy_config(tp);
2756 case RTL_GIGA_MAC_VER_06:
2757 rtl8169sce_hw_phy_config(tp);
2759 case RTL_GIGA_MAC_VER_07:
2760 case RTL_GIGA_MAC_VER_08:
2761 case RTL_GIGA_MAC_VER_09:
2762 rtl8102e_hw_phy_config(tp);
2764 case RTL_GIGA_MAC_VER_11:
2765 rtl8168bb_hw_phy_config(tp);
2767 case RTL_GIGA_MAC_VER_12:
2768 rtl8168bef_hw_phy_config(tp);
2770 case RTL_GIGA_MAC_VER_17:
2771 rtl8168bef_hw_phy_config(tp);
2773 case RTL_GIGA_MAC_VER_18:
2774 rtl8168cp_1_hw_phy_config(tp);
2776 case RTL_GIGA_MAC_VER_19:
2777 rtl8168c_1_hw_phy_config(tp);
2779 case RTL_GIGA_MAC_VER_20:
2780 rtl8168c_2_hw_phy_config(tp);
2782 case RTL_GIGA_MAC_VER_21:
2783 rtl8168c_3_hw_phy_config(tp);
2785 case RTL_GIGA_MAC_VER_22:
2786 rtl8168c_4_hw_phy_config(tp);
2788 case RTL_GIGA_MAC_VER_23:
2789 case RTL_GIGA_MAC_VER_24:
2790 rtl8168cp_2_hw_phy_config(tp);
2792 case RTL_GIGA_MAC_VER_25:
2793 rtl8168d_1_hw_phy_config(tp);
2795 case RTL_GIGA_MAC_VER_26:
2796 rtl8168d_2_hw_phy_config(tp);
2798 case RTL_GIGA_MAC_VER_27:
2799 rtl8168d_3_hw_phy_config(tp);
2801 case RTL_GIGA_MAC_VER_28:
2802 rtl8168d_4_hw_phy_config(tp);
2804 case RTL_GIGA_MAC_VER_29:
2805 case RTL_GIGA_MAC_VER_30:
2806 rtl8105e_hw_phy_config(tp);
2808 case RTL_GIGA_MAC_VER_31:
2811 case RTL_GIGA_MAC_VER_32:
2812 case RTL_GIGA_MAC_VER_33:
2813 rtl8168e_hw_phy_config(tp);
2821 static void rtl8169_phy_timer(unsigned long __opaque)
2823 struct net_device *dev = (struct net_device *)__opaque;
2824 struct rtl8169_private *tp = netdev_priv(dev);
2825 struct timer_list *timer = &tp->timer;
2826 void __iomem *ioaddr = tp->mmio_addr;
2827 unsigned long timeout = RTL8169_PHY_TIMEOUT;
2829 assert(tp->mac_version > RTL_GIGA_MAC_VER_01);
2831 spin_lock_irq(&tp->lock);
2833 if (tp->phy_reset_pending(tp)) {
2835 * A busy loop could burn quite a few cycles on nowadays CPU.
2836 * Let's delay the execution of the timer for a few ticks.
2842 if (tp->link_ok(ioaddr))
2845 netif_warn(tp, link, dev, "PHY reset until link up\n");
2847 tp->phy_reset_enable(tp);
2850 mod_timer(timer, jiffies + timeout);
2852 spin_unlock_irq(&tp->lock);
2855 #ifdef CONFIG_NET_POLL_CONTROLLER
2857 * Polling 'interrupt' - used by things like netconsole to send skbs
2858 * without having to re-enable interrupts. It's not called while
2859 * the interrupt routine is executing.
2861 static void rtl8169_netpoll(struct net_device *dev)
2863 struct rtl8169_private *tp = netdev_priv(dev);
2864 struct pci_dev *pdev = tp->pci_dev;
2866 disable_irq(pdev->irq);
2867 rtl8169_interrupt(pdev->irq, dev);
2868 enable_irq(pdev->irq);
2872 static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev,
2873 void __iomem *ioaddr)
2876 pci_release_regions(pdev);
2877 pci_clear_mwi(pdev);
2878 pci_disable_device(pdev);
2882 static void rtl8169_phy_reset(struct net_device *dev,
2883 struct rtl8169_private *tp)
2887 tp->phy_reset_enable(tp);
2888 for (i = 0; i < 100; i++) {
2889 if (!tp->phy_reset_pending(tp))
2893 netif_err(tp, link, dev, "PHY reset failed\n");
2896 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
2898 void __iomem *ioaddr = tp->mmio_addr;
2900 rtl_hw_phy_config(dev);
2902 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
2903 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
2907 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
2909 if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
2910 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
2912 if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
2913 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
2915 dprintk("Set PHY Reg 0x0bh = 0x00h\n");
2916 rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0
2919 rtl8169_phy_reset(dev, tp);
2921 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
2922 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
2923 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
2924 (tp->mii.supports_gmii ?
2925 ADVERTISED_1000baseT_Half |
2926 ADVERTISED_1000baseT_Full : 0));
2928 if (RTL_R8(PHYstatus) & TBI_Enable)
2929 netif_info(tp, link, dev, "TBI auto-negotiating\n");
2932 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
2934 void __iomem *ioaddr = tp->mmio_addr;
2938 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24);
2939 high = addr[4] | (addr[5] << 8);
2941 spin_lock_irq(&tp->lock);
2943 RTL_W8(Cfg9346, Cfg9346_Unlock);
2945 RTL_W32(MAC4, high);
2951 RTL_W8(Cfg9346, Cfg9346_Lock);
2953 spin_unlock_irq(&tp->lock);
2956 static int rtl_set_mac_address(struct net_device *dev, void *p)
2958 struct rtl8169_private *tp = netdev_priv(dev);
2959 struct sockaddr *addr = p;
2961 if (!is_valid_ether_addr(addr->sa_data))
2962 return -EADDRNOTAVAIL;
2964 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2966 rtl_rar_set(tp, dev->dev_addr);
2971 static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2973 struct rtl8169_private *tp = netdev_priv(dev);
2974 struct mii_ioctl_data *data = if_mii(ifr);
2976 return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV;
2979 static int rtl_xmii_ioctl(struct rtl8169_private *tp,
2980 struct mii_ioctl_data *data, int cmd)
2984 data->phy_id = 32; /* Internal PHY */
2988 data->val_out = rtl_readphy(tp, data->reg_num & 0x1f);
2992 rtl_writephy(tp, data->reg_num & 0x1f, data->val_in);
2998 static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd)
3003 static const struct rtl_cfg_info {
3004 void (*hw_start)(struct net_device *);
3005 unsigned int region;
3011 } rtl_cfg_infos [] = {
3013 .hw_start = rtl_hw_start_8169,
3016 .intr_event = SYSErr | LinkChg | RxOverflow |
3017 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
3018 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
3019 .features = RTL_FEATURE_GMII,
3020 .default_ver = RTL_GIGA_MAC_VER_01,
3023 .hw_start = rtl_hw_start_8168,
3026 .intr_event = SYSErr | LinkChg | RxOverflow |
3027 TxErr | TxOK | RxOK | RxErr,
3028 .napi_event = TxErr | TxOK | RxOK | RxOverflow,
3029 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
3030 .default_ver = RTL_GIGA_MAC_VER_11,
3033 .hw_start = rtl_hw_start_8101,
3036 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
3037 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
3038 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
3039 .features = RTL_FEATURE_MSI,
3040 .default_ver = RTL_GIGA_MAC_VER_13,
3044 /* Cfg9346_Unlock assumed. */
3045 static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr,
3046 const struct rtl_cfg_info *cfg)
3051 cfg2 = RTL_R8(Config2) & ~MSIEnable;
3052 if (cfg->features & RTL_FEATURE_MSI) {
3053 if (pci_enable_msi(pdev)) {
3054 dev_info(&pdev->dev, "no MSI. Back to INTx.\n");
3057 msi = RTL_FEATURE_MSI;
3060 RTL_W8(Config2, cfg2);
3064 static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
3066 if (tp->features & RTL_FEATURE_MSI) {
3067 pci_disable_msi(pdev);
3068 tp->features &= ~RTL_FEATURE_MSI;
3072 static const struct net_device_ops rtl8169_netdev_ops = {
3073 .ndo_open = rtl8169_open,
3074 .ndo_stop = rtl8169_close,
3075 .ndo_get_stats = rtl8169_get_stats,
3076 .ndo_start_xmit = rtl8169_start_xmit,
3077 .ndo_tx_timeout = rtl8169_tx_timeout,
3078 .ndo_validate_addr = eth_validate_addr,
3079 .ndo_change_mtu = rtl8169_change_mtu,
3080 .ndo_fix_features = rtl8169_fix_features,
3081 .ndo_set_features = rtl8169_set_features,
3082 .ndo_set_mac_address = rtl_set_mac_address,
3083 .ndo_do_ioctl = rtl8169_ioctl,
3084 .ndo_set_multicast_list = rtl_set_rx_mode,
3085 #ifdef CONFIG_NET_POLL_CONTROLLER
3086 .ndo_poll_controller = rtl8169_netpoll,
3091 static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp)
3093 struct mdio_ops *ops = &tp->mdio_ops;
3095 switch (tp->mac_version) {
3096 case RTL_GIGA_MAC_VER_27:
3097 ops->write = r8168dp_1_mdio_write;
3098 ops->read = r8168dp_1_mdio_read;
3100 case RTL_GIGA_MAC_VER_28:
3101 case RTL_GIGA_MAC_VER_31:
3102 ops->write = r8168dp_2_mdio_write;
3103 ops->read = r8168dp_2_mdio_read;
3106 ops->write = r8169_mdio_write;
3107 ops->read = r8169_mdio_read;
3112 static void r810x_phy_power_down(struct rtl8169_private *tp)
3114 rtl_writephy(tp, 0x1f, 0x0000);
3115 rtl_writephy(tp, MII_BMCR, BMCR_PDOWN);
3118 static void r810x_phy_power_up(struct rtl8169_private *tp)
3120 rtl_writephy(tp, 0x1f, 0x0000);
3121 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE);
3124 static void r810x_pll_power_down(struct rtl8169_private *tp)
3126 if (__rtl8169_get_wol(tp) & WAKE_ANY) {
3127 rtl_writephy(tp, 0x1f, 0x0000);
3128 rtl_writephy(tp, MII_BMCR, 0x0000);
3132 r810x_phy_power_down(tp);
3135 static void r810x_pll_power_up(struct rtl8169_private *tp)
3137 r810x_phy_power_up(tp);
3140 static void r8168_phy_power_up(struct rtl8169_private *tp)
3142 rtl_writephy(tp, 0x1f, 0x0000);
3143 switch (tp->mac_version) {
3144 case RTL_GIGA_MAC_VER_11:
3145 case RTL_GIGA_MAC_VER_12:
3146 case RTL_GIGA_MAC_VER_17:
3147 case RTL_GIGA_MAC_VER_18:
3148 case RTL_GIGA_MAC_VER_19:
3149 case RTL_GIGA_MAC_VER_20:
3150 case RTL_GIGA_MAC_VER_21:
3151 case RTL_GIGA_MAC_VER_22:
3152 case RTL_GIGA_MAC_VER_23:
3153 case RTL_GIGA_MAC_VER_24:
3154 case RTL_GIGA_MAC_VER_25:
3155 case RTL_GIGA_MAC_VER_26:
3156 case RTL_GIGA_MAC_VER_27:
3157 case RTL_GIGA_MAC_VER_28:
3158 case RTL_GIGA_MAC_VER_31:
3159 rtl_writephy(tp, 0x0e, 0x0000);
3164 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE);
3167 static void r8168_phy_power_down(struct rtl8169_private *tp)
3169 rtl_writephy(tp, 0x1f, 0x0000);
3170 switch (tp->mac_version) {
3171 case RTL_GIGA_MAC_VER_32:
3172 case RTL_GIGA_MAC_VER_33:
3173 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN);
3176 case RTL_GIGA_MAC_VER_11:
3177 case RTL_GIGA_MAC_VER_12:
3178 case RTL_GIGA_MAC_VER_17:
3179 case RTL_GIGA_MAC_VER_18:
3180 case RTL_GIGA_MAC_VER_19:
3181 case RTL_GIGA_MAC_VER_20:
3182 case RTL_GIGA_MAC_VER_21:
3183 case RTL_GIGA_MAC_VER_22:
3184 case RTL_GIGA_MAC_VER_23:
3185 case RTL_GIGA_MAC_VER_24:
3186 case RTL_GIGA_MAC_VER_25:
3187 case RTL_GIGA_MAC_VER_26:
3188 case RTL_GIGA_MAC_VER_27:
3189 case RTL_GIGA_MAC_VER_28:
3190 case RTL_GIGA_MAC_VER_31:
3191 rtl_writephy(tp, 0x0e, 0x0200);
3193 rtl_writephy(tp, MII_BMCR, BMCR_PDOWN);
3198 static void r8168_pll_power_down(struct rtl8169_private *tp)
3200 void __iomem *ioaddr = tp->mmio_addr;
3202 if ((tp->mac_version == RTL_GIGA_MAC_VER_27 ||
3203 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
3204 tp->mac_version == RTL_GIGA_MAC_VER_31) &&
3205 r8168dp_check_dash(tp)) {
3209 if ((tp->mac_version == RTL_GIGA_MAC_VER_23 ||
3210 tp->mac_version == RTL_GIGA_MAC_VER_24) &&
3211 (RTL_R16(CPlusCmd) & ASF)) {
3215 if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
3216 tp->mac_version == RTL_GIGA_MAC_VER_33)
3217 rtl_ephy_write(ioaddr, 0x19, 0xff64);
3219 if (__rtl8169_get_wol(tp) & WAKE_ANY) {
3220 rtl_writephy(tp, 0x1f, 0x0000);
3221 rtl_writephy(tp, MII_BMCR, 0x0000);
3223 RTL_W32(RxConfig, RTL_R32(RxConfig) |
3224 AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
3228 r8168_phy_power_down(tp);
3230 switch (tp->mac_version) {
3231 case RTL_GIGA_MAC_VER_25:
3232 case RTL_GIGA_MAC_VER_26:
3233 case RTL_GIGA_MAC_VER_27:
3234 case RTL_GIGA_MAC_VER_28:
3235 case RTL_GIGA_MAC_VER_31:
3236 case RTL_GIGA_MAC_VER_32:
3237 case RTL_GIGA_MAC_VER_33:
3238 RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80);
3243 static void r8168_pll_power_up(struct rtl8169_private *tp)
3245 void __iomem *ioaddr = tp->mmio_addr;
3247 if ((tp->mac_version == RTL_GIGA_MAC_VER_27 ||
3248 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
3249 tp->mac_version == RTL_GIGA_MAC_VER_31) &&
3250 r8168dp_check_dash(tp)) {
3254 switch (tp->mac_version) {
3255 case RTL_GIGA_MAC_VER_25:
3256 case RTL_GIGA_MAC_VER_26:
3257 case RTL_GIGA_MAC_VER_27:
3258 case RTL_GIGA_MAC_VER_28:
3259 case RTL_GIGA_MAC_VER_31:
3260 case RTL_GIGA_MAC_VER_32:
3261 case RTL_GIGA_MAC_VER_33:
3262 RTL_W8(PMCH, RTL_R8(PMCH) | 0x80);
3266 r8168_phy_power_up(tp);
3269 static void rtl_pll_power_op(struct rtl8169_private *tp,
3270 void (*op)(struct rtl8169_private *))
3276 static void rtl_pll_power_down(struct rtl8169_private *tp)
3278 rtl_pll_power_op(tp, tp->pll_power_ops.down);
3281 static void rtl_pll_power_up(struct rtl8169_private *tp)
3283 rtl_pll_power_op(tp, tp->pll_power_ops.up);
3286 static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp)
3288 struct pll_power_ops *ops = &tp->pll_power_ops;
3290 switch (tp->mac_version) {
3291 case RTL_GIGA_MAC_VER_07:
3292 case RTL_GIGA_MAC_VER_08:
3293 case RTL_GIGA_MAC_VER_09:
3294 case RTL_GIGA_MAC_VER_10:
3295 case RTL_GIGA_MAC_VER_16:
3296 case RTL_GIGA_MAC_VER_29:
3297 case RTL_GIGA_MAC_VER_30:
3298 ops->down = r810x_pll_power_down;
3299 ops->up = r810x_pll_power_up;
3302 case RTL_GIGA_MAC_VER_11:
3303 case RTL_GIGA_MAC_VER_12:
3304 case RTL_GIGA_MAC_VER_17:
3305 case RTL_GIGA_MAC_VER_18:
3306 case RTL_GIGA_MAC_VER_19:
3307 case RTL_GIGA_MAC_VER_20:
3308 case RTL_GIGA_MAC_VER_21:
3309 case RTL_GIGA_MAC_VER_22:
3310 case RTL_GIGA_MAC_VER_23:
3311 case RTL_GIGA_MAC_VER_24:
3312 case RTL_GIGA_MAC_VER_25:
3313 case RTL_GIGA_MAC_VER_26:
3314 case RTL_GIGA_MAC_VER_27:
3315 case RTL_GIGA_MAC_VER_28:
3316 case RTL_GIGA_MAC_VER_31:
3317 case RTL_GIGA_MAC_VER_32:
3318 case RTL_GIGA_MAC_VER_33:
3319 ops->down = r8168_pll_power_down;
3320 ops->up = r8168_pll_power_up;
3330 static void rtl_hw_reset(struct rtl8169_private *tp)
3332 void __iomem *ioaddr = tp->mmio_addr;
3335 /* Soft reset the chip. */
3336 RTL_W8(ChipCmd, CmdReset);
3338 /* Check that the chip has finished the reset. */
3339 for (i = 0; i < 100; i++) {
3340 if ((RTL_R8(ChipCmd) & CmdReset) == 0)
3342 msleep_interruptible(1);
3346 static int __devinit
3347 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
3349 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
3350 const unsigned int region = cfg->region;
3351 struct rtl8169_private *tp;
3352 struct mii_if_info *mii;
3353 struct net_device *dev;
3354 void __iomem *ioaddr;
3358 if (netif_msg_drv(&debug)) {
3359 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
3360 MODULENAME, RTL8169_VERSION);
3363 dev = alloc_etherdev(sizeof (*tp));
3365 if (netif_msg_drv(&debug))
3366 dev_err(&pdev->dev, "unable to alloc new ethernet\n");
3371 SET_NETDEV_DEV(dev, &pdev->dev);
3372 dev->netdev_ops = &rtl8169_netdev_ops;
3373 tp = netdev_priv(dev);
3376 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
3380 mii->mdio_read = rtl_mdio_read;
3381 mii->mdio_write = rtl_mdio_write;
3382 mii->phy_id_mask = 0x1f;
3383 mii->reg_num_mask = 0x1f;
3384 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII);
3386 /* disable ASPM completely as that cause random device stop working
3387 * problems as well as full system hangs for some PCIe devices users */
3388 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
3389 PCIE_LINK_STATE_CLKPM);
3391 /* enable device (incl. PCI PM wakeup and hotplug setup) */
3392 rc = pci_enable_device(pdev);
3394 netif_err(tp, probe, dev, "enable failure\n");
3395 goto err_out_free_dev_1;
3398 if (pci_set_mwi(pdev) < 0)
3399 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n");
3401 /* make sure PCI base addr 1 is MMIO */
3402 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) {
3403 netif_err(tp, probe, dev,
3404 "region #%d not an MMIO resource, aborting\n",
3410 /* check for weird/broken PCI region reporting */
3411 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
3412 netif_err(tp, probe, dev,
3413 "Invalid PCI region size(s), aborting\n");
3418 rc = pci_request_regions(pdev, MODULENAME);
3420 netif_err(tp, probe, dev, "could not request regions\n");
3424 tp->cp_cmd = RxChkSum;
3426 if ((sizeof(dma_addr_t) > 4) &&
3427 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) {
3428 tp->cp_cmd |= PCIDAC;
3429 dev->features |= NETIF_F_HIGHDMA;
3431 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
3433 netif_err(tp, probe, dev, "DMA configuration failed\n");
3434 goto err_out_free_res_3;
3438 /* ioremap MMIO region */
3439 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE);
3441 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n");
3443 goto err_out_free_res_3;
3445 tp->mmio_addr = ioaddr;
3447 tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3449 netif_info(tp, probe, dev, "no PCI Express capability\n");
3451 RTL_W16(IntrMask, 0x0000);
3455 RTL_W16(IntrStatus, 0xffff);
3457 pci_set_master(pdev);
3459 /* Identify chip attached to board */
3460 rtl8169_get_mac_version(tp, dev, cfg->default_ver);
3463 * Pretend we are using VLANs; This bypasses a nasty bug where
3464 * Interrupts stop flowing on high load on 8110SCd controllers.
3466 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
3467 tp->cp_cmd |= RxVlan;
3469 rtl_init_mdio_ops(tp);
3470 rtl_init_pll_power_ops(tp);
3472 rtl8169_print_mac_version(tp);
3474 chipset = tp->mac_version;
3475 tp->txd_version = rtl_chip_infos[chipset].txd_version;
3477 RTL_W8(Cfg9346, Cfg9346_Unlock);
3478 RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
3479 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
3480 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
3481 tp->features |= RTL_FEATURE_WOL;
3482 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
3483 tp->features |= RTL_FEATURE_WOL;
3484 tp->features |= rtl_try_msi(pdev, ioaddr, cfg);
3485 RTL_W8(Cfg9346, Cfg9346_Lock);
3487 if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) &&
3488 (RTL_R8(PHYstatus) & TBI_Enable)) {
3489 tp->set_speed = rtl8169_set_speed_tbi;
3490 tp->get_settings = rtl8169_gset_tbi;
3491 tp->phy_reset_enable = rtl8169_tbi_reset_enable;
3492 tp->phy_reset_pending = rtl8169_tbi_reset_pending;
3493 tp->link_ok = rtl8169_tbi_link_ok;
3494 tp->do_ioctl = rtl_tbi_ioctl;
3496 tp->set_speed = rtl8169_set_speed_xmii;
3497 tp->get_settings = rtl8169_gset_xmii;
3498 tp->phy_reset_enable = rtl8169_xmii_reset_enable;
3499 tp->phy_reset_pending = rtl8169_xmii_reset_pending;
3500 tp->link_ok = rtl8169_xmii_link_ok;
3501 tp->do_ioctl = rtl_xmii_ioctl;
3504 spin_lock_init(&tp->lock);
3506 /* Get MAC address */
3507 for (i = 0; i < MAC_ADDR_LEN; i++)
3508 dev->dev_addr[i] = RTL_R8(MAC0 + i);
3509 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
3511 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops);
3512 dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
3513 dev->irq = pdev->irq;
3514 dev->base_addr = (unsigned long) ioaddr;
3516 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT);
3518 /* don't enable SG, IP_CSUM and TSO by default - it might not work
3519 * properly for all devices */
3520 dev->features |= NETIF_F_RXCSUM |
3521 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
3523 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
3524 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
3525 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
3528 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
3529 /* 8110SCd requires hardware Rx VLAN - disallow toggling */
3530 dev->hw_features &= ~NETIF_F_HW_VLAN_RX;
3532 tp->intr_mask = 0xffff;
3533 tp->hw_start = cfg->hw_start;
3534 tp->intr_event = cfg->intr_event;
3535 tp->napi_event = cfg->napi_event;
3537 init_timer(&tp->timer);
3538 tp->timer.data = (unsigned long) dev;
3539 tp->timer.function = rtl8169_phy_timer;
3541 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
3543 rc = register_netdev(dev);
3547 pci_set_drvdata(pdev, dev);
3549 netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n",
3550 rtl_chip_infos[chipset].name, dev->base_addr, dev->dev_addr,
3551 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq);
3553 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
3554 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
3555 tp->mac_version == RTL_GIGA_MAC_VER_31) {
3556 rtl8168_driver_start(tp);
3559 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
3561 if (pci_dev_run_wake(pdev))
3562 pm_runtime_put_noidle(&pdev->dev);
3564 netif_carrier_off(dev);
3570 rtl_disable_msi(pdev, tp);
3573 pci_release_regions(pdev);
3575 pci_clear_mwi(pdev);
3576 pci_disable_device(pdev);
3582 static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
3584 struct net_device *dev = pci_get_drvdata(pdev);
3585 struct rtl8169_private *tp = netdev_priv(dev);
3587 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
3588 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
3589 tp->mac_version == RTL_GIGA_MAC_VER_31) {
3590 rtl8168_driver_stop(tp);
3593 cancel_delayed_work_sync(&tp->task);
3595 unregister_netdev(dev);
3597 rtl_release_firmware(tp);
3599 if (pci_dev_run_wake(pdev))
3600 pm_runtime_get_noresume(&pdev->dev);
3602 /* restore original MAC address */
3603 rtl_rar_set(tp, dev->perm_addr);
3605 rtl_disable_msi(pdev, tp);
3606 rtl8169_release_board(pdev, dev, tp->mmio_addr);
3607 pci_set_drvdata(pdev, NULL);
3610 static void rtl_request_uncached_firmware(struct rtl8169_private *tp)
3612 struct rtl_fw *rtl_fw;
3616 name = rtl_lookup_firmware_name(tp);
3618 goto out_no_firmware;
3620 rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL);
3624 rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev);
3628 rc = rtl_check_firmware(tp, rtl_fw);
3630 goto err_release_firmware;
3632 tp->rtl_fw = rtl_fw;
3636 err_release_firmware:
3637 release_firmware(rtl_fw->fw);
3641 netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n",
3648 static void rtl_request_firmware(struct rtl8169_private *tp)
3650 if (IS_ERR(tp->rtl_fw))
3651 rtl_request_uncached_firmware(tp);
3654 static int rtl8169_open(struct net_device *dev)
3656 struct rtl8169_private *tp = netdev_priv(dev);
3657 void __iomem *ioaddr = tp->mmio_addr;
3658 struct pci_dev *pdev = tp->pci_dev;
3659 int retval = -ENOMEM;
3661 pm_runtime_get_sync(&pdev->dev);
3664 * Rx and Tx desscriptors needs 256 bytes alignment.
3665 * dma_alloc_coherent provides more.
3667 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
3668 &tp->TxPhyAddr, GFP_KERNEL);
3669 if (!tp->TxDescArray)
3670 goto err_pm_runtime_put;
3672 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
3673 &tp->RxPhyAddr, GFP_KERNEL);
3674 if (!tp->RxDescArray)
3677 retval = rtl8169_init_ring(dev);
3681 INIT_DELAYED_WORK(&tp->task, NULL);
3685 rtl_request_firmware(tp);
3687 retval = request_irq(dev->irq, rtl8169_interrupt,
3688 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED,
3691 goto err_release_fw_2;
3693 napi_enable(&tp->napi);
3695 rtl8169_init_phy(dev, tp);
3697 rtl8169_set_features(dev, dev->features);
3699 rtl_pll_power_up(tp);
3703 tp->saved_wolopts = 0;
3704 pm_runtime_put_noidle(&pdev->dev);
3706 rtl8169_check_link_status(dev, tp, ioaddr);
3711 rtl_release_firmware(tp);
3712 rtl8169_rx_clear(tp);
3714 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
3716 tp->RxDescArray = NULL;
3718 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
3720 tp->TxDescArray = NULL;
3722 pm_runtime_put_noidle(&pdev->dev);
3726 static void rtl8169_hw_reset(struct rtl8169_private *tp)
3728 void __iomem *ioaddr = tp->mmio_addr;
3730 /* Disable interrupts */
3731 rtl8169_irq_mask_and_ack(ioaddr);
3733 if (tp->mac_version == RTL_GIGA_MAC_VER_27 ||
3734 tp->mac_version == RTL_GIGA_MAC_VER_28 ||
3735 tp->mac_version == RTL_GIGA_MAC_VER_31) {
3736 while (RTL_R8(TxPoll) & NPQ)
3741 /* Reset the chipset */
3742 RTL_W8(ChipCmd, CmdReset);
3748 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
3750 void __iomem *ioaddr = tp->mmio_addr;
3751 u32 cfg = rtl8169_rx_config;
3753 cfg |= (RTL_R32(RxConfig) & RTL_RX_CONFIG_MASK);
3754 RTL_W32(RxConfig, cfg);
3756 /* Set DMA burst size and Interframe Gap Time */
3757 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
3758 (InterFrameGap << TxInterFrameGapShift));
3761 static void rtl_hw_start(struct net_device *dev)
3763 struct rtl8169_private *tp = netdev_priv(dev);
3769 netif_start_queue(dev);
3772 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp,
3773 void __iomem *ioaddr)
3776 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
3777 * register to be written before TxDescAddrLow to work.
3778 * Switching from MMIO to I/O access fixes the issue as well.
3780 RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
3781 RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32));
3782 RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
3783 RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
3786 static u16 rtl_rw_cpluscmd(void __iomem *ioaddr)
3790 cmd = RTL_R16(CPlusCmd);
3791 RTL_W16(CPlusCmd, cmd);
3795 static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz)
3797 /* Low hurts. Let's disable the filtering. */
3798 RTL_W16(RxMaxSize, rx_buf_sz + 1);
3801 static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version)
3803 static const struct rtl_cfg2_info {
3808 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd
3809 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff },
3810 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe
3811 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff }
3813 const struct rtl_cfg2_info *p = cfg2_info;
3817 clk = RTL_R8(Config2) & PCI_Clock_66MHz;
3818 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
3819 if ((p->mac_version == mac_version) && (p->clk == clk)) {
3820 RTL_W32(0x7c, p->val);
3826 static void rtl_hw_start_8169(struct net_device *dev)
3828 struct rtl8169_private *tp = netdev_priv(dev);
3829 void __iomem *ioaddr = tp->mmio_addr;
3830 struct pci_dev *pdev = tp->pci_dev;
3832 if (tp->mac_version == RTL_GIGA_MAC_VER_05) {
3833 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW);
3834 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08);
3837 RTL_W8(Cfg9346, Cfg9346_Unlock);
3838 if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
3839 tp->mac_version == RTL_GIGA_MAC_VER_02 ||
3840 tp->mac_version == RTL_GIGA_MAC_VER_03 ||
3841 tp->mac_version == RTL_GIGA_MAC_VER_04)
3842 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
3844 RTL_W8(EarlyTxThres, NoEarlyTx);
3846 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
3848 if (tp->mac_version == RTL_GIGA_MAC_VER_01 ||
3849 tp->mac_version == RTL_GIGA_MAC_VER_02 ||
3850 tp->mac_version == RTL_GIGA_MAC_VER_03 ||
3851 tp->mac_version == RTL_GIGA_MAC_VER_04)
3852 rtl_set_rx_tx_config_registers(tp);
3854 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW;
3856 if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
3857 tp->mac_version == RTL_GIGA_MAC_VER_03) {
3858 dprintk("Set MAC Reg C+CR Offset 0xE0. "
3859 "Bit-3 and bit-14 MUST be 1\n");
3860 tp->cp_cmd |= (1 << 14);
3863 RTL_W16(CPlusCmd, tp->cp_cmd);
3865 rtl8169_set_magic_reg(ioaddr, tp->mac_version);
3868 * Undocumented corner. Supposedly:
3869 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
3871 RTL_W16(IntrMitigate, 0x0000);
3873 rtl_set_rx_tx_desc_registers(tp, ioaddr);
3875 if (tp->mac_version != RTL_GIGA_MAC_VER_01 &&
3876 tp->mac_version != RTL_GIGA_MAC_VER_02 &&
3877 tp->mac_version != RTL_GIGA_MAC_VER_03 &&
3878 tp->mac_version != RTL_GIGA_MAC_VER_04) {
3879 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
3880 rtl_set_rx_tx_config_registers(tp);
3883 RTL_W8(Cfg9346, Cfg9346_Lock);
3885 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
3888 RTL_W32(RxMissed, 0);
3890 rtl_set_rx_mode(dev);
3892 /* no early-rx interrupts */
3893 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
3895 /* Enable all known interrupts by setting the interrupt mask. */
3896 RTL_W16(IntrMask, tp->intr_event);
3899 static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force)
3901 struct net_device *dev = pci_get_drvdata(pdev);
3902 struct rtl8169_private *tp = netdev_priv(dev);
3903 int cap = tp->pcie_cap;
3908 pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl);
3909 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force;
3910 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl);
3914 static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits)
3918 csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff;
3919 rtl_csi_write(ioaddr, 0x070c, csi | bits);
3922 static void rtl_csi_access_enable_1(void __iomem *ioaddr)
3924 rtl_csi_access_enable(ioaddr, 0x17000000);
3927 static void rtl_csi_access_enable_2(void __iomem *ioaddr)
3929 rtl_csi_access_enable(ioaddr, 0x27000000);
3933 unsigned int offset;
3938 static void rtl_ephy_init(void __iomem *ioaddr, const struct ephy_info *e, int len)
3943 w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits;
3944 rtl_ephy_write(ioaddr, e->offset, w);
3949 static void rtl_disable_clock_request(struct pci_dev *pdev)
3951 struct net_device *dev = pci_get_drvdata(pdev);
3952 struct rtl8169_private *tp = netdev_priv(dev);
3953 int cap = tp->pcie_cap;
3958 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
3959 ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN;
3960 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
3964 static void rtl_enable_clock_request(struct pci_dev *pdev)
3966 struct net_device *dev = pci_get_drvdata(pdev);
3967 struct rtl8169_private *tp = netdev_priv(dev);
3968 int cap = tp->pcie_cap;
3973 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl);
3974 ctl |= PCI_EXP_LNKCTL_CLKREQ_EN;
3975 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl);
3979 #define R8168_CPCMD_QUIRK_MASK (\
3990 static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev)
3992 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
3994 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
3996 rtl_tx_performance_tweak(pdev,
3997 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN);
4000 static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev)
4002 rtl_hw_start_8168bb(ioaddr, pdev);
4004 RTL_W8(MaxTxPacketSize, TxPacketMax);
4006 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0));
4009 static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev)
4011 RTL_W8(Config1, RTL_R8(Config1) | Speed_down);
4013 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
4015 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4017 rtl_disable_clock_request(pdev);
4019 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
4022 static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev)
4024 static const struct ephy_info e_info_8168cp[] = {
4025 { 0x01, 0, 0x0001 },
4026 { 0x02, 0x0800, 0x1000 },
4027 { 0x03, 0, 0x0042 },
4028 { 0x06, 0x0080, 0x0000 },
4032 rtl_csi_access_enable_2(ioaddr);
4034 rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp));
4036 __rtl_hw_start_8168cp(ioaddr, pdev);
4039 static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev)
4041 rtl_csi_access_enable_2(ioaddr);
4043 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
4045 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4047 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
4050 static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev)
4052 rtl_csi_access_enable_2(ioaddr);
4054 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
4057 RTL_W8(DBG_REG, 0x20);
4059 RTL_W8(MaxTxPacketSize, TxPacketMax);
4061 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4063 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
4066 static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev)
4068 static const struct ephy_info e_info_8168c_1[] = {
4069 { 0x02, 0x0800, 0x1000 },
4070 { 0x03, 0, 0x0002 },
4071 { 0x06, 0x0080, 0x0000 }
4074 rtl_csi_access_enable_2(ioaddr);
4076 RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
4078 rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1));
4080 __rtl_hw_start_8168cp(ioaddr, pdev);
4083 static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev)
4085 static const struct ephy_info e_info_8168c_2[] = {
4086 { 0x01, 0, 0x0001 },
4087 { 0x03, 0x0400, 0x0220 }
4090 rtl_csi_access_enable_2(ioaddr);
4092 rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2));
4094 __rtl_hw_start_8168cp(ioaddr, pdev);
4097 static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev)
4099 rtl_hw_start_8168c_2(ioaddr, pdev);
4102 static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev)
4104 rtl_csi_access_enable_2(ioaddr);
4106 __rtl_hw_start_8168cp(ioaddr, pdev);
4109 static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev)
4111 rtl_csi_access_enable_2(ioaddr);
4113 rtl_disable_clock_request(pdev);
4115 RTL_W8(MaxTxPacketSize, TxPacketMax);
4117 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4119 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK);
4122 static void rtl_hw_start_8168dp(void __iomem *ioaddr, struct pci_dev *pdev)
4124 rtl_csi_access_enable_1(ioaddr);
4126 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4128 RTL_W8(MaxTxPacketSize, TxPacketMax);
4130 rtl_disable_clock_request(pdev);
4133 static void rtl_hw_start_8168d_4(void __iomem *ioaddr, struct pci_dev *pdev)
4135 static const struct ephy_info e_info_8168d_4[] = {
4137 { 0x19, 0x20, 0x50 },
4142 rtl_csi_access_enable_1(ioaddr);
4144 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4146 RTL_W8(MaxTxPacketSize, TxPacketMax);
4148 for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) {
4149 const struct ephy_info *e = e_info_8168d_4 + i;
4152 w = rtl_ephy_read(ioaddr, e->offset);
4153 rtl_ephy_write(ioaddr, 0x03, (w & e->mask) | e->bits);
4156 rtl_enable_clock_request(pdev);
4159 static void rtl_hw_start_8168e(void __iomem *ioaddr, struct pci_dev *pdev)
4161 static const struct ephy_info e_info_8168e[] = {
4162 { 0x00, 0x0200, 0x0100 },
4163 { 0x00, 0x0000, 0x0004 },
4164 { 0x06, 0x0002, 0x0001 },
4165 { 0x06, 0x0000, 0x0030 },
4166 { 0x07, 0x0000, 0x2000 },
4167 { 0x00, 0x0000, 0x0020 },
4168 { 0x03, 0x5800, 0x2000 },
4169 { 0x03, 0x0000, 0x0001 },
4170 { 0x01, 0x0800, 0x1000 },
4171 { 0x07, 0x0000, 0x4000 },
4172 { 0x1e, 0x0000, 0x2000 },
4173 { 0x19, 0xffff, 0xfe6c },
4174 { 0x0a, 0x0000, 0x0040 }
4177 rtl_csi_access_enable_2(ioaddr);
4179 rtl_ephy_init(ioaddr, e_info_8168e, ARRAY_SIZE(e_info_8168e));
4181 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4183 RTL_W8(MaxTxPacketSize, TxPacketMax);
4185 rtl_disable_clock_request(pdev);
4187 /* Reset tx FIFO pointer */
4188 RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST);
4189 RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST);
4191 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en);
4194 static void rtl_hw_start_8168(struct net_device *dev)
4196 struct rtl8169_private *tp = netdev_priv(dev);
4197 void __iomem *ioaddr = tp->mmio_addr;
4198 struct pci_dev *pdev = tp->pci_dev;
4200 RTL_W8(Cfg9346, Cfg9346_Unlock);
4202 RTL_W8(MaxTxPacketSize, TxPacketMax);
4204 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
4206 tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1;
4208 RTL_W16(CPlusCmd, tp->cp_cmd);
4210 RTL_W16(IntrMitigate, 0x5151);
4212 /* Work around for RxFIFO overflow. */
4213 if (tp->mac_version == RTL_GIGA_MAC_VER_11 ||
4214 tp->mac_version == RTL_GIGA_MAC_VER_22) {
4215 tp->intr_event |= RxFIFOOver | PCSTimeout;
4216 tp->intr_event &= ~RxOverflow;
4219 rtl_set_rx_tx_desc_registers(tp, ioaddr);
4221 rtl_set_rx_mode(dev);
4223 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) |
4224 (InterFrameGap << TxInterFrameGapShift));
4228 switch (tp->mac_version) {
4229 case RTL_GIGA_MAC_VER_11:
4230 rtl_hw_start_8168bb(ioaddr, pdev);
4233 case RTL_GIGA_MAC_VER_12:
4234 case RTL_GIGA_MAC_VER_17:
4235 rtl_hw_start_8168bef(ioaddr, pdev);
4238 case RTL_GIGA_MAC_VER_18:
4239 rtl_hw_start_8168cp_1(ioaddr, pdev);
4242 case RTL_GIGA_MAC_VER_19:
4243 rtl_hw_start_8168c_1(ioaddr, pdev);
4246 case RTL_GIGA_MAC_VER_20:
4247 rtl_hw_start_8168c_2(ioaddr, pdev);
4250 case RTL_GIGA_MAC_VER_21:
4251 rtl_hw_start_8168c_3(ioaddr, pdev);
4254 case RTL_GIGA_MAC_VER_22:
4255 rtl_hw_start_8168c_4(ioaddr, pdev);
4258 case RTL_GIGA_MAC_VER_23:
4259 rtl_hw_start_8168cp_2(ioaddr, pdev);
4262 case RTL_GIGA_MAC_VER_24:
4263 rtl_hw_start_8168cp_3(ioaddr, pdev);
4266 case RTL_GIGA_MAC_VER_25:
4267 case RTL_GIGA_MAC_VER_26:
4268 case RTL_GIGA_MAC_VER_27:
4269 rtl_hw_start_8168d(ioaddr, pdev);
4272 case RTL_GIGA_MAC_VER_28:
4273 rtl_hw_start_8168d_4(ioaddr, pdev);
4276 case RTL_GIGA_MAC_VER_31:
4277 rtl_hw_start_8168dp(ioaddr, pdev);
4280 case RTL_GIGA_MAC_VER_32:
4281 case RTL_GIGA_MAC_VER_33:
4282 rtl_hw_start_8168e(ioaddr, pdev);
4286 printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n",
4287 dev->name, tp->mac_version);
4291 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
4293 RTL_W8(Cfg9346, Cfg9346_Lock);
4295 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000);
4297 RTL_W16(IntrMask, tp->intr_event);
4300 #define R810X_CPCMD_QUIRK_MASK (\
4311 static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev)
4313 static const struct ephy_info e_info_8102e_1[] = {
4314 { 0x01, 0, 0x6e65 },
4315 { 0x02, 0, 0x091f },
4316 { 0x03, 0, 0xc2f9 },
4317 { 0x06, 0, 0xafb5 },
4318 { 0x07, 0, 0x0e00 },
4319 { 0x19, 0, 0xec80 },
4320 { 0x01, 0, 0x2e65 },
4325 rtl_csi_access_enable_2(ioaddr);
4327 RTL_W8(DBG_REG, FIX_NAK_1);
4329 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4332 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable);
4333 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
4335 cfg1 = RTL_R8(Config1);
4336 if ((cfg1 & LEDS0) && (cfg1 & LEDS1))
4337 RTL_W8(Config1, cfg1 & ~LEDS0);
4339 rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1));
4342 static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev)
4344 rtl_csi_access_enable_2(ioaddr);
4346 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT);
4348 RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable);
4349 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en);
4352 static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev)
4354 rtl_hw_start_8102e_2(ioaddr, pdev);
4356 rtl_ephy_write(ioaddr, 0x03, 0xc2f9);
4359 static void rtl_hw_start_8105e_1(void __iomem *ioaddr, struct pci_dev *pdev)
4361 static const struct ephy_info e_info_8105e_1[] = {
4362 { 0x07, 0, 0x4000 },
4363 { 0x19, 0, 0x0200 },
4364 { 0x19, 0, 0x0020 },
4365 { 0x1e, 0, 0x2000 },
4366 { 0x03, 0, 0x0001 },
4367 { 0x19, 0, 0x0100 },
4368 { 0x19, 0, 0x0004 },
4372 /* Force LAN exit from ASPM if Rx/Tx are not idle */
4373 RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800);
4375 /* Disable Early Tally Counter */
4376 RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000);
4378 RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET);
4379 RTL_W8(DLLPR, RTL_R8(DLLPR) | PM_SWITCH);
4381 rtl_ephy_init(ioaddr, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1));
4384 static void rtl_hw_start_8105e_2(void __iomem *ioaddr, struct pci_dev *pdev)
4386 rtl_hw_start_8105e_1(ioaddr, pdev);
4387 rtl_ephy_write(ioaddr, 0x1e, rtl_ephy_read(ioaddr, 0x1e) | 0x8000);
4390 static void rtl_hw_start_8101(struct net_device *dev)
4392 struct rtl8169_private *tp = netdev_priv(dev);
4393 void __iomem *ioaddr = tp->mmio_addr;
4394 struct pci_dev *pdev = tp->pci_dev;
4396 if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
4397 tp->mac_version == RTL_GIGA_MAC_VER_16) {
4398 int cap = tp->pcie_cap;
4401 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL,
4402 PCI_EXP_DEVCTL_NOSNOOP_EN);
4406 RTL_W8(Cfg9346, Cfg9346_Unlock);
4408 switch (tp->mac_version) {
4409 case RTL_GIGA_MAC_VER_07:
4410 rtl_hw_start_8102e_1(ioaddr, pdev);
4413 case RTL_GIGA_MAC_VER_08:
4414 rtl_hw_start_8102e_3(ioaddr, pdev);
4417 case RTL_GIGA_MAC_VER_09:
4418 rtl_hw_start_8102e_2(ioaddr, pdev);
4421 case RTL_GIGA_MAC_VER_29:
4422 rtl_hw_start_8105e_1(ioaddr, pdev);
4424 case RTL_GIGA_MAC_VER_30:
4425 rtl_hw_start_8105e_2(ioaddr, pdev);
4429 RTL_W8(Cfg9346, Cfg9346_Lock);
4431 RTL_W8(MaxTxPacketSize, TxPacketMax);
4433 rtl_set_rx_max_size(ioaddr, rx_buf_sz);
4435 tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK;
4436 RTL_W16(CPlusCmd, tp->cp_cmd);
4438 RTL_W16(IntrMitigate, 0x0000);
4440 rtl_set_rx_tx_desc_registers(tp, ioaddr);
4442 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
4443 rtl_set_rx_tx_config_registers(tp);
4447 rtl_set_rx_mode(dev);
4449 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000);
4451 RTL_W16(IntrMask, tp->intr_event);
4454 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
4456 if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu)
4460 netdev_update_features(dev);
4465 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
4467 desc->addr = cpu_to_le64(0x0badbadbadbadbadull);
4468 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask);
4471 static void rtl8169_free_rx_databuff(struct rtl8169_private *tp,
4472 void **data_buff, struct RxDesc *desc)
4474 dma_unmap_single(&tp->pci_dev->dev, le64_to_cpu(desc->addr), rx_buf_sz,
4479 rtl8169_make_unusable_by_asic(desc);
4482 static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz)
4484 u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
4486 desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz);
4489 static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
4492 desc->addr = cpu_to_le64(mapping);
4494 rtl8169_mark_to_asic(desc, rx_buf_sz);
4497 static inline void *rtl8169_align(void *data)
4499 return (void *)ALIGN((long)data, 16);
4502 static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
4503 struct RxDesc *desc)
4507 struct device *d = &tp->pci_dev->dev;
4508 struct net_device *dev = tp->dev;
4509 int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1;
4511 data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node);
4515 if (rtl8169_align(data) != data) {
4517 data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node);
4522 mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz,
4524 if (unlikely(dma_mapping_error(d, mapping))) {
4525 if (net_ratelimit())
4526 netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
4530 rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
4538 static void rtl8169_rx_clear(struct rtl8169_private *tp)
4542 for (i = 0; i < NUM_RX_DESC; i++) {
4543 if (tp->Rx_databuff[i]) {
4544 rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i,
4545 tp->RxDescArray + i);
4550 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc)
4552 desc->opts1 |= cpu_to_le32(RingEnd);
4555 static int rtl8169_rx_fill(struct rtl8169_private *tp)
4559 for (i = 0; i < NUM_RX_DESC; i++) {
4562 if (tp->Rx_databuff[i])
4565 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i);
4567 rtl8169_make_unusable_by_asic(tp->RxDescArray + i);
4570 tp->Rx_databuff[i] = data;
4573 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
4577 rtl8169_rx_clear(tp);
4581 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
4583 tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0;
4586 static int rtl8169_init_ring(struct net_device *dev)
4588 struct rtl8169_private *tp = netdev_priv(dev);
4590 rtl8169_init_ring_indexes(tp);
4592 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
4593 memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *));
4595 return rtl8169_rx_fill(tp);
4598 static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb,
4599 struct TxDesc *desc)
4601 unsigned int len = tx_skb->len;
4603 dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE);
4611 static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start,
4616 for (i = 0; i < n; i++) {
4617 unsigned int entry = (start + i) % NUM_TX_DESC;
4618 struct ring_info *tx_skb = tp->tx_skb + entry;
4619 unsigned int len = tx_skb->len;
4622 struct sk_buff *skb = tx_skb->skb;
4624 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
4625 tp->TxDescArray + entry);
4627 tp->dev->stats.tx_dropped++;
4635 static void rtl8169_tx_clear(struct rtl8169_private *tp)
4637 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC);
4638 tp->cur_tx = tp->dirty_tx = 0;
4641 static void rtl8169_schedule_work(struct net_device *dev, work_func_t task)
4643 struct rtl8169_private *tp = netdev_priv(dev);
4645 PREPARE_DELAYED_WORK(&tp->task, task);
4646 schedule_delayed_work(&tp->task, 4);
4649 static void rtl8169_wait_for_quiescence(struct net_device *dev)
4651 struct rtl8169_private *tp = netdev_priv(dev);
4652 void __iomem *ioaddr = tp->mmio_addr;
4654 synchronize_irq(dev->irq);
4656 /* Wait for any pending NAPI task to complete */
4657 napi_disable(&tp->napi);
4659 rtl8169_irq_mask_and_ack(ioaddr);
4661 tp->intr_mask = 0xffff;
4662 RTL_W16(IntrMask, tp->intr_event);
4663 napi_enable(&tp->napi);
4666 static void rtl8169_reinit_task(struct work_struct *work)
4668 struct rtl8169_private *tp =
4669 container_of(work, struct rtl8169_private, task.work);
4670 struct net_device *dev = tp->dev;
4675 if (!netif_running(dev))
4678 rtl8169_wait_for_quiescence(dev);
4681 ret = rtl8169_open(dev);
4682 if (unlikely(ret < 0)) {
4683 if (net_ratelimit())
4684 netif_err(tp, drv, dev,
4685 "reinit failure (status = %d). Rescheduling\n",
4687 rtl8169_schedule_work(dev, rtl8169_reinit_task);
4694 static void rtl8169_reset_task(struct work_struct *work)
4696 struct rtl8169_private *tp =
4697 container_of(work, struct rtl8169_private, task.work);
4698 struct net_device *dev = tp->dev;
4703 if (!netif_running(dev))
4706 rtl8169_wait_for_quiescence(dev);
4708 for (i = 0; i < NUM_RX_DESC; i++)
4709 rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz);
4711 rtl8169_tx_clear(tp);
4713 rtl8169_init_ring_indexes(tp);
4715 netif_wake_queue(dev);
4716 rtl8169_check_link_status(dev, tp, tp->mmio_addr);
4722 static void rtl8169_tx_timeout(struct net_device *dev)
4724 struct rtl8169_private *tp = netdev_priv(dev);
4726 rtl8169_hw_reset(tp);
4728 /* Let's wait a bit while any (async) irq lands on */
4729 rtl8169_schedule_work(dev, rtl8169_reset_task);
4732 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
4735 struct skb_shared_info *info = skb_shinfo(skb);
4736 unsigned int cur_frag, entry;
4737 struct TxDesc * uninitialized_var(txd);
4738 struct device *d = &tp->pci_dev->dev;
4741 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
4742 skb_frag_t *frag = info->frags + cur_frag;
4747 entry = (entry + 1) % NUM_TX_DESC;
4749 txd = tp->TxDescArray + entry;
4751 addr = ((void *) page_address(frag->page)) + frag->page_offset;
4752 mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE);
4753 if (unlikely(dma_mapping_error(d, mapping))) {
4754 if (net_ratelimit())
4755 netif_err(tp, drv, tp->dev,
4756 "Failed to map TX fragments DMA!\n");
4760 /* Anti gcc 2.95.3 bugware (sic) */
4761 status = opts[0] | len |
4762 (RingEnd * !((entry + 1) % NUM_TX_DESC));
4764 txd->opts1 = cpu_to_le32(status);
4765 txd->opts2 = cpu_to_le32(opts[1]);
4766 txd->addr = cpu_to_le64(mapping);
4768 tp->tx_skb[entry].len = len;
4772 tp->tx_skb[entry].skb = skb;
4773 txd->opts1 |= cpu_to_le32(LastFrag);
4779 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag);
4783 static inline void rtl8169_tso_csum(struct rtl8169_private *tp,
4784 struct sk_buff *skb, u32 *opts)
4786 const struct rtl_tx_desc_info *info = tx_desc_info + tp->txd_version;
4787 u32 mss = skb_shinfo(skb)->gso_size;
4788 int offset = info->opts_offset;
4792 opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift;
4793 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
4794 const struct iphdr *ip = ip_hdr(skb);
4796 if (ip->protocol == IPPROTO_TCP)
4797 opts[offset] |= info->checksum.tcp;
4798 else if (ip->protocol == IPPROTO_UDP)
4799 opts[offset] |= info->checksum.udp;
4805 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
4806 struct net_device *dev)
4808 struct rtl8169_private *tp = netdev_priv(dev);
4809 unsigned int entry = tp->cur_tx % NUM_TX_DESC;
4810 struct TxDesc *txd = tp->TxDescArray + entry;
4811 void __iomem *ioaddr = tp->mmio_addr;
4812 struct device *d = &tp->pci_dev->dev;
4818 if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
4819 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
4823 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn))
4826 len = skb_headlen(skb);
4827 mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE);
4828 if (unlikely(dma_mapping_error(d, mapping))) {
4829 if (net_ratelimit())
4830 netif_err(tp, drv, dev, "Failed to map TX DMA!\n");
4834 tp->tx_skb[entry].len = len;
4835 txd->addr = cpu_to_le64(mapping);
4837 opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb));
4840 rtl8169_tso_csum(tp, skb, opts);
4842 frags = rtl8169_xmit_frags(tp, skb, opts);
4846 opts[0] |= FirstFrag;
4848 opts[0] |= FirstFrag | LastFrag;
4849 tp->tx_skb[entry].skb = skb;
4852 txd->opts2 = cpu_to_le32(opts[1]);
4856 /* Anti gcc 2.95.3 bugware (sic) */
4857 status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
4858 txd->opts1 = cpu_to_le32(status);
4860 tp->cur_tx += frags + 1;
4864 RTL_W8(TxPoll, NPQ);
4866 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
4867 netif_stop_queue(dev);
4869 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
4870 netif_wake_queue(dev);
4873 return NETDEV_TX_OK;
4876 rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd);
4879 dev->stats.tx_dropped++;
4880 return NETDEV_TX_OK;
4883 netif_stop_queue(dev);
4884 dev->stats.tx_dropped++;
4885 return NETDEV_TX_BUSY;
4888 static void rtl8169_pcierr_interrupt(struct net_device *dev)
4890 struct rtl8169_private *tp = netdev_priv(dev);
4891 struct pci_dev *pdev = tp->pci_dev;
4892 u16 pci_status, pci_cmd;
4894 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
4895 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
4897 netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n",
4898 pci_cmd, pci_status);
4901 * The recovery sequence below admits a very elaborated explanation:
4902 * - it seems to work;
4903 * - I did not see what else could be done;
4904 * - it makes iop3xx happy.
4906 * Feel free to adjust to your needs.
4908 if (pdev->broken_parity_status)
4909 pci_cmd &= ~PCI_COMMAND_PARITY;
4911 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
4913 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
4915 pci_write_config_word(pdev, PCI_STATUS,
4916 pci_status & (PCI_STATUS_DETECTED_PARITY |
4917 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT |
4918 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT));
4920 /* The infamous DAC f*ckup only happens at boot time */
4921 if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) {
4922 void __iomem *ioaddr = tp->mmio_addr;
4924 netif_info(tp, intr, dev, "disabling PCI DAC\n");
4925 tp->cp_cmd &= ~PCIDAC;
4926 RTL_W16(CPlusCmd, tp->cp_cmd);
4927 dev->features &= ~NETIF_F_HIGHDMA;
4930 rtl8169_hw_reset(tp);
4932 rtl8169_schedule_work(dev, rtl8169_reinit_task);
4935 static void rtl8169_tx_interrupt(struct net_device *dev,
4936 struct rtl8169_private *tp,
4937 void __iomem *ioaddr)
4939 unsigned int dirty_tx, tx_left;
4941 dirty_tx = tp->dirty_tx;
4943 tx_left = tp->cur_tx - dirty_tx;
4945 while (tx_left > 0) {
4946 unsigned int entry = dirty_tx % NUM_TX_DESC;
4947 struct ring_info *tx_skb = tp->tx_skb + entry;
4951 status = le32_to_cpu(tp->TxDescArray[entry].opts1);
4952 if (status & DescOwn)
4955 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb,
4956 tp->TxDescArray + entry);
4957 if (status & LastFrag) {
4958 dev->stats.tx_packets++;
4959 dev->stats.tx_bytes += tx_skb->skb->len;
4960 dev_kfree_skb(tx_skb->skb);
4967 if (tp->dirty_tx != dirty_tx) {
4968 tp->dirty_tx = dirty_tx;
4970 if (netif_queue_stopped(dev) &&
4971 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
4972 netif_wake_queue(dev);
4975 * 8168 hack: TxPoll requests are lost when the Tx packets are
4976 * too close. Let's kick an extra TxPoll request when a burst
4977 * of start_xmit activity is detected (if it is not detected,
4978 * it is slow enough). -- FR
4981 if (tp->cur_tx != dirty_tx)
4982 RTL_W8(TxPoll, NPQ);
4986 static inline int rtl8169_fragmented_frame(u32 status)
4988 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag);
4991 static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1)
4993 u32 status = opts1 & RxProtoMask;
4995 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||
4996 ((status == RxProtoUDP) && !(opts1 & UDPFail)))
4997 skb->ip_summed = CHECKSUM_UNNECESSARY;
4999 skb_checksum_none_assert(skb);
5002 static struct sk_buff *rtl8169_try_rx_copy(void *data,
5003 struct rtl8169_private *tp,
5007 struct sk_buff *skb;
5008 struct device *d = &tp->pci_dev->dev;
5010 data = rtl8169_align(data);
5011 dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
5013 skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size);
5015 memcpy(skb->data, data, pkt_size);
5016 dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE);
5021 static int rtl8169_rx_interrupt(struct net_device *dev,
5022 struct rtl8169_private *tp,
5023 void __iomem *ioaddr, u32 budget)
5025 unsigned int cur_rx, rx_left;
5028 cur_rx = tp->cur_rx;
5029 rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx;
5030 rx_left = min(rx_left, budget);
5032 for (; rx_left > 0; rx_left--, cur_rx++) {
5033 unsigned int entry = cur_rx % NUM_RX_DESC;
5034 struct RxDesc *desc = tp->RxDescArray + entry;
5038 status = le32_to_cpu(desc->opts1);
5040 if (status & DescOwn)
5042 if (unlikely(status & RxRES)) {
5043 netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n",
5045 dev->stats.rx_errors++;
5046 if (status & (RxRWT | RxRUNT))
5047 dev->stats.rx_length_errors++;
5049 dev->stats.rx_crc_errors++;
5050 if (status & RxFOVF) {
5051 rtl8169_schedule_work(dev, rtl8169_reset_task);
5052 dev->stats.rx_fifo_errors++;
5054 rtl8169_mark_to_asic(desc, rx_buf_sz);
5056 struct sk_buff *skb;
5057 dma_addr_t addr = le64_to_cpu(desc->addr);
5058 int pkt_size = (status & 0x00001FFF) - 4;
5061 * The driver does not support incoming fragmented
5062 * frames. They are seen as a symptom of over-mtu
5065 if (unlikely(rtl8169_fragmented_frame(status))) {
5066 dev->stats.rx_dropped++;
5067 dev->stats.rx_length_errors++;
5068 rtl8169_mark_to_asic(desc, rx_buf_sz);
5072 skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry],
5073 tp, pkt_size, addr);
5074 rtl8169_mark_to_asic(desc, rx_buf_sz);
5076 dev->stats.rx_dropped++;
5080 rtl8169_rx_csum(skb, status);
5081 skb_put(skb, pkt_size);
5082 skb->protocol = eth_type_trans(skb, dev);
5084 rtl8169_rx_vlan_tag(desc, skb);
5086 napi_gro_receive(&tp->napi, skb);
5088 dev->stats.rx_bytes += pkt_size;
5089 dev->stats.rx_packets++;
5092 /* Work around for AMD plateform. */
5093 if ((desc->opts2 & cpu_to_le32(0xfffe000)) &&
5094 (tp->mac_version == RTL_GIGA_MAC_VER_05)) {
5100 count = cur_rx - tp->cur_rx;
5101 tp->cur_rx = cur_rx;
5103 tp->dirty_rx += count;
5108 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
5110 struct net_device *dev = dev_instance;
5111 struct rtl8169_private *tp = netdev_priv(dev);
5112 void __iomem *ioaddr = tp->mmio_addr;
5116 /* loop handling interrupts until we have no new ones or
5117 * we hit a invalid/hotplug case.
5119 status = RTL_R16(IntrStatus);
5120 while (status && status != 0xffff) {
5123 /* Handle all of the error cases first. These will reset
5124 * the chip, so just exit the loop.
5126 if (unlikely(!netif_running(dev))) {
5127 rtl8169_asic_down(ioaddr);
5131 if (unlikely(status & RxFIFOOver)) {
5132 switch (tp->mac_version) {
5133 /* Work around for rx fifo overflow */
5134 case RTL_GIGA_MAC_VER_11:
5135 case RTL_GIGA_MAC_VER_22:
5136 case RTL_GIGA_MAC_VER_26:
5137 netif_stop_queue(dev);
5138 rtl8169_tx_timeout(dev);
5140 /* Testers needed. */
5141 case RTL_GIGA_MAC_VER_17:
5142 case RTL_GIGA_MAC_VER_19:
5143 case RTL_GIGA_MAC_VER_20:
5144 case RTL_GIGA_MAC_VER_21:
5145 case RTL_GIGA_MAC_VER_23:
5146 case RTL_GIGA_MAC_VER_24:
5147 case RTL_GIGA_MAC_VER_27:
5148 case RTL_GIGA_MAC_VER_28:
5149 case RTL_GIGA_MAC_VER_31:
5150 /* Experimental science. Pktgen proof. */
5151 case RTL_GIGA_MAC_VER_12:
5152 case RTL_GIGA_MAC_VER_25:
5153 if (status == RxFIFOOver)
5161 if (unlikely(status & SYSErr)) {
5162 rtl8169_pcierr_interrupt(dev);
5166 if (status & LinkChg)
5167 __rtl8169_check_link_status(dev, tp, ioaddr, true);
5169 /* We need to see the lastest version of tp->intr_mask to
5170 * avoid ignoring an MSI interrupt and having to wait for
5171 * another event which may never come.
5174 if (status & tp->intr_mask & tp->napi_event) {
5175 RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
5176 tp->intr_mask = ~tp->napi_event;
5178 if (likely(napi_schedule_prep(&tp->napi)))
5179 __napi_schedule(&tp->napi);
5181 netif_info(tp, intr, dev,
5182 "interrupt %04x in poll\n", status);
5185 /* We only get a new MSI interrupt when all active irq
5186 * sources on the chip have been acknowledged. So, ack
5187 * everything we've seen and check if new sources have become
5188 * active to avoid blocking all interrupts from the chip.
5191 (status & RxFIFOOver) ? (status | RxOverflow) : status);
5192 status = RTL_R16(IntrStatus);
5195 return IRQ_RETVAL(handled);
5198 static int rtl8169_poll(struct napi_struct *napi, int budget)
5200 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
5201 struct net_device *dev = tp->dev;
5202 void __iomem *ioaddr = tp->mmio_addr;
5205 work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget);
5206 rtl8169_tx_interrupt(dev, tp, ioaddr);
5208 if (work_done < budget) {
5209 napi_complete(napi);
5211 /* We need for force the visibility of tp->intr_mask
5212 * for other CPUs, as we can loose an MSI interrupt
5213 * and potentially wait for a retransmit timeout if we don't.
5214 * The posted write to IntrMask is safe, as it will
5215 * eventually make it to the chip and we won't loose anything
5218 tp->intr_mask = 0xffff;
5220 RTL_W16(IntrMask, tp->intr_event);
5226 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr)
5228 struct rtl8169_private *tp = netdev_priv(dev);
5230 if (tp->mac_version > RTL_GIGA_MAC_VER_06)
5233 dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff);
5234 RTL_W32(RxMissed, 0);
5237 static void rtl8169_down(struct net_device *dev)
5239 struct rtl8169_private *tp = netdev_priv(dev);
5240 void __iomem *ioaddr = tp->mmio_addr;
5242 del_timer_sync(&tp->timer);
5244 netif_stop_queue(dev);
5246 napi_disable(&tp->napi);
5248 spin_lock_irq(&tp->lock);
5250 rtl8169_asic_down(ioaddr);
5252 * At this point device interrupts can not be enabled in any function,
5253 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task,
5254 * rtl8169_reinit_task) and napi is disabled (rtl8169_poll).
5256 rtl8169_rx_missed(dev, ioaddr);
5258 spin_unlock_irq(&tp->lock);
5260 synchronize_irq(dev->irq);
5262 /* Give a racing hard_start_xmit a few cycles to complete. */
5263 synchronize_sched(); /* FIXME: should this be synchronize_irq()? */
5265 rtl8169_tx_clear(tp);
5267 rtl8169_rx_clear(tp);
5269 rtl_pll_power_down(tp);
5272 static int rtl8169_close(struct net_device *dev)
5274 struct rtl8169_private *tp = netdev_priv(dev);
5275 struct pci_dev *pdev = tp->pci_dev;
5277 pm_runtime_get_sync(&pdev->dev);
5279 /* Update counters before going down */
5280 rtl8169_update_counters(dev);
5284 free_irq(dev->irq, dev);
5286 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
5288 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
5290 tp->TxDescArray = NULL;
5291 tp->RxDescArray = NULL;
5293 pm_runtime_put_sync(&pdev->dev);
5298 static void rtl_set_rx_mode(struct net_device *dev)
5300 struct rtl8169_private *tp = netdev_priv(dev);
5301 void __iomem *ioaddr = tp->mmio_addr;
5302 unsigned long flags;
5303 u32 mc_filter[2]; /* Multicast hash filter */
5307 if (dev->flags & IFF_PROMISC) {
5308 /* Unconditionally log net taps. */
5309 netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
5311 AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
5313 mc_filter[1] = mc_filter[0] = 0xffffffff;
5314 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
5315 (dev->flags & IFF_ALLMULTI)) {
5316 /* Too many to filter perfectly -- accept all multicasts. */
5317 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
5318 mc_filter[1] = mc_filter[0] = 0xffffffff;
5320 struct netdev_hw_addr *ha;
5322 rx_mode = AcceptBroadcast | AcceptMyPhys;
5323 mc_filter[1] = mc_filter[0] = 0;
5324 netdev_for_each_mc_addr(ha, dev) {
5325 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
5326 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
5327 rx_mode |= AcceptMulticast;
5331 spin_lock_irqsave(&tp->lock, flags);
5333 tmp = rtl8169_rx_config | rx_mode |
5334 (RTL_R32(RxConfig) & RTL_RX_CONFIG_MASK);
5336 if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
5337 u32 data = mc_filter[0];
5339 mc_filter[0] = swab32(mc_filter[1]);
5340 mc_filter[1] = swab32(data);
5343 RTL_W32(MAR0 + 4, mc_filter[1]);
5344 RTL_W32(MAR0 + 0, mc_filter[0]);
5346 RTL_W32(RxConfig, tmp);
5348 spin_unlock_irqrestore(&tp->lock, flags);
5352 * rtl8169_get_stats - Get rtl8169 read/write statistics
5353 * @dev: The Ethernet Device to get statistics for
5355 * Get TX/RX statistics for rtl8169
5357 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
5359 struct rtl8169_private *tp = netdev_priv(dev);
5360 void __iomem *ioaddr = tp->mmio_addr;
5361 unsigned long flags;
5363 if (netif_running(dev)) {
5364 spin_lock_irqsave(&tp->lock, flags);
5365 rtl8169_rx_missed(dev, ioaddr);
5366 spin_unlock_irqrestore(&tp->lock, flags);
5372 static void rtl8169_net_suspend(struct net_device *dev)
5374 struct rtl8169_private *tp = netdev_priv(dev);
5376 if (!netif_running(dev))
5379 rtl_pll_power_down(tp);
5381 netif_device_detach(dev);
5382 netif_stop_queue(dev);
5387 static int rtl8169_suspend(struct device *device)
5389 struct pci_dev *pdev = to_pci_dev(device);
5390 struct net_device *dev = pci_get_drvdata(pdev);
5392 rtl8169_net_suspend(dev);
5397 static void __rtl8169_resume(struct net_device *dev)
5399 struct rtl8169_private *tp = netdev_priv(dev);
5401 netif_device_attach(dev);
5403 rtl_pll_power_up(tp);
5405 rtl8169_schedule_work(dev, rtl8169_reset_task);
5408 static int rtl8169_resume(struct device *device)
5410 struct pci_dev *pdev = to_pci_dev(device);
5411 struct net_device *dev = pci_get_drvdata(pdev);
5412 struct rtl8169_private *tp = netdev_priv(dev);
5414 rtl8169_init_phy(dev, tp);
5416 if (netif_running(dev))
5417 __rtl8169_resume(dev);
5422 static int rtl8169_runtime_suspend(struct device *device)
5424 struct pci_dev *pdev = to_pci_dev(device);
5425 struct net_device *dev = pci_get_drvdata(pdev);
5426 struct rtl8169_private *tp = netdev_priv(dev);
5428 if (!tp->TxDescArray)
5431 spin_lock_irq(&tp->lock);
5432 tp->saved_wolopts = __rtl8169_get_wol(tp);
5433 __rtl8169_set_wol(tp, WAKE_ANY);
5434 spin_unlock_irq(&tp->lock);
5436 rtl8169_net_suspend(dev);
5441 static int rtl8169_runtime_resume(struct device *device)
5443 struct pci_dev *pdev = to_pci_dev(device);
5444 struct net_device *dev = pci_get_drvdata(pdev);
5445 struct rtl8169_private *tp = netdev_priv(dev);
5447 if (!tp->TxDescArray)
5450 spin_lock_irq(&tp->lock);
5451 __rtl8169_set_wol(tp, tp->saved_wolopts);
5452 tp->saved_wolopts = 0;
5453 spin_unlock_irq(&tp->lock);
5455 rtl8169_init_phy(dev, tp);
5457 __rtl8169_resume(dev);
5462 static int rtl8169_runtime_idle(struct device *device)
5464 struct pci_dev *pdev = to_pci_dev(device);
5465 struct net_device *dev = pci_get_drvdata(pdev);
5466 struct rtl8169_private *tp = netdev_priv(dev);
5468 return tp->TxDescArray ? -EBUSY : 0;
5471 static const struct dev_pm_ops rtl8169_pm_ops = {
5472 .suspend = rtl8169_suspend,
5473 .resume = rtl8169_resume,
5474 .freeze = rtl8169_suspend,
5475 .thaw = rtl8169_resume,
5476 .poweroff = rtl8169_suspend,
5477 .restore = rtl8169_resume,
5478 .runtime_suspend = rtl8169_runtime_suspend,
5479 .runtime_resume = rtl8169_runtime_resume,
5480 .runtime_idle = rtl8169_runtime_idle,
5483 #define RTL8169_PM_OPS (&rtl8169_pm_ops)
5485 #else /* !CONFIG_PM */
5487 #define RTL8169_PM_OPS NULL
5489 #endif /* !CONFIG_PM */
5491 static void rtl_shutdown(struct pci_dev *pdev)
5493 struct net_device *dev = pci_get_drvdata(pdev);
5494 struct rtl8169_private *tp = netdev_priv(dev);
5495 void __iomem *ioaddr = tp->mmio_addr;
5497 rtl8169_net_suspend(dev);
5499 /* Restore original MAC address */
5500 rtl_rar_set(tp, dev->perm_addr);
5502 spin_lock_irq(&tp->lock);
5504 rtl8169_asic_down(ioaddr);
5506 spin_unlock_irq(&tp->lock);
5508 if (system_state == SYSTEM_POWER_OFF) {
5509 /* WoL fails with some 8168 when the receiver is disabled. */
5510 if (tp->features & RTL_FEATURE_WOL) {
5511 pci_clear_master(pdev);
5513 RTL_W8(ChipCmd, CmdRxEnb);
5518 pci_wake_from_d3(pdev, true);
5519 pci_set_power_state(pdev, PCI_D3hot);
5523 static struct pci_driver rtl8169_pci_driver = {
5525 .id_table = rtl8169_pci_tbl,
5526 .probe = rtl8169_init_one,
5527 .remove = __devexit_p(rtl8169_remove_one),
5528 .shutdown = rtl_shutdown,
5529 .driver.pm = RTL8169_PM_OPS,
5532 static int __init rtl8169_init_module(void)
5534 return pci_register_driver(&rtl8169_pci_driver);
5537 static void __exit rtl8169_cleanup_module(void)
5539 pci_unregister_driver(&rtl8169_pci_driver);
5542 module_init(rtl8169_init_module);
5543 module_exit(rtl8169_cleanup_module);