Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2 | * r8169.c: RealTek 8169/8168/8101 ethernet driver. |
| 3 | * |
| 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. |
| 7 | * |
| 8 | * See MAINTAINERS file for support contact information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/etherdevice.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/ethtool.h> |
| 18 | #include <linux/mii.h> |
| 19 | #include <linux/if_vlan.h> |
| 20 | #include <linux/crc32.h> |
| 21 | #include <linux/in.h> |
| 22 | #include <linux/ip.h> |
| 23 | #include <linux/tcp.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 28 | #include <linux/prefetch.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 29 | #include <linux/ipv6.h> |
| 30 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/irq.h> |
| 34 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 35 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MODULENAME "r8169" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 38 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 39 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 40 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 41 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 42 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 44 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 50 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 51 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 52 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 53 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 54 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 55 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 56 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 57 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 58 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 59 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 60 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 61 | #define TX_SLOTS_AVAIL(tp) \ |
| 62 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 63 | |
| 64 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 65 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 66 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 69 | The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 70 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 72 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 74 | |
| 75 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 76 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 78 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 80 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 81 | |
| 82 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 83 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 84 | |
| 85 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 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)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 94 | RTL_GIGA_MAC_VER_01 = 0, |
| 95 | RTL_GIGA_MAC_VER_02, |
| 96 | RTL_GIGA_MAC_VER_03, |
| 97 | RTL_GIGA_MAC_VER_04, |
| 98 | RTL_GIGA_MAC_VER_05, |
| 99 | RTL_GIGA_MAC_VER_06, |
| 100 | RTL_GIGA_MAC_VER_07, |
| 101 | RTL_GIGA_MAC_VER_08, |
| 102 | RTL_GIGA_MAC_VER_09, |
| 103 | RTL_GIGA_MAC_VER_10, |
| 104 | RTL_GIGA_MAC_VER_11, |
| 105 | RTL_GIGA_MAC_VER_12, |
| 106 | RTL_GIGA_MAC_VER_13, |
| 107 | RTL_GIGA_MAC_VER_14, |
| 108 | RTL_GIGA_MAC_VER_15, |
| 109 | RTL_GIGA_MAC_VER_16, |
| 110 | RTL_GIGA_MAC_VER_17, |
| 111 | RTL_GIGA_MAC_VER_18, |
| 112 | RTL_GIGA_MAC_VER_19, |
| 113 | RTL_GIGA_MAC_VER_20, |
| 114 | RTL_GIGA_MAC_VER_21, |
| 115 | RTL_GIGA_MAC_VER_22, |
| 116 | RTL_GIGA_MAC_VER_23, |
| 117 | RTL_GIGA_MAC_VER_24, |
| 118 | RTL_GIGA_MAC_VER_25, |
| 119 | RTL_GIGA_MAC_VER_26, |
| 120 | RTL_GIGA_MAC_VER_27, |
| 121 | RTL_GIGA_MAC_VER_28, |
| 122 | RTL_GIGA_MAC_VER_29, |
| 123 | RTL_GIGA_MAC_VER_30, |
| 124 | RTL_GIGA_MAC_VER_31, |
| 125 | RTL_GIGA_MAC_VER_32, |
| 126 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 127 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_35, |
| 129 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 130 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 131 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 132 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 133 | RTL_GIGA_MAC_VER_40, |
| 134 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 135 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 136 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 137 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 138 | RTL_GIGA_MAC_VER_45, |
| 139 | RTL_GIGA_MAC_VER_46, |
| 140 | RTL_GIGA_MAC_VER_47, |
| 141 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 142 | RTL_GIGA_MAC_VER_49, |
| 143 | RTL_GIGA_MAC_VER_50, |
| 144 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 145 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 148 | enum rtl_tx_desc_version { |
| 149 | RTL_TD_0 = 0, |
| 150 | RTL_TD_1 = 1, |
| 151 | }; |
| 152 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 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) |
| 158 | |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 159 | #define _R(NAME,TD,FW,SZ) { \ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 160 | .name = NAME, \ |
| 161 | .txd_version = TD, \ |
| 162 | .fw_name = FW, \ |
| 163 | .jumbo_max = SZ, \ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 166 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 168 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 169 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 170 | u16 jumbo_max; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 171 | } rtl_chip_infos[] = { |
| 172 | /* PCI devices. */ |
| 173 | [RTL_GIGA_MAC_VER_01] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 174 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 175 | [RTL_GIGA_MAC_VER_02] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 176 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 177 | [RTL_GIGA_MAC_VER_03] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 178 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 179 | [RTL_GIGA_MAC_VER_04] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 180 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 181 | [RTL_GIGA_MAC_VER_05] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 182 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 183 | [RTL_GIGA_MAC_VER_06] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 184 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 185 | /* PCI-E devices. */ |
| 186 | [RTL_GIGA_MAC_VER_07] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 187 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 188 | [RTL_GIGA_MAC_VER_08] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 189 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 190 | [RTL_GIGA_MAC_VER_09] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 191 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 192 | [RTL_GIGA_MAC_VER_10] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 193 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 194 | [RTL_GIGA_MAC_VER_11] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 195 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_12] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 197 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 198 | [RTL_GIGA_MAC_VER_13] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 199 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 200 | [RTL_GIGA_MAC_VER_14] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 201 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 202 | [RTL_GIGA_MAC_VER_15] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 203 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 204 | [RTL_GIGA_MAC_VER_16] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 205 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 206 | [RTL_GIGA_MAC_VER_17] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 207 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 208 | [RTL_GIGA_MAC_VER_18] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 209 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 210 | [RTL_GIGA_MAC_VER_19] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 211 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 212 | [RTL_GIGA_MAC_VER_20] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 213 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 214 | [RTL_GIGA_MAC_VER_21] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 215 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 216 | [RTL_GIGA_MAC_VER_22] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 217 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 218 | [RTL_GIGA_MAC_VER_23] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 219 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 220 | [RTL_GIGA_MAC_VER_24] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 221 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 222 | [RTL_GIGA_MAC_VER_25] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 223 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 224 | [RTL_GIGA_MAC_VER_26] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 225 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 226 | [RTL_GIGA_MAC_VER_27] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 227 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 228 | [RTL_GIGA_MAC_VER_28] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 229 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 230 | [RTL_GIGA_MAC_VER_29] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 231 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 232 | [RTL_GIGA_MAC_VER_30] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 233 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 234 | [RTL_GIGA_MAC_VER_31] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 235 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 236 | [RTL_GIGA_MAC_VER_32] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 237 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 238 | [RTL_GIGA_MAC_VER_33] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 239 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, JUMBO_9K), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 240 | [RTL_GIGA_MAC_VER_34] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 241 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, JUMBO_9K), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 242 | [RTL_GIGA_MAC_VER_35] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 243 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, JUMBO_9K), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 244 | [RTL_GIGA_MAC_VER_36] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 245 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, JUMBO_9K), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 246 | [RTL_GIGA_MAC_VER_37] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 247 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, JUMBO_1K), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 248 | [RTL_GIGA_MAC_VER_38] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 249 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, JUMBO_9K), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 250 | [RTL_GIGA_MAC_VER_39] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 251 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, JUMBO_1K), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 252 | [RTL_GIGA_MAC_VER_40] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 253 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, JUMBO_9K), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 254 | [RTL_GIGA_MAC_VER_41] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 255 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K), |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 256 | [RTL_GIGA_MAC_VER_42] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 257 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, JUMBO_9K), |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 258 | [RTL_GIGA_MAC_VER_43] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 259 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, JUMBO_1K), |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 260 | [RTL_GIGA_MAC_VER_44] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 261 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 262 | [RTL_GIGA_MAC_VER_45] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 263 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 264 | [RTL_GIGA_MAC_VER_46] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 265 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 266 | [RTL_GIGA_MAC_VER_47] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 267 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, JUMBO_1K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 268 | [RTL_GIGA_MAC_VER_48] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 269 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, JUMBO_1K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 270 | [RTL_GIGA_MAC_VER_49] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 271 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 272 | [RTL_GIGA_MAC_VER_50] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 273 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 274 | [RTL_GIGA_MAC_VER_51] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 275 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | }; |
| 277 | #undef _R |
| 278 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 279 | enum cfg_version { |
| 280 | RTL_CFG_0 = 0x00, |
| 281 | RTL_CFG_1, |
| 282 | RTL_CFG_2 |
| 283 | }; |
| 284 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 285 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 286 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 287 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Chun-Hao Lin | 610c908 | 2016-12-27 16:29:43 +0800 | [diff] [blame] | 288 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 289 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 290 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 291 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 292 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 293 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 294 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 295 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 296 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 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 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 300 | { 0x0001, 0x8168, |
| 301 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | {0,}, |
| 303 | }; |
| 304 | |
| 305 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 306 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 307 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 308 | static struct { |
| 309 | u32 msg_enable; |
| 310 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 312 | enum rtl_registers { |
| 313 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 314 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 315 | MAR0 = 8, /* Multicast filter. */ |
| 316 | CounterAddrLow = 0x10, |
| 317 | CounterAddrHigh = 0x14, |
| 318 | TxDescStartAddrLow = 0x20, |
| 319 | TxDescStartAddrHigh = 0x24, |
| 320 | TxHDescStartAddrLow = 0x28, |
| 321 | TxHDescStartAddrHigh = 0x2c, |
| 322 | FLASH = 0x30, |
| 323 | ERSR = 0x36, |
| 324 | ChipCmd = 0x37, |
| 325 | TxPoll = 0x38, |
| 326 | IntrMask = 0x3c, |
| 327 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 328 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 329 | TxConfig = 0x40, |
| 330 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 331 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 332 | |
| 333 | RxConfig = 0x44, |
| 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) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 339 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 340 | #define RXCFG_DMA_SHIFT 8 |
| 341 | /* Unlimited maximum PCI burst. */ |
| 342 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 343 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 344 | RxMissed = 0x4c, |
| 345 | Cfg9346 = 0x50, |
| 346 | Config0 = 0x51, |
| 347 | Config1 = 0x52, |
| 348 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 349 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 350 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 351 | Config3 = 0x54, |
| 352 | Config4 = 0x55, |
| 353 | Config5 = 0x56, |
| 354 | MultiIntr = 0x5c, |
| 355 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 356 | PHYstatus = 0x6c, |
| 357 | RxMaxSize = 0xda, |
| 358 | CPlusCmd = 0xe0, |
| 359 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 360 | |
| 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) |
| 365 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 366 | RxDescAddrLow = 0xe4, |
| 367 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 368 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 369 | |
| 370 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 371 | |
| 372 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 373 | |
| 374 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 375 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 376 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 377 | FuncEvent = 0xf0, |
| 378 | FuncEventMask = 0xf4, |
| 379 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 380 | IBCR0 = 0xf8, |
| 381 | IBCR2 = 0xf9, |
| 382 | IBIMR0 = 0xfa, |
| 383 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 384 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 387 | enum rtl8168_8101_registers { |
| 388 | CSIDR = 0x64, |
| 389 | CSIAR = 0x68, |
| 390 | #define CSIAR_FLAG 0x80000000 |
| 391 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 392 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 393 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 394 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 395 | EPHYAR = 0x80, |
| 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 |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 401 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 402 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 403 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 404 | DBG_REG = 0xd1, |
| 405 | #define FIX_NAK_1 (1 << 4) |
| 406 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 407 | TWSI = 0xd2, |
| 408 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 409 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 410 | #define TX_EMPTY (1 << 5) |
| 411 | #define RX_EMPTY (1 << 4) |
| 412 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 413 | #define EN_NDP (1 << 3) |
| 414 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 415 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 416 | EFUSEAR = 0xdc, |
| 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 |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 423 | MISC_1 = 0xf2, |
| 424 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 425 | }; |
| 426 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 427 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 428 | LED_FREQ = 0x1a, |
| 429 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 430 | ERIDR = 0x70, |
| 431 | ERIAR = 0x74, |
| 432 | #define ERIAR_FLAG 0x80000000 |
| 433 | #define ERIAR_WRITE_CMD 0x80000000 |
| 434 | #define ERIAR_READ_CMD 0x00000000 |
| 435 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 436 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 437 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 438 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 439 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 440 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 441 | #define ERIAR_MASK_SHIFT 12 |
| 442 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 443 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 444 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 445 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 446 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 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 |
| 454 | OCPAR = 0xb4, |
| 455 | #define OCPAR_FLAG 0x80000000 |
| 456 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 457 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 458 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 459 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 460 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 461 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 462 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 463 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 464 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 465 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 466 | }; |
| 467 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 468 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 470 | SYSErr = 0x8000, |
| 471 | PCSTimeout = 0x4000, |
| 472 | SWInt = 0x0100, |
| 473 | TxDescUnavail = 0x0080, |
| 474 | RxFIFOOver = 0x0040, |
| 475 | LinkChg = 0x0020, |
| 476 | RxOverflow = 0x0010, |
| 477 | TxErr = 0x0008, |
| 478 | TxOK = 0x0004, |
| 479 | RxErr = 0x0002, |
| 480 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 483 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 484 | RxFOVF = (1 << 23), |
| 485 | RxRWT = (1 << 22), |
| 486 | RxRES = (1 << 21), |
| 487 | RxRUNT = (1 << 20), |
| 488 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 491 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 492 | CmdReset = 0x10, |
| 493 | CmdRxEnb = 0x08, |
| 494 | CmdTxEnb = 0x04, |
| 495 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 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 */ |
| 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 503 | Cfg9346_Lock = 0x00, |
| 504 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 507 | AcceptErr = 0x20, |
| 508 | AcceptRunt = 0x10, |
| 509 | AcceptBroadcast = 0x08, |
| 510 | AcceptMulticast = 0x04, |
| 511 | AcceptMyPhys = 0x02, |
| 512 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 513 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* TxConfigBits */ |
| 516 | TxInterFrameGapShift = 24, |
| 517 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 518 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 519 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 520 | LEDS1 = (1 << 7), |
| 521 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 522 | Speed_down = (1 << 4), |
| 523 | MEMMAP = (1 << 3), |
| 524 | IOMAP = (1 << 2), |
| 525 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 526 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 527 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 528 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 529 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 530 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 531 | PCI_Clock_66MHz = 0x01, |
| 532 | PCI_Clock_33MHz = 0x00, |
| 533 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 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 */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 537 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 538 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 539 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 540 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 541 | /* Config4 register */ |
| 542 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 543 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 544 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 545 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 546 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 547 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 548 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 549 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 550 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 551 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | RxVlan = (1 << 6), |
| 565 | RxChkSum = (1 << 5), |
| 566 | PCIDAC = (1 << 4), |
| 567 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 568 | #define INTT_MASK GENMASK(1, 0) |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 569 | INTT_0 = 0x0000, // 8168 |
| 570 | INTT_1 = 0x0001, // 8168 |
| 571 | INTT_2 = 0x0002, // 8168 |
| 572 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 575 | TBI_Enable = 0x80, |
| 576 | TxFlowCtrl = 0x40, |
| 577 | RxFlowCtrl = 0x20, |
| 578 | _1000bpsF = 0x10, |
| 579 | _100bps = 0x08, |
| 580 | _10bps = 0x04, |
| 581 | LinkStatus = 0x02, |
| 582 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 585 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 586 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 587 | /* ResetCounterCommand */ |
| 588 | CounterReset = 0x1, |
| 589 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 590 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 591 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 592 | |
| 593 | /* magic enable v2 */ |
| 594 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | }; |
| 596 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 597 | enum rtl_desc_bit { |
| 598 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 603 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 605 | /* Generic case. */ |
| 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 611 | /* Second doubleword. */ |
| 612 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 613 | }; |
| 614 | |
| 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 */ |
| 622 | }; |
| 623 | |
| 624 | /* 8102e, 8168c and beyond. */ |
| 625 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 626 | /* First doubleword. */ |
| 627 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 628 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 629 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 630 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 631 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 632 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 633 | #define TCPHO_SHIFT 18 |
| 634 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 635 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 636 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 637 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 638 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 639 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 640 | }; |
| 641 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 642 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* Rx private */ |
| 644 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 645 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | #define RxProtoUDP (PID1) |
| 648 | #define RxProtoTCP (PID0) |
| 649 | #define RxProtoIP (PID1 | PID0) |
| 650 | #define RxProtoMask RxProtoIP |
| 651 | |
| 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 */ |
| 656 | }; |
| 657 | |
| 658 | #define RsvdMask 0x3fffc000 |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 659 | #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 662 | __le32 opts1; |
| 663 | __le32 opts2; |
| 664 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 668 | __le32 opts1; |
| 669 | __le32 opts2; |
| 670 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | struct ring_info { |
| 674 | struct sk_buff *skb; |
| 675 | u32 len; |
| 676 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 677 | }; |
| 678 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 679 | struct rtl8169_counters { |
| 680 | __le64 tx_packets; |
| 681 | __le64 rx_packets; |
| 682 | __le64 tx_errors; |
| 683 | __le32 rx_errors; |
| 684 | __le16 rx_missed; |
| 685 | __le16 align_errors; |
| 686 | __le32 tx_one_collision; |
| 687 | __le32 tx_multi_collision; |
| 688 | __le64 rx_unicast; |
| 689 | __le64 rx_broadcast; |
| 690 | __le32 rx_multicast; |
| 691 | __le16 tx_aborted; |
| 692 | __le16 tx_underun; |
| 693 | }; |
| 694 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 695 | struct rtl8169_tc_offsets { |
| 696 | bool inited; |
| 697 | __le64 tx_errors; |
| 698 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 699 | __le16 tx_aborted; |
| 700 | }; |
| 701 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 702 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 703 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 704 | RTL_FLAG_TASK_SLOW_PENDING, |
| 705 | RTL_FLAG_TASK_RESET_PENDING, |
| 706 | RTL_FLAG_TASK_PHY_PENDING, |
| 707 | RTL_FLAG_MAX |
| 708 | }; |
| 709 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 710 | struct rtl8169_stats { |
| 711 | u64 packets; |
| 712 | u64 bytes; |
| 713 | struct u64_stats_sync syncp; |
| 714 | }; |
| 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | struct rtl8169_private { |
| 717 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 718 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 719 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 720 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 721 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 722 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 724 | u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 726 | struct rtl8169_stats rx_stats; |
| 727 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 729 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 730 | dma_addr_t TxPhyAddr; |
| 731 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 732 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | struct timer_list timer; |
| 735 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 736 | |
| 737 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 738 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 739 | |
| 740 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 741 | void (*write)(struct rtl8169_private *, int, int); |
| 742 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 743 | } mdio_ops; |
| 744 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 745 | struct jumbo_ops { |
| 746 | void (*enable)(struct rtl8169_private *); |
| 747 | void (*disable)(struct rtl8169_private *); |
| 748 | } jumbo_ops; |
| 749 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 750 | void (*hw_start)(struct rtl8169_private *tp); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 751 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 752 | |
| 753 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 754 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 755 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 756 | struct work_struct work; |
| 757 | } wk; |
| 758 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 759 | struct mii_if_info mii; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 760 | dma_addr_t counters_phys_addr; |
| 761 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 762 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 763 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 764 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 765 | struct rtl_fw { |
| 766 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 767 | |
| 768 | #define RTL_VER_SIZE 32 |
| 769 | |
| 770 | char version[RTL_VER_SIZE]; |
| 771 | |
| 772 | struct rtl_fw_phy_action { |
| 773 | __le32 *code; |
| 774 | size_t size; |
| 775 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 776 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 777 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 778 | |
| 779 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | }; |
| 781 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 782 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 785 | MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 786 | module_param_named(debug, debug.msg_enable, int, 0); |
| 787 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | MODULE_LICENSE("GPL"); |
| 789 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 790 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 791 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 792 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 793 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 794 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 795 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 796 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 797 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 798 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 799 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 800 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 801 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 802 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 803 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 804 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 805 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 806 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 807 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 808 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 810 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 811 | { |
| 812 | return &tp->pci_dev->dev; |
| 813 | } |
| 814 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 815 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 816 | { |
| 817 | mutex_lock(&tp->wk.mutex); |
| 818 | } |
| 819 | |
| 820 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 821 | { |
| 822 | mutex_unlock(&tp->wk.mutex); |
| 823 | } |
| 824 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 825 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 826 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 827 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 828 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 831 | struct rtl_cond { |
| 832 | bool (*check)(struct rtl8169_private *); |
| 833 | const char *msg; |
| 834 | }; |
| 835 | |
| 836 | static void rtl_udelay(unsigned int d) |
| 837 | { |
| 838 | udelay(d); |
| 839 | } |
| 840 | |
| 841 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 842 | void (*delay)(unsigned int), unsigned int d, int n, |
| 843 | bool high) |
| 844 | { |
| 845 | int i; |
| 846 | |
| 847 | for (i = 0; i < n; i++) { |
| 848 | delay(d); |
| 849 | if (c->check(tp) == high) |
| 850 | return true; |
| 851 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 852 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 853 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 854 | return false; |
| 855 | } |
| 856 | |
| 857 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 858 | const struct rtl_cond *c, |
| 859 | unsigned int d, int n) |
| 860 | { |
| 861 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 862 | } |
| 863 | |
| 864 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 865 | const struct rtl_cond *c, |
| 866 | unsigned int d, int n) |
| 867 | { |
| 868 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 869 | } |
| 870 | |
| 871 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 872 | const struct rtl_cond *c, |
| 873 | unsigned int d, int n) |
| 874 | { |
| 875 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 876 | } |
| 877 | |
| 878 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 879 | const struct rtl_cond *c, |
| 880 | unsigned int d, int n) |
| 881 | { |
| 882 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 883 | } |
| 884 | |
| 885 | #define DECLARE_RTL_COND(name) \ |
| 886 | static bool name ## _check(struct rtl8169_private *); \ |
| 887 | \ |
| 888 | static const struct rtl_cond name = { \ |
| 889 | .check = name ## _check, \ |
| 890 | .msg = #name \ |
| 891 | }; \ |
| 892 | \ |
| 893 | static bool name ## _check(struct rtl8169_private *tp) |
| 894 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 895 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 896 | { |
| 897 | if (reg & 0xffff0001) { |
| 898 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 899 | return true; |
| 900 | } |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 905 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 906 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 910 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 911 | if (rtl_ocp_reg_failure(tp, reg)) |
| 912 | return; |
| 913 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 914 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 915 | |
| 916 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 917 | } |
| 918 | |
| 919 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 920 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 921 | if (rtl_ocp_reg_failure(tp, reg)) |
| 922 | return 0; |
| 923 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 924 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 925 | |
| 926 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 927 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 928 | } |
| 929 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 930 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 931 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 932 | if (rtl_ocp_reg_failure(tp, reg)) |
| 933 | return; |
| 934 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 935 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 939 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 940 | if (rtl_ocp_reg_failure(tp, reg)) |
| 941 | return 0; |
| 942 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 943 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 944 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 945 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | #define OCP_STD_PHY_BASE 0xa400 |
| 949 | |
| 950 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 951 | { |
| 952 | if (reg == 0x1f) { |
| 953 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 954 | return; |
| 955 | } |
| 956 | |
| 957 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 958 | reg -= 0x10; |
| 959 | |
| 960 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 961 | } |
| 962 | |
| 963 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 964 | { |
| 965 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 966 | reg -= 0x10; |
| 967 | |
| 968 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 969 | } |
| 970 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 971 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 972 | { |
| 973 | if (reg == 0x1f) { |
| 974 | tp->ocp_base = value << 4; |
| 975 | return; |
| 976 | } |
| 977 | |
| 978 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 979 | } |
| 980 | |
| 981 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 982 | { |
| 983 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 984 | } |
| 985 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 986 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 987 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 988 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 989 | } |
| 990 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 991 | static void r8169_mdio_write(struct rtl8169_private *tp, int reg, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 993 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 995 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 996 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 997 | * According to hardware specs a 20us delay is required after write |
| 998 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 999 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1000 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1003 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1005 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1007 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1009 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1010 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1011 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1012 | /* |
| 1013 | * According to hardware specs a 20us delay is required after read |
| 1014 | * complete indication, but before sending next command. |
| 1015 | */ |
| 1016 | udelay(20); |
| 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | return value; |
| 1019 | } |
| 1020 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1021 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 1022 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1023 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1024 | } |
| 1025 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1026 | static void r8168dp_1_mdio_access(struct rtl8169_private *tp, int reg, u32 data) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1027 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1028 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 1029 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1030 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1031 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1032 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1035 | static void r8168dp_1_mdio_write(struct rtl8169_private *tp, int reg, int value) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1036 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1037 | r8168dp_1_mdio_access(tp, reg, |
| 1038 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1041 | static int r8168dp_1_mdio_read(struct rtl8169_private *tp, int reg) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1042 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1043 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1044 | |
| 1045 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1046 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 1047 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1048 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1049 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1050 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1053 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1054 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1055 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1056 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1057 | RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1060 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1061 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1062 | RTL_W32(tp, 0xd0, RTL_R32(tp, 0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1065 | static void r8168dp_2_mdio_write(struct rtl8169_private *tp, int reg, int value) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1066 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1067 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1068 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1069 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1070 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1071 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1074 | static int r8168dp_2_mdio_read(struct rtl8169_private *tp, int reg) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1075 | { |
| 1076 | int value; |
| 1077 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1078 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1079 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1080 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1081 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1082 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1083 | |
| 1084 | return value; |
| 1085 | } |
| 1086 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1087 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1088 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1089 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1090 | } |
| 1091 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1092 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1093 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1094 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1098 | { |
| 1099 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1100 | } |
| 1101 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1102 | static void rtl_w0w1_phy(struct rtl8169_private *tp, int reg_addr, int p, int m) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1103 | { |
| 1104 | int val; |
| 1105 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1106 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1107 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1110 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1111 | int val) |
| 1112 | { |
| 1113 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1114 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1115 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1119 | { |
| 1120 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1121 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1122 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1123 | } |
| 1124 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1125 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1126 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1127 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1130 | static void rtl_ephy_write(struct rtl8169_private *tp, int reg_addr, int value) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1131 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1132 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1133 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1134 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1135 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1136 | |
| 1137 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1140 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1141 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1142 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1143 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1144 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1145 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1146 | } |
| 1147 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1148 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1149 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1150 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1153 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1154 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1155 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1156 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1157 | RTL_W32(tp, ERIDR, val); |
| 1158 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1159 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1160 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1161 | } |
| 1162 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1163 | static u32 rtl_eri_read(struct rtl8169_private *tp, int addr, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1164 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1165 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1166 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1167 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1168 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1171 | static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p, |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1172 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1173 | { |
| 1174 | u32 val; |
| 1175 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1176 | val = rtl_eri_read(tp, addr, type); |
| 1177 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1178 | } |
| 1179 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1180 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1181 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1182 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1183 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1184 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1188 | { |
| 1189 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1190 | } |
| 1191 | |
| 1192 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1193 | { |
| 1194 | switch (tp->mac_version) { |
| 1195 | case RTL_GIGA_MAC_VER_27: |
| 1196 | case RTL_GIGA_MAC_VER_28: |
| 1197 | case RTL_GIGA_MAC_VER_31: |
| 1198 | return r8168dp_ocp_read(tp, mask, reg); |
| 1199 | case RTL_GIGA_MAC_VER_49: |
| 1200 | case RTL_GIGA_MAC_VER_50: |
| 1201 | case RTL_GIGA_MAC_VER_51: |
| 1202 | return r8168ep_ocp_read(tp, mask, reg); |
| 1203 | default: |
| 1204 | BUG(); |
| 1205 | return ~0; |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1210 | u32 data) |
| 1211 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1212 | RTL_W32(tp, OCPDR, data); |
| 1213 | RTL_W32(tp, OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1214 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1215 | } |
| 1216 | |
| 1217 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1218 | u32 data) |
| 1219 | { |
| 1220 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1221 | data, ERIAR_OOB); |
| 1222 | } |
| 1223 | |
| 1224 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1225 | { |
| 1226 | switch (tp->mac_version) { |
| 1227 | case RTL_GIGA_MAC_VER_27: |
| 1228 | case RTL_GIGA_MAC_VER_28: |
| 1229 | case RTL_GIGA_MAC_VER_31: |
| 1230 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1231 | break; |
| 1232 | case RTL_GIGA_MAC_VER_49: |
| 1233 | case RTL_GIGA_MAC_VER_50: |
| 1234 | case RTL_GIGA_MAC_VER_51: |
| 1235 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1236 | break; |
| 1237 | default: |
| 1238 | BUG(); |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1243 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1244 | { |
| 1245 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1246 | |
| 1247 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1248 | } |
| 1249 | |
| 1250 | #define OOB_CMD_RESET 0x00 |
| 1251 | #define OOB_CMD_DRIVER_START 0x05 |
| 1252 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1253 | |
| 1254 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1255 | { |
| 1256 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1257 | } |
| 1258 | |
| 1259 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1260 | { |
| 1261 | u16 reg; |
| 1262 | |
| 1263 | reg = rtl8168_get_ocp_reg(tp); |
| 1264 | |
| 1265 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1266 | } |
| 1267 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1268 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1269 | { |
| 1270 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1271 | } |
| 1272 | |
| 1273 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1274 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1275 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1278 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1279 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1280 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1281 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1282 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1283 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1284 | } |
| 1285 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1286 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1287 | { |
| 1288 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1289 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1290 | } |
| 1291 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1292 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1293 | { |
| 1294 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1295 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1296 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1297 | } |
| 1298 | |
| 1299 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1300 | { |
| 1301 | switch (tp->mac_version) { |
| 1302 | case RTL_GIGA_MAC_VER_27: |
| 1303 | case RTL_GIGA_MAC_VER_28: |
| 1304 | case RTL_GIGA_MAC_VER_31: |
| 1305 | rtl8168dp_driver_start(tp); |
| 1306 | break; |
| 1307 | case RTL_GIGA_MAC_VER_49: |
| 1308 | case RTL_GIGA_MAC_VER_50: |
| 1309 | case RTL_GIGA_MAC_VER_51: |
| 1310 | rtl8168ep_driver_start(tp); |
| 1311 | break; |
| 1312 | default: |
| 1313 | BUG(); |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1319 | { |
| 1320 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1321 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1322 | } |
| 1323 | |
| 1324 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1325 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1326 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1327 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1328 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1329 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1330 | } |
| 1331 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1332 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1333 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1334 | switch (tp->mac_version) { |
| 1335 | case RTL_GIGA_MAC_VER_27: |
| 1336 | case RTL_GIGA_MAC_VER_28: |
| 1337 | case RTL_GIGA_MAC_VER_31: |
| 1338 | rtl8168dp_driver_stop(tp); |
| 1339 | break; |
| 1340 | case RTL_GIGA_MAC_VER_49: |
| 1341 | case RTL_GIGA_MAC_VER_50: |
| 1342 | case RTL_GIGA_MAC_VER_51: |
| 1343 | rtl8168ep_driver_stop(tp); |
| 1344 | break; |
| 1345 | default: |
| 1346 | BUG(); |
| 1347 | break; |
| 1348 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1349 | } |
| 1350 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1351 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1352 | { |
| 1353 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1354 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1355 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1358 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1359 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1360 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1361 | } |
| 1362 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1363 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1364 | { |
| 1365 | switch (tp->mac_version) { |
| 1366 | case RTL_GIGA_MAC_VER_27: |
| 1367 | case RTL_GIGA_MAC_VER_28: |
| 1368 | case RTL_GIGA_MAC_VER_31: |
| 1369 | return r8168dp_check_dash(tp); |
| 1370 | case RTL_GIGA_MAC_VER_49: |
| 1371 | case RTL_GIGA_MAC_VER_50: |
| 1372 | case RTL_GIGA_MAC_VER_51: |
| 1373 | return r8168ep_check_dash(tp); |
| 1374 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1375 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1379 | struct exgmac_reg { |
| 1380 | u16 addr; |
| 1381 | u16 mask; |
| 1382 | u32 val; |
| 1383 | }; |
| 1384 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1385 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1386 | const struct exgmac_reg *r, int len) |
| 1387 | { |
| 1388 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1389 | rtl_eri_write(tp, r->addr, r->mask, r->val, ERIAR_EXGMAC); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1390 | r++; |
| 1391 | } |
| 1392 | } |
| 1393 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1394 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1395 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1396 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1399 | static u8 rtl8168d_efuse_read(struct rtl8169_private *tp, int reg_addr) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1400 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1401 | RTL_W32(tp, EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1402 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1403 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1404 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1407 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1408 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1409 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1413 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1414 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1415 | mmiowb(); |
| 1416 | } |
| 1417 | |
| 1418 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1419 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1420 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1421 | mmiowb(); |
| 1422 | } |
| 1423 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1424 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1425 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1426 | RTL_W16(tp, IntrMask, bits); |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1429 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1430 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1431 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1432 | |
| 1433 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1434 | { |
| 1435 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1436 | } |
| 1437 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1438 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1440 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1441 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1442 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1445 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1447 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1450 | static unsigned int rtl8169_xmii_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1452 | return RTL_R8(tp, PHYstatus) & LinkStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1455 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | unsigned int val; |
| 1458 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1459 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1460 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1463 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1464 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1465 | struct net_device *dev = tp->dev; |
| 1466 | |
| 1467 | if (!netif_running(dev)) |
| 1468 | return; |
| 1469 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1470 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1471 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1472 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1473 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1474 | ERIAR_EXGMAC); |
| 1475 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1476 | ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1477 | } else if (RTL_R8(tp, PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1478 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1479 | ERIAR_EXGMAC); |
| 1480 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1481 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1482 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1483 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1484 | ERIAR_EXGMAC); |
| 1485 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1486 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1487 | } |
| 1488 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1489 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1490 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1491 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1492 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1493 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1494 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1495 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1496 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1497 | ERIAR_EXGMAC); |
| 1498 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1499 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1500 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1501 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1502 | ERIAR_EXGMAC); |
| 1503 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1504 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1505 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1506 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1507 | if (RTL_R8(tp, PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1508 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1509 | ERIAR_EXGMAC); |
| 1510 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1511 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1512 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1513 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1514 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1515 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1516 | } |
| 1517 | } |
| 1518 | |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1519 | static void rtl8169_check_link_status(struct net_device *dev, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1520 | struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1522 | struct device *d = tp_to_dev(tp); |
| 1523 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 1524 | if (rtl8169_xmii_link_ok(tp)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1525 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1526 | /* This is to cancel a scheduled suspend if there's one. */ |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1527 | pm_request_resume(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1529 | if (net_ratelimit()) |
| 1530 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1531 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1533 | netif_info(tp, ifdown, dev, "link down\n"); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1534 | pm_runtime_idle(d); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1538 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1539 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1540 | /* Currently we only enable WoL if explicitly told by userspace to circumvent |
| 1541 | * issues on certain platforms, see commit bde135a672bf ("r8169: only enable |
| 1542 | * PCI wakeups when WOL is active"). Let's keep __rtl8169_get_wol() for the |
| 1543 | * case that we want to respect BIOS settings again. |
| 1544 | */ |
| 1545 | #if 0 |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1546 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1547 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1548 | u8 options; |
| 1549 | u32 wolopts = 0; |
| 1550 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1551 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1552 | if (!(options & PMEnable)) |
| 1553 | return 0; |
| 1554 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1555 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1556 | if (options & LinkUp) |
| 1557 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1558 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1559 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1560 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1561 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1562 | wolopts |= WAKE_MAGIC; |
| 1563 | break; |
| 1564 | default: |
| 1565 | if (options & MagicPacket) |
| 1566 | wolopts |= WAKE_MAGIC; |
| 1567 | break; |
| 1568 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1569 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1570 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1571 | if (options & UWF) |
| 1572 | wolopts |= WAKE_UCAST; |
| 1573 | if (options & BWF) |
| 1574 | wolopts |= WAKE_BCAST; |
| 1575 | if (options & MWF) |
| 1576 | wolopts |= WAKE_MCAST; |
| 1577 | |
| 1578 | return wolopts; |
| 1579 | } |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1580 | #endif |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1581 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1582 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1583 | { |
| 1584 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1585 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1586 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1587 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1588 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1589 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1590 | } |
| 1591 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1592 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1593 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1594 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1595 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1596 | u32 opt; |
| 1597 | u16 reg; |
| 1598 | u8 mask; |
| 1599 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1600 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1601 | { WAKE_UCAST, Config5, UWF }, |
| 1602 | { WAKE_BCAST, Config5, BWF }, |
| 1603 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1604 | { WAKE_ANY, Config5, LanWake }, |
| 1605 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1606 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1607 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1608 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1609 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1610 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1611 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1612 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1613 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1614 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1615 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1616 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1617 | 0x0dc, |
| 1618 | ERIAR_MASK_0100, |
| 1619 | MagicPacket_v2, |
| 1620 | 0x0000, |
| 1621 | ERIAR_EXGMAC); |
| 1622 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1623 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1624 | 0x0dc, |
| 1625 | ERIAR_MASK_0100, |
| 1626 | 0x0000, |
| 1627 | MagicPacket_v2, |
| 1628 | ERIAR_EXGMAC); |
| 1629 | break; |
| 1630 | default: |
| 1631 | tmp = ARRAY_SIZE(cfg); |
| 1632 | break; |
| 1633 | } |
| 1634 | |
| 1635 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1636 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1637 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1638 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1639 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1642 | switch (tp->mac_version) { |
| 1643 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1644 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1645 | if (wolopts) |
| 1646 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1647 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1648 | break; |
| 1649 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1650 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1651 | if (wolopts) |
| 1652 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1653 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1654 | break; |
| 1655 | } |
| 1656 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1657 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1661 | { |
| 1662 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1663 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1664 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1665 | if (wol->wolopts & ~WAKE_ANY) |
| 1666 | return -EINVAL; |
| 1667 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1668 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1669 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1670 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1671 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1672 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1673 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1674 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1675 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1676 | |
| 1677 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1678 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1679 | device_set_wakeup_enable(d, tp->saved_wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1680 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1681 | pm_runtime_put_noidle(d); |
| 1682 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1686 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1687 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1688 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1689 | } |
| 1690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1692 | struct ethtool_drvinfo *info) |
| 1693 | { |
| 1694 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1695 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1697 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1698 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1699 | strlcpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1700 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1701 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1702 | strlcpy(info->fw_version, rtl_fw->version, |
| 1703 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1707 | { |
| 1708 | return R8169_REGS_SIZE; |
| 1709 | } |
| 1710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1712 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | { |
| 1714 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1715 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1716 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1718 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
| 1720 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1721 | int auto_nego; |
| 1722 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1723 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1724 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1725 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1726 | |
| 1727 | if (adv & ADVERTISED_10baseT_Half) |
| 1728 | auto_nego |= ADVERTISE_10HALF; |
| 1729 | if (adv & ADVERTISED_10baseT_Full) |
| 1730 | auto_nego |= ADVERTISE_10FULL; |
| 1731 | if (adv & ADVERTISED_100baseT_Half) |
| 1732 | auto_nego |= ADVERTISE_100HALF; |
| 1733 | if (adv & ADVERTISED_100baseT_Full) |
| 1734 | auto_nego |= ADVERTISE_100FULL; |
| 1735 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1736 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1737 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1738 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1739 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1740 | |
| 1741 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1742 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1743 | if (adv & ADVERTISED_1000baseT_Half) |
| 1744 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1745 | if (adv & ADVERTISED_1000baseT_Full) |
| 1746 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1747 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1748 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1749 | netif_info(tp, link, dev, |
| 1750 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1751 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1754 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1755 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1756 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1757 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1758 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1759 | if (speed == SPEED_10) |
| 1760 | bmcr = 0; |
| 1761 | else if (speed == SPEED_100) |
| 1762 | bmcr = BMCR_SPEED100; |
| 1763 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1764 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1765 | |
| 1766 | if (duplex == DUPLEX_FULL) |
| 1767 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1768 | } |
| 1769 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1770 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1771 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1772 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1773 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1774 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1775 | rtl_writephy(tp, 0x17, 0x2138); |
| 1776 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1777 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1778 | rtl_writephy(tp, 0x17, 0x2108); |
| 1779 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1780 | } |
| 1781 | } |
| 1782 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1783 | rc = 0; |
| 1784 | out: |
| 1785 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1789 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | { |
| 1791 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1792 | int ret; |
| 1793 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 1794 | ret = rtl8169_set_speed_xmii(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1795 | if (ret < 0) |
| 1796 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1798 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 1799 | (advertising & ADVERTISED_1000baseT_Full) && |
| 1800 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1802 | } |
| 1803 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | return ret; |
| 1805 | } |
| 1806 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1807 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1808 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1810 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1811 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1812 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1813 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1815 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1816 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1817 | features &= ~NETIF_F_IP_CSUM; |
| 1818 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1819 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1822 | static int rtl8169_set_features(struct net_device *dev, |
| 1823 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
| 1825 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1826 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1828 | rtl_lock_work(tp); |
| 1829 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1830 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1831 | if (features & NETIF_F_RXALL) |
| 1832 | rx_config |= (AcceptErr | AcceptRunt); |
| 1833 | else |
| 1834 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1836 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1837 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1838 | if (features & NETIF_F_RXCSUM) |
| 1839 | tp->cp_cmd |= RxChkSum; |
| 1840 | else |
| 1841 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1842 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1843 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1844 | tp->cp_cmd |= RxVlan; |
| 1845 | else |
| 1846 | tp->cp_cmd &= ~RxVlan; |
| 1847 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1848 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1849 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1851 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | return 0; |
| 1854 | } |
| 1855 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1856 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1858 | return (skb_vlan_tag_present(skb)) ? |
| 1859 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1862 | static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | { |
| 1864 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1866 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1867 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 1870 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 1871 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
| 1873 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 1875 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 1876 | |
| 1877 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 1880 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 1881 | const struct ethtool_link_ksettings *cmd) |
| 1882 | { |
| 1883 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1884 | int rc; |
| 1885 | u32 advertising; |
| 1886 | |
| 1887 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 1888 | cmd->link_modes.advertising)) |
| 1889 | return -EINVAL; |
| 1890 | |
| 1891 | del_timer_sync(&tp->timer); |
| 1892 | |
| 1893 | rtl_lock_work(tp); |
| 1894 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 1895 | cmd->base.duplex, advertising); |
| 1896 | rtl_unlock_work(tp); |
| 1897 | |
| 1898 | return rc; |
| 1899 | } |
| 1900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1902 | void *p) |
| 1903 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1904 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1905 | u32 __iomem *data = tp->mmio_addr; |
| 1906 | u32 *dw = p; |
| 1907 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1909 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1910 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1911 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1912 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1915 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1916 | { |
| 1917 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1918 | |
| 1919 | return tp->msg_enable; |
| 1920 | } |
| 1921 | |
| 1922 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1923 | { |
| 1924 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1925 | |
| 1926 | tp->msg_enable = value; |
| 1927 | } |
| 1928 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1929 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1930 | "tx_packets", |
| 1931 | "rx_packets", |
| 1932 | "tx_errors", |
| 1933 | "rx_errors", |
| 1934 | "rx_missed", |
| 1935 | "align_errors", |
| 1936 | "tx_single_collisions", |
| 1937 | "tx_multi_collisions", |
| 1938 | "unicast", |
| 1939 | "broadcast", |
| 1940 | "multicast", |
| 1941 | "tx_aborted", |
| 1942 | "tx_underrun", |
| 1943 | }; |
| 1944 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1945 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1946 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1947 | switch (sset) { |
| 1948 | case ETH_SS_STATS: |
| 1949 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1950 | default: |
| 1951 | return -EOPNOTSUPP; |
| 1952 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1953 | } |
| 1954 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1955 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1956 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1957 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1960 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1961 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1962 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1963 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1964 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1965 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1966 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1967 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1968 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1969 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1970 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1971 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1972 | } |
| 1973 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1974 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1975 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1976 | /* |
| 1977 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1978 | * tally counters. |
| 1979 | */ |
| 1980 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1981 | return true; |
| 1982 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1983 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1984 | } |
| 1985 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1986 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1987 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1988 | /* |
| 1989 | * Some chips are unable to dump tally counters when the receiver |
| 1990 | * is disabled. |
| 1991 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1992 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1993 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1994 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1995 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1996 | } |
| 1997 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1998 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1999 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2000 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2001 | bool ret = false; |
| 2002 | |
| 2003 | /* |
| 2004 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2005 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2006 | * reset by a power cycle, while the counter values collected by the |
| 2007 | * driver are reset at every driver unload/load cycle. |
| 2008 | * |
| 2009 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2010 | * values, we collect the initial values at first open(*) and use them |
| 2011 | * as offsets to normalize the values returned by @get_stats64. |
| 2012 | * |
| 2013 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2014 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2015 | * set at open time by rtl_hw_start. |
| 2016 | */ |
| 2017 | |
| 2018 | if (tp->tc_offset.inited) |
| 2019 | return true; |
| 2020 | |
| 2021 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2022 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2023 | ret = true; |
| 2024 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2025 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2026 | ret = true; |
| 2027 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2028 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2029 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2030 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2031 | tp->tc_offset.inited = true; |
| 2032 | |
| 2033 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2034 | } |
| 2035 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2036 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2037 | struct ethtool_stats *stats, u64 *data) |
| 2038 | { |
| 2039 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 2040 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2041 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2042 | |
| 2043 | ASSERT_RTNL(); |
| 2044 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2045 | pm_runtime_get_noresume(d); |
| 2046 | |
| 2047 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2048 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2049 | |
| 2050 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2051 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2052 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2053 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2054 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2055 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2056 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2057 | data[5] = le16_to_cpu(counters->align_errors); |
| 2058 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2059 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2060 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2061 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2062 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2063 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2064 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2065 | } |
| 2066 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2067 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2068 | { |
| 2069 | switch(stringset) { |
| 2070 | case ETH_SS_STATS: |
| 2071 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2072 | break; |
| 2073 | } |
| 2074 | } |
| 2075 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2076 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2077 | { |
| 2078 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2079 | |
| 2080 | return mii_nway_restart(&tp->mii); |
| 2081 | } |
| 2082 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2083 | /* |
| 2084 | * Interrupt coalescing |
| 2085 | * |
| 2086 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2087 | * > 8169, 8168 and 810x line of chipsets |
| 2088 | * |
| 2089 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2090 | * |
| 2091 | * > 2 - the Tx timer unit at gigabit speed |
| 2092 | * |
| 2093 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2094 | * (0xe0) bit 1 and bit 0. |
| 2095 | * |
| 2096 | * For 8169 |
| 2097 | * bit[1:0] \ speed 1000M 100M 10M |
| 2098 | * 0 0 320ns 2.56us 40.96us |
| 2099 | * 0 1 2.56us 20.48us 327.7us |
| 2100 | * 1 0 5.12us 40.96us 655.4us |
| 2101 | * 1 1 10.24us 81.92us 1.31ms |
| 2102 | * |
| 2103 | * For the other |
| 2104 | * bit[1:0] \ speed 1000M 100M 10M |
| 2105 | * 0 0 5us 2.56us 40.96us |
| 2106 | * 0 1 40us 20.48us 327.7us |
| 2107 | * 1 0 80us 40.96us 655.4us |
| 2108 | * 1 1 160us 81.92us 1.31ms |
| 2109 | */ |
| 2110 | |
| 2111 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2112 | struct rtl_coalesce_scale { |
| 2113 | /* Rx / Tx */ |
| 2114 | u32 nsecs[2]; |
| 2115 | }; |
| 2116 | |
| 2117 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2118 | struct rtl_coalesce_info { |
| 2119 | u32 speed; |
| 2120 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2121 | }; |
| 2122 | |
| 2123 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2124 | #define rxtx_x1822(r, t) { \ |
| 2125 | {{(r), (t)}}, \ |
| 2126 | {{(r)*8, (t)*8}}, \ |
| 2127 | {{(r)*8*2, (t)*8*2}}, \ |
| 2128 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2129 | } |
| 2130 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2131 | /* speed delays: rx00 tx00 */ |
| 2132 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2133 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2134 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2135 | { 0 }, |
| 2136 | }; |
| 2137 | |
| 2138 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2139 | /* speed delays: rx00 tx00 */ |
| 2140 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2141 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2142 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2143 | { 0 }, |
| 2144 | }; |
| 2145 | #undef rxtx_x1822 |
| 2146 | |
| 2147 | /* get rx/tx scale vector corresponding to current speed */ |
| 2148 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2149 | { |
| 2150 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2151 | struct ethtool_link_ksettings ecmd; |
| 2152 | const struct rtl_coalesce_info *ci; |
| 2153 | int rc; |
| 2154 | |
| 2155 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2156 | if (rc < 0) |
| 2157 | return ERR_PTR(rc); |
| 2158 | |
| 2159 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2160 | if (ecmd.base.speed == ci->speed) { |
| 2161 | return ci; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | return ERR_PTR(-ELNRNG); |
| 2166 | } |
| 2167 | |
| 2168 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2169 | { |
| 2170 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2171 | const struct rtl_coalesce_info *ci; |
| 2172 | const struct rtl_coalesce_scale *scale; |
| 2173 | struct { |
| 2174 | u32 *max_frames; |
| 2175 | u32 *usecs; |
| 2176 | } coal_settings [] = { |
| 2177 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2178 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2179 | }, *p = coal_settings; |
| 2180 | int i; |
| 2181 | u16 w; |
| 2182 | |
| 2183 | memset(ec, 0, sizeof(*ec)); |
| 2184 | |
| 2185 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2186 | ci = rtl_coalesce_info(dev); |
| 2187 | if (IS_ERR(ci)) |
| 2188 | return PTR_ERR(ci); |
| 2189 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 2190 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2191 | |
| 2192 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2193 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2194 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2195 | w >>= RTL_COALESCE_SHIFT; |
| 2196 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2197 | } |
| 2198 | |
| 2199 | for (i = 0; i < 2; i++) { |
| 2200 | p = coal_settings + i; |
| 2201 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2202 | |
| 2203 | /* |
| 2204 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2205 | * max_frames to 0. |
| 2206 | */ |
| 2207 | if (!*p->usecs && !*p->max_frames) |
| 2208 | *p->max_frames = 1; |
| 2209 | } |
| 2210 | |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
| 2214 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2215 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2216 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2217 | { |
| 2218 | const struct rtl_coalesce_info *ci; |
| 2219 | u16 i; |
| 2220 | |
| 2221 | ci = rtl_coalesce_info(dev); |
| 2222 | if (IS_ERR(ci)) |
| 2223 | return ERR_CAST(ci); |
| 2224 | |
| 2225 | for (i = 0; i < 4; i++) { |
| 2226 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2227 | ci->scalev[i].nsecs[1]); |
| 2228 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2229 | *cp01 = i; |
| 2230 | return &ci->scalev[i]; |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | return ERR_PTR(-EINVAL); |
| 2235 | } |
| 2236 | |
| 2237 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2238 | { |
| 2239 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2240 | const struct rtl_coalesce_scale *scale; |
| 2241 | struct { |
| 2242 | u32 frames; |
| 2243 | u32 usecs; |
| 2244 | } coal_settings [] = { |
| 2245 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2246 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2247 | }, *p = coal_settings; |
| 2248 | u16 w = 0, cp01; |
| 2249 | int i; |
| 2250 | |
| 2251 | scale = rtl_coalesce_choose_scale(dev, |
| 2252 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2253 | if (IS_ERR(scale)) |
| 2254 | return PTR_ERR(scale); |
| 2255 | |
| 2256 | for (i = 0; i < 2; i++, p++) { |
| 2257 | u32 units; |
| 2258 | |
| 2259 | /* |
| 2260 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2261 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2262 | * |
| 2263 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2264 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2265 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2266 | * |
| 2267 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2268 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2269 | * we'll reject it below in `frames % 4 != 0`. |
| 2270 | */ |
| 2271 | if (p->frames == 1) { |
| 2272 | p->frames = 0; |
| 2273 | } |
| 2274 | |
| 2275 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2276 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2277 | return -EINVAL; |
| 2278 | |
| 2279 | w <<= RTL_COALESCE_SHIFT; |
| 2280 | w |= units; |
| 2281 | w <<= RTL_COALESCE_SHIFT; |
| 2282 | w |= p->frames >> 2; |
| 2283 | } |
| 2284 | |
| 2285 | rtl_lock_work(tp); |
| 2286 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2287 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2288 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 2289 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2290 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2291 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2292 | |
| 2293 | rtl_unlock_work(tp); |
| 2294 | |
| 2295 | return 0; |
| 2296 | } |
| 2297 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2298 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2300 | .get_regs_len = rtl8169_get_regs_len, |
| 2301 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2302 | .get_coalesce = rtl_get_coalesce, |
| 2303 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2304 | .get_msglevel = rtl8169_get_msglevel, |
| 2305 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2307 | .get_wol = rtl8169_get_wol, |
| 2308 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2309 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2310 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2311 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2312 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2313 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2314 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2315 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | }; |
| 2317 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2318 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2319 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2321 | /* |
| 2322 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2323 | * but they can be identified more specifically through the test below |
| 2324 | * if needed: |
| 2325 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2326 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2327 | * |
| 2328 | * Same thing for the 8101Eb and the 8101Ec: |
| 2329 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2330 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2331 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2332 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2334 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | int mac_version; |
| 2336 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2337 | /* 8168EP family. */ |
| 2338 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2339 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2340 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2341 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2342 | /* 8168H family. */ |
| 2343 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2344 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2345 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2346 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2347 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2348 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2349 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2350 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2351 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2352 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2353 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2354 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2355 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2356 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2357 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2358 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2359 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2360 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2361 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2362 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2363 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2364 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2365 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2366 | /* 8168DP family. */ |
| 2367 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2368 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2369 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2370 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2371 | /* 8168C family. */ |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2372 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2373 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2374 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2375 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2376 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2377 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2378 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2379 | |
| 2380 | /* 8168B family. */ |
| 2381 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2382 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2383 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2384 | |
| 2385 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2386 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2387 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2388 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2389 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2390 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2391 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2392 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2393 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2394 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2395 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2396 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2397 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2398 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2399 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2400 | /* FIXME: where did these entries come from ? -- FR */ |
| 2401 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2402 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2403 | |
| 2404 | /* 8110 family. */ |
| 2405 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2406 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2407 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2408 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2409 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2410 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2411 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2412 | /* Catch-all */ |
| 2413 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2414 | }; |
| 2415 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | u32 reg; |
| 2417 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2418 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2419 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | p++; |
| 2421 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2422 | |
| 2423 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2424 | dev_notice(tp_to_dev(tp), |
| 2425 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2426 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2427 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2428 | tp->mac_version = tp->mii.supports_gmii ? |
| 2429 | RTL_GIGA_MAC_VER_42 : |
| 2430 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2431 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2432 | tp->mac_version = tp->mii.supports_gmii ? |
| 2433 | RTL_GIGA_MAC_VER_45 : |
| 2434 | RTL_GIGA_MAC_VER_47; |
| 2435 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2436 | tp->mac_version = tp->mii.supports_gmii ? |
| 2437 | RTL_GIGA_MAC_VER_46 : |
| 2438 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2443 | { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 2444 | netif_dbg(tp, drv, tp->dev, "mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2447 | struct phy_reg { |
| 2448 | u16 reg; |
| 2449 | u16 val; |
| 2450 | }; |
| 2451 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2452 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2453 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2454 | { |
| 2455 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2456 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2457 | regs++; |
| 2458 | } |
| 2459 | } |
| 2460 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2461 | #define PHY_READ 0x00000000 |
| 2462 | #define PHY_DATA_OR 0x10000000 |
| 2463 | #define PHY_DATA_AND 0x20000000 |
| 2464 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2465 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2466 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2467 | #define PHY_WRITE 0x80000000 |
| 2468 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2469 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2470 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2471 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2472 | #define PHY_SKIPN 0xd0000000 |
| 2473 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2474 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2475 | struct fw_info { |
| 2476 | u32 magic; |
| 2477 | char version[RTL_VER_SIZE]; |
| 2478 | __le32 fw_start; |
| 2479 | __le32 fw_len; |
| 2480 | u8 chksum; |
| 2481 | } __packed; |
| 2482 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2483 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2484 | |
| 2485 | static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2486 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2487 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2488 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2489 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2490 | char *version = rtl_fw->version; |
| 2491 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2492 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2493 | if (fw->size < FW_OPCODE_SIZE) |
| 2494 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2495 | |
| 2496 | if (!fw_info->magic) { |
| 2497 | size_t i, size, start; |
| 2498 | u8 checksum = 0; |
| 2499 | |
| 2500 | if (fw->size < sizeof(*fw_info)) |
| 2501 | goto out; |
| 2502 | |
| 2503 | for (i = 0; i < fw->size; i++) |
| 2504 | checksum += fw->data[i]; |
| 2505 | if (checksum != 0) |
| 2506 | goto out; |
| 2507 | |
| 2508 | start = le32_to_cpu(fw_info->fw_start); |
| 2509 | if (start > fw->size) |
| 2510 | goto out; |
| 2511 | |
| 2512 | size = le32_to_cpu(fw_info->fw_len); |
| 2513 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2514 | goto out; |
| 2515 | |
| 2516 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2517 | |
| 2518 | pa->code = (__le32 *)(fw->data + start); |
| 2519 | pa->size = size; |
| 2520 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2521 | if (fw->size % FW_OPCODE_SIZE) |
| 2522 | goto out; |
| 2523 | |
| 2524 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2525 | |
| 2526 | pa->code = (__le32 *)fw->data; |
| 2527 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2528 | } |
| 2529 | version[RTL_VER_SIZE - 1] = 0; |
| 2530 | |
| 2531 | rc = true; |
| 2532 | out: |
| 2533 | return rc; |
| 2534 | } |
| 2535 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2536 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2537 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2538 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2539 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2540 | size_t index; |
| 2541 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2542 | for (index = 0; index < pa->size; index++) { |
| 2543 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2544 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2545 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2546 | switch(action & 0xf0000000) { |
| 2547 | case PHY_READ: |
| 2548 | case PHY_DATA_OR: |
| 2549 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2550 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2551 | case PHY_CLEAR_READCOUNT: |
| 2552 | case PHY_WRITE: |
| 2553 | case PHY_WRITE_PREVIOUS: |
| 2554 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2557 | case PHY_BJMPN: |
| 2558 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2559 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2560 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2561 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2562 | } |
| 2563 | break; |
| 2564 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2565 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2566 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2567 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2568 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2569 | } |
| 2570 | break; |
| 2571 | case PHY_COMP_EQ_SKIPN: |
| 2572 | case PHY_COMP_NEQ_SKIPN: |
| 2573 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2574 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2575 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2576 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2577 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2578 | } |
| 2579 | break; |
| 2580 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2581 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2582 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2583 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2584 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2585 | } |
| 2586 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2587 | rc = true; |
| 2588 | out: |
| 2589 | return rc; |
| 2590 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2591 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2592 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2593 | { |
| 2594 | struct net_device *dev = tp->dev; |
| 2595 | int rc = -EINVAL; |
| 2596 | |
| 2597 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2598 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2599 | goto out; |
| 2600 | } |
| 2601 | |
| 2602 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2603 | rc = 0; |
| 2604 | out: |
| 2605 | return rc; |
| 2606 | } |
| 2607 | |
| 2608 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2609 | { |
| 2610 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2611 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2612 | u32 predata, count; |
| 2613 | size_t index; |
| 2614 | |
| 2615 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2616 | org.write = ops->write; |
| 2617 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2618 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2619 | for (index = 0; index < pa->size; ) { |
| 2620 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2621 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2622 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2623 | |
| 2624 | if (!action) |
| 2625 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2626 | |
| 2627 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2628 | case PHY_READ: |
| 2629 | predata = rtl_readphy(tp, regno); |
| 2630 | count++; |
| 2631 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2632 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2633 | case PHY_DATA_OR: |
| 2634 | predata |= data; |
| 2635 | index++; |
| 2636 | break; |
| 2637 | case PHY_DATA_AND: |
| 2638 | predata &= data; |
| 2639 | index++; |
| 2640 | break; |
| 2641 | case PHY_BJMPN: |
| 2642 | index -= regno; |
| 2643 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2644 | case PHY_MDIO_CHG: |
| 2645 | if (data == 0) { |
| 2646 | ops->write = org.write; |
| 2647 | ops->read = org.read; |
| 2648 | } else if (data == 1) { |
| 2649 | ops->write = mac_mcu_write; |
| 2650 | ops->read = mac_mcu_read; |
| 2651 | } |
| 2652 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2653 | index++; |
| 2654 | break; |
| 2655 | case PHY_CLEAR_READCOUNT: |
| 2656 | count = 0; |
| 2657 | index++; |
| 2658 | break; |
| 2659 | case PHY_WRITE: |
| 2660 | rtl_writephy(tp, regno, data); |
| 2661 | index++; |
| 2662 | break; |
| 2663 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2664 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2665 | break; |
| 2666 | case PHY_COMP_EQ_SKIPN: |
| 2667 | if (predata == data) |
| 2668 | index += regno; |
| 2669 | index++; |
| 2670 | break; |
| 2671 | case PHY_COMP_NEQ_SKIPN: |
| 2672 | if (predata != data) |
| 2673 | index += regno; |
| 2674 | index++; |
| 2675 | break; |
| 2676 | case PHY_WRITE_PREVIOUS: |
| 2677 | rtl_writephy(tp, regno, predata); |
| 2678 | index++; |
| 2679 | break; |
| 2680 | case PHY_SKIPN: |
| 2681 | index += regno + 1; |
| 2682 | break; |
| 2683 | case PHY_DELAY_MS: |
| 2684 | mdelay(data); |
| 2685 | index++; |
| 2686 | break; |
| 2687 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2688 | default: |
| 2689 | BUG(); |
| 2690 | } |
| 2691 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2692 | |
| 2693 | ops->write = org.write; |
| 2694 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2697 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2698 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2699 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2700 | release_firmware(tp->rtl_fw->fw); |
| 2701 | kfree(tp->rtl_fw); |
| 2702 | } |
| 2703 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2704 | } |
| 2705 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2706 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2707 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2708 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2709 | |
| 2710 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2711 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2712 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2716 | { |
| 2717 | if (rtl_readphy(tp, reg) != val) |
| 2718 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2719 | else |
| 2720 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2723 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2725 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2726 | { 0x1f, 0x0001 }, |
| 2727 | { 0x06, 0x006e }, |
| 2728 | { 0x08, 0x0708 }, |
| 2729 | { 0x15, 0x4000 }, |
| 2730 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2732 | { 0x1f, 0x0001 }, |
| 2733 | { 0x03, 0x00a1 }, |
| 2734 | { 0x02, 0x0008 }, |
| 2735 | { 0x01, 0x0120 }, |
| 2736 | { 0x00, 0x1000 }, |
| 2737 | { 0x04, 0x0800 }, |
| 2738 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2740 | { 0x03, 0xff41 }, |
| 2741 | { 0x02, 0xdf60 }, |
| 2742 | { 0x01, 0x0140 }, |
| 2743 | { 0x00, 0x0077 }, |
| 2744 | { 0x04, 0x7800 }, |
| 2745 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2747 | { 0x03, 0x802f }, |
| 2748 | { 0x02, 0x4f02 }, |
| 2749 | { 0x01, 0x0409 }, |
| 2750 | { 0x00, 0xf0f9 }, |
| 2751 | { 0x04, 0x9800 }, |
| 2752 | { 0x04, 0x9000 }, |
| 2753 | |
| 2754 | { 0x03, 0xdf01 }, |
| 2755 | { 0x02, 0xdf20 }, |
| 2756 | { 0x01, 0xff95 }, |
| 2757 | { 0x00, 0xba00 }, |
| 2758 | { 0x04, 0xa800 }, |
| 2759 | { 0x04, 0xa000 }, |
| 2760 | |
| 2761 | { 0x03, 0xff41 }, |
| 2762 | { 0x02, 0xdf20 }, |
| 2763 | { 0x01, 0x0140 }, |
| 2764 | { 0x00, 0x00bb }, |
| 2765 | { 0x04, 0xb800 }, |
| 2766 | { 0x04, 0xb000 }, |
| 2767 | |
| 2768 | { 0x03, 0xdf41 }, |
| 2769 | { 0x02, 0xdc60 }, |
| 2770 | { 0x01, 0x6340 }, |
| 2771 | { 0x00, 0x007d }, |
| 2772 | { 0x04, 0xd800 }, |
| 2773 | { 0x04, 0xd000 }, |
| 2774 | |
| 2775 | { 0x03, 0xdf01 }, |
| 2776 | { 0x02, 0xdf20 }, |
| 2777 | { 0x01, 0x100a }, |
| 2778 | { 0x00, 0xa0ff }, |
| 2779 | { 0x04, 0xf800 }, |
| 2780 | { 0x04, 0xf000 }, |
| 2781 | |
| 2782 | { 0x1f, 0x0000 }, |
| 2783 | { 0x0b, 0x0000 }, |
| 2784 | { 0x00, 0x9200 } |
| 2785 | }; |
| 2786 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2787 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2790 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2791 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2792 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2793 | { 0x1f, 0x0002 }, |
| 2794 | { 0x01, 0x90d0 }, |
| 2795 | { 0x1f, 0x0000 } |
| 2796 | }; |
| 2797 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2798 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2799 | } |
| 2800 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2801 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2802 | { |
| 2803 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2804 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2805 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2806 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2807 | return; |
| 2808 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2809 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2810 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2811 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2814 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2815 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2816 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2817 | { 0x1f, 0x0001 }, |
| 2818 | { 0x04, 0x0000 }, |
| 2819 | { 0x03, 0x00a1 }, |
| 2820 | { 0x02, 0x0008 }, |
| 2821 | { 0x01, 0x0120 }, |
| 2822 | { 0x00, 0x1000 }, |
| 2823 | { 0x04, 0x0800 }, |
| 2824 | { 0x04, 0x9000 }, |
| 2825 | { 0x03, 0x802f }, |
| 2826 | { 0x02, 0x4f02 }, |
| 2827 | { 0x01, 0x0409 }, |
| 2828 | { 0x00, 0xf099 }, |
| 2829 | { 0x04, 0x9800 }, |
| 2830 | { 0x04, 0xa000 }, |
| 2831 | { 0x03, 0xdf01 }, |
| 2832 | { 0x02, 0xdf20 }, |
| 2833 | { 0x01, 0xff95 }, |
| 2834 | { 0x00, 0xba00 }, |
| 2835 | { 0x04, 0xa800 }, |
| 2836 | { 0x04, 0xf000 }, |
| 2837 | { 0x03, 0xdf01 }, |
| 2838 | { 0x02, 0xdf20 }, |
| 2839 | { 0x01, 0x101a }, |
| 2840 | { 0x00, 0xa0ff }, |
| 2841 | { 0x04, 0xf800 }, |
| 2842 | { 0x04, 0x0000 }, |
| 2843 | { 0x1f, 0x0000 }, |
| 2844 | |
| 2845 | { 0x1f, 0x0001 }, |
| 2846 | { 0x10, 0xf41b }, |
| 2847 | { 0x14, 0xfb54 }, |
| 2848 | { 0x18, 0xf5c7 }, |
| 2849 | { 0x1f, 0x0000 }, |
| 2850 | |
| 2851 | { 0x1f, 0x0001 }, |
| 2852 | { 0x17, 0x0cc0 }, |
| 2853 | { 0x1f, 0x0000 } |
| 2854 | }; |
| 2855 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2856 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2857 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2858 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2861 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2862 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2863 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2864 | { 0x1f, 0x0001 }, |
| 2865 | { 0x04, 0x0000 }, |
| 2866 | { 0x03, 0x00a1 }, |
| 2867 | { 0x02, 0x0008 }, |
| 2868 | { 0x01, 0x0120 }, |
| 2869 | { 0x00, 0x1000 }, |
| 2870 | { 0x04, 0x0800 }, |
| 2871 | { 0x04, 0x9000 }, |
| 2872 | { 0x03, 0x802f }, |
| 2873 | { 0x02, 0x4f02 }, |
| 2874 | { 0x01, 0x0409 }, |
| 2875 | { 0x00, 0xf099 }, |
| 2876 | { 0x04, 0x9800 }, |
| 2877 | { 0x04, 0xa000 }, |
| 2878 | { 0x03, 0xdf01 }, |
| 2879 | { 0x02, 0xdf20 }, |
| 2880 | { 0x01, 0xff95 }, |
| 2881 | { 0x00, 0xba00 }, |
| 2882 | { 0x04, 0xa800 }, |
| 2883 | { 0x04, 0xf000 }, |
| 2884 | { 0x03, 0xdf01 }, |
| 2885 | { 0x02, 0xdf20 }, |
| 2886 | { 0x01, 0x101a }, |
| 2887 | { 0x00, 0xa0ff }, |
| 2888 | { 0x04, 0xf800 }, |
| 2889 | { 0x04, 0x0000 }, |
| 2890 | { 0x1f, 0x0000 }, |
| 2891 | |
| 2892 | { 0x1f, 0x0001 }, |
| 2893 | { 0x0b, 0x8480 }, |
| 2894 | { 0x1f, 0x0000 }, |
| 2895 | |
| 2896 | { 0x1f, 0x0001 }, |
| 2897 | { 0x18, 0x67c7 }, |
| 2898 | { 0x04, 0x2000 }, |
| 2899 | { 0x03, 0x002f }, |
| 2900 | { 0x02, 0x4360 }, |
| 2901 | { 0x01, 0x0109 }, |
| 2902 | { 0x00, 0x3022 }, |
| 2903 | { 0x04, 0x2800 }, |
| 2904 | { 0x1f, 0x0000 }, |
| 2905 | |
| 2906 | { 0x1f, 0x0001 }, |
| 2907 | { 0x17, 0x0cc0 }, |
| 2908 | { 0x1f, 0x0000 } |
| 2909 | }; |
| 2910 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2911 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2912 | } |
| 2913 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2914 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2915 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2916 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2917 | { 0x10, 0xf41b }, |
| 2918 | { 0x1f, 0x0000 } |
| 2919 | }; |
| 2920 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2921 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2922 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2923 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2924 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2925 | } |
| 2926 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2927 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2928 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2929 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2930 | { 0x1f, 0x0001 }, |
| 2931 | { 0x10, 0xf41b }, |
| 2932 | { 0x1f, 0x0000 } |
| 2933 | }; |
| 2934 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2935 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2936 | } |
| 2937 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2938 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2939 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2940 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2941 | { 0x1f, 0x0000 }, |
| 2942 | { 0x1d, 0x0f00 }, |
| 2943 | { 0x1f, 0x0002 }, |
| 2944 | { 0x0c, 0x1ec8 }, |
| 2945 | { 0x1f, 0x0000 } |
| 2946 | }; |
| 2947 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2948 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2949 | } |
| 2950 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2951 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2952 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2953 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2954 | { 0x1f, 0x0001 }, |
| 2955 | { 0x1d, 0x3d98 }, |
| 2956 | { 0x1f, 0x0000 } |
| 2957 | }; |
| 2958 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2959 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2960 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2961 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2962 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2963 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2964 | } |
| 2965 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2966 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2967 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2968 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2969 | { 0x1f, 0x0001 }, |
| 2970 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2971 | { 0x1f, 0x0002 }, |
| 2972 | { 0x00, 0x88d4 }, |
| 2973 | { 0x01, 0x82b1 }, |
| 2974 | { 0x03, 0x7002 }, |
| 2975 | { 0x08, 0x9e30 }, |
| 2976 | { 0x09, 0x01f0 }, |
| 2977 | { 0x0a, 0x5500 }, |
| 2978 | { 0x0c, 0x00c8 }, |
| 2979 | { 0x1f, 0x0003 }, |
| 2980 | { 0x12, 0xc096 }, |
| 2981 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2982 | { 0x1f, 0x0000 }, |
| 2983 | { 0x1f, 0x0000 }, |
| 2984 | { 0x09, 0x2000 }, |
| 2985 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2986 | }; |
| 2987 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2988 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2989 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2990 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2991 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2992 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2993 | } |
| 2994 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2995 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2996 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2997 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2998 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2999 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3000 | { 0x03, 0x802f }, |
| 3001 | { 0x02, 0x4f02 }, |
| 3002 | { 0x01, 0x0409 }, |
| 3003 | { 0x00, 0xf099 }, |
| 3004 | { 0x04, 0x9800 }, |
| 3005 | { 0x04, 0x9000 }, |
| 3006 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3007 | { 0x1f, 0x0002 }, |
| 3008 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3009 | { 0x06, 0x0761 }, |
| 3010 | { 0x1f, 0x0003 }, |
| 3011 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3012 | { 0x1f, 0x0000 } |
| 3013 | }; |
| 3014 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3015 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3016 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3017 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3018 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3019 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3020 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3021 | } |
| 3022 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3023 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3024 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3025 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3026 | { 0x1f, 0x0001 }, |
| 3027 | { 0x12, 0x2300 }, |
| 3028 | { 0x1d, 0x3d98 }, |
| 3029 | { 0x1f, 0x0002 }, |
| 3030 | { 0x0c, 0x7eb8 }, |
| 3031 | { 0x06, 0x5461 }, |
| 3032 | { 0x1f, 0x0003 }, |
| 3033 | { 0x16, 0x0f0a }, |
| 3034 | { 0x1f, 0x0000 } |
| 3035 | }; |
| 3036 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3037 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3038 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3039 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3040 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3041 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3042 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3045 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3046 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3047 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3048 | } |
| 3049 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3050 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3051 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3052 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3053 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3054 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3055 | { 0x06, 0x4064 }, |
| 3056 | { 0x07, 0x2863 }, |
| 3057 | { 0x08, 0x059c }, |
| 3058 | { 0x09, 0x26b4 }, |
| 3059 | { 0x0a, 0x6a19 }, |
| 3060 | { 0x0b, 0xdcc8 }, |
| 3061 | { 0x10, 0xf06d }, |
| 3062 | { 0x14, 0x7f68 }, |
| 3063 | { 0x18, 0x7fd9 }, |
| 3064 | { 0x1c, 0xf0ff }, |
| 3065 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3066 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3067 | { 0x12, 0xf49f }, |
| 3068 | { 0x13, 0x070b }, |
| 3069 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3070 | { 0x14, 0x94c0 }, |
| 3071 | |
| 3072 | /* |
| 3073 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3074 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3075 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3076 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3077 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3078 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3079 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3080 | { 0x06, 0x5561 }, |
| 3081 | |
| 3082 | /* |
| 3083 | * Can not link to 1Gbps with bad cable |
| 3084 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3085 | */ |
| 3086 | { 0x1f, 0x0001 }, |
| 3087 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3088 | |
| 3089 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3090 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3091 | }; |
| 3092 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3093 | rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3094 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3095 | /* |
| 3096 | * Rx Error Issue |
| 3097 | * Fine Tune Switching regulator parameter |
| 3098 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3099 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3100 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3101 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3102 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3103 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3104 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3105 | { 0x1f, 0x0002 }, |
| 3106 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3107 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3108 | { 0x05, 0x8330 }, |
| 3109 | { 0x06, 0x669a }, |
| 3110 | { 0x1f, 0x0002 } |
| 3111 | }; |
| 3112 | int val; |
| 3113 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3114 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3115 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3116 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3117 | |
| 3118 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3119 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3120 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3121 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3122 | }; |
| 3123 | int i; |
| 3124 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3125 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3126 | |
| 3127 | val &= 0xff00; |
| 3128 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3129 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3130 | } |
| 3131 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3132 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3133 | { 0x1f, 0x0002 }, |
| 3134 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3135 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3136 | { 0x05, 0x8330 }, |
| 3137 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3138 | }; |
| 3139 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3140 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3141 | } |
| 3142 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3143 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3144 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3145 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3146 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3147 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3148 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3149 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3150 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3151 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3152 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3153 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3154 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3155 | |
| 3156 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3157 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3158 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3161 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3162 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3163 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3164 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3165 | { 0x1f, 0x0001 }, |
| 3166 | { 0x06, 0x4064 }, |
| 3167 | { 0x07, 0x2863 }, |
| 3168 | { 0x08, 0x059c }, |
| 3169 | { 0x09, 0x26b4 }, |
| 3170 | { 0x0a, 0x6a19 }, |
| 3171 | { 0x0b, 0xdcc8 }, |
| 3172 | { 0x10, 0xf06d }, |
| 3173 | { 0x14, 0x7f68 }, |
| 3174 | { 0x18, 0x7fd9 }, |
| 3175 | { 0x1c, 0xf0ff }, |
| 3176 | { 0x1d, 0x3d9c }, |
| 3177 | { 0x1f, 0x0003 }, |
| 3178 | { 0x12, 0xf49f }, |
| 3179 | { 0x13, 0x070b }, |
| 3180 | { 0x1a, 0x05ad }, |
| 3181 | { 0x14, 0x94c0 }, |
| 3182 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3183 | /* |
| 3184 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3185 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3186 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3187 | { 0x1f, 0x0002 }, |
| 3188 | { 0x06, 0x5561 }, |
| 3189 | { 0x1f, 0x0005 }, |
| 3190 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3191 | { 0x06, 0x5561 }, |
| 3192 | |
| 3193 | /* |
| 3194 | * Can not link to 1Gbps with bad cable |
| 3195 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3196 | */ |
| 3197 | { 0x1f, 0x0001 }, |
| 3198 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3199 | |
| 3200 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3201 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3202 | }; |
| 3203 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3204 | rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3205 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3206 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3207 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3208 | { 0x1f, 0x0002 }, |
| 3209 | { 0x05, 0x669a }, |
| 3210 | { 0x1f, 0x0005 }, |
| 3211 | { 0x05, 0x8330 }, |
| 3212 | { 0x06, 0x669a }, |
| 3213 | |
| 3214 | { 0x1f, 0x0002 } |
| 3215 | }; |
| 3216 | int val; |
| 3217 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3218 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3219 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3220 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3221 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3222 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3223 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3224 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3225 | }; |
| 3226 | int i; |
| 3227 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3228 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3229 | |
| 3230 | val &= 0xff00; |
| 3231 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3232 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3233 | } |
| 3234 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3235 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3236 | { 0x1f, 0x0002 }, |
| 3237 | { 0x05, 0x2642 }, |
| 3238 | { 0x1f, 0x0005 }, |
| 3239 | { 0x05, 0x8330 }, |
| 3240 | { 0x06, 0x2642 } |
| 3241 | }; |
| 3242 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3243 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3246 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3247 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3248 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3249 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3250 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3251 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3252 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3253 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3254 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3255 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3256 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3257 | |
| 3258 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3259 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3260 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3263 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3264 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3265 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3266 | { 0x1f, 0x0002 }, |
| 3267 | { 0x10, 0x0008 }, |
| 3268 | { 0x0d, 0x006c }, |
| 3269 | |
| 3270 | { 0x1f, 0x0000 }, |
| 3271 | { 0x0d, 0xf880 }, |
| 3272 | |
| 3273 | { 0x1f, 0x0001 }, |
| 3274 | { 0x17, 0x0cc0 }, |
| 3275 | |
| 3276 | { 0x1f, 0x0001 }, |
| 3277 | { 0x0b, 0xa4d8 }, |
| 3278 | { 0x09, 0x281c }, |
| 3279 | { 0x07, 0x2883 }, |
| 3280 | { 0x0a, 0x6b35 }, |
| 3281 | { 0x1d, 0x3da4 }, |
| 3282 | { 0x1c, 0xeffd }, |
| 3283 | { 0x14, 0x7f52 }, |
| 3284 | { 0x18, 0x7fc6 }, |
| 3285 | { 0x08, 0x0601 }, |
| 3286 | { 0x06, 0x4063 }, |
| 3287 | { 0x10, 0xf074 }, |
| 3288 | { 0x1f, 0x0003 }, |
| 3289 | { 0x13, 0x0789 }, |
| 3290 | { 0x12, 0xf4bd }, |
| 3291 | { 0x1a, 0x04fd }, |
| 3292 | { 0x14, 0x84b0 }, |
| 3293 | { 0x1f, 0x0000 }, |
| 3294 | { 0x00, 0x9200 }, |
| 3295 | |
| 3296 | { 0x1f, 0x0005 }, |
| 3297 | { 0x01, 0x0340 }, |
| 3298 | { 0x1f, 0x0001 }, |
| 3299 | { 0x04, 0x4000 }, |
| 3300 | { 0x03, 0x1d21 }, |
| 3301 | { 0x02, 0x0c32 }, |
| 3302 | { 0x01, 0x0200 }, |
| 3303 | { 0x00, 0x5554 }, |
| 3304 | { 0x04, 0x4800 }, |
| 3305 | { 0x04, 0x4000 }, |
| 3306 | { 0x04, 0xf000 }, |
| 3307 | { 0x03, 0xdf01 }, |
| 3308 | { 0x02, 0xdf20 }, |
| 3309 | { 0x01, 0x101a }, |
| 3310 | { 0x00, 0xa0ff }, |
| 3311 | { 0x04, 0xf800 }, |
| 3312 | { 0x04, 0xf000 }, |
| 3313 | { 0x1f, 0x0000 }, |
| 3314 | |
| 3315 | { 0x1f, 0x0007 }, |
| 3316 | { 0x1e, 0x0023 }, |
| 3317 | { 0x16, 0x0000 }, |
| 3318 | { 0x1f, 0x0000 } |
| 3319 | }; |
| 3320 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3321 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3322 | } |
| 3323 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3324 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3325 | { |
| 3326 | static const struct phy_reg phy_reg_init[] = { |
| 3327 | { 0x1f, 0x0001 }, |
| 3328 | { 0x17, 0x0cc0 }, |
| 3329 | |
| 3330 | { 0x1f, 0x0007 }, |
| 3331 | { 0x1e, 0x002d }, |
| 3332 | { 0x18, 0x0040 }, |
| 3333 | { 0x1f, 0x0000 } |
| 3334 | }; |
| 3335 | |
| 3336 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3337 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3338 | } |
| 3339 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3340 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3341 | { |
| 3342 | static const struct phy_reg phy_reg_init[] = { |
| 3343 | /* Enable Delay cap */ |
| 3344 | { 0x1f, 0x0005 }, |
| 3345 | { 0x05, 0x8b80 }, |
| 3346 | { 0x06, 0xc896 }, |
| 3347 | { 0x1f, 0x0000 }, |
| 3348 | |
| 3349 | /* Channel estimation fine tune */ |
| 3350 | { 0x1f, 0x0001 }, |
| 3351 | { 0x0b, 0x6c20 }, |
| 3352 | { 0x07, 0x2872 }, |
| 3353 | { 0x1c, 0xefff }, |
| 3354 | { 0x1f, 0x0003 }, |
| 3355 | { 0x14, 0x6420 }, |
| 3356 | { 0x1f, 0x0000 }, |
| 3357 | |
| 3358 | /* Update PFM & 10M TX idle timer */ |
| 3359 | { 0x1f, 0x0007 }, |
| 3360 | { 0x1e, 0x002f }, |
| 3361 | { 0x15, 0x1919 }, |
| 3362 | { 0x1f, 0x0000 }, |
| 3363 | |
| 3364 | { 0x1f, 0x0007 }, |
| 3365 | { 0x1e, 0x00ac }, |
| 3366 | { 0x18, 0x0006 }, |
| 3367 | { 0x1f, 0x0000 } |
| 3368 | }; |
| 3369 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3370 | rtl_apply_firmware(tp); |
| 3371 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3372 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3373 | |
| 3374 | /* DCO enable for 10M IDLE Power */ |
| 3375 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3376 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3377 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3378 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3379 | |
| 3380 | /* For impedance matching */ |
| 3381 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3382 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3383 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3384 | |
| 3385 | /* PHY auto speed down */ |
| 3386 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3387 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3388 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3389 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3390 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3391 | |
| 3392 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3393 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3394 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3395 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3396 | |
| 3397 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3398 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3399 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3400 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3401 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3402 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3403 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3404 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3405 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3406 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3407 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3408 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3409 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3410 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3411 | } |
| 3412 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3413 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3414 | { |
| 3415 | const u16 w[] = { |
| 3416 | addr[0] | (addr[1] << 8), |
| 3417 | addr[2] | (addr[3] << 8), |
| 3418 | addr[4] | (addr[5] << 8) |
| 3419 | }; |
| 3420 | const struct exgmac_reg e[] = { |
| 3421 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3422 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3423 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3424 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3425 | }; |
| 3426 | |
| 3427 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3428 | } |
| 3429 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3430 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3431 | { |
| 3432 | static const struct phy_reg phy_reg_init[] = { |
| 3433 | /* Enable Delay cap */ |
| 3434 | { 0x1f, 0x0004 }, |
| 3435 | { 0x1f, 0x0007 }, |
| 3436 | { 0x1e, 0x00ac }, |
| 3437 | { 0x18, 0x0006 }, |
| 3438 | { 0x1f, 0x0002 }, |
| 3439 | { 0x1f, 0x0000 }, |
| 3440 | { 0x1f, 0x0000 }, |
| 3441 | |
| 3442 | /* Channel estimation fine tune */ |
| 3443 | { 0x1f, 0x0003 }, |
| 3444 | { 0x09, 0xa20f }, |
| 3445 | { 0x1f, 0x0000 }, |
| 3446 | { 0x1f, 0x0000 }, |
| 3447 | |
| 3448 | /* Green Setting */ |
| 3449 | { 0x1f, 0x0005 }, |
| 3450 | { 0x05, 0x8b5b }, |
| 3451 | { 0x06, 0x9222 }, |
| 3452 | { 0x05, 0x8b6d }, |
| 3453 | { 0x06, 0x8000 }, |
| 3454 | { 0x05, 0x8b76 }, |
| 3455 | { 0x06, 0x8000 }, |
| 3456 | { 0x1f, 0x0000 } |
| 3457 | }; |
| 3458 | |
| 3459 | rtl_apply_firmware(tp); |
| 3460 | |
| 3461 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3462 | |
| 3463 | /* For 4-corner performance improve */ |
| 3464 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3465 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3466 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3467 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3468 | |
| 3469 | /* PHY auto speed down */ |
| 3470 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3471 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3472 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3473 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3474 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3475 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3476 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3477 | |
| 3478 | /* improve 10M EEE waveform */ |
| 3479 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3480 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3481 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3482 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3483 | |
| 3484 | /* Improve 2-pair detection performance */ |
| 3485 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3486 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3487 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3488 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3489 | |
| 3490 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3491 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3492 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3493 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3494 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3495 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3496 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3497 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3498 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3499 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3500 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3501 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3502 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3503 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3504 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3505 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3506 | |
| 3507 | /* Green feature */ |
| 3508 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3509 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3510 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3511 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3512 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3513 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3514 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3515 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3516 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3517 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3518 | } |
| 3519 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3520 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3521 | { |
| 3522 | /* For 4-corner performance improve */ |
| 3523 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3524 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3525 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3526 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3527 | |
| 3528 | /* PHY auto speed down */ |
| 3529 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3530 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3531 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3532 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3533 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3534 | |
| 3535 | /* Improve 10M EEE waveform */ |
| 3536 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3537 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3538 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3539 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3540 | } |
| 3541 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3542 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3543 | { |
| 3544 | static const struct phy_reg phy_reg_init[] = { |
| 3545 | /* Channel estimation fine tune */ |
| 3546 | { 0x1f, 0x0003 }, |
| 3547 | { 0x09, 0xa20f }, |
| 3548 | { 0x1f, 0x0000 }, |
| 3549 | |
| 3550 | /* Modify green table for giga & fnet */ |
| 3551 | { 0x1f, 0x0005 }, |
| 3552 | { 0x05, 0x8b55 }, |
| 3553 | { 0x06, 0x0000 }, |
| 3554 | { 0x05, 0x8b5e }, |
| 3555 | { 0x06, 0x0000 }, |
| 3556 | { 0x05, 0x8b67 }, |
| 3557 | { 0x06, 0x0000 }, |
| 3558 | { 0x05, 0x8b70 }, |
| 3559 | { 0x06, 0x0000 }, |
| 3560 | { 0x1f, 0x0000 }, |
| 3561 | { 0x1f, 0x0007 }, |
| 3562 | { 0x1e, 0x0078 }, |
| 3563 | { 0x17, 0x0000 }, |
| 3564 | { 0x19, 0x00fb }, |
| 3565 | { 0x1f, 0x0000 }, |
| 3566 | |
| 3567 | /* Modify green table for 10M */ |
| 3568 | { 0x1f, 0x0005 }, |
| 3569 | { 0x05, 0x8b79 }, |
| 3570 | { 0x06, 0xaa00 }, |
| 3571 | { 0x1f, 0x0000 }, |
| 3572 | |
| 3573 | /* Disable hiimpedance detection (RTCT) */ |
| 3574 | { 0x1f, 0x0003 }, |
| 3575 | { 0x01, 0x328a }, |
| 3576 | { 0x1f, 0x0000 } |
| 3577 | }; |
| 3578 | |
| 3579 | rtl_apply_firmware(tp); |
| 3580 | |
| 3581 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3582 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3583 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3584 | |
| 3585 | /* Improve 2-pair detection performance */ |
| 3586 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3587 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3588 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3589 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3590 | } |
| 3591 | |
| 3592 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3593 | { |
| 3594 | rtl_apply_firmware(tp); |
| 3595 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3596 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3597 | } |
| 3598 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3599 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3600 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3601 | static const struct phy_reg phy_reg_init[] = { |
| 3602 | /* Channel estimation fine tune */ |
| 3603 | { 0x1f, 0x0003 }, |
| 3604 | { 0x09, 0xa20f }, |
| 3605 | { 0x1f, 0x0000 }, |
| 3606 | |
| 3607 | /* Modify green table for giga & fnet */ |
| 3608 | { 0x1f, 0x0005 }, |
| 3609 | { 0x05, 0x8b55 }, |
| 3610 | { 0x06, 0x0000 }, |
| 3611 | { 0x05, 0x8b5e }, |
| 3612 | { 0x06, 0x0000 }, |
| 3613 | { 0x05, 0x8b67 }, |
| 3614 | { 0x06, 0x0000 }, |
| 3615 | { 0x05, 0x8b70 }, |
| 3616 | { 0x06, 0x0000 }, |
| 3617 | { 0x1f, 0x0000 }, |
| 3618 | { 0x1f, 0x0007 }, |
| 3619 | { 0x1e, 0x0078 }, |
| 3620 | { 0x17, 0x0000 }, |
| 3621 | { 0x19, 0x00aa }, |
| 3622 | { 0x1f, 0x0000 }, |
| 3623 | |
| 3624 | /* Modify green table for 10M */ |
| 3625 | { 0x1f, 0x0005 }, |
| 3626 | { 0x05, 0x8b79 }, |
| 3627 | { 0x06, 0xaa00 }, |
| 3628 | { 0x1f, 0x0000 }, |
| 3629 | |
| 3630 | /* Disable hiimpedance detection (RTCT) */ |
| 3631 | { 0x1f, 0x0003 }, |
| 3632 | { 0x01, 0x328a }, |
| 3633 | { 0x1f, 0x0000 } |
| 3634 | }; |
| 3635 | |
| 3636 | |
| 3637 | rtl_apply_firmware(tp); |
| 3638 | |
| 3639 | rtl8168f_hw_phy_config(tp); |
| 3640 | |
| 3641 | /* Improve 2-pair detection performance */ |
| 3642 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3643 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3644 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3645 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3646 | |
| 3647 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3648 | |
| 3649 | /* Modify green table for giga */ |
| 3650 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3651 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3652 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3653 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3654 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3655 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3656 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3657 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3658 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3659 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3660 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3661 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3662 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3663 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3664 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3665 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3666 | |
| 3667 | /* uc same-seed solution */ |
| 3668 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3669 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3670 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3671 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3672 | |
| 3673 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3674 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3675 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3676 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3677 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3678 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3679 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3680 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3681 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3682 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3683 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3684 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3685 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3686 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3687 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3688 | |
| 3689 | /* Green feature */ |
| 3690 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3691 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3692 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3693 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3694 | } |
| 3695 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3696 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3697 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3698 | rtl_apply_firmware(tp); |
| 3699 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3700 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3701 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3702 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3703 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3704 | } else { |
| 3705 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3706 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3707 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3708 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3709 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3710 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3711 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3712 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3713 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3714 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3715 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3716 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3717 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3718 | /* Enable PHY auto speed down */ |
| 3719 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3720 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3721 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3722 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3723 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3724 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3725 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3726 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3727 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3728 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3729 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3730 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3731 | /* EEE auto-fallback function */ |
| 3732 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3733 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3734 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3735 | /* Enable UC LPF tune function */ |
| 3736 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3737 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3738 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3739 | |
| 3740 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3741 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3742 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3743 | /* Improve SWR Efficiency */ |
| 3744 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3745 | rtl_writephy(tp, 0x14, 0x5065); |
| 3746 | rtl_writephy(tp, 0x14, 0xd065); |
| 3747 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3748 | rtl_writephy(tp, 0x11, 0x5655); |
| 3749 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3750 | rtl_writephy(tp, 0x14, 0x1065); |
| 3751 | rtl_writephy(tp, 0x14, 0x9065); |
| 3752 | rtl_writephy(tp, 0x14, 0x1065); |
| 3753 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3754 | /* Check ALDPS bit, disable it if enabled */ |
| 3755 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3756 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3757 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3758 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3759 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3760 | } |
| 3761 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3762 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3763 | { |
| 3764 | rtl_apply_firmware(tp); |
| 3765 | } |
| 3766 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3767 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3768 | { |
| 3769 | u16 dout_tapbin; |
| 3770 | u32 data; |
| 3771 | |
| 3772 | rtl_apply_firmware(tp); |
| 3773 | |
| 3774 | /* CHN EST parameters adjust - giga master */ |
| 3775 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3776 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3777 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3778 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3779 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3780 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3781 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3782 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3783 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3784 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3785 | |
| 3786 | /* CHN EST parameters adjust - giga slave */ |
| 3787 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3788 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3789 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3790 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3791 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3792 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3793 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3794 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3795 | |
| 3796 | /* CHN EST parameters adjust - fnet */ |
| 3797 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3798 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3799 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3800 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3801 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3802 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3803 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3804 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3805 | |
| 3806 | /* enable R-tune & PGA-retune function */ |
| 3807 | dout_tapbin = 0; |
| 3808 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3809 | data = rtl_readphy(tp, 0x13); |
| 3810 | data &= 3; |
| 3811 | data <<= 2; |
| 3812 | dout_tapbin |= data; |
| 3813 | data = rtl_readphy(tp, 0x12); |
| 3814 | data &= 0xc000; |
| 3815 | data >>= 14; |
| 3816 | dout_tapbin |= data; |
| 3817 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3818 | dout_tapbin <<= 12; |
| 3819 | dout_tapbin &= 0xf000; |
| 3820 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3821 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3822 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3823 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3824 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3825 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3826 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3827 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3828 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3829 | |
| 3830 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3831 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3832 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3833 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3834 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3835 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3836 | |
| 3837 | /* enable GPHY 10M */ |
| 3838 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3839 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3840 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3841 | |
| 3842 | /* SAR ADC performance */ |
| 3843 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3844 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3845 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3846 | |
| 3847 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3848 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3849 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3850 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3851 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3852 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3853 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3854 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3855 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3856 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3857 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3858 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3859 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3860 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3861 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3862 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3863 | |
| 3864 | /* disable phy pfm mode */ |
| 3865 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3866 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3867 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3868 | |
| 3869 | /* Check ALDPS bit, disable it if enabled */ |
| 3870 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3871 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3872 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3873 | |
| 3874 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3875 | } |
| 3876 | |
| 3877 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3878 | { |
| 3879 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3880 | u16 rlen; |
| 3881 | u32 data; |
| 3882 | |
| 3883 | rtl_apply_firmware(tp); |
| 3884 | |
| 3885 | /* CHIN EST parameter update */ |
| 3886 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3887 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3888 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3889 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3890 | |
| 3891 | /* enable R-tune & PGA-retune function */ |
| 3892 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3893 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3894 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3895 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3896 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3897 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3898 | |
| 3899 | /* enable GPHY 10M */ |
| 3900 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3901 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3902 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3903 | |
| 3904 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3905 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3906 | ioffset_p3 = ((data & 0x80)>>7); |
| 3907 | ioffset_p3 <<= 3; |
| 3908 | |
| 3909 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3910 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3911 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3912 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3913 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3914 | ioffset_p0 <<= 3; |
| 3915 | ioffset_p0 |= (data & (0x07)); |
| 3916 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3917 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3918 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3919 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3920 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3921 | rtl_writephy(tp, 0x16, data); |
| 3922 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3923 | } |
| 3924 | |
| 3925 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3926 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3927 | data = rtl_readphy(tp, 0x16); |
| 3928 | data &= 0x000f; |
| 3929 | rlen = 0; |
| 3930 | if (data > 3) |
| 3931 | rlen = data - 3; |
| 3932 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3933 | rtl_writephy(tp, 0x17, data); |
| 3934 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3935 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3936 | |
| 3937 | /* disable phy pfm mode */ |
| 3938 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3939 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3940 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3941 | |
| 3942 | /* Check ALDPS bit, disable it if enabled */ |
| 3943 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3944 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3945 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3946 | |
| 3947 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3948 | } |
| 3949 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3950 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3951 | { |
| 3952 | /* Enable PHY auto speed down */ |
| 3953 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3954 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 3955 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3956 | |
| 3957 | /* patch 10M & ALDPS */ |
| 3958 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3959 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3960 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3961 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3962 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3963 | rtl_writephy(tp, 0x13, 0x8084); |
| 3964 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3965 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3966 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3967 | |
| 3968 | /* Enable EEE auto-fallback function */ |
| 3969 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 3970 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 3971 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3972 | |
| 3973 | /* Enable UC LPF tune function */ |
| 3974 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3975 | rtl_writephy(tp, 0x13, 0x8012); |
| 3976 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3977 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3978 | |
| 3979 | /* set rg_sel_sdm_rate */ |
| 3980 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3981 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3982 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3983 | |
| 3984 | /* Check ALDPS bit, disable it if enabled */ |
| 3985 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3986 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3987 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3988 | |
| 3989 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3990 | } |
| 3991 | |
| 3992 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3993 | { |
| 3994 | /* patch 10M & ALDPS */ |
| 3995 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3996 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3997 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3998 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3999 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4000 | rtl_writephy(tp, 0x13, 0x8084); |
| 4001 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4002 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4003 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4004 | |
| 4005 | /* Enable UC LPF tune function */ |
| 4006 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4007 | rtl_writephy(tp, 0x13, 0x8012); |
| 4008 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4009 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4010 | |
| 4011 | /* Set rg_sel_sdm_rate */ |
| 4012 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4013 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4014 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4015 | |
| 4016 | /* Channel estimation parameters */ |
| 4017 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4018 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4019 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4020 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4021 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4022 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4023 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4024 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4025 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4026 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4027 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4028 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4029 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4030 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4031 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4032 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4033 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4034 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4035 | rtl_writephy(tp, 0x13, 0x8110); |
| 4036 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4037 | rtl_writephy(tp, 0x13, 0x810f); |
| 4038 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4039 | rtl_writephy(tp, 0x13, 0x8111); |
| 4040 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4041 | rtl_writephy(tp, 0x13, 0x8113); |
| 4042 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4043 | rtl_writephy(tp, 0x13, 0x8115); |
| 4044 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4045 | rtl_writephy(tp, 0x13, 0x810e); |
| 4046 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4047 | rtl_writephy(tp, 0x13, 0x810c); |
| 4048 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4049 | rtl_writephy(tp, 0x13, 0x810b); |
| 4050 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4051 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4052 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4053 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4054 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4055 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4056 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4057 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4058 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4059 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4060 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4061 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4062 | |
| 4063 | /* Force PWM-mode */ |
| 4064 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4065 | rtl_writephy(tp, 0x14, 0x5065); |
| 4066 | rtl_writephy(tp, 0x14, 0xd065); |
| 4067 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4068 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4069 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4070 | rtl_writephy(tp, 0x14, 0x1065); |
| 4071 | rtl_writephy(tp, 0x14, 0x9065); |
| 4072 | rtl_writephy(tp, 0x14, 0x1065); |
| 4073 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4074 | |
| 4075 | /* Check ALDPS bit, disable it if enabled */ |
| 4076 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4077 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4078 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4079 | |
| 4080 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4081 | } |
| 4082 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4083 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4084 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4085 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4086 | { 0x1f, 0x0003 }, |
| 4087 | { 0x08, 0x441d }, |
| 4088 | { 0x01, 0x9100 }, |
| 4089 | { 0x1f, 0x0000 } |
| 4090 | }; |
| 4091 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4092 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4093 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4094 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4095 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4096 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4097 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4098 | } |
| 4099 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4100 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4101 | { |
| 4102 | static const struct phy_reg phy_reg_init[] = { |
| 4103 | { 0x1f, 0x0005 }, |
| 4104 | { 0x1a, 0x0000 }, |
| 4105 | { 0x1f, 0x0000 }, |
| 4106 | |
| 4107 | { 0x1f, 0x0004 }, |
| 4108 | { 0x1c, 0x0000 }, |
| 4109 | { 0x1f, 0x0000 }, |
| 4110 | |
| 4111 | { 0x1f, 0x0001 }, |
| 4112 | { 0x15, 0x7701 }, |
| 4113 | { 0x1f, 0x0000 } |
| 4114 | }; |
| 4115 | |
| 4116 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4117 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4118 | rtl_writephy(tp, 0x18, 0x0310); |
| 4119 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4120 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4121 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4122 | |
| 4123 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4124 | } |
| 4125 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4126 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4127 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4128 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4129 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4130 | rtl_writephy(tp, 0x18, 0x0310); |
| 4131 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4132 | |
| 4133 | rtl_apply_firmware(tp); |
| 4134 | |
| 4135 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4136 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4137 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4138 | rtl_writephy(tp, 0x10, 0x401f); |
| 4139 | rtl_writephy(tp, 0x19, 0x7030); |
| 4140 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4141 | } |
| 4142 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4143 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4144 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4145 | static const struct phy_reg phy_reg_init[] = { |
| 4146 | { 0x1f, 0x0004 }, |
| 4147 | { 0x10, 0xc07f }, |
| 4148 | { 0x19, 0x7030 }, |
| 4149 | { 0x1f, 0x0000 } |
| 4150 | }; |
| 4151 | |
| 4152 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4153 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4154 | rtl_writephy(tp, 0x18, 0x0310); |
| 4155 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4156 | |
| 4157 | rtl_apply_firmware(tp); |
| 4158 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4159 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4160 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4161 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4162 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4163 | } |
| 4164 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4165 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4166 | { |
| 4167 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4168 | |
| 4169 | rtl8169_print_mac_version(tp); |
| 4170 | |
| 4171 | switch (tp->mac_version) { |
| 4172 | case RTL_GIGA_MAC_VER_01: |
| 4173 | break; |
| 4174 | case RTL_GIGA_MAC_VER_02: |
| 4175 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4176 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4177 | break; |
| 4178 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4179 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4180 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4181 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4182 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4183 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4184 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4185 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4186 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4187 | case RTL_GIGA_MAC_VER_07: |
| 4188 | case RTL_GIGA_MAC_VER_08: |
| 4189 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4190 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4191 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4192 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4193 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4194 | break; |
| 4195 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4196 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4197 | break; |
| 4198 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4199 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4200 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4201 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4202 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4203 | break; |
| 4204 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4205 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4206 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4207 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4208 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4209 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4210 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4211 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4212 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4213 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4214 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4215 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4216 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4217 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4218 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4219 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4220 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4221 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4224 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4225 | break; |
| 4226 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4227 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4228 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4229 | case RTL_GIGA_MAC_VER_28: |
| 4230 | rtl8168d_4_hw_phy_config(tp); |
| 4231 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4232 | case RTL_GIGA_MAC_VER_29: |
| 4233 | case RTL_GIGA_MAC_VER_30: |
| 4234 | rtl8105e_hw_phy_config(tp); |
| 4235 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4236 | case RTL_GIGA_MAC_VER_31: |
| 4237 | /* None. */ |
| 4238 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4239 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4240 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4241 | rtl8168e_1_hw_phy_config(tp); |
| 4242 | break; |
| 4243 | case RTL_GIGA_MAC_VER_34: |
| 4244 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4245 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4246 | case RTL_GIGA_MAC_VER_35: |
| 4247 | rtl8168f_1_hw_phy_config(tp); |
| 4248 | break; |
| 4249 | case RTL_GIGA_MAC_VER_36: |
| 4250 | rtl8168f_2_hw_phy_config(tp); |
| 4251 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4252 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4253 | case RTL_GIGA_MAC_VER_37: |
| 4254 | rtl8402_hw_phy_config(tp); |
| 4255 | break; |
| 4256 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4257 | case RTL_GIGA_MAC_VER_38: |
| 4258 | rtl8411_hw_phy_config(tp); |
| 4259 | break; |
| 4260 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4261 | case RTL_GIGA_MAC_VER_39: |
| 4262 | rtl8106e_hw_phy_config(tp); |
| 4263 | break; |
| 4264 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4265 | case RTL_GIGA_MAC_VER_40: |
| 4266 | rtl8168g_1_hw_phy_config(tp); |
| 4267 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4268 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4269 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4270 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4271 | rtl8168g_2_hw_phy_config(tp); |
| 4272 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4273 | case RTL_GIGA_MAC_VER_45: |
| 4274 | case RTL_GIGA_MAC_VER_47: |
| 4275 | rtl8168h_1_hw_phy_config(tp); |
| 4276 | break; |
| 4277 | case RTL_GIGA_MAC_VER_46: |
| 4278 | case RTL_GIGA_MAC_VER_48: |
| 4279 | rtl8168h_2_hw_phy_config(tp); |
| 4280 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4281 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4282 | case RTL_GIGA_MAC_VER_49: |
| 4283 | rtl8168ep_1_hw_phy_config(tp); |
| 4284 | break; |
| 4285 | case RTL_GIGA_MAC_VER_50: |
| 4286 | case RTL_GIGA_MAC_VER_51: |
| 4287 | rtl8168ep_2_hw_phy_config(tp); |
| 4288 | break; |
| 4289 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4290 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4291 | default: |
| 4292 | break; |
| 4293 | } |
| 4294 | } |
| 4295 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4296 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | struct timer_list *timer = &tp->timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4300 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4301 | if (rtl8169_xmii_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4302 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4304 | * Let's delay the execution of the timer for a few ticks. |
| 4305 | */ |
| 4306 | timeout = HZ/10; |
| 4307 | goto out_mod_timer; |
| 4308 | } |
| 4309 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4310 | if (rtl8169_xmii_link_ok(tp)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4311 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4313 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4315 | rtl8169_xmii_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | |
| 4317 | out_mod_timer: |
| 4318 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4322 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4323 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4324 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4327 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4328 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4329 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4330 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4331 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4334 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4335 | { |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4336 | return rtl8169_xmii_reset_pending(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4337 | } |
| 4338 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4339 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4340 | struct rtl8169_private *tp) |
| 4341 | { |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4342 | rtl8169_xmii_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4343 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4344 | } |
| 4345 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4346 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4347 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4348 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4349 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4350 | } |
| 4351 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4352 | static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4354 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4355 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4356 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4357 | netif_dbg(tp, drv, dev, |
| 4358 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4359 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4360 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4361 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4362 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4363 | |
| 4364 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4365 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4366 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4367 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4368 | netif_dbg(tp, drv, dev, |
| 4369 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4370 | RTL_W8(tp, 0x82, 0x01); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4371 | netif_dbg(tp, drv, dev, |
| 4372 | "Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4373 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4374 | } |
| 4375 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4376 | rtl8169_phy_reset(dev, tp); |
| 4377 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4378 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4379 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4380 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4381 | (tp->mii.supports_gmii ? |
| 4382 | ADVERTISED_1000baseT_Half | |
| 4383 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4384 | } |
| 4385 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4386 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4387 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4388 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4389 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4390 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4391 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4392 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4393 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4394 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4395 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4396 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4397 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4398 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4399 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4400 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4401 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4402 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4403 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4407 | { |
| 4408 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4409 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4410 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4411 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4412 | ret = eth_mac_addr(dev, p); |
| 4413 | if (ret) |
| 4414 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4415 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4416 | pm_runtime_get_noresume(d); |
| 4417 | |
| 4418 | if (pm_runtime_active(d)) |
| 4419 | rtl_rar_set(tp, dev->dev_addr); |
| 4420 | |
| 4421 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4422 | |
| 4423 | return 0; |
| 4424 | } |
| 4425 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4426 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4427 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4428 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4429 | switch (cmd) { |
| 4430 | case SIOCGMIIPHY: |
| 4431 | data->phy_id = 32; /* Internal PHY */ |
| 4432 | return 0; |
| 4433 | |
| 4434 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4435 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4436 | return 0; |
| 4437 | |
| 4438 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4439 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4440 | return 0; |
| 4441 | } |
| 4442 | return -EOPNOTSUPP; |
| 4443 | } |
| 4444 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4445 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4446 | { |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 4447 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4448 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4449 | |
| 4450 | return netif_running(dev) ? rtl_xmii_ioctl(tp, data, cmd) : -ENODEV; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4453 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4454 | { |
| 4455 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4456 | |
| 4457 | switch (tp->mac_version) { |
| 4458 | case RTL_GIGA_MAC_VER_27: |
| 4459 | ops->write = r8168dp_1_mdio_write; |
| 4460 | ops->read = r8168dp_1_mdio_read; |
| 4461 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4462 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4463 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4464 | ops->write = r8168dp_2_mdio_write; |
| 4465 | ops->read = r8168dp_2_mdio_read; |
| 4466 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4467 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4468 | ops->write = r8168g_mdio_write; |
| 4469 | ops->read = r8168g_mdio_read; |
| 4470 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4471 | default: |
| 4472 | ops->write = r8169_mdio_write; |
| 4473 | ops->read = r8169_mdio_read; |
| 4474 | break; |
| 4475 | } |
| 4476 | } |
| 4477 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4478 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4479 | { |
| 4480 | u32 adv; |
| 4481 | int lpa; |
| 4482 | |
| 4483 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4484 | lpa = rtl_readphy(tp, MII_LPA); |
| 4485 | |
| 4486 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4487 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4488 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4489 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4490 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4491 | else |
| 4492 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4493 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4494 | (tp->mii.supports_gmii ? |
| 4495 | ADVERTISED_1000baseT_Half | |
| 4496 | ADVERTISED_1000baseT_Full : 0); |
| 4497 | |
| 4498 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4499 | adv); |
| 4500 | } |
| 4501 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4502 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4503 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4504 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4505 | case RTL_GIGA_MAC_VER_25: |
| 4506 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4507 | case RTL_GIGA_MAC_VER_29: |
| 4508 | case RTL_GIGA_MAC_VER_30: |
| 4509 | case RTL_GIGA_MAC_VER_32: |
| 4510 | case RTL_GIGA_MAC_VER_33: |
| 4511 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4512 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4513 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4514 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4515 | break; |
| 4516 | default: |
| 4517 | break; |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4522 | { |
Heiner Kallweit | fe87bef | 2018-06-24 18:40:23 +0200 | [diff] [blame] | 4523 | if (!netif_running(tp->dev) || !tp->saved_wolopts) |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4524 | return false; |
| 4525 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4526 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4527 | rtl_wol_suspend_quirk(tp); |
| 4528 | |
| 4529 | return true; |
| 4530 | } |
| 4531 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4532 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4533 | { |
| 4534 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4535 | switch (tp->mac_version) { |
| 4536 | case RTL_GIGA_MAC_VER_11: |
| 4537 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4538 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4539 | case RTL_GIGA_MAC_VER_31: |
| 4540 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4541 | break; |
| 4542 | default: |
| 4543 | break; |
| 4544 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4545 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
David S. Miller | b2d6cee | 2018-05-11 20:53:22 -0400 | [diff] [blame] | 4546 | |
| 4547 | /* give MAC/PHY some time to resume */ |
| 4548 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4552 | { |
| 4553 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4554 | switch (tp->mac_version) { |
| 4555 | case RTL_GIGA_MAC_VER_32: |
| 4556 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4557 | case RTL_GIGA_MAC_VER_40: |
| 4558 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4559 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4560 | break; |
| 4561 | |
| 4562 | case RTL_GIGA_MAC_VER_11: |
| 4563 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4564 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4565 | case RTL_GIGA_MAC_VER_31: |
| 4566 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4567 | default: |
| 4568 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4569 | break; |
| 4570 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4571 | } |
| 4572 | |
| 4573 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4574 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4575 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4576 | return; |
| 4577 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4578 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4579 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4580 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4581 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4582 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4583 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4584 | |
| 4585 | r8168_phy_power_down(tp); |
| 4586 | |
| 4587 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4588 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4589 | case RTL_GIGA_MAC_VER_37: |
| 4590 | case RTL_GIGA_MAC_VER_39: |
| 4591 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4592 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4593 | case RTL_GIGA_MAC_VER_45: |
| 4594 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4595 | case RTL_GIGA_MAC_VER_47: |
| 4596 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4597 | case RTL_GIGA_MAC_VER_50: |
| 4598 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4599 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4600 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4601 | case RTL_GIGA_MAC_VER_40: |
| 4602 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4603 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4604 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4605 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4606 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4607 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4612 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4613 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4614 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4615 | case RTL_GIGA_MAC_VER_37: |
| 4616 | case RTL_GIGA_MAC_VER_39: |
| 4617 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4618 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4619 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4620 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4621 | case RTL_GIGA_MAC_VER_45: |
| 4622 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4623 | case RTL_GIGA_MAC_VER_47: |
| 4624 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4625 | case RTL_GIGA_MAC_VER_50: |
| 4626 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4627 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4628 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4629 | case RTL_GIGA_MAC_VER_40: |
| 4630 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4631 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4632 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4633 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4634 | 0x00000000, ERIAR_EXGMAC); |
| 4635 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | r8168_phy_power_up(tp); |
| 4639 | } |
| 4640 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4641 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4642 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4643 | switch (tp->mac_version) { |
| 4644 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4645 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4646 | break; |
| 4647 | default: |
| 4648 | r8168_pll_power_down(tp); |
| 4649 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4653 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4654 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4655 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4656 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4657 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4658 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4659 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4663 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4664 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4665 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4666 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4667 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4668 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4669 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4670 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4671 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 4672 | case RTL_GIGA_MAC_VER_35: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4673 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4674 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4675 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4676 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4677 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4678 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4679 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4680 | break; |
| 4681 | } |
| 4682 | } |
| 4683 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4684 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4685 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4686 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4687 | } |
| 4688 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4689 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4690 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4691 | if (tp->jumbo_ops.enable) { |
| 4692 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4693 | tp->jumbo_ops.enable(tp); |
| 4694 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4695 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4699 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4700 | if (tp->jumbo_ops.disable) { |
| 4701 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4702 | tp->jumbo_ops.disable(tp); |
| 4703 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4704 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4708 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4709 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4710 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4711 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4715 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4716 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4717 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4718 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4722 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4723 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4727 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4728 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4732 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4733 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4734 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4735 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4736 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4740 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4741 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4742 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4743 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4744 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4748 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4749 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4750 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4754 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4755 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4756 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4760 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4761 | r8168b_0_hw_jumbo_enable(tp); |
| 4762 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4763 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4767 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4768 | r8168b_0_hw_jumbo_disable(tp); |
| 4769 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4770 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4771 | } |
| 4772 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4773 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4774 | { |
| 4775 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4776 | |
| 4777 | switch (tp->mac_version) { |
| 4778 | case RTL_GIGA_MAC_VER_11: |
| 4779 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4780 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4781 | break; |
| 4782 | case RTL_GIGA_MAC_VER_12: |
| 4783 | case RTL_GIGA_MAC_VER_17: |
| 4784 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4785 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4786 | break; |
| 4787 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4788 | case RTL_GIGA_MAC_VER_19: |
| 4789 | case RTL_GIGA_MAC_VER_20: |
| 4790 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4791 | case RTL_GIGA_MAC_VER_22: |
| 4792 | case RTL_GIGA_MAC_VER_23: |
| 4793 | case RTL_GIGA_MAC_VER_24: |
| 4794 | case RTL_GIGA_MAC_VER_25: |
| 4795 | case RTL_GIGA_MAC_VER_26: |
| 4796 | ops->disable = r8168c_hw_jumbo_disable; |
| 4797 | ops->enable = r8168c_hw_jumbo_enable; |
| 4798 | break; |
| 4799 | case RTL_GIGA_MAC_VER_27: |
| 4800 | case RTL_GIGA_MAC_VER_28: |
| 4801 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4802 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4803 | break; |
| 4804 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4805 | case RTL_GIGA_MAC_VER_32: |
| 4806 | case RTL_GIGA_MAC_VER_33: |
| 4807 | case RTL_GIGA_MAC_VER_34: |
| 4808 | ops->disable = r8168e_hw_jumbo_disable; |
| 4809 | ops->enable = r8168e_hw_jumbo_enable; |
| 4810 | break; |
| 4811 | |
| 4812 | /* |
| 4813 | * No action needed for jumbo frames with 8169. |
| 4814 | * No jumbo for 810x at all. |
| 4815 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4816 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4817 | default: |
| 4818 | ops->disable = NULL; |
| 4819 | ops->enable = NULL; |
| 4820 | break; |
| 4821 | } |
| 4822 | } |
| 4823 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4824 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4825 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4826 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4827 | } |
| 4828 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4829 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4830 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4831 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4832 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4833 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4836 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4837 | { |
| 4838 | struct rtl_fw *rtl_fw; |
| 4839 | const char *name; |
| 4840 | int rc = -ENOMEM; |
| 4841 | |
| 4842 | name = rtl_lookup_firmware_name(tp); |
| 4843 | if (!name) |
| 4844 | goto out_no_firmware; |
| 4845 | |
| 4846 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4847 | if (!rtl_fw) |
| 4848 | goto err_warn; |
| 4849 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4850 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4851 | if (rc < 0) |
| 4852 | goto err_free; |
| 4853 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4854 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4855 | if (rc < 0) |
| 4856 | goto err_release_firmware; |
| 4857 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4858 | tp->rtl_fw = rtl_fw; |
| 4859 | out: |
| 4860 | return; |
| 4861 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4862 | err_release_firmware: |
| 4863 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4864 | err_free: |
| 4865 | kfree(rtl_fw); |
| 4866 | err_warn: |
| 4867 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4868 | name, rc); |
| 4869 | out_no_firmware: |
| 4870 | tp->rtl_fw = NULL; |
| 4871 | goto out; |
| 4872 | } |
| 4873 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4874 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4875 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4876 | if (IS_ERR(tp->rtl_fw)) |
| 4877 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4878 | } |
| 4879 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4880 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4881 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4882 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4885 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4886 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4887 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4891 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4892 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4893 | } |
| 4894 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4895 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | { |
| 4897 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4898 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4900 | rtl_rx_close(tp); |
| 4901 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4902 | switch (tp->mac_version) { |
| 4903 | case RTL_GIGA_MAC_VER_27: |
| 4904 | case RTL_GIGA_MAC_VER_28: |
| 4905 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4906 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4907 | break; |
| 4908 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 4909 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4910 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4911 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4912 | break; |
| 4913 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4914 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4915 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4916 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4919 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | } |
| 4921 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4922 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4923 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4924 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4925 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4926 | (InterFrameGap << TxInterFrameGapShift)); |
| 4927 | } |
| 4928 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4929 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4931 | /* Low hurts. Let's disable the filtering. */ |
| 4932 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4933 | } |
| 4934 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4935 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4936 | { |
| 4937 | /* |
| 4938 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4939 | * register to be written before TxDescAddrLow to work. |
| 4940 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4941 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4942 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4943 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4944 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4945 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4946 | } |
| 4947 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4948 | static void rtl8169_set_magic_reg(struct rtl8169_private *tp, unsigned mac_version) |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4949 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4950 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4951 | u32 mac_version; |
| 4952 | u32 clk; |
| 4953 | u32 val; |
| 4954 | } cfg2_info [] = { |
| 4955 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4956 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4957 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4958 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4959 | }; |
| 4960 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4961 | unsigned int i; |
| 4962 | u32 clk; |
| 4963 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4964 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4965 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4966 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4967 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4968 | break; |
| 4969 | } |
| 4970 | } |
| 4971 | } |
| 4972 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4973 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4974 | { |
| 4975 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4976 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4977 | int rx_mode; |
| 4978 | u32 tmp = 0; |
| 4979 | |
| 4980 | if (dev->flags & IFF_PROMISC) { |
| 4981 | /* Unconditionally log net taps. */ |
| 4982 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4983 | rx_mode = |
| 4984 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4985 | AcceptAllPhys; |
| 4986 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4987 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4988 | (dev->flags & IFF_ALLMULTI)) { |
| 4989 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4990 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4991 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4992 | } else { |
| 4993 | struct netdev_hw_addr *ha; |
| 4994 | |
| 4995 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4996 | mc_filter[1] = mc_filter[0] = 0; |
| 4997 | netdev_for_each_mc_addr(ha, dev) { |
| 4998 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4999 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5000 | rx_mode |= AcceptMulticast; |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | if (dev->features & NETIF_F_RXALL) |
| 5005 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5006 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5007 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5008 | |
| 5009 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5010 | u32 data = mc_filter[0]; |
| 5011 | |
| 5012 | mc_filter[0] = swab32(mc_filter[1]); |
| 5013 | mc_filter[1] = swab32(data); |
| 5014 | } |
| 5015 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5016 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5017 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5018 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5019 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 5020 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5021 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5022 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5023 | } |
| 5024 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 5025 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 5026 | { |
| 5027 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 5028 | |
| 5029 | tp->hw_start(tp); |
| 5030 | |
| 5031 | rtl_set_rx_max_size(tp); |
| 5032 | rtl_set_rx_tx_desc_registers(tp); |
| 5033 | rtl_set_rx_tx_config_registers(tp); |
| 5034 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 5035 | |
| 5036 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5037 | RTL_R8(tp, IntrMask); |
| 5038 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5039 | rtl_set_rx_mode(tp->dev); |
| 5040 | /* no early-rx interrupts */ |
| 5041 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
| 5042 | rtl_irq_enable_all(tp); |
| 5043 | } |
| 5044 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5045 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5046 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5047 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5048 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5049 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5050 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5052 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5053 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5054 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5055 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 5056 | netif_dbg(tp, drv, tp->dev, |
| 5057 | "Set MAC Reg C+CR Offset 0xe0. Bit 3 and Bit 14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5058 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | } |
| 5060 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5061 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5062 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5063 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | /* |
| 5066 | * Undocumented corner. Supposedly: |
| 5067 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5068 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5069 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5071 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5074 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5075 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5076 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5077 | } |
| 5078 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5079 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5080 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5081 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5082 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5083 | RTL_W32(tp, CSIDR, value); |
| 5084 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5085 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5086 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5087 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5088 | } |
| 5089 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5090 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5091 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5092 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5093 | |
| 5094 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 5095 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5096 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5097 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5098 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5099 | } |
| 5100 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5101 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5102 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5103 | struct pci_dev *pdev = tp->pci_dev; |
| 5104 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5105 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5106 | /* According to Realtek the value at config space address 0x070f |
| 5107 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 5108 | * first and if it fails fall back to CSI. |
| 5109 | */ |
| 5110 | if (pdev->cfg_size > 0x070f && |
| 5111 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 5112 | return; |
| 5113 | |
| 5114 | netdev_notice_once(tp->dev, |
| 5115 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 5116 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5117 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5118 | } |
| 5119 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5120 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5121 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5122 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | struct ephy_info { |
| 5126 | unsigned int offset; |
| 5127 | u16 mask; |
| 5128 | u16 bits; |
| 5129 | }; |
| 5130 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5131 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5132 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5133 | { |
| 5134 | u16 w; |
| 5135 | |
| 5136 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5137 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5138 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5139 | e++; |
| 5140 | } |
| 5141 | } |
| 5142 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5143 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5144 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5145 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5146 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5147 | } |
| 5148 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5149 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5150 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5151 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5152 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5155 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5156 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5157 | u8 data; |
| 5158 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5159 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5160 | |
| 5161 | if (enable) |
| 5162 | data |= Rdy_to_L23; |
| 5163 | else |
| 5164 | data &= ~Rdy_to_L23; |
| 5165 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5166 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5167 | } |
| 5168 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5169 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 5170 | { |
| 5171 | if (enable) { |
| 5172 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
| 5173 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
| 5174 | } else { |
| 5175 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5176 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 5177 | } |
| 5178 | } |
| 5179 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5180 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5181 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5182 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5183 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5184 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5185 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5186 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5187 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5188 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5189 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5190 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5191 | } |
| 5192 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5193 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5194 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5195 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5196 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5197 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5198 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5199 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5200 | } |
| 5201 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5202 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5203 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5204 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5205 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5206 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5207 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5208 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5209 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5210 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5211 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5212 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5213 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5214 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5215 | } |
| 5216 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5217 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5218 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5219 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5220 | { 0x01, 0, 0x0001 }, |
| 5221 | { 0x02, 0x0800, 0x1000 }, |
| 5222 | { 0x03, 0, 0x0042 }, |
| 5223 | { 0x06, 0x0080, 0x0000 }, |
| 5224 | { 0x07, 0, 0x2000 } |
| 5225 | }; |
| 5226 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5227 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5228 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5229 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5230 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5231 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5232 | } |
| 5233 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5234 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5235 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5236 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5237 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5238 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5239 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5240 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5241 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5242 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5243 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5244 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5247 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5248 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5249 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5250 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5251 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5252 | |
| 5253 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5254 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5255 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5256 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5257 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5258 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5259 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5260 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5261 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5262 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5263 | } |
| 5264 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5265 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5266 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5267 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5268 | { 0x02, 0x0800, 0x1000 }, |
| 5269 | { 0x03, 0, 0x0002 }, |
| 5270 | { 0x06, 0x0080, 0x0000 } |
| 5271 | }; |
| 5272 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5273 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5274 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5275 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5276 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5277 | rtl_ephy_init(tp, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5278 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5279 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5280 | } |
| 5281 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5282 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5283 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5284 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5285 | { 0x01, 0, 0x0001 }, |
| 5286 | { 0x03, 0x0400, 0x0220 } |
| 5287 | }; |
| 5288 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5289 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5290 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5291 | rtl_ephy_init(tp, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5292 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5293 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5294 | } |
| 5295 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5296 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5297 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5298 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5299 | } |
| 5300 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5301 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5302 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5303 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5304 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5305 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5306 | } |
| 5307 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5308 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5309 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5310 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5311 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5312 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5313 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5314 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5315 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5316 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5317 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5318 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5319 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5320 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5321 | } |
| 5322 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5323 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5324 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5325 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5326 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5327 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5328 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5329 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5330 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5331 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5332 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5335 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5336 | { |
| 5337 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5338 | { 0x0b, 0x0000, 0x0048 }, |
| 5339 | { 0x19, 0x0020, 0x0050 }, |
| 5340 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5341 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5342 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5343 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5344 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5345 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5346 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5347 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5348 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5349 | rtl_ephy_init(tp, e_info_8168d_4, ARRAY_SIZE(e_info_8168d_4)); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5350 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5351 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5354 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5355 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5356 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5357 | { 0x00, 0x0200, 0x0100 }, |
| 5358 | { 0x00, 0x0000, 0x0004 }, |
| 5359 | { 0x06, 0x0002, 0x0001 }, |
| 5360 | { 0x06, 0x0000, 0x0030 }, |
| 5361 | { 0x07, 0x0000, 0x2000 }, |
| 5362 | { 0x00, 0x0000, 0x0020 }, |
| 5363 | { 0x03, 0x5800, 0x2000 }, |
| 5364 | { 0x03, 0x0000, 0x0001 }, |
| 5365 | { 0x01, 0x0800, 0x1000 }, |
| 5366 | { 0x07, 0x0000, 0x4000 }, |
| 5367 | { 0x1e, 0x0000, 0x2000 }, |
| 5368 | { 0x19, 0xffff, 0xfe6c }, |
| 5369 | { 0x0a, 0x0000, 0x0040 } |
| 5370 | }; |
| 5371 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5372 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5373 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5374 | rtl_ephy_init(tp, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1)); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5375 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5376 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5377 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5378 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5379 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5380 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5381 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5382 | |
| 5383 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5384 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 5385 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5386 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5387 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5390 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5391 | { |
| 5392 | static const struct ephy_info e_info_8168e_2[] = { |
| 5393 | { 0x09, 0x0000, 0x0080 }, |
| 5394 | { 0x19, 0x0000, 0x0224 } |
| 5395 | }; |
| 5396 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5397 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5398 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5399 | rtl_ephy_init(tp, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5400 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5401 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5402 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5403 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5404 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5405 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5406 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5407 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5408 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5409 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5410 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5411 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5412 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5413 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5414 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5415 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5416 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5417 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5418 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5419 | |
| 5420 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5421 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5422 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5423 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5424 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5425 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 5426 | |
| 5427 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5428 | } |
| 5429 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5430 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5431 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5432 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5433 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5434 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5435 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5436 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5437 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5438 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5439 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5440 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5441 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5442 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5443 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5444 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5445 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5446 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5447 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5448 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5449 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5450 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5451 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5452 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5453 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5454 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5455 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5456 | } |
| 5457 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5458 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5459 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5460 | static const struct ephy_info e_info_8168f_1[] = { |
| 5461 | { 0x06, 0x00c0, 0x0020 }, |
| 5462 | { 0x08, 0x0001, 0x0002 }, |
| 5463 | { 0x09, 0x0000, 0x0080 }, |
| 5464 | { 0x19, 0x0000, 0x0224 } |
| 5465 | }; |
| 5466 | |
| 5467 | rtl_hw_start_8168f(tp); |
| 5468 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5469 | rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5470 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5471 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5472 | |
| 5473 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5474 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5475 | } |
| 5476 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5477 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5478 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5479 | static const struct ephy_info e_info_8168f_1[] = { |
| 5480 | { 0x06, 0x00c0, 0x0020 }, |
| 5481 | { 0x0f, 0xffff, 0x5200 }, |
| 5482 | { 0x1e, 0x0000, 0x4000 }, |
| 5483 | { 0x19, 0x0000, 0x0224 } |
| 5484 | }; |
| 5485 | |
| 5486 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5487 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5488 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5489 | rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5490 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5491 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5492 | } |
| 5493 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5494 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5495 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5496 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5497 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5498 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5499 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5500 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5501 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5502 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5503 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5504 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5505 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5506 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5507 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5508 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5509 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5510 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5511 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5512 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5513 | |
| 5514 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5515 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5516 | |
| 5517 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5518 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5519 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5520 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5521 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5522 | |
| 5523 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5524 | } |
| 5525 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5526 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5527 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5528 | static const struct ephy_info e_info_8168g_1[] = { |
| 5529 | { 0x00, 0x0000, 0x0008 }, |
| 5530 | { 0x0c, 0x37d0, 0x0820 }, |
| 5531 | { 0x1e, 0x0000, 0x0001 }, |
| 5532 | { 0x19, 0x8000, 0x0000 } |
| 5533 | }; |
| 5534 | |
| 5535 | rtl_hw_start_8168g(tp); |
| 5536 | |
| 5537 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5538 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5539 | rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1)); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5540 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5541 | } |
| 5542 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5543 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5544 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5545 | static const struct ephy_info e_info_8168g_2[] = { |
| 5546 | { 0x00, 0x0000, 0x0008 }, |
| 5547 | { 0x0c, 0x3df0, 0x0200 }, |
| 5548 | { 0x19, 0xffff, 0xfc00 }, |
| 5549 | { 0x1e, 0xffff, 0x20eb } |
| 5550 | }; |
| 5551 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5552 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5553 | |
| 5554 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5555 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5556 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5557 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5558 | } |
| 5559 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5560 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5561 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5562 | static const struct ephy_info e_info_8411_2[] = { |
| 5563 | { 0x00, 0x0000, 0x0008 }, |
| 5564 | { 0x0c, 0x3df0, 0x0200 }, |
| 5565 | { 0x0f, 0xffff, 0x5200 }, |
| 5566 | { 0x19, 0x0020, 0x0000 }, |
| 5567 | { 0x1e, 0x0000, 0x2000 } |
| 5568 | }; |
| 5569 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5570 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5571 | |
| 5572 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5573 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5574 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5575 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5576 | } |
| 5577 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5578 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5579 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5580 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5581 | u32 data; |
| 5582 | static const struct ephy_info e_info_8168h_1[] = { |
| 5583 | { 0x1e, 0x0800, 0x0001 }, |
| 5584 | { 0x1d, 0x0000, 0x0800 }, |
| 5585 | { 0x05, 0xffff, 0x2089 }, |
| 5586 | { 0x06, 0xffff, 0x5881 }, |
| 5587 | { 0x04, 0xffff, 0x154a }, |
| 5588 | { 0x01, 0xffff, 0x068b } |
| 5589 | }; |
| 5590 | |
| 5591 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5592 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5593 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5594 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5595 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5596 | |
| 5597 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5598 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5599 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5600 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5601 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5602 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5603 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5604 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5605 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5606 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5607 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5608 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5609 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_1111, 0x0010, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5610 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5611 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f00, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5612 | |
| 5613 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5614 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5615 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5616 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5617 | |
| 5618 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5619 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5620 | |
| 5621 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5622 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5623 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5624 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5625 | RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5626 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5627 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5628 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5629 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5630 | |
| 5631 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5632 | |
| 5633 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5634 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5635 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5636 | if (rg_saw_cnt > 0) { |
| 5637 | u16 sw_cnt_1ms_ini; |
| 5638 | |
| 5639 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5640 | sw_cnt_1ms_ini &= 0x0fff; |
| 5641 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5642 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5643 | data |= sw_cnt_1ms_ini; |
| 5644 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5645 | } |
| 5646 | |
| 5647 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5648 | data &= ~0xf0; |
| 5649 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5650 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5651 | |
| 5652 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5653 | data &= ~0x6000; |
| 5654 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5655 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5656 | |
| 5657 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5658 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5659 | data |= 0x017f; |
| 5660 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5661 | |
| 5662 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5663 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5664 | data |= 0x047f; |
| 5665 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5666 | |
| 5667 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5668 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5669 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5670 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5671 | |
| 5672 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5673 | } |
| 5674 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5675 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5676 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5677 | rtl8168ep_stop_cmac(tp); |
| 5678 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5679 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5680 | |
| 5681 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5682 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5683 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5684 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5685 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5686 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5687 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5688 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5689 | |
| 5690 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5691 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5692 | |
| 5693 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5694 | |
| 5695 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5696 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5697 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5698 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5699 | |
| 5700 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5701 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5702 | |
| 5703 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5704 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5705 | |
| 5706 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5707 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5708 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~TX_10M_PS_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5709 | |
| 5710 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5711 | } |
| 5712 | |
| 5713 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5714 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5715 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5716 | { 0x00, 0xffff, 0x10ab }, |
| 5717 | { 0x06, 0xffff, 0xf030 }, |
| 5718 | { 0x08, 0xffff, 0x2006 }, |
| 5719 | { 0x0d, 0xffff, 0x1666 }, |
| 5720 | { 0x0c, 0x3ff0, 0x0000 } |
| 5721 | }; |
| 5722 | |
| 5723 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5724 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5725 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5726 | |
| 5727 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5728 | |
| 5729 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5733 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5734 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5735 | { 0x00, 0xffff, 0x10a3 }, |
| 5736 | { 0x19, 0xffff, 0xfc00 }, |
| 5737 | { 0x1e, 0xffff, 0x20ea } |
| 5738 | }; |
| 5739 | |
| 5740 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5741 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5742 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5743 | |
| 5744 | rtl_hw_start_8168ep(tp); |
| 5745 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5746 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5747 | RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5748 | |
| 5749 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5753 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5754 | u32 data; |
| 5755 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5756 | { 0x00, 0xffff, 0x10a3 }, |
| 5757 | { 0x19, 0xffff, 0x7c00 }, |
| 5758 | { 0x1e, 0xffff, 0x20eb }, |
| 5759 | { 0x0d, 0xffff, 0x1666 } |
| 5760 | }; |
| 5761 | |
| 5762 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5763 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5764 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5765 | |
| 5766 | rtl_hw_start_8168ep(tp); |
| 5767 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5768 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5769 | RTL_W8(tp, MISC_1, RTL_R8(tp, MISC_1) & ~PFM_D3COLD_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5770 | |
| 5771 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5772 | data &= 0xf000; |
| 5773 | data |= 0x0271; |
| 5774 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5775 | |
| 5776 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5777 | data &= 0xff00; |
| 5778 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5779 | |
| 5780 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5781 | data |= 0x0080; |
| 5782 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5783 | |
| 5784 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5785 | } |
| 5786 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5787 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5788 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5789 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5790 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5791 | tp->cp_cmd &= ~INTT_MASK; |
| 5792 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5793 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5794 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5795 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5796 | |
| 5797 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5798 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5799 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5800 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5801 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5802 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5803 | switch (tp->mac_version) { |
| 5804 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5805 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5806 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5807 | |
| 5808 | case RTL_GIGA_MAC_VER_12: |
| 5809 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5810 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5811 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5812 | |
| 5813 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5814 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5815 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5816 | |
| 5817 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5818 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5819 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5820 | |
| 5821 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5822 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5823 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5824 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5825 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5826 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5827 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5828 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5829 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5830 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5831 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5832 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5833 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5834 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5835 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5836 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5837 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5838 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5839 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5840 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5841 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5842 | case RTL_GIGA_MAC_VER_26: |
| 5843 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5844 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5845 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5846 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5847 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5848 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5849 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5850 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5851 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5852 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5853 | break; |
| 5854 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5855 | case RTL_GIGA_MAC_VER_32: |
| 5856 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5857 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5858 | break; |
| 5859 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5860 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5861 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5862 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5863 | case RTL_GIGA_MAC_VER_35: |
| 5864 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5865 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5866 | break; |
| 5867 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5868 | case RTL_GIGA_MAC_VER_38: |
| 5869 | rtl_hw_start_8411(tp); |
| 5870 | break; |
| 5871 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5872 | case RTL_GIGA_MAC_VER_40: |
| 5873 | case RTL_GIGA_MAC_VER_41: |
| 5874 | rtl_hw_start_8168g_1(tp); |
| 5875 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5876 | case RTL_GIGA_MAC_VER_42: |
| 5877 | rtl_hw_start_8168g_2(tp); |
| 5878 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5879 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5880 | case RTL_GIGA_MAC_VER_44: |
| 5881 | rtl_hw_start_8411_2(tp); |
| 5882 | break; |
| 5883 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5884 | case RTL_GIGA_MAC_VER_45: |
| 5885 | case RTL_GIGA_MAC_VER_46: |
| 5886 | rtl_hw_start_8168h_1(tp); |
| 5887 | break; |
| 5888 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5889 | case RTL_GIGA_MAC_VER_49: |
| 5890 | rtl_hw_start_8168ep_1(tp); |
| 5891 | break; |
| 5892 | |
| 5893 | case RTL_GIGA_MAC_VER_50: |
| 5894 | rtl_hw_start_8168ep_2(tp); |
| 5895 | break; |
| 5896 | |
| 5897 | case RTL_GIGA_MAC_VER_51: |
| 5898 | rtl_hw_start_8168ep_3(tp); |
| 5899 | break; |
| 5900 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5901 | default: |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 5902 | netif_err(tp, drv, tp->dev, |
| 5903 | "unknown chipset (mac_version = %d)\n", |
| 5904 | tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5905 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5906 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5907 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5908 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5909 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5910 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5911 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5912 | { 0x01, 0, 0x6e65 }, |
| 5913 | { 0x02, 0, 0x091f }, |
| 5914 | { 0x03, 0, 0xc2f9 }, |
| 5915 | { 0x06, 0, 0xafb5 }, |
| 5916 | { 0x07, 0, 0x0e00 }, |
| 5917 | { 0x19, 0, 0xec80 }, |
| 5918 | { 0x01, 0, 0x2e65 }, |
| 5919 | { 0x01, 0, 0x6e65 } |
| 5920 | }; |
| 5921 | u8 cfg1; |
| 5922 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5923 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5924 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5925 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5926 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5927 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5928 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5929 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5930 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5931 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5932 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5933 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5934 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5935 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5936 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5937 | rtl_ephy_init(tp, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5938 | } |
| 5939 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5940 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5941 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5942 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5943 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5944 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5945 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5946 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5947 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5948 | } |
| 5949 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5950 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5951 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5952 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5953 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5954 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5955 | } |
| 5956 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5957 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5958 | { |
| 5959 | static const struct ephy_info e_info_8105e_1[] = { |
| 5960 | { 0x07, 0, 0x4000 }, |
| 5961 | { 0x19, 0, 0x0200 }, |
| 5962 | { 0x19, 0, 0x0020 }, |
| 5963 | { 0x1e, 0, 0x2000 }, |
| 5964 | { 0x03, 0, 0x0001 }, |
| 5965 | { 0x19, 0, 0x0100 }, |
| 5966 | { 0x19, 0, 0x0004 }, |
| 5967 | { 0x0a, 0, 0x0020 } |
| 5968 | }; |
| 5969 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5970 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5971 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5972 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5973 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5974 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5975 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5976 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5977 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5978 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5979 | rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5980 | |
| 5981 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5982 | } |
| 5983 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5984 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5985 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5986 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5987 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5988 | } |
| 5989 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5990 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5991 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5992 | static const struct ephy_info e_info_8402[] = { |
| 5993 | { 0x19, 0xffff, 0xff64 }, |
| 5994 | { 0x1e, 0, 0x4000 } |
| 5995 | }; |
| 5996 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5997 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5998 | |
| 5999 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6000 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6001 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6002 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 6003 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6004 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6005 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6006 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6007 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6008 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6009 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6010 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6011 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6012 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6013 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6014 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6015 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6016 | |
| 6017 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6018 | } |
| 6019 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6020 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6021 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6022 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6023 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6024 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6025 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 6026 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6027 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6028 | |
| 6029 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6030 | } |
| 6031 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6032 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6033 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6034 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6035 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6036 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6037 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6038 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6039 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6040 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6041 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6042 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6043 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 6044 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6045 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6046 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6047 | switch (tp->mac_version) { |
| 6048 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6049 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6050 | break; |
| 6051 | |
| 6052 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6053 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6054 | break; |
| 6055 | |
| 6056 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6057 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6058 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6059 | |
| 6060 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6061 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6062 | break; |
| 6063 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6064 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6065 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6066 | |
| 6067 | case RTL_GIGA_MAC_VER_37: |
| 6068 | rtl_hw_start_8402(tp); |
| 6069 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6070 | |
| 6071 | case RTL_GIGA_MAC_VER_39: |
| 6072 | rtl_hw_start_8106(tp); |
| 6073 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6074 | case RTL_GIGA_MAC_VER_43: |
| 6075 | rtl_hw_start_8168g_2(tp); |
| 6076 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6077 | case RTL_GIGA_MAC_VER_47: |
| 6078 | case RTL_GIGA_MAC_VER_48: |
| 6079 | rtl_hw_start_8168h_1(tp); |
| 6080 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6081 | } |
| 6082 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6083 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6087 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6088 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6089 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6090 | if (new_mtu > ETH_DATA_LEN) |
| 6091 | rtl_hw_jumbo_enable(tp); |
| 6092 | else |
| 6093 | rtl_hw_jumbo_disable(tp); |
| 6094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6096 | netdev_update_features(dev); |
| 6097 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6098 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6102 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6103 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6105 | } |
| 6106 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6107 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6108 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6110 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 6111 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6112 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6113 | kfree(*data_buff); |
| 6114 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | rtl8169_make_unusable_by_asic(desc); |
| 6116 | } |
| 6117 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6118 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | { |
| 6120 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6121 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6122 | /* Force memory writes to complete before releasing descriptor */ |
| 6123 | dma_wmb(); |
| 6124 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6125 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | } |
| 6127 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6128 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6129 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6130 | return (void *)ALIGN((long)data, 16); |
| 6131 | } |
| 6132 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6133 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6134 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6135 | { |
| 6136 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6138 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 6139 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6141 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6142 | if (!data) |
| 6143 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6144 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6145 | if (rtl8169_align(data) != data) { |
| 6146 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6147 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6148 | if (!data) |
| 6149 | return NULL; |
| 6150 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6151 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6152 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6153 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6154 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6155 | if (net_ratelimit()) |
| 6156 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6157 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 6160 | desc->addr = cpu_to_le64(mapping); |
| 6161 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6162 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6163 | |
| 6164 | err_out: |
| 6165 | kfree(data); |
| 6166 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
| 6169 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6170 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6171 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6172 | |
| 6173 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6174 | if (tp->Rx_databuff[i]) { |
| 6175 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | tp->RxDescArray + i); |
| 6177 | } |
| 6178 | } |
| 6179 | } |
| 6180 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6181 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6182 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6183 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6184 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6185 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6186 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6187 | { |
| 6188 | unsigned int i; |
| 6189 | |
| 6190 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6191 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6192 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6193 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6194 | if (!data) { |
| 6195 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6196 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6197 | } |
| 6198 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6201 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6202 | return 0; |
| 6203 | |
| 6204 | err_out: |
| 6205 | rtl8169_rx_clear(tp); |
| 6206 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6207 | } |
| 6208 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6209 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6211 | rtl8169_init_ring_indexes(tp); |
| 6212 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6213 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 6214 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6216 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6219 | static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | struct TxDesc *desc) |
| 6221 | { |
| 6222 | unsigned int len = tx_skb->len; |
| 6223 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6224 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | desc->opts1 = 0x00; |
| 6227 | desc->opts2 = 0x00; |
| 6228 | desc->addr = 0x00; |
| 6229 | tx_skb->len = 0; |
| 6230 | } |
| 6231 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6232 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6233 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6234 | { |
| 6235 | unsigned int i; |
| 6236 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6237 | for (i = 0; i < n; i++) { |
| 6238 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6240 | unsigned int len = tx_skb->len; |
| 6241 | |
| 6242 | if (len) { |
| 6243 | struct sk_buff *skb = tx_skb->skb; |
| 6244 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6245 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | tp->TxDescArray + entry); |
| 6247 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6248 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | tx_skb->skb = NULL; |
| 6250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6251 | } |
| 6252 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6256 | { |
| 6257 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | tp->cur_tx = tp->dirty_tx = 0; |
| 6259 | } |
| 6260 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6261 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6263 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6264 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6266 | napi_disable(&tp->napi); |
| 6267 | netif_stop_queue(dev); |
| 6268 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6270 | rtl8169_hw_reset(tp); |
| 6271 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6272 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6273 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6276 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6278 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6279 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6280 | netif_wake_queue(dev); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6281 | rtl8169_check_link_status(dev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6285 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6286 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6287 | |
| 6288 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6292 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6293 | { |
| 6294 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6295 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6296 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6297 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | |
| 6299 | entry = tp->cur_tx; |
| 6300 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6301 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | dma_addr_t mapping; |
| 6303 | u32 status, len; |
| 6304 | void *addr; |
| 6305 | |
| 6306 | entry = (entry + 1) % NUM_TX_DESC; |
| 6307 | |
| 6308 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6309 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6310 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6311 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6312 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6313 | if (net_ratelimit()) |
| 6314 | netif_err(tp, drv, tp->dev, |
| 6315 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6316 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6317 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6318 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6319 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6320 | status = opts[0] | len | |
| 6321 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | |
| 6323 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6324 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6325 | txd->addr = cpu_to_le64(mapping); |
| 6326 | |
| 6327 | tp->tx_skb[entry].len = len; |
| 6328 | } |
| 6329 | |
| 6330 | if (cur_frag) { |
| 6331 | tp->tx_skb[entry].skb = skb; |
| 6332 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6333 | } |
| 6334 | |
| 6335 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6336 | |
| 6337 | err_out: |
| 6338 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6339 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6340 | } |
| 6341 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6342 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6343 | { |
| 6344 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6345 | } |
| 6346 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6347 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6348 | struct net_device *dev); |
| 6349 | /* r8169_csum_workaround() |
| 6350 | * The hw limites the value the transport offset. When the offset is out of the |
| 6351 | * range, calculate the checksum by sw. |
| 6352 | */ |
| 6353 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6354 | struct sk_buff *skb) |
| 6355 | { |
| 6356 | if (skb_shinfo(skb)->gso_size) { |
| 6357 | netdev_features_t features = tp->dev->features; |
| 6358 | struct sk_buff *segs, *nskb; |
| 6359 | |
| 6360 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6361 | segs = skb_gso_segment(skb, features); |
| 6362 | if (IS_ERR(segs) || !segs) |
| 6363 | goto drop; |
| 6364 | |
| 6365 | do { |
| 6366 | nskb = segs; |
| 6367 | segs = segs->next; |
| 6368 | nskb->next = NULL; |
| 6369 | rtl8169_start_xmit(nskb, tp->dev); |
| 6370 | } while (segs); |
| 6371 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6372 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6373 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6374 | if (skb_checksum_help(skb) < 0) |
| 6375 | goto drop; |
| 6376 | |
| 6377 | rtl8169_start_xmit(skb, tp->dev); |
| 6378 | } else { |
| 6379 | struct net_device_stats *stats; |
| 6380 | |
| 6381 | drop: |
| 6382 | stats = &tp->dev->stats; |
| 6383 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6384 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6385 | } |
| 6386 | } |
| 6387 | |
| 6388 | /* msdn_giant_send_check() |
| 6389 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6390 | * packet length for IPv6 TCP large packets. |
| 6391 | */ |
| 6392 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6393 | { |
| 6394 | const struct ipv6hdr *ipv6h; |
| 6395 | struct tcphdr *th; |
| 6396 | int ret; |
| 6397 | |
| 6398 | ret = skb_cow_head(skb, 0); |
| 6399 | if (ret) |
| 6400 | return ret; |
| 6401 | |
| 6402 | ipv6h = ipv6_hdr(skb); |
| 6403 | th = tcp_hdr(skb); |
| 6404 | |
| 6405 | th->check = 0; |
| 6406 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6407 | |
| 6408 | return ret; |
| 6409 | } |
| 6410 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6411 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6412 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6414 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6415 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6416 | if (mss) { |
| 6417 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6418 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6419 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6420 | const struct iphdr *ip = ip_hdr(skb); |
| 6421 | |
| 6422 | if (ip->protocol == IPPROTO_TCP) |
| 6423 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6424 | else if (ip->protocol == IPPROTO_UDP) |
| 6425 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6426 | else |
| 6427 | WARN_ON_ONCE(1); |
| 6428 | } |
| 6429 | |
| 6430 | return true; |
| 6431 | } |
| 6432 | |
| 6433 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6434 | struct sk_buff *skb, u32 *opts) |
| 6435 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6436 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6437 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6438 | |
| 6439 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6440 | if (transport_offset > GTTCPHO_MAX) { |
| 6441 | netif_warn(tp, tx_err, tp->dev, |
| 6442 | "Invalid transport offset 0x%x for TSO\n", |
| 6443 | transport_offset); |
| 6444 | return false; |
| 6445 | } |
| 6446 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6447 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6448 | case htons(ETH_P_IP): |
| 6449 | opts[0] |= TD1_GTSENV4; |
| 6450 | break; |
| 6451 | |
| 6452 | case htons(ETH_P_IPV6): |
| 6453 | if (msdn_giant_send_check(skb)) |
| 6454 | return false; |
| 6455 | |
| 6456 | opts[0] |= TD1_GTSENV6; |
| 6457 | break; |
| 6458 | |
| 6459 | default: |
| 6460 | WARN_ON_ONCE(1); |
| 6461 | break; |
| 6462 | } |
| 6463 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6464 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6465 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6466 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6467 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6468 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6469 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6470 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6471 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6472 | if (transport_offset > TCPHO_MAX) { |
| 6473 | netif_warn(tp, tx_err, tp->dev, |
| 6474 | "Invalid transport offset 0x%x\n", |
| 6475 | transport_offset); |
| 6476 | return false; |
| 6477 | } |
| 6478 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6479 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6480 | case htons(ETH_P_IP): |
| 6481 | opts[1] |= TD1_IPv4_CS; |
| 6482 | ip_protocol = ip_hdr(skb)->protocol; |
| 6483 | break; |
| 6484 | |
| 6485 | case htons(ETH_P_IPV6): |
| 6486 | opts[1] |= TD1_IPv6_CS; |
| 6487 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6488 | break; |
| 6489 | |
| 6490 | default: |
| 6491 | ip_protocol = IPPROTO_RAW; |
| 6492 | break; |
| 6493 | } |
| 6494 | |
| 6495 | if (ip_protocol == IPPROTO_TCP) |
| 6496 | opts[1] |= TD1_TCP_CS; |
| 6497 | else if (ip_protocol == IPPROTO_UDP) |
| 6498 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6499 | else |
| 6500 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6501 | |
| 6502 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6503 | } else { |
| 6504 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6505 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6506 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6507 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6508 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6509 | } |
| 6510 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6511 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6512 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6513 | { |
| 6514 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6515 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6516 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6517 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6518 | dma_addr_t mapping; |
| 6519 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6520 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6521 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6522 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6523 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6524 | netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6525 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6526 | } |
| 6527 | |
| 6528 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6529 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6531 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6532 | opts[0] = DescOwn; |
| 6533 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6534 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6535 | r8169_csum_workaround(tp, skb); |
| 6536 | return NETDEV_TX_OK; |
| 6537 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6538 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6539 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6540 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6541 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6542 | if (net_ratelimit()) |
| 6543 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6544 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6546 | |
| 6547 | tp->tx_skb[entry].len = len; |
| 6548 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6549 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6550 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6551 | if (frags < 0) |
| 6552 | goto err_dma_1; |
| 6553 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6554 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6555 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6556 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6557 | tp->tx_skb[entry].skb = skb; |
| 6558 | } |
| 6559 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6560 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6561 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6562 | skb_tx_timestamp(skb); |
| 6563 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6564 | /* Force memory writes to complete before releasing descriptor */ |
| 6565 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6567 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6568 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | txd->opts1 = cpu_to_le32(status); |
| 6570 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6571 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6572 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6573 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6574 | tp->cur_tx += frags + 1; |
| 6575 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6576 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6578 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6579 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6580 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6581 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6582 | * not miss a ring update when it notices a stopped queue. |
| 6583 | */ |
| 6584 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6585 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6586 | /* Sync with rtl_tx: |
| 6587 | * - publish queue status and cur_tx ring index (write barrier) |
| 6588 | * - refresh dirty_tx ring index (read barrier). |
| 6589 | * May the current thread have a pessimistic view of the ring |
| 6590 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6591 | * can't. |
| 6592 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6593 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6594 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6595 | netif_wake_queue(dev); |
| 6596 | } |
| 6597 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6598 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6599 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6600 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6601 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6602 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6603 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6604 | dev->stats.tx_dropped++; |
| 6605 | return NETDEV_TX_OK; |
| 6606 | |
| 6607 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6608 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6609 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6610 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6611 | } |
| 6612 | |
| 6613 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6614 | { |
| 6615 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6616 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6617 | u16 pci_status, pci_cmd; |
| 6618 | |
| 6619 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6620 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6621 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6622 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6623 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6624 | |
| 6625 | /* |
| 6626 | * The recovery sequence below admits a very elaborated explanation: |
| 6627 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6628 | * - I did not see what else could be done; |
| 6629 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6630 | * |
| 6631 | * Feel free to adjust to your needs. |
| 6632 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6633 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6634 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6635 | else |
| 6636 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6637 | |
| 6638 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6639 | |
| 6640 | pci_write_config_word(pdev, PCI_STATUS, |
| 6641 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6642 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6643 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6644 | |
| 6645 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6646 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6647 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6648 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6649 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6650 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6651 | } |
| 6652 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6653 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6654 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6655 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6656 | } |
| 6657 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6658 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6659 | { |
| 6660 | unsigned int dirty_tx, tx_left; |
| 6661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6662 | dirty_tx = tp->dirty_tx; |
| 6663 | smp_rmb(); |
| 6664 | tx_left = tp->cur_tx - dirty_tx; |
| 6665 | |
| 6666 | while (tx_left > 0) { |
| 6667 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6668 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6669 | u32 status; |
| 6670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6671 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6672 | if (status & DescOwn) |
| 6673 | break; |
| 6674 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6675 | /* This barrier is needed to keep us from reading |
| 6676 | * any other fields out of the Tx descriptor until |
| 6677 | * we know the status of DescOwn |
| 6678 | */ |
| 6679 | dma_rmb(); |
| 6680 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6681 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6682 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6683 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6684 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6685 | tp->tx_stats.packets++; |
| 6686 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 6687 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6688 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6689 | tx_skb->skb = NULL; |
| 6690 | } |
| 6691 | dirty_tx++; |
| 6692 | tx_left--; |
| 6693 | } |
| 6694 | |
| 6695 | if (tp->dirty_tx != dirty_tx) { |
| 6696 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6697 | /* Sync with rtl8169_start_xmit: |
| 6698 | * - publish dirty_tx ring index (write barrier) |
| 6699 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6700 | * May the current thread miss the stopped queue condition, |
| 6701 | * a racing xmit thread can only have a right view of the |
| 6702 | * ring status. |
| 6703 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6704 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6705 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6706 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6707 | netif_wake_queue(dev); |
| 6708 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6709 | /* |
| 6710 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6711 | * too close. Let's kick an extra TxPoll request when a burst |
| 6712 | * of start_xmit activity is detected (if it is not detected, |
| 6713 | * it is slow enough). -- FR |
| 6714 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6715 | if (tp->cur_tx != dirty_tx) |
| 6716 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6717 | } |
| 6718 | } |
| 6719 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6720 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6721 | { |
| 6722 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6723 | } |
| 6724 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6725 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6726 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6727 | u32 status = opts1 & RxProtoMask; |
| 6728 | |
| 6729 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6730 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6731 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6732 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6733 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6734 | } |
| 6735 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6736 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6737 | struct rtl8169_private *tp, |
| 6738 | int pkt_size, |
| 6739 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6740 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6741 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6742 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6744 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6745 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6746 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6747 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6748 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6749 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6750 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6751 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6752 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | } |
| 6754 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6755 | static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | { |
| 6757 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6758 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6760 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6761 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6762 | for (rx_left = min(budget, NUM_RX_DESC); rx_left > 0; rx_left--, cur_rx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6763 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6764 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6765 | u32 status; |
| 6766 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6767 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6768 | if (status & DescOwn) |
| 6769 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6770 | |
| 6771 | /* This barrier is needed to keep us from reading |
| 6772 | * any other fields out of the Rx descriptor until |
| 6773 | * we know the status of DescOwn |
| 6774 | */ |
| 6775 | dma_rmb(); |
| 6776 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6777 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6778 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6779 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6780 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6781 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6782 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6784 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6785 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6786 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6787 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6788 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6789 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6790 | } else if (status & (RxRUNT | RxCRC) && |
| 6791 | !(status & RxRWT) && |
| 6792 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6793 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6795 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6796 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6797 | dma_addr_t addr; |
| 6798 | int pkt_size; |
| 6799 | |
| 6800 | process_pkt: |
| 6801 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6802 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6803 | pkt_size = (status & 0x00003fff) - 4; |
| 6804 | else |
| 6805 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6807 | /* |
| 6808 | * The driver does not support incoming fragmented |
| 6809 | * frames. They are seen as a symptom of over-mtu |
| 6810 | * sized frames. |
| 6811 | */ |
| 6812 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6813 | dev->stats.rx_dropped++; |
| 6814 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6815 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6816 | } |
| 6817 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6818 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6819 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6820 | if (!skb) { |
| 6821 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6822 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6823 | } |
| 6824 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6825 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6826 | skb_put(skb, pkt_size); |
| 6827 | skb->protocol = eth_type_trans(skb, dev); |
| 6828 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6829 | rtl8169_rx_vlan_tag(desc, skb); |
| 6830 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6831 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6832 | dev->stats.multicast++; |
| 6833 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6834 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6835 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6836 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6837 | tp->rx_stats.packets++; |
| 6838 | tp->rx_stats.bytes += pkt_size; |
| 6839 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6841 | release_descriptor: |
| 6842 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6843 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6844 | } |
| 6845 | |
| 6846 | count = cur_rx - tp->cur_rx; |
| 6847 | tp->cur_rx = cur_rx; |
| 6848 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6849 | return count; |
| 6850 | } |
| 6851 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6852 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6853 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6854 | struct rtl8169_private *tp = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6855 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6856 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6857 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6858 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6859 | if (status && status != 0xffff) { |
| 6860 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 6861 | if (status) { |
| 6862 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6863 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6864 | rtl_irq_disable(tp); |
Heiner Kallweit | 9a899a3 | 2018-04-17 23:21:01 +0200 | [diff] [blame] | 6865 | napi_schedule_irqoff(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6868 | return IRQ_RETVAL(handled); |
| 6869 | } |
| 6870 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6871 | /* |
| 6872 | * Workqueue context. |
| 6873 | */ |
| 6874 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6875 | { |
| 6876 | struct net_device *dev = tp->dev; |
| 6877 | u16 status; |
| 6878 | |
| 6879 | status = rtl_get_events(tp) & tp->event_slow; |
| 6880 | rtl_ack_events(tp, status); |
| 6881 | |
| 6882 | if (unlikely(status & RxFIFOOver)) { |
| 6883 | switch (tp->mac_version) { |
| 6884 | /* Work around for rx fifo overflow */ |
| 6885 | case RTL_GIGA_MAC_VER_11: |
| 6886 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6887 | /* XXX - Hack alert. See rtl_task(). */ |
| 6888 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6889 | default: |
| 6890 | break; |
| 6891 | } |
| 6892 | } |
| 6893 | |
| 6894 | if (unlikely(status & SYSErr)) |
| 6895 | rtl8169_pcierr_interrupt(dev); |
| 6896 | |
| 6897 | if (status & LinkChg) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6898 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6899 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 6900 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6901 | } |
| 6902 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6903 | static void rtl_task(struct work_struct *work) |
| 6904 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6905 | static const struct { |
| 6906 | int bitnr; |
| 6907 | void (*action)(struct rtl8169_private *); |
| 6908 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6909 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6910 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 6911 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 6912 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 6913 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6914 | struct rtl8169_private *tp = |
| 6915 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6916 | struct net_device *dev = tp->dev; |
| 6917 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6918 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6919 | rtl_lock_work(tp); |
| 6920 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6921 | if (!netif_running(dev) || |
| 6922 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6923 | goto out_unlock; |
| 6924 | |
| 6925 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6926 | bool pending; |
| 6927 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6928 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6929 | if (pending) |
| 6930 | rtl_work[i].action(tp); |
| 6931 | } |
| 6932 | |
| 6933 | out_unlock: |
| 6934 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6935 | } |
| 6936 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6937 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6938 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6939 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6940 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6941 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 6942 | int work_done= 0; |
| 6943 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6944 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6945 | status = rtl_get_events(tp); |
| 6946 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 6947 | |
| 6948 | if (status & RTL_EVENT_NAPI_RX) |
| 6949 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 6950 | |
| 6951 | if (status & RTL_EVENT_NAPI_TX) |
| 6952 | rtl_tx(dev, tp); |
| 6953 | |
| 6954 | if (status & tp->event_slow) { |
| 6955 | enable_mask &= ~tp->event_slow; |
| 6956 | |
| 6957 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 6958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6959 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6960 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 6961 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 6962 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6963 | rtl_irq_enable(tp, enable_mask); |
| 6964 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6967 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6969 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6970 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6971 | { |
| 6972 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6973 | |
| 6974 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6975 | return; |
| 6976 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6977 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 6978 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6979 | } |
| 6980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6981 | static void rtl8169_down(struct net_device *dev) |
| 6982 | { |
| 6983 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6984 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 6985 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6986 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6987 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6988 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6989 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6990 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6991 | /* |
| 6992 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6993 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6994 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6995 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6996 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6998 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6999 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7001 | rtl8169_tx_clear(tp); |
| 7002 | |
| 7003 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7004 | |
| 7005 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7006 | } |
| 7007 | |
| 7008 | static int rtl8169_close(struct net_device *dev) |
| 7009 | { |
| 7010 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7011 | struct pci_dev *pdev = tp->pci_dev; |
| 7012 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7013 | pm_runtime_get_sync(&pdev->dev); |
| 7014 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7015 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7016 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7017 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7018 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7019 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7021 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7022 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7023 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7024 | cancel_work_sync(&tp->wk.work); |
| 7025 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7026 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7027 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7028 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7029 | tp->RxPhyAddr); |
| 7030 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7031 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7032 | tp->TxDescArray = NULL; |
| 7033 | tp->RxDescArray = NULL; |
| 7034 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7035 | pm_runtime_put_sync(&pdev->dev); |
| 7036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7037 | return 0; |
| 7038 | } |
| 7039 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7040 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7041 | static void rtl8169_netpoll(struct net_device *dev) |
| 7042 | { |
| 7043 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7044 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 7045 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7046 | } |
| 7047 | #endif |
| 7048 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7049 | static int rtl_open(struct net_device *dev) |
| 7050 | { |
| 7051 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7052 | struct pci_dev *pdev = tp->pci_dev; |
| 7053 | int retval = -ENOMEM; |
| 7054 | |
| 7055 | pm_runtime_get_sync(&pdev->dev); |
| 7056 | |
| 7057 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7058 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7059 | * dma_alloc_coherent provides more. |
| 7060 | */ |
| 7061 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7062 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7063 | if (!tp->TxDescArray) |
| 7064 | goto err_pm_runtime_put; |
| 7065 | |
| 7066 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7067 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7068 | if (!tp->RxDescArray) |
| 7069 | goto err_free_tx_0; |
| 7070 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 7071 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7072 | if (retval < 0) |
| 7073 | goto err_free_rx_1; |
| 7074 | |
| 7075 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7076 | |
| 7077 | smp_mb(); |
| 7078 | |
| 7079 | rtl_request_firmware(tp); |
| 7080 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7081 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7082 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7083 | if (retval < 0) |
| 7084 | goto err_release_fw_2; |
| 7085 | |
| 7086 | rtl_lock_work(tp); |
| 7087 | |
| 7088 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7089 | |
| 7090 | napi_enable(&tp->napi); |
| 7091 | |
| 7092 | rtl8169_init_phy(dev, tp); |
| 7093 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7094 | rtl_pll_power_up(tp); |
| 7095 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7096 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7097 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7098 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7099 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7100 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7101 | netif_start_queue(dev); |
| 7102 | |
| 7103 | rtl_unlock_work(tp); |
| 7104 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7105 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7106 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7107 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7108 | out: |
| 7109 | return retval; |
| 7110 | |
| 7111 | err_release_fw_2: |
| 7112 | rtl_release_firmware(tp); |
| 7113 | rtl8169_rx_clear(tp); |
| 7114 | err_free_rx_1: |
| 7115 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7116 | tp->RxPhyAddr); |
| 7117 | tp->RxDescArray = NULL; |
| 7118 | err_free_tx_0: |
| 7119 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7120 | tp->TxPhyAddr); |
| 7121 | tp->TxDescArray = NULL; |
| 7122 | err_pm_runtime_put: |
| 7123 | pm_runtime_put_noidle(&pdev->dev); |
| 7124 | goto out; |
| 7125 | } |
| 7126 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7127 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7128 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7129 | { |
| 7130 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7131 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7132 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7133 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7134 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7135 | pm_runtime_get_noresume(&pdev->dev); |
| 7136 | |
| 7137 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7138 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7139 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7140 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7141 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7142 | stats->rx_packets = tp->rx_stats.packets; |
| 7143 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7144 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7145 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7146 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7147 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7148 | stats->tx_packets = tp->tx_stats.packets; |
| 7149 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7150 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7151 | |
| 7152 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7153 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7154 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7155 | stats->rx_errors = dev->stats.rx_errors; |
| 7156 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7157 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7158 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7159 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7160 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7161 | /* |
| 7162 | * Fetch additonal counter values missing in stats collected by driver |
| 7163 | * from tally counters. |
| 7164 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7165 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7166 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7167 | |
| 7168 | /* |
| 7169 | * Subtract values fetched during initalization. |
| 7170 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 7171 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7172 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7173 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7174 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7175 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7176 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7177 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 7178 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7179 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7180 | } |
| 7181 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7182 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7183 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7184 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7185 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7186 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7187 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7188 | |
| 7189 | netif_device_detach(dev); |
| 7190 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7191 | |
| 7192 | rtl_lock_work(tp); |
| 7193 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7194 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7195 | rtl_unlock_work(tp); |
| 7196 | |
| 7197 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7198 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7199 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7200 | #ifdef CONFIG_PM |
| 7201 | |
| 7202 | static int rtl8169_suspend(struct device *device) |
| 7203 | { |
| 7204 | struct pci_dev *pdev = to_pci_dev(device); |
| 7205 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7206 | |
| 7207 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 7208 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7209 | return 0; |
| 7210 | } |
| 7211 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7212 | static void __rtl8169_resume(struct net_device *dev) |
| 7213 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7214 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7215 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7216 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7217 | |
| 7218 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 7219 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7220 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7221 | rtl_lock_work(tp); |
| 7222 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7223 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7224 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7225 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7226 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7227 | } |
| 7228 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7229 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7230 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7231 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7232 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7233 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7234 | if (netif_running(dev)) |
| 7235 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7236 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7237 | return 0; |
| 7238 | } |
| 7239 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7240 | static int rtl8169_runtime_suspend(struct device *device) |
| 7241 | { |
| 7242 | struct pci_dev *pdev = to_pci_dev(device); |
| 7243 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7244 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7245 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7246 | if (!tp->TxDescArray) { |
| 7247 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7248 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7249 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7250 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7251 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7252 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7253 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7254 | |
| 7255 | rtl8169_net_suspend(dev); |
| 7256 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7257 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7258 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7259 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7260 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7261 | return 0; |
| 7262 | } |
| 7263 | |
| 7264 | static int rtl8169_runtime_resume(struct device *device) |
| 7265 | { |
| 7266 | struct pci_dev *pdev = to_pci_dev(device); |
| 7267 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7268 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 7269 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7270 | |
| 7271 | if (!tp->TxDescArray) |
| 7272 | return 0; |
| 7273 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7274 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7275 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7276 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7277 | |
| 7278 | __rtl8169_resume(dev); |
| 7279 | |
| 7280 | return 0; |
| 7281 | } |
| 7282 | |
| 7283 | static int rtl8169_runtime_idle(struct device *device) |
| 7284 | { |
| 7285 | struct pci_dev *pdev = to_pci_dev(device); |
| 7286 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7287 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7288 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 7289 | pm_schedule_suspend(device, 10000); |
| 7290 | |
| 7291 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7292 | } |
| 7293 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7294 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7295 | .suspend = rtl8169_suspend, |
| 7296 | .resume = rtl8169_resume, |
| 7297 | .freeze = rtl8169_suspend, |
| 7298 | .thaw = rtl8169_resume, |
| 7299 | .poweroff = rtl8169_suspend, |
| 7300 | .restore = rtl8169_resume, |
| 7301 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7302 | .runtime_resume = rtl8169_runtime_resume, |
| 7303 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7304 | }; |
| 7305 | |
| 7306 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7307 | |
| 7308 | #else /* !CONFIG_PM */ |
| 7309 | |
| 7310 | #define RTL8169_PM_OPS NULL |
| 7311 | |
| 7312 | #endif /* !CONFIG_PM */ |
| 7313 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7314 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7315 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7316 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7317 | switch (tp->mac_version) { |
| 7318 | case RTL_GIGA_MAC_VER_11: |
| 7319 | case RTL_GIGA_MAC_VER_12: |
| 7320 | case RTL_GIGA_MAC_VER_17: |
| 7321 | pci_clear_master(tp->pci_dev); |
| 7322 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7323 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7324 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7325 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7326 | break; |
| 7327 | default: |
| 7328 | break; |
| 7329 | } |
| 7330 | } |
| 7331 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7332 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7333 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7334 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7335 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7336 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7337 | rtl8169_net_suspend(dev); |
| 7338 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7339 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7340 | rtl_rar_set(tp, dev->perm_addr); |
| 7341 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7342 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7343 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7344 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 7345 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7346 | rtl_wol_suspend_quirk(tp); |
| 7347 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7348 | } |
| 7349 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7350 | pci_wake_from_d3(pdev, true); |
| 7351 | pci_set_power_state(pdev, PCI_D3hot); |
| 7352 | } |
| 7353 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7354 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7355 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7356 | { |
| 7357 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7358 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7359 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7360 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7361 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7362 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7363 | netif_napi_del(&tp->napi); |
| 7364 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7365 | unregister_netdev(dev); |
| 7366 | |
| 7367 | rtl_release_firmware(tp); |
| 7368 | |
| 7369 | if (pci_dev_run_wake(pdev)) |
| 7370 | pm_runtime_get_noresume(&pdev->dev); |
| 7371 | |
| 7372 | /* restore original MAC address */ |
| 7373 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7374 | } |
| 7375 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7376 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7377 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7378 | .ndo_stop = rtl8169_close, |
| 7379 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7380 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7381 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7382 | .ndo_validate_addr = eth_validate_addr, |
| 7383 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7384 | .ndo_fix_features = rtl8169_fix_features, |
| 7385 | .ndo_set_features = rtl8169_set_features, |
| 7386 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7387 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7388 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7389 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7390 | .ndo_poll_controller = rtl8169_netpoll, |
| 7391 | #endif |
| 7392 | |
| 7393 | }; |
| 7394 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7395 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7396 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7397 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7398 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7399 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7400 | u8 default_ver; |
| 7401 | } rtl_cfg_infos [] = { |
| 7402 | [RTL_CFG_0] = { |
| 7403 | .hw_start = rtl_hw_start_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7404 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7405 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7406 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7407 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7408 | }, |
| 7409 | [RTL_CFG_1] = { |
| 7410 | .hw_start = rtl_hw_start_8168, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7411 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7412 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7413 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7414 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7415 | }, |
| 7416 | [RTL_CFG_2] = { |
| 7417 | .hw_start = rtl_hw_start_8101, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7418 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7419 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7420 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7421 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7422 | } |
| 7423 | }; |
| 7424 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7425 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7426 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7427 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7428 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7429 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7430 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7431 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7432 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7433 | flags = PCI_IRQ_LEGACY; |
| 7434 | } else { |
| 7435 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7436 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7437 | |
| 7438 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7439 | } |
| 7440 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7441 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7442 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7443 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7444 | } |
| 7445 | |
| 7446 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7447 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7448 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7449 | } |
| 7450 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7451 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7452 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7453 | u32 data; |
| 7454 | |
| 7455 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7456 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7457 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7458 | |
| 7459 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7460 | return; |
| 7461 | |
| 7462 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7463 | return; |
| 7464 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7465 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7466 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7467 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7468 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7469 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7470 | data &= ~(1 << 14); |
| 7471 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7472 | |
| 7473 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7474 | return; |
| 7475 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7476 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7477 | data |= (1 << 15); |
| 7478 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7479 | |
| 7480 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7481 | return; |
| 7482 | } |
| 7483 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7484 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7485 | { |
| 7486 | rtl8168ep_stop_cmac(tp); |
| 7487 | rtl_hw_init_8168g(tp); |
| 7488 | } |
| 7489 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7490 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7491 | { |
| 7492 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7493 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7494 | rtl_hw_init_8168g(tp); |
| 7495 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7496 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7497 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7498 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7499 | default: |
| 7500 | break; |
| 7501 | } |
| 7502 | } |
| 7503 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7504 | static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7505 | { |
| 7506 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7507 | struct rtl8169_private *tp; |
| 7508 | struct mii_if_info *mii; |
| 7509 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7510 | int chipset, region, i; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7511 | int rc; |
| 7512 | |
| 7513 | if (netif_msg_drv(&debug)) { |
| 7514 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 7515 | MODULENAME, RTL8169_VERSION); |
| 7516 | } |
| 7517 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7518 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7519 | if (!dev) |
| 7520 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7521 | |
| 7522 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7523 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7524 | tp = netdev_priv(dev); |
| 7525 | tp->dev = dev; |
| 7526 | tp->pci_dev = pdev; |
| 7527 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 7528 | |
| 7529 | mii = &tp->mii; |
| 7530 | mii->dev = dev; |
| 7531 | mii->mdio_read = rtl_mdio_read; |
| 7532 | mii->mdio_write = rtl_mdio_write; |
| 7533 | mii->phy_id_mask = 0x1f; |
| 7534 | mii->reg_num_mask = 0x1f; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7535 | mii->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7536 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7537 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7538 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7539 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7540 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7541 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7542 | } |
| 7543 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7544 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7545 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7546 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7547 | /* use first MMIO region */ |
| 7548 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7549 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7550 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7551 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7552 | } |
| 7553 | |
| 7554 | /* check for weird/broken PCI region reporting */ |
| 7555 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7556 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7557 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7558 | } |
| 7559 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7560 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7561 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7562 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7563 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7564 | } |
| 7565 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7566 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7567 | |
| 7568 | if (!pci_is_pcie(pdev)) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7569 | dev_info(&pdev->dev, "not PCI Express\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7570 | |
| 7571 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7572 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7573 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame^] | 7574 | if (rtl_tbi_enabled(tp)) { |
| 7575 | dev_err(&pdev->dev, "TBI fiber mode not supported\n"); |
| 7576 | return -ENODEV; |
| 7577 | } |
| 7578 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7579 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7580 | |
| 7581 | if ((sizeof(dma_addr_t) > 4) && |
| 7582 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 7583 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 7584 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 7585 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7586 | |
| 7587 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7588 | if (!pci_is_pcie(pdev)) |
| 7589 | tp->cp_cmd |= PCIDAC; |
| 7590 | dev->features |= NETIF_F_HIGHDMA; |
| 7591 | } else { |
| 7592 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7593 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7594 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7595 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7596 | } |
| 7597 | } |
| 7598 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7599 | rtl_init_rxcfg(tp); |
| 7600 | |
| 7601 | rtl_irq_disable(tp); |
| 7602 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7603 | rtl_hw_initialize(tp); |
| 7604 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7605 | rtl_hw_reset(tp); |
| 7606 | |
| 7607 | rtl_ack_events(tp, 0xffff); |
| 7608 | |
| 7609 | pci_set_master(pdev); |
| 7610 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7611 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7612 | rtl_init_jumbo_ops(tp); |
| 7613 | |
| 7614 | rtl8169_print_mac_version(tp); |
| 7615 | |
| 7616 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7617 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7618 | rc = rtl_alloc_irq(tp); |
| 7619 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7620 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7621 | return rc; |
| 7622 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7623 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7624 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 7625 | __rtl8169_set_wol(tp, 0); |
| 7626 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7627 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7628 | u64_stats_init(&tp->rx_stats.syncp); |
| 7629 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7630 | |
| 7631 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7632 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7633 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7634 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7635 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7636 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7637 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7638 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7639 | if (is_valid_ether_addr(mac_addr)) |
| 7640 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7641 | break; |
| 7642 | default: |
| 7643 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7644 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7645 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7646 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7647 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7648 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7649 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7650 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7651 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7652 | |
| 7653 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7654 | * properly for all devices */ |
| 7655 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7656 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7657 | |
| 7658 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7659 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7660 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7661 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7662 | NETIF_F_HIGHDMA; |
| 7663 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7664 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7665 | |
| 7666 | /* |
| 7667 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7668 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7669 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7670 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7671 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7672 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7673 | |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7674 | switch (rtl_chip_infos[chipset].txd_version) { |
| 7675 | case RTL_TD_0: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7676 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7677 | break; |
| 7678 | case RTL_TD_1: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7679 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7680 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7681 | break; |
| 7682 | default: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7683 | WARN_ON_ONCE(1); |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7684 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7685 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7686 | dev->hw_features |= NETIF_F_RXALL; |
| 7687 | dev->hw_features |= NETIF_F_RXFCS; |
| 7688 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7689 | /* MTU range: 60 - hw-specific max */ |
| 7690 | dev->min_mtu = ETH_ZLEN; |
| 7691 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 7692 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7693 | tp->hw_start = cfg->hw_start; |
| 7694 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7695 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7696 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 7697 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7698 | |
| 7699 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7700 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7701 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7702 | &tp->counters_phys_addr, |
| 7703 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7704 | if (!tp->counters) |
| 7705 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7706 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7707 | pci_set_drvdata(pdev, dev); |
| 7708 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7709 | rc = register_netdev(dev); |
| 7710 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7711 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7712 | |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7713 | netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n", |
| 7714 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 90b989c | 2018-04-17 23:32:15 +0200 | [diff] [blame] | 7715 | (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7716 | pci_irq_vector(pdev, 0)); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7717 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 7718 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 7719 | "tx checksumming: %s]\n", |
| 7720 | rtl_chip_infos[chipset].jumbo_max, |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 7721 | tp->mac_version <= RTL_GIGA_MAC_VER_06 ? "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7722 | } |
| 7723 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7724 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7725 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7726 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7727 | netif_carrier_off(dev); |
| 7728 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7729 | if (pci_dev_run_wake(pdev)) |
| 7730 | pm_runtime_put_sync(&pdev->dev); |
| 7731 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7732 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7733 | } |
| 7734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7735 | static struct pci_driver rtl8169_pci_driver = { |
| 7736 | .name = MODULENAME, |
| 7737 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7738 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7739 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7740 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7741 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7742 | }; |
| 7743 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7744 | module_pci_driver(rtl8169_pci_driver); |