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/phy.h>
20 #include <linux/if_vlan.h>
21 #include <linux/crc32.h>
24 #include <linux/tcp.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/prefetch.h>
30 #include <linux/ipv6.h>
31 #include <net/ip6_checksum.h>
36 #define RTL8169_VERSION "2.3LK-NAPI"
37 #define MODULENAME "r8169"
39 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw"
40 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw"
41 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw"
42 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw"
43 #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw"
44 #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw"
45 #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw"
46 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw"
47 #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw"
48 #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw"
49 #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw"
50 #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw"
51 #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw"
52 #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw"
53 #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw"
54 #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw"
55 #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw"
56 #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw"
57 #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw"
59 #define R8169_MSG_DEFAULT \
60 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
62 #define TX_SLOTS_AVAIL(tp) \
63 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
65 /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
66 #define TX_FRAGS_READY_FOR(tp,nr_frags) \
67 (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
69 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
70 The RTL chips use a 64 element hash table based on the Ethernet CRC. */
71 static const int multicast_filter_limit = 32;
73 #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */
74 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */
76 #define R8169_REGS_SIZE 256
77 #define R8169_RX_BUF_SIZE (SZ_16K - 1)
78 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */
79 #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */
80 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
81 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
83 #define RTL8169_TX_TIMEOUT (6*HZ)
85 /* write/read MMIO register */
86 #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg))
87 #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg))
88 #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg))
89 #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg))
90 #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg))
91 #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg))
94 RTL_GIGA_MAC_VER_01 = 0,
145 RTL_GIGA_MAC_NONE = 0xff,
148 enum rtl_tx_desc_version {
153 #define JUMBO_1K ETH_DATA_LEN
154 #define JUMBO_4K (4*1024 - ETH_HLEN - 2)
155 #define JUMBO_6K (6*1024 - ETH_HLEN - 2)
156 #define JUMBO_7K (7*1024 - ETH_HLEN - 2)
157 #define JUMBO_9K (9*1024 - ETH_HLEN - 2)
159 #define _R(NAME,TD,FW,SZ) { \
166 static const struct {
168 enum rtl_tx_desc_version txd_version;
171 } rtl_chip_infos[] = {
173 [RTL_GIGA_MAC_VER_01] =
174 _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K),
175 [RTL_GIGA_MAC_VER_02] =
176 _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K),
177 [RTL_GIGA_MAC_VER_03] =
178 _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K),
179 [RTL_GIGA_MAC_VER_04] =
180 _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K),
181 [RTL_GIGA_MAC_VER_05] =
182 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K),
183 [RTL_GIGA_MAC_VER_06] =
184 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K),
186 [RTL_GIGA_MAC_VER_07] =
187 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K),
188 [RTL_GIGA_MAC_VER_08] =
189 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K),
190 [RTL_GIGA_MAC_VER_09] =
191 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K),
192 [RTL_GIGA_MAC_VER_10] =
193 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K),
194 [RTL_GIGA_MAC_VER_11] =
195 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K),
196 [RTL_GIGA_MAC_VER_12] =
197 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K),
198 [RTL_GIGA_MAC_VER_13] =
199 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K),
200 [RTL_GIGA_MAC_VER_14] =
201 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K),
202 [RTL_GIGA_MAC_VER_15] =
203 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K),
204 [RTL_GIGA_MAC_VER_16] =
205 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K),
206 [RTL_GIGA_MAC_VER_17] =
207 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K),
208 [RTL_GIGA_MAC_VER_18] =
209 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K),
210 [RTL_GIGA_MAC_VER_19] =
211 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K),
212 [RTL_GIGA_MAC_VER_20] =
213 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K),
214 [RTL_GIGA_MAC_VER_21] =
215 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K),
216 [RTL_GIGA_MAC_VER_22] =
217 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K),
218 [RTL_GIGA_MAC_VER_23] =
219 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K),
220 [RTL_GIGA_MAC_VER_24] =
221 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K),
222 [RTL_GIGA_MAC_VER_25] =
223 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, JUMBO_9K),
224 [RTL_GIGA_MAC_VER_26] =
225 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, JUMBO_9K),
226 [RTL_GIGA_MAC_VER_27] =
227 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K),
228 [RTL_GIGA_MAC_VER_28] =
229 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K),
230 [RTL_GIGA_MAC_VER_29] =
231 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K),
232 [RTL_GIGA_MAC_VER_30] =
233 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K),
234 [RTL_GIGA_MAC_VER_31] =
235 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K),
236 [RTL_GIGA_MAC_VER_32] =
237 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, JUMBO_9K),
238 [RTL_GIGA_MAC_VER_33] =
239 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, JUMBO_9K),
240 [RTL_GIGA_MAC_VER_34] =
241 _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, JUMBO_9K),
242 [RTL_GIGA_MAC_VER_35] =
243 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, JUMBO_9K),
244 [RTL_GIGA_MAC_VER_36] =
245 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, JUMBO_9K),
246 [RTL_GIGA_MAC_VER_37] =
247 _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, JUMBO_1K),
248 [RTL_GIGA_MAC_VER_38] =
249 _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, JUMBO_9K),
250 [RTL_GIGA_MAC_VER_39] =
251 _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, JUMBO_1K),
252 [RTL_GIGA_MAC_VER_40] =
253 _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, JUMBO_9K),
254 [RTL_GIGA_MAC_VER_41] =
255 _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K),
256 [RTL_GIGA_MAC_VER_42] =
257 _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, JUMBO_9K),
258 [RTL_GIGA_MAC_VER_43] =
259 _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, JUMBO_1K),
260 [RTL_GIGA_MAC_VER_44] =
261 _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, JUMBO_9K),
262 [RTL_GIGA_MAC_VER_45] =
263 _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, JUMBO_9K),
264 [RTL_GIGA_MAC_VER_46] =
265 _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, JUMBO_9K),
266 [RTL_GIGA_MAC_VER_47] =
267 _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, JUMBO_1K),
268 [RTL_GIGA_MAC_VER_48] =
269 _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, JUMBO_1K),
270 [RTL_GIGA_MAC_VER_49] =
271 _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K),
272 [RTL_GIGA_MAC_VER_50] =
273 _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K),
274 [RTL_GIGA_MAC_VER_51] =
275 _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K),
285 static const struct pci_device_id rtl8169_pci_tbl[] = {
286 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 },
287 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 },
288 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 },
289 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 },
290 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 },
291 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 },
292 { PCI_VENDOR_ID_DLINK, 0x4300,
293 PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 },
294 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 },
295 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 },
296 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 },
297 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 },
298 { PCI_VENDOR_ID_LINKSYS, 0x1032,
299 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
301 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
305 MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
307 static int use_dac = -1;
313 MAC0 = 0, /* Ethernet hardware address. */
315 MAR0 = 8, /* Multicast filter. */
316 CounterAddrLow = 0x10,
317 CounterAddrHigh = 0x14,
318 TxDescStartAddrLow = 0x20,
319 TxDescStartAddrHigh = 0x24,
320 TxHDescStartAddrLow = 0x28,
321 TxHDescStartAddrHigh = 0x2c,
330 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */
331 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */
334 #define RX128_INT_EN (1 << 15) /* 8111c and later */
335 #define RX_MULTI_EN (1 << 14) /* 8111c only */
336 #define RXCFG_FIFO_SHIFT 13
337 /* No threshold before first PCI xfer */
338 #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT)
339 #define RX_EARLY_OFF (1 << 11)
340 #define RXCFG_DMA_SHIFT 8
341 /* Unlimited maximum PCI burst. */
342 #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT)
349 #define PME_SIGNAL (1 << 5) /* 8168c and later */
361 #define RTL_COALESCE_MASK 0x0f
362 #define RTL_COALESCE_SHIFT 4
363 #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK)
364 #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2)
366 RxDescAddrLow = 0xe4,
367 RxDescAddrHigh = 0xe8,
368 EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */
370 #define NoEarlyTx 0x3f /* Max value : no early transmit. */
372 MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */
374 #define TxPacketMax (8064 >> 7)
375 #define EarlySize 0x27
378 FuncEventMask = 0xf4,
379 FuncPresetState = 0xf8,
384 FuncForceEvent = 0xfc,
387 enum rtl8168_8101_registers {
390 #define CSIAR_FLAG 0x80000000
391 #define CSIAR_WRITE_CMD 0x80000000
392 #define CSIAR_BYTE_ENABLE 0x0000f000
393 #define CSIAR_ADDR_MASK 0x00000fff
396 #define EPHYAR_FLAG 0x80000000
397 #define EPHYAR_WRITE_CMD 0x80000000
398 #define EPHYAR_REG_MASK 0x1f
399 #define EPHYAR_REG_SHIFT 16
400 #define EPHYAR_DATA_MASK 0xffff
402 #define PFM_EN (1 << 6)
403 #define TX_10M_PS_EN (1 << 7)
405 #define FIX_NAK_1 (1 << 4)
406 #define FIX_NAK_2 (1 << 3)
409 #define NOW_IS_OOB (1 << 7)
410 #define TX_EMPTY (1 << 5)
411 #define RX_EMPTY (1 << 4)
412 #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY)
413 #define EN_NDP (1 << 3)
414 #define EN_OOB_RESET (1 << 2)
415 #define LINK_LIST_RDY (1 << 1)
417 #define EFUSEAR_FLAG 0x80000000
418 #define EFUSEAR_WRITE_CMD 0x80000000
419 #define EFUSEAR_READ_CMD 0x00000000
420 #define EFUSEAR_REG_MASK 0x03ff
421 #define EFUSEAR_REG_SHIFT 8
422 #define EFUSEAR_DATA_MASK 0xff
424 #define PFM_D3COLD_EN (1 << 6)
427 enum rtl8168_registers {
432 #define ERIAR_FLAG 0x80000000
433 #define ERIAR_WRITE_CMD 0x80000000
434 #define ERIAR_READ_CMD 0x00000000
435 #define ERIAR_ADDR_BYTE_ALIGN 4
436 #define ERIAR_TYPE_SHIFT 16
437 #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT)
438 #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT)
439 #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT)
440 #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT)
441 #define ERIAR_MASK_SHIFT 12
442 #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT)
443 #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT)
444 #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT)
445 #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT)
446 #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT)
447 EPHY_RXER_NUM = 0x7c,
448 OCPDR = 0xb0, /* OCP GPHY access */
449 #define OCPDR_WRITE_CMD 0x80000000
450 #define OCPDR_READ_CMD 0x00000000
451 #define OCPDR_REG_MASK 0x7f
452 #define OCPDR_GPHY_REG_SHIFT 16
453 #define OCPDR_DATA_MASK 0xffff
455 #define OCPAR_FLAG 0x80000000
456 #define OCPAR_GPHY_WRITE_CMD 0x8000f060
457 #define OCPAR_GPHY_READ_CMD 0x0000f060
459 RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */
460 MISC = 0xf0, /* 8168e only. */
461 #define TXPLA_RST (1 << 29)
462 #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */
463 #define PWM_EN (1 << 22)
464 #define RXDV_GATED_EN (1 << 19)
465 #define EARLY_TALLY_EN (1 << 16)
468 enum rtl_register_content {
469 /* InterruptStatusBits */
473 TxDescUnavail = 0x0080,
497 /* TXPoll register p.5 */
498 HPQ = 0x80, /* Poll cmd on the high prio queue */
499 NPQ = 0x40, /* Poll cmd on the low prio queue */
500 FSWInt = 0x01, /* Forced software interrupt */
504 Cfg9346_Unlock = 0xc0,
509 AcceptBroadcast = 0x08,
510 AcceptMulticast = 0x04,
512 AcceptAllPhys = 0x01,
513 #define RX_CONFIG_ACCEPT_MASK 0x3f
516 TxInterFrameGapShift = 24,
517 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
519 /* Config1 register p.24 */
522 Speed_down = (1 << 4),
526 PMEnable = (1 << 0), /* Power Management Enable */
528 /* Config2 register p. 25 */
529 ClkReqEn = (1 << 7), /* Clock Request Enable */
530 MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */
531 PCI_Clock_66MHz = 0x01,
532 PCI_Clock_33MHz = 0x00,
534 /* Config3 register p.25 */
535 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */
536 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */
537 Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */
538 Rdy_to_L23 = (1 << 1), /* L23 Enable */
539 Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */
541 /* Config4 register */
542 Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */
544 /* Config5 register p.27 */
545 BWF = (1 << 6), /* Accept Broadcast wakeup frame */
546 MWF = (1 << 5), /* Accept Multicast wakeup frame */
547 UWF = (1 << 4), /* Accept Unicast wakeup frame */
549 LanWake = (1 << 1), /* LanWake enable/disable */
550 PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */
551 ASPM_en = (1 << 0), /* ASPM enable */
554 EnableBist = (1 << 15), // 8168 8101
555 Mac_dbgo_oe = (1 << 14), // 8168 8101
556 Normal_mode = (1 << 13), // unused
557 Force_half_dup = (1 << 12), // 8168 8101
558 Force_rxflow_en = (1 << 11), // 8168 8101
559 Force_txflow_en = (1 << 10), // 8168 8101
560 Cxpl_dbg_sel = (1 << 9), // 8168 8101
561 ASF = (1 << 8), // 8168 8101
562 PktCntrDisable = (1 << 7), // 8168 8101
563 Mac_dbgo_sel = 0x001c, // 8168
568 #define INTT_MASK GENMASK(1, 0)
569 INTT_0 = 0x0000, // 8168
570 INTT_1 = 0x0001, // 8168
571 INTT_2 = 0x0002, // 8168
572 INTT_3 = 0x0003, // 8168
574 /* rtl8169_PHYstatus */
585 TBILinkOK = 0x02000000,
587 /* ResetCounterCommand */
590 /* DumpCounterCommand */
593 /* magic enable v2 */
594 MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */
598 /* First doubleword. */
599 DescOwn = (1 << 31), /* Descriptor is owned by NIC */
600 RingEnd = (1 << 30), /* End of descriptor ring */
601 FirstFrag = (1 << 29), /* First segment of a packet */
602 LastFrag = (1 << 28), /* Final segment of a packet */
606 enum rtl_tx_desc_bit {
607 /* First doubleword. */
608 TD_LSO = (1 << 27), /* Large Send Offload */
609 #define TD_MSS_MAX 0x07ffu /* MSS value */
611 /* Second doubleword. */
612 TxVlanTag = (1 << 17), /* Add VLAN tag */
615 /* 8169, 8168b and 810x except 8102e. */
616 enum rtl_tx_desc_bit_0 {
617 /* First doubleword. */
618 #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */
619 TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */
620 TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */
621 TD0_IP_CS = (1 << 18), /* Calculate IP checksum */
624 /* 8102e, 8168c and beyond. */
625 enum rtl_tx_desc_bit_1 {
626 /* First doubleword. */
627 TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */
628 TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */
629 #define GTTCPHO_SHIFT 18
630 #define GTTCPHO_MAX 0x7fU
632 /* Second doubleword. */
633 #define TCPHO_SHIFT 18
634 #define TCPHO_MAX 0x3ffU
635 #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */
636 TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */
637 TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */
638 TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */
639 TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */
642 enum rtl_rx_desc_bit {
644 PID1 = (1 << 18), /* Protocol ID bit 1/2 */
645 PID0 = (1 << 17), /* Protocol ID bit 0/2 */
647 #define RxProtoUDP (PID1)
648 #define RxProtoTCP (PID0)
649 #define RxProtoIP (PID1 | PID0)
650 #define RxProtoMask RxProtoIP
652 IPFail = (1 << 16), /* IP checksum failed */
653 UDPFail = (1 << 15), /* UDP/IP checksum failed */
654 TCPFail = (1 << 14), /* TCP/IP checksum failed */
655 RxVlanTag = (1 << 16), /* VLAN tag available */
658 #define RsvdMask 0x3fffc000
659 #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK)
676 u8 __pad[sizeof(void *) - sizeof(u32)];
679 struct rtl8169_counters {
686 __le32 tx_one_collision;
687 __le32 tx_multi_collision;
695 struct rtl8169_tc_offsets {
698 __le32 tx_multi_collision;
703 RTL_FLAG_TASK_ENABLED,
704 RTL_FLAG_TASK_SLOW_PENDING,
705 RTL_FLAG_TASK_RESET_PENDING,
709 struct rtl8169_stats {
712 struct u64_stats_sync syncp;
715 struct rtl8169_private {
716 void __iomem *mmio_addr; /* memory map physical address */
717 struct pci_dev *pci_dev;
718 struct net_device *dev;
719 struct napi_struct napi;
722 u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */
723 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */
725 struct rtl8169_stats rx_stats;
726 struct rtl8169_stats tx_stats;
727 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */
728 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */
729 dma_addr_t TxPhyAddr;
730 dma_addr_t RxPhyAddr;
731 void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */
732 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */
736 const struct rtl_coalesce_info *coalesce_info;
739 void (*write)(struct rtl8169_private *, int, int);
740 int (*read)(struct rtl8169_private *, int);
744 void (*enable)(struct rtl8169_private *);
745 void (*disable)(struct rtl8169_private *);
748 void (*hw_start)(struct rtl8169_private *tp);
749 bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *);
752 DECLARE_BITMAP(flags, RTL_FLAG_MAX);
754 struct work_struct work;
757 struct mii_if_info mii;
758 struct mii_bus *mii_bus;
759 dma_addr_t counters_phys_addr;
760 struct rtl8169_counters *counters;
761 struct rtl8169_tc_offsets tc_offset;
765 const struct firmware *fw;
767 #define RTL_VER_SIZE 32
769 char version[RTL_VER_SIZE];
771 struct rtl_fw_phy_action {
776 #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN)
781 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
782 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
783 module_param(use_dac, int, 0);
784 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
785 module_param_named(debug, debug.msg_enable, int, 0);
786 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
787 MODULE_LICENSE("GPL");
788 MODULE_VERSION(RTL8169_VERSION);
789 MODULE_FIRMWARE(FIRMWARE_8168D_1);
790 MODULE_FIRMWARE(FIRMWARE_8168D_2);
791 MODULE_FIRMWARE(FIRMWARE_8168E_1);
792 MODULE_FIRMWARE(FIRMWARE_8168E_2);
793 MODULE_FIRMWARE(FIRMWARE_8168E_3);
794 MODULE_FIRMWARE(FIRMWARE_8105E_1);
795 MODULE_FIRMWARE(FIRMWARE_8168F_1);
796 MODULE_FIRMWARE(FIRMWARE_8168F_2);
797 MODULE_FIRMWARE(FIRMWARE_8402_1);
798 MODULE_FIRMWARE(FIRMWARE_8411_1);
799 MODULE_FIRMWARE(FIRMWARE_8411_2);
800 MODULE_FIRMWARE(FIRMWARE_8106E_1);
801 MODULE_FIRMWARE(FIRMWARE_8106E_2);
802 MODULE_FIRMWARE(FIRMWARE_8168G_2);
803 MODULE_FIRMWARE(FIRMWARE_8168G_3);
804 MODULE_FIRMWARE(FIRMWARE_8168H_1);
805 MODULE_FIRMWARE(FIRMWARE_8168H_2);
806 MODULE_FIRMWARE(FIRMWARE_8107E_1);
807 MODULE_FIRMWARE(FIRMWARE_8107E_2);
809 static inline struct device *tp_to_dev(struct rtl8169_private *tp)
811 return &tp->pci_dev->dev;
814 static void rtl_lock_work(struct rtl8169_private *tp)
816 mutex_lock(&tp->wk.mutex);
819 static void rtl_unlock_work(struct rtl8169_private *tp)
821 mutex_unlock(&tp->wk.mutex);
824 static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force)
826 pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
827 PCI_EXP_DEVCTL_READRQ, force);
831 bool (*check)(struct rtl8169_private *);
835 static void rtl_udelay(unsigned int d)
840 static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c,
841 void (*delay)(unsigned int), unsigned int d, int n,
846 for (i = 0; i < n; i++) {
848 if (c->check(tp) == high)
851 netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n",
852 c->msg, !high, n, d);
856 static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp,
857 const struct rtl_cond *c,
858 unsigned int d, int n)
860 return rtl_loop_wait(tp, c, rtl_udelay, d, n, true);
863 static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp,
864 const struct rtl_cond *c,
865 unsigned int d, int n)
867 return rtl_loop_wait(tp, c, rtl_udelay, d, n, false);
870 static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp,
871 const struct rtl_cond *c,
872 unsigned int d, int n)
874 return rtl_loop_wait(tp, c, msleep, d, n, true);
877 static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp,
878 const struct rtl_cond *c,
879 unsigned int d, int n)
881 return rtl_loop_wait(tp, c, msleep, d, n, false);
884 #define DECLARE_RTL_COND(name) \
885 static bool name ## _check(struct rtl8169_private *); \
887 static const struct rtl_cond name = { \
888 .check = name ## _check, \
892 static bool name ## _check(struct rtl8169_private *tp)
894 static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg)
896 if (reg & 0xffff0001) {
897 netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg);
903 DECLARE_RTL_COND(rtl_ocp_gphy_cond)
905 return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG;
908 static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data)
910 if (rtl_ocp_reg_failure(tp, reg))
913 RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data);
915 rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10);
918 static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg)
920 if (rtl_ocp_reg_failure(tp, reg))
923 RTL_W32(tp, GPHY_OCP, reg << 15);
925 return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ?
926 (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0;
929 static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data)
931 if (rtl_ocp_reg_failure(tp, reg))
934 RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data);
937 static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg)
939 if (rtl_ocp_reg_failure(tp, reg))
942 RTL_W32(tp, OCPDR, reg << 15);
944 return RTL_R32(tp, OCPDR);
947 #define OCP_STD_PHY_BASE 0xa400
949 static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value)
952 tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE;
956 if (tp->ocp_base != OCP_STD_PHY_BASE)
959 r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value);
962 static int r8168g_mdio_read(struct rtl8169_private *tp, int reg)
964 if (tp->ocp_base != OCP_STD_PHY_BASE)
967 return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2);
970 static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value)
973 tp->ocp_base = value << 4;
977 r8168_mac_ocp_write(tp, tp->ocp_base + reg, value);
980 static int mac_mcu_read(struct rtl8169_private *tp, int reg)
982 return r8168_mac_ocp_read(tp, tp->ocp_base + reg);
985 DECLARE_RTL_COND(rtl_phyar_cond)
987 return RTL_R32(tp, PHYAR) & 0x80000000;
990 static void r8169_mdio_write(struct rtl8169_private *tp, int reg, int value)
992 RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff));
994 rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20);
996 * According to hardware specs a 20us delay is required after write
997 * complete indication, but before sending next command.
1002 static int r8169_mdio_read(struct rtl8169_private *tp, int reg)
1006 RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16);
1008 value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ?
1009 RTL_R32(tp, PHYAR) & 0xffff : ~0;
1012 * According to hardware specs a 20us delay is required after read
1013 * complete indication, but before sending next command.
1020 DECLARE_RTL_COND(rtl_ocpar_cond)
1022 return RTL_R32(tp, OCPAR) & OCPAR_FLAG;
1025 static void r8168dp_1_mdio_access(struct rtl8169_private *tp, int reg, u32 data)
1027 RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT));
1028 RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD);
1029 RTL_W32(tp, EPHY_RXER_NUM, 0);
1031 rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100);
1034 static void r8168dp_1_mdio_write(struct rtl8169_private *tp, int reg, int value)
1036 r8168dp_1_mdio_access(tp, reg,
1037 OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK));
1040 static int r8168dp_1_mdio_read(struct rtl8169_private *tp, int reg)
1042 r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD);
1045 RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD);
1046 RTL_W32(tp, EPHY_RXER_NUM, 0);
1048 return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ?
1049 RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0;
1052 #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000
1054 static void r8168dp_2_mdio_start(struct rtl8169_private *tp)
1056 RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT);
1059 static void r8168dp_2_mdio_stop(struct rtl8169_private *tp)
1061 RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) | R8168DP_1_MDIO_ACCESS_BIT);
1064 static void r8168dp_2_mdio_write(struct rtl8169_private *tp, int reg, int value)
1066 r8168dp_2_mdio_start(tp);
1068 r8169_mdio_write(tp, reg, value);
1070 r8168dp_2_mdio_stop(tp);
1073 static int r8168dp_2_mdio_read(struct rtl8169_private *tp, int reg)
1077 r8168dp_2_mdio_start(tp);
1079 value = r8169_mdio_read(tp, reg);
1081 r8168dp_2_mdio_stop(tp);
1086 static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val)
1088 tp->mdio_ops.write(tp, location, val);
1091 static int rtl_readphy(struct rtl8169_private *tp, int location)
1093 return tp->mdio_ops.read(tp, location);
1096 static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value)
1098 rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value);
1101 static void rtl_w0w1_phy(struct rtl8169_private *tp, int reg_addr, int p, int m)
1105 val = rtl_readphy(tp, reg_addr);
1106 rtl_writephy(tp, reg_addr, (val & ~m) | p);
1109 static void rtl_mdio_write(struct net_device *dev, int phy_id, int location,
1112 struct rtl8169_private *tp = netdev_priv(dev);
1114 rtl_writephy(tp, location, val);
1117 static int rtl_mdio_read(struct net_device *dev, int phy_id, int location)
1119 struct rtl8169_private *tp = netdev_priv(dev);
1121 return rtl_readphy(tp, location);
1124 DECLARE_RTL_COND(rtl_ephyar_cond)
1126 return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG;
1129 static void rtl_ephy_write(struct rtl8169_private *tp, int reg_addr, int value)
1131 RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) |
1132 (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
1134 rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100);
1139 static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr)
1141 RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT);
1143 return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ?
1144 RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0;
1147 DECLARE_RTL_COND(rtl_eriar_cond)
1149 return RTL_R32(tp, ERIAR) & ERIAR_FLAG;
1152 static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask,
1155 BUG_ON((addr & 3) || (mask == 0));
1156 RTL_W32(tp, ERIDR, val);
1157 RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr);
1159 rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100);
1162 static u32 rtl_eri_read(struct rtl8169_private *tp, int addr, int type)
1164 RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr);
1166 return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ?
1167 RTL_R32(tp, ERIDR) : ~0;
1170 static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p,
1175 val = rtl_eri_read(tp, addr, type);
1176 rtl_eri_write(tp, addr, mask, (val & ~m) | p, type);
1179 static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
1181 RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
1182 return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ?
1183 RTL_R32(tp, OCPDR) : ~0;
1186 static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
1188 return rtl_eri_read(tp, reg, ERIAR_OOB);
1191 static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg)
1193 switch (tp->mac_version) {
1194 case RTL_GIGA_MAC_VER_27:
1195 case RTL_GIGA_MAC_VER_28:
1196 case RTL_GIGA_MAC_VER_31:
1197 return r8168dp_ocp_read(tp, mask, reg);
1198 case RTL_GIGA_MAC_VER_49:
1199 case RTL_GIGA_MAC_VER_50:
1200 case RTL_GIGA_MAC_VER_51:
1201 return r8168ep_ocp_read(tp, mask, reg);
1208 static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg,
1211 RTL_W32(tp, OCPDR, data);
1212 RTL_W32(tp, OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff));
1213 rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20);
1216 static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg,
1219 rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT,
1223 static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data)
1225 switch (tp->mac_version) {
1226 case RTL_GIGA_MAC_VER_27:
1227 case RTL_GIGA_MAC_VER_28:
1228 case RTL_GIGA_MAC_VER_31:
1229 r8168dp_ocp_write(tp, mask, reg, data);
1231 case RTL_GIGA_MAC_VER_49:
1232 case RTL_GIGA_MAC_VER_50:
1233 case RTL_GIGA_MAC_VER_51:
1234 r8168ep_ocp_write(tp, mask, reg, data);
1242 static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd)
1244 rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC);
1246 ocp_write(tp, 0x1, 0x30, 0x00000001);
1249 #define OOB_CMD_RESET 0x00
1250 #define OOB_CMD_DRIVER_START 0x05
1251 #define OOB_CMD_DRIVER_STOP 0x06
1253 static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp)
1255 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10;
1258 DECLARE_RTL_COND(rtl_ocp_read_cond)
1262 reg = rtl8168_get_ocp_reg(tp);
1264 return ocp_read(tp, 0x0f, reg) & 0x00000800;
1267 DECLARE_RTL_COND(rtl_ep_ocp_read_cond)
1269 return ocp_read(tp, 0x0f, 0x124) & 0x00000001;
1272 DECLARE_RTL_COND(rtl_ocp_tx_cond)
1274 return RTL_R8(tp, IBISR0) & 0x20;
1277 static void rtl8168ep_stop_cmac(struct rtl8169_private *tp)
1279 RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01);
1280 rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000);
1281 RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20);
1282 RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01);
1285 static void rtl8168dp_driver_start(struct rtl8169_private *tp)
1287 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START);
1288 rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10);
1291 static void rtl8168ep_driver_start(struct rtl8169_private *tp)
1293 ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START);
1294 ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01);
1295 rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10);
1298 static void rtl8168_driver_start(struct rtl8169_private *tp)
1300 switch (tp->mac_version) {
1301 case RTL_GIGA_MAC_VER_27:
1302 case RTL_GIGA_MAC_VER_28:
1303 case RTL_GIGA_MAC_VER_31:
1304 rtl8168dp_driver_start(tp);
1306 case RTL_GIGA_MAC_VER_49:
1307 case RTL_GIGA_MAC_VER_50:
1308 case RTL_GIGA_MAC_VER_51:
1309 rtl8168ep_driver_start(tp);
1317 static void rtl8168dp_driver_stop(struct rtl8169_private *tp)
1319 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP);
1320 rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10);
1323 static void rtl8168ep_driver_stop(struct rtl8169_private *tp)
1325 rtl8168ep_stop_cmac(tp);
1326 ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP);
1327 ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01);
1328 rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10);
1331 static void rtl8168_driver_stop(struct rtl8169_private *tp)
1333 switch (tp->mac_version) {
1334 case RTL_GIGA_MAC_VER_27:
1335 case RTL_GIGA_MAC_VER_28:
1336 case RTL_GIGA_MAC_VER_31:
1337 rtl8168dp_driver_stop(tp);
1339 case RTL_GIGA_MAC_VER_49:
1340 case RTL_GIGA_MAC_VER_50:
1341 case RTL_GIGA_MAC_VER_51:
1342 rtl8168ep_driver_stop(tp);
1350 static bool r8168dp_check_dash(struct rtl8169_private *tp)
1352 u16 reg = rtl8168_get_ocp_reg(tp);
1354 return !!(ocp_read(tp, 0x0f, reg) & 0x00008000);
1357 static bool r8168ep_check_dash(struct rtl8169_private *tp)
1359 return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001);
1362 static bool r8168_check_dash(struct rtl8169_private *tp)
1364 switch (tp->mac_version) {
1365 case RTL_GIGA_MAC_VER_27:
1366 case RTL_GIGA_MAC_VER_28:
1367 case RTL_GIGA_MAC_VER_31:
1368 return r8168dp_check_dash(tp);
1369 case RTL_GIGA_MAC_VER_49:
1370 case RTL_GIGA_MAC_VER_50:
1371 case RTL_GIGA_MAC_VER_51:
1372 return r8168ep_check_dash(tp);
1384 static void rtl_write_exgmac_batch(struct rtl8169_private *tp,
1385 const struct exgmac_reg *r, int len)
1388 rtl_eri_write(tp, r->addr, r->mask, r->val, ERIAR_EXGMAC);
1393 DECLARE_RTL_COND(rtl_efusear_cond)
1395 return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG;
1398 static u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr)
1400 RTL_W32(tp, EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT);
1402 return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ?
1403 RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0;
1406 static u16 rtl_get_events(struct rtl8169_private *tp)
1408 return RTL_R16(tp, IntrStatus);
1411 static void rtl_ack_events(struct rtl8169_private *tp, u16 bits)
1413 RTL_W16(tp, IntrStatus, bits);
1417 static void rtl_irq_disable(struct rtl8169_private *tp)
1419 RTL_W16(tp, IntrMask, 0);
1423 static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits)
1425 RTL_W16(tp, IntrMask, bits);
1428 #define RTL_EVENT_NAPI_RX (RxOK | RxErr)
1429 #define RTL_EVENT_NAPI_TX (TxOK | TxErr)
1430 #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX)
1432 static void rtl_irq_enable_all(struct rtl8169_private *tp)
1434 rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow);
1437 static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp)
1439 rtl_irq_disable(tp);
1440 rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow);
1441 RTL_R8(tp, ChipCmd);
1444 static void rtl_link_chg_patch(struct rtl8169_private *tp)
1446 struct net_device *dev = tp->dev;
1448 if (!netif_running(dev))
1451 if (tp->mac_version == RTL_GIGA_MAC_VER_34 ||
1452 tp->mac_version == RTL_GIGA_MAC_VER_38) {
1453 if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
1454 rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011,
1456 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
1458 } else if (RTL_R8(tp, PHYstatus) & _100bps) {
1459 rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f,
1461 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
1464 rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f,
1466 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f,
1469 /* Reset packet filter */
1470 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01,
1472 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00,
1474 } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 ||
1475 tp->mac_version == RTL_GIGA_MAC_VER_36) {
1476 if (RTL_R8(tp, PHYstatus) & _1000bpsF) {
1477 rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011,
1479 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005,
1482 rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f,
1484 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f,
1487 } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) {
1488 if (RTL_R8(tp, PHYstatus) & _10bps) {
1489 rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02,
1491 rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060,
1494 rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000,
1500 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
1502 static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
1507 options = RTL_R8(tp, Config1);
1508 if (!(options & PMEnable))
1511 options = RTL_R8(tp, Config3);
1512 if (options & LinkUp)
1513 wolopts |= WAKE_PHY;
1514 switch (tp->mac_version) {
1515 case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
1516 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
1517 if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2)
1518 wolopts |= WAKE_MAGIC;
1521 if (options & MagicPacket)
1522 wolopts |= WAKE_MAGIC;
1526 options = RTL_R8(tp, Config5);
1528 wolopts |= WAKE_UCAST;
1530 wolopts |= WAKE_BCAST;
1532 wolopts |= WAKE_MCAST;
1537 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1539 struct rtl8169_private *tp = netdev_priv(dev);
1542 wol->supported = WAKE_ANY;
1543 wol->wolopts = tp->saved_wolopts;
1544 rtl_unlock_work(tp);
1547 static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
1549 unsigned int i, tmp;
1550 static const struct {
1555 { WAKE_PHY, Config3, LinkUp },
1556 { WAKE_UCAST, Config5, UWF },
1557 { WAKE_BCAST, Config5, BWF },
1558 { WAKE_MCAST, Config5, MWF },
1559 { WAKE_ANY, Config5, LanWake },
1560 { WAKE_MAGIC, Config3, MagicPacket }
1564 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
1566 switch (tp->mac_version) {
1567 case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
1568 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
1569 tmp = ARRAY_SIZE(cfg) - 1;
1570 if (wolopts & WAKE_MAGIC)
1586 tmp = ARRAY_SIZE(cfg);
1590 for (i = 0; i < tmp; i++) {
1591 options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask;
1592 if (wolopts & cfg[i].opt)
1593 options |= cfg[i].mask;
1594 RTL_W8(tp, cfg[i].reg, options);
1597 switch (tp->mac_version) {
1598 case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17:
1599 options = RTL_R8(tp, Config1) & ~PMEnable;
1601 options |= PMEnable;
1602 RTL_W8(tp, Config1, options);
1605 options = RTL_R8(tp, Config2) & ~PME_SIGNAL;
1607 options |= PME_SIGNAL;
1608 RTL_W8(tp, Config2, options);
1612 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
1615 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1617 struct rtl8169_private *tp = netdev_priv(dev);
1618 struct device *d = tp_to_dev(tp);
1620 if (wol->wolopts & ~WAKE_ANY)
1623 pm_runtime_get_noresume(d);
1627 tp->saved_wolopts = wol->wolopts;
1629 if (pm_runtime_active(d))
1630 __rtl8169_set_wol(tp, tp->saved_wolopts);
1632 rtl_unlock_work(tp);
1634 device_set_wakeup_enable(d, tp->saved_wolopts);
1636 pm_runtime_put_noidle(d);
1641 static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp)
1643 return rtl_chip_infos[tp->mac_version].fw_name;
1646 static void rtl8169_get_drvinfo(struct net_device *dev,
1647 struct ethtool_drvinfo *info)
1649 struct rtl8169_private *tp = netdev_priv(dev);
1650 struct rtl_fw *rtl_fw = tp->rtl_fw;
1652 strlcpy(info->driver, MODULENAME, sizeof(info->driver));
1653 strlcpy(info->version, RTL8169_VERSION, sizeof(info->version));
1654 strlcpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info));
1655 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version));
1656 if (!IS_ERR_OR_NULL(rtl_fw))
1657 strlcpy(info->fw_version, rtl_fw->version,
1658 sizeof(info->fw_version));
1661 static int rtl8169_get_regs_len(struct net_device *dev)
1663 return R8169_REGS_SIZE;
1666 static int rtl8169_set_speed_xmii(struct net_device *dev,
1667 u8 autoneg, u16 speed, u8 duplex, u32 adv)
1669 struct rtl8169_private *tp = netdev_priv(dev);
1670 int giga_ctrl, bmcr;
1673 rtl_writephy(tp, 0x1f, 0x0000);
1675 if (autoneg == AUTONEG_ENABLE) {
1678 auto_nego = rtl_readphy(tp, MII_ADVERTISE);
1679 auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
1680 ADVERTISE_100HALF | ADVERTISE_100FULL);
1682 if (adv & ADVERTISED_10baseT_Half)
1683 auto_nego |= ADVERTISE_10HALF;
1684 if (adv & ADVERTISED_10baseT_Full)
1685 auto_nego |= ADVERTISE_10FULL;
1686 if (adv & ADVERTISED_100baseT_Half)
1687 auto_nego |= ADVERTISE_100HALF;
1688 if (adv & ADVERTISED_100baseT_Full)
1689 auto_nego |= ADVERTISE_100FULL;
1691 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
1693 giga_ctrl = rtl_readphy(tp, MII_CTRL1000);
1694 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
1696 /* The 8100e/8101e/8102e do Fast Ethernet only. */
1697 if (tp->mii.supports_gmii) {
1698 if (adv & ADVERTISED_1000baseT_Half)
1699 giga_ctrl |= ADVERTISE_1000HALF;
1700 if (adv & ADVERTISED_1000baseT_Full)
1701 giga_ctrl |= ADVERTISE_1000FULL;
1702 } else if (adv & (ADVERTISED_1000baseT_Half |
1703 ADVERTISED_1000baseT_Full)) {
1704 netif_info(tp, link, dev,
1705 "PHY does not support 1000Mbps\n");
1709 bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
1711 rtl_writephy(tp, MII_ADVERTISE, auto_nego);
1712 rtl_writephy(tp, MII_CTRL1000, giga_ctrl);
1714 if (speed == SPEED_10)
1716 else if (speed == SPEED_100)
1717 bmcr = BMCR_SPEED100;
1721 if (duplex == DUPLEX_FULL)
1722 bmcr |= BMCR_FULLDPLX;
1725 rtl_writephy(tp, MII_BMCR, bmcr);
1727 if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
1728 tp->mac_version == RTL_GIGA_MAC_VER_03) {
1729 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) {
1730 rtl_writephy(tp, 0x17, 0x2138);
1731 rtl_writephy(tp, 0x0e, 0x0260);
1733 rtl_writephy(tp, 0x17, 0x2108);
1734 rtl_writephy(tp, 0x0e, 0x0000);
1743 static int rtl8169_set_speed(struct net_device *dev,
1744 u8 autoneg, u16 speed, u8 duplex, u32 advertising)
1746 return rtl8169_set_speed_xmii(dev, autoneg, speed, duplex, advertising);
1749 static netdev_features_t rtl8169_fix_features(struct net_device *dev,
1750 netdev_features_t features)
1752 struct rtl8169_private *tp = netdev_priv(dev);
1754 if (dev->mtu > TD_MSS_MAX)
1755 features &= ~NETIF_F_ALL_TSO;
1757 if (dev->mtu > JUMBO_1K &&
1758 tp->mac_version > RTL_GIGA_MAC_VER_06)
1759 features &= ~NETIF_F_IP_CSUM;
1764 static int rtl8169_set_features(struct net_device *dev,
1765 netdev_features_t features)
1767 struct rtl8169_private *tp = netdev_priv(dev);
1772 rx_config = RTL_R32(tp, RxConfig);
1773 if (features & NETIF_F_RXALL)
1774 rx_config |= (AcceptErr | AcceptRunt);
1776 rx_config &= ~(AcceptErr | AcceptRunt);
1778 RTL_W32(tp, RxConfig, rx_config);
1780 if (features & NETIF_F_RXCSUM)
1781 tp->cp_cmd |= RxChkSum;
1783 tp->cp_cmd &= ~RxChkSum;
1785 if (features & NETIF_F_HW_VLAN_CTAG_RX)
1786 tp->cp_cmd |= RxVlan;
1788 tp->cp_cmd &= ~RxVlan;
1790 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
1791 RTL_R16(tp, CPlusCmd);
1793 rtl_unlock_work(tp);
1798 static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb)
1800 return (skb_vlan_tag_present(skb)) ?
1801 TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00;
1804 static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb)
1806 u32 opts2 = le32_to_cpu(desc->opts2);
1808 if (opts2 & RxVlanTag)
1809 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff));
1812 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
1815 struct rtl8169_private *tp = netdev_priv(dev);
1816 u32 __iomem *data = tp->mmio_addr;
1821 for (i = 0; i < R8169_REGS_SIZE; i += 4)
1822 memcpy_fromio(dw++, data++, 4);
1823 rtl_unlock_work(tp);
1826 static u32 rtl8169_get_msglevel(struct net_device *dev)
1828 struct rtl8169_private *tp = netdev_priv(dev);
1830 return tp->msg_enable;
1833 static void rtl8169_set_msglevel(struct net_device *dev, u32 value)
1835 struct rtl8169_private *tp = netdev_priv(dev);
1837 tp->msg_enable = value;
1840 static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = {
1847 "tx_single_collisions",
1848 "tx_multi_collisions",
1856 static int rtl8169_get_sset_count(struct net_device *dev, int sset)
1860 return ARRAY_SIZE(rtl8169_gstrings);
1866 DECLARE_RTL_COND(rtl_counters_cond)
1868 return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump);
1871 static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd)
1873 dma_addr_t paddr = tp->counters_phys_addr;
1876 RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32);
1877 RTL_R32(tp, CounterAddrHigh);
1878 cmd = (u64)paddr & DMA_BIT_MASK(32);
1879 RTL_W32(tp, CounterAddrLow, cmd);
1880 RTL_W32(tp, CounterAddrLow, cmd | counter_cmd);
1882 return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000);
1885 static bool rtl8169_reset_counters(struct rtl8169_private *tp)
1888 * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the
1891 if (tp->mac_version < RTL_GIGA_MAC_VER_19)
1894 return rtl8169_do_counters(tp, CounterReset);
1897 static bool rtl8169_update_counters(struct rtl8169_private *tp)
1900 * Some chips are unable to dump tally counters when the receiver
1903 if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0)
1906 return rtl8169_do_counters(tp, CounterDump);
1909 static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp)
1911 struct rtl8169_counters *counters = tp->counters;
1915 * rtl8169_init_counter_offsets is called from rtl_open. On chip
1916 * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only
1917 * reset by a power cycle, while the counter values collected by the
1918 * driver are reset at every driver unload/load cycle.
1920 * To make sure the HW values returned by @get_stats64 match the SW
1921 * values, we collect the initial values at first open(*) and use them
1922 * as offsets to normalize the values returned by @get_stats64.
1924 * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one
1925 * for the reason stated in rtl8169_update_counters; CmdRxEnb is only
1926 * set at open time by rtl_hw_start.
1929 if (tp->tc_offset.inited)
1932 /* If both, reset and update fail, propagate to caller. */
1933 if (rtl8169_reset_counters(tp))
1936 if (rtl8169_update_counters(tp))
1939 tp->tc_offset.tx_errors = counters->tx_errors;
1940 tp->tc_offset.tx_multi_collision = counters->tx_multi_collision;
1941 tp->tc_offset.tx_aborted = counters->tx_aborted;
1942 tp->tc_offset.inited = true;
1947 static void rtl8169_get_ethtool_stats(struct net_device *dev,
1948 struct ethtool_stats *stats, u64 *data)
1950 struct rtl8169_private *tp = netdev_priv(dev);
1951 struct device *d = tp_to_dev(tp);
1952 struct rtl8169_counters *counters = tp->counters;
1956 pm_runtime_get_noresume(d);
1958 if (pm_runtime_active(d))
1959 rtl8169_update_counters(tp);
1961 pm_runtime_put_noidle(d);
1963 data[0] = le64_to_cpu(counters->tx_packets);
1964 data[1] = le64_to_cpu(counters->rx_packets);
1965 data[2] = le64_to_cpu(counters->tx_errors);
1966 data[3] = le32_to_cpu(counters->rx_errors);
1967 data[4] = le16_to_cpu(counters->rx_missed);
1968 data[5] = le16_to_cpu(counters->align_errors);
1969 data[6] = le32_to_cpu(counters->tx_one_collision);
1970 data[7] = le32_to_cpu(counters->tx_multi_collision);
1971 data[8] = le64_to_cpu(counters->rx_unicast);
1972 data[9] = le64_to_cpu(counters->rx_broadcast);
1973 data[10] = le32_to_cpu(counters->rx_multicast);
1974 data[11] = le16_to_cpu(counters->tx_aborted);
1975 data[12] = le16_to_cpu(counters->tx_underun);
1978 static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1982 memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings));
1988 * Interrupt coalescing
1990 * > 1 - the availability of the IntrMitigate (0xe2) register through the
1991 * > 8169, 8168 and 810x line of chipsets
1993 * 8169, 8168, and 8136(810x) serial chipsets support it.
1995 * > 2 - the Tx timer unit at gigabit speed
1997 * The unit of the timer depends on both the speed and the setting of CPlusCmd
1998 * (0xe0) bit 1 and bit 0.
2001 * bit[1:0] \ speed 1000M 100M 10M
2002 * 0 0 320ns 2.56us 40.96us
2003 * 0 1 2.56us 20.48us 327.7us
2004 * 1 0 5.12us 40.96us 655.4us
2005 * 1 1 10.24us 81.92us 1.31ms
2008 * bit[1:0] \ speed 1000M 100M 10M
2009 * 0 0 5us 2.56us 40.96us
2010 * 0 1 40us 20.48us 327.7us
2011 * 1 0 80us 40.96us 655.4us
2012 * 1 1 160us 81.92us 1.31ms
2015 /* rx/tx scale factors for one particular CPlusCmd[0:1] value */
2016 struct rtl_coalesce_scale {
2021 /* rx/tx scale factors for all CPlusCmd[0:1] cases */
2022 struct rtl_coalesce_info {
2024 struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */
2027 /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */
2028 #define rxtx_x1822(r, t) { \
2031 {{(r)*8*2, (t)*8*2}}, \
2032 {{(r)*8*2*2, (t)*8*2*2}}, \
2034 static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = {
2035 /* speed delays: rx00 tx00 */
2036 { SPEED_10, rxtx_x1822(40960, 40960) },
2037 { SPEED_100, rxtx_x1822( 2560, 2560) },
2038 { SPEED_1000, rxtx_x1822( 320, 320) },
2042 static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = {
2043 /* speed delays: rx00 tx00 */
2044 { SPEED_10, rxtx_x1822(40960, 40960) },
2045 { SPEED_100, rxtx_x1822( 2560, 2560) },
2046 { SPEED_1000, rxtx_x1822( 5000, 5000) },
2051 /* get rx/tx scale vector corresponding to current speed */
2052 static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev)
2054 struct rtl8169_private *tp = netdev_priv(dev);
2055 struct ethtool_link_ksettings ecmd;
2056 const struct rtl_coalesce_info *ci;
2059 rc = phy_ethtool_get_link_ksettings(dev, &ecmd);
2063 for (ci = tp->coalesce_info; ci->speed != 0; ci++) {
2064 if (ecmd.base.speed == ci->speed) {
2069 return ERR_PTR(-ELNRNG);
2072 static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
2074 struct rtl8169_private *tp = netdev_priv(dev);
2075 const struct rtl_coalesce_info *ci;
2076 const struct rtl_coalesce_scale *scale;
2080 } coal_settings [] = {
2081 { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs },
2082 { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs }
2083 }, *p = coal_settings;
2087 memset(ec, 0, sizeof(*ec));
2089 /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */
2090 ci = rtl_coalesce_info(dev);
2094 scale = &ci->scalev[tp->cp_cmd & INTT_MASK];
2096 /* read IntrMitigate and adjust according to scale */
2097 for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) {
2098 *p->max_frames = (w & RTL_COALESCE_MASK) << 2;
2099 w >>= RTL_COALESCE_SHIFT;
2100 *p->usecs = w & RTL_COALESCE_MASK;
2103 for (i = 0; i < 2; i++) {
2104 p = coal_settings + i;
2105 *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000;
2108 * ethtool_coalesce says it is illegal to set both usecs and
2111 if (!*p->usecs && !*p->max_frames)
2118 /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */
2119 static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale(
2120 struct net_device *dev, u32 nsec, u16 *cp01)
2122 const struct rtl_coalesce_info *ci;
2125 ci = rtl_coalesce_info(dev);
2127 return ERR_CAST(ci);
2129 for (i = 0; i < 4; i++) {
2130 u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0],
2131 ci->scalev[i].nsecs[1]);
2132 if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) {
2134 return &ci->scalev[i];
2138 return ERR_PTR(-EINVAL);
2141 static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
2143 struct rtl8169_private *tp = netdev_priv(dev);
2144 const struct rtl_coalesce_scale *scale;
2148 } coal_settings [] = {
2149 { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs },
2150 { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs }
2151 }, *p = coal_settings;
2155 scale = rtl_coalesce_choose_scale(dev,
2156 max(p[0].usecs, p[1].usecs) * 1000, &cp01);
2158 return PTR_ERR(scale);
2160 for (i = 0; i < 2; i++, p++) {
2164 * accept max_frames=1 we returned in rtl_get_coalesce.
2165 * accept it not only when usecs=0 because of e.g. the following scenario:
2167 * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX)
2168 * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1
2169 * - then user does `ethtool -C eth0 rx-usecs 100`
2171 * since ethtool sends to kernel whole ethtool_coalesce
2172 * settings, if we do not handle rx_usecs=!0, rx_frames=1
2173 * we'll reject it below in `frames % 4 != 0`.
2175 if (p->frames == 1) {
2179 units = p->usecs * 1000 / scale->nsecs[i];
2180 if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4)
2183 w <<= RTL_COALESCE_SHIFT;
2185 w <<= RTL_COALESCE_SHIFT;
2186 w |= p->frames >> 2;
2191 RTL_W16(tp, IntrMitigate, swab16(w));
2193 tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01;
2194 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
2195 RTL_R16(tp, CPlusCmd);
2197 rtl_unlock_work(tp);
2202 static const struct ethtool_ops rtl8169_ethtool_ops = {
2203 .get_drvinfo = rtl8169_get_drvinfo,
2204 .get_regs_len = rtl8169_get_regs_len,
2205 .get_link = ethtool_op_get_link,
2206 .get_coalesce = rtl_get_coalesce,
2207 .set_coalesce = rtl_set_coalesce,
2208 .get_msglevel = rtl8169_get_msglevel,
2209 .set_msglevel = rtl8169_set_msglevel,
2210 .get_regs = rtl8169_get_regs,
2211 .get_wol = rtl8169_get_wol,
2212 .set_wol = rtl8169_set_wol,
2213 .get_strings = rtl8169_get_strings,
2214 .get_sset_count = rtl8169_get_sset_count,
2215 .get_ethtool_stats = rtl8169_get_ethtool_stats,
2216 .get_ts_info = ethtool_op_get_ts_info,
2217 .nway_reset = phy_ethtool_nway_reset,
2218 .get_link_ksettings = phy_ethtool_get_link_ksettings,
2219 .set_link_ksettings = phy_ethtool_set_link_ksettings,
2222 static void rtl8169_get_mac_version(struct rtl8169_private *tp,
2226 * The driver currently handles the 8168Bf and the 8168Be identically
2227 * but they can be identified more specifically through the test below
2230 * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
2232 * Same thing for the 8101Eb and the 8101Ec:
2234 * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
2236 static const struct rtl_mac_info {
2241 /* 8168EP family. */
2242 { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 },
2243 { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 },
2244 { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 },
2247 { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 },
2248 { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 },
2251 { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 },
2252 { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 },
2253 { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 },
2254 { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 },
2257 { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 },
2258 { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 },
2259 { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 },
2262 { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 },
2263 { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 },
2264 { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 },
2267 { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 },
2268 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 },
2270 /* 8168DP family. */
2271 { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 },
2272 { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 },
2273 { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 },
2276 { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 },
2277 { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 },
2278 { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 },
2279 { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 },
2280 { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 },
2281 { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 },
2282 { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 },
2285 { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 },
2286 { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 },
2287 { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 },
2290 { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 },
2291 { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 },
2292 { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 },
2293 { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 },
2294 { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 },
2295 { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 },
2296 { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 },
2297 { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 },
2298 { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 },
2299 { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 },
2300 { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 },
2301 { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 },
2302 { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 },
2303 { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 },
2304 /* FIXME: where did these entries come from ? -- FR */
2305 { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 },
2306 { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 },
2309 { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 },
2310 { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 },
2311 { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 },
2312 { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 },
2313 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
2314 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
2317 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE }
2319 const struct rtl_mac_info *p = mac_info;
2322 reg = RTL_R32(tp, TxConfig);
2323 while ((reg & p->mask) != p->val)
2325 tp->mac_version = p->mac_version;
2327 if (tp->mac_version == RTL_GIGA_MAC_NONE) {
2328 dev_notice(tp_to_dev(tp),
2329 "unknown MAC, using family default\n");
2330 tp->mac_version = default_version;
2331 } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) {
2332 tp->mac_version = tp->mii.supports_gmii ?
2333 RTL_GIGA_MAC_VER_42 :
2334 RTL_GIGA_MAC_VER_43;
2335 } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) {
2336 tp->mac_version = tp->mii.supports_gmii ?
2337 RTL_GIGA_MAC_VER_45 :
2338 RTL_GIGA_MAC_VER_47;
2339 } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) {
2340 tp->mac_version = tp->mii.supports_gmii ?
2341 RTL_GIGA_MAC_VER_46 :
2342 RTL_GIGA_MAC_VER_48;
2346 static void rtl8169_print_mac_version(struct rtl8169_private *tp)
2348 netif_dbg(tp, drv, tp->dev, "mac_version = 0x%02x\n", tp->mac_version);
2356 static void rtl_writephy_batch(struct rtl8169_private *tp,
2357 const struct phy_reg *regs, int len)
2360 rtl_writephy(tp, regs->reg, regs->val);
2365 #define PHY_READ 0x00000000
2366 #define PHY_DATA_OR 0x10000000
2367 #define PHY_DATA_AND 0x20000000
2368 #define PHY_BJMPN 0x30000000
2369 #define PHY_MDIO_CHG 0x40000000
2370 #define PHY_CLEAR_READCOUNT 0x70000000
2371 #define PHY_WRITE 0x80000000
2372 #define PHY_READCOUNT_EQ_SKIP 0x90000000
2373 #define PHY_COMP_EQ_SKIPN 0xa0000000
2374 #define PHY_COMP_NEQ_SKIPN 0xb0000000
2375 #define PHY_WRITE_PREVIOUS 0xc0000000
2376 #define PHY_SKIPN 0xd0000000
2377 #define PHY_DELAY_MS 0xe0000000
2381 char version[RTL_VER_SIZE];
2387 #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code))
2389 static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
2391 const struct firmware *fw = rtl_fw->fw;
2392 struct fw_info *fw_info = (struct fw_info *)fw->data;
2393 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
2394 char *version = rtl_fw->version;
2397 if (fw->size < FW_OPCODE_SIZE)
2400 if (!fw_info->magic) {
2401 size_t i, size, start;
2404 if (fw->size < sizeof(*fw_info))
2407 for (i = 0; i < fw->size; i++)
2408 checksum += fw->data[i];
2412 start = le32_to_cpu(fw_info->fw_start);
2413 if (start > fw->size)
2416 size = le32_to_cpu(fw_info->fw_len);
2417 if (size > (fw->size - start) / FW_OPCODE_SIZE)
2420 memcpy(version, fw_info->version, RTL_VER_SIZE);
2422 pa->code = (__le32 *)(fw->data + start);
2425 if (fw->size % FW_OPCODE_SIZE)
2428 strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE);
2430 pa->code = (__le32 *)fw->data;
2431 pa->size = fw->size / FW_OPCODE_SIZE;
2433 version[RTL_VER_SIZE - 1] = 0;
2440 static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev,
2441 struct rtl_fw_phy_action *pa)
2446 for (index = 0; index < pa->size; index++) {
2447 u32 action = le32_to_cpu(pa->code[index]);
2448 u32 regno = (action & 0x0fff0000) >> 16;
2450 switch(action & 0xf0000000) {
2455 case PHY_CLEAR_READCOUNT:
2457 case PHY_WRITE_PREVIOUS:
2462 if (regno > index) {
2463 netif_err(tp, ifup, tp->dev,
2464 "Out of range of firmware\n");
2468 case PHY_READCOUNT_EQ_SKIP:
2469 if (index + 2 >= pa->size) {
2470 netif_err(tp, ifup, tp->dev,
2471 "Out of range of firmware\n");
2475 case PHY_COMP_EQ_SKIPN:
2476 case PHY_COMP_NEQ_SKIPN:
2478 if (index + 1 + regno >= pa->size) {
2479 netif_err(tp, ifup, tp->dev,
2480 "Out of range of firmware\n");
2486 netif_err(tp, ifup, tp->dev,
2487 "Invalid action 0x%08x\n", action);
2496 static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
2498 struct net_device *dev = tp->dev;
2501 if (!rtl_fw_format_ok(tp, rtl_fw)) {
2502 netif_err(tp, ifup, dev, "invalid firmware\n");
2506 if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action))
2512 static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw)
2514 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action;
2515 struct mdio_ops org, *ops = &tp->mdio_ops;
2519 predata = count = 0;
2520 org.write = ops->write;
2521 org.read = ops->read;
2523 for (index = 0; index < pa->size; ) {
2524 u32 action = le32_to_cpu(pa->code[index]);
2525 u32 data = action & 0x0000ffff;
2526 u32 regno = (action & 0x0fff0000) >> 16;
2531 switch(action & 0xf0000000) {
2533 predata = rtl_readphy(tp, regno);
2550 ops->write = org.write;
2551 ops->read = org.read;
2552 } else if (data == 1) {
2553 ops->write = mac_mcu_write;
2554 ops->read = mac_mcu_read;
2559 case PHY_CLEAR_READCOUNT:
2564 rtl_writephy(tp, regno, data);
2567 case PHY_READCOUNT_EQ_SKIP:
2568 index += (count == data) ? 2 : 1;
2570 case PHY_COMP_EQ_SKIPN:
2571 if (predata == data)
2575 case PHY_COMP_NEQ_SKIPN:
2576 if (predata != data)
2580 case PHY_WRITE_PREVIOUS:
2581 rtl_writephy(tp, regno, predata);
2597 ops->write = org.write;
2598 ops->read = org.read;
2601 static void rtl_release_firmware(struct rtl8169_private *tp)
2603 if (!IS_ERR_OR_NULL(tp->rtl_fw)) {
2604 release_firmware(tp->rtl_fw->fw);
2607 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
2610 static void rtl_apply_firmware(struct rtl8169_private *tp)
2612 struct rtl_fw *rtl_fw = tp->rtl_fw;
2614 /* TODO: release firmware once rtl_phy_write_fw signals failures. */
2615 if (!IS_ERR_OR_NULL(rtl_fw))
2616 rtl_phy_write_fw(tp, rtl_fw);
2619 static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val)
2621 if (rtl_readphy(tp, reg) != val)
2622 netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n");
2624 rtl_apply_firmware(tp);
2627 static void rtl8169s_hw_phy_config(struct rtl8169_private *tp)
2629 static const struct phy_reg phy_reg_init[] = {
2691 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2694 static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp)
2696 static const struct phy_reg phy_reg_init[] = {
2702 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2705 static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp)
2707 struct pci_dev *pdev = tp->pci_dev;
2709 if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) ||
2710 (pdev->subsystem_device != 0xe000))
2713 rtl_writephy(tp, 0x1f, 0x0001);
2714 rtl_writephy(tp, 0x10, 0xf01b);
2715 rtl_writephy(tp, 0x1f, 0x0000);
2718 static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp)
2720 static const struct phy_reg phy_reg_init[] = {
2760 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2762 rtl8169scd_hw_phy_config_quirk(tp);
2765 static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp)
2767 static const struct phy_reg phy_reg_init[] = {
2815 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2818 static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp)
2820 static const struct phy_reg phy_reg_init[] = {
2825 rtl_writephy(tp, 0x1f, 0x0001);
2826 rtl_patchphy(tp, 0x16, 1 << 0);
2828 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2831 static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp)
2833 static const struct phy_reg phy_reg_init[] = {
2839 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2842 static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp)
2844 static const struct phy_reg phy_reg_init[] = {
2852 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2855 static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp)
2857 static const struct phy_reg phy_reg_init[] = {
2863 rtl_writephy(tp, 0x1f, 0x0000);
2864 rtl_patchphy(tp, 0x14, 1 << 5);
2865 rtl_patchphy(tp, 0x0d, 1 << 5);
2867 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2870 static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp)
2872 static const struct phy_reg phy_reg_init[] = {
2892 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2894 rtl_patchphy(tp, 0x14, 1 << 5);
2895 rtl_patchphy(tp, 0x0d, 1 << 5);
2896 rtl_writephy(tp, 0x1f, 0x0000);
2899 static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp)
2901 static const struct phy_reg phy_reg_init[] = {
2919 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2921 rtl_patchphy(tp, 0x16, 1 << 0);
2922 rtl_patchphy(tp, 0x14, 1 << 5);
2923 rtl_patchphy(tp, 0x0d, 1 << 5);
2924 rtl_writephy(tp, 0x1f, 0x0000);
2927 static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp)
2929 static const struct phy_reg phy_reg_init[] = {
2941 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
2943 rtl_patchphy(tp, 0x16, 1 << 0);
2944 rtl_patchphy(tp, 0x14, 1 << 5);
2945 rtl_patchphy(tp, 0x0d, 1 << 5);
2946 rtl_writephy(tp, 0x1f, 0x0000);
2949 static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp)
2951 rtl8168c_3_hw_phy_config(tp);
2954 static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp)
2956 static const struct phy_reg phy_reg_init_0[] = {
2957 /* Channel Estimation */
2978 * Enhance line driver power
2987 * Can not link to 1Gbps with bad cable
2988 * Decrease SNR threshold form 21.07dB to 19.04dB
2997 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
3001 * Fine Tune Switching regulator parameter
3003 rtl_writephy(tp, 0x1f, 0x0002);
3004 rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef);
3005 rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00);
3007 if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
3008 static const struct phy_reg phy_reg_init[] = {
3018 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3020 val = rtl_readphy(tp, 0x0d);
3022 if ((val & 0x00ff) != 0x006c) {
3023 static const u32 set[] = {
3024 0x0065, 0x0066, 0x0067, 0x0068,
3025 0x0069, 0x006a, 0x006b, 0x006c
3029 rtl_writephy(tp, 0x1f, 0x0002);
3032 for (i = 0; i < ARRAY_SIZE(set); i++)
3033 rtl_writephy(tp, 0x0d, val | set[i]);
3036 static const struct phy_reg phy_reg_init[] = {
3044 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3047 /* RSET couple improve */
3048 rtl_writephy(tp, 0x1f, 0x0002);
3049 rtl_patchphy(tp, 0x0d, 0x0300);
3050 rtl_patchphy(tp, 0x0f, 0x0010);
3052 /* Fine tune PLL performance */
3053 rtl_writephy(tp, 0x1f, 0x0002);
3054 rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600);
3055 rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000);
3057 rtl_writephy(tp, 0x1f, 0x0005);
3058 rtl_writephy(tp, 0x05, 0x001b);
3060 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00);
3062 rtl_writephy(tp, 0x1f, 0x0000);
3065 static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp)
3067 static const struct phy_reg phy_reg_init_0[] = {
3068 /* Channel Estimation */
3089 * Enhance line driver power
3098 * Can not link to 1Gbps with bad cable
3099 * Decrease SNR threshold form 21.07dB to 19.04dB
3108 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0));
3110 if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) {
3111 static const struct phy_reg phy_reg_init[] = {
3122 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3124 val = rtl_readphy(tp, 0x0d);
3125 if ((val & 0x00ff) != 0x006c) {
3126 static const u32 set[] = {
3127 0x0065, 0x0066, 0x0067, 0x0068,
3128 0x0069, 0x006a, 0x006b, 0x006c
3132 rtl_writephy(tp, 0x1f, 0x0002);
3135 for (i = 0; i < ARRAY_SIZE(set); i++)
3136 rtl_writephy(tp, 0x0d, val | set[i]);
3139 static const struct phy_reg phy_reg_init[] = {
3147 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3150 /* Fine tune PLL performance */
3151 rtl_writephy(tp, 0x1f, 0x0002);
3152 rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600);
3153 rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000);
3155 /* Switching regulator Slew rate */
3156 rtl_writephy(tp, 0x1f, 0x0002);
3157 rtl_patchphy(tp, 0x0f, 0x0017);
3159 rtl_writephy(tp, 0x1f, 0x0005);
3160 rtl_writephy(tp, 0x05, 0x001b);
3162 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300);
3164 rtl_writephy(tp, 0x1f, 0x0000);
3167 static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp)
3169 static const struct phy_reg phy_reg_init[] = {
3225 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3228 static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp)
3230 static const struct phy_reg phy_reg_init[] = {
3240 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3241 rtl_patchphy(tp, 0x0d, 1 << 5);
3244 static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp)
3246 static const struct phy_reg phy_reg_init[] = {
3247 /* Enable Delay cap */
3253 /* Channel estimation fine tune */
3262 /* Update PFM & 10M TX idle timer */
3274 rtl_apply_firmware(tp);
3276 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3278 /* DCO enable for 10M IDLE Power */
3279 rtl_writephy(tp, 0x1f, 0x0007);
3280 rtl_writephy(tp, 0x1e, 0x0023);
3281 rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000);
3282 rtl_writephy(tp, 0x1f, 0x0000);
3284 /* For impedance matching */
3285 rtl_writephy(tp, 0x1f, 0x0002);
3286 rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00);
3287 rtl_writephy(tp, 0x1f, 0x0000);
3289 /* PHY auto speed down */
3290 rtl_writephy(tp, 0x1f, 0x0007);
3291 rtl_writephy(tp, 0x1e, 0x002d);
3292 rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000);
3293 rtl_writephy(tp, 0x1f, 0x0000);
3294 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3296 rtl_writephy(tp, 0x1f, 0x0005);
3297 rtl_writephy(tp, 0x05, 0x8b86);
3298 rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000);
3299 rtl_writephy(tp, 0x1f, 0x0000);
3301 rtl_writephy(tp, 0x1f, 0x0005);
3302 rtl_writephy(tp, 0x05, 0x8b85);
3303 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000);
3304 rtl_writephy(tp, 0x1f, 0x0007);
3305 rtl_writephy(tp, 0x1e, 0x0020);
3306 rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100);
3307 rtl_writephy(tp, 0x1f, 0x0006);
3308 rtl_writephy(tp, 0x00, 0x5a00);
3309 rtl_writephy(tp, 0x1f, 0x0000);
3310 rtl_writephy(tp, 0x0d, 0x0007);
3311 rtl_writephy(tp, 0x0e, 0x003c);
3312 rtl_writephy(tp, 0x0d, 0x4007);
3313 rtl_writephy(tp, 0x0e, 0x0000);
3314 rtl_writephy(tp, 0x0d, 0x0000);
3317 static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr)
3320 addr[0] | (addr[1] << 8),
3321 addr[2] | (addr[3] << 8),
3322 addr[4] | (addr[5] << 8)
3324 const struct exgmac_reg e[] = {
3325 { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) },
3326 { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] },
3327 { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 },
3328 { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) }
3331 rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e));
3334 static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp)
3336 static const struct phy_reg phy_reg_init[] = {
3337 /* Enable Delay cap */
3346 /* Channel estimation fine tune */
3363 rtl_apply_firmware(tp);
3365 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3367 /* For 4-corner performance improve */
3368 rtl_writephy(tp, 0x1f, 0x0005);
3369 rtl_writephy(tp, 0x05, 0x8b80);
3370 rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000);
3371 rtl_writephy(tp, 0x1f, 0x0000);
3373 /* PHY auto speed down */
3374 rtl_writephy(tp, 0x1f, 0x0004);
3375 rtl_writephy(tp, 0x1f, 0x0007);
3376 rtl_writephy(tp, 0x1e, 0x002d);
3377 rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000);
3378 rtl_writephy(tp, 0x1f, 0x0002);
3379 rtl_writephy(tp, 0x1f, 0x0000);
3380 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3382 /* improve 10M EEE waveform */
3383 rtl_writephy(tp, 0x1f, 0x0005);
3384 rtl_writephy(tp, 0x05, 0x8b86);
3385 rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000);
3386 rtl_writephy(tp, 0x1f, 0x0000);
3388 /* Improve 2-pair detection performance */
3389 rtl_writephy(tp, 0x1f, 0x0005);
3390 rtl_writephy(tp, 0x05, 0x8b85);
3391 rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000);
3392 rtl_writephy(tp, 0x1f, 0x0000);
3395 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC);
3396 rtl_writephy(tp, 0x1f, 0x0005);
3397 rtl_writephy(tp, 0x05, 0x8b85);
3398 rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000);
3399 rtl_writephy(tp, 0x1f, 0x0004);
3400 rtl_writephy(tp, 0x1f, 0x0007);
3401 rtl_writephy(tp, 0x1e, 0x0020);
3402 rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000);
3403 rtl_writephy(tp, 0x1f, 0x0002);
3404 rtl_writephy(tp, 0x1f, 0x0000);
3405 rtl_writephy(tp, 0x0d, 0x0007);
3406 rtl_writephy(tp, 0x0e, 0x003c);
3407 rtl_writephy(tp, 0x0d, 0x4007);
3408 rtl_writephy(tp, 0x0e, 0x0006);
3409 rtl_writephy(tp, 0x0d, 0x0000);
3412 rtl_writephy(tp, 0x1f, 0x0003);
3413 rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000);
3414 rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000);
3415 rtl_writephy(tp, 0x1f, 0x0000);
3416 rtl_writephy(tp, 0x1f, 0x0005);
3417 rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000);
3418 rtl_writephy(tp, 0x1f, 0x0000);
3420 /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */
3421 rtl_rar_exgmac_set(tp, tp->dev->dev_addr);
3424 static void rtl8168f_hw_phy_config(struct rtl8169_private *tp)
3426 /* For 4-corner performance improve */
3427 rtl_writephy(tp, 0x1f, 0x0005);
3428 rtl_writephy(tp, 0x05, 0x8b80);
3429 rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000);
3430 rtl_writephy(tp, 0x1f, 0x0000);
3432 /* PHY auto speed down */
3433 rtl_writephy(tp, 0x1f, 0x0007);
3434 rtl_writephy(tp, 0x1e, 0x002d);
3435 rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000);
3436 rtl_writephy(tp, 0x1f, 0x0000);
3437 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3439 /* Improve 10M EEE waveform */
3440 rtl_writephy(tp, 0x1f, 0x0005);
3441 rtl_writephy(tp, 0x05, 0x8b86);
3442 rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000);
3443 rtl_writephy(tp, 0x1f, 0x0000);
3446 static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp)
3448 static const struct phy_reg phy_reg_init[] = {
3449 /* Channel estimation fine tune */
3454 /* Modify green table for giga & fnet */
3471 /* Modify green table for 10M */
3477 /* Disable hiimpedance detection (RTCT) */
3483 rtl_apply_firmware(tp);
3485 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3487 rtl8168f_hw_phy_config(tp);
3489 /* Improve 2-pair detection performance */
3490 rtl_writephy(tp, 0x1f, 0x0005);
3491 rtl_writephy(tp, 0x05, 0x8b85);
3492 rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000);
3493 rtl_writephy(tp, 0x1f, 0x0000);
3496 static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp)
3498 rtl_apply_firmware(tp);
3500 rtl8168f_hw_phy_config(tp);
3503 static void rtl8411_hw_phy_config(struct rtl8169_private *tp)
3505 static const struct phy_reg phy_reg_init[] = {
3506 /* Channel estimation fine tune */
3511 /* Modify green table for giga & fnet */
3528 /* Modify green table for 10M */
3534 /* Disable hiimpedance detection (RTCT) */
3541 rtl_apply_firmware(tp);
3543 rtl8168f_hw_phy_config(tp);
3545 /* Improve 2-pair detection performance */
3546 rtl_writephy(tp, 0x1f, 0x0005);
3547 rtl_writephy(tp, 0x05, 0x8b85);
3548 rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000);
3549 rtl_writephy(tp, 0x1f, 0x0000);
3551 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
3553 /* Modify green table for giga */
3554 rtl_writephy(tp, 0x1f, 0x0005);
3555 rtl_writephy(tp, 0x05, 0x8b54);
3556 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800);
3557 rtl_writephy(tp, 0x05, 0x8b5d);
3558 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800);
3559 rtl_writephy(tp, 0x05, 0x8a7c);
3560 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100);
3561 rtl_writephy(tp, 0x05, 0x8a7f);
3562 rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000);
3563 rtl_writephy(tp, 0x05, 0x8a82);
3564 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100);
3565 rtl_writephy(tp, 0x05, 0x8a85);
3566 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100);
3567 rtl_writephy(tp, 0x05, 0x8a88);
3568 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100);
3569 rtl_writephy(tp, 0x1f, 0x0000);
3571 /* uc same-seed solution */
3572 rtl_writephy(tp, 0x1f, 0x0005);
3573 rtl_writephy(tp, 0x05, 0x8b85);
3574 rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000);
3575 rtl_writephy(tp, 0x1f, 0x0000);
3578 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC);
3579 rtl_writephy(tp, 0x1f, 0x0005);
3580 rtl_writephy(tp, 0x05, 0x8b85);
3581 rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000);
3582 rtl_writephy(tp, 0x1f, 0x0004);
3583 rtl_writephy(tp, 0x1f, 0x0007);
3584 rtl_writephy(tp, 0x1e, 0x0020);
3585 rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100);
3586 rtl_writephy(tp, 0x1f, 0x0000);
3587 rtl_writephy(tp, 0x0d, 0x0007);
3588 rtl_writephy(tp, 0x0e, 0x003c);
3589 rtl_writephy(tp, 0x0d, 0x4007);
3590 rtl_writephy(tp, 0x0e, 0x0000);
3591 rtl_writephy(tp, 0x0d, 0x0000);
3594 rtl_writephy(tp, 0x1f, 0x0003);
3595 rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001);
3596 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400);
3597 rtl_writephy(tp, 0x1f, 0x0000);
3600 static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp)
3602 rtl_apply_firmware(tp);
3604 rtl_writephy(tp, 0x1f, 0x0a46);
3605 if (rtl_readphy(tp, 0x10) & 0x0100) {
3606 rtl_writephy(tp, 0x1f, 0x0bcc);
3607 rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000);
3609 rtl_writephy(tp, 0x1f, 0x0bcc);
3610 rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000);
3613 rtl_writephy(tp, 0x1f, 0x0a46);
3614 if (rtl_readphy(tp, 0x13) & 0x0100) {
3615 rtl_writephy(tp, 0x1f, 0x0c41);
3616 rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000);
3618 rtl_writephy(tp, 0x1f, 0x0c41);
3619 rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002);
3622 /* Enable PHY auto speed down */
3623 rtl_writephy(tp, 0x1f, 0x0a44);
3624 rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000);
3626 rtl_writephy(tp, 0x1f, 0x0bcc);
3627 rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000);
3628 rtl_writephy(tp, 0x1f, 0x0a44);
3629 rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000);
3630 rtl_writephy(tp, 0x1f, 0x0a43);
3631 rtl_writephy(tp, 0x13, 0x8084);
3632 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000);
3633 rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000);
3635 /* EEE auto-fallback function */
3636 rtl_writephy(tp, 0x1f, 0x0a4b);
3637 rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000);
3639 /* Enable UC LPF tune function */
3640 rtl_writephy(tp, 0x1f, 0x0a43);
3641 rtl_writephy(tp, 0x13, 0x8012);
3642 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3644 rtl_writephy(tp, 0x1f, 0x0c42);
3645 rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000);
3647 /* Improve SWR Efficiency */
3648 rtl_writephy(tp, 0x1f, 0x0bcd);
3649 rtl_writephy(tp, 0x14, 0x5065);
3650 rtl_writephy(tp, 0x14, 0xd065);
3651 rtl_writephy(tp, 0x1f, 0x0bc8);
3652 rtl_writephy(tp, 0x11, 0x5655);
3653 rtl_writephy(tp, 0x1f, 0x0bcd);
3654 rtl_writephy(tp, 0x14, 0x1065);
3655 rtl_writephy(tp, 0x14, 0x9065);
3656 rtl_writephy(tp, 0x14, 0x1065);
3658 /* Check ALDPS bit, disable it if enabled */
3659 rtl_writephy(tp, 0x1f, 0x0a43);
3660 if (rtl_readphy(tp, 0x10) & 0x0004)
3661 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004);
3663 rtl_writephy(tp, 0x1f, 0x0000);
3666 static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp)
3668 rtl_apply_firmware(tp);
3671 static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp)
3676 rtl_apply_firmware(tp);
3678 /* CHN EST parameters adjust - giga master */
3679 rtl_writephy(tp, 0x1f, 0x0a43);
3680 rtl_writephy(tp, 0x13, 0x809b);
3681 rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800);
3682 rtl_writephy(tp, 0x13, 0x80a2);
3683 rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00);
3684 rtl_writephy(tp, 0x13, 0x80a4);
3685 rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00);
3686 rtl_writephy(tp, 0x13, 0x809c);
3687 rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00);
3688 rtl_writephy(tp, 0x1f, 0x0000);
3690 /* CHN EST parameters adjust - giga slave */
3691 rtl_writephy(tp, 0x1f, 0x0a43);
3692 rtl_writephy(tp, 0x13, 0x80ad);
3693 rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800);
3694 rtl_writephy(tp, 0x13, 0x80b4);
3695 rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00);
3696 rtl_writephy(tp, 0x13, 0x80ac);
3697 rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00);
3698 rtl_writephy(tp, 0x1f, 0x0000);
3700 /* CHN EST parameters adjust - fnet */
3701 rtl_writephy(tp, 0x1f, 0x0a43);
3702 rtl_writephy(tp, 0x13, 0x808e);
3703 rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00);
3704 rtl_writephy(tp, 0x13, 0x8090);
3705 rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00);
3706 rtl_writephy(tp, 0x13, 0x8092);
3707 rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00);
3708 rtl_writephy(tp, 0x1f, 0x0000);
3710 /* enable R-tune & PGA-retune function */
3712 rtl_writephy(tp, 0x1f, 0x0a46);
3713 data = rtl_readphy(tp, 0x13);
3716 dout_tapbin |= data;
3717 data = rtl_readphy(tp, 0x12);
3720 dout_tapbin |= data;
3721 dout_tapbin = ~(dout_tapbin^0x08);
3723 dout_tapbin &= 0xf000;
3724 rtl_writephy(tp, 0x1f, 0x0a43);
3725 rtl_writephy(tp, 0x13, 0x827a);
3726 rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000);
3727 rtl_writephy(tp, 0x13, 0x827b);
3728 rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000);
3729 rtl_writephy(tp, 0x13, 0x827c);
3730 rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000);
3731 rtl_writephy(tp, 0x13, 0x827d);
3732 rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000);
3734 rtl_writephy(tp, 0x1f, 0x0a43);
3735 rtl_writephy(tp, 0x13, 0x0811);
3736 rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000);
3737 rtl_writephy(tp, 0x1f, 0x0a42);
3738 rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000);
3739 rtl_writephy(tp, 0x1f, 0x0000);
3741 /* enable GPHY 10M */
3742 rtl_writephy(tp, 0x1f, 0x0a44);
3743 rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000);
3744 rtl_writephy(tp, 0x1f, 0x0000);
3746 /* SAR ADC performance */
3747 rtl_writephy(tp, 0x1f, 0x0bca);
3748 rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000);
3749 rtl_writephy(tp, 0x1f, 0x0000);
3751 rtl_writephy(tp, 0x1f, 0x0a43);
3752 rtl_writephy(tp, 0x13, 0x803f);
3753 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3754 rtl_writephy(tp, 0x13, 0x8047);
3755 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3756 rtl_writephy(tp, 0x13, 0x804f);
3757 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3758 rtl_writephy(tp, 0x13, 0x8057);
3759 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3760 rtl_writephy(tp, 0x13, 0x805f);
3761 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3762 rtl_writephy(tp, 0x13, 0x8067);
3763 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3764 rtl_writephy(tp, 0x13, 0x806f);
3765 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000);
3766 rtl_writephy(tp, 0x1f, 0x0000);
3768 /* disable phy pfm mode */
3769 rtl_writephy(tp, 0x1f, 0x0a44);
3770 rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080);
3771 rtl_writephy(tp, 0x1f, 0x0000);
3773 /* Check ALDPS bit, disable it if enabled */
3774 rtl_writephy(tp, 0x1f, 0x0a43);
3775 if (rtl_readphy(tp, 0x10) & 0x0004)
3776 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004);
3778 rtl_writephy(tp, 0x1f, 0x0000);
3781 static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp)
3783 u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0;
3787 rtl_apply_firmware(tp);
3789 /* CHIN EST parameter update */
3790 rtl_writephy(tp, 0x1f, 0x0a43);
3791 rtl_writephy(tp, 0x13, 0x808a);
3792 rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f);
3793 rtl_writephy(tp, 0x1f, 0x0000);
3795 /* enable R-tune & PGA-retune function */
3796 rtl_writephy(tp, 0x1f, 0x0a43);
3797 rtl_writephy(tp, 0x13, 0x0811);
3798 rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000);
3799 rtl_writephy(tp, 0x1f, 0x0a42);
3800 rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000);
3801 rtl_writephy(tp, 0x1f, 0x0000);
3803 /* enable GPHY 10M */
3804 rtl_writephy(tp, 0x1f, 0x0a44);
3805 rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000);
3806 rtl_writephy(tp, 0x1f, 0x0000);
3808 r8168_mac_ocp_write(tp, 0xdd02, 0x807d);
3809 data = r8168_mac_ocp_read(tp, 0xdd02);
3810 ioffset_p3 = ((data & 0x80)>>7);
3813 data = r8168_mac_ocp_read(tp, 0xdd00);
3814 ioffset_p3 |= ((data & (0xe000))>>13);
3815 ioffset_p2 = ((data & (0x1e00))>>9);
3816 ioffset_p1 = ((data & (0x01e0))>>5);
3817 ioffset_p0 = ((data & 0x0010)>>4);
3819 ioffset_p0 |= (data & (0x07));
3820 data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0);
3822 if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) ||
3823 (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) {
3824 rtl_writephy(tp, 0x1f, 0x0bcf);
3825 rtl_writephy(tp, 0x16, data);
3826 rtl_writephy(tp, 0x1f, 0x0000);
3829 /* Modify rlen (TX LPF corner frequency) level */
3830 rtl_writephy(tp, 0x1f, 0x0bcd);
3831 data = rtl_readphy(tp, 0x16);
3836 data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12);
3837 rtl_writephy(tp, 0x17, data);
3838 rtl_writephy(tp, 0x1f, 0x0bcd);
3839 rtl_writephy(tp, 0x1f, 0x0000);
3841 /* disable phy pfm mode */
3842 rtl_writephy(tp, 0x1f, 0x0a44);
3843 rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080);
3844 rtl_writephy(tp, 0x1f, 0x0000);
3846 /* Check ALDPS bit, disable it if enabled */
3847 rtl_writephy(tp, 0x1f, 0x0a43);
3848 if (rtl_readphy(tp, 0x10) & 0x0004)
3849 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004);
3851 rtl_writephy(tp, 0x1f, 0x0000);
3854 static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp)
3856 /* Enable PHY auto speed down */
3857 rtl_writephy(tp, 0x1f, 0x0a44);
3858 rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000);
3859 rtl_writephy(tp, 0x1f, 0x0000);
3861 /* patch 10M & ALDPS */
3862 rtl_writephy(tp, 0x1f, 0x0bcc);
3863 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100);
3864 rtl_writephy(tp, 0x1f, 0x0a44);
3865 rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000);
3866 rtl_writephy(tp, 0x1f, 0x0a43);
3867 rtl_writephy(tp, 0x13, 0x8084);
3868 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000);
3869 rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000);
3870 rtl_writephy(tp, 0x1f, 0x0000);
3872 /* Enable EEE auto-fallback function */
3873 rtl_writephy(tp, 0x1f, 0x0a4b);
3874 rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000);
3875 rtl_writephy(tp, 0x1f, 0x0000);
3877 /* Enable UC LPF tune function */
3878 rtl_writephy(tp, 0x1f, 0x0a43);
3879 rtl_writephy(tp, 0x13, 0x8012);
3880 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3881 rtl_writephy(tp, 0x1f, 0x0000);
3883 /* set rg_sel_sdm_rate */
3884 rtl_writephy(tp, 0x1f, 0x0c42);
3885 rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000);
3886 rtl_writephy(tp, 0x1f, 0x0000);
3888 /* Check ALDPS bit, disable it if enabled */
3889 rtl_writephy(tp, 0x1f, 0x0a43);
3890 if (rtl_readphy(tp, 0x10) & 0x0004)
3891 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004);
3893 rtl_writephy(tp, 0x1f, 0x0000);
3896 static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp)
3898 /* patch 10M & ALDPS */
3899 rtl_writephy(tp, 0x1f, 0x0bcc);
3900 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100);
3901 rtl_writephy(tp, 0x1f, 0x0a44);
3902 rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000);
3903 rtl_writephy(tp, 0x1f, 0x0a43);
3904 rtl_writephy(tp, 0x13, 0x8084);
3905 rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000);
3906 rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000);
3907 rtl_writephy(tp, 0x1f, 0x0000);
3909 /* Enable UC LPF tune function */
3910 rtl_writephy(tp, 0x1f, 0x0a43);
3911 rtl_writephy(tp, 0x13, 0x8012);
3912 rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000);
3913 rtl_writephy(tp, 0x1f, 0x0000);
3915 /* Set rg_sel_sdm_rate */
3916 rtl_writephy(tp, 0x1f, 0x0c42);
3917 rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000);
3918 rtl_writephy(tp, 0x1f, 0x0000);
3920 /* Channel estimation parameters */
3921 rtl_writephy(tp, 0x1f, 0x0a43);
3922 rtl_writephy(tp, 0x13, 0x80f3);
3923 rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff);
3924 rtl_writephy(tp, 0x13, 0x80f0);
3925 rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff);
3926 rtl_writephy(tp, 0x13, 0x80ef);
3927 rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff);
3928 rtl_writephy(tp, 0x13, 0x80f6);
3929 rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff);
3930 rtl_writephy(tp, 0x13, 0x80ec);
3931 rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff);
3932 rtl_writephy(tp, 0x13, 0x80ed);
3933 rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff);
3934 rtl_writephy(tp, 0x13, 0x80f2);
3935 rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff);
3936 rtl_writephy(tp, 0x13, 0x80f4);
3937 rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff);
3938 rtl_writephy(tp, 0x1f, 0x0a43);
3939 rtl_writephy(tp, 0x13, 0x8110);
3940 rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff);
3941 rtl_writephy(tp, 0x13, 0x810f);
3942 rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff);
3943 rtl_writephy(tp, 0x13, 0x8111);
3944 rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff);
3945 rtl_writephy(tp, 0x13, 0x8113);
3946 rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff);
3947 rtl_writephy(tp, 0x13, 0x8115);
3948 rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff);
3949 rtl_writephy(tp, 0x13, 0x810e);
3950 rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff);
3951 rtl_writephy(tp, 0x13, 0x810c);
3952 rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff);
3953 rtl_writephy(tp, 0x13, 0x810b);
3954 rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff);
3955 rtl_writephy(tp, 0x1f, 0x0a43);
3956 rtl_writephy(tp, 0x13, 0x80d1);
3957 rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff);
3958 rtl_writephy(tp, 0x13, 0x80cd);
3959 rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff);
3960 rtl_writephy(tp, 0x13, 0x80d3);
3961 rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff);
3962 rtl_writephy(tp, 0x13, 0x80d5);
3963 rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff);
3964 rtl_writephy(tp, 0x13, 0x80d7);
3965 rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff);
3967 /* Force PWM-mode */
3968 rtl_writephy(tp, 0x1f, 0x0bcd);
3969 rtl_writephy(tp, 0x14, 0x5065);
3970 rtl_writephy(tp, 0x14, 0xd065);
3971 rtl_writephy(tp, 0x1f, 0x0bc8);
3972 rtl_writephy(tp, 0x12, 0x00ed);
3973 rtl_writephy(tp, 0x1f, 0x0bcd);
3974 rtl_writephy(tp, 0x14, 0x1065);
3975 rtl_writephy(tp, 0x14, 0x9065);
3976 rtl_writephy(tp, 0x14, 0x1065);
3977 rtl_writephy(tp, 0x1f, 0x0000);
3979 /* Check ALDPS bit, disable it if enabled */
3980 rtl_writephy(tp, 0x1f, 0x0a43);
3981 if (rtl_readphy(tp, 0x10) & 0x0004)
3982 rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004);
3984 rtl_writephy(tp, 0x1f, 0x0000);
3987 static void rtl8102e_hw_phy_config(struct rtl8169_private *tp)
3989 static const struct phy_reg phy_reg_init[] = {
3996 rtl_writephy(tp, 0x1f, 0x0000);
3997 rtl_patchphy(tp, 0x11, 1 << 12);
3998 rtl_patchphy(tp, 0x19, 1 << 13);
3999 rtl_patchphy(tp, 0x10, 1 << 15);
4001 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
4004 static void rtl8105e_hw_phy_config(struct rtl8169_private *tp)
4006 static const struct phy_reg phy_reg_init[] = {
4020 /* Disable ALDPS before ram code */
4021 rtl_writephy(tp, 0x1f, 0x0000);
4022 rtl_writephy(tp, 0x18, 0x0310);
4025 rtl_apply_firmware(tp);
4027 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
4030 static void rtl8402_hw_phy_config(struct rtl8169_private *tp)
4032 /* Disable ALDPS before setting firmware */
4033 rtl_writephy(tp, 0x1f, 0x0000);
4034 rtl_writephy(tp, 0x18, 0x0310);
4037 rtl_apply_firmware(tp);
4040 rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
4041 rtl_writephy(tp, 0x1f, 0x0004);
4042 rtl_writephy(tp, 0x10, 0x401f);
4043 rtl_writephy(tp, 0x19, 0x7030);
4044 rtl_writephy(tp, 0x1f, 0x0000);
4047 static void rtl8106e_hw_phy_config(struct rtl8169_private *tp)
4049 static const struct phy_reg phy_reg_init[] = {
4056 /* Disable ALDPS before ram code */
4057 rtl_writephy(tp, 0x1f, 0x0000);
4058 rtl_writephy(tp, 0x18, 0x0310);
4061 rtl_apply_firmware(tp);
4063 rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
4064 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init));
4066 rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
4069 static void rtl_hw_phy_config(struct net_device *dev)
4071 struct rtl8169_private *tp = netdev_priv(dev);
4073 rtl8169_print_mac_version(tp);
4075 switch (tp->mac_version) {
4076 case RTL_GIGA_MAC_VER_01:
4078 case RTL_GIGA_MAC_VER_02:
4079 case RTL_GIGA_MAC_VER_03:
4080 rtl8169s_hw_phy_config(tp);
4082 case RTL_GIGA_MAC_VER_04:
4083 rtl8169sb_hw_phy_config(tp);
4085 case RTL_GIGA_MAC_VER_05:
4086 rtl8169scd_hw_phy_config(tp);
4088 case RTL_GIGA_MAC_VER_06:
4089 rtl8169sce_hw_phy_config(tp);
4091 case RTL_GIGA_MAC_VER_07:
4092 case RTL_GIGA_MAC_VER_08:
4093 case RTL_GIGA_MAC_VER_09:
4094 rtl8102e_hw_phy_config(tp);
4096 case RTL_GIGA_MAC_VER_11:
4097 rtl8168bb_hw_phy_config(tp);
4099 case RTL_GIGA_MAC_VER_12:
4100 rtl8168bef_hw_phy_config(tp);
4102 case RTL_GIGA_MAC_VER_17:
4103 rtl8168bef_hw_phy_config(tp);
4105 case RTL_GIGA_MAC_VER_18:
4106 rtl8168cp_1_hw_phy_config(tp);
4108 case RTL_GIGA_MAC_VER_19:
4109 rtl8168c_1_hw_phy_config(tp);
4111 case RTL_GIGA_MAC_VER_20:
4112 rtl8168c_2_hw_phy_config(tp);
4114 case RTL_GIGA_MAC_VER_21:
4115 rtl8168c_3_hw_phy_config(tp);
4117 case RTL_GIGA_MAC_VER_22:
4118 rtl8168c_4_hw_phy_config(tp);
4120 case RTL_GIGA_MAC_VER_23:
4121 case RTL_GIGA_MAC_VER_24:
4122 rtl8168cp_2_hw_phy_config(tp);
4124 case RTL_GIGA_MAC_VER_25:
4125 rtl8168d_1_hw_phy_config(tp);
4127 case RTL_GIGA_MAC_VER_26:
4128 rtl8168d_2_hw_phy_config(tp);
4130 case RTL_GIGA_MAC_VER_27:
4131 rtl8168d_3_hw_phy_config(tp);
4133 case RTL_GIGA_MAC_VER_28:
4134 rtl8168d_4_hw_phy_config(tp);
4136 case RTL_GIGA_MAC_VER_29:
4137 case RTL_GIGA_MAC_VER_30:
4138 rtl8105e_hw_phy_config(tp);
4140 case RTL_GIGA_MAC_VER_31:
4143 case RTL_GIGA_MAC_VER_32:
4144 case RTL_GIGA_MAC_VER_33:
4145 rtl8168e_1_hw_phy_config(tp);
4147 case RTL_GIGA_MAC_VER_34:
4148 rtl8168e_2_hw_phy_config(tp);
4150 case RTL_GIGA_MAC_VER_35:
4151 rtl8168f_1_hw_phy_config(tp);
4153 case RTL_GIGA_MAC_VER_36:
4154 rtl8168f_2_hw_phy_config(tp);
4157 case RTL_GIGA_MAC_VER_37:
4158 rtl8402_hw_phy_config(tp);
4161 case RTL_GIGA_MAC_VER_38:
4162 rtl8411_hw_phy_config(tp);
4165 case RTL_GIGA_MAC_VER_39:
4166 rtl8106e_hw_phy_config(tp);
4169 case RTL_GIGA_MAC_VER_40:
4170 rtl8168g_1_hw_phy_config(tp);
4172 case RTL_GIGA_MAC_VER_42:
4173 case RTL_GIGA_MAC_VER_43:
4174 case RTL_GIGA_MAC_VER_44:
4175 rtl8168g_2_hw_phy_config(tp);
4177 case RTL_GIGA_MAC_VER_45:
4178 case RTL_GIGA_MAC_VER_47:
4179 rtl8168h_1_hw_phy_config(tp);
4181 case RTL_GIGA_MAC_VER_46:
4182 case RTL_GIGA_MAC_VER_48:
4183 rtl8168h_2_hw_phy_config(tp);
4186 case RTL_GIGA_MAC_VER_49:
4187 rtl8168ep_1_hw_phy_config(tp);
4189 case RTL_GIGA_MAC_VER_50:
4190 case RTL_GIGA_MAC_VER_51:
4191 rtl8168ep_2_hw_phy_config(tp);
4194 case RTL_GIGA_MAC_VER_41:
4200 static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag)
4202 if (!test_and_set_bit(flag, tp->wk.flags))
4203 schedule_work(&tp->wk.work);
4206 static bool rtl_tbi_enabled(struct rtl8169_private *tp)
4208 return (tp->mac_version == RTL_GIGA_MAC_VER_01) &&
4209 (RTL_R8(tp, PHYstatus) & TBI_Enable);
4212 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)
4214 rtl_hw_phy_config(dev);
4216 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
4217 netif_dbg(tp, drv, dev,
4218 "Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
4219 RTL_W8(tp, 0x82, 0x01);
4222 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40);
4224 if (tp->mac_version <= RTL_GIGA_MAC_VER_06)
4225 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
4227 if (tp->mac_version == RTL_GIGA_MAC_VER_02) {
4228 netif_dbg(tp, drv, dev,
4229 "Set MAC Reg C+CR Offset 0x82h = 0x01h\n");
4230 RTL_W8(tp, 0x82, 0x01);
4231 netif_dbg(tp, drv, dev,
4232 "Set PHY Reg 0x0bh = 0x00h\n");
4233 rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0
4236 genphy_soft_reset(dev->phydev);
4238 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
4239 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4240 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
4241 (tp->mii.supports_gmii ?
4242 ADVERTISED_1000baseT_Half |
4243 ADVERTISED_1000baseT_Full : 0));
4246 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr)
4250 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
4252 RTL_W32(tp, MAC4, addr[4] | addr[5] << 8);
4255 RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24);
4258 if (tp->mac_version == RTL_GIGA_MAC_VER_34)
4259 rtl_rar_exgmac_set(tp, addr);
4261 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
4263 rtl_unlock_work(tp);
4266 static int rtl_set_mac_address(struct net_device *dev, void *p)
4268 struct rtl8169_private *tp = netdev_priv(dev);
4269 struct device *d = tp_to_dev(tp);
4272 ret = eth_mac_addr(dev, p);
4276 pm_runtime_get_noresume(d);
4278 if (pm_runtime_active(d))
4279 rtl_rar_set(tp, dev->dev_addr);
4281 pm_runtime_put_noidle(d);
4286 static int rtl_xmii_ioctl(struct rtl8169_private *tp,
4287 struct mii_ioctl_data *data, int cmd)
4291 data->phy_id = 32; /* Internal PHY */
4295 data->val_out = rtl_readphy(tp, data->reg_num & 0x1f);
4299 rtl_writephy(tp, data->reg_num & 0x1f, data->val_in);
4305 static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4307 struct rtl8169_private *tp = netdev_priv(dev);
4308 struct mii_ioctl_data *data = if_mii(ifr);
4310 return netif_running(dev) ? rtl_xmii_ioctl(tp, data, cmd) : -ENODEV;
4313 static void rtl_init_mdio_ops(struct rtl8169_private *tp)
4315 struct mdio_ops *ops = &tp->mdio_ops;
4317 switch (tp->mac_version) {
4318 case RTL_GIGA_MAC_VER_27:
4319 ops->write = r8168dp_1_mdio_write;
4320 ops->read = r8168dp_1_mdio_read;
4322 case RTL_GIGA_MAC_VER_28:
4323 case RTL_GIGA_MAC_VER_31:
4324 ops->write = r8168dp_2_mdio_write;
4325 ops->read = r8168dp_2_mdio_read;
4327 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
4328 ops->write = r8168g_mdio_write;
4329 ops->read = r8168g_mdio_read;
4332 ops->write = r8169_mdio_write;
4333 ops->read = r8169_mdio_read;
4338 static void rtl_speed_down(struct rtl8169_private *tp)
4343 rtl_writephy(tp, 0x1f, 0x0000);
4344 lpa = rtl_readphy(tp, MII_LPA);
4346 if (lpa & (LPA_10HALF | LPA_10FULL))
4347 adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full;
4348 else if (lpa & (LPA_100HALF | LPA_100FULL))
4349 adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4350 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4352 adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4353 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full |
4354 (tp->mii.supports_gmii ?
4355 ADVERTISED_1000baseT_Half |
4356 ADVERTISED_1000baseT_Full : 0);
4358 rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL,
4362 static void rtl_wol_suspend_quirk(struct rtl8169_private *tp)
4364 switch (tp->mac_version) {
4365 case RTL_GIGA_MAC_VER_25:
4366 case RTL_GIGA_MAC_VER_26:
4367 case RTL_GIGA_MAC_VER_29:
4368 case RTL_GIGA_MAC_VER_30:
4369 case RTL_GIGA_MAC_VER_32:
4370 case RTL_GIGA_MAC_VER_33:
4371 case RTL_GIGA_MAC_VER_34:
4372 case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51:
4373 RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) |
4374 AcceptBroadcast | AcceptMulticast | AcceptMyPhys);
4381 static bool rtl_wol_pll_power_down(struct rtl8169_private *tp)
4383 if (!netif_running(tp->dev) || !__rtl8169_get_wol(tp))
4387 rtl_wol_suspend_quirk(tp);
4392 static void r8168_pll_power_down(struct rtl8169_private *tp)
4394 if (r8168_check_dash(tp))
4397 if (tp->mac_version == RTL_GIGA_MAC_VER_32 ||
4398 tp->mac_version == RTL_GIGA_MAC_VER_33)
4399 rtl_ephy_write(tp, 0x19, 0xff64);
4401 if (rtl_wol_pll_power_down(tp))
4404 switch (tp->mac_version) {
4405 case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33:
4406 case RTL_GIGA_MAC_VER_37:
4407 case RTL_GIGA_MAC_VER_39:
4408 case RTL_GIGA_MAC_VER_43:
4409 case RTL_GIGA_MAC_VER_44:
4410 case RTL_GIGA_MAC_VER_45:
4411 case RTL_GIGA_MAC_VER_46:
4412 case RTL_GIGA_MAC_VER_47:
4413 case RTL_GIGA_MAC_VER_48:
4414 case RTL_GIGA_MAC_VER_50:
4415 case RTL_GIGA_MAC_VER_51:
4416 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80);
4418 case RTL_GIGA_MAC_VER_40:
4419 case RTL_GIGA_MAC_VER_41:
4420 case RTL_GIGA_MAC_VER_49:
4421 rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000,
4422 0xfc000000, ERIAR_EXGMAC);
4423 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80);
4428 static void r8168_pll_power_up(struct rtl8169_private *tp)
4430 switch (tp->mac_version) {
4431 case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33:
4432 case RTL_GIGA_MAC_VER_37:
4433 case RTL_GIGA_MAC_VER_39:
4434 case RTL_GIGA_MAC_VER_43:
4435 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80);
4437 case RTL_GIGA_MAC_VER_44:
4438 case RTL_GIGA_MAC_VER_45:
4439 case RTL_GIGA_MAC_VER_46:
4440 case RTL_GIGA_MAC_VER_47:
4441 case RTL_GIGA_MAC_VER_48:
4442 case RTL_GIGA_MAC_VER_50:
4443 case RTL_GIGA_MAC_VER_51:
4444 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0);
4446 case RTL_GIGA_MAC_VER_40:
4447 case RTL_GIGA_MAC_VER_41:
4448 case RTL_GIGA_MAC_VER_49:
4449 RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0);
4450 rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000,
4451 0x00000000, ERIAR_EXGMAC);
4455 phy_resume(tp->dev->phydev);
4456 /* give MAC/PHY some time to resume */
4460 static void rtl_pll_power_down(struct rtl8169_private *tp)
4462 switch (tp->mac_version) {
4463 case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06:
4464 case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15:
4467 r8168_pll_power_down(tp);
4471 static void rtl_pll_power_up(struct rtl8169_private *tp)
4473 switch (tp->mac_version) {
4474 case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06:
4475 case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15:
4478 r8168_pll_power_up(tp);
4482 static void rtl_init_rxcfg(struct rtl8169_private *tp)
4484 switch (tp->mac_version) {
4485 case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06:
4486 case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17:
4487 RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST);
4489 case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24:
4490 case RTL_GIGA_MAC_VER_34:
4491 case RTL_GIGA_MAC_VER_35:
4492 RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST);
4494 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
4495 RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF);
4498 RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST);
4503 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp)
4505 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0;
4508 static void rtl_hw_jumbo_enable(struct rtl8169_private *tp)
4510 if (tp->jumbo_ops.enable) {
4511 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
4512 tp->jumbo_ops.enable(tp);
4513 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
4517 static void rtl_hw_jumbo_disable(struct rtl8169_private *tp)
4519 if (tp->jumbo_ops.disable) {
4520 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
4521 tp->jumbo_ops.disable(tp);
4522 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
4526 static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp)
4528 RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
4529 RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1);
4530 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B);
4533 static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp)
4535 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
4536 RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1);
4537 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4540 static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp)
4542 RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
4545 static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp)
4547 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
4550 static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp)
4552 RTL_W8(tp, MaxTxPacketSize, 0x3f);
4553 RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0);
4554 RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01);
4555 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B);
4558 static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp)
4560 RTL_W8(tp, MaxTxPacketSize, 0x0c);
4561 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0);
4562 RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01);
4563 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
4566 static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp)
4568 rtl_tx_performance_tweak(tp,
4569 PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN);
4572 static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp)
4574 rtl_tx_performance_tweak(tp,
4575 PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN);
4578 static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp)
4580 r8168b_0_hw_jumbo_enable(tp);
4582 RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0));
4585 static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp)
4587 r8168b_0_hw_jumbo_disable(tp);
4589 RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
4592 static void rtl_init_jumbo_ops(struct rtl8169_private *tp)
4594 struct jumbo_ops *ops = &tp->jumbo_ops;
4596 switch (tp->mac_version) {
4597 case RTL_GIGA_MAC_VER_11:
4598 ops->disable = r8168b_0_hw_jumbo_disable;
4599 ops->enable = r8168b_0_hw_jumbo_enable;
4601 case RTL_GIGA_MAC_VER_12:
4602 case RTL_GIGA_MAC_VER_17:
4603 ops->disable = r8168b_1_hw_jumbo_disable;
4604 ops->enable = r8168b_1_hw_jumbo_enable;
4606 case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */
4607 case RTL_GIGA_MAC_VER_19:
4608 case RTL_GIGA_MAC_VER_20:
4609 case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */
4610 case RTL_GIGA_MAC_VER_22:
4611 case RTL_GIGA_MAC_VER_23:
4612 case RTL_GIGA_MAC_VER_24:
4613 case RTL_GIGA_MAC_VER_25:
4614 case RTL_GIGA_MAC_VER_26:
4615 ops->disable = r8168c_hw_jumbo_disable;
4616 ops->enable = r8168c_hw_jumbo_enable;
4618 case RTL_GIGA_MAC_VER_27:
4619 case RTL_GIGA_MAC_VER_28:
4620 ops->disable = r8168dp_hw_jumbo_disable;
4621 ops->enable = r8168dp_hw_jumbo_enable;
4623 case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */
4624 case RTL_GIGA_MAC_VER_32:
4625 case RTL_GIGA_MAC_VER_33:
4626 case RTL_GIGA_MAC_VER_34:
4627 ops->disable = r8168e_hw_jumbo_disable;
4628 ops->enable = r8168e_hw_jumbo_enable;
4632 * No action needed for jumbo frames with 8169.
4633 * No jumbo for 810x at all.
4635 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
4637 ops->disable = NULL;
4643 DECLARE_RTL_COND(rtl_chipcmd_cond)
4645 return RTL_R8(tp, ChipCmd) & CmdReset;
4648 static void rtl_hw_reset(struct rtl8169_private *tp)
4650 RTL_W8(tp, ChipCmd, CmdReset);
4652 rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100);
4655 static void rtl_request_uncached_firmware(struct rtl8169_private *tp)
4657 struct rtl_fw *rtl_fw;
4661 name = rtl_lookup_firmware_name(tp);
4663 goto out_no_firmware;
4665 rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL);
4669 rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp));
4673 rc = rtl_check_firmware(tp, rtl_fw);
4675 goto err_release_firmware;
4677 tp->rtl_fw = rtl_fw;
4681 err_release_firmware:
4682 release_firmware(rtl_fw->fw);
4686 netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n",
4693 static void rtl_request_firmware(struct rtl8169_private *tp)
4695 if (IS_ERR(tp->rtl_fw))
4696 rtl_request_uncached_firmware(tp);
4699 static void rtl_rx_close(struct rtl8169_private *tp)
4701 RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK);
4704 DECLARE_RTL_COND(rtl_npq_cond)
4706 return RTL_R8(tp, TxPoll) & NPQ;
4709 DECLARE_RTL_COND(rtl_txcfg_empty_cond)
4711 return RTL_R32(tp, TxConfig) & TXCFG_EMPTY;
4714 static void rtl8169_hw_reset(struct rtl8169_private *tp)
4716 /* Disable interrupts */
4717 rtl8169_irq_mask_and_ack(tp);
4721 switch (tp->mac_version) {
4722 case RTL_GIGA_MAC_VER_27:
4723 case RTL_GIGA_MAC_VER_28:
4724 case RTL_GIGA_MAC_VER_31:
4725 rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42);
4727 case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38:
4728 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
4729 RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
4730 rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666);
4733 RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq);
4741 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp)
4743 /* Set DMA burst size and Interframe Gap Time */
4744 RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) |
4745 (InterFrameGap << TxInterFrameGapShift));
4748 static void rtl_set_rx_max_size(struct rtl8169_private *tp)
4750 /* Low hurts. Let's disable the filtering. */
4751 RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1);
4754 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp)
4757 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh
4758 * register to be written before TxDescAddrLow to work.
4759 * Switching from MMIO to I/O access fixes the issue as well.
4761 RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32);
4762 RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32));
4763 RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32);
4764 RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32));
4767 static void rtl8169_set_magic_reg(struct rtl8169_private *tp, unsigned mac_version)
4769 static const struct rtl_cfg2_info {
4774 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd
4775 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff },
4776 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe
4777 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff }
4779 const struct rtl_cfg2_info *p = cfg2_info;
4783 clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz;
4784 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) {
4785 if ((p->mac_version == mac_version) && (p->clk == clk)) {
4786 RTL_W32(tp, 0x7c, p->val);
4792 static void rtl_set_rx_mode(struct net_device *dev)
4794 struct rtl8169_private *tp = netdev_priv(dev);
4795 u32 mc_filter[2]; /* Multicast hash filter */
4799 if (dev->flags & IFF_PROMISC) {
4800 /* Unconditionally log net taps. */
4801 netif_notice(tp, link, dev, "Promiscuous mode enabled\n");
4803 AcceptBroadcast | AcceptMulticast | AcceptMyPhys |
4805 mc_filter[1] = mc_filter[0] = 0xffffffff;
4806 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
4807 (dev->flags & IFF_ALLMULTI)) {
4808 /* Too many to filter perfectly -- accept all multicasts. */
4809 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys;
4810 mc_filter[1] = mc_filter[0] = 0xffffffff;
4812 struct netdev_hw_addr *ha;
4814 rx_mode = AcceptBroadcast | AcceptMyPhys;
4815 mc_filter[1] = mc_filter[0] = 0;
4816 netdev_for_each_mc_addr(ha, dev) {
4817 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
4818 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
4819 rx_mode |= AcceptMulticast;
4823 if (dev->features & NETIF_F_RXALL)
4824 rx_mode |= (AcceptErr | AcceptRunt);
4826 tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode;
4828 if (tp->mac_version > RTL_GIGA_MAC_VER_06) {
4829 u32 data = mc_filter[0];
4831 mc_filter[0] = swab32(mc_filter[1]);
4832 mc_filter[1] = swab32(data);
4835 if (tp->mac_version == RTL_GIGA_MAC_VER_35)
4836 mc_filter[1] = mc_filter[0] = 0xffffffff;
4838 RTL_W32(tp, MAR0 + 4, mc_filter[1]);
4839 RTL_W32(tp, MAR0 + 0, mc_filter[0]);
4841 RTL_W32(tp, RxConfig, tmp);
4844 static void rtl_hw_start(struct rtl8169_private *tp)
4846 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
4850 rtl_set_rx_max_size(tp);
4851 rtl_set_rx_tx_desc_registers(tp);
4852 rtl_set_rx_tx_config_registers(tp);
4853 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
4855 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
4856 RTL_R8(tp, IntrMask);
4857 RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb);
4858 rtl_set_rx_mode(tp->dev);
4859 /* no early-rx interrupts */
4860 RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000);
4861 rtl_irq_enable_all(tp);
4864 static void rtl_hw_start_8169(struct rtl8169_private *tp)
4866 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
4867 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08);
4869 RTL_W8(tp, EarlyTxThres, NoEarlyTx);
4871 tp->cp_cmd |= PCIMulRW;
4873 if (tp->mac_version == RTL_GIGA_MAC_VER_02 ||
4874 tp->mac_version == RTL_GIGA_MAC_VER_03) {
4875 netif_dbg(tp, drv, tp->dev,
4876 "Set MAC Reg C+CR Offset 0xe0. Bit 3 and Bit 14 MUST be 1\n");
4877 tp->cp_cmd |= (1 << 14);
4880 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
4882 rtl8169_set_magic_reg(tp, tp->mac_version);
4885 * Undocumented corner. Supposedly:
4886 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets
4888 RTL_W16(tp, IntrMitigate, 0x0000);
4890 RTL_W32(tp, RxMissed, 0);
4893 DECLARE_RTL_COND(rtl_csiar_cond)
4895 return RTL_R32(tp, CSIAR) & CSIAR_FLAG;
4898 static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value)
4900 u32 func = PCI_FUNC(tp->pci_dev->devfn);
4902 RTL_W32(tp, CSIDR, value);
4903 RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) |
4904 CSIAR_BYTE_ENABLE | func << 16);
4906 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100);
4909 static u32 rtl_csi_read(struct rtl8169_private *tp, int addr)
4911 u32 func = PCI_FUNC(tp->pci_dev->devfn);
4913 RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 |
4916 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ?
4917 RTL_R32(tp, CSIDR) : ~0;
4920 static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val)
4922 struct pci_dev *pdev = tp->pci_dev;
4925 /* According to Realtek the value at config space address 0x070f
4926 * controls the L0s/L1 entrance latency. We try standard ECAM access
4927 * first and if it fails fall back to CSI.
4929 if (pdev->cfg_size > 0x070f &&
4930 pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL)
4933 netdev_notice_once(tp->dev,
4934 "No native access to PCI extended config space, falling back to CSI\n");
4935 csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff;
4936 rtl_csi_write(tp, 0x070c, csi | val << 24);
4939 static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp)
4941 rtl_csi_access_enable(tp, 0x27);
4945 unsigned int offset;
4950 static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e,
4956 w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits;
4957 rtl_ephy_write(tp, e->offset, w);
4962 static void rtl_disable_clock_request(struct rtl8169_private *tp)
4964 pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL,
4965 PCI_EXP_LNKCTL_CLKREQ_EN);
4968 static void rtl_enable_clock_request(struct rtl8169_private *tp)
4970 pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL,
4971 PCI_EXP_LNKCTL_CLKREQ_EN);
4974 static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable)
4978 data = RTL_R8(tp, Config3);
4983 data &= ~Rdy_to_L23;
4985 RTL_W8(tp, Config3, data);
4988 static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable)
4991 RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn);
4992 RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en);
4994 RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
4995 RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
4999 static void rtl_hw_start_8168bb(struct rtl8169_private *tp)
5001 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5003 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5004 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5006 if (tp->dev->mtu <= ETH_DATA_LEN) {
5007 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B |
5008 PCI_EXP_DEVCTL_NOSNOOP_EN);
5012 static void rtl_hw_start_8168bef(struct rtl8169_private *tp)
5014 rtl_hw_start_8168bb(tp);
5016 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5018 RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
5021 static void __rtl_hw_start_8168cp(struct rtl8169_private *tp)
5023 RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down);
5025 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5027 if (tp->dev->mtu <= ETH_DATA_LEN)
5028 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5030 rtl_disable_clock_request(tp);
5032 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5033 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5036 static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp)
5038 static const struct ephy_info e_info_8168cp[] = {
5039 { 0x01, 0, 0x0001 },
5040 { 0x02, 0x0800, 0x1000 },
5041 { 0x03, 0, 0x0042 },
5042 { 0x06, 0x0080, 0x0000 },
5046 rtl_set_def_aspm_entry_latency(tp);
5048 rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp));
5050 __rtl_hw_start_8168cp(tp);
5053 static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp)
5055 rtl_set_def_aspm_entry_latency(tp);
5057 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5059 if (tp->dev->mtu <= ETH_DATA_LEN)
5060 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5062 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5063 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5066 static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp)
5068 rtl_set_def_aspm_entry_latency(tp);
5070 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5073 RTL_W8(tp, DBG_REG, 0x20);
5075 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5077 if (tp->dev->mtu <= ETH_DATA_LEN)
5078 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5080 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5081 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5084 static void rtl_hw_start_8168c_1(struct rtl8169_private *tp)
5086 static const struct ephy_info e_info_8168c_1[] = {
5087 { 0x02, 0x0800, 0x1000 },
5088 { 0x03, 0, 0x0002 },
5089 { 0x06, 0x0080, 0x0000 }
5092 rtl_set_def_aspm_entry_latency(tp);
5094 RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2);
5096 rtl_ephy_init(tp, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1));
5098 __rtl_hw_start_8168cp(tp);
5101 static void rtl_hw_start_8168c_2(struct rtl8169_private *tp)
5103 static const struct ephy_info e_info_8168c_2[] = {
5104 { 0x01, 0, 0x0001 },
5105 { 0x03, 0x0400, 0x0220 }
5108 rtl_set_def_aspm_entry_latency(tp);
5110 rtl_ephy_init(tp, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2));
5112 __rtl_hw_start_8168cp(tp);
5115 static void rtl_hw_start_8168c_3(struct rtl8169_private *tp)
5117 rtl_hw_start_8168c_2(tp);
5120 static void rtl_hw_start_8168c_4(struct rtl8169_private *tp)
5122 rtl_set_def_aspm_entry_latency(tp);
5124 __rtl_hw_start_8168cp(tp);
5127 static void rtl_hw_start_8168d(struct rtl8169_private *tp)
5129 rtl_set_def_aspm_entry_latency(tp);
5131 rtl_disable_clock_request(tp);
5133 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5135 if (tp->dev->mtu <= ETH_DATA_LEN)
5136 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5138 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5139 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5142 static void rtl_hw_start_8168dp(struct rtl8169_private *tp)
5144 rtl_set_def_aspm_entry_latency(tp);
5146 if (tp->dev->mtu <= ETH_DATA_LEN)
5147 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5149 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5151 rtl_disable_clock_request(tp);
5154 static void rtl_hw_start_8168d_4(struct rtl8169_private *tp)
5156 static const struct ephy_info e_info_8168d_4[] = {
5157 { 0x0b, 0x0000, 0x0048 },
5158 { 0x19, 0x0020, 0x0050 },
5159 { 0x0c, 0x0100, 0x0020 }
5162 rtl_set_def_aspm_entry_latency(tp);
5164 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5166 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5168 rtl_ephy_init(tp, e_info_8168d_4, ARRAY_SIZE(e_info_8168d_4));
5170 rtl_enable_clock_request(tp);
5173 static void rtl_hw_start_8168e_1(struct rtl8169_private *tp)
5175 static const struct ephy_info e_info_8168e_1[] = {
5176 { 0x00, 0x0200, 0x0100 },
5177 { 0x00, 0x0000, 0x0004 },
5178 { 0x06, 0x0002, 0x0001 },
5179 { 0x06, 0x0000, 0x0030 },
5180 { 0x07, 0x0000, 0x2000 },
5181 { 0x00, 0x0000, 0x0020 },
5182 { 0x03, 0x5800, 0x2000 },
5183 { 0x03, 0x0000, 0x0001 },
5184 { 0x01, 0x0800, 0x1000 },
5185 { 0x07, 0x0000, 0x4000 },
5186 { 0x1e, 0x0000, 0x2000 },
5187 { 0x19, 0xffff, 0xfe6c },
5188 { 0x0a, 0x0000, 0x0040 }
5191 rtl_set_def_aspm_entry_latency(tp);
5193 rtl_ephy_init(tp, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1));
5195 if (tp->dev->mtu <= ETH_DATA_LEN)
5196 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5198 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5200 rtl_disable_clock_request(tp);
5202 /* Reset tx FIFO pointer */
5203 RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST);
5204 RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST);
5206 RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
5209 static void rtl_hw_start_8168e_2(struct rtl8169_private *tp)
5211 static const struct ephy_info e_info_8168e_2[] = {
5212 { 0x09, 0x0000, 0x0080 },
5213 { 0x19, 0x0000, 0x0224 }
5216 rtl_set_def_aspm_entry_latency(tp);
5218 rtl_ephy_init(tp, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2));
5220 if (tp->dev->mtu <= ETH_DATA_LEN)
5221 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5223 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5224 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5225 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC);
5226 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC);
5227 rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC);
5228 rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC);
5229 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC);
5230 rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC);
5232 RTL_W8(tp, MaxTxPacketSize, EarlySize);
5234 rtl_disable_clock_request(tp);
5236 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5237 RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
5239 /* Adjust EEE LED frequency */
5240 RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
5242 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
5243 RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN);
5244 RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
5246 rtl_hw_aspm_clkreq_enable(tp, true);
5249 static void rtl_hw_start_8168f(struct rtl8169_private *tp)
5251 rtl_set_def_aspm_entry_latency(tp);
5253 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5255 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5256 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5257 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC);
5258 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC);
5259 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
5260 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
5261 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC);
5262 rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC);
5263 rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC);
5264 rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC);
5266 RTL_W8(tp, MaxTxPacketSize, EarlySize);
5268 rtl_disable_clock_request(tp);
5270 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5271 RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
5272 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
5273 RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN);
5274 RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en);
5277 static void rtl_hw_start_8168f_1(struct rtl8169_private *tp)
5279 static const struct ephy_info e_info_8168f_1[] = {
5280 { 0x06, 0x00c0, 0x0020 },
5281 { 0x08, 0x0001, 0x0002 },
5282 { 0x09, 0x0000, 0x0080 },
5283 { 0x19, 0x0000, 0x0224 }
5286 rtl_hw_start_8168f(tp);
5288 rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1));
5290 rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC);
5292 /* Adjust EEE LED frequency */
5293 RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
5296 static void rtl_hw_start_8411(struct rtl8169_private *tp)
5298 static const struct ephy_info e_info_8168f_1[] = {
5299 { 0x06, 0x00c0, 0x0020 },
5300 { 0x0f, 0xffff, 0x5200 },
5301 { 0x1e, 0x0000, 0x4000 },
5302 { 0x19, 0x0000, 0x0224 }
5305 rtl_hw_start_8168f(tp);
5306 rtl_pcie_state_l2l3_enable(tp, false);
5308 rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1));
5310 rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC);
5313 static void rtl_hw_start_8168g(struct rtl8169_private *tp)
5315 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5317 rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC);
5318 rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC);
5319 rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC);
5320 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC);
5322 rtl_set_def_aspm_entry_latency(tp);
5324 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5326 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
5327 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
5328 rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC);
5330 RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
5331 RTL_W8(tp, MaxTxPacketSize, EarlySize);
5333 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5334 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5336 /* Adjust EEE LED frequency */
5337 RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
5339 rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC);
5340 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC);
5342 rtl_pcie_state_l2l3_enable(tp, false);
5345 static void rtl_hw_start_8168g_1(struct rtl8169_private *tp)
5347 static const struct ephy_info e_info_8168g_1[] = {
5348 { 0x00, 0x0000, 0x0008 },
5349 { 0x0c, 0x37d0, 0x0820 },
5350 { 0x1e, 0x0000, 0x0001 },
5351 { 0x19, 0x8000, 0x0000 }
5354 rtl_hw_start_8168g(tp);
5356 /* disable aspm and clock request before access ephy */
5357 rtl_hw_aspm_clkreq_enable(tp, false);
5358 rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1));
5359 rtl_hw_aspm_clkreq_enable(tp, true);
5362 static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
5364 static const struct ephy_info e_info_8168g_2[] = {
5365 { 0x00, 0x0000, 0x0008 },
5366 { 0x0c, 0x3df0, 0x0200 },
5367 { 0x19, 0xffff, 0xfc00 },
5368 { 0x1e, 0xffff, 0x20eb }
5371 rtl_hw_start_8168g(tp);
5373 /* disable aspm and clock request before access ephy */
5374 RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn);
5375 RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en);
5376 rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2));
5379 static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
5381 static const struct ephy_info e_info_8411_2[] = {
5382 { 0x00, 0x0000, 0x0008 },
5383 { 0x0c, 0x3df0, 0x0200 },
5384 { 0x0f, 0xffff, 0x5200 },
5385 { 0x19, 0x0020, 0x0000 },
5386 { 0x1e, 0x0000, 0x2000 }
5389 rtl_hw_start_8168g(tp);
5391 /* disable aspm and clock request before access ephy */
5392 rtl_hw_aspm_clkreq_enable(tp, false);
5393 rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2));
5394 rtl_hw_aspm_clkreq_enable(tp, true);
5397 static void rtl_hw_start_8168h_1(struct rtl8169_private *tp)
5401 static const struct ephy_info e_info_8168h_1[] = {
5402 { 0x1e, 0x0800, 0x0001 },
5403 { 0x1d, 0x0000, 0x0800 },
5404 { 0x05, 0xffff, 0x2089 },
5405 { 0x06, 0xffff, 0x5881 },
5406 { 0x04, 0xffff, 0x154a },
5407 { 0x01, 0xffff, 0x068b }
5410 /* disable aspm and clock request before access ephy */
5411 rtl_hw_aspm_clkreq_enable(tp, false);
5412 rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1));
5414 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5416 rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC);
5417 rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC);
5418 rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC);
5419 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC);
5421 rtl_set_def_aspm_entry_latency(tp);
5423 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5425 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
5426 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
5428 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_1111, 0x0010, 0x00, ERIAR_EXGMAC);
5430 rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f00, 0x00, ERIAR_EXGMAC);
5432 rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC);
5434 RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
5435 RTL_W8(tp, MaxTxPacketSize, EarlySize);
5437 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5438 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5440 /* Adjust EEE LED frequency */
5441 RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
5443 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
5444 RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
5446 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN);
5448 rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC);
5450 rtl_pcie_state_l2l3_enable(tp, false);
5452 rtl_writephy(tp, 0x1f, 0x0c42);
5453 rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff);
5454 rtl_writephy(tp, 0x1f, 0x0000);
5455 if (rg_saw_cnt > 0) {
5458 sw_cnt_1ms_ini = 16000000/rg_saw_cnt;
5459 sw_cnt_1ms_ini &= 0x0fff;
5460 data = r8168_mac_ocp_read(tp, 0xd412);
5462 data |= sw_cnt_1ms_ini;
5463 r8168_mac_ocp_write(tp, 0xd412, data);
5466 data = r8168_mac_ocp_read(tp, 0xe056);
5469 r8168_mac_ocp_write(tp, 0xe056, data);
5471 data = r8168_mac_ocp_read(tp, 0xe052);
5474 r8168_mac_ocp_write(tp, 0xe052, data);
5476 data = r8168_mac_ocp_read(tp, 0xe0d6);
5479 r8168_mac_ocp_write(tp, 0xe0d6, data);
5481 data = r8168_mac_ocp_read(tp, 0xd420);
5484 r8168_mac_ocp_write(tp, 0xd420, data);
5486 r8168_mac_ocp_write(tp, 0xe63e, 0x0001);
5487 r8168_mac_ocp_write(tp, 0xe63e, 0x0000);
5488 r8168_mac_ocp_write(tp, 0xc094, 0x0000);
5489 r8168_mac_ocp_write(tp, 0xc09e, 0x0000);
5491 rtl_hw_aspm_clkreq_enable(tp, true);
5494 static void rtl_hw_start_8168ep(struct rtl8169_private *tp)
5496 rtl8168ep_stop_cmac(tp);
5498 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5500 rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC);
5501 rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC);
5502 rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC);
5503 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC);
5505 rtl_set_def_aspm_entry_latency(tp);
5507 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5509 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
5510 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
5512 rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC);
5514 rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC);
5516 RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN);
5517 RTL_W8(tp, MaxTxPacketSize, EarlySize);
5519 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5520 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5522 /* Adjust EEE LED frequency */
5523 RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07);
5525 rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC);
5527 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN);
5529 rtl_pcie_state_l2l3_enable(tp, false);
5532 static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp)
5534 static const struct ephy_info e_info_8168ep_1[] = {
5535 { 0x00, 0xffff, 0x10ab },
5536 { 0x06, 0xffff, 0xf030 },
5537 { 0x08, 0xffff, 0x2006 },
5538 { 0x0d, 0xffff, 0x1666 },
5539 { 0x0c, 0x3ff0, 0x0000 }
5542 /* disable aspm and clock request before access ephy */
5543 rtl_hw_aspm_clkreq_enable(tp, false);
5544 rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1));
5546 rtl_hw_start_8168ep(tp);
5548 rtl_hw_aspm_clkreq_enable(tp, true);
5551 static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp)
5553 static const struct ephy_info e_info_8168ep_2[] = {
5554 { 0x00, 0xffff, 0x10a3 },
5555 { 0x19, 0xffff, 0xfc00 },
5556 { 0x1e, 0xffff, 0x20ea }
5559 /* disable aspm and clock request before access ephy */
5560 rtl_hw_aspm_clkreq_enable(tp, false);
5561 rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2));
5563 rtl_hw_start_8168ep(tp);
5565 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
5566 RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
5568 rtl_hw_aspm_clkreq_enable(tp, true);
5571 static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp)
5574 static const struct ephy_info e_info_8168ep_3[] = {
5575 { 0x00, 0xffff, 0x10a3 },
5576 { 0x19, 0xffff, 0x7c00 },
5577 { 0x1e, 0xffff, 0x20eb },
5578 { 0x0d, 0xffff, 0x1666 }
5581 /* disable aspm and clock request before access ephy */
5582 rtl_hw_aspm_clkreq_enable(tp, false);
5583 rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3));
5585 rtl_hw_start_8168ep(tp);
5587 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
5588 RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN);
5590 data = r8168_mac_ocp_read(tp, 0xd3e2);
5593 r8168_mac_ocp_write(tp, 0xd3e2, data);
5595 data = r8168_mac_ocp_read(tp, 0xd3e4);
5597 r8168_mac_ocp_write(tp, 0xd3e4, data);
5599 data = r8168_mac_ocp_read(tp, 0xe860);
5601 r8168_mac_ocp_write(tp, 0xe860, data);
5603 rtl_hw_aspm_clkreq_enable(tp, true);
5606 static void rtl_hw_start_8168(struct rtl8169_private *tp)
5608 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5610 tp->cp_cmd &= ~INTT_MASK;
5611 tp->cp_cmd |= PktCntrDisable | INTT_1;
5612 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5614 RTL_W16(tp, IntrMitigate, 0x5151);
5616 /* Work around for RxFIFO overflow. */
5617 if (tp->mac_version == RTL_GIGA_MAC_VER_11) {
5618 tp->event_slow |= RxFIFOOver | PCSTimeout;
5619 tp->event_slow &= ~RxOverflow;
5622 switch (tp->mac_version) {
5623 case RTL_GIGA_MAC_VER_11:
5624 rtl_hw_start_8168bb(tp);
5627 case RTL_GIGA_MAC_VER_12:
5628 case RTL_GIGA_MAC_VER_17:
5629 rtl_hw_start_8168bef(tp);
5632 case RTL_GIGA_MAC_VER_18:
5633 rtl_hw_start_8168cp_1(tp);
5636 case RTL_GIGA_MAC_VER_19:
5637 rtl_hw_start_8168c_1(tp);
5640 case RTL_GIGA_MAC_VER_20:
5641 rtl_hw_start_8168c_2(tp);
5644 case RTL_GIGA_MAC_VER_21:
5645 rtl_hw_start_8168c_3(tp);
5648 case RTL_GIGA_MAC_VER_22:
5649 rtl_hw_start_8168c_4(tp);
5652 case RTL_GIGA_MAC_VER_23:
5653 rtl_hw_start_8168cp_2(tp);
5656 case RTL_GIGA_MAC_VER_24:
5657 rtl_hw_start_8168cp_3(tp);
5660 case RTL_GIGA_MAC_VER_25:
5661 case RTL_GIGA_MAC_VER_26:
5662 case RTL_GIGA_MAC_VER_27:
5663 rtl_hw_start_8168d(tp);
5666 case RTL_GIGA_MAC_VER_28:
5667 rtl_hw_start_8168d_4(tp);
5670 case RTL_GIGA_MAC_VER_31:
5671 rtl_hw_start_8168dp(tp);
5674 case RTL_GIGA_MAC_VER_32:
5675 case RTL_GIGA_MAC_VER_33:
5676 rtl_hw_start_8168e_1(tp);
5678 case RTL_GIGA_MAC_VER_34:
5679 rtl_hw_start_8168e_2(tp);
5682 case RTL_GIGA_MAC_VER_35:
5683 case RTL_GIGA_MAC_VER_36:
5684 rtl_hw_start_8168f_1(tp);
5687 case RTL_GIGA_MAC_VER_38:
5688 rtl_hw_start_8411(tp);
5691 case RTL_GIGA_MAC_VER_40:
5692 case RTL_GIGA_MAC_VER_41:
5693 rtl_hw_start_8168g_1(tp);
5695 case RTL_GIGA_MAC_VER_42:
5696 rtl_hw_start_8168g_2(tp);
5699 case RTL_GIGA_MAC_VER_44:
5700 rtl_hw_start_8411_2(tp);
5703 case RTL_GIGA_MAC_VER_45:
5704 case RTL_GIGA_MAC_VER_46:
5705 rtl_hw_start_8168h_1(tp);
5708 case RTL_GIGA_MAC_VER_49:
5709 rtl_hw_start_8168ep_1(tp);
5712 case RTL_GIGA_MAC_VER_50:
5713 rtl_hw_start_8168ep_2(tp);
5716 case RTL_GIGA_MAC_VER_51:
5717 rtl_hw_start_8168ep_3(tp);
5721 netif_err(tp, drv, tp->dev,
5722 "unknown chipset (mac_version = %d)\n",
5728 static void rtl_hw_start_8102e_1(struct rtl8169_private *tp)
5730 static const struct ephy_info e_info_8102e_1[] = {
5731 { 0x01, 0, 0x6e65 },
5732 { 0x02, 0, 0x091f },
5733 { 0x03, 0, 0xc2f9 },
5734 { 0x06, 0, 0xafb5 },
5735 { 0x07, 0, 0x0e00 },
5736 { 0x19, 0, 0xec80 },
5737 { 0x01, 0, 0x2e65 },
5742 rtl_set_def_aspm_entry_latency(tp);
5744 RTL_W8(tp, DBG_REG, FIX_NAK_1);
5746 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5749 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable);
5750 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5752 cfg1 = RTL_R8(tp, Config1);
5753 if ((cfg1 & LEDS0) && (cfg1 & LEDS1))
5754 RTL_W8(tp, Config1, cfg1 & ~LEDS0);
5756 rtl_ephy_init(tp, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1));
5759 static void rtl_hw_start_8102e_2(struct rtl8169_private *tp)
5761 rtl_set_def_aspm_entry_latency(tp);
5763 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5765 RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable);
5766 RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en);
5769 static void rtl_hw_start_8102e_3(struct rtl8169_private *tp)
5771 rtl_hw_start_8102e_2(tp);
5773 rtl_ephy_write(tp, 0x03, 0xc2f9);
5776 static void rtl_hw_start_8105e_1(struct rtl8169_private *tp)
5778 static const struct ephy_info e_info_8105e_1[] = {
5779 { 0x07, 0, 0x4000 },
5780 { 0x19, 0, 0x0200 },
5781 { 0x19, 0, 0x0020 },
5782 { 0x1e, 0, 0x2000 },
5783 { 0x03, 0, 0x0001 },
5784 { 0x19, 0, 0x0100 },
5785 { 0x19, 0, 0x0004 },
5789 /* Force LAN exit from ASPM if Rx/Tx are not idle */
5790 RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
5792 /* Disable Early Tally Counter */
5793 RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000);
5795 RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET);
5796 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN);
5798 rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1));
5800 rtl_pcie_state_l2l3_enable(tp, false);
5803 static void rtl_hw_start_8105e_2(struct rtl8169_private *tp)
5805 rtl_hw_start_8105e_1(tp);
5806 rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000);
5809 static void rtl_hw_start_8402(struct rtl8169_private *tp)
5811 static const struct ephy_info e_info_8402[] = {
5812 { 0x19, 0xffff, 0xff64 },
5816 rtl_set_def_aspm_entry_latency(tp);
5818 /* Force LAN exit from ASPM if Rx/Tx are not idle */
5819 RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
5821 RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO);
5822 RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
5824 rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402));
5826 rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B);
5828 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC);
5829 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC);
5830 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC);
5831 rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC);
5832 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5833 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC);
5834 rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC);
5836 rtl_pcie_state_l2l3_enable(tp, false);
5839 static void rtl_hw_start_8106(struct rtl8169_private *tp)
5841 /* Force LAN exit from ASPM if Rx/Tx are not idle */
5842 RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800);
5844 RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN);
5845 RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET);
5846 RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN);
5848 rtl_pcie_state_l2l3_enable(tp, false);
5851 static void rtl_hw_start_8101(struct rtl8169_private *tp)
5853 if (tp->mac_version >= RTL_GIGA_MAC_VER_30)
5854 tp->event_slow &= ~RxFIFOOver;
5856 if (tp->mac_version == RTL_GIGA_MAC_VER_13 ||
5857 tp->mac_version == RTL_GIGA_MAC_VER_16)
5858 pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL,
5859 PCI_EXP_DEVCTL_NOSNOOP_EN);
5861 RTL_W8(tp, MaxTxPacketSize, TxPacketMax);
5863 tp->cp_cmd &= CPCMD_QUIRK_MASK;
5864 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
5866 switch (tp->mac_version) {
5867 case RTL_GIGA_MAC_VER_07:
5868 rtl_hw_start_8102e_1(tp);
5871 case RTL_GIGA_MAC_VER_08:
5872 rtl_hw_start_8102e_3(tp);
5875 case RTL_GIGA_MAC_VER_09:
5876 rtl_hw_start_8102e_2(tp);
5879 case RTL_GIGA_MAC_VER_29:
5880 rtl_hw_start_8105e_1(tp);
5882 case RTL_GIGA_MAC_VER_30:
5883 rtl_hw_start_8105e_2(tp);
5886 case RTL_GIGA_MAC_VER_37:
5887 rtl_hw_start_8402(tp);
5890 case RTL_GIGA_MAC_VER_39:
5891 rtl_hw_start_8106(tp);
5893 case RTL_GIGA_MAC_VER_43:
5894 rtl_hw_start_8168g_2(tp);
5896 case RTL_GIGA_MAC_VER_47:
5897 case RTL_GIGA_MAC_VER_48:
5898 rtl_hw_start_8168h_1(tp);
5902 RTL_W16(tp, IntrMitigate, 0x0000);
5905 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
5907 struct rtl8169_private *tp = netdev_priv(dev);
5909 if (new_mtu > ETH_DATA_LEN)
5910 rtl_hw_jumbo_enable(tp);
5912 rtl_hw_jumbo_disable(tp);
5915 netdev_update_features(dev);
5920 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
5922 desc->addr = cpu_to_le64(0x0badbadbadbadbadull);
5923 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask);
5926 static void rtl8169_free_rx_databuff(struct rtl8169_private *tp,
5927 void **data_buff, struct RxDesc *desc)
5929 dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr),
5930 R8169_RX_BUF_SIZE, DMA_FROM_DEVICE);
5934 rtl8169_make_unusable_by_asic(desc);
5937 static inline void rtl8169_mark_to_asic(struct RxDesc *desc)
5939 u32 eor = le32_to_cpu(desc->opts1) & RingEnd;
5941 /* Force memory writes to complete before releasing descriptor */
5944 desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE);
5947 static inline void *rtl8169_align(void *data)
5949 return (void *)ALIGN((long)data, 16);
5952 static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
5953 struct RxDesc *desc)
5957 struct device *d = tp_to_dev(tp);
5958 int node = dev_to_node(d);
5960 data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node);
5964 if (rtl8169_align(data) != data) {
5966 data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node);
5971 mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE,
5973 if (unlikely(dma_mapping_error(d, mapping))) {
5974 if (net_ratelimit())
5975 netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
5979 desc->addr = cpu_to_le64(mapping);
5980 rtl8169_mark_to_asic(desc);
5988 static void rtl8169_rx_clear(struct rtl8169_private *tp)
5992 for (i = 0; i < NUM_RX_DESC; i++) {
5993 if (tp->Rx_databuff[i]) {
5994 rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i,
5995 tp->RxDescArray + i);
6000 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc)
6002 desc->opts1 |= cpu_to_le32(RingEnd);
6005 static int rtl8169_rx_fill(struct rtl8169_private *tp)
6009 for (i = 0; i < NUM_RX_DESC; i++) {
6012 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i);
6014 rtl8169_make_unusable_by_asic(tp->RxDescArray + i);
6017 tp->Rx_databuff[i] = data;
6020 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
6024 rtl8169_rx_clear(tp);
6028 static int rtl8169_init_ring(struct rtl8169_private *tp)
6030 rtl8169_init_ring_indexes(tp);
6032 memset(tp->tx_skb, 0, sizeof(tp->tx_skb));
6033 memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff));
6035 return rtl8169_rx_fill(tp);
6038 static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb,
6039 struct TxDesc *desc)
6041 unsigned int len = tx_skb->len;
6043 dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE);
6051 static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start,
6056 for (i = 0; i < n; i++) {
6057 unsigned int entry = (start + i) % NUM_TX_DESC;
6058 struct ring_info *tx_skb = tp->tx_skb + entry;
6059 unsigned int len = tx_skb->len;
6062 struct sk_buff *skb = tx_skb->skb;
6064 rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb,
6065 tp->TxDescArray + entry);
6067 dev_consume_skb_any(skb);
6074 static void rtl8169_tx_clear(struct rtl8169_private *tp)
6076 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC);
6077 tp->cur_tx = tp->dirty_tx = 0;
6080 static void rtl_reset_work(struct rtl8169_private *tp)
6082 struct net_device *dev = tp->dev;
6085 napi_disable(&tp->napi);
6086 netif_stop_queue(dev);
6087 synchronize_sched();
6089 rtl8169_hw_reset(tp);
6091 for (i = 0; i < NUM_RX_DESC; i++)
6092 rtl8169_mark_to_asic(tp->RxDescArray + i);
6094 rtl8169_tx_clear(tp);
6095 rtl8169_init_ring_indexes(tp);
6097 napi_enable(&tp->napi);
6099 netif_wake_queue(dev);
6102 static void rtl8169_tx_timeout(struct net_device *dev)
6104 struct rtl8169_private *tp = netdev_priv(dev);
6106 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
6109 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
6112 struct skb_shared_info *info = skb_shinfo(skb);
6113 unsigned int cur_frag, entry;
6114 struct TxDesc *uninitialized_var(txd);
6115 struct device *d = tp_to_dev(tp);
6118 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
6119 const skb_frag_t *frag = info->frags + cur_frag;
6124 entry = (entry + 1) % NUM_TX_DESC;
6126 txd = tp->TxDescArray + entry;
6127 len = skb_frag_size(frag);
6128 addr = skb_frag_address(frag);
6129 mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE);
6130 if (unlikely(dma_mapping_error(d, mapping))) {
6131 if (net_ratelimit())
6132 netif_err(tp, drv, tp->dev,
6133 "Failed to map TX fragments DMA!\n");
6137 /* Anti gcc 2.95.3 bugware (sic) */
6138 status = opts[0] | len |
6139 (RingEnd * !((entry + 1) % NUM_TX_DESC));
6141 txd->opts1 = cpu_to_le32(status);
6142 txd->opts2 = cpu_to_le32(opts[1]);
6143 txd->addr = cpu_to_le64(mapping);
6145 tp->tx_skb[entry].len = len;
6149 tp->tx_skb[entry].skb = skb;
6150 txd->opts1 |= cpu_to_le32(LastFrag);
6156 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag);
6160 static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb)
6162 return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34;
6165 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
6166 struct net_device *dev);
6167 /* r8169_csum_workaround()
6168 * The hw limites the value the transport offset. When the offset is out of the
6169 * range, calculate the checksum by sw.
6171 static void r8169_csum_workaround(struct rtl8169_private *tp,
6172 struct sk_buff *skb)
6174 if (skb_shinfo(skb)->gso_size) {
6175 netdev_features_t features = tp->dev->features;
6176 struct sk_buff *segs, *nskb;
6178 features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6);
6179 segs = skb_gso_segment(skb, features);
6180 if (IS_ERR(segs) || !segs)
6187 rtl8169_start_xmit(nskb, tp->dev);
6190 dev_consume_skb_any(skb);
6191 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
6192 if (skb_checksum_help(skb) < 0)
6195 rtl8169_start_xmit(skb, tp->dev);
6197 struct net_device_stats *stats;
6200 stats = &tp->dev->stats;
6201 stats->tx_dropped++;
6202 dev_kfree_skb_any(skb);
6206 /* msdn_giant_send_check()
6207 * According to the document of microsoft, the TCP Pseudo Header excludes the
6208 * packet length for IPv6 TCP large packets.
6210 static int msdn_giant_send_check(struct sk_buff *skb)
6212 const struct ipv6hdr *ipv6h;
6216 ret = skb_cow_head(skb, 0);
6220 ipv6h = ipv6_hdr(skb);
6224 th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
6229 static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp,
6230 struct sk_buff *skb, u32 *opts)
6232 u32 mss = skb_shinfo(skb)->gso_size;
6236 opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT;
6237 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
6238 const struct iphdr *ip = ip_hdr(skb);
6240 if (ip->protocol == IPPROTO_TCP)
6241 opts[0] |= TD0_IP_CS | TD0_TCP_CS;
6242 else if (ip->protocol == IPPROTO_UDP)
6243 opts[0] |= TD0_IP_CS | TD0_UDP_CS;
6251 static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
6252 struct sk_buff *skb, u32 *opts)
6254 u32 transport_offset = (u32)skb_transport_offset(skb);
6255 u32 mss = skb_shinfo(skb)->gso_size;
6258 if (transport_offset > GTTCPHO_MAX) {
6259 netif_warn(tp, tx_err, tp->dev,
6260 "Invalid transport offset 0x%x for TSO\n",
6265 switch (vlan_get_protocol(skb)) {
6266 case htons(ETH_P_IP):
6267 opts[0] |= TD1_GTSENV4;
6270 case htons(ETH_P_IPV6):
6271 if (msdn_giant_send_check(skb))
6274 opts[0] |= TD1_GTSENV6;
6282 opts[0] |= transport_offset << GTTCPHO_SHIFT;
6283 opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT;
6284 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
6287 if (unlikely(rtl_test_hw_pad_bug(tp, skb)))
6288 return !(skb_checksum_help(skb) || eth_skb_pad(skb));
6290 if (transport_offset > TCPHO_MAX) {
6291 netif_warn(tp, tx_err, tp->dev,
6292 "Invalid transport offset 0x%x\n",
6297 switch (vlan_get_protocol(skb)) {
6298 case htons(ETH_P_IP):
6299 opts[1] |= TD1_IPv4_CS;
6300 ip_protocol = ip_hdr(skb)->protocol;
6303 case htons(ETH_P_IPV6):
6304 opts[1] |= TD1_IPv6_CS;
6305 ip_protocol = ipv6_hdr(skb)->nexthdr;
6309 ip_protocol = IPPROTO_RAW;
6313 if (ip_protocol == IPPROTO_TCP)
6314 opts[1] |= TD1_TCP_CS;
6315 else if (ip_protocol == IPPROTO_UDP)
6316 opts[1] |= TD1_UDP_CS;
6320 opts[1] |= transport_offset << TCPHO_SHIFT;
6322 if (unlikely(rtl_test_hw_pad_bug(tp, skb)))
6323 return !eth_skb_pad(skb);
6329 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
6330 struct net_device *dev)
6332 struct rtl8169_private *tp = netdev_priv(dev);
6333 unsigned int entry = tp->cur_tx % NUM_TX_DESC;
6334 struct TxDesc *txd = tp->TxDescArray + entry;
6335 struct device *d = tp_to_dev(tp);
6341 if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
6342 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
6346 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn))
6349 opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb));
6352 if (!tp->tso_csum(tp, skb, opts)) {
6353 r8169_csum_workaround(tp, skb);
6354 return NETDEV_TX_OK;
6357 len = skb_headlen(skb);
6358 mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE);
6359 if (unlikely(dma_mapping_error(d, mapping))) {
6360 if (net_ratelimit())
6361 netif_err(tp, drv, dev, "Failed to map TX DMA!\n");
6365 tp->tx_skb[entry].len = len;
6366 txd->addr = cpu_to_le64(mapping);
6368 frags = rtl8169_xmit_frags(tp, skb, opts);
6372 opts[0] |= FirstFrag;
6374 opts[0] |= FirstFrag | LastFrag;
6375 tp->tx_skb[entry].skb = skb;
6378 txd->opts2 = cpu_to_le32(opts[1]);
6380 skb_tx_timestamp(skb);
6382 /* Force memory writes to complete before releasing descriptor */
6385 /* Anti gcc 2.95.3 bugware (sic) */
6386 status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
6387 txd->opts1 = cpu_to_le32(status);
6389 /* Force all memory writes to complete before notifying device */
6392 tp->cur_tx += frags + 1;
6394 RTL_W8(tp, TxPoll, NPQ);
6398 if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
6399 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
6400 * not miss a ring update when it notices a stopped queue.
6403 netif_stop_queue(dev);
6404 /* Sync with rtl_tx:
6405 * - publish queue status and cur_tx ring index (write barrier)
6406 * - refresh dirty_tx ring index (read barrier).
6407 * May the current thread have a pessimistic view of the ring
6408 * status and forget to wake up queue, a racing rtl_tx thread
6412 if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
6413 netif_wake_queue(dev);
6416 return NETDEV_TX_OK;
6419 rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd);
6421 dev_kfree_skb_any(skb);
6422 dev->stats.tx_dropped++;
6423 return NETDEV_TX_OK;
6426 netif_stop_queue(dev);
6427 dev->stats.tx_dropped++;
6428 return NETDEV_TX_BUSY;
6431 static void rtl8169_pcierr_interrupt(struct net_device *dev)
6433 struct rtl8169_private *tp = netdev_priv(dev);
6434 struct pci_dev *pdev = tp->pci_dev;
6435 u16 pci_status, pci_cmd;
6437 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd);
6438 pci_read_config_word(pdev, PCI_STATUS, &pci_status);
6440 netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n",
6441 pci_cmd, pci_status);
6444 * The recovery sequence below admits a very elaborated explanation:
6445 * - it seems to work;
6446 * - I did not see what else could be done;
6447 * - it makes iop3xx happy.
6449 * Feel free to adjust to your needs.
6451 if (pdev->broken_parity_status)
6452 pci_cmd &= ~PCI_COMMAND_PARITY;
6454 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
6456 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd);
6458 pci_write_config_word(pdev, PCI_STATUS,
6459 pci_status & (PCI_STATUS_DETECTED_PARITY |
6460 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT |
6461 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT));
6463 /* The infamous DAC f*ckup only happens at boot time */
6464 if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) {
6465 netif_info(tp, intr, dev, "disabling PCI DAC\n");
6466 tp->cp_cmd &= ~PCIDAC;
6467 RTL_W16(tp, CPlusCmd, tp->cp_cmd);
6468 dev->features &= ~NETIF_F_HIGHDMA;
6471 rtl8169_hw_reset(tp);
6473 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
6476 static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
6478 unsigned int dirty_tx, tx_left;
6480 dirty_tx = tp->dirty_tx;
6482 tx_left = tp->cur_tx - dirty_tx;
6484 while (tx_left > 0) {
6485 unsigned int entry = dirty_tx % NUM_TX_DESC;
6486 struct ring_info *tx_skb = tp->tx_skb + entry;
6489 status = le32_to_cpu(tp->TxDescArray[entry].opts1);
6490 if (status & DescOwn)
6493 /* This barrier is needed to keep us from reading
6494 * any other fields out of the Tx descriptor until
6495 * we know the status of DescOwn
6499 rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb,
6500 tp->TxDescArray + entry);
6501 if (status & LastFrag) {
6502 u64_stats_update_begin(&tp->tx_stats.syncp);
6503 tp->tx_stats.packets++;
6504 tp->tx_stats.bytes += tx_skb->skb->len;
6505 u64_stats_update_end(&tp->tx_stats.syncp);
6506 dev_consume_skb_any(tx_skb->skb);
6513 if (tp->dirty_tx != dirty_tx) {
6514 tp->dirty_tx = dirty_tx;
6515 /* Sync with rtl8169_start_xmit:
6516 * - publish dirty_tx ring index (write barrier)
6517 * - refresh cur_tx ring index and queue status (read barrier)
6518 * May the current thread miss the stopped queue condition,
6519 * a racing xmit thread can only have a right view of the
6523 if (netif_queue_stopped(dev) &&
6524 TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
6525 netif_wake_queue(dev);
6528 * 8168 hack: TxPoll requests are lost when the Tx packets are
6529 * too close. Let's kick an extra TxPoll request when a burst
6530 * of start_xmit activity is detected (if it is not detected,
6531 * it is slow enough). -- FR
6533 if (tp->cur_tx != dirty_tx)
6534 RTL_W8(tp, TxPoll, NPQ);
6538 static inline int rtl8169_fragmented_frame(u32 status)
6540 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag);
6543 static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1)
6545 u32 status = opts1 & RxProtoMask;
6547 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) ||
6548 ((status == RxProtoUDP) && !(opts1 & UDPFail)))
6549 skb->ip_summed = CHECKSUM_UNNECESSARY;
6551 skb_checksum_none_assert(skb);
6554 static struct sk_buff *rtl8169_try_rx_copy(void *data,
6555 struct rtl8169_private *tp,
6559 struct sk_buff *skb;
6560 struct device *d = tp_to_dev(tp);
6562 data = rtl8169_align(data);
6563 dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
6565 skb = napi_alloc_skb(&tp->napi, pkt_size);
6567 skb_copy_to_linear_data(skb, data, pkt_size);
6568 dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE);
6573 static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget)
6575 unsigned int cur_rx, rx_left;
6578 cur_rx = tp->cur_rx;
6580 for (rx_left = min(budget, NUM_RX_DESC); rx_left > 0; rx_left--, cur_rx++) {
6581 unsigned int entry = cur_rx % NUM_RX_DESC;
6582 struct RxDesc *desc = tp->RxDescArray + entry;
6585 status = le32_to_cpu(desc->opts1);
6586 if (status & DescOwn)
6589 /* This barrier is needed to keep us from reading
6590 * any other fields out of the Rx descriptor until
6591 * we know the status of DescOwn
6595 if (unlikely(status & RxRES)) {
6596 netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n",
6598 dev->stats.rx_errors++;
6599 if (status & (RxRWT | RxRUNT))
6600 dev->stats.rx_length_errors++;
6602 dev->stats.rx_crc_errors++;
6603 /* RxFOVF is a reserved bit on later chip versions */
6604 if (tp->mac_version == RTL_GIGA_MAC_VER_01 &&
6606 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
6607 dev->stats.rx_fifo_errors++;
6608 } else if (status & (RxRUNT | RxCRC) &&
6609 !(status & RxRWT) &&
6610 dev->features & NETIF_F_RXALL) {
6614 struct sk_buff *skb;
6619 addr = le64_to_cpu(desc->addr);
6620 if (likely(!(dev->features & NETIF_F_RXFCS)))
6621 pkt_size = (status & 0x00003fff) - 4;
6623 pkt_size = status & 0x00003fff;
6626 * The driver does not support incoming fragmented
6627 * frames. They are seen as a symptom of over-mtu
6630 if (unlikely(rtl8169_fragmented_frame(status))) {
6631 dev->stats.rx_dropped++;
6632 dev->stats.rx_length_errors++;
6633 goto release_descriptor;
6636 skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry],
6637 tp, pkt_size, addr);
6639 dev->stats.rx_dropped++;
6640 goto release_descriptor;
6643 rtl8169_rx_csum(skb, status);
6644 skb_put(skb, pkt_size);
6645 skb->protocol = eth_type_trans(skb, dev);
6647 rtl8169_rx_vlan_tag(desc, skb);
6649 if (skb->pkt_type == PACKET_MULTICAST)
6650 dev->stats.multicast++;
6652 napi_gro_receive(&tp->napi, skb);
6654 u64_stats_update_begin(&tp->rx_stats.syncp);
6655 tp->rx_stats.packets++;
6656 tp->rx_stats.bytes += pkt_size;
6657 u64_stats_update_end(&tp->rx_stats.syncp);
6661 rtl8169_mark_to_asic(desc);
6664 count = cur_rx - tp->cur_rx;
6665 tp->cur_rx = cur_rx;
6670 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
6672 struct rtl8169_private *tp = dev_instance;
6676 status = rtl_get_events(tp);
6677 if (status && status != 0xffff) {
6678 status &= RTL_EVENT_NAPI | tp->event_slow;
6682 rtl_irq_disable(tp);
6683 napi_schedule_irqoff(&tp->napi);
6686 return IRQ_RETVAL(handled);
6690 * Workqueue context.
6692 static void rtl_slow_event_work(struct rtl8169_private *tp)
6694 struct net_device *dev = tp->dev;
6697 status = rtl_get_events(tp) & tp->event_slow;
6698 rtl_ack_events(tp, status);
6700 if (unlikely(status & RxFIFOOver)) {
6701 switch (tp->mac_version) {
6702 /* Work around for rx fifo overflow */
6703 case RTL_GIGA_MAC_VER_11:
6704 netif_stop_queue(dev);
6705 /* XXX - Hack alert. See rtl_task(). */
6706 set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags);
6712 if (unlikely(status & SYSErr))
6713 rtl8169_pcierr_interrupt(dev);
6715 if (status & LinkChg)
6716 phy_mac_interrupt(dev->phydev);
6718 rtl_irq_enable_all(tp);
6721 static void rtl_task(struct work_struct *work)
6723 static const struct {
6725 void (*action)(struct rtl8169_private *);
6727 /* XXX - keep rtl_slow_event_work() as first element. */
6728 { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work },
6729 { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work },
6731 struct rtl8169_private *tp =
6732 container_of(work, struct rtl8169_private, wk.work);
6733 struct net_device *dev = tp->dev;
6738 if (!netif_running(dev) ||
6739 !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags))
6742 for (i = 0; i < ARRAY_SIZE(rtl_work); i++) {
6745 pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags);
6747 rtl_work[i].action(tp);
6751 rtl_unlock_work(tp);
6754 static int rtl8169_poll(struct napi_struct *napi, int budget)
6756 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi);
6757 struct net_device *dev = tp->dev;
6758 u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow;
6762 status = rtl_get_events(tp);
6763 rtl_ack_events(tp, status & ~tp->event_slow);
6765 if (status & RTL_EVENT_NAPI_RX)
6766 work_done = rtl_rx(dev, tp, (u32) budget);
6768 if (status & RTL_EVENT_NAPI_TX)
6771 if (status & tp->event_slow) {
6772 enable_mask &= ~tp->event_slow;
6774 rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING);
6777 if (work_done < budget) {
6778 napi_complete_done(napi, work_done);
6780 rtl_irq_enable(tp, enable_mask);
6787 static void rtl8169_rx_missed(struct net_device *dev)
6789 struct rtl8169_private *tp = netdev_priv(dev);
6791 if (tp->mac_version > RTL_GIGA_MAC_VER_06)
6794 dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff;
6795 RTL_W32(tp, RxMissed, 0);
6798 static void r8169_phylink_handler(struct net_device *ndev)
6800 struct rtl8169_private *tp = netdev_priv(ndev);
6802 if (netif_carrier_ok(ndev)) {
6803 rtl_link_chg_patch(tp);
6804 pm_request_resume(&tp->pci_dev->dev);
6806 pm_runtime_idle(&tp->pci_dev->dev);
6809 if (net_ratelimit())
6810 phy_print_status(ndev->phydev);
6813 static int r8169_phy_connect(struct rtl8169_private *tp)
6815 struct phy_device *phydev = mdiobus_get_phy(tp->mii_bus, 0);
6816 phy_interface_t phy_mode;
6819 phy_mode = tp->mii.supports_gmii ? PHY_INTERFACE_MODE_GMII :
6820 PHY_INTERFACE_MODE_MII;
6822 ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler,
6827 if (!tp->mii.supports_gmii)
6828 phy_set_max_speed(phydev, SPEED_100);
6830 /* Ensure to advertise everything, incl. pause */
6831 phydev->advertising = phydev->supported;
6833 phy_attached_info(phydev);
6838 static void rtl8169_down(struct net_device *dev)
6840 struct rtl8169_private *tp = netdev_priv(dev);
6842 phy_stop(dev->phydev);
6844 napi_disable(&tp->napi);
6845 netif_stop_queue(dev);
6847 rtl8169_hw_reset(tp);
6849 * At this point device interrupts can not be enabled in any function,
6850 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task)
6851 * and napi is disabled (rtl8169_poll).
6853 rtl8169_rx_missed(dev);
6855 /* Give a racing hard_start_xmit a few cycles to complete. */
6856 synchronize_sched();
6858 rtl8169_tx_clear(tp);
6860 rtl8169_rx_clear(tp);
6862 rtl_pll_power_down(tp);
6865 static int rtl8169_close(struct net_device *dev)
6867 struct rtl8169_private *tp = netdev_priv(dev);
6868 struct pci_dev *pdev = tp->pci_dev;
6870 pm_runtime_get_sync(&pdev->dev);
6872 /* Update counters before going down */
6873 rtl8169_update_counters(tp);
6876 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
6879 rtl_unlock_work(tp);
6881 cancel_work_sync(&tp->wk.work);
6883 phy_disconnect(dev->phydev);
6885 pci_free_irq(pdev, 0, tp);
6887 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
6889 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
6891 tp->TxDescArray = NULL;
6892 tp->RxDescArray = NULL;
6894 pm_runtime_put_sync(&pdev->dev);
6899 #ifdef CONFIG_NET_POLL_CONTROLLER
6900 static void rtl8169_netpoll(struct net_device *dev)
6902 struct rtl8169_private *tp = netdev_priv(dev);
6904 rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp);
6908 static int rtl_open(struct net_device *dev)
6910 struct rtl8169_private *tp = netdev_priv(dev);
6911 struct pci_dev *pdev = tp->pci_dev;
6912 int retval = -ENOMEM;
6914 pm_runtime_get_sync(&pdev->dev);
6917 * Rx and Tx descriptors needs 256 bytes alignment.
6918 * dma_alloc_coherent provides more.
6920 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
6921 &tp->TxPhyAddr, GFP_KERNEL);
6922 if (!tp->TxDescArray)
6923 goto err_pm_runtime_put;
6925 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
6926 &tp->RxPhyAddr, GFP_KERNEL);
6927 if (!tp->RxDescArray)
6930 retval = rtl8169_init_ring(tp);
6934 INIT_WORK(&tp->wk.work, rtl_task);
6938 rtl_request_firmware(tp);
6940 retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp,
6943 goto err_release_fw_2;
6945 retval = r8169_phy_connect(tp);
6951 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
6953 napi_enable(&tp->napi);
6955 rtl8169_init_phy(dev, tp);
6957 rtl_pll_power_up(tp);
6961 if (!rtl8169_init_counter_offsets(tp))
6962 netif_warn(tp, hw, dev, "counter reset/update failed\n");
6964 phy_start(dev->phydev);
6965 netif_start_queue(dev);
6967 rtl_unlock_work(tp);
6969 pm_runtime_put_sync(&pdev->dev);
6974 pci_free_irq(pdev, 0, tp);
6976 rtl_release_firmware(tp);
6977 rtl8169_rx_clear(tp);
6979 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
6981 tp->RxDescArray = NULL;
6983 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
6985 tp->TxDescArray = NULL;
6987 pm_runtime_put_noidle(&pdev->dev);
6992 rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
6994 struct rtl8169_private *tp = netdev_priv(dev);
6995 struct pci_dev *pdev = tp->pci_dev;
6996 struct rtl8169_counters *counters = tp->counters;
6999 pm_runtime_get_noresume(&pdev->dev);
7001 if (netif_running(dev) && pm_runtime_active(&pdev->dev))
7002 rtl8169_rx_missed(dev);
7005 start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp);
7006 stats->rx_packets = tp->rx_stats.packets;
7007 stats->rx_bytes = tp->rx_stats.bytes;
7008 } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start));
7011 start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp);
7012 stats->tx_packets = tp->tx_stats.packets;
7013 stats->tx_bytes = tp->tx_stats.bytes;
7014 } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start));
7016 stats->rx_dropped = dev->stats.rx_dropped;
7017 stats->tx_dropped = dev->stats.tx_dropped;
7018 stats->rx_length_errors = dev->stats.rx_length_errors;
7019 stats->rx_errors = dev->stats.rx_errors;
7020 stats->rx_crc_errors = dev->stats.rx_crc_errors;
7021 stats->rx_fifo_errors = dev->stats.rx_fifo_errors;
7022 stats->rx_missed_errors = dev->stats.rx_missed_errors;
7023 stats->multicast = dev->stats.multicast;
7026 * Fetch additonal counter values missing in stats collected by driver
7027 * from tally counters.
7029 if (pm_runtime_active(&pdev->dev))
7030 rtl8169_update_counters(tp);
7033 * Subtract values fetched during initalization.
7034 * See rtl8169_init_counter_offsets for a description why we do that.
7036 stats->tx_errors = le64_to_cpu(counters->tx_errors) -
7037 le64_to_cpu(tp->tc_offset.tx_errors);
7038 stats->collisions = le32_to_cpu(counters->tx_multi_collision) -
7039 le32_to_cpu(tp->tc_offset.tx_multi_collision);
7040 stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) -
7041 le16_to_cpu(tp->tc_offset.tx_aborted);
7043 pm_runtime_put_noidle(&pdev->dev);
7046 static void rtl8169_net_suspend(struct net_device *dev)
7048 struct rtl8169_private *tp = netdev_priv(dev);
7050 if (!netif_running(dev))
7053 phy_stop(dev->phydev);
7054 netif_device_detach(dev);
7055 netif_stop_queue(dev);
7058 napi_disable(&tp->napi);
7059 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
7060 rtl_unlock_work(tp);
7062 rtl_pll_power_down(tp);
7067 static int rtl8169_suspend(struct device *device)
7069 struct pci_dev *pdev = to_pci_dev(device);
7070 struct net_device *dev = pci_get_drvdata(pdev);
7072 rtl8169_net_suspend(dev);
7077 static void __rtl8169_resume(struct net_device *dev)
7079 struct rtl8169_private *tp = netdev_priv(dev);
7081 netif_device_attach(dev);
7083 rtl_pll_power_up(tp);
7084 rtl8169_init_phy(dev, tp);
7086 phy_start(tp->dev->phydev);
7089 napi_enable(&tp->napi);
7090 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags);
7091 rtl_unlock_work(tp);
7093 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING);
7096 static int rtl8169_resume(struct device *device)
7098 struct pci_dev *pdev = to_pci_dev(device);
7099 struct net_device *dev = pci_get_drvdata(pdev);
7101 if (netif_running(dev))
7102 __rtl8169_resume(dev);
7107 static int rtl8169_runtime_suspend(struct device *device)
7109 struct pci_dev *pdev = to_pci_dev(device);
7110 struct net_device *dev = pci_get_drvdata(pdev);
7111 struct rtl8169_private *tp = netdev_priv(dev);
7113 if (!tp->TxDescArray) {
7114 rtl_pll_power_down(tp);
7119 __rtl8169_set_wol(tp, WAKE_ANY);
7120 rtl_unlock_work(tp);
7122 rtl8169_net_suspend(dev);
7124 /* Update counters before going runtime suspend */
7125 rtl8169_rx_missed(dev);
7126 rtl8169_update_counters(tp);
7131 static int rtl8169_runtime_resume(struct device *device)
7133 struct pci_dev *pdev = to_pci_dev(device);
7134 struct net_device *dev = pci_get_drvdata(pdev);
7135 struct rtl8169_private *tp = netdev_priv(dev);
7136 rtl_rar_set(tp, dev->dev_addr);
7138 if (!tp->TxDescArray)
7142 __rtl8169_set_wol(tp, tp->saved_wolopts);
7143 rtl_unlock_work(tp);
7145 __rtl8169_resume(dev);
7150 static int rtl8169_runtime_idle(struct device *device)
7152 struct pci_dev *pdev = to_pci_dev(device);
7153 struct net_device *dev = pci_get_drvdata(pdev);
7155 if (!netif_running(dev) || !netif_carrier_ok(dev))
7156 pm_schedule_suspend(device, 10000);
7161 static const struct dev_pm_ops rtl8169_pm_ops = {
7162 .suspend = rtl8169_suspend,
7163 .resume = rtl8169_resume,
7164 .freeze = rtl8169_suspend,
7165 .thaw = rtl8169_resume,
7166 .poweroff = rtl8169_suspend,
7167 .restore = rtl8169_resume,
7168 .runtime_suspend = rtl8169_runtime_suspend,
7169 .runtime_resume = rtl8169_runtime_resume,
7170 .runtime_idle = rtl8169_runtime_idle,
7173 #define RTL8169_PM_OPS (&rtl8169_pm_ops)
7175 #else /* !CONFIG_PM */
7177 #define RTL8169_PM_OPS NULL
7179 #endif /* !CONFIG_PM */
7181 static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp)
7183 /* WoL fails with 8168b when the receiver is disabled. */
7184 switch (tp->mac_version) {
7185 case RTL_GIGA_MAC_VER_11:
7186 case RTL_GIGA_MAC_VER_12:
7187 case RTL_GIGA_MAC_VER_17:
7188 pci_clear_master(tp->pci_dev);
7190 RTL_W8(tp, ChipCmd, CmdRxEnb);
7192 RTL_R8(tp, ChipCmd);
7199 static void rtl_shutdown(struct pci_dev *pdev)
7201 struct net_device *dev = pci_get_drvdata(pdev);
7202 struct rtl8169_private *tp = netdev_priv(dev);
7204 rtl8169_net_suspend(dev);
7206 /* Restore original MAC address */
7207 rtl_rar_set(tp, dev->perm_addr);
7209 rtl8169_hw_reset(tp);
7211 if (system_state == SYSTEM_POWER_OFF) {
7212 if (tp->saved_wolopts) {
7213 rtl_wol_suspend_quirk(tp);
7214 rtl_wol_shutdown_quirk(tp);
7217 pci_wake_from_d3(pdev, true);
7218 pci_set_power_state(pdev, PCI_D3hot);
7222 static void rtl_remove_one(struct pci_dev *pdev)
7224 struct net_device *dev = pci_get_drvdata(pdev);
7225 struct rtl8169_private *tp = netdev_priv(dev);
7227 if (r8168_check_dash(tp))
7228 rtl8168_driver_stop(tp);
7230 netif_napi_del(&tp->napi);
7232 unregister_netdev(dev);
7233 mdiobus_unregister(tp->mii_bus);
7235 rtl_release_firmware(tp);
7237 if (pci_dev_run_wake(pdev))
7238 pm_runtime_get_noresume(&pdev->dev);
7240 /* restore original MAC address */
7241 rtl_rar_set(tp, dev->perm_addr);
7244 static const struct net_device_ops rtl_netdev_ops = {
7245 .ndo_open = rtl_open,
7246 .ndo_stop = rtl8169_close,
7247 .ndo_get_stats64 = rtl8169_get_stats64,
7248 .ndo_start_xmit = rtl8169_start_xmit,
7249 .ndo_tx_timeout = rtl8169_tx_timeout,
7250 .ndo_validate_addr = eth_validate_addr,
7251 .ndo_change_mtu = rtl8169_change_mtu,
7252 .ndo_fix_features = rtl8169_fix_features,
7253 .ndo_set_features = rtl8169_set_features,
7254 .ndo_set_mac_address = rtl_set_mac_address,
7255 .ndo_do_ioctl = rtl8169_ioctl,
7256 .ndo_set_rx_mode = rtl_set_rx_mode,
7257 #ifdef CONFIG_NET_POLL_CONTROLLER
7258 .ndo_poll_controller = rtl8169_netpoll,
7263 static const struct rtl_cfg_info {
7264 void (*hw_start)(struct rtl8169_private *tp);
7266 unsigned int has_gmii:1;
7267 const struct rtl_coalesce_info *coalesce_info;
7269 } rtl_cfg_infos [] = {
7271 .hw_start = rtl_hw_start_8169,
7272 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver,
7274 .coalesce_info = rtl_coalesce_info_8169,
7275 .default_ver = RTL_GIGA_MAC_VER_01,
7278 .hw_start = rtl_hw_start_8168,
7279 .event_slow = SYSErr | LinkChg | RxOverflow,
7281 .coalesce_info = rtl_coalesce_info_8168_8136,
7282 .default_ver = RTL_GIGA_MAC_VER_11,
7285 .hw_start = rtl_hw_start_8101,
7286 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver |
7288 .coalesce_info = rtl_coalesce_info_8168_8136,
7289 .default_ver = RTL_GIGA_MAC_VER_13,
7293 static int rtl_alloc_irq(struct rtl8169_private *tp)
7297 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) {
7298 RTL_W8(tp, Cfg9346, Cfg9346_Unlock);
7299 RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable);
7300 RTL_W8(tp, Cfg9346, Cfg9346_Lock);
7301 flags = PCI_IRQ_LEGACY;
7303 flags = PCI_IRQ_ALL_TYPES;
7306 return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags);
7309 DECLARE_RTL_COND(rtl_link_list_ready_cond)
7311 return RTL_R8(tp, MCU) & LINK_LIST_RDY;
7314 DECLARE_RTL_COND(rtl_rxtx_empty_cond)
7316 return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY;
7319 static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg)
7321 struct rtl8169_private *tp = mii_bus->priv;
7326 return rtl_readphy(tp, phyreg);
7329 static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr,
7330 int phyreg, u16 val)
7332 struct rtl8169_private *tp = mii_bus->priv;
7337 rtl_writephy(tp, phyreg, val);
7342 static int r8169_mdio_register(struct rtl8169_private *tp)
7344 struct pci_dev *pdev = tp->pci_dev;
7345 struct phy_device *phydev;
7346 struct mii_bus *new_bus;
7349 new_bus = devm_mdiobus_alloc(&pdev->dev);
7353 new_bus->name = "r8169";
7355 new_bus->parent = &pdev->dev;
7356 new_bus->irq[0] = PHY_IGNORE_INTERRUPT;
7357 snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x",
7358 PCI_DEVID(pdev->bus->number, pdev->devfn));
7360 new_bus->read = r8169_mdio_read_reg;
7361 new_bus->write = r8169_mdio_write_reg;
7363 ret = mdiobus_register(new_bus);
7367 phydev = mdiobus_get_phy(new_bus, 0);
7369 mdiobus_unregister(new_bus);
7373 /* PHY will be woken up in rtl_open() */
7374 phy_suspend(phydev);
7376 tp->mii_bus = new_bus;
7381 static void rtl_hw_init_8168g(struct rtl8169_private *tp)
7385 tp->ocp_base = OCP_STD_PHY_BASE;
7387 RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN);
7389 if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42))
7392 if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42))
7395 RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb));
7397 RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB);
7399 data = r8168_mac_ocp_read(tp, 0xe8de);
7401 r8168_mac_ocp_write(tp, 0xe8de, data);
7403 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
7406 data = r8168_mac_ocp_read(tp, 0xe8de);
7408 r8168_mac_ocp_write(tp, 0xe8de, data);
7410 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42))
7414 static void rtl_hw_init_8168ep(struct rtl8169_private *tp)
7416 rtl8168ep_stop_cmac(tp);
7417 rtl_hw_init_8168g(tp);
7420 static void rtl_hw_initialize(struct rtl8169_private *tp)
7422 switch (tp->mac_version) {
7423 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48:
7424 rtl_hw_init_8168g(tp);
7426 case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51:
7427 rtl_hw_init_8168ep(tp);
7434 static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7436 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
7437 struct rtl8169_private *tp;
7438 struct mii_if_info *mii;
7439 struct net_device *dev;
7440 int chipset, region, i;
7443 if (netif_msg_drv(&debug)) {
7444 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n",
7445 MODULENAME, RTL8169_VERSION);
7448 dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp));
7452 SET_NETDEV_DEV(dev, &pdev->dev);
7453 dev->netdev_ops = &rtl_netdev_ops;
7454 tp = netdev_priv(dev);
7457 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
7461 mii->mdio_read = rtl_mdio_read;
7462 mii->mdio_write = rtl_mdio_write;
7463 mii->phy_id_mask = 0x1f;
7464 mii->reg_num_mask = 0x1f;
7465 mii->supports_gmii = cfg->has_gmii;
7467 /* enable device (incl. PCI PM wakeup and hotplug setup) */
7468 rc = pcim_enable_device(pdev);
7470 dev_err(&pdev->dev, "enable failure\n");
7474 if (pcim_set_mwi(pdev) < 0)
7475 dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n");
7477 /* use first MMIO region */
7478 region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1;
7480 dev_err(&pdev->dev, "no MMIO resource found\n");
7484 /* check for weird/broken PCI region reporting */
7485 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) {
7486 dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n");
7490 rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME);
7492 dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
7496 tp->mmio_addr = pcim_iomap_table(pdev)[region];
7498 if (!pci_is_pcie(pdev))
7499 dev_info(&pdev->dev, "not PCI Express\n");
7501 /* Identify chip attached to board */
7502 rtl8169_get_mac_version(tp, cfg->default_ver);
7504 if (rtl_tbi_enabled(tp)) {
7505 dev_err(&pdev->dev, "TBI fiber mode not supported\n");
7509 tp->cp_cmd = RTL_R16(tp, CPlusCmd);
7511 if ((sizeof(dma_addr_t) > 4) &&
7512 (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) &&
7513 tp->mac_version >= RTL_GIGA_MAC_VER_18)) &&
7514 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
7515 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
7517 /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */
7518 if (!pci_is_pcie(pdev))
7519 tp->cp_cmd |= PCIDAC;
7520 dev->features |= NETIF_F_HIGHDMA;
7522 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
7524 dev_err(&pdev->dev, "DMA configuration failed\n");
7531 rtl_irq_disable(tp);
7533 rtl_hw_initialize(tp);
7537 rtl_ack_events(tp, 0xffff);
7539 pci_set_master(pdev);
7541 rtl_init_mdio_ops(tp);
7542 rtl_init_jumbo_ops(tp);
7544 rtl8169_print_mac_version(tp);
7546 chipset = tp->mac_version;
7548 rc = rtl_alloc_irq(tp);
7550 dev_err(&pdev->dev, "Can't allocate interrupt\n");
7554 /* override BIOS settings, use userspace tools to enable WOL */
7555 __rtl8169_set_wol(tp, 0);
7557 mutex_init(&tp->wk.mutex);
7558 u64_stats_init(&tp->rx_stats.syncp);
7559 u64_stats_init(&tp->tx_stats.syncp);
7561 /* Get MAC address */
7562 switch (tp->mac_version) {
7563 u8 mac_addr[ETH_ALEN] __aligned(4);
7564 case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38:
7565 case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
7566 *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC);
7567 *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC);
7569 if (is_valid_ether_addr(mac_addr))
7570 rtl_rar_set(tp, mac_addr);
7575 for (i = 0; i < ETH_ALEN; i++)
7576 dev->dev_addr[i] = RTL_R8(tp, MAC0 + i);
7578 dev->ethtool_ops = &rtl8169_ethtool_ops;
7579 dev->watchdog_timeo = RTL8169_TX_TIMEOUT;
7581 netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT);
7583 /* don't enable SG, IP_CSUM and TSO by default - it might not work
7584 * properly for all devices */
7585 dev->features |= NETIF_F_RXCSUM |
7586 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
7588 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
7589 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX |
7590 NETIF_F_HW_VLAN_CTAG_RX;
7591 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO |
7594 tp->cp_cmd |= RxChkSum | RxVlan;
7597 * Pretend we are using VLANs; This bypasses a nasty bug where
7598 * Interrupts stop flowing on high load on 8110SCd controllers.
7600 if (tp->mac_version == RTL_GIGA_MAC_VER_05)
7601 /* Disallow toggling */
7602 dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX;
7604 switch (rtl_chip_infos[chipset].txd_version) {
7606 tp->tso_csum = rtl8169_tso_csum_v1;
7609 tp->tso_csum = rtl8169_tso_csum_v2;
7610 dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6;
7616 dev->hw_features |= NETIF_F_RXALL;
7617 dev->hw_features |= NETIF_F_RXFCS;
7619 /* MTU range: 60 - hw-specific max */
7620 dev->min_mtu = ETH_ZLEN;
7621 dev->max_mtu = rtl_chip_infos[chipset].jumbo_max;
7623 tp->hw_start = cfg->hw_start;
7624 tp->event_slow = cfg->event_slow;
7625 tp->coalesce_info = cfg->coalesce_info;
7627 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN;
7629 tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters),
7630 &tp->counters_phys_addr,
7635 pci_set_drvdata(pdev, dev);
7637 rc = r8169_mdio_register(tp);
7641 rc = register_netdev(dev);
7643 goto err_mdio_unregister;
7645 netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n",
7646 rtl_chip_infos[chipset].name, dev->dev_addr,
7647 (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff),
7648 pci_irq_vector(pdev, 0));
7649 if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) {
7650 netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, "
7651 "tx checksumming: %s]\n",
7652 rtl_chip_infos[chipset].jumbo_max,
7653 tp->mac_version <= RTL_GIGA_MAC_VER_06 ? "ok" : "ko");
7656 if (r8168_check_dash(tp))
7657 rtl8168_driver_start(tp);
7659 if (pci_dev_run_wake(pdev))
7660 pm_runtime_put_sync(&pdev->dev);
7664 err_mdio_unregister:
7665 mdiobus_unregister(tp->mii_bus);
7669 static struct pci_driver rtl8169_pci_driver = {
7671 .id_table = rtl8169_pci_tbl,
7672 .probe = rtl_init_one,
7673 .remove = rtl_remove_one,
7674 .shutdown = rtl_shutdown,
7675 .driver.pm = RTL8169_PM_OPS,
7678 module_pci_driver(rtl8169_pci_driver);