Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3 | * r8169.c: RealTek 8169/8168/8101 ethernet driver. |
| 4 | * |
| 5 | * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw> |
| 6 | * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com> |
| 7 | * Copyright (c) a lot of people too. Please respect their work. |
| 8 | * |
| 9 | * See MAINTAINERS file for support contact information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/pci.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/etherdevice.h> |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 17 | #include <linux/clk.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/delay.h> |
| 19 | #include <linux/ethtool.h> |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 20 | #include <linux/phy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/if_vlan.h> |
| 22 | #include <linux/crc32.h> |
| 23 | #include <linux/in.h> |
Heiner Kallweit | 098b01a | 2018-08-10 22:37:31 +0200 | [diff] [blame] | 24 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/ip.h> |
| 26 | #include <linux/tcp.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 29 | #include <linux/pm_runtime.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 30 | #include <linux/prefetch.h> |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 31 | #include <linux/pci-aspm.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 32 | #include <linux/ipv6.h> |
| 33 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Heiner Kallweit | 8197f9d | 2019-06-05 08:02:31 +0200 | [diff] [blame] | 35 | #include "r8169_firmware.h" |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define MODULENAME "r8169" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 39 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 40 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 41 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 42 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 45 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 50 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 51 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 52 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 53 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 54 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 55 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 56 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 57 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 58 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 59 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 60 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 63 | The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 64 | #define MC_FILTER_LIMIT 32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 66 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 68 | |
| 69 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 70 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 72 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 74 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 75 | |
Heiner Kallweit | 145a40e | 2019-06-10 18:25:29 +0200 | [diff] [blame] | 76 | #define RTL_CFG_NO_GBIT 1 |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 79 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 80 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 81 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 82 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 83 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 84 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | enum mac_version { |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 87 | /* support for ancient RTL_GIGA_MAC_VER_01 has been removed */ |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 88 | RTL_GIGA_MAC_VER_02, |
| 89 | RTL_GIGA_MAC_VER_03, |
| 90 | RTL_GIGA_MAC_VER_04, |
| 91 | RTL_GIGA_MAC_VER_05, |
| 92 | RTL_GIGA_MAC_VER_06, |
| 93 | RTL_GIGA_MAC_VER_07, |
| 94 | RTL_GIGA_MAC_VER_08, |
| 95 | RTL_GIGA_MAC_VER_09, |
| 96 | RTL_GIGA_MAC_VER_10, |
| 97 | RTL_GIGA_MAC_VER_11, |
| 98 | RTL_GIGA_MAC_VER_12, |
| 99 | RTL_GIGA_MAC_VER_13, |
| 100 | RTL_GIGA_MAC_VER_14, |
| 101 | RTL_GIGA_MAC_VER_15, |
| 102 | RTL_GIGA_MAC_VER_16, |
| 103 | RTL_GIGA_MAC_VER_17, |
| 104 | RTL_GIGA_MAC_VER_18, |
| 105 | RTL_GIGA_MAC_VER_19, |
| 106 | RTL_GIGA_MAC_VER_20, |
| 107 | RTL_GIGA_MAC_VER_21, |
| 108 | RTL_GIGA_MAC_VER_22, |
| 109 | RTL_GIGA_MAC_VER_23, |
| 110 | RTL_GIGA_MAC_VER_24, |
| 111 | RTL_GIGA_MAC_VER_25, |
| 112 | RTL_GIGA_MAC_VER_26, |
| 113 | RTL_GIGA_MAC_VER_27, |
| 114 | RTL_GIGA_MAC_VER_28, |
| 115 | RTL_GIGA_MAC_VER_29, |
| 116 | RTL_GIGA_MAC_VER_30, |
| 117 | RTL_GIGA_MAC_VER_31, |
| 118 | RTL_GIGA_MAC_VER_32, |
| 119 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 120 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 121 | RTL_GIGA_MAC_VER_35, |
| 122 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 123 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 124 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 125 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 126 | RTL_GIGA_MAC_VER_40, |
| 127 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 129 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 130 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 131 | RTL_GIGA_MAC_VER_45, |
| 132 | RTL_GIGA_MAC_VER_46, |
| 133 | RTL_GIGA_MAC_VER_47, |
| 134 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 135 | RTL_GIGA_MAC_VER_49, |
| 136 | RTL_GIGA_MAC_VER_50, |
| 137 | RTL_GIGA_MAC_VER_51, |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 138 | RTL_GIGA_MAC_NONE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 141 | #define JUMBO_1K ETH_DATA_LEN |
| 142 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 143 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 144 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 145 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 146 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 147 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | const char *name; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 149 | const char *fw_name; |
| 150 | } rtl_chip_infos[] = { |
| 151 | /* PCI devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 152 | [RTL_GIGA_MAC_VER_02] = {"RTL8169s" }, |
| 153 | [RTL_GIGA_MAC_VER_03] = {"RTL8110s" }, |
| 154 | [RTL_GIGA_MAC_VER_04] = {"RTL8169sb/8110sb" }, |
| 155 | [RTL_GIGA_MAC_VER_05] = {"RTL8169sc/8110sc" }, |
| 156 | [RTL_GIGA_MAC_VER_06] = {"RTL8169sc/8110sc" }, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 157 | /* PCI-E devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 158 | [RTL_GIGA_MAC_VER_07] = {"RTL8102e" }, |
| 159 | [RTL_GIGA_MAC_VER_08] = {"RTL8102e" }, |
Heiner Kallweit | 9e0773c | 2019-07-07 13:59:54 +0200 | [diff] [blame] | 160 | [RTL_GIGA_MAC_VER_09] = {"RTL8102e/RTL8103e" }, |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 161 | [RTL_GIGA_MAC_VER_10] = {"RTL8101e" }, |
| 162 | [RTL_GIGA_MAC_VER_11] = {"RTL8168b/8111b" }, |
| 163 | [RTL_GIGA_MAC_VER_12] = {"RTL8168b/8111b" }, |
| 164 | [RTL_GIGA_MAC_VER_13] = {"RTL8101e" }, |
| 165 | [RTL_GIGA_MAC_VER_14] = {"RTL8100e" }, |
| 166 | [RTL_GIGA_MAC_VER_15] = {"RTL8100e" }, |
| 167 | [RTL_GIGA_MAC_VER_16] = {"RTL8101e" }, |
| 168 | [RTL_GIGA_MAC_VER_17] = {"RTL8168b/8111b" }, |
| 169 | [RTL_GIGA_MAC_VER_18] = {"RTL8168cp/8111cp" }, |
| 170 | [RTL_GIGA_MAC_VER_19] = {"RTL8168c/8111c" }, |
| 171 | [RTL_GIGA_MAC_VER_20] = {"RTL8168c/8111c" }, |
| 172 | [RTL_GIGA_MAC_VER_21] = {"RTL8168c/8111c" }, |
| 173 | [RTL_GIGA_MAC_VER_22] = {"RTL8168c/8111c" }, |
| 174 | [RTL_GIGA_MAC_VER_23] = {"RTL8168cp/8111cp" }, |
| 175 | [RTL_GIGA_MAC_VER_24] = {"RTL8168cp/8111cp" }, |
| 176 | [RTL_GIGA_MAC_VER_25] = {"RTL8168d/8111d", FIRMWARE_8168D_1}, |
| 177 | [RTL_GIGA_MAC_VER_26] = {"RTL8168d/8111d", FIRMWARE_8168D_2}, |
| 178 | [RTL_GIGA_MAC_VER_27] = {"RTL8168dp/8111dp" }, |
| 179 | [RTL_GIGA_MAC_VER_28] = {"RTL8168dp/8111dp" }, |
| 180 | [RTL_GIGA_MAC_VER_29] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 181 | [RTL_GIGA_MAC_VER_30] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 182 | [RTL_GIGA_MAC_VER_31] = {"RTL8168dp/8111dp" }, |
| 183 | [RTL_GIGA_MAC_VER_32] = {"RTL8168e/8111e", FIRMWARE_8168E_1}, |
| 184 | [RTL_GIGA_MAC_VER_33] = {"RTL8168e/8111e", FIRMWARE_8168E_2}, |
| 185 | [RTL_GIGA_MAC_VER_34] = {"RTL8168evl/8111evl", FIRMWARE_8168E_3}, |
| 186 | [RTL_GIGA_MAC_VER_35] = {"RTL8168f/8111f", FIRMWARE_8168F_1}, |
| 187 | [RTL_GIGA_MAC_VER_36] = {"RTL8168f/8111f", FIRMWARE_8168F_2}, |
| 188 | [RTL_GIGA_MAC_VER_37] = {"RTL8402", FIRMWARE_8402_1 }, |
| 189 | [RTL_GIGA_MAC_VER_38] = {"RTL8411", FIRMWARE_8411_1 }, |
| 190 | [RTL_GIGA_MAC_VER_39] = {"RTL8106e", FIRMWARE_8106E_1}, |
| 191 | [RTL_GIGA_MAC_VER_40] = {"RTL8168g/8111g", FIRMWARE_8168G_2}, |
| 192 | [RTL_GIGA_MAC_VER_41] = {"RTL8168g/8111g" }, |
Heiner Kallweit | 9e0773c | 2019-07-07 13:59:54 +0200 | [diff] [blame] | 193 | [RTL_GIGA_MAC_VER_42] = {"RTL8168gu/8111gu", FIRMWARE_8168G_3}, |
| 194 | [RTL_GIGA_MAC_VER_43] = {"RTL8106eus", FIRMWARE_8106E_2}, |
| 195 | [RTL_GIGA_MAC_VER_44] = {"RTL8411b", FIRMWARE_8411_2 }, |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_45] = {"RTL8168h/8111h", FIRMWARE_8168H_1}, |
| 197 | [RTL_GIGA_MAC_VER_46] = {"RTL8168h/8111h", FIRMWARE_8168H_2}, |
| 198 | [RTL_GIGA_MAC_VER_47] = {"RTL8107e", FIRMWARE_8107E_1}, |
| 199 | [RTL_GIGA_MAC_VER_48] = {"RTL8107e", FIRMWARE_8107E_2}, |
| 200 | [RTL_GIGA_MAC_VER_49] = {"RTL8168ep/8111ep" }, |
| 201 | [RTL_GIGA_MAC_VER_50] = {"RTL8168ep/8111ep" }, |
| 202 | [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 205 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Heiner Kallweit | 145a40e | 2019-06-10 18:25:29 +0200 | [diff] [blame] | 206 | { PCI_VDEVICE(REALTEK, 0x2502) }, |
| 207 | { PCI_VDEVICE(REALTEK, 0x2600) }, |
| 208 | { PCI_VDEVICE(REALTEK, 0x8129) }, |
| 209 | { PCI_VDEVICE(REALTEK, 0x8136), RTL_CFG_NO_GBIT }, |
| 210 | { PCI_VDEVICE(REALTEK, 0x8161) }, |
| 211 | { PCI_VDEVICE(REALTEK, 0x8167) }, |
| 212 | { PCI_VDEVICE(REALTEK, 0x8168) }, |
| 213 | { PCI_VDEVICE(NCUBE, 0x8168) }, |
| 214 | { PCI_VDEVICE(REALTEK, 0x8169) }, |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 215 | { PCI_VENDOR_ID_DLINK, 0x4300, |
Heiner Kallweit | 145a40e | 2019-06-10 18:25:29 +0200 | [diff] [blame] | 216 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0 }, |
Heiner Kallweit | 9d9f3fb | 2019-06-15 09:58:21 +0200 | [diff] [blame] | 217 | { PCI_VDEVICE(DLINK, 0x4300) }, |
| 218 | { PCI_VDEVICE(DLINK, 0x4302) }, |
| 219 | { PCI_VDEVICE(AT, 0xc107) }, |
| 220 | { PCI_VDEVICE(USR, 0x0116) }, |
| 221 | { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0024 }, |
| 222 | { 0x0001, 0x8168, PCI_ANY_ID, 0x2410 }, |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 223 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 227 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 228 | static struct { |
| 229 | u32 msg_enable; |
| 230 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 232 | enum rtl_registers { |
| 233 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 234 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 235 | MAR0 = 8, /* Multicast filter. */ |
| 236 | CounterAddrLow = 0x10, |
| 237 | CounterAddrHigh = 0x14, |
| 238 | TxDescStartAddrLow = 0x20, |
| 239 | TxDescStartAddrHigh = 0x24, |
| 240 | TxHDescStartAddrLow = 0x28, |
| 241 | TxHDescStartAddrHigh = 0x2c, |
| 242 | FLASH = 0x30, |
| 243 | ERSR = 0x36, |
| 244 | ChipCmd = 0x37, |
| 245 | TxPoll = 0x38, |
| 246 | IntrMask = 0x3c, |
| 247 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 248 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 249 | TxConfig = 0x40, |
| 250 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 251 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 252 | |
| 253 | RxConfig = 0x44, |
| 254 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 255 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 256 | #define RXCFG_FIFO_SHIFT 13 |
| 257 | /* No threshold before first PCI xfer */ |
| 258 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 259 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 260 | #define RXCFG_DMA_SHIFT 8 |
| 261 | /* Unlimited maximum PCI burst. */ |
| 262 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 263 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 264 | RxMissed = 0x4c, |
| 265 | Cfg9346 = 0x50, |
| 266 | Config0 = 0x51, |
| 267 | Config1 = 0x52, |
| 268 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 269 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 270 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 271 | Config3 = 0x54, |
| 272 | Config4 = 0x55, |
| 273 | Config5 = 0x56, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 274 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 275 | PHYstatus = 0x6c, |
| 276 | RxMaxSize = 0xda, |
| 277 | CPlusCmd = 0xe0, |
| 278 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 279 | |
| 280 | #define RTL_COALESCE_MASK 0x0f |
| 281 | #define RTL_COALESCE_SHIFT 4 |
| 282 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 283 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 284 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 285 | RxDescAddrLow = 0xe4, |
| 286 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 287 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 288 | |
| 289 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 290 | |
| 291 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 292 | |
| 293 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 294 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 295 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 296 | FuncEvent = 0xf0, |
| 297 | FuncEventMask = 0xf4, |
| 298 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 299 | IBCR0 = 0xf8, |
| 300 | IBCR2 = 0xf9, |
| 301 | IBIMR0 = 0xfa, |
| 302 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 303 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 306 | enum rtl8168_8101_registers { |
| 307 | CSIDR = 0x64, |
| 308 | CSIAR = 0x68, |
| 309 | #define CSIAR_FLAG 0x80000000 |
| 310 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 311 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 312 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 313 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 314 | EPHYAR = 0x80, |
| 315 | #define EPHYAR_FLAG 0x80000000 |
| 316 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 317 | #define EPHYAR_REG_MASK 0x1f |
| 318 | #define EPHYAR_REG_SHIFT 16 |
| 319 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 320 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 321 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 322 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 323 | DBG_REG = 0xd1, |
| 324 | #define FIX_NAK_1 (1 << 4) |
| 325 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 326 | TWSI = 0xd2, |
| 327 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 328 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 329 | #define TX_EMPTY (1 << 5) |
| 330 | #define RX_EMPTY (1 << 4) |
| 331 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 332 | #define EN_NDP (1 << 3) |
| 333 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 334 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 335 | EFUSEAR = 0xdc, |
| 336 | #define EFUSEAR_FLAG 0x80000000 |
| 337 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 338 | #define EFUSEAR_READ_CMD 0x00000000 |
| 339 | #define EFUSEAR_REG_MASK 0x03ff |
| 340 | #define EFUSEAR_REG_SHIFT 8 |
| 341 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 342 | MISC_1 = 0xf2, |
| 343 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 344 | }; |
| 345 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 346 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 347 | LED_FREQ = 0x1a, |
| 348 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 349 | ERIDR = 0x70, |
| 350 | ERIAR = 0x74, |
| 351 | #define ERIAR_FLAG 0x80000000 |
| 352 | #define ERIAR_WRITE_CMD 0x80000000 |
| 353 | #define ERIAR_READ_CMD 0x00000000 |
| 354 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 355 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 356 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 357 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 358 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 359 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 360 | #define ERIAR_MASK_SHIFT 12 |
| 361 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 362 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 363 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 364 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 365 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 366 | EPHY_RXER_NUM = 0x7c, |
| 367 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 368 | #define OCPDR_WRITE_CMD 0x80000000 |
| 369 | #define OCPDR_READ_CMD 0x00000000 |
| 370 | #define OCPDR_REG_MASK 0x7f |
| 371 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 372 | #define OCPDR_DATA_MASK 0xffff |
| 373 | OCPAR = 0xb4, |
| 374 | #define OCPAR_FLAG 0x80000000 |
| 375 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 376 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 377 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 378 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 379 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 380 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 381 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 382 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 383 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 384 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 385 | }; |
| 386 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 387 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 389 | SYSErr = 0x8000, |
| 390 | PCSTimeout = 0x4000, |
| 391 | SWInt = 0x0100, |
| 392 | TxDescUnavail = 0x0080, |
| 393 | RxFIFOOver = 0x0040, |
| 394 | LinkChg = 0x0020, |
| 395 | RxOverflow = 0x0010, |
| 396 | TxErr = 0x0008, |
| 397 | TxOK = 0x0004, |
| 398 | RxErr = 0x0002, |
| 399 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | /* RxStatusDesc */ |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 402 | RxRWT = (1 << 22), |
| 403 | RxRES = (1 << 21), |
| 404 | RxRUNT = (1 << 20), |
| 405 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 408 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 409 | CmdReset = 0x10, |
| 410 | CmdRxEnb = 0x08, |
| 411 | CmdTxEnb = 0x04, |
| 412 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 414 | /* TXPoll register p.5 */ |
| 415 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 416 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 417 | FSWInt = 0x01, /* Forced software interrupt */ |
| 418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 420 | Cfg9346_Lock = 0x00, |
| 421 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 424 | AcceptErr = 0x20, |
| 425 | AcceptRunt = 0x10, |
| 426 | AcceptBroadcast = 0x08, |
| 427 | AcceptMulticast = 0x04, |
| 428 | AcceptMyPhys = 0x02, |
| 429 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 430 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* TxConfigBits */ |
| 433 | TxInterFrameGapShift = 24, |
| 434 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 435 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 436 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 437 | LEDS1 = (1 << 7), |
| 438 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 439 | Speed_down = (1 << 4), |
| 440 | MEMMAP = (1 << 3), |
| 441 | IOMAP = (1 << 2), |
| 442 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 443 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 444 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 445 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 446 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 447 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 448 | PCI_Clock_66MHz = 0x01, |
| 449 | PCI_Clock_33MHz = 0x00, |
| 450 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 451 | /* Config3 register p.25 */ |
| 452 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 453 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 454 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 455 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 456 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 457 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 458 | /* Config4 register */ |
| 459 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 460 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 461 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 462 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 463 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 464 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 465 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 466 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 467 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 468 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 471 | EnableBist = (1 << 15), // 8168 8101 |
| 472 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 473 | Normal_mode = (1 << 13), // unused |
| 474 | Force_half_dup = (1 << 12), // 8168 8101 |
| 475 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 476 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 477 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 478 | ASF = (1 << 8), // 8168 8101 |
| 479 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 480 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | RxVlan = (1 << 6), |
| 482 | RxChkSum = (1 << 5), |
| 483 | PCIDAC = (1 << 4), |
| 484 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 485 | #define INTT_MASK GENMASK(1, 0) |
Heiner Kallweit | bc73241 | 2019-06-10 18:22:33 +0200 | [diff] [blame] | 486 | #define CPCMD_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 489 | TBI_Enable = 0x80, |
| 490 | TxFlowCtrl = 0x40, |
| 491 | RxFlowCtrl = 0x20, |
| 492 | _1000bpsF = 0x10, |
| 493 | _100bps = 0x08, |
| 494 | _10bps = 0x04, |
| 495 | LinkStatus = 0x02, |
| 496 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 498 | /* ResetCounterCommand */ |
| 499 | CounterReset = 0x1, |
| 500 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 501 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 502 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 503 | |
| 504 | /* magic enable v2 */ |
| 505 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | }; |
| 507 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 508 | enum rtl_desc_bit { |
| 509 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 511 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 512 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 513 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 514 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 516 | /* Generic case. */ |
| 517 | enum rtl_tx_desc_bit { |
| 518 | /* First doubleword. */ |
| 519 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 520 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 522 | /* Second doubleword. */ |
| 523 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 524 | }; |
| 525 | |
| 526 | /* 8169, 8168b and 810x except 8102e. */ |
| 527 | enum rtl_tx_desc_bit_0 { |
| 528 | /* First doubleword. */ |
| 529 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 530 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 531 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 532 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 533 | }; |
| 534 | |
| 535 | /* 8102e, 8168c and beyond. */ |
| 536 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 537 | /* First doubleword. */ |
| 538 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 539 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 540 | #define GTTCPHO_SHIFT 18 |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 541 | #define GTTCPHO_MAX 0x7f |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 542 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 543 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 544 | #define TCPHO_SHIFT 18 |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 545 | #define TCPHO_MAX 0x3ff |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 546 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 547 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 548 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 549 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 550 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 551 | }; |
| 552 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 553 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | /* Rx private */ |
| 555 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 556 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | #define RxProtoUDP (PID1) |
| 559 | #define RxProtoTCP (PID0) |
| 560 | #define RxProtoIP (PID1 | PID0) |
| 561 | #define RxProtoMask RxProtoIP |
| 562 | |
| 563 | IPFail = (1 << 16), /* IP checksum failed */ |
| 564 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 565 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 566 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 567 | }; |
| 568 | |
| 569 | #define RsvdMask 0x3fffc000 |
| 570 | |
Heiner Kallweit | 0170d59 | 2019-07-26 21:48:32 +0200 | [diff] [blame] | 571 | #define RTL_GSO_MAX_SIZE_V1 32000 |
| 572 | #define RTL_GSO_MAX_SEGS_V1 24 |
| 573 | #define RTL_GSO_MAX_SIZE_V2 64000 |
| 574 | #define RTL_GSO_MAX_SEGS_V2 64 |
| 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 577 | __le32 opts1; |
| 578 | __le32 opts2; |
| 579 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 583 | __le32 opts1; |
| 584 | __le32 opts2; |
| 585 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | struct ring_info { |
| 589 | struct sk_buff *skb; |
| 590 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | }; |
| 592 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 593 | struct rtl8169_counters { |
| 594 | __le64 tx_packets; |
| 595 | __le64 rx_packets; |
| 596 | __le64 tx_errors; |
| 597 | __le32 rx_errors; |
| 598 | __le16 rx_missed; |
| 599 | __le16 align_errors; |
| 600 | __le32 tx_one_collision; |
| 601 | __le32 tx_multi_collision; |
| 602 | __le64 rx_unicast; |
| 603 | __le64 rx_broadcast; |
| 604 | __le32 rx_multicast; |
| 605 | __le16 tx_aborted; |
| 606 | __le16 tx_underun; |
| 607 | }; |
| 608 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 609 | struct rtl8169_tc_offsets { |
| 610 | bool inited; |
| 611 | __le64 tx_errors; |
| 612 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 613 | __le16 tx_aborted; |
| 614 | }; |
| 615 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 616 | enum rtl_flag { |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 617 | RTL_FLAG_TASK_ENABLED = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 618 | RTL_FLAG_TASK_RESET_PENDING, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 619 | RTL_FLAG_MAX |
| 620 | }; |
| 621 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 622 | struct rtl8169_stats { |
| 623 | u64 packets; |
| 624 | u64 bytes; |
| 625 | struct u64_stats_sync syncp; |
| 626 | }; |
| 627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | struct rtl8169_private { |
| 629 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 630 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 631 | struct net_device *dev; |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 632 | struct phy_device *phydev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 633 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 634 | u32 msg_enable; |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 635 | enum mac_version mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 637 | 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] | 638 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 639 | struct rtl8169_stats rx_stats; |
| 640 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 642 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 643 | dma_addr_t TxPhyAddr; |
| 644 | dma_addr_t RxPhyAddr; |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 645 | struct page *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | u16 cp_cmd; |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame] | 648 | u32 irq_mask; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 649 | struct clk *clk; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 650 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 651 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 652 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 653 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 654 | struct work_struct work; |
| 655 | } wk; |
| 656 | |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 657 | unsigned irq_enabled:1; |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 658 | unsigned supports_gmii:1; |
Heiner Kallweit | 62b1b3b | 2019-06-18 23:14:50 +0200 | [diff] [blame] | 659 | unsigned aspm_manageable:1; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 660 | dma_addr_t counters_phys_addr; |
| 661 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 662 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 663 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 664 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 665 | const char *fw_name; |
Heiner Kallweit | 8197f9d | 2019-06-05 08:02:31 +0200 | [diff] [blame] | 666 | struct rtl_fw *rtl_fw; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 667 | |
| 668 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | }; |
| 670 | |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 671 | typedef void (*rtl_generic_fct)(struct rtl8169_private *tp); |
| 672 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 673 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 675 | module_param_named(debug, debug.msg_enable, int, 0); |
| 676 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Heiner Kallweit | 11287b6 | 2019-01-07 21:49:09 +0100 | [diff] [blame] | 677 | MODULE_SOFTDEP("pre: realtek"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | MODULE_LICENSE("GPL"); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 679 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 680 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 681 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 682 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 683 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 684 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 685 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 686 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 687 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 688 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 689 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 690 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 691 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 692 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 693 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 694 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 695 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 696 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 697 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 699 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 700 | { |
| 701 | return &tp->pci_dev->dev; |
| 702 | } |
| 703 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 704 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 705 | { |
| 706 | mutex_lock(&tp->wk.mutex); |
| 707 | } |
| 708 | |
| 709 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 710 | { |
| 711 | mutex_unlock(&tp->wk.mutex); |
| 712 | } |
| 713 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 714 | static void rtl_lock_config_regs(struct rtl8169_private *tp) |
| 715 | { |
| 716 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 717 | } |
| 718 | |
| 719 | static void rtl_unlock_config_regs(struct rtl8169_private *tp) |
| 720 | { |
| 721 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 722 | } |
| 723 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 724 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 725 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 726 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 727 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 728 | } |
| 729 | |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 730 | static bool rtl_is_8168evl_up(struct rtl8169_private *tp) |
| 731 | { |
| 732 | return tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
Heiner Kallweit | c623305 | 2019-08-28 22:24:54 +0200 | [diff] [blame^] | 733 | tp->mac_version != RTL_GIGA_MAC_VER_39 && |
| 734 | tp->mac_version <= RTL_GIGA_MAC_VER_51; |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 737 | static bool rtl_supports_eee(struct rtl8169_private *tp) |
| 738 | { |
| 739 | return tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
| 740 | tp->mac_version != RTL_GIGA_MAC_VER_37 && |
| 741 | tp->mac_version != RTL_GIGA_MAC_VER_39; |
| 742 | } |
| 743 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 744 | struct rtl_cond { |
| 745 | bool (*check)(struct rtl8169_private *); |
| 746 | const char *msg; |
| 747 | }; |
| 748 | |
| 749 | static void rtl_udelay(unsigned int d) |
| 750 | { |
| 751 | udelay(d); |
| 752 | } |
| 753 | |
| 754 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 755 | void (*delay)(unsigned int), unsigned int d, int n, |
| 756 | bool high) |
| 757 | { |
| 758 | int i; |
| 759 | |
| 760 | for (i = 0; i < n; i++) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 761 | if (c->check(tp) == high) |
| 762 | return true; |
Heiner Kallweit | d1f5050 | 2019-05-04 15:20:38 +0200 | [diff] [blame] | 763 | delay(d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 764 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 765 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 766 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 767 | return false; |
| 768 | } |
| 769 | |
| 770 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 771 | const struct rtl_cond *c, |
| 772 | unsigned int d, int n) |
| 773 | { |
| 774 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 775 | } |
| 776 | |
| 777 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 778 | const struct rtl_cond *c, |
| 779 | unsigned int d, int n) |
| 780 | { |
| 781 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 782 | } |
| 783 | |
| 784 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 785 | const struct rtl_cond *c, |
| 786 | unsigned int d, int n) |
| 787 | { |
| 788 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 789 | } |
| 790 | |
| 791 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 792 | const struct rtl_cond *c, |
| 793 | unsigned int d, int n) |
| 794 | { |
| 795 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 796 | } |
| 797 | |
| 798 | #define DECLARE_RTL_COND(name) \ |
| 799 | static bool name ## _check(struct rtl8169_private *); \ |
| 800 | \ |
| 801 | static const struct rtl_cond name = { \ |
| 802 | .check = name ## _check, \ |
| 803 | .msg = #name \ |
| 804 | }; \ |
| 805 | \ |
| 806 | static bool name ## _check(struct rtl8169_private *tp) |
| 807 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 808 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 809 | { |
| 810 | if (reg & 0xffff0001) { |
| 811 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 812 | return true; |
| 813 | } |
| 814 | return false; |
| 815 | } |
| 816 | |
| 817 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 818 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 819 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 823 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 824 | if (rtl_ocp_reg_failure(tp, reg)) |
| 825 | return; |
| 826 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 827 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 828 | |
| 829 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 830 | } |
| 831 | |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 832 | static int r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 833 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 834 | if (rtl_ocp_reg_failure(tp, reg)) |
| 835 | return 0; |
| 836 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 837 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 838 | |
| 839 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 840 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 841 | } |
| 842 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 843 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 844 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 845 | if (rtl_ocp_reg_failure(tp, reg)) |
| 846 | return; |
| 847 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 848 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 852 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 853 | if (rtl_ocp_reg_failure(tp, reg)) |
| 854 | return 0; |
| 855 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 856 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 857 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 858 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 859 | } |
| 860 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 861 | static void r8168_mac_ocp_modify(struct rtl8169_private *tp, u32 reg, u16 mask, |
| 862 | u16 set) |
| 863 | { |
| 864 | u16 data = r8168_mac_ocp_read(tp, reg); |
| 865 | |
| 866 | r8168_mac_ocp_write(tp, reg, (data & ~mask) | set); |
| 867 | } |
| 868 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 869 | #define OCP_STD_PHY_BASE 0xa400 |
| 870 | |
| 871 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 872 | { |
| 873 | if (reg == 0x1f) { |
| 874 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 879 | reg -= 0x10; |
| 880 | |
| 881 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 882 | } |
| 883 | |
| 884 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 885 | { |
| 886 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 887 | reg -= 0x10; |
| 888 | |
| 889 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 890 | } |
| 891 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 892 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 893 | { |
| 894 | if (reg == 0x1f) { |
| 895 | tp->ocp_base = value << 4; |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 900 | } |
| 901 | |
| 902 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 903 | { |
| 904 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 905 | } |
| 906 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 907 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 908 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 909 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 910 | } |
| 911 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 912 | 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] | 913 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 914 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 916 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 917 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 918 | * According to hardware specs a 20us delay is required after write |
| 919 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 920 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 921 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 924 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 926 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 928 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 930 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 931 | RTL_R32(tp, PHYAR) & 0xffff : -ETIMEDOUT; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 932 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 933 | /* |
| 934 | * According to hardware specs a 20us delay is required after read |
| 935 | * complete indication, but before sending next command. |
| 936 | */ |
| 937 | udelay(20); |
| 938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | return value; |
| 940 | } |
| 941 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 942 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 943 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 944 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 945 | } |
| 946 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 947 | 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] | 948 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 949 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 950 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 951 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 952 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 953 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 956 | 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] | 957 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 958 | r8168dp_1_mdio_access(tp, reg, |
| 959 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 962 | 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] | 963 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 964 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 965 | |
| 966 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 967 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 968 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 969 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 970 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 971 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : -ETIMEDOUT; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 972 | } |
| 973 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 974 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 975 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 976 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 977 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 978 | 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] | 979 | } |
| 980 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 981 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 982 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 983 | 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] | 984 | } |
| 985 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 986 | 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] | 987 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 988 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 989 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 990 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 991 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 992 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 995 | 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] | 996 | { |
| 997 | int value; |
| 998 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 999 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1000 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1001 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1002 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1003 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1004 | |
| 1005 | return value; |
| 1006 | } |
| 1007 | |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 1008 | static void rtl_writephy(struct rtl8169_private *tp, int location, int val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1009 | { |
Heiner Kallweit | 5f95052 | 2019-05-31 19:53:28 +0200 | [diff] [blame] | 1010 | switch (tp->mac_version) { |
| 1011 | case RTL_GIGA_MAC_VER_27: |
| 1012 | r8168dp_1_mdio_write(tp, location, val); |
| 1013 | break; |
| 1014 | case RTL_GIGA_MAC_VER_28: |
| 1015 | case RTL_GIGA_MAC_VER_31: |
| 1016 | r8168dp_2_mdio_write(tp, location, val); |
| 1017 | break; |
| 1018 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1019 | r8168g_mdio_write(tp, location, val); |
| 1020 | break; |
| 1021 | default: |
| 1022 | r8169_mdio_write(tp, location, val); |
| 1023 | break; |
| 1024 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1027 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1028 | { |
Heiner Kallweit | 5f95052 | 2019-05-31 19:53:28 +0200 | [diff] [blame] | 1029 | switch (tp->mac_version) { |
| 1030 | case RTL_GIGA_MAC_VER_27: |
| 1031 | return r8168dp_1_mdio_read(tp, location); |
| 1032 | case RTL_GIGA_MAC_VER_28: |
| 1033 | case RTL_GIGA_MAC_VER_31: |
| 1034 | return r8168dp_2_mdio_read(tp, location); |
| 1035 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1036 | return r8168g_mdio_read(tp, location); |
| 1037 | default: |
| 1038 | return r8169_mdio_read(tp, location); |
| 1039 | } |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1043 | { |
| 1044 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1045 | } |
| 1046 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1047 | 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] | 1048 | { |
| 1049 | int val; |
| 1050 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1051 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1052 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1055 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1056 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1057 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1060 | 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] | 1061 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1062 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1063 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1064 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1065 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1066 | |
| 1067 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1068 | } |
| 1069 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1070 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1071 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1072 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1073 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1074 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1075 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1078 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1079 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1080 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1083 | static void _rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1084 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1085 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1086 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1087 | RTL_W32(tp, ERIDR, val); |
| 1088 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1089 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1090 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1091 | } |
| 1092 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1093 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1094 | u32 val) |
| 1095 | { |
| 1096 | _rtl_eri_write(tp, addr, mask, val, ERIAR_EXGMAC); |
| 1097 | } |
| 1098 | |
| 1099 | 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] | 1100 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1101 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1102 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1103 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1104 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1105 | } |
| 1106 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1107 | static u32 rtl_eri_read(struct rtl8169_private *tp, int addr) |
| 1108 | { |
| 1109 | return _rtl_eri_read(tp, addr, ERIAR_EXGMAC); |
| 1110 | } |
| 1111 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1112 | static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p, |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1113 | u32 m) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1114 | { |
| 1115 | u32 val; |
| 1116 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1117 | val = rtl_eri_read(tp, addr); |
| 1118 | rtl_eri_write(tp, addr, mask, (val & ~m) | p); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1119 | } |
| 1120 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1121 | static void rtl_eri_set_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1122 | u32 p) |
| 1123 | { |
| 1124 | rtl_w0w1_eri(tp, addr, mask, p, 0); |
| 1125 | } |
| 1126 | |
| 1127 | static void rtl_eri_clear_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1128 | u32 m) |
| 1129 | { |
| 1130 | rtl_w0w1_eri(tp, addr, mask, 0, m); |
| 1131 | } |
| 1132 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1133 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1134 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1135 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1136 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1137 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1141 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1142 | return _rtl_eri_read(tp, reg, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1143 | } |
| 1144 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1145 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1146 | u32 data) |
| 1147 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1148 | RTL_W32(tp, OCPDR, data); |
| 1149 | 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] | 1150 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1151 | } |
| 1152 | |
| 1153 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1154 | u32 data) |
| 1155 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1156 | _rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1157 | data, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1158 | } |
| 1159 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1160 | static void r8168dp_oob_notify(struct rtl8169_private *tp, u8 cmd) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1161 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1162 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1163 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1164 | r8168dp_ocp_write(tp, 0x1, 0x30, 0x00000001); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | #define OOB_CMD_RESET 0x00 |
| 1168 | #define OOB_CMD_DRIVER_START 0x05 |
| 1169 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1170 | |
| 1171 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1172 | { |
| 1173 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1174 | } |
| 1175 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1176 | DECLARE_RTL_COND(rtl_dp_ocp_read_cond) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1177 | { |
| 1178 | u16 reg; |
| 1179 | |
| 1180 | reg = rtl8168_get_ocp_reg(tp); |
| 1181 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1182 | return r8168dp_ocp_read(tp, 0x0f, reg) & 0x00000800; |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1185 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1186 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1187 | return r8168ep_ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1191 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1192 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1193 | } |
| 1194 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1195 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1196 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1197 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1198 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1199 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1200 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1203 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1204 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1205 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 1206 | rtl_msleep_loop_wait_high(tp, &rtl_dp_ocp_read_cond, 10, 10); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1207 | } |
| 1208 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1209 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1210 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1211 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1212 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1213 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1214 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1215 | } |
| 1216 | |
| 1217 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1218 | { |
| 1219 | switch (tp->mac_version) { |
| 1220 | case RTL_GIGA_MAC_VER_27: |
| 1221 | case RTL_GIGA_MAC_VER_28: |
| 1222 | case RTL_GIGA_MAC_VER_31: |
| 1223 | rtl8168dp_driver_start(tp); |
| 1224 | break; |
| 1225 | case RTL_GIGA_MAC_VER_49: |
| 1226 | case RTL_GIGA_MAC_VER_50: |
| 1227 | case RTL_GIGA_MAC_VER_51: |
| 1228 | rtl8168ep_driver_start(tp); |
| 1229 | break; |
| 1230 | default: |
| 1231 | BUG(); |
| 1232 | break; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1237 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1238 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1239 | rtl_msleep_loop_wait_low(tp, &rtl_dp_ocp_read_cond, 10, 10); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1243 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1244 | rtl8168ep_stop_cmac(tp); |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1245 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1246 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1247 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1248 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1249 | } |
| 1250 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1251 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1252 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1253 | switch (tp->mac_version) { |
| 1254 | case RTL_GIGA_MAC_VER_27: |
| 1255 | case RTL_GIGA_MAC_VER_28: |
| 1256 | case RTL_GIGA_MAC_VER_31: |
| 1257 | rtl8168dp_driver_stop(tp); |
| 1258 | break; |
| 1259 | case RTL_GIGA_MAC_VER_49: |
| 1260 | case RTL_GIGA_MAC_VER_50: |
| 1261 | case RTL_GIGA_MAC_VER_51: |
| 1262 | rtl8168ep_driver_stop(tp); |
| 1263 | break; |
| 1264 | default: |
| 1265 | BUG(); |
| 1266 | break; |
| 1267 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1268 | } |
| 1269 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1270 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1271 | { |
| 1272 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1273 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1274 | return !!(r8168dp_ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1277 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1278 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1279 | return !!(r8168ep_ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1280 | } |
| 1281 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1282 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1283 | { |
| 1284 | switch (tp->mac_version) { |
| 1285 | case RTL_GIGA_MAC_VER_27: |
| 1286 | case RTL_GIGA_MAC_VER_28: |
| 1287 | case RTL_GIGA_MAC_VER_31: |
| 1288 | return r8168dp_check_dash(tp); |
| 1289 | case RTL_GIGA_MAC_VER_49: |
| 1290 | case RTL_GIGA_MAC_VER_50: |
| 1291 | case RTL_GIGA_MAC_VER_51: |
| 1292 | return r8168ep_check_dash(tp); |
| 1293 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1294 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1298 | static void rtl_reset_packet_filter(struct rtl8169_private *tp) |
| 1299 | { |
| 1300 | rtl_eri_clear_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1301 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1302 | } |
| 1303 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1304 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1305 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1306 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1309 | 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] | 1310 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1311 | 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] | 1312 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1313 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1314 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame] | 1317 | static u32 rtl_get_events(struct rtl8169_private *tp) |
| 1318 | { |
| 1319 | return RTL_R16(tp, IntrStatus); |
| 1320 | } |
| 1321 | |
| 1322 | static void rtl_ack_events(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1323 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1324 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1328 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1329 | RTL_W16(tp, IntrMask, 0); |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1330 | tp->irq_enabled = 0; |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1333 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1334 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1335 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1336 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1337 | static void rtl_irq_enable(struct rtl8169_private *tp) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1338 | { |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1339 | tp->irq_enabled = 1; |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 1340 | RTL_W16(tp, IntrMask, tp->irq_mask); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1343 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1345 | rtl_irq_disable(tp); |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame] | 1346 | rtl_ack_events(tp, 0xffffffff); |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 1347 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1348 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1351 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1352 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1353 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 1354 | struct phy_device *phydev = tp->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1355 | |
| 1356 | if (!netif_running(dev)) |
| 1357 | return; |
| 1358 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1359 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1360 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1361 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1362 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1363 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1364 | } else if (phydev->speed == SPEED_100) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1365 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1366 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1367 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1368 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1369 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1370 | } |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1371 | rtl_reset_packet_filter(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1372 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1373 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1374 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1375 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1376 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1377 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1378 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1379 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1380 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1381 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1382 | if (phydev->speed == SPEED_10) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1383 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02); |
| 1384 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060a); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1385 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1386 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1387 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1388 | } |
| 1389 | } |
| 1390 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1391 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1392 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1393 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1394 | { |
| 1395 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1396 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1397 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1398 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1399 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1400 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1403 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1404 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1405 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1406 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1407 | u32 opt; |
| 1408 | u16 reg; |
| 1409 | u8 mask; |
| 1410 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1411 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1412 | { WAKE_UCAST, Config5, UWF }, |
| 1413 | { WAKE_BCAST, Config5, BWF }, |
| 1414 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1415 | { WAKE_ANY, Config5, LanWake }, |
| 1416 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1417 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1418 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1419 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1420 | rtl_unlock_config_regs(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1421 | |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 1422 | if (rtl_is_8168evl_up(tp)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1423 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1424 | if (wolopts & WAKE_MAGIC) |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1425 | rtl_eri_set_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1426 | MagicPacket_v2); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1427 | else |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1428 | rtl_eri_clear_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1429 | MagicPacket_v2); |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 1430 | } else { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1431 | tmp = ARRAY_SIZE(cfg); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1435 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1436 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1437 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1438 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1441 | switch (tp->mac_version) { |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1442 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1443 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1444 | if (wolopts) |
| 1445 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1446 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1447 | break; |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1448 | case RTL_GIGA_MAC_VER_34: |
| 1449 | case RTL_GIGA_MAC_VER_37: |
| 1450 | case RTL_GIGA_MAC_VER_39 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1451 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1452 | if (wolopts) |
| 1453 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1454 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1455 | break; |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1456 | default: |
| 1457 | break; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1458 | } |
| 1459 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1460 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 3bd8264 | 2018-12-30 13:16:12 +0100 | [diff] [blame] | 1461 | |
| 1462 | device_set_wakeup_enable(tp_to_dev(tp), wolopts); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1466 | { |
| 1467 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1468 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1469 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1470 | if (wol->wolopts & ~WAKE_ANY) |
| 1471 | return -EINVAL; |
| 1472 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1473 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1474 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1475 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1476 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1477 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1478 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1479 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1480 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1481 | |
| 1482 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1483 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1484 | pm_runtime_put_noidle(d); |
| 1485 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1486 | return 0; |
| 1487 | } |
| 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1490 | struct ethtool_drvinfo *info) |
| 1491 | { |
| 1492 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1493 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1495 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1496 | 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] | 1497 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 1498 | if (rtl_fw) |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1499 | strlcpy(info->fw_version, rtl_fw->version, |
| 1500 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1504 | { |
| 1505 | return R8169_REGS_SIZE; |
| 1506 | } |
| 1507 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1508 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1509 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1511 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1512 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1513 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1514 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1516 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1517 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1518 | features &= ~NETIF_F_IP_CSUM; |
| 1519 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1520 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1523 | static int rtl8169_set_features(struct net_device *dev, |
| 1524 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | { |
| 1526 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1527 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1529 | rtl_lock_work(tp); |
| 1530 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1531 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1532 | if (features & NETIF_F_RXALL) |
| 1533 | rx_config |= (AcceptErr | AcceptRunt); |
| 1534 | else |
| 1535 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1537 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1538 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1539 | if (features & NETIF_F_RXCSUM) |
| 1540 | tp->cp_cmd |= RxChkSum; |
| 1541 | else |
| 1542 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1543 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1544 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1545 | tp->cp_cmd |= RxVlan; |
| 1546 | else |
| 1547 | tp->cp_cmd &= ~RxVlan; |
| 1548 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1549 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1550 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1552 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1557 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1559 | return (skb_vlan_tag_present(skb)) ? |
Heiner Kallweit | 7424edb | 2019-07-02 07:59:17 +0200 | [diff] [blame] | 1560 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1563 | 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] | 1564 | { |
| 1565 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1567 | if (opts2 & RxVlanTag) |
Heiner Kallweit | 7424edb | 2019-07-02 07:59:17 +0200 | [diff] [blame] | 1568 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1572 | void *p) |
| 1573 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1574 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1575 | u32 __iomem *data = tp->mmio_addr; |
| 1576 | u32 *dw = p; |
| 1577 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1579 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1580 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1581 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1582 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1585 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1586 | { |
| 1587 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1588 | |
| 1589 | return tp->msg_enable; |
| 1590 | } |
| 1591 | |
| 1592 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1593 | { |
| 1594 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1595 | |
| 1596 | tp->msg_enable = value; |
| 1597 | } |
| 1598 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1599 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1600 | "tx_packets", |
| 1601 | "rx_packets", |
| 1602 | "tx_errors", |
| 1603 | "rx_errors", |
| 1604 | "rx_missed", |
| 1605 | "align_errors", |
| 1606 | "tx_single_collisions", |
| 1607 | "tx_multi_collisions", |
| 1608 | "unicast", |
| 1609 | "broadcast", |
| 1610 | "multicast", |
| 1611 | "tx_aborted", |
| 1612 | "tx_underrun", |
| 1613 | }; |
| 1614 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1615 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1616 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1617 | switch (sset) { |
| 1618 | case ETH_SS_STATS: |
| 1619 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1620 | default: |
| 1621 | return -EOPNOTSUPP; |
| 1622 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1623 | } |
| 1624 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1625 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1626 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1627 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1628 | } |
| 1629 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1630 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1631 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1632 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1633 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1634 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1635 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1636 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1637 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1638 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1639 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1640 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1641 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1644 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1645 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1646 | /* |
| 1647 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1648 | * tally counters. |
| 1649 | */ |
| 1650 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1651 | return true; |
| 1652 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1653 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1654 | } |
| 1655 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1656 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1657 | { |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1658 | u8 val = RTL_R8(tp, ChipCmd); |
| 1659 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1660 | /* |
| 1661 | * Some chips are unable to dump tally counters when the receiver |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1662 | * is disabled. If 0xff chip may be in a PCI power-save state. |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1663 | */ |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1664 | if (!(val & CmdRxEnb) || val == 0xff) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1665 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1666 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1667 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1668 | } |
| 1669 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1670 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1671 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1672 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1673 | bool ret = false; |
| 1674 | |
| 1675 | /* |
| 1676 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1677 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1678 | * reset by a power cycle, while the counter values collected by the |
| 1679 | * driver are reset at every driver unload/load cycle. |
| 1680 | * |
| 1681 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1682 | * values, we collect the initial values at first open(*) and use them |
| 1683 | * as offsets to normalize the values returned by @get_stats64. |
| 1684 | * |
| 1685 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1686 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1687 | * set at open time by rtl_hw_start. |
| 1688 | */ |
| 1689 | |
| 1690 | if (tp->tc_offset.inited) |
| 1691 | return true; |
| 1692 | |
| 1693 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1694 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1695 | ret = true; |
| 1696 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1697 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1698 | ret = true; |
| 1699 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1700 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1701 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1702 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1703 | tp->tc_offset.inited = true; |
| 1704 | |
| 1705 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1706 | } |
| 1707 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1708 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1709 | struct ethtool_stats *stats, u64 *data) |
| 1710 | { |
| 1711 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1712 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1713 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1714 | |
| 1715 | ASSERT_RTNL(); |
| 1716 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1717 | pm_runtime_get_noresume(d); |
| 1718 | |
| 1719 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1720 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1721 | |
| 1722 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1723 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1724 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1725 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1726 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1727 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1728 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1729 | data[5] = le16_to_cpu(counters->align_errors); |
| 1730 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1731 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1732 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1733 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1734 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1735 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1736 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1737 | } |
| 1738 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1739 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1740 | { |
| 1741 | switch(stringset) { |
| 1742 | case ETH_SS_STATS: |
| 1743 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1744 | break; |
| 1745 | } |
| 1746 | } |
| 1747 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1748 | /* |
| 1749 | * Interrupt coalescing |
| 1750 | * |
| 1751 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1752 | * > 8169, 8168 and 810x line of chipsets |
| 1753 | * |
| 1754 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1755 | * |
| 1756 | * > 2 - the Tx timer unit at gigabit speed |
| 1757 | * |
| 1758 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1759 | * (0xe0) bit 1 and bit 0. |
| 1760 | * |
| 1761 | * For 8169 |
| 1762 | * bit[1:0] \ speed 1000M 100M 10M |
| 1763 | * 0 0 320ns 2.56us 40.96us |
| 1764 | * 0 1 2.56us 20.48us 327.7us |
| 1765 | * 1 0 5.12us 40.96us 655.4us |
| 1766 | * 1 1 10.24us 81.92us 1.31ms |
| 1767 | * |
| 1768 | * For the other |
| 1769 | * bit[1:0] \ speed 1000M 100M 10M |
| 1770 | * 0 0 5us 2.56us 40.96us |
| 1771 | * 0 1 40us 20.48us 327.7us |
| 1772 | * 1 0 80us 40.96us 655.4us |
| 1773 | * 1 1 160us 81.92us 1.31ms |
| 1774 | */ |
| 1775 | |
| 1776 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1777 | struct rtl_coalesce_scale { |
| 1778 | /* Rx / Tx */ |
| 1779 | u32 nsecs[2]; |
| 1780 | }; |
| 1781 | |
| 1782 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1783 | struct rtl_coalesce_info { |
| 1784 | u32 speed; |
| 1785 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1786 | }; |
| 1787 | |
| 1788 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1789 | #define rxtx_x1822(r, t) { \ |
| 1790 | {{(r), (t)}}, \ |
| 1791 | {{(r)*8, (t)*8}}, \ |
| 1792 | {{(r)*8*2, (t)*8*2}}, \ |
| 1793 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1794 | } |
| 1795 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1796 | /* speed delays: rx00 tx00 */ |
| 1797 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1798 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1799 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1800 | { 0 }, |
| 1801 | }; |
| 1802 | |
| 1803 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1804 | /* speed delays: rx00 tx00 */ |
| 1805 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1806 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1807 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1808 | { 0 }, |
| 1809 | }; |
| 1810 | #undef rxtx_x1822 |
| 1811 | |
| 1812 | /* get rx/tx scale vector corresponding to current speed */ |
| 1813 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1814 | { |
| 1815 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1816 | const struct rtl_coalesce_info *ci; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1817 | |
Heiner Kallweit | 20023d3 | 2019-06-11 21:09:19 +0200 | [diff] [blame] | 1818 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 1819 | ci = rtl_coalesce_info_8169; |
| 1820 | else |
| 1821 | ci = rtl_coalesce_info_8168_8136; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1822 | |
Heiner Kallweit | 20023d3 | 2019-06-11 21:09:19 +0200 | [diff] [blame] | 1823 | for (; ci->speed; ci++) { |
| 1824 | if (tp->phydev->speed == ci->speed) |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1825 | return ci; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | return ERR_PTR(-ELNRNG); |
| 1829 | } |
| 1830 | |
| 1831 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1832 | { |
| 1833 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1834 | const struct rtl_coalesce_info *ci; |
| 1835 | const struct rtl_coalesce_scale *scale; |
| 1836 | struct { |
| 1837 | u32 *max_frames; |
| 1838 | u32 *usecs; |
| 1839 | } coal_settings [] = { |
| 1840 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1841 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1842 | }, *p = coal_settings; |
| 1843 | int i; |
| 1844 | u16 w; |
| 1845 | |
| 1846 | memset(ec, 0, sizeof(*ec)); |
| 1847 | |
| 1848 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1849 | ci = rtl_coalesce_info(dev); |
| 1850 | if (IS_ERR(ci)) |
| 1851 | return PTR_ERR(ci); |
| 1852 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1853 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1854 | |
| 1855 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1856 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1857 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1858 | w >>= RTL_COALESCE_SHIFT; |
| 1859 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1860 | } |
| 1861 | |
| 1862 | for (i = 0; i < 2; i++) { |
| 1863 | p = coal_settings + i; |
| 1864 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1865 | |
| 1866 | /* |
| 1867 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1868 | * max_frames to 0. |
| 1869 | */ |
| 1870 | if (!*p->usecs && !*p->max_frames) |
| 1871 | *p->max_frames = 1; |
| 1872 | } |
| 1873 | |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1878 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1879 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1880 | { |
| 1881 | const struct rtl_coalesce_info *ci; |
| 1882 | u16 i; |
| 1883 | |
| 1884 | ci = rtl_coalesce_info(dev); |
| 1885 | if (IS_ERR(ci)) |
| 1886 | return ERR_CAST(ci); |
| 1887 | |
| 1888 | for (i = 0; i < 4; i++) { |
| 1889 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1890 | ci->scalev[i].nsecs[1]); |
| 1891 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1892 | *cp01 = i; |
| 1893 | return &ci->scalev[i]; |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | return ERR_PTR(-EINVAL); |
| 1898 | } |
| 1899 | |
| 1900 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1901 | { |
| 1902 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1903 | const struct rtl_coalesce_scale *scale; |
| 1904 | struct { |
| 1905 | u32 frames; |
| 1906 | u32 usecs; |
| 1907 | } coal_settings [] = { |
| 1908 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1909 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1910 | }, *p = coal_settings; |
| 1911 | u16 w = 0, cp01; |
| 1912 | int i; |
| 1913 | |
| 1914 | scale = rtl_coalesce_choose_scale(dev, |
| 1915 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1916 | if (IS_ERR(scale)) |
| 1917 | return PTR_ERR(scale); |
| 1918 | |
| 1919 | for (i = 0; i < 2; i++, p++) { |
| 1920 | u32 units; |
| 1921 | |
| 1922 | /* |
| 1923 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1924 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1925 | * |
| 1926 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 1927 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 1928 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 1929 | * |
| 1930 | * since ethtool sends to kernel whole ethtool_coalesce |
| 1931 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 1932 | * we'll reject it below in `frames % 4 != 0`. |
| 1933 | */ |
| 1934 | if (p->frames == 1) { |
| 1935 | p->frames = 0; |
| 1936 | } |
| 1937 | |
| 1938 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 1939 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 1940 | return -EINVAL; |
| 1941 | |
| 1942 | w <<= RTL_COALESCE_SHIFT; |
| 1943 | w |= units; |
| 1944 | w <<= RTL_COALESCE_SHIFT; |
| 1945 | w |= p->frames >> 2; |
| 1946 | } |
| 1947 | |
| 1948 | rtl_lock_work(tp); |
| 1949 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1950 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1951 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 1952 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1953 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1954 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1955 | |
| 1956 | rtl_unlock_work(tp); |
| 1957 | |
| 1958 | return 0; |
| 1959 | } |
| 1960 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1961 | static int rtl8169_get_eee(struct net_device *dev, struct ethtool_eee *data) |
| 1962 | { |
| 1963 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1964 | struct device *d = tp_to_dev(tp); |
| 1965 | int ret; |
| 1966 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1967 | if (!rtl_supports_eee(tp)) |
| 1968 | return -EOPNOTSUPP; |
| 1969 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1970 | pm_runtime_get_noresume(d); |
| 1971 | |
| 1972 | if (!pm_runtime_active(d)) { |
| 1973 | ret = -EOPNOTSUPP; |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1974 | } else { |
| 1975 | ret = phy_ethtool_get_eee(tp->phydev, data); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1976 | } |
| 1977 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1978 | pm_runtime_put_noidle(d); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1979 | |
| 1980 | return ret; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | static int rtl8169_set_eee(struct net_device *dev, struct ethtool_eee *data) |
| 1984 | { |
| 1985 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1986 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1987 | int ret; |
| 1988 | |
| 1989 | if (!rtl_supports_eee(tp)) |
| 1990 | return -EOPNOTSUPP; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1991 | |
| 1992 | pm_runtime_get_noresume(d); |
| 1993 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1994 | if (!pm_runtime_active(d)) { |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1995 | ret = -EOPNOTSUPP; |
| 1996 | goto out; |
| 1997 | } |
| 1998 | |
| 1999 | if (dev->phydev->autoneg == AUTONEG_DISABLE || |
| 2000 | dev->phydev->duplex != DUPLEX_FULL) { |
| 2001 | ret = -EPROTONOSUPPORT; |
| 2002 | goto out; |
| 2003 | } |
| 2004 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2005 | ret = phy_ethtool_set_eee(tp->phydev, data); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2006 | out: |
| 2007 | pm_runtime_put_noidle(d); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2008 | return ret; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2009 | } |
| 2010 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2011 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2013 | .get_regs_len = rtl8169_get_regs_len, |
| 2014 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2015 | .get_coalesce = rtl_get_coalesce, |
| 2016 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2017 | .get_msglevel = rtl8169_get_msglevel, |
| 2018 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2020 | .get_wol = rtl8169_get_wol, |
| 2021 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2022 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2023 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2024 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2025 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2026 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2027 | .get_eee = rtl8169_get_eee, |
| 2028 | .set_eee = rtl8169_set_eee, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2029 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2030 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | }; |
| 2032 | |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2033 | static void rtl_enable_eee(struct rtl8169_private *tp) |
| 2034 | { |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2035 | struct phy_device *phydev = tp->phydev; |
| 2036 | int supported = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2037 | |
| 2038 | if (supported > 0) |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2039 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, supported); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2040 | } |
| 2041 | |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2042 | static void rtl8169_get_mac_version(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2044 | /* |
| 2045 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2046 | * but they can be identified more specifically through the test below |
| 2047 | * if needed: |
| 2048 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2049 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2050 | * |
| 2051 | * Same thing for the 8101Eb and the 8101Ec: |
| 2052 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2053 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2054 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2055 | static const struct rtl_mac_info { |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2056 | u16 mask; |
| 2057 | u16 val; |
| 2058 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2060 | /* 8168EP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2061 | { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51 }, |
| 2062 | { 0x7cf, 0x501, RTL_GIGA_MAC_VER_50 }, |
| 2063 | { 0x7cf, 0x500, RTL_GIGA_MAC_VER_49 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2064 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2065 | /* 8168H family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2066 | { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46 }, |
| 2067 | { 0x7cf, 0x540, RTL_GIGA_MAC_VER_45 }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2068 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2069 | /* 8168G family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2070 | { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44 }, |
| 2071 | { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42 }, |
| 2072 | { 0x7cf, 0x4c1, RTL_GIGA_MAC_VER_41 }, |
| 2073 | { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2074 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2075 | /* 8168F family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2076 | { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38 }, |
| 2077 | { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36 }, |
| 2078 | { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2079 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2080 | /* 8168E family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2081 | { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34 }, |
| 2082 | { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32 }, |
| 2083 | { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2084 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2085 | /* 8168D family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2086 | { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25 }, |
| 2087 | { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2088 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2089 | /* 8168DP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2090 | { 0x7cf, 0x288, RTL_GIGA_MAC_VER_27 }, |
| 2091 | { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28 }, |
| 2092 | { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2093 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2094 | /* 8168C family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2095 | { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23 }, |
| 2096 | { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18 }, |
| 2097 | { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24 }, |
| 2098 | { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19 }, |
| 2099 | { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20 }, |
| 2100 | { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21 }, |
| 2101 | { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2102 | |
| 2103 | /* 8168B family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2104 | { 0x7cf, 0x380, RTL_GIGA_MAC_VER_12 }, |
| 2105 | { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17 }, |
| 2106 | { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2107 | |
| 2108 | /* 8101 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2109 | { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39 }, |
| 2110 | { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37 }, |
| 2111 | { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29 }, |
| 2112 | { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30 }, |
| 2113 | { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08 }, |
| 2114 | { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08 }, |
| 2115 | { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07 }, |
| 2116 | { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07 }, |
| 2117 | { 0x7cf, 0x340, RTL_GIGA_MAC_VER_13 }, |
| 2118 | { 0x7cf, 0x343, RTL_GIGA_MAC_VER_10 }, |
| 2119 | { 0x7cf, 0x342, RTL_GIGA_MAC_VER_16 }, |
| 2120 | { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09 }, |
| 2121 | { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09 }, |
| 2122 | { 0x7c8, 0x340, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2123 | /* FIXME: where did these entries come from ? -- FR */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2124 | { 0xfc8, 0x388, RTL_GIGA_MAC_VER_15 }, |
| 2125 | { 0xfc8, 0x308, RTL_GIGA_MAC_VER_14 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2126 | |
| 2127 | /* 8110 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2128 | { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06 }, |
| 2129 | { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05 }, |
| 2130 | { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04 }, |
| 2131 | { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03 }, |
| 2132 | { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2133 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2134 | /* Catch-all */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2135 | { 0x000, 0x000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2136 | }; |
| 2137 | const struct rtl_mac_info *p = mac_info; |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2138 | u16 reg = RTL_R32(tp, TxConfig) >> 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2140 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | p++; |
| 2142 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2143 | |
| 2144 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2145 | dev_err(tp_to_dev(tp), "unknown chip XID %03x\n", reg & 0xfcf); |
Heiner Kallweit | 45f1996 | 2018-11-22 22:00:10 +0100 | [diff] [blame] | 2146 | } else if (!tp->supports_gmii) { |
| 2147 | if (tp->mac_version == RTL_GIGA_MAC_VER_42) |
| 2148 | tp->mac_version = RTL_GIGA_MAC_VER_43; |
| 2149 | else if (tp->mac_version == RTL_GIGA_MAC_VER_45) |
| 2150 | tp->mac_version = RTL_GIGA_MAC_VER_47; |
| 2151 | else if (tp->mac_version == RTL_GIGA_MAC_VER_46) |
| 2152 | tp->mac_version = RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2156 | struct phy_reg { |
| 2157 | u16 reg; |
| 2158 | u16 val; |
| 2159 | }; |
| 2160 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2161 | static void __rtl_writephy_batch(struct rtl8169_private *tp, |
| 2162 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2163 | { |
| 2164 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2165 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2166 | regs++; |
| 2167 | } |
| 2168 | } |
| 2169 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2170 | #define rtl_writephy_batch(tp, a) __rtl_writephy_batch(tp, a, ARRAY_SIZE(a)) |
| 2171 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2172 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2173 | { |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2174 | if (tp->rtl_fw) { |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 2175 | rtl_fw_release_firmware(tp->rtl_fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2176 | kfree(tp->rtl_fw); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2177 | tp->rtl_fw = NULL; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2178 | } |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2179 | } |
| 2180 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2181 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2182 | { |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 2183 | /* TODO: release firmware if rtl_fw_write_firmware signals failure. */ |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2184 | if (tp->rtl_fw) |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 2185 | rtl_fw_write_firmware(tp, tp->rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2189 | { |
| 2190 | if (rtl_readphy(tp, reg) != val) |
| 2191 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2192 | else |
| 2193 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2196 | static void rtl8168_config_eee_mac(struct rtl8169_private *tp) |
| 2197 | { |
Heiner Kallweit | f452825 | 2019-05-04 17:13:09 +0200 | [diff] [blame] | 2198 | /* Adjust EEE LED frequency */ |
| 2199 | if (tp->mac_version != RTL_GIGA_MAC_VER_38) |
| 2200 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
| 2201 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 2202 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_1111, 0x0003); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2205 | static void rtl8168f_config_eee_phy(struct rtl8169_private *tp) |
| 2206 | { |
| 2207 | struct phy_device *phydev = tp->phydev; |
| 2208 | |
| 2209 | phy_write(phydev, 0x1f, 0x0007); |
| 2210 | phy_write(phydev, 0x1e, 0x0020); |
| 2211 | phy_set_bits(phydev, 0x15, BIT(8)); |
| 2212 | |
| 2213 | phy_write(phydev, 0x1f, 0x0005); |
| 2214 | phy_write(phydev, 0x05, 0x8b85); |
| 2215 | phy_set_bits(phydev, 0x06, BIT(13)); |
| 2216 | |
| 2217 | phy_write(phydev, 0x1f, 0x0000); |
| 2218 | } |
| 2219 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2220 | static void rtl8168g_config_eee_phy(struct rtl8169_private *tp) |
| 2221 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 2222 | phy_modify_paged(tp->phydev, 0x0a43, 0x11, 0, BIT(4)); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2223 | } |
| 2224 | |
Heiner Kallweit | b6cef26 | 2019-08-15 14:21:30 +0200 | [diff] [blame] | 2225 | static void rtl8168h_config_eee_phy(struct rtl8169_private *tp) |
| 2226 | { |
| 2227 | struct phy_device *phydev = tp->phydev; |
| 2228 | |
| 2229 | rtl8168g_config_eee_phy(tp); |
| 2230 | |
| 2231 | phy_modify_paged(phydev, 0xa4a, 0x11, 0x0000, 0x0200); |
| 2232 | phy_modify_paged(phydev, 0xa42, 0x14, 0x0000, 0x0080); |
| 2233 | } |
| 2234 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2235 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2237 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2238 | { 0x1f, 0x0001 }, |
| 2239 | { 0x06, 0x006e }, |
| 2240 | { 0x08, 0x0708 }, |
| 2241 | { 0x15, 0x4000 }, |
| 2242 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2244 | { 0x1f, 0x0001 }, |
| 2245 | { 0x03, 0x00a1 }, |
| 2246 | { 0x02, 0x0008 }, |
| 2247 | { 0x01, 0x0120 }, |
| 2248 | { 0x00, 0x1000 }, |
| 2249 | { 0x04, 0x0800 }, |
| 2250 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2252 | { 0x03, 0xff41 }, |
| 2253 | { 0x02, 0xdf60 }, |
| 2254 | { 0x01, 0x0140 }, |
| 2255 | { 0x00, 0x0077 }, |
| 2256 | { 0x04, 0x7800 }, |
| 2257 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2259 | { 0x03, 0x802f }, |
| 2260 | { 0x02, 0x4f02 }, |
| 2261 | { 0x01, 0x0409 }, |
| 2262 | { 0x00, 0xf0f9 }, |
| 2263 | { 0x04, 0x9800 }, |
| 2264 | { 0x04, 0x9000 }, |
| 2265 | |
| 2266 | { 0x03, 0xdf01 }, |
| 2267 | { 0x02, 0xdf20 }, |
| 2268 | { 0x01, 0xff95 }, |
| 2269 | { 0x00, 0xba00 }, |
| 2270 | { 0x04, 0xa800 }, |
| 2271 | { 0x04, 0xa000 }, |
| 2272 | |
| 2273 | { 0x03, 0xff41 }, |
| 2274 | { 0x02, 0xdf20 }, |
| 2275 | { 0x01, 0x0140 }, |
| 2276 | { 0x00, 0x00bb }, |
| 2277 | { 0x04, 0xb800 }, |
| 2278 | { 0x04, 0xb000 }, |
| 2279 | |
| 2280 | { 0x03, 0xdf41 }, |
| 2281 | { 0x02, 0xdc60 }, |
| 2282 | { 0x01, 0x6340 }, |
| 2283 | { 0x00, 0x007d }, |
| 2284 | { 0x04, 0xd800 }, |
| 2285 | { 0x04, 0xd000 }, |
| 2286 | |
| 2287 | { 0x03, 0xdf01 }, |
| 2288 | { 0x02, 0xdf20 }, |
| 2289 | { 0x01, 0x100a }, |
| 2290 | { 0x00, 0xa0ff }, |
| 2291 | { 0x04, 0xf800 }, |
| 2292 | { 0x04, 0xf000 }, |
| 2293 | |
| 2294 | { 0x1f, 0x0000 }, |
| 2295 | { 0x0b, 0x0000 }, |
| 2296 | { 0x00, 0x9200 } |
| 2297 | }; |
| 2298 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2299 | rtl_writephy_batch(tp, phy_reg_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2302 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2303 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2304 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2305 | { 0x1f, 0x0002 }, |
| 2306 | { 0x01, 0x90d0 }, |
| 2307 | { 0x1f, 0x0000 } |
| 2308 | }; |
| 2309 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2310 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2313 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2314 | { |
| 2315 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2316 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2317 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2318 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2319 | return; |
| 2320 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2321 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2322 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2323 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2326 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2327 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2328 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2329 | { 0x1f, 0x0001 }, |
| 2330 | { 0x04, 0x0000 }, |
| 2331 | { 0x03, 0x00a1 }, |
| 2332 | { 0x02, 0x0008 }, |
| 2333 | { 0x01, 0x0120 }, |
| 2334 | { 0x00, 0x1000 }, |
| 2335 | { 0x04, 0x0800 }, |
| 2336 | { 0x04, 0x9000 }, |
| 2337 | { 0x03, 0x802f }, |
| 2338 | { 0x02, 0x4f02 }, |
| 2339 | { 0x01, 0x0409 }, |
| 2340 | { 0x00, 0xf099 }, |
| 2341 | { 0x04, 0x9800 }, |
| 2342 | { 0x04, 0xa000 }, |
| 2343 | { 0x03, 0xdf01 }, |
| 2344 | { 0x02, 0xdf20 }, |
| 2345 | { 0x01, 0xff95 }, |
| 2346 | { 0x00, 0xba00 }, |
| 2347 | { 0x04, 0xa800 }, |
| 2348 | { 0x04, 0xf000 }, |
| 2349 | { 0x03, 0xdf01 }, |
| 2350 | { 0x02, 0xdf20 }, |
| 2351 | { 0x01, 0x101a }, |
| 2352 | { 0x00, 0xa0ff }, |
| 2353 | { 0x04, 0xf800 }, |
| 2354 | { 0x04, 0x0000 }, |
| 2355 | { 0x1f, 0x0000 }, |
| 2356 | |
| 2357 | { 0x1f, 0x0001 }, |
| 2358 | { 0x10, 0xf41b }, |
| 2359 | { 0x14, 0xfb54 }, |
| 2360 | { 0x18, 0xf5c7 }, |
| 2361 | { 0x1f, 0x0000 }, |
| 2362 | |
| 2363 | { 0x1f, 0x0001 }, |
| 2364 | { 0x17, 0x0cc0 }, |
| 2365 | { 0x1f, 0x0000 } |
| 2366 | }; |
| 2367 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2368 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2369 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2370 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2373 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2374 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2375 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2376 | { 0x1f, 0x0001 }, |
| 2377 | { 0x04, 0x0000 }, |
| 2378 | { 0x03, 0x00a1 }, |
| 2379 | { 0x02, 0x0008 }, |
| 2380 | { 0x01, 0x0120 }, |
| 2381 | { 0x00, 0x1000 }, |
| 2382 | { 0x04, 0x0800 }, |
| 2383 | { 0x04, 0x9000 }, |
| 2384 | { 0x03, 0x802f }, |
| 2385 | { 0x02, 0x4f02 }, |
| 2386 | { 0x01, 0x0409 }, |
| 2387 | { 0x00, 0xf099 }, |
| 2388 | { 0x04, 0x9800 }, |
| 2389 | { 0x04, 0xa000 }, |
| 2390 | { 0x03, 0xdf01 }, |
| 2391 | { 0x02, 0xdf20 }, |
| 2392 | { 0x01, 0xff95 }, |
| 2393 | { 0x00, 0xba00 }, |
| 2394 | { 0x04, 0xa800 }, |
| 2395 | { 0x04, 0xf000 }, |
| 2396 | { 0x03, 0xdf01 }, |
| 2397 | { 0x02, 0xdf20 }, |
| 2398 | { 0x01, 0x101a }, |
| 2399 | { 0x00, 0xa0ff }, |
| 2400 | { 0x04, 0xf800 }, |
| 2401 | { 0x04, 0x0000 }, |
| 2402 | { 0x1f, 0x0000 }, |
| 2403 | |
| 2404 | { 0x1f, 0x0001 }, |
| 2405 | { 0x0b, 0x8480 }, |
| 2406 | { 0x1f, 0x0000 }, |
| 2407 | |
| 2408 | { 0x1f, 0x0001 }, |
| 2409 | { 0x18, 0x67c7 }, |
| 2410 | { 0x04, 0x2000 }, |
| 2411 | { 0x03, 0x002f }, |
| 2412 | { 0x02, 0x4360 }, |
| 2413 | { 0x01, 0x0109 }, |
| 2414 | { 0x00, 0x3022 }, |
| 2415 | { 0x04, 0x2800 }, |
| 2416 | { 0x1f, 0x0000 }, |
| 2417 | |
| 2418 | { 0x1f, 0x0001 }, |
| 2419 | { 0x17, 0x0cc0 }, |
| 2420 | { 0x1f, 0x0000 } |
| 2421 | }; |
| 2422 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2423 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2426 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2427 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2428 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2429 | { 0x10, 0xf41b }, |
| 2430 | { 0x1f, 0x0000 } |
| 2431 | }; |
| 2432 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2433 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2434 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2435 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2436 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2437 | } |
| 2438 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2439 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2440 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2441 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2442 | { 0x1f, 0x0001 }, |
| 2443 | { 0x10, 0xf41b }, |
| 2444 | { 0x1f, 0x0000 } |
| 2445 | }; |
| 2446 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2447 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2448 | } |
| 2449 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2450 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2451 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2452 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2453 | { 0x1f, 0x0000 }, |
| 2454 | { 0x1d, 0x0f00 }, |
| 2455 | { 0x1f, 0x0002 }, |
| 2456 | { 0x0c, 0x1ec8 }, |
| 2457 | { 0x1f, 0x0000 } |
| 2458 | }; |
| 2459 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2460 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2461 | } |
| 2462 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2463 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2464 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2465 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2466 | { 0x1f, 0x0001 }, |
| 2467 | { 0x1d, 0x3d98 }, |
| 2468 | { 0x1f, 0x0000 } |
| 2469 | }; |
| 2470 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2471 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2472 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2473 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2474 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2475 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2476 | } |
| 2477 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2478 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2479 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2480 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2481 | { 0x1f, 0x0001 }, |
| 2482 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2483 | { 0x1f, 0x0002 }, |
| 2484 | { 0x00, 0x88d4 }, |
| 2485 | { 0x01, 0x82b1 }, |
| 2486 | { 0x03, 0x7002 }, |
| 2487 | { 0x08, 0x9e30 }, |
| 2488 | { 0x09, 0x01f0 }, |
| 2489 | { 0x0a, 0x5500 }, |
| 2490 | { 0x0c, 0x00c8 }, |
| 2491 | { 0x1f, 0x0003 }, |
| 2492 | { 0x12, 0xc096 }, |
| 2493 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2494 | { 0x1f, 0x0000 }, |
| 2495 | { 0x1f, 0x0000 }, |
| 2496 | { 0x09, 0x2000 }, |
| 2497 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2498 | }; |
| 2499 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2500 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2501 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2502 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2503 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2504 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2505 | } |
| 2506 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2507 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2508 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2509 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2510 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2511 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2512 | { 0x03, 0x802f }, |
| 2513 | { 0x02, 0x4f02 }, |
| 2514 | { 0x01, 0x0409 }, |
| 2515 | { 0x00, 0xf099 }, |
| 2516 | { 0x04, 0x9800 }, |
| 2517 | { 0x04, 0x9000 }, |
| 2518 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2519 | { 0x1f, 0x0002 }, |
| 2520 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2521 | { 0x06, 0x0761 }, |
| 2522 | { 0x1f, 0x0003 }, |
| 2523 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2524 | { 0x1f, 0x0000 } |
| 2525 | }; |
| 2526 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2527 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2528 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2529 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2530 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2531 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2532 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2535 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2536 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2537 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2538 | { 0x1f, 0x0001 }, |
| 2539 | { 0x12, 0x2300 }, |
| 2540 | { 0x1d, 0x3d98 }, |
| 2541 | { 0x1f, 0x0002 }, |
| 2542 | { 0x0c, 0x7eb8 }, |
| 2543 | { 0x06, 0x5461 }, |
| 2544 | { 0x1f, 0x0003 }, |
| 2545 | { 0x16, 0x0f0a }, |
| 2546 | { 0x1f, 0x0000 } |
| 2547 | }; |
| 2548 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2549 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2550 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2551 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2552 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2553 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2554 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2555 | } |
| 2556 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2557 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2558 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2559 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2560 | } |
| 2561 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2562 | static const struct phy_reg rtl8168d_1_phy_reg_init_0[] = { |
| 2563 | /* Channel Estimation */ |
| 2564 | { 0x1f, 0x0001 }, |
| 2565 | { 0x06, 0x4064 }, |
| 2566 | { 0x07, 0x2863 }, |
| 2567 | { 0x08, 0x059c }, |
| 2568 | { 0x09, 0x26b4 }, |
| 2569 | { 0x0a, 0x6a19 }, |
| 2570 | { 0x0b, 0xdcc8 }, |
| 2571 | { 0x10, 0xf06d }, |
| 2572 | { 0x14, 0x7f68 }, |
| 2573 | { 0x18, 0x7fd9 }, |
| 2574 | { 0x1c, 0xf0ff }, |
| 2575 | { 0x1d, 0x3d9c }, |
| 2576 | { 0x1f, 0x0003 }, |
| 2577 | { 0x12, 0xf49f }, |
| 2578 | { 0x13, 0x070b }, |
| 2579 | { 0x1a, 0x05ad }, |
| 2580 | { 0x14, 0x94c0 }, |
| 2581 | |
| 2582 | /* |
| 2583 | * Tx Error Issue |
| 2584 | * Enhance line driver power |
| 2585 | */ |
| 2586 | { 0x1f, 0x0002 }, |
| 2587 | { 0x06, 0x5561 }, |
| 2588 | { 0x1f, 0x0005 }, |
| 2589 | { 0x05, 0x8332 }, |
| 2590 | { 0x06, 0x5561 }, |
| 2591 | |
| 2592 | /* |
| 2593 | * Can not link to 1Gbps with bad cable |
| 2594 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2595 | */ |
| 2596 | { 0x1f, 0x0001 }, |
| 2597 | { 0x17, 0x0cc0 }, |
| 2598 | |
| 2599 | { 0x1f, 0x0000 }, |
| 2600 | { 0x0d, 0xf880 } |
| 2601 | }; |
| 2602 | |
| 2603 | static const struct phy_reg rtl8168d_1_phy_reg_init_1[] = { |
| 2604 | { 0x1f, 0x0002 }, |
| 2605 | { 0x05, 0x669a }, |
| 2606 | { 0x1f, 0x0005 }, |
| 2607 | { 0x05, 0x8330 }, |
| 2608 | { 0x06, 0x669a }, |
| 2609 | { 0x1f, 0x0002 } |
| 2610 | }; |
| 2611 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2612 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2613 | { |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2614 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_0); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2615 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2616 | /* |
| 2617 | * Rx Error Issue |
| 2618 | * Fine Tune Switching regulator parameter |
| 2619 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2620 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2621 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2622 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2623 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2624 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2625 | int val; |
| 2626 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2627 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_1); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2628 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2629 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2630 | |
| 2631 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2632 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2633 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2634 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2635 | }; |
| 2636 | int i; |
| 2637 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2638 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2639 | |
| 2640 | val &= 0xff00; |
| 2641 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2642 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2643 | } |
| 2644 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2645 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2646 | { 0x1f, 0x0002 }, |
| 2647 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2648 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2649 | { 0x05, 0x8330 }, |
| 2650 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2651 | }; |
| 2652 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2653 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2654 | } |
| 2655 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2656 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2657 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2658 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2659 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2660 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2661 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2662 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2663 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2664 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2665 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2666 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2667 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2668 | |
| 2669 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2670 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2671 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2674 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2675 | { |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2676 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_0); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2677 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2678 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2679 | int val; |
| 2680 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2681 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_1); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2682 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2683 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2684 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2685 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2686 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2687 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2688 | }; |
| 2689 | int i; |
| 2690 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2691 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2692 | |
| 2693 | val &= 0xff00; |
| 2694 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2695 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2696 | } |
| 2697 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2698 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2699 | { 0x1f, 0x0002 }, |
| 2700 | { 0x05, 0x2642 }, |
| 2701 | { 0x1f, 0x0005 }, |
| 2702 | { 0x05, 0x8330 }, |
| 2703 | { 0x06, 0x2642 } |
| 2704 | }; |
| 2705 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2706 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2709 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2710 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2711 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2712 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2713 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2714 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2715 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2716 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2717 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2718 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2719 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2720 | |
| 2721 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2722 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2723 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2726 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2727 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2728 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2729 | { 0x1f, 0x0002 }, |
| 2730 | { 0x10, 0x0008 }, |
| 2731 | { 0x0d, 0x006c }, |
| 2732 | |
| 2733 | { 0x1f, 0x0000 }, |
| 2734 | { 0x0d, 0xf880 }, |
| 2735 | |
| 2736 | { 0x1f, 0x0001 }, |
| 2737 | { 0x17, 0x0cc0 }, |
| 2738 | |
| 2739 | { 0x1f, 0x0001 }, |
| 2740 | { 0x0b, 0xa4d8 }, |
| 2741 | { 0x09, 0x281c }, |
| 2742 | { 0x07, 0x2883 }, |
| 2743 | { 0x0a, 0x6b35 }, |
| 2744 | { 0x1d, 0x3da4 }, |
| 2745 | { 0x1c, 0xeffd }, |
| 2746 | { 0x14, 0x7f52 }, |
| 2747 | { 0x18, 0x7fc6 }, |
| 2748 | { 0x08, 0x0601 }, |
| 2749 | { 0x06, 0x4063 }, |
| 2750 | { 0x10, 0xf074 }, |
| 2751 | { 0x1f, 0x0003 }, |
| 2752 | { 0x13, 0x0789 }, |
| 2753 | { 0x12, 0xf4bd }, |
| 2754 | { 0x1a, 0x04fd }, |
| 2755 | { 0x14, 0x84b0 }, |
| 2756 | { 0x1f, 0x0000 }, |
| 2757 | { 0x00, 0x9200 }, |
| 2758 | |
| 2759 | { 0x1f, 0x0005 }, |
| 2760 | { 0x01, 0x0340 }, |
| 2761 | { 0x1f, 0x0001 }, |
| 2762 | { 0x04, 0x4000 }, |
| 2763 | { 0x03, 0x1d21 }, |
| 2764 | { 0x02, 0x0c32 }, |
| 2765 | { 0x01, 0x0200 }, |
| 2766 | { 0x00, 0x5554 }, |
| 2767 | { 0x04, 0x4800 }, |
| 2768 | { 0x04, 0x4000 }, |
| 2769 | { 0x04, 0xf000 }, |
| 2770 | { 0x03, 0xdf01 }, |
| 2771 | { 0x02, 0xdf20 }, |
| 2772 | { 0x01, 0x101a }, |
| 2773 | { 0x00, 0xa0ff }, |
| 2774 | { 0x04, 0xf800 }, |
| 2775 | { 0x04, 0xf000 }, |
| 2776 | { 0x1f, 0x0000 }, |
| 2777 | |
| 2778 | { 0x1f, 0x0007 }, |
| 2779 | { 0x1e, 0x0023 }, |
| 2780 | { 0x16, 0x0000 }, |
| 2781 | { 0x1f, 0x0000 } |
| 2782 | }; |
| 2783 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2784 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2785 | } |
| 2786 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2787 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 2788 | { |
| 2789 | static const struct phy_reg phy_reg_init[] = { |
| 2790 | { 0x1f, 0x0001 }, |
| 2791 | { 0x17, 0x0cc0 }, |
| 2792 | |
| 2793 | { 0x1f, 0x0007 }, |
| 2794 | { 0x1e, 0x002d }, |
| 2795 | { 0x18, 0x0040 }, |
| 2796 | { 0x1f, 0x0000 } |
| 2797 | }; |
| 2798 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2799 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2800 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2801 | } |
| 2802 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2803 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2804 | { |
| 2805 | static const struct phy_reg phy_reg_init[] = { |
| 2806 | /* Enable Delay cap */ |
| 2807 | { 0x1f, 0x0005 }, |
| 2808 | { 0x05, 0x8b80 }, |
| 2809 | { 0x06, 0xc896 }, |
| 2810 | { 0x1f, 0x0000 }, |
| 2811 | |
| 2812 | /* Channel estimation fine tune */ |
| 2813 | { 0x1f, 0x0001 }, |
| 2814 | { 0x0b, 0x6c20 }, |
| 2815 | { 0x07, 0x2872 }, |
| 2816 | { 0x1c, 0xefff }, |
| 2817 | { 0x1f, 0x0003 }, |
| 2818 | { 0x14, 0x6420 }, |
| 2819 | { 0x1f, 0x0000 }, |
| 2820 | |
| 2821 | /* Update PFM & 10M TX idle timer */ |
| 2822 | { 0x1f, 0x0007 }, |
| 2823 | { 0x1e, 0x002f }, |
| 2824 | { 0x15, 0x1919 }, |
| 2825 | { 0x1f, 0x0000 }, |
| 2826 | |
| 2827 | { 0x1f, 0x0007 }, |
| 2828 | { 0x1e, 0x00ac }, |
| 2829 | { 0x18, 0x0006 }, |
| 2830 | { 0x1f, 0x0000 } |
| 2831 | }; |
| 2832 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2833 | rtl_apply_firmware(tp); |
| 2834 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2835 | rtl_writephy_batch(tp, phy_reg_init); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2836 | |
| 2837 | /* DCO enable for 10M IDLE Power */ |
| 2838 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2839 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2840 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2841 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2842 | |
| 2843 | /* For impedance matching */ |
| 2844 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2845 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2846 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2847 | |
| 2848 | /* PHY auto speed down */ |
| 2849 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2850 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2851 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2852 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2853 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2854 | |
| 2855 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2856 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2857 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2858 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2859 | |
| 2860 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2861 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2862 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2863 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2864 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2865 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2866 | rtl_writephy(tp, 0x1f, 0x0006); |
| 2867 | rtl_writephy(tp, 0x00, 0x5a00); |
| 2868 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2869 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2870 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2871 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2872 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2873 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2874 | } |
| 2875 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2876 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 2877 | { |
| 2878 | const u16 w[] = { |
| 2879 | addr[0] | (addr[1] << 8), |
| 2880 | addr[2] | (addr[3] << 8), |
| 2881 | addr[4] | (addr[5] << 8) |
| 2882 | }; |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2883 | |
Heiner Kallweit | 3aa4c49 | 2019-05-02 20:46:52 +0200 | [diff] [blame] | 2884 | rtl_eri_write(tp, 0xe0, ERIAR_MASK_1111, w[0] | (w[1] << 16)); |
| 2885 | rtl_eri_write(tp, 0xe4, ERIAR_MASK_1111, w[2]); |
| 2886 | rtl_eri_write(tp, 0xf0, ERIAR_MASK_1111, w[0] << 16); |
| 2887 | rtl_eri_write(tp, 0xf4, ERIAR_MASK_1111, w[1] | (w[2] << 16)); |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2890 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 2891 | { |
| 2892 | static const struct phy_reg phy_reg_init[] = { |
| 2893 | /* Enable Delay cap */ |
| 2894 | { 0x1f, 0x0004 }, |
| 2895 | { 0x1f, 0x0007 }, |
| 2896 | { 0x1e, 0x00ac }, |
| 2897 | { 0x18, 0x0006 }, |
| 2898 | { 0x1f, 0x0002 }, |
| 2899 | { 0x1f, 0x0000 }, |
| 2900 | { 0x1f, 0x0000 }, |
| 2901 | |
| 2902 | /* Channel estimation fine tune */ |
| 2903 | { 0x1f, 0x0003 }, |
| 2904 | { 0x09, 0xa20f }, |
| 2905 | { 0x1f, 0x0000 }, |
| 2906 | { 0x1f, 0x0000 }, |
| 2907 | |
| 2908 | /* Green Setting */ |
| 2909 | { 0x1f, 0x0005 }, |
| 2910 | { 0x05, 0x8b5b }, |
| 2911 | { 0x06, 0x9222 }, |
| 2912 | { 0x05, 0x8b6d }, |
| 2913 | { 0x06, 0x8000 }, |
| 2914 | { 0x05, 0x8b76 }, |
| 2915 | { 0x06, 0x8000 }, |
| 2916 | { 0x1f, 0x0000 } |
| 2917 | }; |
| 2918 | |
| 2919 | rtl_apply_firmware(tp); |
| 2920 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2921 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2922 | |
| 2923 | /* For 4-corner performance improve */ |
| 2924 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2925 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2926 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2927 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2928 | |
| 2929 | /* PHY auto speed down */ |
| 2930 | rtl_writephy(tp, 0x1f, 0x0004); |
| 2931 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2932 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2933 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2934 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2935 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2936 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2937 | |
| 2938 | /* improve 10M EEE waveform */ |
| 2939 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2940 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2941 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2942 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2943 | |
| 2944 | /* Improve 2-pair detection performance */ |
| 2945 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2946 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2947 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2948 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2949 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2950 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 2951 | rtl_enable_eee(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2952 | |
| 2953 | /* Green feature */ |
| 2954 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 2955 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 2956 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2957 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 2958 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2959 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 2960 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 2961 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2962 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 2963 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2964 | } |
| 2965 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2966 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 2967 | { |
| 2968 | /* For 4-corner performance improve */ |
| 2969 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2970 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2971 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2972 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2973 | |
| 2974 | /* PHY auto speed down */ |
| 2975 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2976 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2977 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2978 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2979 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2980 | |
| 2981 | /* Improve 10M EEE waveform */ |
| 2982 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2983 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2984 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2985 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2986 | |
| 2987 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 2988 | rtl_enable_eee(tp); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2989 | } |
| 2990 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2991 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 2992 | { |
| 2993 | static const struct phy_reg phy_reg_init[] = { |
| 2994 | /* Channel estimation fine tune */ |
| 2995 | { 0x1f, 0x0003 }, |
| 2996 | { 0x09, 0xa20f }, |
| 2997 | { 0x1f, 0x0000 }, |
| 2998 | |
| 2999 | /* Modify green table for giga & fnet */ |
| 3000 | { 0x1f, 0x0005 }, |
| 3001 | { 0x05, 0x8b55 }, |
| 3002 | { 0x06, 0x0000 }, |
| 3003 | { 0x05, 0x8b5e }, |
| 3004 | { 0x06, 0x0000 }, |
| 3005 | { 0x05, 0x8b67 }, |
| 3006 | { 0x06, 0x0000 }, |
| 3007 | { 0x05, 0x8b70 }, |
| 3008 | { 0x06, 0x0000 }, |
| 3009 | { 0x1f, 0x0000 }, |
| 3010 | { 0x1f, 0x0007 }, |
| 3011 | { 0x1e, 0x0078 }, |
| 3012 | { 0x17, 0x0000 }, |
| 3013 | { 0x19, 0x00fb }, |
| 3014 | { 0x1f, 0x0000 }, |
| 3015 | |
| 3016 | /* Modify green table for 10M */ |
| 3017 | { 0x1f, 0x0005 }, |
| 3018 | { 0x05, 0x8b79 }, |
| 3019 | { 0x06, 0xaa00 }, |
| 3020 | { 0x1f, 0x0000 }, |
| 3021 | |
| 3022 | /* Disable hiimpedance detection (RTCT) */ |
| 3023 | { 0x1f, 0x0003 }, |
| 3024 | { 0x01, 0x328a }, |
| 3025 | { 0x1f, 0x0000 } |
| 3026 | }; |
| 3027 | |
| 3028 | rtl_apply_firmware(tp); |
| 3029 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3030 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3031 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3032 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3033 | |
| 3034 | /* Improve 2-pair detection performance */ |
| 3035 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3036 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3037 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3038 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3039 | } |
| 3040 | |
| 3041 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3042 | { |
| 3043 | rtl_apply_firmware(tp); |
| 3044 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3045 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3046 | } |
| 3047 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3048 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3049 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3050 | static const struct phy_reg phy_reg_init[] = { |
| 3051 | /* Channel estimation fine tune */ |
| 3052 | { 0x1f, 0x0003 }, |
| 3053 | { 0x09, 0xa20f }, |
| 3054 | { 0x1f, 0x0000 }, |
| 3055 | |
| 3056 | /* Modify green table for giga & fnet */ |
| 3057 | { 0x1f, 0x0005 }, |
| 3058 | { 0x05, 0x8b55 }, |
| 3059 | { 0x06, 0x0000 }, |
| 3060 | { 0x05, 0x8b5e }, |
| 3061 | { 0x06, 0x0000 }, |
| 3062 | { 0x05, 0x8b67 }, |
| 3063 | { 0x06, 0x0000 }, |
| 3064 | { 0x05, 0x8b70 }, |
| 3065 | { 0x06, 0x0000 }, |
| 3066 | { 0x1f, 0x0000 }, |
| 3067 | { 0x1f, 0x0007 }, |
| 3068 | { 0x1e, 0x0078 }, |
| 3069 | { 0x17, 0x0000 }, |
| 3070 | { 0x19, 0x00aa }, |
| 3071 | { 0x1f, 0x0000 }, |
| 3072 | |
| 3073 | /* Modify green table for 10M */ |
| 3074 | { 0x1f, 0x0005 }, |
| 3075 | { 0x05, 0x8b79 }, |
| 3076 | { 0x06, 0xaa00 }, |
| 3077 | { 0x1f, 0x0000 }, |
| 3078 | |
| 3079 | /* Disable hiimpedance detection (RTCT) */ |
| 3080 | { 0x1f, 0x0003 }, |
| 3081 | { 0x01, 0x328a }, |
| 3082 | { 0x1f, 0x0000 } |
| 3083 | }; |
| 3084 | |
| 3085 | |
| 3086 | rtl_apply_firmware(tp); |
| 3087 | |
| 3088 | rtl8168f_hw_phy_config(tp); |
| 3089 | |
| 3090 | /* Improve 2-pair detection performance */ |
| 3091 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3092 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3093 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3094 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3095 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3096 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3097 | |
| 3098 | /* Modify green table for giga */ |
| 3099 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3100 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3101 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3102 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3103 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3104 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3105 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3106 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3107 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3108 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3109 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3110 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3111 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3112 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3113 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3114 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3115 | |
| 3116 | /* uc same-seed solution */ |
| 3117 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3118 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3119 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3120 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3121 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3122 | /* Green feature */ |
| 3123 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3124 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3125 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3126 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3127 | } |
| 3128 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3129 | static void rtl8168g_disable_aldps(struct rtl8169_private *tp) |
| 3130 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3131 | phy_modify_paged(tp->phydev, 0x0a43, 0x10, BIT(2), 0); |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3132 | } |
| 3133 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3134 | static void rtl8168g_phy_adjust_10m_aldps(struct rtl8169_private *tp) |
| 3135 | { |
| 3136 | struct phy_device *phydev = tp->phydev; |
| 3137 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3138 | phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0); |
| 3139 | phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6)); |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3140 | phy_write(phydev, 0x1f, 0x0a43); |
| 3141 | phy_write(phydev, 0x13, 0x8084); |
| 3142 | phy_clear_bits(phydev, 0x14, BIT(14) | BIT(13)); |
| 3143 | phy_set_bits(phydev, 0x10, BIT(12) | BIT(1) | BIT(0)); |
| 3144 | |
| 3145 | phy_write(phydev, 0x1f, 0x0000); |
| 3146 | } |
| 3147 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3148 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3149 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3150 | int ret; |
| 3151 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3152 | rtl_apply_firmware(tp); |
| 3153 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3154 | ret = phy_read_paged(tp->phydev, 0x0a46, 0x10); |
| 3155 | if (ret & BIT(8)) |
| 3156 | phy_modify_paged(tp->phydev, 0x0bcc, 0x12, BIT(15), 0); |
| 3157 | else |
| 3158 | phy_modify_paged(tp->phydev, 0x0bcc, 0x12, 0, BIT(15)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3159 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3160 | ret = phy_read_paged(tp->phydev, 0x0a46, 0x13); |
| 3161 | if (ret & BIT(8)) |
Thomas Voegtle | 1a03bb5 | 2019-07-20 19:01:22 +0200 | [diff] [blame] | 3162 | phy_modify_paged(tp->phydev, 0x0c41, 0x15, 0, BIT(1)); |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3163 | else |
Thomas Voegtle | 1a03bb5 | 2019-07-20 19:01:22 +0200 | [diff] [blame] | 3164 | phy_modify_paged(tp->phydev, 0x0c41, 0x15, BIT(1), 0); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3165 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3166 | /* Enable PHY auto speed down */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3167 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3168 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3169 | rtl8168g_phy_adjust_10m_aldps(tp); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3170 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3171 | /* EEE auto-fallback function */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3172 | phy_modify_paged(tp->phydev, 0x0a4b, 0x11, 0, BIT(2)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3173 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3174 | /* Enable UC LPF tune function */ |
| 3175 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3176 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3177 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3178 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3179 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3180 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3181 | /* Improve SWR Efficiency */ |
| 3182 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3183 | rtl_writephy(tp, 0x14, 0x5065); |
| 3184 | rtl_writephy(tp, 0x14, 0xd065); |
| 3185 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3186 | rtl_writephy(tp, 0x11, 0x5655); |
| 3187 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3188 | rtl_writephy(tp, 0x14, 0x1065); |
| 3189 | rtl_writephy(tp, 0x14, 0x9065); |
| 3190 | rtl_writephy(tp, 0x14, 0x1065); |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3191 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3192 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3193 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3194 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3195 | rtl_enable_eee(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3196 | } |
| 3197 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3198 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3199 | { |
| 3200 | rtl_apply_firmware(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3201 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3202 | rtl_enable_eee(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3205 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3206 | { |
| 3207 | u16 dout_tapbin; |
| 3208 | u32 data; |
| 3209 | |
| 3210 | rtl_apply_firmware(tp); |
| 3211 | |
| 3212 | /* CHN EST parameters adjust - giga master */ |
| 3213 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3214 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3215 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3216 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3217 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3218 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3219 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3220 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3221 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3222 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3223 | |
| 3224 | /* CHN EST parameters adjust - giga slave */ |
| 3225 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3226 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3227 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3228 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3229 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3230 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3231 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3232 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3233 | |
| 3234 | /* CHN EST parameters adjust - fnet */ |
| 3235 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3236 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3237 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3238 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3239 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3240 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3241 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3242 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3243 | |
| 3244 | /* enable R-tune & PGA-retune function */ |
| 3245 | dout_tapbin = 0; |
| 3246 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3247 | data = rtl_readphy(tp, 0x13); |
| 3248 | data &= 3; |
| 3249 | data <<= 2; |
| 3250 | dout_tapbin |= data; |
| 3251 | data = rtl_readphy(tp, 0x12); |
| 3252 | data &= 0xc000; |
| 3253 | data >>= 14; |
| 3254 | dout_tapbin |= data; |
| 3255 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3256 | dout_tapbin <<= 12; |
| 3257 | dout_tapbin &= 0xf000; |
| 3258 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3259 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3260 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3261 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3262 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3263 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3264 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3265 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3266 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3267 | |
| 3268 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3269 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3270 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3271 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3272 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3273 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3274 | |
| 3275 | /* enable GPHY 10M */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3276 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(11)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3277 | |
| 3278 | /* SAR ADC performance */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3279 | phy_modify_paged(tp->phydev, 0x0bca, 0x17, BIT(12) | BIT(13), BIT(14)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3280 | |
| 3281 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3282 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3283 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3284 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3285 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3286 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3287 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3288 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3289 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3290 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3291 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3292 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3293 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3294 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3295 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3296 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3297 | |
| 3298 | /* disable phy pfm mode */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3299 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, BIT(7), 0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3300 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3301 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | b6cef26 | 2019-08-15 14:21:30 +0200 | [diff] [blame] | 3302 | rtl8168h_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3303 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3307 | { |
| 3308 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3309 | u16 rlen; |
| 3310 | u32 data; |
| 3311 | |
| 3312 | rtl_apply_firmware(tp); |
| 3313 | |
| 3314 | /* CHIN EST parameter update */ |
| 3315 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3316 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3317 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3318 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3319 | |
| 3320 | /* enable R-tune & PGA-retune function */ |
| 3321 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3322 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3323 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3324 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3325 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3326 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3327 | |
| 3328 | /* enable GPHY 10M */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3329 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(11)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3330 | |
| 3331 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3332 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3333 | ioffset_p3 = ((data & 0x80)>>7); |
| 3334 | ioffset_p3 <<= 3; |
| 3335 | |
| 3336 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3337 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3338 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3339 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3340 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3341 | ioffset_p0 <<= 3; |
| 3342 | ioffset_p0 |= (data & (0x07)); |
| 3343 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3344 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3345 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3346 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3347 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3348 | rtl_writephy(tp, 0x16, data); |
| 3349 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3350 | } |
| 3351 | |
| 3352 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3353 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3354 | data = rtl_readphy(tp, 0x16); |
| 3355 | data &= 0x000f; |
| 3356 | rlen = 0; |
| 3357 | if (data > 3) |
| 3358 | rlen = data - 3; |
| 3359 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3360 | rtl_writephy(tp, 0x17, data); |
| 3361 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3362 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3363 | |
| 3364 | /* disable phy pfm mode */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3365 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, BIT(7), 0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3366 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3367 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3368 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3369 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3370 | } |
| 3371 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3372 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3373 | { |
| 3374 | /* Enable PHY auto speed down */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3375 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3376 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3377 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3378 | |
| 3379 | /* Enable EEE auto-fallback function */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3380 | phy_modify_paged(tp->phydev, 0x0a4b, 0x11, 0, BIT(2)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3381 | |
| 3382 | /* Enable UC LPF tune function */ |
| 3383 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3384 | rtl_writephy(tp, 0x13, 0x8012); |
| 3385 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3386 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3387 | |
| 3388 | /* set rg_sel_sdm_rate */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3389 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3390 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3391 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3392 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3393 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3397 | { |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3398 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3399 | |
| 3400 | /* Enable UC LPF tune function */ |
| 3401 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3402 | rtl_writephy(tp, 0x13, 0x8012); |
| 3403 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3404 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3405 | |
| 3406 | /* Set rg_sel_sdm_rate */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3407 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3408 | |
| 3409 | /* Channel estimation parameters */ |
| 3410 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3411 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3412 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3413 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3414 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3415 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3416 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3417 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3418 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3419 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3420 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3421 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3422 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3423 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3424 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3425 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3426 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3427 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3428 | rtl_writephy(tp, 0x13, 0x8110); |
| 3429 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3430 | rtl_writephy(tp, 0x13, 0x810f); |
| 3431 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3432 | rtl_writephy(tp, 0x13, 0x8111); |
| 3433 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3434 | rtl_writephy(tp, 0x13, 0x8113); |
| 3435 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3436 | rtl_writephy(tp, 0x13, 0x8115); |
| 3437 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3438 | rtl_writephy(tp, 0x13, 0x810e); |
| 3439 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3440 | rtl_writephy(tp, 0x13, 0x810c); |
| 3441 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3442 | rtl_writephy(tp, 0x13, 0x810b); |
| 3443 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3444 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3445 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3446 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3447 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3448 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3449 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3450 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3451 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3452 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3453 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3454 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3455 | |
| 3456 | /* Force PWM-mode */ |
| 3457 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3458 | rtl_writephy(tp, 0x14, 0x5065); |
| 3459 | rtl_writephy(tp, 0x14, 0xd065); |
| 3460 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3461 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3462 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3463 | rtl_writephy(tp, 0x14, 0x1065); |
| 3464 | rtl_writephy(tp, 0x14, 0x9065); |
| 3465 | rtl_writephy(tp, 0x14, 0x1065); |
| 3466 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3467 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3468 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3469 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3470 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3471 | } |
| 3472 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3473 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3474 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3475 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3476 | { 0x1f, 0x0003 }, |
| 3477 | { 0x08, 0x441d }, |
| 3478 | { 0x01, 0x9100 }, |
| 3479 | { 0x1f, 0x0000 } |
| 3480 | }; |
| 3481 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3482 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3483 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3484 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3485 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3486 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3487 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3488 | } |
| 3489 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3490 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3491 | { |
| 3492 | static const struct phy_reg phy_reg_init[] = { |
| 3493 | { 0x1f, 0x0005 }, |
| 3494 | { 0x1a, 0x0000 }, |
| 3495 | { 0x1f, 0x0000 }, |
| 3496 | |
| 3497 | { 0x1f, 0x0004 }, |
| 3498 | { 0x1c, 0x0000 }, |
| 3499 | { 0x1f, 0x0000 }, |
| 3500 | |
| 3501 | { 0x1f, 0x0001 }, |
| 3502 | { 0x15, 0x7701 }, |
| 3503 | { 0x1f, 0x0000 } |
| 3504 | }; |
| 3505 | |
| 3506 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3507 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3508 | rtl_writephy(tp, 0x18, 0x0310); |
| 3509 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3510 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3511 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3512 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3513 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3514 | } |
| 3515 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3516 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3517 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3518 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3519 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3520 | rtl_writephy(tp, 0x18, 0x0310); |
| 3521 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3522 | |
| 3523 | rtl_apply_firmware(tp); |
| 3524 | |
| 3525 | /* EEE setting */ |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3526 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3527 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3528 | rtl_writephy(tp, 0x10, 0x401f); |
| 3529 | rtl_writephy(tp, 0x19, 0x7030); |
| 3530 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3531 | } |
| 3532 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3533 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3534 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3535 | static const struct phy_reg phy_reg_init[] = { |
| 3536 | { 0x1f, 0x0004 }, |
| 3537 | { 0x10, 0xc07f }, |
| 3538 | { 0x19, 0x7030 }, |
| 3539 | { 0x1f, 0x0000 } |
| 3540 | }; |
| 3541 | |
| 3542 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3543 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3544 | rtl_writephy(tp, 0x18, 0x0310); |
| 3545 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3546 | |
| 3547 | rtl_apply_firmware(tp); |
| 3548 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3549 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3550 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3551 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3552 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3553 | } |
| 3554 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3555 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3556 | { |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3557 | static const rtl_generic_fct phy_configs[] = { |
| 3558 | /* PCI devices. */ |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3559 | [RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config, |
| 3560 | [RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config, |
| 3561 | [RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config, |
| 3562 | [RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config, |
| 3563 | [RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config, |
| 3564 | /* PCI-E devices. */ |
| 3565 | [RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config, |
| 3566 | [RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config, |
| 3567 | [RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config, |
| 3568 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 3569 | [RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config, |
| 3570 | [RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config, |
| 3571 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 3572 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 3573 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 3574 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 3575 | [RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config, |
| 3576 | [RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config, |
| 3577 | [RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config, |
| 3578 | [RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config, |
| 3579 | [RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config, |
| 3580 | [RTL_GIGA_MAC_VER_22] = rtl8168c_4_hw_phy_config, |
| 3581 | [RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config, |
| 3582 | [RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config, |
| 3583 | [RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config, |
| 3584 | [RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config, |
| 3585 | [RTL_GIGA_MAC_VER_27] = rtl8168d_3_hw_phy_config, |
| 3586 | [RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config, |
| 3587 | [RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config, |
| 3588 | [RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config, |
| 3589 | [RTL_GIGA_MAC_VER_31] = NULL, |
| 3590 | [RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config, |
| 3591 | [RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config, |
| 3592 | [RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config, |
| 3593 | [RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config, |
| 3594 | [RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config, |
| 3595 | [RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config, |
| 3596 | [RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config, |
| 3597 | [RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config, |
| 3598 | [RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config, |
| 3599 | [RTL_GIGA_MAC_VER_41] = NULL, |
| 3600 | [RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config, |
| 3601 | [RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config, |
| 3602 | [RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config, |
| 3603 | [RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config, |
| 3604 | [RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config, |
| 3605 | [RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config, |
| 3606 | [RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config, |
| 3607 | [RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config, |
| 3608 | [RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config, |
| 3609 | [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config, |
| 3610 | }; |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3611 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3612 | |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3613 | if (phy_configs[tp->mac_version]) |
| 3614 | phy_configs[tp->mac_version](tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3615 | } |
| 3616 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3617 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3618 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3619 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3620 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3621 | } |
| 3622 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3623 | 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] | 3624 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3625 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3626 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3627 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 7a67e11 | 2018-09-19 22:00:24 +0200 | [diff] [blame] | 3628 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 3629 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 3630 | netif_dbg(tp, drv, dev, |
| 3631 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3632 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3633 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3634 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 3635 | /* We may have called phy_speed_down before */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3636 | phy_speed_up(tp->phydev); |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 3637 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3638 | genphy_soft_reset(tp->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3639 | } |
| 3640 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3641 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 3642 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3643 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3644 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 3645 | rtl_unlock_config_regs(tp); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3646 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3647 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 3648 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3649 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3650 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 3651 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3652 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3653 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 3654 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3655 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 3656 | rtl_lock_config_regs(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3657 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3658 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 3662 | { |
| 3663 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 3664 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 3665 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3666 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 3667 | ret = eth_mac_addr(dev, p); |
| 3668 | if (ret) |
| 3669 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3670 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 3671 | pm_runtime_get_noresume(d); |
| 3672 | |
| 3673 | if (pm_runtime_active(d)) |
| 3674 | rtl_rar_set(tp, dev->dev_addr); |
| 3675 | |
| 3676 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3677 | |
| 3678 | return 0; |
| 3679 | } |
| 3680 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 3681 | 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] | 3682 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3683 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3684 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 3685 | if (!netif_running(dev)) |
| 3686 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 3687 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3688 | return phy_mii_ioctl(tp->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3691 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 3692 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3693 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 3694 | case RTL_GIGA_MAC_VER_25: |
| 3695 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3696 | case RTL_GIGA_MAC_VER_29: |
| 3697 | case RTL_GIGA_MAC_VER_30: |
| 3698 | case RTL_GIGA_MAC_VER_32: |
| 3699 | case RTL_GIGA_MAC_VER_33: |
| 3700 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3701 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3702 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3703 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 3704 | break; |
| 3705 | default: |
| 3706 | break; |
| 3707 | } |
| 3708 | } |
| 3709 | |
Heiner Kallweit | 25e9411 | 2019-05-29 20:52:03 +0200 | [diff] [blame] | 3710 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3711 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 3712 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3713 | return; |
| 3714 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3715 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3716 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3717 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3718 | |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 3719 | if (device_may_wakeup(tp_to_dev(tp))) { |
| 3720 | phy_speed_down(tp->phydev, false); |
| 3721 | rtl_wol_suspend_quirk(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3722 | return; |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 3723 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3724 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3725 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3726 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3727 | case RTL_GIGA_MAC_VER_37: |
| 3728 | case RTL_GIGA_MAC_VER_39: |
| 3729 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 3730 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3731 | case RTL_GIGA_MAC_VER_45: |
| 3732 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3733 | case RTL_GIGA_MAC_VER_47: |
| 3734 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3735 | case RTL_GIGA_MAC_VER_50: |
| 3736 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3737 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3738 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3739 | case RTL_GIGA_MAC_VER_40: |
| 3740 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3741 | case RTL_GIGA_MAC_VER_49: |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 3742 | rtl_eri_clear_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3743 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3744 | break; |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 3745 | default: |
| 3746 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3747 | } |
| 3748 | } |
| 3749 | |
Heiner Kallweit | 25e9411 | 2019-05-29 20:52:03 +0200 | [diff] [blame] | 3750 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3751 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3752 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3753 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3754 | case RTL_GIGA_MAC_VER_37: |
| 3755 | case RTL_GIGA_MAC_VER_39: |
| 3756 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3757 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3758 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 3759 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3760 | case RTL_GIGA_MAC_VER_45: |
| 3761 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3762 | case RTL_GIGA_MAC_VER_47: |
| 3763 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3764 | case RTL_GIGA_MAC_VER_50: |
| 3765 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3766 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3767 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3768 | case RTL_GIGA_MAC_VER_40: |
| 3769 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3770 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3771 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 3772 | rtl_eri_set_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3773 | break; |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 3774 | default: |
| 3775 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3778 | phy_resume(tp->phydev); |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 3779 | /* give MAC/PHY some time to resume */ |
| 3780 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3783 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 3784 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3785 | switch (tp->mac_version) { |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 3786 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3787 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3788 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3789 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3790 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
Maciej S. Szmigiero | 511cfd5 | 2018-10-11 16:02:10 +0200 | [diff] [blame] | 3791 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36: |
| 3792 | case RTL_GIGA_MAC_VER_38: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3793 | 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] | 3794 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3795 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3796 | 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] | 3797 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3798 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3799 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3800 | break; |
| 3801 | } |
| 3802 | } |
| 3803 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3804 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 3805 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 3806 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3807 | } |
| 3808 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3809 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3810 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3811 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 3812 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3813 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3817 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3818 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 3819 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3820 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3824 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3825 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3829 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3830 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3834 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3835 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 3836 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 3837 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3838 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3842 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3843 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 3844 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 3845 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3846 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3850 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3851 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 3852 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3856 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3857 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3858 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3862 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3863 | r8168b_0_hw_jumbo_enable(tp); |
| 3864 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3865 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3866 | } |
| 3867 | |
| 3868 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3869 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3870 | r8168b_0_hw_jumbo_disable(tp); |
| 3871 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3872 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3873 | } |
| 3874 | |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3875 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3876 | { |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3877 | rtl_unlock_config_regs(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3878 | switch (tp->mac_version) { |
| 3879 | case RTL_GIGA_MAC_VER_11: |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3880 | r8168b_0_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3881 | break; |
| 3882 | case RTL_GIGA_MAC_VER_12: |
| 3883 | case RTL_GIGA_MAC_VER_17: |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3884 | r8168b_1_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3885 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3886 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26: |
| 3887 | r8168c_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3888 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3889 | case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28: |
| 3890 | r8168dp_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3891 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3892 | case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_34: |
| 3893 | r8168e_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3894 | break; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3895 | default: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3896 | break; |
| 3897 | } |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3898 | rtl_lock_config_regs(tp); |
| 3899 | } |
| 3900 | |
| 3901 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3902 | { |
| 3903 | rtl_unlock_config_regs(tp); |
| 3904 | switch (tp->mac_version) { |
| 3905 | case RTL_GIGA_MAC_VER_11: |
| 3906 | r8168b_0_hw_jumbo_disable(tp); |
| 3907 | break; |
| 3908 | case RTL_GIGA_MAC_VER_12: |
| 3909 | case RTL_GIGA_MAC_VER_17: |
| 3910 | r8168b_1_hw_jumbo_disable(tp); |
| 3911 | break; |
| 3912 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26: |
| 3913 | r8168c_hw_jumbo_disable(tp); |
| 3914 | break; |
| 3915 | case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28: |
| 3916 | r8168dp_hw_jumbo_disable(tp); |
| 3917 | break; |
| 3918 | case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_34: |
| 3919 | r8168e_hw_jumbo_disable(tp); |
| 3920 | break; |
| 3921 | default: |
| 3922 | break; |
| 3923 | } |
| 3924 | rtl_lock_config_regs(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3925 | } |
| 3926 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3927 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 3928 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3929 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3930 | } |
| 3931 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3932 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 3933 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3934 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3935 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3936 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3937 | } |
| 3938 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 3939 | static void rtl_request_firmware(struct rtl8169_private *tp) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3940 | { |
| 3941 | struct rtl_fw *rtl_fw; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3942 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 3943 | /* firmware loaded already or no firmware available */ |
| 3944 | if (tp->rtl_fw || !tp->fw_name) |
| 3945 | return; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3946 | |
| 3947 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 3948 | if (!rtl_fw) { |
| 3949 | netif_warn(tp, ifup, tp->dev, "Unable to load firmware, out of memory\n"); |
| 3950 | return; |
| 3951 | } |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3952 | |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 3953 | rtl_fw->phy_write = rtl_writephy; |
| 3954 | rtl_fw->phy_read = rtl_readphy; |
| 3955 | rtl_fw->mac_mcu_write = mac_mcu_write; |
| 3956 | rtl_fw->mac_mcu_read = mac_mcu_read; |
Heiner Kallweit | 4edb00f | 2019-06-03 21:25:43 +0200 | [diff] [blame] | 3957 | rtl_fw->fw_name = tp->fw_name; |
| 3958 | rtl_fw->dev = tp_to_dev(tp); |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 3959 | |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 3960 | if (rtl_fw_request_firmware(rtl_fw)) |
| 3961 | kfree(rtl_fw); |
| 3962 | else |
| 3963 | tp->rtl_fw = rtl_fw; |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3964 | } |
| 3965 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3966 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 3967 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3968 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3969 | } |
| 3970 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3971 | DECLARE_RTL_COND(rtl_npq_cond) |
| 3972 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3973 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 3977 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3978 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3979 | } |
| 3980 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3981 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | { |
| 3983 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 3984 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3986 | rtl_rx_close(tp); |
| 3987 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3988 | switch (tp->mac_version) { |
| 3989 | case RTL_GIGA_MAC_VER_27: |
| 3990 | case RTL_GIGA_MAC_VER_28: |
| 3991 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3992 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3993 | break; |
| 3994 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 3995 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3996 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3997 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3998 | break; |
| 3999 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4000 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4001 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4002 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4005 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4008 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4009 | { |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4010 | u32 val = TX_DMA_BURST << TxDMAShift | |
| 4011 | InterFrameGap << TxInterFrameGapShift; |
| 4012 | |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 4013 | if (rtl_is_8168evl_up(tp)) |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4014 | val |= TXCFG_AUTO_FIFO; |
| 4015 | |
| 4016 | RTL_W32(tp, TxConfig, val); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4019 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4021 | /* Low hurts. Let's disable the filtering. */ |
| 4022 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4023 | } |
| 4024 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4025 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4026 | { |
| 4027 | /* |
| 4028 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4029 | * register to be written before TxDescAddrLow to work. |
| 4030 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4031 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4032 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4033 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4034 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4035 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4036 | } |
| 4037 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4038 | 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] | 4039 | { |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4040 | u32 val; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4041 | |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4042 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4043 | val = 0x000fff00; |
| 4044 | else if (tp->mac_version == RTL_GIGA_MAC_VER_06) |
| 4045 | val = 0x00ffff00; |
| 4046 | else |
| 4047 | return; |
| 4048 | |
| 4049 | if (RTL_R8(tp, Config2) & PCI_Clock_66MHz) |
| 4050 | val |= 0xff; |
| 4051 | |
| 4052 | RTL_W32(tp, 0x7c, val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4053 | } |
| 4054 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4055 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4056 | { |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4057 | u32 rx_mode = AcceptBroadcast | AcceptMyPhys | AcceptMulticast; |
| 4058 | /* Multicast hash filter */ |
| 4059 | u32 mc_filter[2] = { 0xffffffff, 0xffffffff }; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4060 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4061 | u32 tmp; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4062 | |
| 4063 | if (dev->flags & IFF_PROMISC) { |
| 4064 | /* Unconditionally log net taps. */ |
| 4065 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4066 | rx_mode |= AcceptAllPhys; |
| 4067 | } else if (netdev_mc_count(dev) > MC_FILTER_LIMIT || |
| 4068 | dev->flags & IFF_ALLMULTI || |
| 4069 | tp->mac_version == RTL_GIGA_MAC_VER_35) { |
| 4070 | /* accept all multicasts */ |
| 4071 | } else if (netdev_mc_empty(dev)) { |
| 4072 | rx_mode &= ~AcceptMulticast; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4073 | } else { |
| 4074 | struct netdev_hw_addr *ha; |
| 4075 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4076 | mc_filter[1] = mc_filter[0] = 0; |
| 4077 | netdev_for_each_mc_addr(ha, dev) { |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4078 | u32 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4079 | mc_filter[bit_nr >> 5] |= BIT(bit_nr & 31); |
| 4080 | } |
| 4081 | |
| 4082 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4083 | tmp = mc_filter[0]; |
| 4084 | mc_filter[0] = swab32(mc_filter[1]); |
| 4085 | mc_filter[1] = swab32(tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | if (dev->features & NETIF_F_RXALL) |
| 4090 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4091 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4092 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4093 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4094 | |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4095 | tmp = RTL_R32(tp, RxConfig); |
| 4096 | RTL_W32(tp, RxConfig, (tmp & ~RX_CONFIG_ACCEPT_MASK) | rx_mode); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4099 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4100 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4101 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4102 | } |
| 4103 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4104 | 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] | 4105 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4106 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4107 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4108 | RTL_W32(tp, CSIDR, value); |
| 4109 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4110 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4111 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4112 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4113 | } |
| 4114 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4115 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4116 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4117 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4118 | |
| 4119 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4120 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4121 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4122 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4123 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4124 | } |
| 4125 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4126 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4127 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4128 | struct pci_dev *pdev = tp->pci_dev; |
| 4129 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4130 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4131 | /* According to Realtek the value at config space address 0x070f |
| 4132 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4133 | * first and if it fails fall back to CSI. |
| 4134 | */ |
| 4135 | if (pdev->cfg_size > 0x070f && |
| 4136 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4137 | return; |
| 4138 | |
| 4139 | netdev_notice_once(tp->dev, |
| 4140 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4141 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4142 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4143 | } |
| 4144 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4145 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4146 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4147 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | struct ephy_info { |
| 4151 | unsigned int offset; |
| 4152 | u16 mask; |
| 4153 | u16 bits; |
| 4154 | }; |
| 4155 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4156 | static void __rtl_ephy_init(struct rtl8169_private *tp, |
| 4157 | const struct ephy_info *e, int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4158 | { |
| 4159 | u16 w; |
| 4160 | |
| 4161 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4162 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4163 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4164 | e++; |
| 4165 | } |
| 4166 | } |
| 4167 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4168 | #define rtl_ephy_init(tp, a) __rtl_ephy_init(tp, a, ARRAY_SIZE(a)) |
| 4169 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4170 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4171 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4172 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4173 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4174 | } |
| 4175 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4176 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4177 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4178 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4179 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4182 | static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp) |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4183 | { |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4184 | /* work around an issue when PCI reset occurs during L2/L3 state */ |
| 4185 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4186 | } |
| 4187 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4188 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4189 | { |
Heiner Kallweit | 62b1b3b | 2019-06-18 23:14:50 +0200 | [diff] [blame] | 4190 | /* Don't enable ASPM in the chip if OS can't control ASPM */ |
| 4191 | if (enable && tp->aspm_manageable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4192 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4193 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4194 | } else { |
| 4195 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4196 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4197 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4198 | |
| 4199 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4200 | } |
| 4201 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4202 | static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat, |
| 4203 | u16 tx_stat, u16 rx_dyn, u16 tx_dyn) |
| 4204 | { |
| 4205 | /* Usage of dynamic vs. static FIFO is controlled by bit |
| 4206 | * TXCFG_AUTO_FIFO. Exact meaning of FIFO values isn't known. |
| 4207 | */ |
| 4208 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, (rx_stat << 16) | rx_dyn); |
| 4209 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, (tx_stat << 16) | tx_dyn); |
| 4210 | } |
| 4211 | |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4212 | static void rtl8168g_set_pause_thresholds(struct rtl8169_private *tp, |
| 4213 | u8 low, u8 high) |
| 4214 | { |
| 4215 | /* FIFO thresholds for pause flow control */ |
| 4216 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, low); |
| 4217 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, high); |
| 4218 | } |
| 4219 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4220 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4221 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4222 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4223 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4224 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4225 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4226 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4227 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4228 | } |
| 4229 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4230 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4231 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4232 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4233 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4234 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4235 | } |
| 4236 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4237 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4238 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4239 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4240 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4241 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4242 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4243 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4244 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4245 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4246 | rtl_disable_clock_request(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4247 | } |
| 4248 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4249 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4250 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4251 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4252 | { 0x01, 0, 0x0001 }, |
| 4253 | { 0x02, 0x0800, 0x1000 }, |
| 4254 | { 0x03, 0, 0x0042 }, |
| 4255 | { 0x06, 0x0080, 0x0000 }, |
| 4256 | { 0x07, 0, 0x2000 } |
| 4257 | }; |
| 4258 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4259 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4260 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4261 | rtl_ephy_init(tp, e_info_8168cp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4262 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4263 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4264 | } |
| 4265 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4266 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4267 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4268 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4269 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4270 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4271 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4272 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4273 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4274 | } |
| 4275 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4276 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4277 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4278 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4279 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4280 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4281 | |
| 4282 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4283 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4284 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4285 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4286 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4287 | } |
| 4288 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4289 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4290 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4291 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4292 | { 0x02, 0x0800, 0x1000 }, |
| 4293 | { 0x03, 0, 0x0002 }, |
| 4294 | { 0x06, 0x0080, 0x0000 } |
| 4295 | }; |
| 4296 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4297 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4298 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4299 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4300 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4301 | rtl_ephy_init(tp, e_info_8168c_1); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4302 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4303 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4304 | } |
| 4305 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4306 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4307 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4308 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4309 | { 0x01, 0, 0x0001 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4310 | { 0x03, 0x0400, 0x0020 } |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4311 | }; |
| 4312 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4313 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4314 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4315 | rtl_ephy_init(tp, e_info_8168c_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4316 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4317 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4318 | } |
| 4319 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4320 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4321 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4322 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4323 | } |
| 4324 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4325 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4326 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4327 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4328 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4329 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4330 | } |
| 4331 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4332 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4333 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4334 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4335 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4336 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4337 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4338 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4339 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4340 | } |
| 4341 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4342 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4343 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4344 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4345 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4346 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4347 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4348 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4349 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4352 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4353 | { |
| 4354 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4355 | { 0x0b, 0x0000, 0x0048 }, |
| 4356 | { 0x19, 0x0020, 0x0050 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4357 | { 0x0c, 0x0100, 0x0020 }, |
| 4358 | { 0x10, 0x0004, 0x0000 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4359 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4360 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4361 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4362 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4363 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4364 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4365 | rtl_ephy_init(tp, e_info_8168d_4); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4366 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4367 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4370 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4371 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4372 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4373 | { 0x00, 0x0200, 0x0100 }, |
| 4374 | { 0x00, 0x0000, 0x0004 }, |
| 4375 | { 0x06, 0x0002, 0x0001 }, |
| 4376 | { 0x06, 0x0000, 0x0030 }, |
| 4377 | { 0x07, 0x0000, 0x2000 }, |
| 4378 | { 0x00, 0x0000, 0x0020 }, |
| 4379 | { 0x03, 0x5800, 0x2000 }, |
| 4380 | { 0x03, 0x0000, 0x0001 }, |
| 4381 | { 0x01, 0x0800, 0x1000 }, |
| 4382 | { 0x07, 0x0000, 0x4000 }, |
| 4383 | { 0x1e, 0x0000, 0x2000 }, |
| 4384 | { 0x19, 0xffff, 0xfe6c }, |
| 4385 | { 0x0a, 0x0000, 0x0040 } |
| 4386 | }; |
| 4387 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4388 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4389 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4390 | rtl_ephy_init(tp, e_info_8168e_1); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4391 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4392 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4393 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4394 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4395 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4396 | |
| 4397 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4398 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4399 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4400 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4401 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4402 | } |
| 4403 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4404 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4405 | { |
| 4406 | static const struct ephy_info e_info_8168e_2[] = { |
| 4407 | { 0x09, 0x0000, 0x0080 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4408 | { 0x19, 0x0000, 0x0224 }, |
| 4409 | { 0x00, 0x0000, 0x0004 }, |
| 4410 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4411 | }; |
| 4412 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4413 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4414 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4415 | rtl_ephy_init(tp, e_info_8168e_2); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4416 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4417 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4418 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4419 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4420 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4421 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4422 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4423 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 4424 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4425 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4426 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4427 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4428 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 4429 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4430 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4431 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 4432 | rtl8168_config_eee_mac(tp); |
| 4433 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4434 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 4435 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 4436 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 4437 | |
| 4438 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4439 | } |
| 4440 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4441 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4442 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4443 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4444 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4445 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4446 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4447 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4448 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4449 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4450 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4451 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
| 4452 | rtl_eri_set_bits(tp, 0x1d0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4453 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 4454 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4455 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4456 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 4457 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4458 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 4459 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 4460 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 4461 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 4462 | |
| 4463 | rtl8168_config_eee_mac(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4464 | } |
| 4465 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4466 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 4467 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4468 | static const struct ephy_info e_info_8168f_1[] = { |
| 4469 | { 0x06, 0x00c0, 0x0020 }, |
| 4470 | { 0x08, 0x0001, 0x0002 }, |
| 4471 | { 0x09, 0x0000, 0x0080 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4472 | { 0x19, 0x0000, 0x0224 }, |
| 4473 | { 0x00, 0x0000, 0x0004 }, |
| 4474 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4475 | }; |
| 4476 | |
| 4477 | rtl_hw_start_8168f(tp); |
| 4478 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4479 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4480 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4481 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4482 | } |
| 4483 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4484 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 4485 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4486 | static const struct ephy_info e_info_8168f_1[] = { |
| 4487 | { 0x06, 0x00c0, 0x0020 }, |
| 4488 | { 0x0f, 0xffff, 0x5200 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4489 | { 0x19, 0x0000, 0x0224 }, |
| 4490 | { 0x00, 0x0000, 0x0004 }, |
| 4491 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4492 | }; |
| 4493 | |
| 4494 | rtl_hw_start_8168f(tp); |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4495 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4496 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4497 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4498 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4499 | rtl_eri_set_bits(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4500 | } |
| 4501 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4502 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4503 | { |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4504 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4505 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4506 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4507 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4508 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4509 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4510 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4511 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4512 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4513 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4514 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4515 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4516 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4517 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4518 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4519 | rtl8168_config_eee_mac(tp); |
| 4520 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4521 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4522 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4523 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4524 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4525 | } |
| 4526 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4527 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 4528 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4529 | static const struct ephy_info e_info_8168g_1[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4530 | { 0x00, 0x0008, 0x0000 }, |
| 4531 | { 0x0c, 0x3ff0, 0x0820 }, |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4532 | { 0x1e, 0x0000, 0x0001 }, |
| 4533 | { 0x19, 0x8000, 0x0000 } |
| 4534 | }; |
| 4535 | |
| 4536 | rtl_hw_start_8168g(tp); |
| 4537 | |
| 4538 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4539 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4540 | rtl_ephy_init(tp, e_info_8168g_1); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4541 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4542 | } |
| 4543 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4544 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 4545 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4546 | static const struct ephy_info e_info_8168g_2[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4547 | { 0x00, 0x0008, 0x0000 }, |
| 4548 | { 0x0c, 0x3ff0, 0x0820 }, |
| 4549 | { 0x19, 0xffff, 0x7c00 }, |
| 4550 | { 0x1e, 0xffff, 0x20eb }, |
| 4551 | { 0x0d, 0xffff, 0x1666 }, |
| 4552 | { 0x00, 0xffff, 0x10a3 }, |
| 4553 | { 0x06, 0xffff, 0xf050 }, |
| 4554 | { 0x04, 0x0000, 0x0010 }, |
| 4555 | { 0x1d, 0x4000, 0x0000 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4556 | }; |
| 4557 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4558 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4559 | |
| 4560 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4561 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4562 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4563 | rtl_ephy_init(tp, e_info_8168g_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4566 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 4567 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4568 | static const struct ephy_info e_info_8411_2[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4569 | { 0x00, 0x0008, 0x0000 }, |
| 4570 | { 0x0c, 0x37d0, 0x0820 }, |
| 4571 | { 0x1e, 0x0000, 0x0001 }, |
| 4572 | { 0x19, 0x8021, 0x0000 }, |
| 4573 | { 0x1e, 0x0000, 0x2000 }, |
| 4574 | { 0x0d, 0x0100, 0x0200 }, |
| 4575 | { 0x00, 0x0000, 0x0080 }, |
| 4576 | { 0x06, 0x0000, 0x0010 }, |
| 4577 | { 0x04, 0x0000, 0x0010 }, |
| 4578 | { 0x1d, 0x0000, 0x4000 }, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4579 | }; |
| 4580 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4581 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4582 | |
| 4583 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4584 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4585 | rtl_ephy_init(tp, e_info_8411_2); |
Heiner Kallweit | fe4e8db0 | 2019-07-13 13:45:47 +0200 | [diff] [blame] | 4586 | |
| 4587 | /* The following Realtek-provided magic fixes an issue with the RX unit |
| 4588 | * getting confused after the PHY having been powered-down. |
| 4589 | */ |
| 4590 | r8168_mac_ocp_write(tp, 0xFC28, 0x0000); |
| 4591 | r8168_mac_ocp_write(tp, 0xFC2A, 0x0000); |
| 4592 | r8168_mac_ocp_write(tp, 0xFC2C, 0x0000); |
| 4593 | r8168_mac_ocp_write(tp, 0xFC2E, 0x0000); |
| 4594 | r8168_mac_ocp_write(tp, 0xFC30, 0x0000); |
| 4595 | r8168_mac_ocp_write(tp, 0xFC32, 0x0000); |
| 4596 | r8168_mac_ocp_write(tp, 0xFC34, 0x0000); |
| 4597 | r8168_mac_ocp_write(tp, 0xFC36, 0x0000); |
| 4598 | mdelay(3); |
| 4599 | r8168_mac_ocp_write(tp, 0xFC26, 0x0000); |
| 4600 | |
| 4601 | r8168_mac_ocp_write(tp, 0xF800, 0xE008); |
| 4602 | r8168_mac_ocp_write(tp, 0xF802, 0xE00A); |
| 4603 | r8168_mac_ocp_write(tp, 0xF804, 0xE00C); |
| 4604 | r8168_mac_ocp_write(tp, 0xF806, 0xE00E); |
| 4605 | r8168_mac_ocp_write(tp, 0xF808, 0xE027); |
| 4606 | r8168_mac_ocp_write(tp, 0xF80A, 0xE04F); |
| 4607 | r8168_mac_ocp_write(tp, 0xF80C, 0xE05E); |
| 4608 | r8168_mac_ocp_write(tp, 0xF80E, 0xE065); |
| 4609 | r8168_mac_ocp_write(tp, 0xF810, 0xC602); |
| 4610 | r8168_mac_ocp_write(tp, 0xF812, 0xBE00); |
| 4611 | r8168_mac_ocp_write(tp, 0xF814, 0x0000); |
| 4612 | r8168_mac_ocp_write(tp, 0xF816, 0xC502); |
| 4613 | r8168_mac_ocp_write(tp, 0xF818, 0xBD00); |
| 4614 | r8168_mac_ocp_write(tp, 0xF81A, 0x074C); |
| 4615 | r8168_mac_ocp_write(tp, 0xF81C, 0xC302); |
| 4616 | r8168_mac_ocp_write(tp, 0xF81E, 0xBB00); |
| 4617 | r8168_mac_ocp_write(tp, 0xF820, 0x080A); |
| 4618 | r8168_mac_ocp_write(tp, 0xF822, 0x6420); |
| 4619 | r8168_mac_ocp_write(tp, 0xF824, 0x48C2); |
| 4620 | r8168_mac_ocp_write(tp, 0xF826, 0x8C20); |
| 4621 | r8168_mac_ocp_write(tp, 0xF828, 0xC516); |
| 4622 | r8168_mac_ocp_write(tp, 0xF82A, 0x64A4); |
| 4623 | r8168_mac_ocp_write(tp, 0xF82C, 0x49C0); |
| 4624 | r8168_mac_ocp_write(tp, 0xF82E, 0xF009); |
| 4625 | r8168_mac_ocp_write(tp, 0xF830, 0x74A2); |
| 4626 | r8168_mac_ocp_write(tp, 0xF832, 0x8CA5); |
| 4627 | r8168_mac_ocp_write(tp, 0xF834, 0x74A0); |
| 4628 | r8168_mac_ocp_write(tp, 0xF836, 0xC50E); |
| 4629 | r8168_mac_ocp_write(tp, 0xF838, 0x9CA2); |
| 4630 | r8168_mac_ocp_write(tp, 0xF83A, 0x1C11); |
| 4631 | r8168_mac_ocp_write(tp, 0xF83C, 0x9CA0); |
| 4632 | r8168_mac_ocp_write(tp, 0xF83E, 0xE006); |
| 4633 | r8168_mac_ocp_write(tp, 0xF840, 0x74F8); |
| 4634 | r8168_mac_ocp_write(tp, 0xF842, 0x48C4); |
| 4635 | r8168_mac_ocp_write(tp, 0xF844, 0x8CF8); |
| 4636 | r8168_mac_ocp_write(tp, 0xF846, 0xC404); |
| 4637 | r8168_mac_ocp_write(tp, 0xF848, 0xBC00); |
| 4638 | r8168_mac_ocp_write(tp, 0xF84A, 0xC403); |
| 4639 | r8168_mac_ocp_write(tp, 0xF84C, 0xBC00); |
| 4640 | r8168_mac_ocp_write(tp, 0xF84E, 0x0BF2); |
| 4641 | r8168_mac_ocp_write(tp, 0xF850, 0x0C0A); |
| 4642 | r8168_mac_ocp_write(tp, 0xF852, 0xE434); |
| 4643 | r8168_mac_ocp_write(tp, 0xF854, 0xD3C0); |
| 4644 | r8168_mac_ocp_write(tp, 0xF856, 0x49D9); |
| 4645 | r8168_mac_ocp_write(tp, 0xF858, 0xF01F); |
| 4646 | r8168_mac_ocp_write(tp, 0xF85A, 0xC526); |
| 4647 | r8168_mac_ocp_write(tp, 0xF85C, 0x64A5); |
| 4648 | r8168_mac_ocp_write(tp, 0xF85E, 0x1400); |
| 4649 | r8168_mac_ocp_write(tp, 0xF860, 0xF007); |
| 4650 | r8168_mac_ocp_write(tp, 0xF862, 0x0C01); |
| 4651 | r8168_mac_ocp_write(tp, 0xF864, 0x8CA5); |
| 4652 | r8168_mac_ocp_write(tp, 0xF866, 0x1C15); |
| 4653 | r8168_mac_ocp_write(tp, 0xF868, 0xC51B); |
| 4654 | r8168_mac_ocp_write(tp, 0xF86A, 0x9CA0); |
| 4655 | r8168_mac_ocp_write(tp, 0xF86C, 0xE013); |
| 4656 | r8168_mac_ocp_write(tp, 0xF86E, 0xC519); |
| 4657 | r8168_mac_ocp_write(tp, 0xF870, 0x74A0); |
| 4658 | r8168_mac_ocp_write(tp, 0xF872, 0x48C4); |
| 4659 | r8168_mac_ocp_write(tp, 0xF874, 0x8CA0); |
| 4660 | r8168_mac_ocp_write(tp, 0xF876, 0xC516); |
| 4661 | r8168_mac_ocp_write(tp, 0xF878, 0x74A4); |
| 4662 | r8168_mac_ocp_write(tp, 0xF87A, 0x48C8); |
| 4663 | r8168_mac_ocp_write(tp, 0xF87C, 0x48CA); |
| 4664 | r8168_mac_ocp_write(tp, 0xF87E, 0x9CA4); |
| 4665 | r8168_mac_ocp_write(tp, 0xF880, 0xC512); |
| 4666 | r8168_mac_ocp_write(tp, 0xF882, 0x1B00); |
| 4667 | r8168_mac_ocp_write(tp, 0xF884, 0x9BA0); |
| 4668 | r8168_mac_ocp_write(tp, 0xF886, 0x1B1C); |
| 4669 | r8168_mac_ocp_write(tp, 0xF888, 0x483F); |
| 4670 | r8168_mac_ocp_write(tp, 0xF88A, 0x9BA2); |
| 4671 | r8168_mac_ocp_write(tp, 0xF88C, 0x1B04); |
| 4672 | r8168_mac_ocp_write(tp, 0xF88E, 0xC508); |
| 4673 | r8168_mac_ocp_write(tp, 0xF890, 0x9BA0); |
| 4674 | r8168_mac_ocp_write(tp, 0xF892, 0xC505); |
| 4675 | r8168_mac_ocp_write(tp, 0xF894, 0xBD00); |
| 4676 | r8168_mac_ocp_write(tp, 0xF896, 0xC502); |
| 4677 | r8168_mac_ocp_write(tp, 0xF898, 0xBD00); |
| 4678 | r8168_mac_ocp_write(tp, 0xF89A, 0x0300); |
| 4679 | r8168_mac_ocp_write(tp, 0xF89C, 0x051E); |
| 4680 | r8168_mac_ocp_write(tp, 0xF89E, 0xE434); |
| 4681 | r8168_mac_ocp_write(tp, 0xF8A0, 0xE018); |
| 4682 | r8168_mac_ocp_write(tp, 0xF8A2, 0xE092); |
| 4683 | r8168_mac_ocp_write(tp, 0xF8A4, 0xDE20); |
| 4684 | r8168_mac_ocp_write(tp, 0xF8A6, 0xD3C0); |
| 4685 | r8168_mac_ocp_write(tp, 0xF8A8, 0xC50F); |
| 4686 | r8168_mac_ocp_write(tp, 0xF8AA, 0x76A4); |
| 4687 | r8168_mac_ocp_write(tp, 0xF8AC, 0x49E3); |
| 4688 | r8168_mac_ocp_write(tp, 0xF8AE, 0xF007); |
| 4689 | r8168_mac_ocp_write(tp, 0xF8B0, 0x49C0); |
| 4690 | r8168_mac_ocp_write(tp, 0xF8B2, 0xF103); |
| 4691 | r8168_mac_ocp_write(tp, 0xF8B4, 0xC607); |
| 4692 | r8168_mac_ocp_write(tp, 0xF8B6, 0xBE00); |
| 4693 | r8168_mac_ocp_write(tp, 0xF8B8, 0xC606); |
| 4694 | r8168_mac_ocp_write(tp, 0xF8BA, 0xBE00); |
| 4695 | r8168_mac_ocp_write(tp, 0xF8BC, 0xC602); |
| 4696 | r8168_mac_ocp_write(tp, 0xF8BE, 0xBE00); |
| 4697 | r8168_mac_ocp_write(tp, 0xF8C0, 0x0C4C); |
| 4698 | r8168_mac_ocp_write(tp, 0xF8C2, 0x0C28); |
| 4699 | r8168_mac_ocp_write(tp, 0xF8C4, 0x0C2C); |
| 4700 | r8168_mac_ocp_write(tp, 0xF8C6, 0xDC00); |
| 4701 | r8168_mac_ocp_write(tp, 0xF8C8, 0xC707); |
| 4702 | r8168_mac_ocp_write(tp, 0xF8CA, 0x1D00); |
| 4703 | r8168_mac_ocp_write(tp, 0xF8CC, 0x8DE2); |
| 4704 | r8168_mac_ocp_write(tp, 0xF8CE, 0x48C1); |
| 4705 | r8168_mac_ocp_write(tp, 0xF8D0, 0xC502); |
| 4706 | r8168_mac_ocp_write(tp, 0xF8D2, 0xBD00); |
| 4707 | r8168_mac_ocp_write(tp, 0xF8D4, 0x00AA); |
| 4708 | r8168_mac_ocp_write(tp, 0xF8D6, 0xE0C0); |
| 4709 | r8168_mac_ocp_write(tp, 0xF8D8, 0xC502); |
| 4710 | r8168_mac_ocp_write(tp, 0xF8DA, 0xBD00); |
| 4711 | r8168_mac_ocp_write(tp, 0xF8DC, 0x0132); |
| 4712 | |
| 4713 | r8168_mac_ocp_write(tp, 0xFC26, 0x8000); |
| 4714 | |
| 4715 | r8168_mac_ocp_write(tp, 0xFC2A, 0x0743); |
| 4716 | r8168_mac_ocp_write(tp, 0xFC2C, 0x0801); |
| 4717 | r8168_mac_ocp_write(tp, 0xFC2E, 0x0BE9); |
| 4718 | r8168_mac_ocp_write(tp, 0xFC30, 0x02FD); |
| 4719 | r8168_mac_ocp_write(tp, 0xFC32, 0x0C25); |
| 4720 | r8168_mac_ocp_write(tp, 0xFC34, 0x00A9); |
| 4721 | r8168_mac_ocp_write(tp, 0xFC36, 0x012D); |
| 4722 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4723 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4724 | } |
| 4725 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4726 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 4727 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4728 | static const struct ephy_info e_info_8168h_1[] = { |
| 4729 | { 0x1e, 0x0800, 0x0001 }, |
| 4730 | { 0x1d, 0x0000, 0x0800 }, |
| 4731 | { 0x05, 0xffff, 0x2089 }, |
| 4732 | { 0x06, 0xffff, 0x5881 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4733 | { 0x04, 0xffff, 0x854a }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4734 | { 0x01, 0xffff, 0x068b } |
| 4735 | }; |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4736 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4737 | |
| 4738 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4739 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4740 | rtl_ephy_init(tp, e_info_8168h_1); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4741 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4742 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4743 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4744 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4745 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4746 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4747 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4748 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4749 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4750 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4751 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_1111, BIT(4)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4752 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4753 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4754 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4755 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4756 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4757 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4758 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4759 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4760 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4761 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4762 | rtl8168_config_eee_mac(tp); |
| 4763 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4764 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4765 | 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] | 4766 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4767 | 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] | 4768 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4769 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4770 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4771 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4772 | |
| 4773 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 4774 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4775 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4776 | if (rg_saw_cnt > 0) { |
| 4777 | u16 sw_cnt_1ms_ini; |
| 4778 | |
| 4779 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 4780 | sw_cnt_1ms_ini &= 0x0fff; |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4781 | r8168_mac_ocp_modify(tp, 0xd412, 0x0fff, sw_cnt_1ms_ini); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4782 | } |
| 4783 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4784 | r8168_mac_ocp_modify(tp, 0xe056, 0x00f0, 0x0070); |
| 4785 | r8168_mac_ocp_modify(tp, 0xe052, 0x6000, 0x8008); |
| 4786 | r8168_mac_ocp_modify(tp, 0xe0d6, 0x01ff, 0x017f); |
| 4787 | r8168_mac_ocp_modify(tp, 0xd420, 0x0fff, 0x047f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4788 | |
| 4789 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 4790 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 4791 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 4792 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4793 | |
| 4794 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4795 | } |
| 4796 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4797 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 4798 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 4799 | rtl8168ep_stop_cmac(tp); |
| 4800 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4801 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4802 | rtl8168g_set_pause_thresholds(tp, 0x2f, 0x5f); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4803 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4804 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4805 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4806 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4807 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4808 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4809 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4810 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f80); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4811 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4812 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4813 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4814 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4815 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4816 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4817 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4818 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4819 | rtl8168_config_eee_mac(tp); |
| 4820 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4821 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4822 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4823 | 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] | 4824 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4825 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 4829 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4830 | static const struct ephy_info e_info_8168ep_1[] = { |
| 4831 | { 0x00, 0xffff, 0x10ab }, |
| 4832 | { 0x06, 0xffff, 0xf030 }, |
| 4833 | { 0x08, 0xffff, 0x2006 }, |
| 4834 | { 0x0d, 0xffff, 0x1666 }, |
| 4835 | { 0x0c, 0x3ff0, 0x0000 } |
| 4836 | }; |
| 4837 | |
| 4838 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4839 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4840 | rtl_ephy_init(tp, e_info_8168ep_1); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4841 | |
| 4842 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4843 | |
| 4844 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 4848 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4849 | static const struct ephy_info e_info_8168ep_2[] = { |
| 4850 | { 0x00, 0xffff, 0x10a3 }, |
| 4851 | { 0x19, 0xffff, 0xfc00 }, |
| 4852 | { 0x1e, 0xffff, 0x20ea } |
| 4853 | }; |
| 4854 | |
| 4855 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4856 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4857 | rtl_ephy_init(tp, e_info_8168ep_2); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4858 | |
| 4859 | rtl_hw_start_8168ep(tp); |
| 4860 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4861 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4862 | 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] | 4863 | |
| 4864 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 4868 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4869 | static const struct ephy_info e_info_8168ep_3[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4870 | { 0x00, 0x0000, 0x0080 }, |
| 4871 | { 0x0d, 0x0100, 0x0200 }, |
| 4872 | { 0x19, 0x8021, 0x0000 }, |
| 4873 | { 0x1e, 0x0000, 0x2000 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4874 | }; |
| 4875 | |
| 4876 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4877 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4878 | rtl_ephy_init(tp, e_info_8168ep_3); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4879 | |
| 4880 | rtl_hw_start_8168ep(tp); |
| 4881 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4882 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4883 | 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] | 4884 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4885 | r8168_mac_ocp_modify(tp, 0xd3e2, 0x0fff, 0x0271); |
| 4886 | r8168_mac_ocp_modify(tp, 0xd3e4, 0x00ff, 0x0000); |
| 4887 | r8168_mac_ocp_modify(tp, 0xe860, 0x0000, 0x0080); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4888 | |
| 4889 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4890 | } |
| 4891 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4892 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4893 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4894 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4895 | { 0x01, 0, 0x6e65 }, |
| 4896 | { 0x02, 0, 0x091f }, |
| 4897 | { 0x03, 0, 0xc2f9 }, |
| 4898 | { 0x06, 0, 0xafb5 }, |
| 4899 | { 0x07, 0, 0x0e00 }, |
| 4900 | { 0x19, 0, 0xec80 }, |
| 4901 | { 0x01, 0, 0x2e65 }, |
| 4902 | { 0x01, 0, 0x6e65 } |
| 4903 | }; |
| 4904 | u8 cfg1; |
| 4905 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4906 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4907 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4908 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4909 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4910 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4911 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4912 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4913 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4914 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4915 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4916 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4917 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4918 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4919 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4920 | rtl_ephy_init(tp, e_info_8102e_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4921 | } |
| 4922 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4923 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4924 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4925 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4926 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4927 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4928 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4929 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 4930 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4931 | } |
| 4932 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4933 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4934 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4935 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4936 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4937 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4938 | } |
| 4939 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4940 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4941 | { |
| 4942 | static const struct ephy_info e_info_8105e_1[] = { |
| 4943 | { 0x07, 0, 0x4000 }, |
| 4944 | { 0x19, 0, 0x0200 }, |
| 4945 | { 0x19, 0, 0x0020 }, |
| 4946 | { 0x1e, 0, 0x2000 }, |
| 4947 | { 0x03, 0, 0x0001 }, |
| 4948 | { 0x19, 0, 0x0100 }, |
| 4949 | { 0x19, 0, 0x0004 }, |
| 4950 | { 0x0a, 0, 0x0020 } |
| 4951 | }; |
| 4952 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4953 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4954 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4955 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4956 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4957 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4958 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4959 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 4960 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4961 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4962 | rtl_ephy_init(tp, e_info_8105e_1); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4963 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4964 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4965 | } |
| 4966 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4967 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4968 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4969 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4970 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4971 | } |
| 4972 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4973 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 4974 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4975 | static const struct ephy_info e_info_8402[] = { |
| 4976 | { 0x19, 0xffff, 0xff64 }, |
| 4977 | { 0x1e, 0, 0x4000 } |
| 4978 | }; |
| 4979 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4980 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4981 | |
| 4982 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4983 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4984 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4985 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4986 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4987 | rtl_ephy_init(tp, e_info_8402); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4988 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4989 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4990 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4991 | rtl_set_fifo_size(tp, 0x00, 0x00, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4992 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4993 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4994 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
| 4995 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4996 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4997 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4998 | } |
| 4999 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5000 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5001 | { |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5002 | rtl_hw_aspm_clkreq_enable(tp, false); |
| 5003 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5004 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5005 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5006 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5007 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5008 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5009 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5010 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5011 | rtl_pcie_state_l2l3_disable(tp); |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5012 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5013 | } |
| 5014 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5015 | static void rtl_hw_config(struct rtl8169_private *tp) |
| 5016 | { |
| 5017 | static const rtl_generic_fct hw_configs[] = { |
| 5018 | [RTL_GIGA_MAC_VER_07] = rtl_hw_start_8102e_1, |
| 5019 | [RTL_GIGA_MAC_VER_08] = rtl_hw_start_8102e_3, |
| 5020 | [RTL_GIGA_MAC_VER_09] = rtl_hw_start_8102e_2, |
| 5021 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 5022 | [RTL_GIGA_MAC_VER_11] = rtl_hw_start_8168bb, |
| 5023 | [RTL_GIGA_MAC_VER_12] = rtl_hw_start_8168bef, |
| 5024 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 5025 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 5026 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 5027 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 5028 | [RTL_GIGA_MAC_VER_17] = rtl_hw_start_8168bef, |
| 5029 | [RTL_GIGA_MAC_VER_18] = rtl_hw_start_8168cp_1, |
| 5030 | [RTL_GIGA_MAC_VER_19] = rtl_hw_start_8168c_1, |
| 5031 | [RTL_GIGA_MAC_VER_20] = rtl_hw_start_8168c_2, |
| 5032 | [RTL_GIGA_MAC_VER_21] = rtl_hw_start_8168c_3, |
| 5033 | [RTL_GIGA_MAC_VER_22] = rtl_hw_start_8168c_4, |
| 5034 | [RTL_GIGA_MAC_VER_23] = rtl_hw_start_8168cp_2, |
| 5035 | [RTL_GIGA_MAC_VER_24] = rtl_hw_start_8168cp_3, |
| 5036 | [RTL_GIGA_MAC_VER_25] = rtl_hw_start_8168d, |
| 5037 | [RTL_GIGA_MAC_VER_26] = rtl_hw_start_8168d, |
| 5038 | [RTL_GIGA_MAC_VER_27] = rtl_hw_start_8168d, |
| 5039 | [RTL_GIGA_MAC_VER_28] = rtl_hw_start_8168d_4, |
| 5040 | [RTL_GIGA_MAC_VER_29] = rtl_hw_start_8105e_1, |
| 5041 | [RTL_GIGA_MAC_VER_30] = rtl_hw_start_8105e_2, |
| 5042 | [RTL_GIGA_MAC_VER_31] = rtl_hw_start_8168dp, |
| 5043 | [RTL_GIGA_MAC_VER_32] = rtl_hw_start_8168e_1, |
| 5044 | [RTL_GIGA_MAC_VER_33] = rtl_hw_start_8168e_1, |
| 5045 | [RTL_GIGA_MAC_VER_34] = rtl_hw_start_8168e_2, |
| 5046 | [RTL_GIGA_MAC_VER_35] = rtl_hw_start_8168f_1, |
| 5047 | [RTL_GIGA_MAC_VER_36] = rtl_hw_start_8168f_1, |
| 5048 | [RTL_GIGA_MAC_VER_37] = rtl_hw_start_8402, |
| 5049 | [RTL_GIGA_MAC_VER_38] = rtl_hw_start_8411, |
| 5050 | [RTL_GIGA_MAC_VER_39] = rtl_hw_start_8106, |
| 5051 | [RTL_GIGA_MAC_VER_40] = rtl_hw_start_8168g_1, |
| 5052 | [RTL_GIGA_MAC_VER_41] = rtl_hw_start_8168g_1, |
| 5053 | [RTL_GIGA_MAC_VER_42] = rtl_hw_start_8168g_2, |
| 5054 | [RTL_GIGA_MAC_VER_43] = rtl_hw_start_8168g_2, |
| 5055 | [RTL_GIGA_MAC_VER_44] = rtl_hw_start_8411_2, |
| 5056 | [RTL_GIGA_MAC_VER_45] = rtl_hw_start_8168h_1, |
| 5057 | [RTL_GIGA_MAC_VER_46] = rtl_hw_start_8168h_1, |
| 5058 | [RTL_GIGA_MAC_VER_47] = rtl_hw_start_8168h_1, |
| 5059 | [RTL_GIGA_MAC_VER_48] = rtl_hw_start_8168h_1, |
| 5060 | [RTL_GIGA_MAC_VER_49] = rtl_hw_start_8168ep_1, |
| 5061 | [RTL_GIGA_MAC_VER_50] = rtl_hw_start_8168ep_2, |
| 5062 | [RTL_GIGA_MAC_VER_51] = rtl_hw_start_8168ep_3, |
| 5063 | }; |
| 5064 | |
| 5065 | if (hw_configs[tp->mac_version]) |
| 5066 | hw_configs[tp->mac_version](tp); |
| 5067 | } |
| 5068 | |
| 5069 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
| 5070 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5071 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5072 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5073 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5074 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5075 | |
Heiner Kallweit | 272b226 | 2019-06-14 07:55:21 +0200 | [diff] [blame] | 5076 | if (rtl_is_8168evl_up(tp)) |
| 5077 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
| 5078 | else |
| 5079 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5080 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5081 | rtl_hw_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | } |
| 5083 | |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5084 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
| 5085 | { |
| 5086 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 5087 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 5088 | |
| 5089 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
| 5090 | |
| 5091 | tp->cp_cmd |= PCIMulRW; |
| 5092 | |
| 5093 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5094 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
| 5095 | netif_dbg(tp, drv, tp->dev, |
| 5096 | "Set MAC Reg C+CR Offset 0xe0. Bit 3 and Bit 14 MUST be 1\n"); |
| 5097 | tp->cp_cmd |= (1 << 14); |
| 5098 | } |
| 5099 | |
| 5100 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 5101 | |
| 5102 | rtl8169_set_magic_reg(tp, tp->mac_version); |
| 5103 | |
| 5104 | RTL_W32(tp, RxMissed, 0); |
| 5105 | } |
| 5106 | |
| 5107 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 5108 | { |
| 5109 | rtl_unlock_config_regs(tp); |
| 5110 | |
| 5111 | tp->cp_cmd &= CPCMD_MASK; |
| 5112 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 5113 | |
| 5114 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 5115 | rtl_hw_start_8169(tp); |
| 5116 | else |
| 5117 | rtl_hw_start_8168(tp); |
| 5118 | |
| 5119 | rtl_set_rx_max_size(tp); |
| 5120 | rtl_set_rx_tx_desc_registers(tp); |
| 5121 | rtl_lock_config_regs(tp); |
| 5122 | |
| 5123 | /* disable interrupt coalescing */ |
| 5124 | RTL_W16(tp, IntrMitigate, 0x0000); |
| 5125 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5126 | RTL_R8(tp, IntrMask); |
| 5127 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5128 | rtl_init_rxcfg(tp); |
| 5129 | rtl_set_tx_config_registers(tp); |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5130 | rtl_set_rx_mode(tp->dev); |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5131 | rtl_irq_enable(tp); |
| 5132 | } |
| 5133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5135 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5136 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5137 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5138 | if (new_mtu > ETH_DATA_LEN) |
| 5139 | rtl_hw_jumbo_enable(tp); |
| 5140 | else |
| 5141 | rtl_hw_jumbo_disable(tp); |
| 5142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5144 | netdev_update_features(dev); |
| 5145 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5146 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5150 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5151 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5153 | } |
| 5154 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5155 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | { |
| 5157 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5158 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5159 | /* Force memory writes to complete before releasing descriptor */ |
| 5160 | dma_wmb(); |
| 5161 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5162 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5165 | static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5166 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5167 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5168 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5169 | int node = dev_to_node(d); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5170 | dma_addr_t mapping; |
| 5171 | struct page *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5173 | data = alloc_pages_node(node, GFP_KERNEL, get_order(R8169_RX_BUF_SIZE)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5174 | if (!data) |
| 5175 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5176 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5177 | mapping = dma_map_page(d, data, 0, R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5178 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5179 | if (net_ratelimit()) |
| 5180 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5181 | __free_pages(data, get_order(R8169_RX_BUF_SIZE)); |
| 5182 | return NULL; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5185 | desc->addr = cpu_to_le64(mapping); |
| 5186 | rtl8169_mark_to_asic(desc); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5187 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5188 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5192 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5193 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | |
Heiner Kallweit | eb2e7f0 | 2019-08-09 22:59:07 +0200 | [diff] [blame] | 5195 | for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { |
| 5196 | dma_unmap_page(tp_to_dev(tp), |
| 5197 | le64_to_cpu(tp->RxDescArray[i].addr), |
| 5198 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
| 5199 | __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); |
| 5200 | tp->Rx_databuff[i] = NULL; |
| 5201 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5205 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5207 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5208 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5209 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5210 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5211 | { |
| 5212 | unsigned int i; |
| 5213 | |
| 5214 | for (i = 0; i < NUM_RX_DESC; i++) { |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5215 | struct page *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5216 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5217 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5218 | if (!data) { |
| 5219 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5220 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5221 | } |
| 5222 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5225 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5226 | return 0; |
| 5227 | |
| 5228 | err_out: |
| 5229 | rtl8169_rx_clear(tp); |
| 5230 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5233 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5235 | rtl8169_init_ring_indexes(tp); |
| 5236 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5237 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5238 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5240 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5243 | 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] | 5244 | struct TxDesc *desc) |
| 5245 | { |
| 5246 | unsigned int len = tx_skb->len; |
| 5247 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5248 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | desc->opts1 = 0x00; |
| 5251 | desc->opts2 = 0x00; |
| 5252 | desc->addr = 0x00; |
| 5253 | tx_skb->len = 0; |
| 5254 | } |
| 5255 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5256 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5257 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | { |
| 5259 | unsigned int i; |
| 5260 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5261 | for (i = 0; i < n; i++) { |
| 5262 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5264 | unsigned int len = tx_skb->len; |
| 5265 | |
| 5266 | if (len) { |
| 5267 | struct sk_buff *skb = tx_skb->skb; |
| 5268 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5269 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5270 | tp->TxDescArray + entry); |
| 5271 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5272 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5273 | tx_skb->skb = NULL; |
| 5274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5275 | } |
| 5276 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5280 | { |
| 5281 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5282 | tp->cur_tx = tp->dirty_tx = 0; |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5283 | netdev_reset_queue(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5286 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5288 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5289 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5291 | napi_disable(&tp->napi); |
| 5292 | netif_stop_queue(dev); |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 5293 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5295 | rtl8169_hw_reset(tp); |
| 5296 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5297 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5298 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5301 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5303 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5304 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5305 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5309 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5310 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5311 | |
| 5312 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | } |
| 5314 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5315 | static __le32 rtl8169_get_txd_opts1(u32 opts0, u32 len, unsigned int entry) |
| 5316 | { |
| 5317 | u32 status = opts0 | len; |
| 5318 | |
| 5319 | if (entry == NUM_TX_DESC - 1) |
| 5320 | status |= RingEnd; |
| 5321 | |
| 5322 | return cpu_to_le32(status); |
| 5323 | } |
| 5324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | 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] | 5326 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | { |
| 5328 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5329 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5330 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5331 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | |
| 5333 | entry = tp->cur_tx; |
| 5334 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5335 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5337 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | void *addr; |
| 5339 | |
| 5340 | entry = (entry + 1) % NUM_TX_DESC; |
| 5341 | |
| 5342 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5343 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5344 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5345 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5346 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5347 | if (net_ratelimit()) |
| 5348 | netif_err(tp, drv, tp->dev, |
| 5349 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5350 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5353 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5354 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5355 | txd->addr = cpu_to_le64(mapping); |
| 5356 | |
| 5357 | tp->tx_skb[entry].len = len; |
| 5358 | } |
| 5359 | |
| 5360 | if (cur_frag) { |
| 5361 | tp->tx_skb[entry].skb = skb; |
| 5362 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5363 | } |
| 5364 | |
| 5365 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5366 | |
| 5367 | err_out: |
| 5368 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5369 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5372 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5373 | { |
| 5374 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5375 | } |
| 5376 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5377 | /* msdn_giant_send_check() |
| 5378 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5379 | * packet length for IPv6 TCP large packets. |
| 5380 | */ |
| 5381 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 5382 | { |
| 5383 | const struct ipv6hdr *ipv6h; |
| 5384 | struct tcphdr *th; |
| 5385 | int ret; |
| 5386 | |
| 5387 | ret = skb_cow_head(skb, 0); |
| 5388 | if (ret) |
| 5389 | return ret; |
| 5390 | |
| 5391 | ipv6h = ipv6_hdr(skb); |
| 5392 | th = tcp_hdr(skb); |
| 5393 | |
| 5394 | th->check = 0; |
| 5395 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 5396 | |
| 5397 | return ret; |
| 5398 | } |
| 5399 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5400 | static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5402 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5403 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5404 | if (mss) { |
| 5405 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5406 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 5407 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5408 | const struct iphdr *ip = ip_hdr(skb); |
| 5409 | |
| 5410 | if (ip->protocol == IPPROTO_TCP) |
| 5411 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 5412 | else if (ip->protocol == IPPROTO_UDP) |
| 5413 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 5414 | else |
| 5415 | WARN_ON_ONCE(1); |
| 5416 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 5420 | struct sk_buff *skb, u32 *opts) |
| 5421 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5422 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5423 | u32 mss = skb_shinfo(skb)->gso_size; |
| 5424 | |
| 5425 | if (mss) { |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5426 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5427 | case htons(ETH_P_IP): |
| 5428 | opts[0] |= TD1_GTSENV4; |
| 5429 | break; |
| 5430 | |
| 5431 | case htons(ETH_P_IPV6): |
| 5432 | if (msdn_giant_send_check(skb)) |
| 5433 | return false; |
| 5434 | |
| 5435 | opts[0] |= TD1_GTSENV6; |
| 5436 | break; |
| 5437 | |
| 5438 | default: |
| 5439 | WARN_ON_ONCE(1); |
| 5440 | break; |
| 5441 | } |
| 5442 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5443 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5444 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5445 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5446 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5448 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5449 | case htons(ETH_P_IP): |
| 5450 | opts[1] |= TD1_IPv4_CS; |
| 5451 | ip_protocol = ip_hdr(skb)->protocol; |
| 5452 | break; |
| 5453 | |
| 5454 | case htons(ETH_P_IPV6): |
| 5455 | opts[1] |= TD1_IPv6_CS; |
| 5456 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 5457 | break; |
| 5458 | |
| 5459 | default: |
| 5460 | ip_protocol = IPPROTO_RAW; |
| 5461 | break; |
| 5462 | } |
| 5463 | |
| 5464 | if (ip_protocol == IPPROTO_TCP) |
| 5465 | opts[1] |= TD1_TCP_CS; |
| 5466 | else if (ip_protocol == IPPROTO_UDP) |
| 5467 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5468 | else |
| 5469 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5470 | |
| 5471 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5472 | } else { |
| 5473 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 5474 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5476 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5477 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5478 | } |
| 5479 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5480 | static bool rtl_tx_slots_avail(struct rtl8169_private *tp, |
| 5481 | unsigned int nr_frags) |
| 5482 | { |
| 5483 | unsigned int slots_avail = tp->dirty_tx + NUM_TX_DESC - tp->cur_tx; |
| 5484 | |
| 5485 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 5486 | return slots_avail > nr_frags; |
| 5487 | } |
| 5488 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5489 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 5490 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 5491 | { |
| 5492 | switch (tp->mac_version) { |
| 5493 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
| 5494 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 5495 | return false; |
| 5496 | default: |
| 5497 | return true; |
| 5498 | } |
| 5499 | } |
| 5500 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5501 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5502 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | { |
| 5504 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5505 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5507 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5509 | u32 opts[2], len; |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5510 | bool stop_queue; |
| 5511 | bool door_bell; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5512 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5513 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5514 | if (unlikely(!rtl_tx_slots_avail(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5515 | 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] | 5516 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5520 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | |
Heiner Kallweit | 355f948 | 2019-06-06 07:49:17 +0200 | [diff] [blame] | 5522 | opts[1] = rtl8169_tx_vlan_tag(skb); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5523 | opts[0] = DescOwn; |
| 5524 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5525 | if (rtl_chip_supports_csum_v2(tp)) { |
Heiner Kallweit | 96ea772 | 2019-07-26 21:50:34 +0200 | [diff] [blame] | 5526 | if (!rtl8169_tso_csum_v2(tp, skb, opts)) |
| 5527 | goto err_dma_0; |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5528 | } else { |
| 5529 | rtl8169_tso_csum_v1(skb, opts); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5530 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5531 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5532 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5533 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5534 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5535 | if (net_ratelimit()) |
| 5536 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5537 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | |
| 5540 | tp->tx_skb[entry].len = len; |
| 5541 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5543 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5544 | if (frags < 0) |
| 5545 | goto err_dma_1; |
| 5546 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5547 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5548 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5549 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5550 | tp->tx_skb[entry].skb = skb; |
| 5551 | } |
| 5552 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5553 | txd->opts2 = cpu_to_le32(opts[1]); |
| 5554 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 5555 | skb_tx_timestamp(skb); |
| 5556 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5557 | /* Force memory writes to complete before releasing descriptor */ |
| 5558 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5560 | door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more()); |
| 5561 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5562 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5564 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5565 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5567 | tp->cur_tx += frags + 1; |
| 5568 | |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5569 | stop_queue = !rtl_tx_slots_avail(tp, MAX_SKB_FRAGS); |
| 5570 | if (unlikely(stop_queue)) { |
Heiner Kallweit | 0255d59 | 2019-02-10 15:28:04 +0100 | [diff] [blame] | 5571 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 5572 | * not miss a ring update when it notices a stopped queue. |
| 5573 | */ |
| 5574 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | netif_stop_queue(dev); |
Heiner Kallweit | 4773f9b | 2019-08-12 20:47:40 +0200 | [diff] [blame] | 5576 | door_bell = true; |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | if (door_bell) |
| 5580 | RTL_W8(tp, TxPoll, NPQ); |
| 5581 | |
| 5582 | if (unlikely(stop_queue)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5583 | /* Sync with rtl_tx: |
| 5584 | * - publish queue status and cur_tx ring index (write barrier) |
| 5585 | * - refresh dirty_tx ring index (read barrier). |
| 5586 | * May the current thread have a pessimistic view of the ring |
| 5587 | * status and forget to wake up queue, a racing rtl_tx thread |
| 5588 | * can't. |
| 5589 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5590 | smp_mb(); |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5591 | if (rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) |
Heiner Kallweit | 601ed4d | 2019-03-21 21:41:48 +0100 | [diff] [blame] | 5592 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5595 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5597 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5598 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5599 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 5600 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5601 | dev->stats.tx_dropped++; |
| 5602 | return NETDEV_TX_OK; |
| 5603 | |
| 5604 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5606 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5607 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 5610 | static netdev_features_t rtl8169_features_check(struct sk_buff *skb, |
| 5611 | struct net_device *dev, |
| 5612 | netdev_features_t features) |
| 5613 | { |
| 5614 | int transport_offset = skb_transport_offset(skb); |
| 5615 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5616 | |
| 5617 | if (skb_is_gso(skb)) { |
| 5618 | if (transport_offset > GTTCPHO_MAX && |
| 5619 | rtl_chip_supports_csum_v2(tp)) |
| 5620 | features &= ~NETIF_F_ALL_TSO; |
| 5621 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5622 | if (skb->len < ETH_ZLEN) { |
| 5623 | switch (tp->mac_version) { |
| 5624 | case RTL_GIGA_MAC_VER_11: |
| 5625 | case RTL_GIGA_MAC_VER_12: |
| 5626 | case RTL_GIGA_MAC_VER_17: |
| 5627 | case RTL_GIGA_MAC_VER_34: |
| 5628 | features &= ~NETIF_F_CSUM_MASK; |
| 5629 | break; |
| 5630 | default: |
| 5631 | break; |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | if (transport_offset > TCPHO_MAX && |
| 5636 | rtl_chip_supports_csum_v2(tp)) |
| 5637 | features &= ~NETIF_F_CSUM_MASK; |
| 5638 | } |
| 5639 | |
| 5640 | return vlan_features_check(skb, features); |
| 5641 | } |
| 5642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 5644 | { |
| 5645 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5646 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | u16 pci_status, pci_cmd; |
| 5648 | |
| 5649 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 5650 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 5651 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5652 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 5653 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | |
| 5655 | /* |
| 5656 | * The recovery sequence below admits a very elaborated explanation: |
| 5657 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5658 | * - I did not see what else could be done; |
| 5659 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5660 | * |
| 5661 | * Feel free to adjust to your needs. |
| 5662 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 5663 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5664 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 5665 | else |
| 5666 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 5667 | |
| 5668 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | |
| 5670 | pci_write_config_word(pdev, PCI_STATUS, |
| 5671 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 5672 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 5673 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 5674 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 5675 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5678 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, |
| 5679 | int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5681 | unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | dirty_tx = tp->dirty_tx; |
| 5684 | smp_rmb(); |
| 5685 | tx_left = tp->cur_tx - dirty_tx; |
| 5686 | |
| 5687 | while (tx_left > 0) { |
| 5688 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 5689 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | u32 status; |
| 5691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 5693 | if (status & DescOwn) |
| 5694 | break; |
| 5695 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5696 | /* This barrier is needed to keep us from reading |
| 5697 | * any other fields out of the Tx descriptor until |
| 5698 | * we know the status of DescOwn |
| 5699 | */ |
| 5700 | dma_rmb(); |
| 5701 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5702 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5703 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | if (status & LastFrag) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5705 | pkts_compl++; |
| 5706 | bytes_compl += tx_skb->skb->len; |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5707 | napi_consume_skb(tx_skb->skb, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | tx_skb->skb = NULL; |
| 5709 | } |
| 5710 | dirty_tx++; |
| 5711 | tx_left--; |
| 5712 | } |
| 5713 | |
| 5714 | if (tp->dirty_tx != dirty_tx) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5715 | netdev_completed_queue(dev, pkts_compl, bytes_compl); |
| 5716 | |
| 5717 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 5718 | tp->tx_stats.packets += pkts_compl; |
| 5719 | tp->tx_stats.bytes += bytes_compl; |
| 5720 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 5721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5723 | /* Sync with rtl8169_start_xmit: |
| 5724 | * - publish dirty_tx ring index (write barrier) |
| 5725 | * - refresh cur_tx ring index and queue status (read barrier) |
| 5726 | * May the current thread miss the stopped queue condition, |
| 5727 | * a racing xmit thread can only have a right view of the |
| 5728 | * ring status. |
| 5729 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5730 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | if (netif_queue_stopped(dev) && |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5732 | rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | netif_wake_queue(dev); |
| 5734 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5735 | /* |
| 5736 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 5737 | * too close. Let's kick an extra TxPoll request when a burst |
| 5738 | * of start_xmit activity is detected (if it is not detected, |
| 5739 | * it is slow enough). -- FR |
| 5740 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5741 | if (tp->cur_tx != dirty_tx) |
| 5742 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5743 | } |
| 5744 | } |
| 5745 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5746 | static inline int rtl8169_fragmented_frame(u32 status) |
| 5747 | { |
| 5748 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 5749 | } |
| 5750 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5751 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | u32 status = opts1 & RxProtoMask; |
| 5754 | |
| 5755 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 5756 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5758 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5759 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5762 | 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] | 5763 | { |
| 5764 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5765 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5768 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 5769 | 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] | 5770 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5771 | const void *rx_buf = page_address(tp->Rx_databuff[entry]); |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5772 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5773 | u32 status; |
| 5774 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 5775 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | if (status & DescOwn) |
| 5777 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5778 | |
| 5779 | /* This barrier is needed to keep us from reading |
| 5780 | * any other fields out of the Rx descriptor until |
| 5781 | * we know the status of DescOwn |
| 5782 | */ |
| 5783 | dma_rmb(); |
| 5784 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5785 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5786 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 5787 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5788 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5790 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5792 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 5793 | if (status & (RxRUNT | RxCRC) && !(status & RxRWT) && |
| 5794 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 5795 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 5796 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | } else { |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5798 | unsigned int pkt_size; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5799 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 5800 | |
| 5801 | process_pkt: |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5802 | pkt_size = status & GENMASK(13, 0); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 5803 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5804 | pkt_size -= ETH_FCS_LEN; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5805 | /* |
| 5806 | * The driver does not support incoming fragmented |
| 5807 | * frames. They are seen as a symptom of over-mtu |
| 5808 | * sized frames. |
| 5809 | */ |
| 5810 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5811 | dev->stats.rx_dropped++; |
| 5812 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5813 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5814 | } |
| 5815 | |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5816 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
| 5817 | if (unlikely(!skb)) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5818 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5819 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
Heiner Kallweit | 3c95e50 | 2019-08-26 22:52:36 +0200 | [diff] [blame] | 5822 | dma_sync_single_for_cpu(tp_to_dev(tp), |
| 5823 | le64_to_cpu(desc->addr), |
| 5824 | pkt_size, DMA_FROM_DEVICE); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5825 | prefetch(rx_buf); |
| 5826 | skb_copy_to_linear_data(skb, rx_buf, pkt_size); |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5827 | skb->tail += pkt_size; |
| 5828 | skb->len = pkt_size; |
| 5829 | |
Heiner Kallweit | d4ed746 | 2019-08-23 20:07:26 +0200 | [diff] [blame] | 5830 | dma_sync_single_for_device(tp_to_dev(tp), |
| 5831 | le64_to_cpu(desc->addr), |
| 5832 | pkt_size, DMA_FROM_DEVICE); |
| 5833 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5834 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | skb->protocol = eth_type_trans(skb, dev); |
| 5836 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 5837 | rtl8169_rx_vlan_tag(desc, skb); |
| 5838 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 5839 | if (skb->pkt_type == PACKET_MULTICAST) |
| 5840 | dev->stats.multicast++; |
| 5841 | |
Heiner Kallweit | 448a241 | 2019-04-03 19:54:12 +0200 | [diff] [blame] | 5842 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5843 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 5844 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 5845 | tp->rx_stats.packets++; |
| 5846 | tp->rx_stats.bytes += pkt_size; |
| 5847 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5848 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5849 | release_descriptor: |
| 5850 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5851 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | count = cur_rx - tp->cur_rx; |
| 5855 | tp->cur_rx = cur_rx; |
| 5856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | return count; |
| 5858 | } |
| 5859 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5860 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5861 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 5862 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame] | 5863 | u32 status = rtl_get_events(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame] | 5865 | if (!tp->irq_enabled || (status & 0xffff) == 0xffff || |
| 5866 | !(status & tp->irq_mask)) |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 5867 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5868 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5869 | if (unlikely(status & SYSErr)) { |
| 5870 | rtl8169_pcierr_interrupt(tp->dev); |
| 5871 | goto out; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5874 | if (status & LinkChg) |
| 5875 | phy_mac_interrupt(tp->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5876 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5877 | if (unlikely(status & RxFIFOOver && |
| 5878 | tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
| 5879 | netif_stop_queue(tp->dev); |
| 5880 | /* XXX - Hack alert. See rtl_task(). */ |
| 5881 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
| 5882 | } |
| 5883 | |
Heiner Kallweit | e62b2fd | 2019-04-14 11:48:39 +0200 | [diff] [blame] | 5884 | rtl_irq_disable(tp); |
| 5885 | napi_schedule_irqoff(&tp->napi); |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5886 | out: |
| 5887 | rtl_ack_events(tp, status); |
| 5888 | |
| 5889 | return IRQ_HANDLED; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5890 | } |
| 5891 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5892 | static void rtl_task(struct work_struct *work) |
| 5893 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5894 | static const struct { |
| 5895 | int bitnr; |
| 5896 | void (*action)(struct rtl8169_private *); |
| 5897 | } rtl_work[] = { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5898 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5899 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5900 | struct rtl8169_private *tp = |
| 5901 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5902 | struct net_device *dev = tp->dev; |
| 5903 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5904 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5905 | rtl_lock_work(tp); |
| 5906 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 5907 | if (!netif_running(dev) || |
| 5908 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5909 | goto out_unlock; |
| 5910 | |
| 5911 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 5912 | bool pending; |
| 5913 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5914 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5915 | if (pending) |
| 5916 | rtl_work[i].action(tp); |
| 5917 | } |
| 5918 | |
| 5919 | out_unlock: |
| 5920 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5921 | } |
| 5922 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5923 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5925 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 5926 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 5927 | int work_done; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5928 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 5929 | work_done = rtl_rx(dev, tp, (u32) budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5930 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5931 | rtl_tx(dev, tp, budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5932 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5933 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 5934 | napi_complete_done(napi, work_done); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 5935 | rtl_irq_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | } |
| 5937 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5938 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5941 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5942 | { |
| 5943 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5944 | |
| 5945 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 5946 | return; |
| 5947 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5948 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 5949 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5950 | } |
| 5951 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5952 | static void r8169_phylink_handler(struct net_device *ndev) |
| 5953 | { |
| 5954 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 5955 | |
| 5956 | if (netif_carrier_ok(ndev)) { |
| 5957 | rtl_link_chg_patch(tp); |
| 5958 | pm_request_resume(&tp->pci_dev->dev); |
| 5959 | } else { |
| 5960 | pm_runtime_idle(&tp->pci_dev->dev); |
| 5961 | } |
| 5962 | |
| 5963 | if (net_ratelimit()) |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5964 | phy_print_status(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 5968 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5969 | struct phy_device *phydev = tp->phydev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5970 | phy_interface_t phy_mode; |
| 5971 | int ret; |
| 5972 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 5973 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5974 | PHY_INTERFACE_MODE_MII; |
| 5975 | |
| 5976 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 5977 | phy_mode); |
| 5978 | if (ret) |
| 5979 | return ret; |
| 5980 | |
Heiner Kallweit | 66058b1 | 2019-07-27 12:32:28 +0200 | [diff] [blame] | 5981 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5982 | phy_set_max_speed(phydev, SPEED_100); |
| 5983 | |
Heiner Kallweit | 9cf9b84 | 2019-05-04 12:01:03 +0200 | [diff] [blame] | 5984 | phy_support_asym_pause(phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5985 | |
| 5986 | phy_attached_info(phydev); |
| 5987 | |
| 5988 | return 0; |
| 5989 | } |
| 5990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5991 | static void rtl8169_down(struct net_device *dev) |
| 5992 | { |
| 5993 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5995 | phy_stop(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5996 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5997 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5998 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5999 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6000 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6001 | /* |
| 6002 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6003 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6004 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6005 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6006 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 6009 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | rtl8169_tx_clear(tp); |
| 6012 | |
| 6013 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6014 | |
| 6015 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | static int rtl8169_close(struct net_device *dev) |
| 6019 | { |
| 6020 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6021 | struct pci_dev *pdev = tp->pci_dev; |
| 6022 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6023 | pm_runtime_get_sync(&pdev->dev); |
| 6024 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6025 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6026 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6027 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6028 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6029 | /* Clear all task flags */ |
| 6030 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6032 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6033 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6034 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6035 | cancel_work_sync(&tp->wk.work); |
| 6036 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6037 | phy_disconnect(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6038 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6039 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6040 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6041 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6042 | tp->RxPhyAddr); |
| 6043 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6044 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6045 | tp->TxDescArray = NULL; |
| 6046 | tp->RxDescArray = NULL; |
| 6047 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6048 | pm_runtime_put_sync(&pdev->dev); |
| 6049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6050 | return 0; |
| 6051 | } |
| 6052 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6053 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6054 | static void rtl8169_netpoll(struct net_device *dev) |
| 6055 | { |
| 6056 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6057 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6058 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6059 | } |
| 6060 | #endif |
| 6061 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6062 | static int rtl_open(struct net_device *dev) |
| 6063 | { |
| 6064 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6065 | struct pci_dev *pdev = tp->pci_dev; |
| 6066 | int retval = -ENOMEM; |
| 6067 | |
| 6068 | pm_runtime_get_sync(&pdev->dev); |
| 6069 | |
| 6070 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6071 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6072 | * dma_alloc_coherent provides more. |
| 6073 | */ |
| 6074 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6075 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6076 | if (!tp->TxDescArray) |
| 6077 | goto err_pm_runtime_put; |
| 6078 | |
| 6079 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6080 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6081 | if (!tp->RxDescArray) |
| 6082 | goto err_free_tx_0; |
| 6083 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6084 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6085 | if (retval < 0) |
| 6086 | goto err_free_rx_1; |
| 6087 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6088 | rtl_request_firmware(tp); |
| 6089 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6090 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6091 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6092 | if (retval < 0) |
| 6093 | goto err_release_fw_2; |
| 6094 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6095 | retval = r8169_phy_connect(tp); |
| 6096 | if (retval) |
| 6097 | goto err_free_irq; |
| 6098 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6099 | rtl_lock_work(tp); |
| 6100 | |
| 6101 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6102 | |
| 6103 | napi_enable(&tp->napi); |
| 6104 | |
| 6105 | rtl8169_init_phy(dev, tp); |
| 6106 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6107 | rtl_pll_power_up(tp); |
| 6108 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6109 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6110 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6111 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6112 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6113 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6114 | phy_start(tp->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6115 | netif_start_queue(dev); |
| 6116 | |
| 6117 | rtl_unlock_work(tp); |
| 6118 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6119 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6120 | out: |
| 6121 | return retval; |
| 6122 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6123 | err_free_irq: |
| 6124 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6125 | err_release_fw_2: |
| 6126 | rtl_release_firmware(tp); |
| 6127 | rtl8169_rx_clear(tp); |
| 6128 | err_free_rx_1: |
| 6129 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6130 | tp->RxPhyAddr); |
| 6131 | tp->RxDescArray = NULL; |
| 6132 | err_free_tx_0: |
| 6133 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6134 | tp->TxPhyAddr); |
| 6135 | tp->TxDescArray = NULL; |
| 6136 | err_pm_runtime_put: |
| 6137 | pm_runtime_put_noidle(&pdev->dev); |
| 6138 | goto out; |
| 6139 | } |
| 6140 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6141 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6142 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6143 | { |
| 6144 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6145 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6146 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6147 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6149 | pm_runtime_get_noresume(&pdev->dev); |
| 6150 | |
| 6151 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6152 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6153 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6154 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6155 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6156 | stats->rx_packets = tp->rx_stats.packets; |
| 6157 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6158 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6159 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6160 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6161 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6162 | stats->tx_packets = tp->tx_stats.packets; |
| 6163 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6164 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6165 | |
| 6166 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6167 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6168 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6169 | stats->rx_errors = dev->stats.rx_errors; |
| 6170 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6171 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6172 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6173 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6174 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6175 | /* |
Corentin Musard | ed72a9b | 2019-07-24 14:34:43 +0200 | [diff] [blame] | 6176 | * Fetch additional counter values missing in stats collected by driver |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6177 | * from tally counters. |
| 6178 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6179 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6180 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6181 | |
| 6182 | /* |
| 6183 | * Subtract values fetched during initalization. |
| 6184 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6185 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6186 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6187 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6188 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6189 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6190 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6191 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6192 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6193 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | } |
| 6195 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6196 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6197 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6198 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6199 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6200 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6201 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6202 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6203 | phy_stop(tp->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6204 | netif_device_detach(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6205 | |
| 6206 | rtl_lock_work(tp); |
| 6207 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6208 | /* Clear all task flags */ |
| 6209 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6210 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6211 | rtl_unlock_work(tp); |
| 6212 | |
| 6213 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6214 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6215 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6216 | #ifdef CONFIG_PM |
| 6217 | |
| 6218 | static int rtl8169_suspend(struct device *device) |
| 6219 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6220 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6221 | struct rtl8169_private *tp = netdev_priv(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6222 | |
| 6223 | rtl8169_net_suspend(dev); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6224 | clk_disable_unprepare(tp->clk); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6225 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6226 | return 0; |
| 6227 | } |
| 6228 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6229 | static void __rtl8169_resume(struct net_device *dev) |
| 6230 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6231 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6232 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6233 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6234 | |
| 6235 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6236 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6237 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6238 | phy_start(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6239 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6240 | rtl_lock_work(tp); |
| 6241 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6242 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Heiner Kallweit | 58ba566 | 2019-01-19 22:06:25 +0100 | [diff] [blame] | 6243 | rtl_reset_work(tp); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6244 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6247 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6248 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6249 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6250 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6251 | |
Heiner Kallweit | 5971517 | 2019-05-29 07:44:01 +0200 | [diff] [blame] | 6252 | rtl_rar_set(tp, dev->dev_addr); |
| 6253 | |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6254 | clk_prepare_enable(tp->clk); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6255 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6256 | if (netif_running(dev)) |
| 6257 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6258 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6259 | return 0; |
| 6260 | } |
| 6261 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6262 | static int rtl8169_runtime_suspend(struct device *device) |
| 6263 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6264 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6265 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6266 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6267 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6268 | return 0; |
| 6269 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6270 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6271 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6272 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6273 | |
| 6274 | rtl8169_net_suspend(dev); |
| 6275 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6276 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6277 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6278 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6279 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6280 | return 0; |
| 6281 | } |
| 6282 | |
| 6283 | static int rtl8169_runtime_resume(struct device *device) |
| 6284 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6285 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6286 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 5971517 | 2019-05-29 07:44:01 +0200 | [diff] [blame] | 6287 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6288 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6289 | |
| 6290 | if (!tp->TxDescArray) |
| 6291 | return 0; |
| 6292 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6293 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6294 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6295 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6296 | |
| 6297 | __rtl8169_resume(dev); |
| 6298 | |
| 6299 | return 0; |
| 6300 | } |
| 6301 | |
| 6302 | static int rtl8169_runtime_idle(struct device *device) |
| 6303 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6304 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6305 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6306 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6307 | pm_schedule_suspend(device, 10000); |
| 6308 | |
| 6309 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6312 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6313 | .suspend = rtl8169_suspend, |
| 6314 | .resume = rtl8169_resume, |
| 6315 | .freeze = rtl8169_suspend, |
| 6316 | .thaw = rtl8169_resume, |
| 6317 | .poweroff = rtl8169_suspend, |
| 6318 | .restore = rtl8169_resume, |
| 6319 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6320 | .runtime_resume = rtl8169_runtime_resume, |
| 6321 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6322 | }; |
| 6323 | |
| 6324 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6325 | |
| 6326 | #else /* !CONFIG_PM */ |
| 6327 | |
| 6328 | #define RTL8169_PM_OPS NULL |
| 6329 | |
| 6330 | #endif /* !CONFIG_PM */ |
| 6331 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6332 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6333 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6334 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6335 | switch (tp->mac_version) { |
| 6336 | case RTL_GIGA_MAC_VER_11: |
| 6337 | case RTL_GIGA_MAC_VER_12: |
| 6338 | case RTL_GIGA_MAC_VER_17: |
| 6339 | pci_clear_master(tp->pci_dev); |
| 6340 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6341 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6342 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6343 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6344 | break; |
| 6345 | default: |
| 6346 | break; |
| 6347 | } |
| 6348 | } |
| 6349 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6350 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6351 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6352 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6353 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6354 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6355 | rtl8169_net_suspend(dev); |
| 6356 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6357 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6358 | rtl_rar_set(tp, dev->perm_addr); |
| 6359 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6360 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6361 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6362 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6363 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6364 | rtl_wol_suspend_quirk(tp); |
| 6365 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6368 | pci_wake_from_d3(pdev, true); |
| 6369 | pci_set_power_state(pdev, PCI_D3hot); |
| 6370 | } |
| 6371 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6372 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6373 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6374 | { |
| 6375 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6376 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6377 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6378 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6379 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6380 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6381 | netif_napi_del(&tp->napi); |
| 6382 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6383 | unregister_netdev(dev); |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6384 | mdiobus_unregister(tp->phydev->mdio.bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6385 | |
| 6386 | rtl_release_firmware(tp); |
| 6387 | |
| 6388 | if (pci_dev_run_wake(pdev)) |
| 6389 | pm_runtime_get_noresume(&pdev->dev); |
| 6390 | |
| 6391 | /* restore original MAC address */ |
| 6392 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6393 | } |
| 6394 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6395 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6396 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6397 | .ndo_stop = rtl8169_close, |
| 6398 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6399 | .ndo_start_xmit = rtl8169_start_xmit, |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 6400 | .ndo_features_check = rtl8169_features_check, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6401 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 6402 | .ndo_validate_addr = eth_validate_addr, |
| 6403 | .ndo_change_mtu = rtl8169_change_mtu, |
| 6404 | .ndo_fix_features = rtl8169_fix_features, |
| 6405 | .ndo_set_features = rtl8169_set_features, |
| 6406 | .ndo_set_mac_address = rtl_set_mac_address, |
| 6407 | .ndo_do_ioctl = rtl8169_ioctl, |
| 6408 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 6409 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6410 | .ndo_poll_controller = rtl8169_netpoll, |
| 6411 | #endif |
| 6412 | |
| 6413 | }; |
| 6414 | |
Heiner Kallweit | ec9a408 | 2019-06-10 18:21:50 +0200 | [diff] [blame] | 6415 | static void rtl_set_irq_mask(struct rtl8169_private *tp) |
| 6416 | { |
| 6417 | tp->irq_mask = RTL_EVENT_NAPI | LinkChg; |
| 6418 | |
| 6419 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 6420 | tp->irq_mask |= SYSErr | RxOverflow | RxFIFOOver; |
| 6421 | else if (tp->mac_version == RTL_GIGA_MAC_VER_11) |
| 6422 | /* special workaround needed */ |
| 6423 | tp->irq_mask |= RxFIFOOver; |
| 6424 | else |
| 6425 | tp->irq_mask |= RxOverflow; |
| 6426 | } |
| 6427 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6428 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6429 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6430 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6431 | |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6432 | switch (tp->mac_version) { |
| 6433 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6434 | rtl_unlock_config_regs(tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6435 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6436 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6437 | /* fall through */ |
| 6438 | case RTL_GIGA_MAC_VER_07 ... RTL_GIGA_MAC_VER_24: |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6439 | flags = PCI_IRQ_LEGACY; |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6440 | break; |
| 6441 | default: |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6442 | flags = PCI_IRQ_ALL_TYPES; |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6443 | break; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6444 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6445 | |
| 6446 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6447 | } |
| 6448 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6449 | static void rtl_read_mac_address(struct rtl8169_private *tp, |
| 6450 | u8 mac_addr[ETH_ALEN]) |
| 6451 | { |
| 6452 | /* Get MAC address */ |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 6453 | if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) { |
| 6454 | u32 value = rtl_eri_read(tp, 0xe0); |
| 6455 | |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6456 | mac_addr[0] = (value >> 0) & 0xff; |
| 6457 | mac_addr[1] = (value >> 8) & 0xff; |
| 6458 | mac_addr[2] = (value >> 16) & 0xff; |
| 6459 | mac_addr[3] = (value >> 24) & 0xff; |
| 6460 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 6461 | value = rtl_eri_read(tp, 0xe4); |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6462 | mac_addr[4] = (value >> 0) & 0xff; |
| 6463 | mac_addr[5] = (value >> 8) & 0xff; |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6464 | } |
| 6465 | } |
| 6466 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6467 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 6468 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6469 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 6473 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6474 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6475 | } |
| 6476 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6477 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 6478 | { |
| 6479 | struct rtl8169_private *tp = mii_bus->priv; |
| 6480 | |
| 6481 | if (phyaddr > 0) |
| 6482 | return -ENODEV; |
| 6483 | |
| 6484 | return rtl_readphy(tp, phyreg); |
| 6485 | } |
| 6486 | |
| 6487 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 6488 | int phyreg, u16 val) |
| 6489 | { |
| 6490 | struct rtl8169_private *tp = mii_bus->priv; |
| 6491 | |
| 6492 | if (phyaddr > 0) |
| 6493 | return -ENODEV; |
| 6494 | |
| 6495 | rtl_writephy(tp, phyreg, val); |
| 6496 | |
| 6497 | return 0; |
| 6498 | } |
| 6499 | |
| 6500 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 6501 | { |
| 6502 | struct pci_dev *pdev = tp->pci_dev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6503 | struct mii_bus *new_bus; |
| 6504 | int ret; |
| 6505 | |
| 6506 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 6507 | if (!new_bus) |
| 6508 | return -ENOMEM; |
| 6509 | |
| 6510 | new_bus->name = "r8169"; |
| 6511 | new_bus->priv = tp; |
| 6512 | new_bus->parent = &pdev->dev; |
| 6513 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
Heiner Kallweit | a195016 | 2019-04-24 21:13:25 +0200 | [diff] [blame] | 6514 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x", pci_dev_id(pdev)); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6515 | |
| 6516 | new_bus->read = r8169_mdio_read_reg; |
| 6517 | new_bus->write = r8169_mdio_write_reg; |
| 6518 | |
| 6519 | ret = mdiobus_register(new_bus); |
| 6520 | if (ret) |
| 6521 | return ret; |
| 6522 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6523 | tp->phydev = mdiobus_get_phy(new_bus, 0); |
| 6524 | if (!tp->phydev) { |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6525 | mdiobus_unregister(new_bus); |
| 6526 | return -ENODEV; |
| 6527 | } |
| 6528 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 6529 | /* PHY will be woken up in rtl_open() */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6530 | phy_suspend(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6531 | |
| 6532 | return 0; |
| 6533 | } |
| 6534 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6535 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6536 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6537 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 6538 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6539 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6540 | |
| 6541 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 6542 | return; |
| 6543 | |
| 6544 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 6545 | return; |
| 6546 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6547 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6548 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6549 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6550 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 6551 | r8168_mac_ocp_modify(tp, 0xe8de, BIT(14), 0); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6552 | |
| 6553 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 6554 | return; |
| 6555 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 6556 | r8168_mac_ocp_modify(tp, 0xe8de, 0, BIT(15)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6557 | |
Heiner Kallweit | 7160be2 | 2019-05-25 20:44:01 +0200 | [diff] [blame] | 6558 | rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6559 | } |
| 6560 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6561 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6562 | { |
| 6563 | switch (tp->mac_version) { |
Heiner Kallweit | 29ec048 | 2019-05-25 20:43:25 +0200 | [diff] [blame] | 6564 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
| 6565 | rtl8168ep_stop_cmac(tp); |
| 6566 | /* fall through */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 6567 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 6568 | rtl_hw_init_8168g(tp); |
| 6569 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6570 | default: |
| 6571 | break; |
| 6572 | } |
| 6573 | } |
| 6574 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6575 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 6576 | { |
| 6577 | /* Non-GBit versions don't support jumbo frames */ |
| 6578 | if (!tp->supports_gmii) |
| 6579 | return JUMBO_1K; |
| 6580 | |
| 6581 | switch (tp->mac_version) { |
| 6582 | /* RTL8169 */ |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 6583 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6584 | return JUMBO_7K; |
| 6585 | /* RTL8168b */ |
| 6586 | case RTL_GIGA_MAC_VER_11: |
| 6587 | case RTL_GIGA_MAC_VER_12: |
| 6588 | case RTL_GIGA_MAC_VER_17: |
| 6589 | return JUMBO_4K; |
| 6590 | /* RTL8168c */ |
| 6591 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 6592 | return JUMBO_6K; |
| 6593 | default: |
| 6594 | return JUMBO_9K; |
| 6595 | } |
| 6596 | } |
| 6597 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6598 | static void rtl_disable_clk(void *data) |
| 6599 | { |
| 6600 | clk_disable_unprepare(data); |
| 6601 | } |
| 6602 | |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 6603 | static int rtl_get_ether_clk(struct rtl8169_private *tp) |
| 6604 | { |
| 6605 | struct device *d = tp_to_dev(tp); |
| 6606 | struct clk *clk; |
| 6607 | int rc; |
| 6608 | |
| 6609 | clk = devm_clk_get(d, "ether_clk"); |
| 6610 | if (IS_ERR(clk)) { |
| 6611 | rc = PTR_ERR(clk); |
| 6612 | if (rc == -ENOENT) |
| 6613 | /* clk-core allows NULL (for suspend / resume) */ |
| 6614 | rc = 0; |
| 6615 | else if (rc != -EPROBE_DEFER) |
| 6616 | dev_err(d, "failed to get clk: %d\n", rc); |
| 6617 | } else { |
| 6618 | tp->clk = clk; |
| 6619 | rc = clk_prepare_enable(clk); |
| 6620 | if (rc) |
| 6621 | dev_err(d, "failed to enable clk: %d\n", rc); |
| 6622 | else |
| 6623 | rc = devm_add_action_or_reset(d, rtl_disable_clk, clk); |
| 6624 | } |
| 6625 | |
| 6626 | return rc; |
| 6627 | } |
| 6628 | |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6629 | static void rtl_init_mac_address(struct rtl8169_private *tp) |
| 6630 | { |
| 6631 | struct net_device *dev = tp->dev; |
| 6632 | u8 *mac_addr = dev->dev_addr; |
| 6633 | int rc, i; |
| 6634 | |
| 6635 | rc = eth_platform_get_mac_address(tp_to_dev(tp), mac_addr); |
| 6636 | if (!rc) |
| 6637 | goto done; |
| 6638 | |
| 6639 | rtl_read_mac_address(tp, mac_addr); |
| 6640 | if (is_valid_ether_addr(mac_addr)) |
| 6641 | goto done; |
| 6642 | |
| 6643 | for (i = 0; i < ETH_ALEN; i++) |
| 6644 | mac_addr[i] = RTL_R8(tp, MAC0 + i); |
| 6645 | if (is_valid_ether_addr(mac_addr)) |
| 6646 | goto done; |
| 6647 | |
| 6648 | eth_hw_addr_random(dev); |
| 6649 | dev_warn(tp_to_dev(tp), "can't read MAC address, setting random one\n"); |
| 6650 | done: |
| 6651 | rtl_rar_set(tp, mac_addr); |
| 6652 | } |
| 6653 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6654 | 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] | 6655 | { |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6656 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6657 | struct net_device *dev; |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6658 | int chipset, region; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6659 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6660 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6661 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 6662 | if (!dev) |
| 6663 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6664 | |
| 6665 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6666 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6667 | tp = netdev_priv(dev); |
| 6668 | tp->dev = dev; |
| 6669 | tp->pci_dev = pdev; |
| 6670 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | 145a40e | 2019-06-10 18:25:29 +0200 | [diff] [blame] | 6671 | tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6672 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6673 | /* Get the *optional* external "ether_clk" used on some boards */ |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 6674 | rc = rtl_get_ether_clk(tp); |
| 6675 | if (rc) |
| 6676 | return rc; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6677 | |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 6678 | /* Disable ASPM completely as that cause random device stop working |
| 6679 | * problems as well as full system hangs for some PCIe devices users. |
| 6680 | */ |
Heiner Kallweit | 62b1b3b | 2019-06-18 23:14:50 +0200 | [diff] [blame] | 6681 | rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
| 6682 | PCIE_LINK_STATE_L1); |
| 6683 | tp->aspm_manageable = !rc; |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 6684 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6685 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6686 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6687 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6688 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6689 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6690 | } |
| 6691 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6692 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6693 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6694 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 6695 | /* use first MMIO region */ |
| 6696 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 6697 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6698 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6699 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | /* check for weird/broken PCI region reporting */ |
| 6703 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6704 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6705 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6706 | } |
| 6707 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 6708 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6709 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6710 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6711 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6712 | } |
| 6713 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 6714 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6715 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6716 | /* Identify chip attached to board */ |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 6717 | rtl8169_get_mac_version(tp); |
| 6718 | if (tp->mac_version == RTL_GIGA_MAC_NONE) |
| 6719 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6720 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 6721 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6722 | |
Heiner Kallweit | 10b63e8 | 2019-01-20 11:45:20 +0100 | [diff] [blame] | 6723 | if (sizeof(dma_addr_t) > 4 && tp->mac_version >= RTL_GIGA_MAC_VER_18 && |
Heiner Kallweit | 3c18cbe | 2019-06-27 23:12:39 +0200 | [diff] [blame] | 6724 | !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6725 | dev->features |= NETIF_F_HIGHDMA; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6726 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6727 | rtl_init_rxcfg(tp); |
| 6728 | |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 6729 | rtl8169_irq_mask_and_ack(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6730 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6731 | rtl_hw_initialize(tp); |
| 6732 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6733 | rtl_hw_reset(tp); |
| 6734 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6735 | pci_set_master(pdev); |
| 6736 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6737 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6738 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6739 | rc = rtl_alloc_irq(tp); |
| 6740 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6741 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6742 | return rc; |
| 6743 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6744 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6745 | mutex_init(&tp->wk.mutex); |
Heiner Kallweit | 5c41e78 | 2019-01-19 22:03:49 +0100 | [diff] [blame] | 6746 | INIT_WORK(&tp->wk.work, rtl_task); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 6747 | u64_stats_init(&tp->rx_stats.syncp); |
| 6748 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6749 | |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6750 | rtl_init_mac_address(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6751 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 6752 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6753 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 6754 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6755 | |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6756 | dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6757 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 6758 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6759 | 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] | 6760 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 6761 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6762 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6763 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 6764 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6765 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6766 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 6767 | |
| 6768 | /* |
| 6769 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 6770 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 6771 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6772 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6773 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 6774 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6775 | |
Heiner Kallweit | 0170d59 | 2019-07-26 21:48:32 +0200 | [diff] [blame] | 6776 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6777 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6778 | dev->features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | 0170d59 | 2019-07-26 21:48:32 +0200 | [diff] [blame] | 6779 | dev->gso_max_size = RTL_GSO_MAX_SIZE_V2; |
| 6780 | dev->gso_max_segs = RTL_GSO_MAX_SEGS_V2; |
| 6781 | } else { |
| 6782 | dev->gso_max_size = RTL_GSO_MAX_SIZE_V1; |
| 6783 | dev->gso_max_segs = RTL_GSO_MAX_SEGS_V1; |
| 6784 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6785 | |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6786 | /* RTL8168e-vl has a HW issue with TSO */ |
| 6787 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
Holger Hoffstätte | a7eb6a4 | 2019-08-09 00:02:40 +0200 | [diff] [blame] | 6788 | dev->vlan_features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
| 6789 | dev->hw_features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
| 6790 | dev->features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6791 | } |
| 6792 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6793 | dev->hw_features |= NETIF_F_RXALL; |
| 6794 | dev->hw_features |= NETIF_F_RXFCS; |
| 6795 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 6796 | /* MTU range: 60 - hw-specific max */ |
| 6797 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6798 | jumbo_max = rtl_jumbo_max(tp); |
| 6799 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 6800 | |
Heiner Kallweit | ec9a408 | 2019-06-10 18:21:50 +0200 | [diff] [blame] | 6801 | rtl_set_irq_mask(tp); |
Heiner Kallweit | 9fa0a8e | 2019-06-10 18:24:25 +0200 | [diff] [blame] | 6802 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 6803 | tp->fw_name = rtl_chip_infos[chipset].fw_name; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6804 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6805 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 6806 | &tp->counters_phys_addr, |
| 6807 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 6808 | if (!tp->counters) |
| 6809 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6810 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 6811 | pci_set_drvdata(pdev, dev); |
| 6812 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6813 | rc = r8169_mdio_register(tp); |
| 6814 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 6815 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6816 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6817 | /* chip gets powered up in rtl_open() */ |
| 6818 | rtl_pll_power_down(tp); |
| 6819 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6820 | rc = register_netdev(dev); |
| 6821 | if (rc) |
| 6822 | goto err_mdio_unregister; |
| 6823 | |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 6824 | netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n", |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 6825 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 6826 | (RTL_R32(tp, TxConfig) >> 20) & 0xfcf, |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 6827 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6828 | |
| 6829 | if (jumbo_max > JUMBO_1K) |
| 6830 | netif_info(tp, probe, dev, |
| 6831 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 6832 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 6833 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6834 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6835 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6836 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6837 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6838 | if (pci_dev_run_wake(pdev)) |
| 6839 | pm_runtime_put_sync(&pdev->dev); |
| 6840 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6841 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6842 | |
| 6843 | err_mdio_unregister: |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6844 | mdiobus_unregister(tp->phydev->mdio.bus); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6845 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6846 | } |
| 6847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | static struct pci_driver rtl8169_pci_driver = { |
| 6849 | .name = MODULENAME, |
| 6850 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6851 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6852 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6853 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6854 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6855 | }; |
| 6856 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 6857 | module_pci_driver(rtl8169_pci_driver); |