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 && |
| 733 | tp->mac_version != RTL_GIGA_MAC_VER_39; |
| 734 | } |
| 735 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 736 | static bool rtl_supports_eee(struct rtl8169_private *tp) |
| 737 | { |
| 738 | return tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
| 739 | tp->mac_version != RTL_GIGA_MAC_VER_37 && |
| 740 | tp->mac_version != RTL_GIGA_MAC_VER_39; |
| 741 | } |
| 742 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 743 | struct rtl_cond { |
| 744 | bool (*check)(struct rtl8169_private *); |
| 745 | const char *msg; |
| 746 | }; |
| 747 | |
| 748 | static void rtl_udelay(unsigned int d) |
| 749 | { |
| 750 | udelay(d); |
| 751 | } |
| 752 | |
| 753 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 754 | void (*delay)(unsigned int), unsigned int d, int n, |
| 755 | bool high) |
| 756 | { |
| 757 | int i; |
| 758 | |
| 759 | for (i = 0; i < n; i++) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 760 | if (c->check(tp) == high) |
| 761 | return true; |
Heiner Kallweit | d1f5050 | 2019-05-04 15:20:38 +0200 | [diff] [blame] | 762 | delay(d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 763 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 764 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 765 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 766 | return false; |
| 767 | } |
| 768 | |
| 769 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 770 | const struct rtl_cond *c, |
| 771 | unsigned int d, int n) |
| 772 | { |
| 773 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 774 | } |
| 775 | |
| 776 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 777 | const struct rtl_cond *c, |
| 778 | unsigned int d, int n) |
| 779 | { |
| 780 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 781 | } |
| 782 | |
| 783 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 784 | const struct rtl_cond *c, |
| 785 | unsigned int d, int n) |
| 786 | { |
| 787 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 788 | } |
| 789 | |
| 790 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 791 | const struct rtl_cond *c, |
| 792 | unsigned int d, int n) |
| 793 | { |
| 794 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 795 | } |
| 796 | |
| 797 | #define DECLARE_RTL_COND(name) \ |
| 798 | static bool name ## _check(struct rtl8169_private *); \ |
| 799 | \ |
| 800 | static const struct rtl_cond name = { \ |
| 801 | .check = name ## _check, \ |
| 802 | .msg = #name \ |
| 803 | }; \ |
| 804 | \ |
| 805 | static bool name ## _check(struct rtl8169_private *tp) |
| 806 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 807 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 808 | { |
| 809 | if (reg & 0xffff0001) { |
| 810 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 811 | return true; |
| 812 | } |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 817 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 818 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 822 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 823 | if (rtl_ocp_reg_failure(tp, reg)) |
| 824 | return; |
| 825 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 826 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 827 | |
| 828 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 829 | } |
| 830 | |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 831 | static int r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 832 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 833 | if (rtl_ocp_reg_failure(tp, reg)) |
| 834 | return 0; |
| 835 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 836 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 837 | |
| 838 | 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] | 839 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : -ETIMEDOUT; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 840 | } |
| 841 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 842 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 843 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 844 | if (rtl_ocp_reg_failure(tp, reg)) |
| 845 | return; |
| 846 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 847 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 851 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 852 | if (rtl_ocp_reg_failure(tp, reg)) |
| 853 | return 0; |
| 854 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 855 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 856 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 857 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 858 | } |
| 859 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 860 | static void r8168_mac_ocp_modify(struct rtl8169_private *tp, u32 reg, u16 mask, |
| 861 | u16 set) |
| 862 | { |
| 863 | u16 data = r8168_mac_ocp_read(tp, reg); |
| 864 | |
| 865 | r8168_mac_ocp_write(tp, reg, (data & ~mask) | set); |
| 866 | } |
| 867 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 868 | #define OCP_STD_PHY_BASE 0xa400 |
| 869 | |
| 870 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 871 | { |
| 872 | if (reg == 0x1f) { |
| 873 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 878 | reg -= 0x10; |
| 879 | |
| 880 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 881 | } |
| 882 | |
| 883 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 884 | { |
| 885 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 886 | reg -= 0x10; |
| 887 | |
| 888 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 889 | } |
| 890 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 891 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 892 | { |
| 893 | if (reg == 0x1f) { |
| 894 | tp->ocp_base = value << 4; |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 899 | } |
| 900 | |
| 901 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 902 | { |
| 903 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 904 | } |
| 905 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 906 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 907 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 908 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 911 | 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] | 912 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 913 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 915 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 916 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 917 | * According to hardware specs a 20us delay is required after write |
| 918 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 919 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 920 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 923 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 925 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 927 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 929 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 930 | RTL_R32(tp, PHYAR) & 0xffff : -ETIMEDOUT; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 931 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 932 | /* |
| 933 | * According to hardware specs a 20us delay is required after read |
| 934 | * complete indication, but before sending next command. |
| 935 | */ |
| 936 | udelay(20); |
| 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | return value; |
| 939 | } |
| 940 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 941 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 942 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 943 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 944 | } |
| 945 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 946 | 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] | 947 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 948 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 949 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 950 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 951 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 952 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 955 | 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] | 956 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 957 | r8168dp_1_mdio_access(tp, reg, |
| 958 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 959 | } |
| 960 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 961 | 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] | 962 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 963 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 964 | |
| 965 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 966 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 967 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 968 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 969 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Heiner Kallweit | 9b994b4 | 2019-06-11 21:04:09 +0200 | [diff] [blame] | 970 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : -ETIMEDOUT; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 971 | } |
| 972 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 973 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 974 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 975 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 976 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 977 | 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] | 978 | } |
| 979 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 980 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 981 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 982 | 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] | 983 | } |
| 984 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 985 | 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] | 986 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 987 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 988 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 989 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 990 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 991 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 992 | } |
| 993 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 994 | 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] | 995 | { |
| 996 | int value; |
| 997 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 998 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 999 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1000 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1001 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1002 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1003 | |
| 1004 | return value; |
| 1005 | } |
| 1006 | |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 1007 | static void rtl_writephy(struct rtl8169_private *tp, int location, int val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1008 | { |
Heiner Kallweit | 5f95052 | 2019-05-31 19:53:28 +0200 | [diff] [blame] | 1009 | switch (tp->mac_version) { |
| 1010 | case RTL_GIGA_MAC_VER_27: |
| 1011 | r8168dp_1_mdio_write(tp, location, val); |
| 1012 | break; |
| 1013 | case RTL_GIGA_MAC_VER_28: |
| 1014 | case RTL_GIGA_MAC_VER_31: |
| 1015 | r8168dp_2_mdio_write(tp, location, val); |
| 1016 | break; |
| 1017 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1018 | r8168g_mdio_write(tp, location, val); |
| 1019 | break; |
| 1020 | default: |
| 1021 | r8169_mdio_write(tp, location, val); |
| 1022 | break; |
| 1023 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1024 | } |
| 1025 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1026 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1027 | { |
Heiner Kallweit | 5f95052 | 2019-05-31 19:53:28 +0200 | [diff] [blame] | 1028 | switch (tp->mac_version) { |
| 1029 | case RTL_GIGA_MAC_VER_27: |
| 1030 | return r8168dp_1_mdio_read(tp, location); |
| 1031 | case RTL_GIGA_MAC_VER_28: |
| 1032 | case RTL_GIGA_MAC_VER_31: |
| 1033 | return r8168dp_2_mdio_read(tp, location); |
| 1034 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1035 | return r8168g_mdio_read(tp, location); |
| 1036 | default: |
| 1037 | return r8169_mdio_read(tp, location); |
| 1038 | } |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1042 | { |
| 1043 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1044 | } |
| 1045 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1046 | 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] | 1047 | { |
| 1048 | int val; |
| 1049 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1050 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1051 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1054 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1055 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1056 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1057 | } |
| 1058 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1059 | 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] | 1060 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1061 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1062 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1063 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1064 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1065 | |
| 1066 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1067 | } |
| 1068 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1069 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1070 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1071 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1072 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1073 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1074 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1075 | } |
| 1076 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1077 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1078 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1079 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1080 | } |
| 1081 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1082 | static void _rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1083 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1084 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1085 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1086 | RTL_W32(tp, ERIDR, val); |
| 1087 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1088 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1089 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1092 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1093 | u32 val) |
| 1094 | { |
| 1095 | _rtl_eri_write(tp, addr, mask, val, ERIAR_EXGMAC); |
| 1096 | } |
| 1097 | |
| 1098 | 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] | 1099 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1100 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1101 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1102 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1103 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1106 | static u32 rtl_eri_read(struct rtl8169_private *tp, int addr) |
| 1107 | { |
| 1108 | return _rtl_eri_read(tp, addr, ERIAR_EXGMAC); |
| 1109 | } |
| 1110 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1111 | 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] | 1112 | u32 m) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1113 | { |
| 1114 | u32 val; |
| 1115 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1116 | val = rtl_eri_read(tp, addr); |
| 1117 | rtl_eri_write(tp, addr, mask, (val & ~m) | p); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1118 | } |
| 1119 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1120 | static void rtl_eri_set_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1121 | u32 p) |
| 1122 | { |
| 1123 | rtl_w0w1_eri(tp, addr, mask, p, 0); |
| 1124 | } |
| 1125 | |
| 1126 | static void rtl_eri_clear_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1127 | u32 m) |
| 1128 | { |
| 1129 | rtl_w0w1_eri(tp, addr, mask, 0, m); |
| 1130 | } |
| 1131 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1132 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1133 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1134 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1135 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1136 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1140 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1141 | return _rtl_eri_read(tp, reg, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1144 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1145 | u32 data) |
| 1146 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1147 | RTL_W32(tp, OCPDR, data); |
| 1148 | 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] | 1149 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1150 | } |
| 1151 | |
| 1152 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1153 | u32 data) |
| 1154 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1155 | _rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1156 | data, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1157 | } |
| 1158 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1159 | static void r8168dp_oob_notify(struct rtl8169_private *tp, u8 cmd) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1160 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1161 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1162 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1163 | r8168dp_ocp_write(tp, 0x1, 0x30, 0x00000001); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | #define OOB_CMD_RESET 0x00 |
| 1167 | #define OOB_CMD_DRIVER_START 0x05 |
| 1168 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1169 | |
| 1170 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1171 | { |
| 1172 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1173 | } |
| 1174 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1175 | DECLARE_RTL_COND(rtl_dp_ocp_read_cond) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1176 | { |
| 1177 | u16 reg; |
| 1178 | |
| 1179 | reg = rtl8168_get_ocp_reg(tp); |
| 1180 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1181 | return r8168dp_ocp_read(tp, 0x0f, reg) & 0x00000800; |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1182 | } |
| 1183 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1184 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1185 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1186 | return r8168ep_ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1190 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1191 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1192 | } |
| 1193 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1194 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1195 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1196 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1197 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1198 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1199 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1200 | } |
| 1201 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1202 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1203 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1204 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 1205 | 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] | 1206 | } |
| 1207 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1208 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1209 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1210 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1211 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1212 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1213 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1214 | } |
| 1215 | |
| 1216 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1217 | { |
| 1218 | switch (tp->mac_version) { |
| 1219 | case RTL_GIGA_MAC_VER_27: |
| 1220 | case RTL_GIGA_MAC_VER_28: |
| 1221 | case RTL_GIGA_MAC_VER_31: |
| 1222 | rtl8168dp_driver_start(tp); |
| 1223 | break; |
| 1224 | case RTL_GIGA_MAC_VER_49: |
| 1225 | case RTL_GIGA_MAC_VER_50: |
| 1226 | case RTL_GIGA_MAC_VER_51: |
| 1227 | rtl8168ep_driver_start(tp); |
| 1228 | break; |
| 1229 | default: |
| 1230 | BUG(); |
| 1231 | break; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1236 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1237 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1238 | 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] | 1239 | } |
| 1240 | |
| 1241 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1242 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1243 | rtl8168ep_stop_cmac(tp); |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1244 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1245 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1246 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1247 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1248 | } |
| 1249 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1250 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1251 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1252 | switch (tp->mac_version) { |
| 1253 | case RTL_GIGA_MAC_VER_27: |
| 1254 | case RTL_GIGA_MAC_VER_28: |
| 1255 | case RTL_GIGA_MAC_VER_31: |
| 1256 | rtl8168dp_driver_stop(tp); |
| 1257 | break; |
| 1258 | case RTL_GIGA_MAC_VER_49: |
| 1259 | case RTL_GIGA_MAC_VER_50: |
| 1260 | case RTL_GIGA_MAC_VER_51: |
| 1261 | rtl8168ep_driver_stop(tp); |
| 1262 | break; |
| 1263 | default: |
| 1264 | BUG(); |
| 1265 | break; |
| 1266 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1267 | } |
| 1268 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1269 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1270 | { |
| 1271 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1272 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1273 | return !!(r8168dp_ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1276 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1277 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1278 | return !!(r8168ep_ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1279 | } |
| 1280 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1281 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1282 | { |
| 1283 | switch (tp->mac_version) { |
| 1284 | case RTL_GIGA_MAC_VER_27: |
| 1285 | case RTL_GIGA_MAC_VER_28: |
| 1286 | case RTL_GIGA_MAC_VER_31: |
| 1287 | return r8168dp_check_dash(tp); |
| 1288 | case RTL_GIGA_MAC_VER_49: |
| 1289 | case RTL_GIGA_MAC_VER_50: |
| 1290 | case RTL_GIGA_MAC_VER_51: |
| 1291 | return r8168ep_check_dash(tp); |
| 1292 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1293 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1297 | static void rtl_reset_packet_filter(struct rtl8169_private *tp) |
| 1298 | { |
| 1299 | rtl_eri_clear_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1300 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1301 | } |
| 1302 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1303 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1304 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1305 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1306 | } |
| 1307 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1308 | 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] | 1309 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1310 | 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] | 1311 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1312 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1313 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame^] | 1316 | static u32 rtl_get_events(struct rtl8169_private *tp) |
| 1317 | { |
| 1318 | return RTL_R16(tp, IntrStatus); |
| 1319 | } |
| 1320 | |
| 1321 | static void rtl_ack_events(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1322 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1323 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1327 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1328 | RTL_W16(tp, IntrMask, 0); |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1329 | tp->irq_enabled = 0; |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1332 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1333 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1334 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1335 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1336 | static void rtl_irq_enable(struct rtl8169_private *tp) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1337 | { |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1338 | tp->irq_enabled = 1; |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 1339 | RTL_W16(tp, IntrMask, tp->irq_mask); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1342 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1344 | rtl_irq_disable(tp); |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame^] | 1345 | rtl_ack_events(tp, 0xffffffff); |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 1346 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1347 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1350 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1351 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1352 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 1353 | struct phy_device *phydev = tp->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1354 | |
| 1355 | if (!netif_running(dev)) |
| 1356 | return; |
| 1357 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1358 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1359 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1360 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1361 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1362 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1363 | } else if (phydev->speed == SPEED_100) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1364 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1365 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1366 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1367 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1368 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1369 | } |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1370 | rtl_reset_packet_filter(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1371 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1372 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1373 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1374 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1375 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1376 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1377 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1378 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1379 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1380 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1381 | if (phydev->speed == SPEED_10) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1382 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02); |
| 1383 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060a); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1384 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1385 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1386 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1390 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1391 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1392 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1393 | { |
| 1394 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1395 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1396 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1397 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1398 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1399 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1402 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1403 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1404 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1405 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1406 | u32 opt; |
| 1407 | u16 reg; |
| 1408 | u8 mask; |
| 1409 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1410 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1411 | { WAKE_UCAST, Config5, UWF }, |
| 1412 | { WAKE_BCAST, Config5, BWF }, |
| 1413 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1414 | { WAKE_ANY, Config5, LanWake }, |
| 1415 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1416 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1417 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1418 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1419 | rtl_unlock_config_regs(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1420 | |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 1421 | if (rtl_is_8168evl_up(tp)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1422 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1423 | if (wolopts & WAKE_MAGIC) |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1424 | rtl_eri_set_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1425 | MagicPacket_v2); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1426 | else |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1427 | rtl_eri_clear_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1428 | MagicPacket_v2); |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 1429 | } else { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1430 | tmp = ARRAY_SIZE(cfg); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1434 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1435 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1436 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1437 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1438 | } |
| 1439 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1440 | switch (tp->mac_version) { |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1441 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1442 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1443 | if (wolopts) |
| 1444 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1445 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1446 | break; |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1447 | case RTL_GIGA_MAC_VER_34: |
| 1448 | case RTL_GIGA_MAC_VER_37: |
| 1449 | case RTL_GIGA_MAC_VER_39 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1450 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1451 | if (wolopts) |
| 1452 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1453 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1454 | break; |
Heiner Kallweit | edcde3e | 2019-07-26 20:56:20 +0200 | [diff] [blame] | 1455 | default: |
| 1456 | break; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1457 | } |
| 1458 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1459 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 3bd8264 | 2018-12-30 13:16:12 +0100 | [diff] [blame] | 1460 | |
| 1461 | device_set_wakeup_enable(tp_to_dev(tp), wolopts); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1465 | { |
| 1466 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1467 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1468 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1469 | if (wol->wolopts & ~WAKE_ANY) |
| 1470 | return -EINVAL; |
| 1471 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1472 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1473 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1474 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1475 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1476 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1477 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1478 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1479 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1480 | |
| 1481 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1482 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1483 | pm_runtime_put_noidle(d); |
| 1484 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1485 | return 0; |
| 1486 | } |
| 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1489 | struct ethtool_drvinfo *info) |
| 1490 | { |
| 1491 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1492 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1494 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1495 | 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] | 1496 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 1497 | if (rtl_fw) |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1498 | strlcpy(info->fw_version, rtl_fw->version, |
| 1499 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1503 | { |
| 1504 | return R8169_REGS_SIZE; |
| 1505 | } |
| 1506 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1507 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1508 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1510 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1511 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1512 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1513 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1515 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1516 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1517 | features &= ~NETIF_F_IP_CSUM; |
| 1518 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1519 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1522 | static int rtl8169_set_features(struct net_device *dev, |
| 1523 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | { |
| 1525 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1526 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1528 | rtl_lock_work(tp); |
| 1529 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1530 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1531 | if (features & NETIF_F_RXALL) |
| 1532 | rx_config |= (AcceptErr | AcceptRunt); |
| 1533 | else |
| 1534 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1536 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1537 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1538 | if (features & NETIF_F_RXCSUM) |
| 1539 | tp->cp_cmd |= RxChkSum; |
| 1540 | else |
| 1541 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1542 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1543 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1544 | tp->cp_cmd |= RxVlan; |
| 1545 | else |
| 1546 | tp->cp_cmd &= ~RxVlan; |
| 1547 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1548 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1549 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1551 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1556 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1558 | return (skb_vlan_tag_present(skb)) ? |
Heiner Kallweit | 7424edb | 2019-07-02 07:59:17 +0200 | [diff] [blame] | 1559 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1562 | 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] | 1563 | { |
| 1564 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1566 | if (opts2 & RxVlanTag) |
Heiner Kallweit | 7424edb | 2019-07-02 07:59:17 +0200 | [diff] [blame] | 1567 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1571 | void *p) |
| 1572 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1573 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1574 | u32 __iomem *data = tp->mmio_addr; |
| 1575 | u32 *dw = p; |
| 1576 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1578 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1579 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1580 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1581 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1584 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1585 | { |
| 1586 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1587 | |
| 1588 | return tp->msg_enable; |
| 1589 | } |
| 1590 | |
| 1591 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1592 | { |
| 1593 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1594 | |
| 1595 | tp->msg_enable = value; |
| 1596 | } |
| 1597 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1598 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1599 | "tx_packets", |
| 1600 | "rx_packets", |
| 1601 | "tx_errors", |
| 1602 | "rx_errors", |
| 1603 | "rx_missed", |
| 1604 | "align_errors", |
| 1605 | "tx_single_collisions", |
| 1606 | "tx_multi_collisions", |
| 1607 | "unicast", |
| 1608 | "broadcast", |
| 1609 | "multicast", |
| 1610 | "tx_aborted", |
| 1611 | "tx_underrun", |
| 1612 | }; |
| 1613 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1614 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1615 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1616 | switch (sset) { |
| 1617 | case ETH_SS_STATS: |
| 1618 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1619 | default: |
| 1620 | return -EOPNOTSUPP; |
| 1621 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1622 | } |
| 1623 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1624 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1625 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1626 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1627 | } |
| 1628 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1629 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1630 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1631 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1632 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1633 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1634 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1635 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1636 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1637 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1638 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1639 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1640 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1641 | } |
| 1642 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1643 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1644 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1645 | /* |
| 1646 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1647 | * tally counters. |
| 1648 | */ |
| 1649 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1650 | return true; |
| 1651 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1652 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1653 | } |
| 1654 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1655 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1656 | { |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1657 | u8 val = RTL_R8(tp, ChipCmd); |
| 1658 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1659 | /* |
| 1660 | * Some chips are unable to dump tally counters when the receiver |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1661 | * 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] | 1662 | */ |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1663 | if (!(val & CmdRxEnb) || val == 0xff) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1664 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1665 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1666 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1669 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1670 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1671 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1672 | bool ret = false; |
| 1673 | |
| 1674 | /* |
| 1675 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1676 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1677 | * reset by a power cycle, while the counter values collected by the |
| 1678 | * driver are reset at every driver unload/load cycle. |
| 1679 | * |
| 1680 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1681 | * values, we collect the initial values at first open(*) and use them |
| 1682 | * as offsets to normalize the values returned by @get_stats64. |
| 1683 | * |
| 1684 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1685 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1686 | * set at open time by rtl_hw_start. |
| 1687 | */ |
| 1688 | |
| 1689 | if (tp->tc_offset.inited) |
| 1690 | return true; |
| 1691 | |
| 1692 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1693 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1694 | ret = true; |
| 1695 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1696 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1697 | ret = true; |
| 1698 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1699 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1700 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1701 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1702 | tp->tc_offset.inited = true; |
| 1703 | |
| 1704 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1705 | } |
| 1706 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1707 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1708 | struct ethtool_stats *stats, u64 *data) |
| 1709 | { |
| 1710 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1711 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1712 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1713 | |
| 1714 | ASSERT_RTNL(); |
| 1715 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1716 | pm_runtime_get_noresume(d); |
| 1717 | |
| 1718 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1719 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1720 | |
| 1721 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1722 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1723 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1724 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1725 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1726 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1727 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1728 | data[5] = le16_to_cpu(counters->align_errors); |
| 1729 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1730 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1731 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1732 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1733 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1734 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1735 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1736 | } |
| 1737 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1738 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1739 | { |
| 1740 | switch(stringset) { |
| 1741 | case ETH_SS_STATS: |
| 1742 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1743 | break; |
| 1744 | } |
| 1745 | } |
| 1746 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1747 | /* |
| 1748 | * Interrupt coalescing |
| 1749 | * |
| 1750 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1751 | * > 8169, 8168 and 810x line of chipsets |
| 1752 | * |
| 1753 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1754 | * |
| 1755 | * > 2 - the Tx timer unit at gigabit speed |
| 1756 | * |
| 1757 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1758 | * (0xe0) bit 1 and bit 0. |
| 1759 | * |
| 1760 | * For 8169 |
| 1761 | * bit[1:0] \ speed 1000M 100M 10M |
| 1762 | * 0 0 320ns 2.56us 40.96us |
| 1763 | * 0 1 2.56us 20.48us 327.7us |
| 1764 | * 1 0 5.12us 40.96us 655.4us |
| 1765 | * 1 1 10.24us 81.92us 1.31ms |
| 1766 | * |
| 1767 | * For the other |
| 1768 | * bit[1:0] \ speed 1000M 100M 10M |
| 1769 | * 0 0 5us 2.56us 40.96us |
| 1770 | * 0 1 40us 20.48us 327.7us |
| 1771 | * 1 0 80us 40.96us 655.4us |
| 1772 | * 1 1 160us 81.92us 1.31ms |
| 1773 | */ |
| 1774 | |
| 1775 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1776 | struct rtl_coalesce_scale { |
| 1777 | /* Rx / Tx */ |
| 1778 | u32 nsecs[2]; |
| 1779 | }; |
| 1780 | |
| 1781 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1782 | struct rtl_coalesce_info { |
| 1783 | u32 speed; |
| 1784 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1785 | }; |
| 1786 | |
| 1787 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1788 | #define rxtx_x1822(r, t) { \ |
| 1789 | {{(r), (t)}}, \ |
| 1790 | {{(r)*8, (t)*8}}, \ |
| 1791 | {{(r)*8*2, (t)*8*2}}, \ |
| 1792 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1793 | } |
| 1794 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1795 | /* speed delays: rx00 tx00 */ |
| 1796 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1797 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1798 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1799 | { 0 }, |
| 1800 | }; |
| 1801 | |
| 1802 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1803 | /* speed delays: rx00 tx00 */ |
| 1804 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1805 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1806 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1807 | { 0 }, |
| 1808 | }; |
| 1809 | #undef rxtx_x1822 |
| 1810 | |
| 1811 | /* get rx/tx scale vector corresponding to current speed */ |
| 1812 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1813 | { |
| 1814 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1815 | const struct rtl_coalesce_info *ci; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1816 | |
Heiner Kallweit | 20023d3 | 2019-06-11 21:09:19 +0200 | [diff] [blame] | 1817 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 1818 | ci = rtl_coalesce_info_8169; |
| 1819 | else |
| 1820 | ci = rtl_coalesce_info_8168_8136; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1821 | |
Heiner Kallweit | 20023d3 | 2019-06-11 21:09:19 +0200 | [diff] [blame] | 1822 | for (; ci->speed; ci++) { |
| 1823 | if (tp->phydev->speed == ci->speed) |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1824 | return ci; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | return ERR_PTR(-ELNRNG); |
| 1828 | } |
| 1829 | |
| 1830 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1831 | { |
| 1832 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1833 | const struct rtl_coalesce_info *ci; |
| 1834 | const struct rtl_coalesce_scale *scale; |
| 1835 | struct { |
| 1836 | u32 *max_frames; |
| 1837 | u32 *usecs; |
| 1838 | } coal_settings [] = { |
| 1839 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1840 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1841 | }, *p = coal_settings; |
| 1842 | int i; |
| 1843 | u16 w; |
| 1844 | |
| 1845 | memset(ec, 0, sizeof(*ec)); |
| 1846 | |
| 1847 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1848 | ci = rtl_coalesce_info(dev); |
| 1849 | if (IS_ERR(ci)) |
| 1850 | return PTR_ERR(ci); |
| 1851 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1852 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1853 | |
| 1854 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1855 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1856 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1857 | w >>= RTL_COALESCE_SHIFT; |
| 1858 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1859 | } |
| 1860 | |
| 1861 | for (i = 0; i < 2; i++) { |
| 1862 | p = coal_settings + i; |
| 1863 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1864 | |
| 1865 | /* |
| 1866 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1867 | * max_frames to 0. |
| 1868 | */ |
| 1869 | if (!*p->usecs && !*p->max_frames) |
| 1870 | *p->max_frames = 1; |
| 1871 | } |
| 1872 | |
| 1873 | return 0; |
| 1874 | } |
| 1875 | |
| 1876 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1877 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1878 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1879 | { |
| 1880 | const struct rtl_coalesce_info *ci; |
| 1881 | u16 i; |
| 1882 | |
| 1883 | ci = rtl_coalesce_info(dev); |
| 1884 | if (IS_ERR(ci)) |
| 1885 | return ERR_CAST(ci); |
| 1886 | |
| 1887 | for (i = 0; i < 4; i++) { |
| 1888 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1889 | ci->scalev[i].nsecs[1]); |
| 1890 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1891 | *cp01 = i; |
| 1892 | return &ci->scalev[i]; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | return ERR_PTR(-EINVAL); |
| 1897 | } |
| 1898 | |
| 1899 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1900 | { |
| 1901 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1902 | const struct rtl_coalesce_scale *scale; |
| 1903 | struct { |
| 1904 | u32 frames; |
| 1905 | u32 usecs; |
| 1906 | } coal_settings [] = { |
| 1907 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1908 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1909 | }, *p = coal_settings; |
| 1910 | u16 w = 0, cp01; |
| 1911 | int i; |
| 1912 | |
| 1913 | scale = rtl_coalesce_choose_scale(dev, |
| 1914 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1915 | if (IS_ERR(scale)) |
| 1916 | return PTR_ERR(scale); |
| 1917 | |
| 1918 | for (i = 0; i < 2; i++, p++) { |
| 1919 | u32 units; |
| 1920 | |
| 1921 | /* |
| 1922 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1923 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1924 | * |
| 1925 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 1926 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 1927 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 1928 | * |
| 1929 | * since ethtool sends to kernel whole ethtool_coalesce |
| 1930 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 1931 | * we'll reject it below in `frames % 4 != 0`. |
| 1932 | */ |
| 1933 | if (p->frames == 1) { |
| 1934 | p->frames = 0; |
| 1935 | } |
| 1936 | |
| 1937 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 1938 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 1939 | return -EINVAL; |
| 1940 | |
| 1941 | w <<= RTL_COALESCE_SHIFT; |
| 1942 | w |= units; |
| 1943 | w <<= RTL_COALESCE_SHIFT; |
| 1944 | w |= p->frames >> 2; |
| 1945 | } |
| 1946 | |
| 1947 | rtl_lock_work(tp); |
| 1948 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1949 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1950 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 1951 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1952 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1953 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1954 | |
| 1955 | rtl_unlock_work(tp); |
| 1956 | |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1960 | static int rtl8169_get_eee(struct net_device *dev, struct ethtool_eee *data) |
| 1961 | { |
| 1962 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1963 | struct device *d = tp_to_dev(tp); |
| 1964 | int ret; |
| 1965 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1966 | if (!rtl_supports_eee(tp)) |
| 1967 | return -EOPNOTSUPP; |
| 1968 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1969 | pm_runtime_get_noresume(d); |
| 1970 | |
| 1971 | if (!pm_runtime_active(d)) { |
| 1972 | ret = -EOPNOTSUPP; |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1973 | } else { |
| 1974 | ret = phy_ethtool_get_eee(tp->phydev, data); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1977 | pm_runtime_put_noidle(d); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1978 | |
| 1979 | return ret; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | static int rtl8169_set_eee(struct net_device *dev, struct ethtool_eee *data) |
| 1983 | { |
| 1984 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1985 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1986 | int ret; |
| 1987 | |
| 1988 | if (!rtl_supports_eee(tp)) |
| 1989 | return -EOPNOTSUPP; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1990 | |
| 1991 | pm_runtime_get_noresume(d); |
| 1992 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 1993 | if (!pm_runtime_active(d)) { |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1994 | ret = -EOPNOTSUPP; |
| 1995 | goto out; |
| 1996 | } |
| 1997 | |
| 1998 | if (dev->phydev->autoneg == AUTONEG_DISABLE || |
| 1999 | dev->phydev->duplex != DUPLEX_FULL) { |
| 2000 | ret = -EPROTONOSUPPORT; |
| 2001 | goto out; |
| 2002 | } |
| 2003 | |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2004 | ret = phy_ethtool_set_eee(tp->phydev, data); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2005 | out: |
| 2006 | pm_runtime_put_noidle(d); |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2007 | return ret; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2010 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2012 | .get_regs_len = rtl8169_get_regs_len, |
| 2013 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2014 | .get_coalesce = rtl_get_coalesce, |
| 2015 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2016 | .get_msglevel = rtl8169_get_msglevel, |
| 2017 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2019 | .get_wol = rtl8169_get_wol, |
| 2020 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2021 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2022 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2023 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2024 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2025 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2026 | .get_eee = rtl8169_get_eee, |
| 2027 | .set_eee = rtl8169_set_eee, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2028 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2029 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | }; |
| 2031 | |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2032 | static void rtl_enable_eee(struct rtl8169_private *tp) |
| 2033 | { |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2034 | struct phy_device *phydev = tp->phydev; |
| 2035 | 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] | 2036 | |
| 2037 | if (supported > 0) |
Heiner Kallweit | 2e779dd | 2019-08-15 14:14:18 +0200 | [diff] [blame] | 2038 | phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, supported); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2039 | } |
| 2040 | |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2041 | static void rtl8169_get_mac_version(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2043 | /* |
| 2044 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2045 | * but they can be identified more specifically through the test below |
| 2046 | * if needed: |
| 2047 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2048 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2049 | * |
| 2050 | * Same thing for the 8101Eb and the 8101Ec: |
| 2051 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2052 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2053 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2054 | static const struct rtl_mac_info { |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2055 | u16 mask; |
| 2056 | u16 val; |
| 2057 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2059 | /* 8168EP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2060 | { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51 }, |
| 2061 | { 0x7cf, 0x501, RTL_GIGA_MAC_VER_50 }, |
| 2062 | { 0x7cf, 0x500, RTL_GIGA_MAC_VER_49 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2063 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2064 | /* 8168H family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2065 | { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46 }, |
| 2066 | { 0x7cf, 0x540, RTL_GIGA_MAC_VER_45 }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2067 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2068 | /* 8168G family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2069 | { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44 }, |
| 2070 | { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42 }, |
| 2071 | { 0x7cf, 0x4c1, RTL_GIGA_MAC_VER_41 }, |
| 2072 | { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2073 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2074 | /* 8168F family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2075 | { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38 }, |
| 2076 | { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36 }, |
| 2077 | { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2078 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2079 | /* 8168E family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2080 | { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34 }, |
| 2081 | { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32 }, |
| 2082 | { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2083 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2084 | /* 8168D family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2085 | { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25 }, |
| 2086 | { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2087 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2088 | /* 8168DP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2089 | { 0x7cf, 0x288, RTL_GIGA_MAC_VER_27 }, |
| 2090 | { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28 }, |
| 2091 | { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2092 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2093 | /* 8168C family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2094 | { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23 }, |
| 2095 | { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18 }, |
| 2096 | { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24 }, |
| 2097 | { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19 }, |
| 2098 | { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20 }, |
| 2099 | { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21 }, |
| 2100 | { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2101 | |
| 2102 | /* 8168B family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2103 | { 0x7cf, 0x380, RTL_GIGA_MAC_VER_12 }, |
| 2104 | { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17 }, |
| 2105 | { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2106 | |
| 2107 | /* 8101 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2108 | { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39 }, |
| 2109 | { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37 }, |
| 2110 | { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29 }, |
| 2111 | { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30 }, |
| 2112 | { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08 }, |
| 2113 | { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08 }, |
| 2114 | { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07 }, |
| 2115 | { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07 }, |
| 2116 | { 0x7cf, 0x340, RTL_GIGA_MAC_VER_13 }, |
| 2117 | { 0x7cf, 0x343, RTL_GIGA_MAC_VER_10 }, |
| 2118 | { 0x7cf, 0x342, RTL_GIGA_MAC_VER_16 }, |
| 2119 | { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09 }, |
| 2120 | { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09 }, |
| 2121 | { 0x7c8, 0x340, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2122 | /* FIXME: where did these entries come from ? -- FR */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2123 | { 0xfc8, 0x388, RTL_GIGA_MAC_VER_15 }, |
| 2124 | { 0xfc8, 0x308, RTL_GIGA_MAC_VER_14 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2125 | |
| 2126 | /* 8110 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2127 | { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06 }, |
| 2128 | { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05 }, |
| 2129 | { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04 }, |
| 2130 | { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03 }, |
| 2131 | { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2132 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2133 | /* Catch-all */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2134 | { 0x000, 0x000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2135 | }; |
| 2136 | const struct rtl_mac_info *p = mac_info; |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2137 | u16 reg = RTL_R32(tp, TxConfig) >> 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2139 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | p++; |
| 2141 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2142 | |
| 2143 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2144 | 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] | 2145 | } else if (!tp->supports_gmii) { |
| 2146 | if (tp->mac_version == RTL_GIGA_MAC_VER_42) |
| 2147 | tp->mac_version = RTL_GIGA_MAC_VER_43; |
| 2148 | else if (tp->mac_version == RTL_GIGA_MAC_VER_45) |
| 2149 | tp->mac_version = RTL_GIGA_MAC_VER_47; |
| 2150 | else if (tp->mac_version == RTL_GIGA_MAC_VER_46) |
| 2151 | tp->mac_version = RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2155 | struct phy_reg { |
| 2156 | u16 reg; |
| 2157 | u16 val; |
| 2158 | }; |
| 2159 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2160 | static void __rtl_writephy_batch(struct rtl8169_private *tp, |
| 2161 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2162 | { |
| 2163 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2164 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2165 | regs++; |
| 2166 | } |
| 2167 | } |
| 2168 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2169 | #define rtl_writephy_batch(tp, a) __rtl_writephy_batch(tp, a, ARRAY_SIZE(a)) |
| 2170 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2171 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2172 | { |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2173 | if (tp->rtl_fw) { |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 2174 | rtl_fw_release_firmware(tp->rtl_fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2175 | kfree(tp->rtl_fw); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2176 | tp->rtl_fw = NULL; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2177 | } |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2180 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2181 | { |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 2182 | /* TODO: release firmware if rtl_fw_write_firmware signals failure. */ |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2183 | if (tp->rtl_fw) |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 2184 | rtl_fw_write_firmware(tp, tp->rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2188 | { |
| 2189 | if (rtl_readphy(tp, reg) != val) |
| 2190 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2191 | else |
| 2192 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2195 | static void rtl8168_config_eee_mac(struct rtl8169_private *tp) |
| 2196 | { |
Heiner Kallweit | f452825 | 2019-05-04 17:13:09 +0200 | [diff] [blame] | 2197 | /* Adjust EEE LED frequency */ |
| 2198 | if (tp->mac_version != RTL_GIGA_MAC_VER_38) |
| 2199 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
| 2200 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 2201 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_1111, 0x0003); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2202 | } |
| 2203 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2204 | static void rtl8168f_config_eee_phy(struct rtl8169_private *tp) |
| 2205 | { |
| 2206 | struct phy_device *phydev = tp->phydev; |
| 2207 | |
| 2208 | phy_write(phydev, 0x1f, 0x0007); |
| 2209 | phy_write(phydev, 0x1e, 0x0020); |
| 2210 | phy_set_bits(phydev, 0x15, BIT(8)); |
| 2211 | |
| 2212 | phy_write(phydev, 0x1f, 0x0005); |
| 2213 | phy_write(phydev, 0x05, 0x8b85); |
| 2214 | phy_set_bits(phydev, 0x06, BIT(13)); |
| 2215 | |
| 2216 | phy_write(phydev, 0x1f, 0x0000); |
| 2217 | } |
| 2218 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2219 | static void rtl8168g_config_eee_phy(struct rtl8169_private *tp) |
| 2220 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 2221 | phy_modify_paged(tp->phydev, 0x0a43, 0x11, 0, BIT(4)); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
Heiner Kallweit | b6cef26 | 2019-08-15 14:21:30 +0200 | [diff] [blame] | 2224 | static void rtl8168h_config_eee_phy(struct rtl8169_private *tp) |
| 2225 | { |
| 2226 | struct phy_device *phydev = tp->phydev; |
| 2227 | |
| 2228 | rtl8168g_config_eee_phy(tp); |
| 2229 | |
| 2230 | phy_modify_paged(phydev, 0xa4a, 0x11, 0x0000, 0x0200); |
| 2231 | phy_modify_paged(phydev, 0xa42, 0x14, 0x0000, 0x0080); |
| 2232 | } |
| 2233 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2234 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2236 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2237 | { 0x1f, 0x0001 }, |
| 2238 | { 0x06, 0x006e }, |
| 2239 | { 0x08, 0x0708 }, |
| 2240 | { 0x15, 0x4000 }, |
| 2241 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2243 | { 0x1f, 0x0001 }, |
| 2244 | { 0x03, 0x00a1 }, |
| 2245 | { 0x02, 0x0008 }, |
| 2246 | { 0x01, 0x0120 }, |
| 2247 | { 0x00, 0x1000 }, |
| 2248 | { 0x04, 0x0800 }, |
| 2249 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2251 | { 0x03, 0xff41 }, |
| 2252 | { 0x02, 0xdf60 }, |
| 2253 | { 0x01, 0x0140 }, |
| 2254 | { 0x00, 0x0077 }, |
| 2255 | { 0x04, 0x7800 }, |
| 2256 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2258 | { 0x03, 0x802f }, |
| 2259 | { 0x02, 0x4f02 }, |
| 2260 | { 0x01, 0x0409 }, |
| 2261 | { 0x00, 0xf0f9 }, |
| 2262 | { 0x04, 0x9800 }, |
| 2263 | { 0x04, 0x9000 }, |
| 2264 | |
| 2265 | { 0x03, 0xdf01 }, |
| 2266 | { 0x02, 0xdf20 }, |
| 2267 | { 0x01, 0xff95 }, |
| 2268 | { 0x00, 0xba00 }, |
| 2269 | { 0x04, 0xa800 }, |
| 2270 | { 0x04, 0xa000 }, |
| 2271 | |
| 2272 | { 0x03, 0xff41 }, |
| 2273 | { 0x02, 0xdf20 }, |
| 2274 | { 0x01, 0x0140 }, |
| 2275 | { 0x00, 0x00bb }, |
| 2276 | { 0x04, 0xb800 }, |
| 2277 | { 0x04, 0xb000 }, |
| 2278 | |
| 2279 | { 0x03, 0xdf41 }, |
| 2280 | { 0x02, 0xdc60 }, |
| 2281 | { 0x01, 0x6340 }, |
| 2282 | { 0x00, 0x007d }, |
| 2283 | { 0x04, 0xd800 }, |
| 2284 | { 0x04, 0xd000 }, |
| 2285 | |
| 2286 | { 0x03, 0xdf01 }, |
| 2287 | { 0x02, 0xdf20 }, |
| 2288 | { 0x01, 0x100a }, |
| 2289 | { 0x00, 0xa0ff }, |
| 2290 | { 0x04, 0xf800 }, |
| 2291 | { 0x04, 0xf000 }, |
| 2292 | |
| 2293 | { 0x1f, 0x0000 }, |
| 2294 | { 0x0b, 0x0000 }, |
| 2295 | { 0x00, 0x9200 } |
| 2296 | }; |
| 2297 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2298 | rtl_writephy_batch(tp, phy_reg_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2301 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2302 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2303 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2304 | { 0x1f, 0x0002 }, |
| 2305 | { 0x01, 0x90d0 }, |
| 2306 | { 0x1f, 0x0000 } |
| 2307 | }; |
| 2308 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2309 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2310 | } |
| 2311 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2312 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2313 | { |
| 2314 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2315 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2316 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2317 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2318 | return; |
| 2319 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2320 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2321 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2322 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2325 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2326 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2327 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2328 | { 0x1f, 0x0001 }, |
| 2329 | { 0x04, 0x0000 }, |
| 2330 | { 0x03, 0x00a1 }, |
| 2331 | { 0x02, 0x0008 }, |
| 2332 | { 0x01, 0x0120 }, |
| 2333 | { 0x00, 0x1000 }, |
| 2334 | { 0x04, 0x0800 }, |
| 2335 | { 0x04, 0x9000 }, |
| 2336 | { 0x03, 0x802f }, |
| 2337 | { 0x02, 0x4f02 }, |
| 2338 | { 0x01, 0x0409 }, |
| 2339 | { 0x00, 0xf099 }, |
| 2340 | { 0x04, 0x9800 }, |
| 2341 | { 0x04, 0xa000 }, |
| 2342 | { 0x03, 0xdf01 }, |
| 2343 | { 0x02, 0xdf20 }, |
| 2344 | { 0x01, 0xff95 }, |
| 2345 | { 0x00, 0xba00 }, |
| 2346 | { 0x04, 0xa800 }, |
| 2347 | { 0x04, 0xf000 }, |
| 2348 | { 0x03, 0xdf01 }, |
| 2349 | { 0x02, 0xdf20 }, |
| 2350 | { 0x01, 0x101a }, |
| 2351 | { 0x00, 0xa0ff }, |
| 2352 | { 0x04, 0xf800 }, |
| 2353 | { 0x04, 0x0000 }, |
| 2354 | { 0x1f, 0x0000 }, |
| 2355 | |
| 2356 | { 0x1f, 0x0001 }, |
| 2357 | { 0x10, 0xf41b }, |
| 2358 | { 0x14, 0xfb54 }, |
| 2359 | { 0x18, 0xf5c7 }, |
| 2360 | { 0x1f, 0x0000 }, |
| 2361 | |
| 2362 | { 0x1f, 0x0001 }, |
| 2363 | { 0x17, 0x0cc0 }, |
| 2364 | { 0x1f, 0x0000 } |
| 2365 | }; |
| 2366 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2367 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2368 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2369 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2372 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2373 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2374 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2375 | { 0x1f, 0x0001 }, |
| 2376 | { 0x04, 0x0000 }, |
| 2377 | { 0x03, 0x00a1 }, |
| 2378 | { 0x02, 0x0008 }, |
| 2379 | { 0x01, 0x0120 }, |
| 2380 | { 0x00, 0x1000 }, |
| 2381 | { 0x04, 0x0800 }, |
| 2382 | { 0x04, 0x9000 }, |
| 2383 | { 0x03, 0x802f }, |
| 2384 | { 0x02, 0x4f02 }, |
| 2385 | { 0x01, 0x0409 }, |
| 2386 | { 0x00, 0xf099 }, |
| 2387 | { 0x04, 0x9800 }, |
| 2388 | { 0x04, 0xa000 }, |
| 2389 | { 0x03, 0xdf01 }, |
| 2390 | { 0x02, 0xdf20 }, |
| 2391 | { 0x01, 0xff95 }, |
| 2392 | { 0x00, 0xba00 }, |
| 2393 | { 0x04, 0xa800 }, |
| 2394 | { 0x04, 0xf000 }, |
| 2395 | { 0x03, 0xdf01 }, |
| 2396 | { 0x02, 0xdf20 }, |
| 2397 | { 0x01, 0x101a }, |
| 2398 | { 0x00, 0xa0ff }, |
| 2399 | { 0x04, 0xf800 }, |
| 2400 | { 0x04, 0x0000 }, |
| 2401 | { 0x1f, 0x0000 }, |
| 2402 | |
| 2403 | { 0x1f, 0x0001 }, |
| 2404 | { 0x0b, 0x8480 }, |
| 2405 | { 0x1f, 0x0000 }, |
| 2406 | |
| 2407 | { 0x1f, 0x0001 }, |
| 2408 | { 0x18, 0x67c7 }, |
| 2409 | { 0x04, 0x2000 }, |
| 2410 | { 0x03, 0x002f }, |
| 2411 | { 0x02, 0x4360 }, |
| 2412 | { 0x01, 0x0109 }, |
| 2413 | { 0x00, 0x3022 }, |
| 2414 | { 0x04, 0x2800 }, |
| 2415 | { 0x1f, 0x0000 }, |
| 2416 | |
| 2417 | { 0x1f, 0x0001 }, |
| 2418 | { 0x17, 0x0cc0 }, |
| 2419 | { 0x1f, 0x0000 } |
| 2420 | }; |
| 2421 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2422 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2425 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2426 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2427 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2428 | { 0x10, 0xf41b }, |
| 2429 | { 0x1f, 0x0000 } |
| 2430 | }; |
| 2431 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2432 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2433 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2434 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2435 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2436 | } |
| 2437 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2438 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2439 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2440 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2441 | { 0x1f, 0x0001 }, |
| 2442 | { 0x10, 0xf41b }, |
| 2443 | { 0x1f, 0x0000 } |
| 2444 | }; |
| 2445 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2446 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2447 | } |
| 2448 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2449 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2450 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2451 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2452 | { 0x1f, 0x0000 }, |
| 2453 | { 0x1d, 0x0f00 }, |
| 2454 | { 0x1f, 0x0002 }, |
| 2455 | { 0x0c, 0x1ec8 }, |
| 2456 | { 0x1f, 0x0000 } |
| 2457 | }; |
| 2458 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2459 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2460 | } |
| 2461 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2462 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2463 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2464 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2465 | { 0x1f, 0x0001 }, |
| 2466 | { 0x1d, 0x3d98 }, |
| 2467 | { 0x1f, 0x0000 } |
| 2468 | }; |
| 2469 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2470 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2471 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2472 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2473 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2474 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2475 | } |
| 2476 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2477 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2478 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2479 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2480 | { 0x1f, 0x0001 }, |
| 2481 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2482 | { 0x1f, 0x0002 }, |
| 2483 | { 0x00, 0x88d4 }, |
| 2484 | { 0x01, 0x82b1 }, |
| 2485 | { 0x03, 0x7002 }, |
| 2486 | { 0x08, 0x9e30 }, |
| 2487 | { 0x09, 0x01f0 }, |
| 2488 | { 0x0a, 0x5500 }, |
| 2489 | { 0x0c, 0x00c8 }, |
| 2490 | { 0x1f, 0x0003 }, |
| 2491 | { 0x12, 0xc096 }, |
| 2492 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2493 | { 0x1f, 0x0000 }, |
| 2494 | { 0x1f, 0x0000 }, |
| 2495 | { 0x09, 0x2000 }, |
| 2496 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2497 | }; |
| 2498 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2499 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2500 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2501 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2502 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2503 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2504 | } |
| 2505 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2506 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2507 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2508 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2509 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2510 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2511 | { 0x03, 0x802f }, |
| 2512 | { 0x02, 0x4f02 }, |
| 2513 | { 0x01, 0x0409 }, |
| 2514 | { 0x00, 0xf099 }, |
| 2515 | { 0x04, 0x9800 }, |
| 2516 | { 0x04, 0x9000 }, |
| 2517 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2518 | { 0x1f, 0x0002 }, |
| 2519 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2520 | { 0x06, 0x0761 }, |
| 2521 | { 0x1f, 0x0003 }, |
| 2522 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2523 | { 0x1f, 0x0000 } |
| 2524 | }; |
| 2525 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2526 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2527 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2528 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2529 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2530 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2531 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2532 | } |
| 2533 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2534 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2535 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2536 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2537 | { 0x1f, 0x0001 }, |
| 2538 | { 0x12, 0x2300 }, |
| 2539 | { 0x1d, 0x3d98 }, |
| 2540 | { 0x1f, 0x0002 }, |
| 2541 | { 0x0c, 0x7eb8 }, |
| 2542 | { 0x06, 0x5461 }, |
| 2543 | { 0x1f, 0x0003 }, |
| 2544 | { 0x16, 0x0f0a }, |
| 2545 | { 0x1f, 0x0000 } |
| 2546 | }; |
| 2547 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2548 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2549 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2550 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2551 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2552 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2553 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2554 | } |
| 2555 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2556 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2557 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2558 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2559 | } |
| 2560 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2561 | static const struct phy_reg rtl8168d_1_phy_reg_init_0[] = { |
| 2562 | /* Channel Estimation */ |
| 2563 | { 0x1f, 0x0001 }, |
| 2564 | { 0x06, 0x4064 }, |
| 2565 | { 0x07, 0x2863 }, |
| 2566 | { 0x08, 0x059c }, |
| 2567 | { 0x09, 0x26b4 }, |
| 2568 | { 0x0a, 0x6a19 }, |
| 2569 | { 0x0b, 0xdcc8 }, |
| 2570 | { 0x10, 0xf06d }, |
| 2571 | { 0x14, 0x7f68 }, |
| 2572 | { 0x18, 0x7fd9 }, |
| 2573 | { 0x1c, 0xf0ff }, |
| 2574 | { 0x1d, 0x3d9c }, |
| 2575 | { 0x1f, 0x0003 }, |
| 2576 | { 0x12, 0xf49f }, |
| 2577 | { 0x13, 0x070b }, |
| 2578 | { 0x1a, 0x05ad }, |
| 2579 | { 0x14, 0x94c0 }, |
| 2580 | |
| 2581 | /* |
| 2582 | * Tx Error Issue |
| 2583 | * Enhance line driver power |
| 2584 | */ |
| 2585 | { 0x1f, 0x0002 }, |
| 2586 | { 0x06, 0x5561 }, |
| 2587 | { 0x1f, 0x0005 }, |
| 2588 | { 0x05, 0x8332 }, |
| 2589 | { 0x06, 0x5561 }, |
| 2590 | |
| 2591 | /* |
| 2592 | * Can not link to 1Gbps with bad cable |
| 2593 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2594 | */ |
| 2595 | { 0x1f, 0x0001 }, |
| 2596 | { 0x17, 0x0cc0 }, |
| 2597 | |
| 2598 | { 0x1f, 0x0000 }, |
| 2599 | { 0x0d, 0xf880 } |
| 2600 | }; |
| 2601 | |
| 2602 | static const struct phy_reg rtl8168d_1_phy_reg_init_1[] = { |
| 2603 | { 0x1f, 0x0002 }, |
| 2604 | { 0x05, 0x669a }, |
| 2605 | { 0x1f, 0x0005 }, |
| 2606 | { 0x05, 0x8330 }, |
| 2607 | { 0x06, 0x669a }, |
| 2608 | { 0x1f, 0x0002 } |
| 2609 | }; |
| 2610 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2611 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2612 | { |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2613 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_0); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2614 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2615 | /* |
| 2616 | * Rx Error Issue |
| 2617 | * Fine Tune Switching regulator parameter |
| 2618 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2619 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2620 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2621 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2622 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2623 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2624 | int val; |
| 2625 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2626 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_1); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2627 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2628 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2629 | |
| 2630 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2631 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2632 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2633 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2634 | }; |
| 2635 | int i; |
| 2636 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2637 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2638 | |
| 2639 | val &= 0xff00; |
| 2640 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2641 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2642 | } |
| 2643 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2644 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2645 | { 0x1f, 0x0002 }, |
| 2646 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2647 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2648 | { 0x05, 0x8330 }, |
| 2649 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2650 | }; |
| 2651 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2652 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2653 | } |
| 2654 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2655 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2656 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2657 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2658 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2659 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2660 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2661 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2662 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2663 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2664 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2665 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2666 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2667 | |
| 2668 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2669 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2670 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2673 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2674 | { |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2675 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_0); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2676 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2677 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2678 | int val; |
| 2679 | |
Heiner Kallweit | fcb40e1 | 2019-05-25 20:57:42 +0200 | [diff] [blame] | 2680 | rtl_writephy_batch(tp, rtl8168d_1_phy_reg_init_1); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2681 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2682 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2683 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2684 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2685 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2686 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2687 | }; |
| 2688 | int i; |
| 2689 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2690 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2691 | |
| 2692 | val &= 0xff00; |
| 2693 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2694 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2695 | } |
| 2696 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2697 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2698 | { 0x1f, 0x0002 }, |
| 2699 | { 0x05, 0x2642 }, |
| 2700 | { 0x1f, 0x0005 }, |
| 2701 | { 0x05, 0x8330 }, |
| 2702 | { 0x06, 0x2642 } |
| 2703 | }; |
| 2704 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2705 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2708 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2709 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2710 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2711 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2712 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2713 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2714 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2715 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2716 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2717 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2718 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2719 | |
| 2720 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2721 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2722 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2725 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2726 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2727 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2728 | { 0x1f, 0x0002 }, |
| 2729 | { 0x10, 0x0008 }, |
| 2730 | { 0x0d, 0x006c }, |
| 2731 | |
| 2732 | { 0x1f, 0x0000 }, |
| 2733 | { 0x0d, 0xf880 }, |
| 2734 | |
| 2735 | { 0x1f, 0x0001 }, |
| 2736 | { 0x17, 0x0cc0 }, |
| 2737 | |
| 2738 | { 0x1f, 0x0001 }, |
| 2739 | { 0x0b, 0xa4d8 }, |
| 2740 | { 0x09, 0x281c }, |
| 2741 | { 0x07, 0x2883 }, |
| 2742 | { 0x0a, 0x6b35 }, |
| 2743 | { 0x1d, 0x3da4 }, |
| 2744 | { 0x1c, 0xeffd }, |
| 2745 | { 0x14, 0x7f52 }, |
| 2746 | { 0x18, 0x7fc6 }, |
| 2747 | { 0x08, 0x0601 }, |
| 2748 | { 0x06, 0x4063 }, |
| 2749 | { 0x10, 0xf074 }, |
| 2750 | { 0x1f, 0x0003 }, |
| 2751 | { 0x13, 0x0789 }, |
| 2752 | { 0x12, 0xf4bd }, |
| 2753 | { 0x1a, 0x04fd }, |
| 2754 | { 0x14, 0x84b0 }, |
| 2755 | { 0x1f, 0x0000 }, |
| 2756 | { 0x00, 0x9200 }, |
| 2757 | |
| 2758 | { 0x1f, 0x0005 }, |
| 2759 | { 0x01, 0x0340 }, |
| 2760 | { 0x1f, 0x0001 }, |
| 2761 | { 0x04, 0x4000 }, |
| 2762 | { 0x03, 0x1d21 }, |
| 2763 | { 0x02, 0x0c32 }, |
| 2764 | { 0x01, 0x0200 }, |
| 2765 | { 0x00, 0x5554 }, |
| 2766 | { 0x04, 0x4800 }, |
| 2767 | { 0x04, 0x4000 }, |
| 2768 | { 0x04, 0xf000 }, |
| 2769 | { 0x03, 0xdf01 }, |
| 2770 | { 0x02, 0xdf20 }, |
| 2771 | { 0x01, 0x101a }, |
| 2772 | { 0x00, 0xa0ff }, |
| 2773 | { 0x04, 0xf800 }, |
| 2774 | { 0x04, 0xf000 }, |
| 2775 | { 0x1f, 0x0000 }, |
| 2776 | |
| 2777 | { 0x1f, 0x0007 }, |
| 2778 | { 0x1e, 0x0023 }, |
| 2779 | { 0x16, 0x0000 }, |
| 2780 | { 0x1f, 0x0000 } |
| 2781 | }; |
| 2782 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2783 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2784 | } |
| 2785 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2786 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 2787 | { |
| 2788 | static const struct phy_reg phy_reg_init[] = { |
| 2789 | { 0x1f, 0x0001 }, |
| 2790 | { 0x17, 0x0cc0 }, |
| 2791 | |
| 2792 | { 0x1f, 0x0007 }, |
| 2793 | { 0x1e, 0x002d }, |
| 2794 | { 0x18, 0x0040 }, |
| 2795 | { 0x1f, 0x0000 } |
| 2796 | }; |
| 2797 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2798 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2799 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2800 | } |
| 2801 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2802 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2803 | { |
| 2804 | static const struct phy_reg phy_reg_init[] = { |
| 2805 | /* Enable Delay cap */ |
| 2806 | { 0x1f, 0x0005 }, |
| 2807 | { 0x05, 0x8b80 }, |
| 2808 | { 0x06, 0xc896 }, |
| 2809 | { 0x1f, 0x0000 }, |
| 2810 | |
| 2811 | /* Channel estimation fine tune */ |
| 2812 | { 0x1f, 0x0001 }, |
| 2813 | { 0x0b, 0x6c20 }, |
| 2814 | { 0x07, 0x2872 }, |
| 2815 | { 0x1c, 0xefff }, |
| 2816 | { 0x1f, 0x0003 }, |
| 2817 | { 0x14, 0x6420 }, |
| 2818 | { 0x1f, 0x0000 }, |
| 2819 | |
| 2820 | /* Update PFM & 10M TX idle timer */ |
| 2821 | { 0x1f, 0x0007 }, |
| 2822 | { 0x1e, 0x002f }, |
| 2823 | { 0x15, 0x1919 }, |
| 2824 | { 0x1f, 0x0000 }, |
| 2825 | |
| 2826 | { 0x1f, 0x0007 }, |
| 2827 | { 0x1e, 0x00ac }, |
| 2828 | { 0x18, 0x0006 }, |
| 2829 | { 0x1f, 0x0000 } |
| 2830 | }; |
| 2831 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2832 | rtl_apply_firmware(tp); |
| 2833 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2834 | rtl_writephy_batch(tp, phy_reg_init); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2835 | |
| 2836 | /* DCO enable for 10M IDLE Power */ |
| 2837 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2838 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2839 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2840 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2841 | |
| 2842 | /* For impedance matching */ |
| 2843 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2844 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2845 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2846 | |
| 2847 | /* PHY auto speed down */ |
| 2848 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2849 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2850 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2851 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2852 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2853 | |
| 2854 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2855 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2856 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2857 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2858 | |
| 2859 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2860 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2861 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2862 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2863 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2864 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2865 | rtl_writephy(tp, 0x1f, 0x0006); |
| 2866 | rtl_writephy(tp, 0x00, 0x5a00); |
| 2867 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2868 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2869 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2870 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2871 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2872 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2873 | } |
| 2874 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2875 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 2876 | { |
| 2877 | const u16 w[] = { |
| 2878 | addr[0] | (addr[1] << 8), |
| 2879 | addr[2] | (addr[3] << 8), |
| 2880 | addr[4] | (addr[5] << 8) |
| 2881 | }; |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2882 | |
Heiner Kallweit | 3aa4c49 | 2019-05-02 20:46:52 +0200 | [diff] [blame] | 2883 | rtl_eri_write(tp, 0xe0, ERIAR_MASK_1111, w[0] | (w[1] << 16)); |
| 2884 | rtl_eri_write(tp, 0xe4, ERIAR_MASK_1111, w[2]); |
| 2885 | rtl_eri_write(tp, 0xf0, ERIAR_MASK_1111, w[0] << 16); |
| 2886 | 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] | 2887 | } |
| 2888 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2889 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 2890 | { |
| 2891 | static const struct phy_reg phy_reg_init[] = { |
| 2892 | /* Enable Delay cap */ |
| 2893 | { 0x1f, 0x0004 }, |
| 2894 | { 0x1f, 0x0007 }, |
| 2895 | { 0x1e, 0x00ac }, |
| 2896 | { 0x18, 0x0006 }, |
| 2897 | { 0x1f, 0x0002 }, |
| 2898 | { 0x1f, 0x0000 }, |
| 2899 | { 0x1f, 0x0000 }, |
| 2900 | |
| 2901 | /* Channel estimation fine tune */ |
| 2902 | { 0x1f, 0x0003 }, |
| 2903 | { 0x09, 0xa20f }, |
| 2904 | { 0x1f, 0x0000 }, |
| 2905 | { 0x1f, 0x0000 }, |
| 2906 | |
| 2907 | /* Green Setting */ |
| 2908 | { 0x1f, 0x0005 }, |
| 2909 | { 0x05, 0x8b5b }, |
| 2910 | { 0x06, 0x9222 }, |
| 2911 | { 0x05, 0x8b6d }, |
| 2912 | { 0x06, 0x8000 }, |
| 2913 | { 0x05, 0x8b76 }, |
| 2914 | { 0x06, 0x8000 }, |
| 2915 | { 0x1f, 0x0000 } |
| 2916 | }; |
| 2917 | |
| 2918 | rtl_apply_firmware(tp); |
| 2919 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2920 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2921 | |
| 2922 | /* For 4-corner performance improve */ |
| 2923 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2924 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2925 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2926 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2927 | |
| 2928 | /* PHY auto speed down */ |
| 2929 | rtl_writephy(tp, 0x1f, 0x0004); |
| 2930 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2931 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2932 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2933 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2934 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2935 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2936 | |
| 2937 | /* improve 10M EEE waveform */ |
| 2938 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2939 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2940 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2941 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2942 | |
| 2943 | /* Improve 2-pair detection performance */ |
| 2944 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2945 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2946 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2947 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2948 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2949 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 2950 | rtl_enable_eee(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2951 | |
| 2952 | /* Green feature */ |
| 2953 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 2954 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 2955 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2956 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 2957 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2958 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 2959 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 2960 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 2961 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 2962 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2963 | } |
| 2964 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2965 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 2966 | { |
| 2967 | /* For 4-corner performance improve */ |
| 2968 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2969 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2970 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2971 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2972 | |
| 2973 | /* PHY auto speed down */ |
| 2974 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2975 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2976 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2977 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2978 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2979 | |
| 2980 | /* Improve 10M EEE waveform */ |
| 2981 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2982 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2983 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2984 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2985 | |
| 2986 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 2987 | rtl_enable_eee(tp); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 2988 | } |
| 2989 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2990 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 2991 | { |
| 2992 | static const struct phy_reg phy_reg_init[] = { |
| 2993 | /* Channel estimation fine tune */ |
| 2994 | { 0x1f, 0x0003 }, |
| 2995 | { 0x09, 0xa20f }, |
| 2996 | { 0x1f, 0x0000 }, |
| 2997 | |
| 2998 | /* Modify green table for giga & fnet */ |
| 2999 | { 0x1f, 0x0005 }, |
| 3000 | { 0x05, 0x8b55 }, |
| 3001 | { 0x06, 0x0000 }, |
| 3002 | { 0x05, 0x8b5e }, |
| 3003 | { 0x06, 0x0000 }, |
| 3004 | { 0x05, 0x8b67 }, |
| 3005 | { 0x06, 0x0000 }, |
| 3006 | { 0x05, 0x8b70 }, |
| 3007 | { 0x06, 0x0000 }, |
| 3008 | { 0x1f, 0x0000 }, |
| 3009 | { 0x1f, 0x0007 }, |
| 3010 | { 0x1e, 0x0078 }, |
| 3011 | { 0x17, 0x0000 }, |
| 3012 | { 0x19, 0x00fb }, |
| 3013 | { 0x1f, 0x0000 }, |
| 3014 | |
| 3015 | /* Modify green table for 10M */ |
| 3016 | { 0x1f, 0x0005 }, |
| 3017 | { 0x05, 0x8b79 }, |
| 3018 | { 0x06, 0xaa00 }, |
| 3019 | { 0x1f, 0x0000 }, |
| 3020 | |
| 3021 | /* Disable hiimpedance detection (RTCT) */ |
| 3022 | { 0x1f, 0x0003 }, |
| 3023 | { 0x01, 0x328a }, |
| 3024 | { 0x1f, 0x0000 } |
| 3025 | }; |
| 3026 | |
| 3027 | rtl_apply_firmware(tp); |
| 3028 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3029 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3030 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3031 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3032 | |
| 3033 | /* Improve 2-pair detection performance */ |
| 3034 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3035 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3036 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3037 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3038 | } |
| 3039 | |
| 3040 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3041 | { |
| 3042 | rtl_apply_firmware(tp); |
| 3043 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3044 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3045 | } |
| 3046 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3047 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3048 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3049 | static const struct phy_reg phy_reg_init[] = { |
| 3050 | /* Channel estimation fine tune */ |
| 3051 | { 0x1f, 0x0003 }, |
| 3052 | { 0x09, 0xa20f }, |
| 3053 | { 0x1f, 0x0000 }, |
| 3054 | |
| 3055 | /* Modify green table for giga & fnet */ |
| 3056 | { 0x1f, 0x0005 }, |
| 3057 | { 0x05, 0x8b55 }, |
| 3058 | { 0x06, 0x0000 }, |
| 3059 | { 0x05, 0x8b5e }, |
| 3060 | { 0x06, 0x0000 }, |
| 3061 | { 0x05, 0x8b67 }, |
| 3062 | { 0x06, 0x0000 }, |
| 3063 | { 0x05, 0x8b70 }, |
| 3064 | { 0x06, 0x0000 }, |
| 3065 | { 0x1f, 0x0000 }, |
| 3066 | { 0x1f, 0x0007 }, |
| 3067 | { 0x1e, 0x0078 }, |
| 3068 | { 0x17, 0x0000 }, |
| 3069 | { 0x19, 0x00aa }, |
| 3070 | { 0x1f, 0x0000 }, |
| 3071 | |
| 3072 | /* Modify green table for 10M */ |
| 3073 | { 0x1f, 0x0005 }, |
| 3074 | { 0x05, 0x8b79 }, |
| 3075 | { 0x06, 0xaa00 }, |
| 3076 | { 0x1f, 0x0000 }, |
| 3077 | |
| 3078 | /* Disable hiimpedance detection (RTCT) */ |
| 3079 | { 0x1f, 0x0003 }, |
| 3080 | { 0x01, 0x328a }, |
| 3081 | { 0x1f, 0x0000 } |
| 3082 | }; |
| 3083 | |
| 3084 | |
| 3085 | rtl_apply_firmware(tp); |
| 3086 | |
| 3087 | rtl8168f_hw_phy_config(tp); |
| 3088 | |
| 3089 | /* Improve 2-pair detection performance */ |
| 3090 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3091 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3092 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3093 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3094 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3095 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3096 | |
| 3097 | /* Modify green table for giga */ |
| 3098 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3099 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3100 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3101 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3102 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3103 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3104 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3105 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3106 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3107 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3108 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3109 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3110 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3111 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3112 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3113 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3114 | |
| 3115 | /* uc same-seed solution */ |
| 3116 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3117 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3118 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3119 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3120 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3121 | /* Green feature */ |
| 3122 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3123 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3124 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3125 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3126 | } |
| 3127 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3128 | static void rtl8168g_disable_aldps(struct rtl8169_private *tp) |
| 3129 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3130 | phy_modify_paged(tp->phydev, 0x0a43, 0x10, BIT(2), 0); |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3131 | } |
| 3132 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3133 | static void rtl8168g_phy_adjust_10m_aldps(struct rtl8169_private *tp) |
| 3134 | { |
| 3135 | struct phy_device *phydev = tp->phydev; |
| 3136 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3137 | phy_modify_paged(phydev, 0x0bcc, 0x14, BIT(8), 0); |
| 3138 | phy_modify_paged(phydev, 0x0a44, 0x11, 0, BIT(7) | BIT(6)); |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3139 | phy_write(phydev, 0x1f, 0x0a43); |
| 3140 | phy_write(phydev, 0x13, 0x8084); |
| 3141 | phy_clear_bits(phydev, 0x14, BIT(14) | BIT(13)); |
| 3142 | phy_set_bits(phydev, 0x10, BIT(12) | BIT(1) | BIT(0)); |
| 3143 | |
| 3144 | phy_write(phydev, 0x1f, 0x0000); |
| 3145 | } |
| 3146 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3147 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3148 | { |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3149 | int ret; |
| 3150 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3151 | rtl_apply_firmware(tp); |
| 3152 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3153 | ret = phy_read_paged(tp->phydev, 0x0a46, 0x10); |
| 3154 | if (ret & BIT(8)) |
| 3155 | phy_modify_paged(tp->phydev, 0x0bcc, 0x12, BIT(15), 0); |
| 3156 | else |
| 3157 | phy_modify_paged(tp->phydev, 0x0bcc, 0x12, 0, BIT(15)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3158 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3159 | ret = phy_read_paged(tp->phydev, 0x0a46, 0x13); |
| 3160 | if (ret & BIT(8)) |
Thomas Voegtle | 1a03bb5 | 2019-07-20 19:01:22 +0200 | [diff] [blame] | 3161 | phy_modify_paged(tp->phydev, 0x0c41, 0x15, 0, BIT(1)); |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3162 | else |
Thomas Voegtle | 1a03bb5 | 2019-07-20 19:01:22 +0200 | [diff] [blame] | 3163 | phy_modify_paged(tp->phydev, 0x0c41, 0x15, BIT(1), 0); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3164 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3165 | /* Enable PHY auto speed down */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3166 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(3) | BIT(2)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3167 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3168 | rtl8168g_phy_adjust_10m_aldps(tp); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3169 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3170 | /* EEE auto-fallback function */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3171 | phy_modify_paged(tp->phydev, 0x0a4b, 0x11, 0, BIT(2)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3172 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3173 | /* Enable UC LPF tune function */ |
| 3174 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3175 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3176 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3177 | |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3178 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3179 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3180 | /* Improve SWR Efficiency */ |
| 3181 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3182 | rtl_writephy(tp, 0x14, 0x5065); |
| 3183 | rtl_writephy(tp, 0x14, 0xd065); |
| 3184 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3185 | rtl_writephy(tp, 0x11, 0x5655); |
| 3186 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3187 | rtl_writephy(tp, 0x14, 0x1065); |
| 3188 | rtl_writephy(tp, 0x14, 0x9065); |
| 3189 | rtl_writephy(tp, 0x14, 0x1065); |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3190 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3191 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3192 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3193 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3194 | rtl_enable_eee(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3195 | } |
| 3196 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3197 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3198 | { |
| 3199 | rtl_apply_firmware(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3200 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3201 | rtl_enable_eee(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3204 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3205 | { |
| 3206 | u16 dout_tapbin; |
| 3207 | u32 data; |
| 3208 | |
| 3209 | rtl_apply_firmware(tp); |
| 3210 | |
| 3211 | /* CHN EST parameters adjust - giga master */ |
| 3212 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3213 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3214 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3215 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3216 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3217 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3218 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3219 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3220 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3221 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3222 | |
| 3223 | /* CHN EST parameters adjust - giga slave */ |
| 3224 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3225 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3226 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3227 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3228 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3229 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3230 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3231 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3232 | |
| 3233 | /* CHN EST parameters adjust - fnet */ |
| 3234 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3235 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3236 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3237 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3238 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3239 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3240 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3241 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3242 | |
| 3243 | /* enable R-tune & PGA-retune function */ |
| 3244 | dout_tapbin = 0; |
| 3245 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3246 | data = rtl_readphy(tp, 0x13); |
| 3247 | data &= 3; |
| 3248 | data <<= 2; |
| 3249 | dout_tapbin |= data; |
| 3250 | data = rtl_readphy(tp, 0x12); |
| 3251 | data &= 0xc000; |
| 3252 | data >>= 14; |
| 3253 | dout_tapbin |= data; |
| 3254 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3255 | dout_tapbin <<= 12; |
| 3256 | dout_tapbin &= 0xf000; |
| 3257 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3258 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3259 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3260 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3261 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3262 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3263 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3264 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3265 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3266 | |
| 3267 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3268 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3269 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3270 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3271 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3272 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3273 | |
| 3274 | /* enable GPHY 10M */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3275 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(11)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3276 | |
| 3277 | /* SAR ADC performance */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3278 | 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] | 3279 | |
| 3280 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3281 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3282 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3283 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3284 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3285 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3286 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3287 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3288 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3289 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3290 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3291 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3292 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3293 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3294 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3295 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3296 | |
| 3297 | /* disable phy pfm mode */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3298 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, BIT(7), 0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3299 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3300 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | b6cef26 | 2019-08-15 14:21:30 +0200 | [diff] [blame] | 3301 | rtl8168h_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3302 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3306 | { |
| 3307 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3308 | u16 rlen; |
| 3309 | u32 data; |
| 3310 | |
| 3311 | rtl_apply_firmware(tp); |
| 3312 | |
| 3313 | /* CHIN EST parameter update */ |
| 3314 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3315 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3316 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3317 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3318 | |
| 3319 | /* enable R-tune & PGA-retune function */ |
| 3320 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3321 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3322 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3323 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3324 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3325 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3326 | |
| 3327 | /* enable GPHY 10M */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3328 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, 0, BIT(11)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3329 | |
| 3330 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3331 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3332 | ioffset_p3 = ((data & 0x80)>>7); |
| 3333 | ioffset_p3 <<= 3; |
| 3334 | |
| 3335 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3336 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3337 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3338 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3339 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3340 | ioffset_p0 <<= 3; |
| 3341 | ioffset_p0 |= (data & (0x07)); |
| 3342 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3343 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3344 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3345 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3346 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3347 | rtl_writephy(tp, 0x16, data); |
| 3348 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3349 | } |
| 3350 | |
| 3351 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3352 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3353 | data = rtl_readphy(tp, 0x16); |
| 3354 | data &= 0x000f; |
| 3355 | rlen = 0; |
| 3356 | if (data > 3) |
| 3357 | rlen = data - 3; |
| 3358 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3359 | rtl_writephy(tp, 0x17, data); |
| 3360 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3361 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3362 | |
| 3363 | /* disable phy pfm mode */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3364 | phy_modify_paged(tp->phydev, 0x0a44, 0x11, BIT(7), 0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3365 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3366 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3367 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3368 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3369 | } |
| 3370 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3371 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3372 | { |
| 3373 | /* Enable PHY auto speed down */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3374 | 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] | 3375 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3376 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3377 | |
| 3378 | /* Enable EEE auto-fallback function */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3379 | phy_modify_paged(tp->phydev, 0x0a4b, 0x11, 0, BIT(2)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3380 | |
| 3381 | /* Enable UC LPF tune function */ |
| 3382 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3383 | rtl_writephy(tp, 0x13, 0x8012); |
| 3384 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3385 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3386 | |
| 3387 | /* set rg_sel_sdm_rate */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3388 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3389 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3390 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3391 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3392 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3396 | { |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3397 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3398 | |
| 3399 | /* Enable UC LPF tune function */ |
| 3400 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3401 | rtl_writephy(tp, 0x13, 0x8012); |
| 3402 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3403 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3404 | |
| 3405 | /* Set rg_sel_sdm_rate */ |
Heiner Kallweit | a2928d2 | 2019-06-02 10:53:49 +0200 | [diff] [blame] | 3406 | phy_modify_paged(tp->phydev, 0x0c42, 0x11, BIT(13), BIT(14)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3407 | |
| 3408 | /* Channel estimation parameters */ |
| 3409 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3410 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3411 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3412 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3413 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3414 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3415 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3416 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3417 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3418 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3419 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3420 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3421 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3422 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3423 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3424 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3425 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3426 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3427 | rtl_writephy(tp, 0x13, 0x8110); |
| 3428 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3429 | rtl_writephy(tp, 0x13, 0x810f); |
| 3430 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3431 | rtl_writephy(tp, 0x13, 0x8111); |
| 3432 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3433 | rtl_writephy(tp, 0x13, 0x8113); |
| 3434 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3435 | rtl_writephy(tp, 0x13, 0x8115); |
| 3436 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3437 | rtl_writephy(tp, 0x13, 0x810e); |
| 3438 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3439 | rtl_writephy(tp, 0x13, 0x810c); |
| 3440 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3441 | rtl_writephy(tp, 0x13, 0x810b); |
| 3442 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3443 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3444 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3445 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3446 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3447 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3448 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3449 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3450 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3451 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3452 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3453 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3454 | |
| 3455 | /* Force PWM-mode */ |
| 3456 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3457 | rtl_writephy(tp, 0x14, 0x5065); |
| 3458 | rtl_writephy(tp, 0x14, 0xd065); |
| 3459 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3460 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3461 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3462 | rtl_writephy(tp, 0x14, 0x1065); |
| 3463 | rtl_writephy(tp, 0x14, 0x9065); |
| 3464 | rtl_writephy(tp, 0x14, 0x1065); |
| 3465 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3466 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3467 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3468 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3469 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3470 | } |
| 3471 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3472 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3473 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3474 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3475 | { 0x1f, 0x0003 }, |
| 3476 | { 0x08, 0x441d }, |
| 3477 | { 0x01, 0x9100 }, |
| 3478 | { 0x1f, 0x0000 } |
| 3479 | }; |
| 3480 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3481 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3482 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3483 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3484 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3485 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3486 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3487 | } |
| 3488 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3489 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3490 | { |
| 3491 | static const struct phy_reg phy_reg_init[] = { |
| 3492 | { 0x1f, 0x0005 }, |
| 3493 | { 0x1a, 0x0000 }, |
| 3494 | { 0x1f, 0x0000 }, |
| 3495 | |
| 3496 | { 0x1f, 0x0004 }, |
| 3497 | { 0x1c, 0x0000 }, |
| 3498 | { 0x1f, 0x0000 }, |
| 3499 | |
| 3500 | { 0x1f, 0x0001 }, |
| 3501 | { 0x15, 0x7701 }, |
| 3502 | { 0x1f, 0x0000 } |
| 3503 | }; |
| 3504 | |
| 3505 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3506 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3507 | rtl_writephy(tp, 0x18, 0x0310); |
| 3508 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3509 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3510 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3511 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3512 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3513 | } |
| 3514 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3515 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3516 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3517 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3518 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3519 | rtl_writephy(tp, 0x18, 0x0310); |
| 3520 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3521 | |
| 3522 | rtl_apply_firmware(tp); |
| 3523 | |
| 3524 | /* EEE setting */ |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3525 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3526 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3527 | rtl_writephy(tp, 0x10, 0x401f); |
| 3528 | rtl_writephy(tp, 0x19, 0x7030); |
| 3529 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3530 | } |
| 3531 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3532 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3533 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3534 | static const struct phy_reg phy_reg_init[] = { |
| 3535 | { 0x1f, 0x0004 }, |
| 3536 | { 0x10, 0xc07f }, |
| 3537 | { 0x19, 0x7030 }, |
| 3538 | { 0x1f, 0x0000 } |
| 3539 | }; |
| 3540 | |
| 3541 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3542 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3543 | rtl_writephy(tp, 0x18, 0x0310); |
| 3544 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3545 | |
| 3546 | rtl_apply_firmware(tp); |
| 3547 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3548 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3549 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3550 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3551 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3552 | } |
| 3553 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3554 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3555 | { |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3556 | static const rtl_generic_fct phy_configs[] = { |
| 3557 | /* PCI devices. */ |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3558 | [RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config, |
| 3559 | [RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config, |
| 3560 | [RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config, |
| 3561 | [RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config, |
| 3562 | [RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config, |
| 3563 | /* PCI-E devices. */ |
| 3564 | [RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config, |
| 3565 | [RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config, |
| 3566 | [RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config, |
| 3567 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 3568 | [RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config, |
| 3569 | [RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config, |
| 3570 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 3571 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 3572 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 3573 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 3574 | [RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config, |
| 3575 | [RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config, |
| 3576 | [RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config, |
| 3577 | [RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config, |
| 3578 | [RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config, |
| 3579 | [RTL_GIGA_MAC_VER_22] = rtl8168c_4_hw_phy_config, |
| 3580 | [RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config, |
| 3581 | [RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config, |
| 3582 | [RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config, |
| 3583 | [RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config, |
| 3584 | [RTL_GIGA_MAC_VER_27] = rtl8168d_3_hw_phy_config, |
| 3585 | [RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config, |
| 3586 | [RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config, |
| 3587 | [RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config, |
| 3588 | [RTL_GIGA_MAC_VER_31] = NULL, |
| 3589 | [RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config, |
| 3590 | [RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config, |
| 3591 | [RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config, |
| 3592 | [RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config, |
| 3593 | [RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config, |
| 3594 | [RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config, |
| 3595 | [RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config, |
| 3596 | [RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config, |
| 3597 | [RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config, |
| 3598 | [RTL_GIGA_MAC_VER_41] = NULL, |
| 3599 | [RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config, |
| 3600 | [RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config, |
| 3601 | [RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config, |
| 3602 | [RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config, |
| 3603 | [RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config, |
| 3604 | [RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config, |
| 3605 | [RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config, |
| 3606 | [RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config, |
| 3607 | [RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config, |
| 3608 | [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config, |
| 3609 | }; |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3610 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3611 | |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3612 | if (phy_configs[tp->mac_version]) |
| 3613 | phy_configs[tp->mac_version](tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3614 | } |
| 3615 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3616 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3617 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3618 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3619 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3622 | 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] | 3623 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3624 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3625 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3626 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 7a67e11 | 2018-09-19 22:00:24 +0200 | [diff] [blame] | 3627 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 3628 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 3629 | netif_dbg(tp, drv, dev, |
| 3630 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3631 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3632 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3633 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 3634 | /* We may have called phy_speed_down before */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3635 | phy_speed_up(tp->phydev); |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 3636 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3637 | genphy_soft_reset(tp->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3638 | } |
| 3639 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3640 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 3641 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3642 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3643 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 3644 | rtl_unlock_config_regs(tp); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3645 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3646 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 3647 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3648 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3649 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 3650 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3651 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3652 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 3653 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3654 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 3655 | rtl_lock_config_regs(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3656 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3657 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 3661 | { |
| 3662 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 3663 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 3664 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3665 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 3666 | ret = eth_mac_addr(dev, p); |
| 3667 | if (ret) |
| 3668 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3669 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 3670 | pm_runtime_get_noresume(d); |
| 3671 | |
| 3672 | if (pm_runtime_active(d)) |
| 3673 | rtl_rar_set(tp, dev->dev_addr); |
| 3674 | |
| 3675 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3676 | |
| 3677 | return 0; |
| 3678 | } |
| 3679 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 3680 | 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] | 3681 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3682 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3683 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 3684 | if (!netif_running(dev)) |
| 3685 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 3686 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3687 | return phy_mii_ioctl(tp->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3688 | } |
| 3689 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3690 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 3691 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3692 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 3693 | case RTL_GIGA_MAC_VER_25: |
| 3694 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3695 | case RTL_GIGA_MAC_VER_29: |
| 3696 | case RTL_GIGA_MAC_VER_30: |
| 3697 | case RTL_GIGA_MAC_VER_32: |
| 3698 | case RTL_GIGA_MAC_VER_33: |
| 3699 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3700 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3701 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3702 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 3703 | break; |
| 3704 | default: |
| 3705 | break; |
| 3706 | } |
| 3707 | } |
| 3708 | |
Heiner Kallweit | 25e9411 | 2019-05-29 20:52:03 +0200 | [diff] [blame] | 3709 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3710 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 3711 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3712 | return; |
| 3713 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3714 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3715 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3716 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3717 | |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 3718 | if (device_may_wakeup(tp_to_dev(tp))) { |
| 3719 | phy_speed_down(tp->phydev, false); |
| 3720 | rtl_wol_suspend_quirk(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3721 | return; |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 3722 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3723 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3724 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3725 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3726 | case RTL_GIGA_MAC_VER_37: |
| 3727 | case RTL_GIGA_MAC_VER_39: |
| 3728 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 3729 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3730 | case RTL_GIGA_MAC_VER_45: |
| 3731 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3732 | case RTL_GIGA_MAC_VER_47: |
| 3733 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3734 | case RTL_GIGA_MAC_VER_50: |
| 3735 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3736 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3737 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3738 | case RTL_GIGA_MAC_VER_40: |
| 3739 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3740 | case RTL_GIGA_MAC_VER_49: |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 3741 | rtl_eri_clear_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3742 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3743 | break; |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 3744 | default: |
| 3745 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3746 | } |
| 3747 | } |
| 3748 | |
Heiner Kallweit | 25e9411 | 2019-05-29 20:52:03 +0200 | [diff] [blame] | 3749 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3750 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3751 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3752 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3753 | case RTL_GIGA_MAC_VER_37: |
| 3754 | case RTL_GIGA_MAC_VER_39: |
| 3755 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3756 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3757 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 3758 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3759 | case RTL_GIGA_MAC_VER_45: |
| 3760 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 3761 | case RTL_GIGA_MAC_VER_47: |
| 3762 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3763 | case RTL_GIGA_MAC_VER_50: |
| 3764 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3765 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3766 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3767 | case RTL_GIGA_MAC_VER_40: |
| 3768 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3769 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3770 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 3771 | rtl_eri_set_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 3772 | break; |
Heiner Kallweit | 76719ee | 2019-05-25 20:45:04 +0200 | [diff] [blame] | 3773 | default: |
| 3774 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 3777 | phy_resume(tp->phydev); |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 3778 | /* give MAC/PHY some time to resume */ |
| 3779 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3780 | } |
| 3781 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3782 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 3783 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3784 | switch (tp->mac_version) { |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 3785 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3786 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3787 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3788 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3789 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
Maciej S. Szmigiero | 511cfd5 | 2018-10-11 16:02:10 +0200 | [diff] [blame] | 3790 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36: |
| 3791 | case RTL_GIGA_MAC_VER_38: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3792 | 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] | 3793 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 3794 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3795 | 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] | 3796 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3797 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3798 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3799 | break; |
| 3800 | } |
| 3801 | } |
| 3802 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3803 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 3804 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 3805 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3806 | } |
| 3807 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3808 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3809 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3810 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 3811 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3812 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3816 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3817 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 3818 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3819 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3823 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3824 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3828 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3829 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3833 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3834 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 3835 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 3836 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3837 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3841 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3842 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 3843 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 3844 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3845 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3849 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3850 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 3851 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3855 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 3856 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 3857 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3861 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3862 | r8168b_0_hw_jumbo_enable(tp); |
| 3863 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3864 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3868 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3869 | r8168b_0_hw_jumbo_disable(tp); |
| 3870 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3871 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3872 | } |
| 3873 | |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3874 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3875 | { |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3876 | rtl_unlock_config_regs(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3877 | switch (tp->mac_version) { |
| 3878 | case RTL_GIGA_MAC_VER_11: |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3879 | r8168b_0_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3880 | break; |
| 3881 | case RTL_GIGA_MAC_VER_12: |
| 3882 | case RTL_GIGA_MAC_VER_17: |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3883 | r8168b_1_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3884 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3885 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26: |
| 3886 | r8168c_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3887 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3888 | case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28: |
| 3889 | r8168dp_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3890 | break; |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3891 | case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_34: |
| 3892 | r8168e_hw_jumbo_enable(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3893 | break; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3894 | default: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3895 | break; |
| 3896 | } |
Heiner Kallweit | 485bb1b | 2019-05-31 19:54:03 +0200 | [diff] [blame] | 3897 | rtl_lock_config_regs(tp); |
| 3898 | } |
| 3899 | |
| 3900 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3901 | { |
| 3902 | rtl_unlock_config_regs(tp); |
| 3903 | switch (tp->mac_version) { |
| 3904 | case RTL_GIGA_MAC_VER_11: |
| 3905 | r8168b_0_hw_jumbo_disable(tp); |
| 3906 | break; |
| 3907 | case RTL_GIGA_MAC_VER_12: |
| 3908 | case RTL_GIGA_MAC_VER_17: |
| 3909 | r8168b_1_hw_jumbo_disable(tp); |
| 3910 | break; |
| 3911 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26: |
| 3912 | r8168c_hw_jumbo_disable(tp); |
| 3913 | break; |
| 3914 | case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28: |
| 3915 | r8168dp_hw_jumbo_disable(tp); |
| 3916 | break; |
| 3917 | case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_34: |
| 3918 | r8168e_hw_jumbo_disable(tp); |
| 3919 | break; |
| 3920 | default: |
| 3921 | break; |
| 3922 | } |
| 3923 | rtl_lock_config_regs(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3924 | } |
| 3925 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3926 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 3927 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3928 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3929 | } |
| 3930 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3931 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 3932 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3933 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3934 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3935 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3936 | } |
| 3937 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 3938 | static void rtl_request_firmware(struct rtl8169_private *tp) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3939 | { |
| 3940 | struct rtl_fw *rtl_fw; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3941 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 3942 | /* firmware loaded already or no firmware available */ |
| 3943 | if (tp->rtl_fw || !tp->fw_name) |
| 3944 | return; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3945 | |
| 3946 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 3947 | if (!rtl_fw) { |
| 3948 | netif_warn(tp, ifup, tp->dev, "Unable to load firmware, out of memory\n"); |
| 3949 | return; |
| 3950 | } |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3951 | |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 3952 | rtl_fw->phy_write = rtl_writephy; |
| 3953 | rtl_fw->phy_read = rtl_readphy; |
| 3954 | rtl_fw->mac_mcu_write = mac_mcu_write; |
| 3955 | rtl_fw->mac_mcu_read = mac_mcu_read; |
Heiner Kallweit | 4edb00f | 2019-06-03 21:25:43 +0200 | [diff] [blame] | 3956 | rtl_fw->fw_name = tp->fw_name; |
| 3957 | rtl_fw->dev = tp_to_dev(tp); |
Heiner Kallweit | ce8843a | 2019-05-29 21:15:06 +0200 | [diff] [blame] | 3958 | |
Heiner Kallweit | 47ad593 | 2019-06-03 21:26:31 +0200 | [diff] [blame] | 3959 | if (rtl_fw_request_firmware(rtl_fw)) |
| 3960 | kfree(rtl_fw); |
| 3961 | else |
| 3962 | tp->rtl_fw = rtl_fw; |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3963 | } |
| 3964 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3965 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 3966 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3967 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3968 | } |
| 3969 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3970 | DECLARE_RTL_COND(rtl_npq_cond) |
| 3971 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3972 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 3976 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3977 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3978 | } |
| 3979 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3980 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | { |
| 3982 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 3983 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3985 | rtl_rx_close(tp); |
| 3986 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3987 | switch (tp->mac_version) { |
| 3988 | case RTL_GIGA_MAC_VER_27: |
| 3989 | case RTL_GIGA_MAC_VER_28: |
| 3990 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3991 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3992 | break; |
| 3993 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 3994 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3995 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3996 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 3997 | break; |
| 3998 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 3999 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4000 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4001 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4004 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4007 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4008 | { |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4009 | u32 val = TX_DMA_BURST << TxDMAShift | |
| 4010 | InterFrameGap << TxInterFrameGapShift; |
| 4011 | |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 4012 | if (rtl_is_8168evl_up(tp)) |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4013 | val |= TXCFG_AUTO_FIFO; |
| 4014 | |
| 4015 | RTL_W32(tp, TxConfig, val); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4016 | } |
| 4017 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4018 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4020 | /* Low hurts. Let's disable the filtering. */ |
| 4021 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4024 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4025 | { |
| 4026 | /* |
| 4027 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4028 | * register to be written before TxDescAddrLow to work. |
| 4029 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4030 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4031 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4032 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4033 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4034 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4035 | } |
| 4036 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4037 | 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] | 4038 | { |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4039 | u32 val; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4040 | |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4041 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4042 | val = 0x000fff00; |
| 4043 | else if (tp->mac_version == RTL_GIGA_MAC_VER_06) |
| 4044 | val = 0x00ffff00; |
| 4045 | else |
| 4046 | return; |
| 4047 | |
| 4048 | if (RTL_R8(tp, Config2) & PCI_Clock_66MHz) |
| 4049 | val |= 0xff; |
| 4050 | |
| 4051 | RTL_W32(tp, 0x7c, val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4054 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4055 | { |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4056 | u32 rx_mode = AcceptBroadcast | AcceptMyPhys | AcceptMulticast; |
| 4057 | /* Multicast hash filter */ |
| 4058 | u32 mc_filter[2] = { 0xffffffff, 0xffffffff }; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4059 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4060 | u32 tmp; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4061 | |
| 4062 | if (dev->flags & IFF_PROMISC) { |
| 4063 | /* Unconditionally log net taps. */ |
| 4064 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4065 | rx_mode |= AcceptAllPhys; |
| 4066 | } else if (netdev_mc_count(dev) > MC_FILTER_LIMIT || |
| 4067 | dev->flags & IFF_ALLMULTI || |
| 4068 | tp->mac_version == RTL_GIGA_MAC_VER_35) { |
| 4069 | /* accept all multicasts */ |
| 4070 | } else if (netdev_mc_empty(dev)) { |
| 4071 | rx_mode &= ~AcceptMulticast; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4072 | } else { |
| 4073 | struct netdev_hw_addr *ha; |
| 4074 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4075 | mc_filter[1] = mc_filter[0] = 0; |
| 4076 | netdev_for_each_mc_addr(ha, dev) { |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4077 | u32 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4078 | mc_filter[bit_nr >> 5] |= BIT(bit_nr & 31); |
| 4079 | } |
| 4080 | |
| 4081 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4082 | tmp = mc_filter[0]; |
| 4083 | mc_filter[0] = swab32(mc_filter[1]); |
| 4084 | mc_filter[1] = swab32(tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | if (dev->features & NETIF_F_RXALL) |
| 4089 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4090 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4091 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4092 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4093 | |
Heiner Kallweit | 81cd17a | 2019-07-24 23:34:45 +0200 | [diff] [blame] | 4094 | tmp = RTL_R32(tp, RxConfig); |
| 4095 | RTL_W32(tp, RxConfig, (tmp & ~RX_CONFIG_ACCEPT_MASK) | rx_mode); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4096 | } |
| 4097 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4098 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4099 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4100 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4101 | } |
| 4102 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4103 | 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] | 4104 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4105 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4106 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4107 | RTL_W32(tp, CSIDR, value); |
| 4108 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4109 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4110 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4111 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4112 | } |
| 4113 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4114 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4115 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4116 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4117 | |
| 4118 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4119 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4120 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4121 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4122 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4123 | } |
| 4124 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4125 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4126 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4127 | struct pci_dev *pdev = tp->pci_dev; |
| 4128 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4129 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4130 | /* According to Realtek the value at config space address 0x070f |
| 4131 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4132 | * first and if it fails fall back to CSI. |
| 4133 | */ |
| 4134 | if (pdev->cfg_size > 0x070f && |
| 4135 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4136 | return; |
| 4137 | |
| 4138 | netdev_notice_once(tp->dev, |
| 4139 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4140 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4141 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4142 | } |
| 4143 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4144 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4145 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4146 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | struct ephy_info { |
| 4150 | unsigned int offset; |
| 4151 | u16 mask; |
| 4152 | u16 bits; |
| 4153 | }; |
| 4154 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4155 | static void __rtl_ephy_init(struct rtl8169_private *tp, |
| 4156 | const struct ephy_info *e, int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4157 | { |
| 4158 | u16 w; |
| 4159 | |
| 4160 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4161 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4162 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4163 | e++; |
| 4164 | } |
| 4165 | } |
| 4166 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4167 | #define rtl_ephy_init(tp, a) __rtl_ephy_init(tp, a, ARRAY_SIZE(a)) |
| 4168 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4169 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4170 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4171 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4172 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4173 | } |
| 4174 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4175 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4176 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4177 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4178 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4181 | static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp) |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4182 | { |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4183 | /* work around an issue when PCI reset occurs during L2/L3 state */ |
| 4184 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4185 | } |
| 4186 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4187 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4188 | { |
Heiner Kallweit | 62b1b3b | 2019-06-18 23:14:50 +0200 | [diff] [blame] | 4189 | /* Don't enable ASPM in the chip if OS can't control ASPM */ |
| 4190 | if (enable && tp->aspm_manageable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4191 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4192 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4193 | } else { |
| 4194 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4195 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4196 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4197 | |
| 4198 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4199 | } |
| 4200 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4201 | static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat, |
| 4202 | u16 tx_stat, u16 rx_dyn, u16 tx_dyn) |
| 4203 | { |
| 4204 | /* Usage of dynamic vs. static FIFO is controlled by bit |
| 4205 | * TXCFG_AUTO_FIFO. Exact meaning of FIFO values isn't known. |
| 4206 | */ |
| 4207 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, (rx_stat << 16) | rx_dyn); |
| 4208 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, (tx_stat << 16) | tx_dyn); |
| 4209 | } |
| 4210 | |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4211 | static void rtl8168g_set_pause_thresholds(struct rtl8169_private *tp, |
| 4212 | u8 low, u8 high) |
| 4213 | { |
| 4214 | /* FIFO thresholds for pause flow control */ |
| 4215 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, low); |
| 4216 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, high); |
| 4217 | } |
| 4218 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4219 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4220 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4221 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4222 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4223 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4224 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4225 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4226 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4227 | } |
| 4228 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4229 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4230 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4231 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4232 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4233 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4234 | } |
| 4235 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4236 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4237 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4238 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4239 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4240 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4241 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4242 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4243 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4244 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4245 | rtl_disable_clock_request(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4246 | } |
| 4247 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4248 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4249 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4250 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4251 | { 0x01, 0, 0x0001 }, |
| 4252 | { 0x02, 0x0800, 0x1000 }, |
| 4253 | { 0x03, 0, 0x0042 }, |
| 4254 | { 0x06, 0x0080, 0x0000 }, |
| 4255 | { 0x07, 0, 0x2000 } |
| 4256 | }; |
| 4257 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4258 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4259 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4260 | rtl_ephy_init(tp, e_info_8168cp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4261 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4262 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4263 | } |
| 4264 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4265 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4266 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4267 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4268 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4269 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4270 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4271 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4272 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4273 | } |
| 4274 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4275 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4276 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4277 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4278 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4279 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4280 | |
| 4281 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4282 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4283 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4284 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4285 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4286 | } |
| 4287 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4288 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4289 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4290 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4291 | { 0x02, 0x0800, 0x1000 }, |
| 4292 | { 0x03, 0, 0x0002 }, |
| 4293 | { 0x06, 0x0080, 0x0000 } |
| 4294 | }; |
| 4295 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4296 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4297 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4298 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4299 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4300 | rtl_ephy_init(tp, e_info_8168c_1); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4301 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4302 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4303 | } |
| 4304 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4305 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4306 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4307 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4308 | { 0x01, 0, 0x0001 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4309 | { 0x03, 0x0400, 0x0020 } |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4310 | }; |
| 4311 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4312 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4313 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4314 | rtl_ephy_init(tp, e_info_8168c_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4315 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4316 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4317 | } |
| 4318 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4319 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4320 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4321 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4322 | } |
| 4323 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4324 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4325 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4326 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4327 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4328 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4329 | } |
| 4330 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4331 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4332 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4333 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4334 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4335 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4336 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4337 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4338 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4339 | } |
| 4340 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4341 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4342 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4343 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4344 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4345 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4346 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4347 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4348 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4351 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4352 | { |
| 4353 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4354 | { 0x0b, 0x0000, 0x0048 }, |
| 4355 | { 0x19, 0x0020, 0x0050 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4356 | { 0x0c, 0x0100, 0x0020 }, |
| 4357 | { 0x10, 0x0004, 0x0000 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4358 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4359 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4360 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4361 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4362 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4363 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4364 | rtl_ephy_init(tp, e_info_8168d_4); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4365 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4366 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4369 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4370 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4371 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4372 | { 0x00, 0x0200, 0x0100 }, |
| 4373 | { 0x00, 0x0000, 0x0004 }, |
| 4374 | { 0x06, 0x0002, 0x0001 }, |
| 4375 | { 0x06, 0x0000, 0x0030 }, |
| 4376 | { 0x07, 0x0000, 0x2000 }, |
| 4377 | { 0x00, 0x0000, 0x0020 }, |
| 4378 | { 0x03, 0x5800, 0x2000 }, |
| 4379 | { 0x03, 0x0000, 0x0001 }, |
| 4380 | { 0x01, 0x0800, 0x1000 }, |
| 4381 | { 0x07, 0x0000, 0x4000 }, |
| 4382 | { 0x1e, 0x0000, 0x2000 }, |
| 4383 | { 0x19, 0xffff, 0xfe6c }, |
| 4384 | { 0x0a, 0x0000, 0x0040 } |
| 4385 | }; |
| 4386 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4387 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4388 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4389 | rtl_ephy_init(tp, e_info_8168e_1); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4390 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4391 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4392 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4393 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4394 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4395 | |
| 4396 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4397 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4398 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4399 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4400 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4403 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4404 | { |
| 4405 | static const struct ephy_info e_info_8168e_2[] = { |
| 4406 | { 0x09, 0x0000, 0x0080 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4407 | { 0x19, 0x0000, 0x0224 }, |
| 4408 | { 0x00, 0x0000, 0x0004 }, |
| 4409 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4410 | }; |
| 4411 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4412 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4413 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4414 | rtl_ephy_init(tp, e_info_8168e_2); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4415 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4416 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4417 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4418 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4419 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4420 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4421 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4422 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 4423 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4424 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4425 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4426 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4427 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 4428 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4429 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4430 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 4431 | rtl8168_config_eee_mac(tp); |
| 4432 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4433 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 4434 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 4435 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 4436 | |
| 4437 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4438 | } |
| 4439 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4440 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4441 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4442 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4443 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4444 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4445 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4446 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4447 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4448 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4449 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4450 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
| 4451 | rtl_eri_set_bits(tp, 0x1d0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4452 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 4453 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4454 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4455 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 4456 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4457 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 4458 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 4459 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 4460 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 4461 | |
| 4462 | rtl8168_config_eee_mac(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4463 | } |
| 4464 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4465 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 4466 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4467 | static const struct ephy_info e_info_8168f_1[] = { |
| 4468 | { 0x06, 0x00c0, 0x0020 }, |
| 4469 | { 0x08, 0x0001, 0x0002 }, |
| 4470 | { 0x09, 0x0000, 0x0080 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4471 | { 0x19, 0x0000, 0x0224 }, |
| 4472 | { 0x00, 0x0000, 0x0004 }, |
| 4473 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4474 | }; |
| 4475 | |
| 4476 | rtl_hw_start_8168f(tp); |
| 4477 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4478 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4479 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4480 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4481 | } |
| 4482 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4483 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 4484 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4485 | static const struct ephy_info e_info_8168f_1[] = { |
| 4486 | { 0x06, 0x00c0, 0x0020 }, |
| 4487 | { 0x0f, 0xffff, 0x5200 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4488 | { 0x19, 0x0000, 0x0224 }, |
| 4489 | { 0x00, 0x0000, 0x0004 }, |
| 4490 | { 0x0c, 0x3df0, 0x0200 }, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4491 | }; |
| 4492 | |
| 4493 | rtl_hw_start_8168f(tp); |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4494 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4495 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4496 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4497 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4498 | rtl_eri_set_bits(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4499 | } |
| 4500 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4501 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4502 | { |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4503 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4504 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4505 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4506 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4507 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4508 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4509 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4510 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4511 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4512 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4513 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4514 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4515 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4516 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4517 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4518 | rtl8168_config_eee_mac(tp); |
| 4519 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4520 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4521 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4522 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4523 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4524 | } |
| 4525 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4526 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 4527 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4528 | static const struct ephy_info e_info_8168g_1[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4529 | { 0x00, 0x0008, 0x0000 }, |
| 4530 | { 0x0c, 0x3ff0, 0x0820 }, |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4531 | { 0x1e, 0x0000, 0x0001 }, |
| 4532 | { 0x19, 0x8000, 0x0000 } |
| 4533 | }; |
| 4534 | |
| 4535 | rtl_hw_start_8168g(tp); |
| 4536 | |
| 4537 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4538 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4539 | rtl_ephy_init(tp, e_info_8168g_1); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4540 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4541 | } |
| 4542 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4543 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 4544 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4545 | static const struct ephy_info e_info_8168g_2[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4546 | { 0x00, 0x0008, 0x0000 }, |
| 4547 | { 0x0c, 0x3ff0, 0x0820 }, |
| 4548 | { 0x19, 0xffff, 0x7c00 }, |
| 4549 | { 0x1e, 0xffff, 0x20eb }, |
| 4550 | { 0x0d, 0xffff, 0x1666 }, |
| 4551 | { 0x00, 0xffff, 0x10a3 }, |
| 4552 | { 0x06, 0xffff, 0xf050 }, |
| 4553 | { 0x04, 0x0000, 0x0010 }, |
| 4554 | { 0x1d, 0x4000, 0x0000 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4555 | }; |
| 4556 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4557 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4558 | |
| 4559 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4560 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4561 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4562 | rtl_ephy_init(tp, e_info_8168g_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4565 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 4566 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4567 | static const struct ephy_info e_info_8411_2[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4568 | { 0x00, 0x0008, 0x0000 }, |
| 4569 | { 0x0c, 0x37d0, 0x0820 }, |
| 4570 | { 0x1e, 0x0000, 0x0001 }, |
| 4571 | { 0x19, 0x8021, 0x0000 }, |
| 4572 | { 0x1e, 0x0000, 0x2000 }, |
| 4573 | { 0x0d, 0x0100, 0x0200 }, |
| 4574 | { 0x00, 0x0000, 0x0080 }, |
| 4575 | { 0x06, 0x0000, 0x0010 }, |
| 4576 | { 0x04, 0x0000, 0x0010 }, |
| 4577 | { 0x1d, 0x0000, 0x4000 }, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4578 | }; |
| 4579 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 4580 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4581 | |
| 4582 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4583 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4584 | rtl_ephy_init(tp, e_info_8411_2); |
Heiner Kallweit | fe4e8db0 | 2019-07-13 13:45:47 +0200 | [diff] [blame] | 4585 | |
| 4586 | /* The following Realtek-provided magic fixes an issue with the RX unit |
| 4587 | * getting confused after the PHY having been powered-down. |
| 4588 | */ |
| 4589 | r8168_mac_ocp_write(tp, 0xFC28, 0x0000); |
| 4590 | r8168_mac_ocp_write(tp, 0xFC2A, 0x0000); |
| 4591 | r8168_mac_ocp_write(tp, 0xFC2C, 0x0000); |
| 4592 | r8168_mac_ocp_write(tp, 0xFC2E, 0x0000); |
| 4593 | r8168_mac_ocp_write(tp, 0xFC30, 0x0000); |
| 4594 | r8168_mac_ocp_write(tp, 0xFC32, 0x0000); |
| 4595 | r8168_mac_ocp_write(tp, 0xFC34, 0x0000); |
| 4596 | r8168_mac_ocp_write(tp, 0xFC36, 0x0000); |
| 4597 | mdelay(3); |
| 4598 | r8168_mac_ocp_write(tp, 0xFC26, 0x0000); |
| 4599 | |
| 4600 | r8168_mac_ocp_write(tp, 0xF800, 0xE008); |
| 4601 | r8168_mac_ocp_write(tp, 0xF802, 0xE00A); |
| 4602 | r8168_mac_ocp_write(tp, 0xF804, 0xE00C); |
| 4603 | r8168_mac_ocp_write(tp, 0xF806, 0xE00E); |
| 4604 | r8168_mac_ocp_write(tp, 0xF808, 0xE027); |
| 4605 | r8168_mac_ocp_write(tp, 0xF80A, 0xE04F); |
| 4606 | r8168_mac_ocp_write(tp, 0xF80C, 0xE05E); |
| 4607 | r8168_mac_ocp_write(tp, 0xF80E, 0xE065); |
| 4608 | r8168_mac_ocp_write(tp, 0xF810, 0xC602); |
| 4609 | r8168_mac_ocp_write(tp, 0xF812, 0xBE00); |
| 4610 | r8168_mac_ocp_write(tp, 0xF814, 0x0000); |
| 4611 | r8168_mac_ocp_write(tp, 0xF816, 0xC502); |
| 4612 | r8168_mac_ocp_write(tp, 0xF818, 0xBD00); |
| 4613 | r8168_mac_ocp_write(tp, 0xF81A, 0x074C); |
| 4614 | r8168_mac_ocp_write(tp, 0xF81C, 0xC302); |
| 4615 | r8168_mac_ocp_write(tp, 0xF81E, 0xBB00); |
| 4616 | r8168_mac_ocp_write(tp, 0xF820, 0x080A); |
| 4617 | r8168_mac_ocp_write(tp, 0xF822, 0x6420); |
| 4618 | r8168_mac_ocp_write(tp, 0xF824, 0x48C2); |
| 4619 | r8168_mac_ocp_write(tp, 0xF826, 0x8C20); |
| 4620 | r8168_mac_ocp_write(tp, 0xF828, 0xC516); |
| 4621 | r8168_mac_ocp_write(tp, 0xF82A, 0x64A4); |
| 4622 | r8168_mac_ocp_write(tp, 0xF82C, 0x49C0); |
| 4623 | r8168_mac_ocp_write(tp, 0xF82E, 0xF009); |
| 4624 | r8168_mac_ocp_write(tp, 0xF830, 0x74A2); |
| 4625 | r8168_mac_ocp_write(tp, 0xF832, 0x8CA5); |
| 4626 | r8168_mac_ocp_write(tp, 0xF834, 0x74A0); |
| 4627 | r8168_mac_ocp_write(tp, 0xF836, 0xC50E); |
| 4628 | r8168_mac_ocp_write(tp, 0xF838, 0x9CA2); |
| 4629 | r8168_mac_ocp_write(tp, 0xF83A, 0x1C11); |
| 4630 | r8168_mac_ocp_write(tp, 0xF83C, 0x9CA0); |
| 4631 | r8168_mac_ocp_write(tp, 0xF83E, 0xE006); |
| 4632 | r8168_mac_ocp_write(tp, 0xF840, 0x74F8); |
| 4633 | r8168_mac_ocp_write(tp, 0xF842, 0x48C4); |
| 4634 | r8168_mac_ocp_write(tp, 0xF844, 0x8CF8); |
| 4635 | r8168_mac_ocp_write(tp, 0xF846, 0xC404); |
| 4636 | r8168_mac_ocp_write(tp, 0xF848, 0xBC00); |
| 4637 | r8168_mac_ocp_write(tp, 0xF84A, 0xC403); |
| 4638 | r8168_mac_ocp_write(tp, 0xF84C, 0xBC00); |
| 4639 | r8168_mac_ocp_write(tp, 0xF84E, 0x0BF2); |
| 4640 | r8168_mac_ocp_write(tp, 0xF850, 0x0C0A); |
| 4641 | r8168_mac_ocp_write(tp, 0xF852, 0xE434); |
| 4642 | r8168_mac_ocp_write(tp, 0xF854, 0xD3C0); |
| 4643 | r8168_mac_ocp_write(tp, 0xF856, 0x49D9); |
| 4644 | r8168_mac_ocp_write(tp, 0xF858, 0xF01F); |
| 4645 | r8168_mac_ocp_write(tp, 0xF85A, 0xC526); |
| 4646 | r8168_mac_ocp_write(tp, 0xF85C, 0x64A5); |
| 4647 | r8168_mac_ocp_write(tp, 0xF85E, 0x1400); |
| 4648 | r8168_mac_ocp_write(tp, 0xF860, 0xF007); |
| 4649 | r8168_mac_ocp_write(tp, 0xF862, 0x0C01); |
| 4650 | r8168_mac_ocp_write(tp, 0xF864, 0x8CA5); |
| 4651 | r8168_mac_ocp_write(tp, 0xF866, 0x1C15); |
| 4652 | r8168_mac_ocp_write(tp, 0xF868, 0xC51B); |
| 4653 | r8168_mac_ocp_write(tp, 0xF86A, 0x9CA0); |
| 4654 | r8168_mac_ocp_write(tp, 0xF86C, 0xE013); |
| 4655 | r8168_mac_ocp_write(tp, 0xF86E, 0xC519); |
| 4656 | r8168_mac_ocp_write(tp, 0xF870, 0x74A0); |
| 4657 | r8168_mac_ocp_write(tp, 0xF872, 0x48C4); |
| 4658 | r8168_mac_ocp_write(tp, 0xF874, 0x8CA0); |
| 4659 | r8168_mac_ocp_write(tp, 0xF876, 0xC516); |
| 4660 | r8168_mac_ocp_write(tp, 0xF878, 0x74A4); |
| 4661 | r8168_mac_ocp_write(tp, 0xF87A, 0x48C8); |
| 4662 | r8168_mac_ocp_write(tp, 0xF87C, 0x48CA); |
| 4663 | r8168_mac_ocp_write(tp, 0xF87E, 0x9CA4); |
| 4664 | r8168_mac_ocp_write(tp, 0xF880, 0xC512); |
| 4665 | r8168_mac_ocp_write(tp, 0xF882, 0x1B00); |
| 4666 | r8168_mac_ocp_write(tp, 0xF884, 0x9BA0); |
| 4667 | r8168_mac_ocp_write(tp, 0xF886, 0x1B1C); |
| 4668 | r8168_mac_ocp_write(tp, 0xF888, 0x483F); |
| 4669 | r8168_mac_ocp_write(tp, 0xF88A, 0x9BA2); |
| 4670 | r8168_mac_ocp_write(tp, 0xF88C, 0x1B04); |
| 4671 | r8168_mac_ocp_write(tp, 0xF88E, 0xC508); |
| 4672 | r8168_mac_ocp_write(tp, 0xF890, 0x9BA0); |
| 4673 | r8168_mac_ocp_write(tp, 0xF892, 0xC505); |
| 4674 | r8168_mac_ocp_write(tp, 0xF894, 0xBD00); |
| 4675 | r8168_mac_ocp_write(tp, 0xF896, 0xC502); |
| 4676 | r8168_mac_ocp_write(tp, 0xF898, 0xBD00); |
| 4677 | r8168_mac_ocp_write(tp, 0xF89A, 0x0300); |
| 4678 | r8168_mac_ocp_write(tp, 0xF89C, 0x051E); |
| 4679 | r8168_mac_ocp_write(tp, 0xF89E, 0xE434); |
| 4680 | r8168_mac_ocp_write(tp, 0xF8A0, 0xE018); |
| 4681 | r8168_mac_ocp_write(tp, 0xF8A2, 0xE092); |
| 4682 | r8168_mac_ocp_write(tp, 0xF8A4, 0xDE20); |
| 4683 | r8168_mac_ocp_write(tp, 0xF8A6, 0xD3C0); |
| 4684 | r8168_mac_ocp_write(tp, 0xF8A8, 0xC50F); |
| 4685 | r8168_mac_ocp_write(tp, 0xF8AA, 0x76A4); |
| 4686 | r8168_mac_ocp_write(tp, 0xF8AC, 0x49E3); |
| 4687 | r8168_mac_ocp_write(tp, 0xF8AE, 0xF007); |
| 4688 | r8168_mac_ocp_write(tp, 0xF8B0, 0x49C0); |
| 4689 | r8168_mac_ocp_write(tp, 0xF8B2, 0xF103); |
| 4690 | r8168_mac_ocp_write(tp, 0xF8B4, 0xC607); |
| 4691 | r8168_mac_ocp_write(tp, 0xF8B6, 0xBE00); |
| 4692 | r8168_mac_ocp_write(tp, 0xF8B8, 0xC606); |
| 4693 | r8168_mac_ocp_write(tp, 0xF8BA, 0xBE00); |
| 4694 | r8168_mac_ocp_write(tp, 0xF8BC, 0xC602); |
| 4695 | r8168_mac_ocp_write(tp, 0xF8BE, 0xBE00); |
| 4696 | r8168_mac_ocp_write(tp, 0xF8C0, 0x0C4C); |
| 4697 | r8168_mac_ocp_write(tp, 0xF8C2, 0x0C28); |
| 4698 | r8168_mac_ocp_write(tp, 0xF8C4, 0x0C2C); |
| 4699 | r8168_mac_ocp_write(tp, 0xF8C6, 0xDC00); |
| 4700 | r8168_mac_ocp_write(tp, 0xF8C8, 0xC707); |
| 4701 | r8168_mac_ocp_write(tp, 0xF8CA, 0x1D00); |
| 4702 | r8168_mac_ocp_write(tp, 0xF8CC, 0x8DE2); |
| 4703 | r8168_mac_ocp_write(tp, 0xF8CE, 0x48C1); |
| 4704 | r8168_mac_ocp_write(tp, 0xF8D0, 0xC502); |
| 4705 | r8168_mac_ocp_write(tp, 0xF8D2, 0xBD00); |
| 4706 | r8168_mac_ocp_write(tp, 0xF8D4, 0x00AA); |
| 4707 | r8168_mac_ocp_write(tp, 0xF8D6, 0xE0C0); |
| 4708 | r8168_mac_ocp_write(tp, 0xF8D8, 0xC502); |
| 4709 | r8168_mac_ocp_write(tp, 0xF8DA, 0xBD00); |
| 4710 | r8168_mac_ocp_write(tp, 0xF8DC, 0x0132); |
| 4711 | |
| 4712 | r8168_mac_ocp_write(tp, 0xFC26, 0x8000); |
| 4713 | |
| 4714 | r8168_mac_ocp_write(tp, 0xFC2A, 0x0743); |
| 4715 | r8168_mac_ocp_write(tp, 0xFC2C, 0x0801); |
| 4716 | r8168_mac_ocp_write(tp, 0xFC2E, 0x0BE9); |
| 4717 | r8168_mac_ocp_write(tp, 0xFC30, 0x02FD); |
| 4718 | r8168_mac_ocp_write(tp, 0xFC32, 0x0C25); |
| 4719 | r8168_mac_ocp_write(tp, 0xFC34, 0x00A9); |
| 4720 | r8168_mac_ocp_write(tp, 0xFC36, 0x012D); |
| 4721 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4722 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4723 | } |
| 4724 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4725 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 4726 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4727 | static const struct ephy_info e_info_8168h_1[] = { |
| 4728 | { 0x1e, 0x0800, 0x0001 }, |
| 4729 | { 0x1d, 0x0000, 0x0800 }, |
| 4730 | { 0x05, 0xffff, 0x2089 }, |
| 4731 | { 0x06, 0xffff, 0x5881 }, |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4732 | { 0x04, 0xffff, 0x854a }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4733 | { 0x01, 0xffff, 0x068b } |
| 4734 | }; |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4735 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4736 | |
| 4737 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4738 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4739 | rtl_ephy_init(tp, e_info_8168h_1); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4740 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4741 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4742 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4743 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4744 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4745 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4746 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4747 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4748 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4749 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4750 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_1111, BIT(4)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4751 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4752 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4753 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4754 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4755 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4756 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4757 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4758 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4759 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4760 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4761 | rtl8168_config_eee_mac(tp); |
| 4762 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4763 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4764 | 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] | 4765 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4766 | 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] | 4767 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4768 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4769 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4770 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4771 | |
| 4772 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 4773 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4774 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4775 | if (rg_saw_cnt > 0) { |
| 4776 | u16 sw_cnt_1ms_ini; |
| 4777 | |
| 4778 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 4779 | sw_cnt_1ms_ini &= 0x0fff; |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4780 | r8168_mac_ocp_modify(tp, 0xd412, 0x0fff, sw_cnt_1ms_ini); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4781 | } |
| 4782 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4783 | r8168_mac_ocp_modify(tp, 0xe056, 0x00f0, 0x0070); |
| 4784 | r8168_mac_ocp_modify(tp, 0xe052, 0x6000, 0x8008); |
| 4785 | r8168_mac_ocp_modify(tp, 0xe0d6, 0x01ff, 0x017f); |
| 4786 | r8168_mac_ocp_modify(tp, 0xd420, 0x0fff, 0x047f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4787 | |
| 4788 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 4789 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 4790 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 4791 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4792 | |
| 4793 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4794 | } |
| 4795 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4796 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 4797 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 4798 | rtl8168ep_stop_cmac(tp); |
| 4799 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4800 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4801 | rtl8168g_set_pause_thresholds(tp, 0x2f, 0x5f); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4802 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4803 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4804 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4805 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4806 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4807 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4808 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4809 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f80); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4810 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4811 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4812 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4813 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4814 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4815 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4816 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4817 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 4818 | rtl8168_config_eee_mac(tp); |
| 4819 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4820 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4821 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4822 | 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] | 4823 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4824 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 4828 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4829 | static const struct ephy_info e_info_8168ep_1[] = { |
| 4830 | { 0x00, 0xffff, 0x10ab }, |
| 4831 | { 0x06, 0xffff, 0xf030 }, |
| 4832 | { 0x08, 0xffff, 0x2006 }, |
| 4833 | { 0x0d, 0xffff, 0x1666 }, |
| 4834 | { 0x0c, 0x3ff0, 0x0000 } |
| 4835 | }; |
| 4836 | |
| 4837 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4838 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4839 | rtl_ephy_init(tp, e_info_8168ep_1); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4840 | |
| 4841 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4842 | |
| 4843 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 4847 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4848 | static const struct ephy_info e_info_8168ep_2[] = { |
| 4849 | { 0x00, 0xffff, 0x10a3 }, |
| 4850 | { 0x19, 0xffff, 0xfc00 }, |
| 4851 | { 0x1e, 0xffff, 0x20ea } |
| 4852 | }; |
| 4853 | |
| 4854 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4855 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4856 | rtl_ephy_init(tp, e_info_8168ep_2); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4857 | |
| 4858 | rtl_hw_start_8168ep(tp); |
| 4859 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4860 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4861 | 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] | 4862 | |
| 4863 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 4867 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4868 | static const struct ephy_info e_info_8168ep_3[] = { |
Heiner Kallweit | a7a92cf | 2019-08-04 09:52:33 +0200 | [diff] [blame] | 4869 | { 0x00, 0x0000, 0x0080 }, |
| 4870 | { 0x0d, 0x0100, 0x0200 }, |
| 4871 | { 0x19, 0x8021, 0x0000 }, |
| 4872 | { 0x1e, 0x0000, 0x2000 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4873 | }; |
| 4874 | |
| 4875 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4876 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4877 | rtl_ephy_init(tp, e_info_8168ep_3); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4878 | |
| 4879 | rtl_hw_start_8168ep(tp); |
| 4880 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4881 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 4882 | 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] | 4883 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 4884 | r8168_mac_ocp_modify(tp, 0xd3e2, 0x0fff, 0x0271); |
| 4885 | r8168_mac_ocp_modify(tp, 0xd3e4, 0x00ff, 0x0000); |
| 4886 | r8168_mac_ocp_modify(tp, 0xe860, 0x0000, 0x0080); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4887 | |
| 4888 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4889 | } |
| 4890 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4891 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4892 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4893 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4894 | { 0x01, 0, 0x6e65 }, |
| 4895 | { 0x02, 0, 0x091f }, |
| 4896 | { 0x03, 0, 0xc2f9 }, |
| 4897 | { 0x06, 0, 0xafb5 }, |
| 4898 | { 0x07, 0, 0x0e00 }, |
| 4899 | { 0x19, 0, 0xec80 }, |
| 4900 | { 0x01, 0, 0x2e65 }, |
| 4901 | { 0x01, 0, 0x6e65 } |
| 4902 | }; |
| 4903 | u8 cfg1; |
| 4904 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4905 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4906 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4907 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4908 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4909 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4910 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4911 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4912 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4913 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4914 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4915 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4916 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4917 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4918 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4919 | rtl_ephy_init(tp, e_info_8102e_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4920 | } |
| 4921 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4922 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4923 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4924 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4925 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4926 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4927 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4928 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 4929 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4930 | } |
| 4931 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4932 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4933 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4934 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4935 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4936 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4937 | } |
| 4938 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4939 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4940 | { |
| 4941 | static const struct ephy_info e_info_8105e_1[] = { |
| 4942 | { 0x07, 0, 0x4000 }, |
| 4943 | { 0x19, 0, 0x0200 }, |
| 4944 | { 0x19, 0, 0x0020 }, |
| 4945 | { 0x1e, 0, 0x2000 }, |
| 4946 | { 0x03, 0, 0x0001 }, |
| 4947 | { 0x19, 0, 0x0100 }, |
| 4948 | { 0x19, 0, 0x0004 }, |
| 4949 | { 0x0a, 0, 0x0020 } |
| 4950 | }; |
| 4951 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4952 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4953 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4954 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4955 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4956 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4957 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4958 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 4959 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4960 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4961 | rtl_ephy_init(tp, e_info_8105e_1); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4962 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4963 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4964 | } |
| 4965 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4966 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4967 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4968 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4969 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4970 | } |
| 4971 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4972 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 4973 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4974 | static const struct ephy_info e_info_8402[] = { |
| 4975 | { 0x19, 0xffff, 0xff64 }, |
| 4976 | { 0x1e, 0, 0x4000 } |
| 4977 | }; |
| 4978 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4979 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4980 | |
| 4981 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4982 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4983 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4984 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4985 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4986 | rtl_ephy_init(tp, e_info_8402); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4987 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4988 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4989 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4990 | rtl_set_fifo_size(tp, 0x00, 0x00, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 4991 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 4992 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 4993 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
| 4994 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4995 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4996 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4997 | } |
| 4998 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4999 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5000 | { |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5001 | rtl_hw_aspm_clkreq_enable(tp, false); |
| 5002 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5003 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5004 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5005 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5006 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5007 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5008 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5009 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5010 | rtl_pcie_state_l2l3_disable(tp); |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5011 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5012 | } |
| 5013 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5014 | static void rtl_hw_config(struct rtl8169_private *tp) |
| 5015 | { |
| 5016 | static const rtl_generic_fct hw_configs[] = { |
| 5017 | [RTL_GIGA_MAC_VER_07] = rtl_hw_start_8102e_1, |
| 5018 | [RTL_GIGA_MAC_VER_08] = rtl_hw_start_8102e_3, |
| 5019 | [RTL_GIGA_MAC_VER_09] = rtl_hw_start_8102e_2, |
| 5020 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 5021 | [RTL_GIGA_MAC_VER_11] = rtl_hw_start_8168bb, |
| 5022 | [RTL_GIGA_MAC_VER_12] = rtl_hw_start_8168bef, |
| 5023 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 5024 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 5025 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 5026 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 5027 | [RTL_GIGA_MAC_VER_17] = rtl_hw_start_8168bef, |
| 5028 | [RTL_GIGA_MAC_VER_18] = rtl_hw_start_8168cp_1, |
| 5029 | [RTL_GIGA_MAC_VER_19] = rtl_hw_start_8168c_1, |
| 5030 | [RTL_GIGA_MAC_VER_20] = rtl_hw_start_8168c_2, |
| 5031 | [RTL_GIGA_MAC_VER_21] = rtl_hw_start_8168c_3, |
| 5032 | [RTL_GIGA_MAC_VER_22] = rtl_hw_start_8168c_4, |
| 5033 | [RTL_GIGA_MAC_VER_23] = rtl_hw_start_8168cp_2, |
| 5034 | [RTL_GIGA_MAC_VER_24] = rtl_hw_start_8168cp_3, |
| 5035 | [RTL_GIGA_MAC_VER_25] = rtl_hw_start_8168d, |
| 5036 | [RTL_GIGA_MAC_VER_26] = rtl_hw_start_8168d, |
| 5037 | [RTL_GIGA_MAC_VER_27] = rtl_hw_start_8168d, |
| 5038 | [RTL_GIGA_MAC_VER_28] = rtl_hw_start_8168d_4, |
| 5039 | [RTL_GIGA_MAC_VER_29] = rtl_hw_start_8105e_1, |
| 5040 | [RTL_GIGA_MAC_VER_30] = rtl_hw_start_8105e_2, |
| 5041 | [RTL_GIGA_MAC_VER_31] = rtl_hw_start_8168dp, |
| 5042 | [RTL_GIGA_MAC_VER_32] = rtl_hw_start_8168e_1, |
| 5043 | [RTL_GIGA_MAC_VER_33] = rtl_hw_start_8168e_1, |
| 5044 | [RTL_GIGA_MAC_VER_34] = rtl_hw_start_8168e_2, |
| 5045 | [RTL_GIGA_MAC_VER_35] = rtl_hw_start_8168f_1, |
| 5046 | [RTL_GIGA_MAC_VER_36] = rtl_hw_start_8168f_1, |
| 5047 | [RTL_GIGA_MAC_VER_37] = rtl_hw_start_8402, |
| 5048 | [RTL_GIGA_MAC_VER_38] = rtl_hw_start_8411, |
| 5049 | [RTL_GIGA_MAC_VER_39] = rtl_hw_start_8106, |
| 5050 | [RTL_GIGA_MAC_VER_40] = rtl_hw_start_8168g_1, |
| 5051 | [RTL_GIGA_MAC_VER_41] = rtl_hw_start_8168g_1, |
| 5052 | [RTL_GIGA_MAC_VER_42] = rtl_hw_start_8168g_2, |
| 5053 | [RTL_GIGA_MAC_VER_43] = rtl_hw_start_8168g_2, |
| 5054 | [RTL_GIGA_MAC_VER_44] = rtl_hw_start_8411_2, |
| 5055 | [RTL_GIGA_MAC_VER_45] = rtl_hw_start_8168h_1, |
| 5056 | [RTL_GIGA_MAC_VER_46] = rtl_hw_start_8168h_1, |
| 5057 | [RTL_GIGA_MAC_VER_47] = rtl_hw_start_8168h_1, |
| 5058 | [RTL_GIGA_MAC_VER_48] = rtl_hw_start_8168h_1, |
| 5059 | [RTL_GIGA_MAC_VER_49] = rtl_hw_start_8168ep_1, |
| 5060 | [RTL_GIGA_MAC_VER_50] = rtl_hw_start_8168ep_2, |
| 5061 | [RTL_GIGA_MAC_VER_51] = rtl_hw_start_8168ep_3, |
| 5062 | }; |
| 5063 | |
| 5064 | if (hw_configs[tp->mac_version]) |
| 5065 | hw_configs[tp->mac_version](tp); |
| 5066 | } |
| 5067 | |
| 5068 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
| 5069 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5070 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5071 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5072 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5073 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5074 | |
Heiner Kallweit | 272b226 | 2019-06-14 07:55:21 +0200 | [diff] [blame] | 5075 | if (rtl_is_8168evl_up(tp)) |
| 5076 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
| 5077 | else |
| 5078 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5079 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5080 | rtl_hw_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5083 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
| 5084 | { |
| 5085 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 5086 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 5087 | |
| 5088 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
| 5089 | |
| 5090 | tp->cp_cmd |= PCIMulRW; |
| 5091 | |
| 5092 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5093 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
| 5094 | netif_dbg(tp, drv, tp->dev, |
| 5095 | "Set MAC Reg C+CR Offset 0xe0. Bit 3 and Bit 14 MUST be 1\n"); |
| 5096 | tp->cp_cmd |= (1 << 14); |
| 5097 | } |
| 5098 | |
| 5099 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 5100 | |
| 5101 | rtl8169_set_magic_reg(tp, tp->mac_version); |
| 5102 | |
| 5103 | RTL_W32(tp, RxMissed, 0); |
| 5104 | } |
| 5105 | |
| 5106 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 5107 | { |
| 5108 | rtl_unlock_config_regs(tp); |
| 5109 | |
| 5110 | tp->cp_cmd &= CPCMD_MASK; |
| 5111 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 5112 | |
| 5113 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 5114 | rtl_hw_start_8169(tp); |
| 5115 | else |
| 5116 | rtl_hw_start_8168(tp); |
| 5117 | |
| 5118 | rtl_set_rx_max_size(tp); |
| 5119 | rtl_set_rx_tx_desc_registers(tp); |
| 5120 | rtl_lock_config_regs(tp); |
| 5121 | |
| 5122 | /* disable interrupt coalescing */ |
| 5123 | RTL_W16(tp, IntrMitigate, 0x0000); |
| 5124 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5125 | RTL_R8(tp, IntrMask); |
| 5126 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5127 | rtl_init_rxcfg(tp); |
| 5128 | rtl_set_tx_config_registers(tp); |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5129 | rtl_set_rx_mode(tp->dev); |
Heiner Kallweit | 6c19156e29 | 2019-06-10 18:23:30 +0200 | [diff] [blame] | 5130 | rtl_irq_enable(tp); |
| 5131 | } |
| 5132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5134 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5135 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5136 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5137 | if (new_mtu > ETH_DATA_LEN) |
| 5138 | rtl_hw_jumbo_enable(tp); |
| 5139 | else |
| 5140 | rtl_hw_jumbo_disable(tp); |
| 5141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5143 | netdev_update_features(dev); |
| 5144 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5145 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5149 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5150 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5152 | } |
| 5153 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5154 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | { |
| 5156 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5157 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5158 | /* Force memory writes to complete before releasing descriptor */ |
| 5159 | dma_wmb(); |
| 5160 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5161 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | } |
| 5163 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5164 | static struct page *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5165 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5166 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5167 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5168 | int node = dev_to_node(d); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5169 | dma_addr_t mapping; |
| 5170 | struct page *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5171 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5172 | 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] | 5173 | if (!data) |
| 5174 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5175 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5176 | 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] | 5177 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5178 | if (net_ratelimit()) |
| 5179 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5180 | __free_pages(data, get_order(R8169_RX_BUF_SIZE)); |
| 5181 | return NULL; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5184 | desc->addr = cpu_to_le64(mapping); |
| 5185 | rtl8169_mark_to_asic(desc); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5186 | |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5187 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5191 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5192 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | |
Heiner Kallweit | eb2e7f0 | 2019-08-09 22:59:07 +0200 | [diff] [blame] | 5194 | for (i = 0; i < NUM_RX_DESC && tp->Rx_databuff[i]; i++) { |
| 5195 | dma_unmap_page(tp_to_dev(tp), |
| 5196 | le64_to_cpu(tp->RxDescArray[i].addr), |
| 5197 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
| 5198 | __free_pages(tp->Rx_databuff[i], get_order(R8169_RX_BUF_SIZE)); |
| 5199 | tp->Rx_databuff[i] = NULL; |
| 5200 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5204 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5206 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5207 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5208 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5209 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5210 | { |
| 5211 | unsigned int i; |
| 5212 | |
| 5213 | for (i = 0; i < NUM_RX_DESC; i++) { |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5214 | struct page *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5215 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5216 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5217 | if (!data) { |
| 5218 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5219 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5220 | } |
| 5221 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5224 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5225 | return 0; |
| 5226 | |
| 5227 | err_out: |
| 5228 | rtl8169_rx_clear(tp); |
| 5229 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | } |
| 5231 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5232 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5233 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | rtl8169_init_ring_indexes(tp); |
| 5235 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5236 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5237 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5239 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5242 | 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] | 5243 | struct TxDesc *desc) |
| 5244 | { |
| 5245 | unsigned int len = tx_skb->len; |
| 5246 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5247 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | desc->opts1 = 0x00; |
| 5250 | desc->opts2 = 0x00; |
| 5251 | desc->addr = 0x00; |
| 5252 | tx_skb->len = 0; |
| 5253 | } |
| 5254 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5255 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5256 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | { |
| 5258 | unsigned int i; |
| 5259 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5260 | for (i = 0; i < n; i++) { |
| 5261 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5263 | unsigned int len = tx_skb->len; |
| 5264 | |
| 5265 | if (len) { |
| 5266 | struct sk_buff *skb = tx_skb->skb; |
| 5267 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5268 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5269 | tp->TxDescArray + entry); |
| 5270 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5271 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | tx_skb->skb = NULL; |
| 5273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | } |
| 5275 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5279 | { |
| 5280 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | tp->cur_tx = tp->dirty_tx = 0; |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5282 | netdev_reset_queue(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5283 | } |
| 5284 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5285 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5287 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5288 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5289 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5290 | napi_disable(&tp->napi); |
| 5291 | netif_stop_queue(dev); |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 5292 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5294 | rtl8169_hw_reset(tp); |
| 5295 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5296 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5297 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5300 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5302 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5303 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5304 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5308 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5309 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5310 | |
| 5311 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5314 | static __le32 rtl8169_get_txd_opts1(u32 opts0, u32 len, unsigned int entry) |
| 5315 | { |
| 5316 | u32 status = opts0 | len; |
| 5317 | |
| 5318 | if (entry == NUM_TX_DESC - 1) |
| 5319 | status |= RingEnd; |
| 5320 | |
| 5321 | return cpu_to_le32(status); |
| 5322 | } |
| 5323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | 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] | 5325 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | { |
| 5327 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5328 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5329 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5330 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | |
| 5332 | entry = tp->cur_tx; |
| 5333 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5334 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5335 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5336 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | void *addr; |
| 5338 | |
| 5339 | entry = (entry + 1) % NUM_TX_DESC; |
| 5340 | |
| 5341 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5342 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5343 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5344 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5345 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5346 | if (net_ratelimit()) |
| 5347 | netif_err(tp, drv, tp->dev, |
| 5348 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5349 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5352 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5353 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | txd->addr = cpu_to_le64(mapping); |
| 5355 | |
| 5356 | tp->tx_skb[entry].len = len; |
| 5357 | } |
| 5358 | |
| 5359 | if (cur_frag) { |
| 5360 | tp->tx_skb[entry].skb = skb; |
| 5361 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5362 | } |
| 5363 | |
| 5364 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5365 | |
| 5366 | err_out: |
| 5367 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5368 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5371 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5372 | { |
| 5373 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5374 | } |
| 5375 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5376 | /* msdn_giant_send_check() |
| 5377 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5378 | * packet length for IPv6 TCP large packets. |
| 5379 | */ |
| 5380 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 5381 | { |
| 5382 | const struct ipv6hdr *ipv6h; |
| 5383 | struct tcphdr *th; |
| 5384 | int ret; |
| 5385 | |
| 5386 | ret = skb_cow_head(skb, 0); |
| 5387 | if (ret) |
| 5388 | return ret; |
| 5389 | |
| 5390 | ipv6h = ipv6_hdr(skb); |
| 5391 | th = tcp_hdr(skb); |
| 5392 | |
| 5393 | th->check = 0; |
| 5394 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 5395 | |
| 5396 | return ret; |
| 5397 | } |
| 5398 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5399 | static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5401 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5403 | if (mss) { |
| 5404 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5405 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 5406 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5407 | const struct iphdr *ip = ip_hdr(skb); |
| 5408 | |
| 5409 | if (ip->protocol == IPPROTO_TCP) |
| 5410 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 5411 | else if (ip->protocol == IPPROTO_UDP) |
| 5412 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 5413 | else |
| 5414 | WARN_ON_ONCE(1); |
| 5415 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 5419 | struct sk_buff *skb, u32 *opts) |
| 5420 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5421 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5422 | u32 mss = skb_shinfo(skb)->gso_size; |
| 5423 | |
| 5424 | if (mss) { |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5425 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5426 | case htons(ETH_P_IP): |
| 5427 | opts[0] |= TD1_GTSENV4; |
| 5428 | break; |
| 5429 | |
| 5430 | case htons(ETH_P_IPV6): |
| 5431 | if (msdn_giant_send_check(skb)) |
| 5432 | return false; |
| 5433 | |
| 5434 | opts[0] |= TD1_GTSENV6; |
| 5435 | break; |
| 5436 | |
| 5437 | default: |
| 5438 | WARN_ON_ONCE(1); |
| 5439 | break; |
| 5440 | } |
| 5441 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5442 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5443 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5444 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5445 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5447 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5448 | case htons(ETH_P_IP): |
| 5449 | opts[1] |= TD1_IPv4_CS; |
| 5450 | ip_protocol = ip_hdr(skb)->protocol; |
| 5451 | break; |
| 5452 | |
| 5453 | case htons(ETH_P_IPV6): |
| 5454 | opts[1] |= TD1_IPv6_CS; |
| 5455 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 5456 | break; |
| 5457 | |
| 5458 | default: |
| 5459 | ip_protocol = IPPROTO_RAW; |
| 5460 | break; |
| 5461 | } |
| 5462 | |
| 5463 | if (ip_protocol == IPPROTO_TCP) |
| 5464 | opts[1] |= TD1_TCP_CS; |
| 5465 | else if (ip_protocol == IPPROTO_UDP) |
| 5466 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5467 | else |
| 5468 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5469 | |
| 5470 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5471 | } else { |
| 5472 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 5473 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5475 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5476 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5479 | static bool rtl_tx_slots_avail(struct rtl8169_private *tp, |
| 5480 | unsigned int nr_frags) |
| 5481 | { |
| 5482 | unsigned int slots_avail = tp->dirty_tx + NUM_TX_DESC - tp->cur_tx; |
| 5483 | |
| 5484 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 5485 | return slots_avail > nr_frags; |
| 5486 | } |
| 5487 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5488 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 5489 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 5490 | { |
| 5491 | switch (tp->mac_version) { |
| 5492 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
| 5493 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 5494 | return false; |
| 5495 | default: |
| 5496 | return true; |
| 5497 | } |
| 5498 | } |
| 5499 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5500 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5501 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | { |
| 5503 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5504 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5506 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5508 | u32 opts[2], len; |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5509 | bool stop_queue; |
| 5510 | bool door_bell; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5511 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5512 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5513 | if (unlikely(!rtl_tx_slots_avail(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5514 | 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] | 5515 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5519 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | |
Heiner Kallweit | 355f948 | 2019-06-06 07:49:17 +0200 | [diff] [blame] | 5521 | opts[1] = rtl8169_tx_vlan_tag(skb); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5522 | opts[0] = DescOwn; |
| 5523 | |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5524 | if (rtl_chip_supports_csum_v2(tp)) { |
Heiner Kallweit | 96ea772 | 2019-07-26 21:50:34 +0200 | [diff] [blame] | 5525 | if (!rtl8169_tso_csum_v2(tp, skb, opts)) |
| 5526 | goto err_dma_0; |
Heiner Kallweit | 87945b6 | 2019-05-31 19:55:11 +0200 | [diff] [blame] | 5527 | } else { |
| 5528 | rtl8169_tso_csum_v1(skb, opts); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5529 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5530 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5531 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5532 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5533 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5534 | if (net_ratelimit()) |
| 5535 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5536 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | |
| 5539 | tp->tx_skb[entry].len = len; |
| 5540 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5542 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5543 | if (frags < 0) |
| 5544 | goto err_dma_1; |
| 5545 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5546 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5547 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5548 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5549 | tp->tx_skb[entry].skb = skb; |
| 5550 | } |
| 5551 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5552 | txd->opts2 = cpu_to_le32(opts[1]); |
| 5553 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 5554 | skb_tx_timestamp(skb); |
| 5555 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5556 | /* Force memory writes to complete before releasing descriptor */ |
| 5557 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5559 | door_bell = __netdev_sent_queue(dev, skb->len, netdev_xmit_more()); |
| 5560 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5561 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5563 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5564 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5566 | tp->cur_tx += frags + 1; |
| 5567 | |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5568 | stop_queue = !rtl_tx_slots_avail(tp, MAX_SKB_FRAGS); |
| 5569 | if (unlikely(stop_queue)) { |
Heiner Kallweit | 0255d59 | 2019-02-10 15:28:04 +0100 | [diff] [blame] | 5570 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 5571 | * not miss a ring update when it notices a stopped queue. |
| 5572 | */ |
| 5573 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5574 | netif_stop_queue(dev); |
Heiner Kallweit | 4773f9b | 2019-08-12 20:47:40 +0200 | [diff] [blame] | 5575 | door_bell = true; |
Heiner Kallweit | ef14358 | 2019-07-28 11:25:19 +0200 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | if (door_bell) |
| 5579 | RTL_W8(tp, TxPoll, NPQ); |
| 5580 | |
| 5581 | if (unlikely(stop_queue)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5582 | /* Sync with rtl_tx: |
| 5583 | * - publish queue status and cur_tx ring index (write barrier) |
| 5584 | * - refresh dirty_tx ring index (read barrier). |
| 5585 | * May the current thread have a pessimistic view of the ring |
| 5586 | * status and forget to wake up queue, a racing rtl_tx thread |
| 5587 | * can't. |
| 5588 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5589 | smp_mb(); |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5590 | if (rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) |
Heiner Kallweit | 601ed4d | 2019-03-21 21:41:48 +0100 | [diff] [blame] | 5591 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5594 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5595 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5596 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5597 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5598 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 5599 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5600 | dev->stats.tx_dropped++; |
| 5601 | return NETDEV_TX_OK; |
| 5602 | |
| 5603 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5605 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5606 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | } |
| 5608 | |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 5609 | static netdev_features_t rtl8169_features_check(struct sk_buff *skb, |
| 5610 | struct net_device *dev, |
| 5611 | netdev_features_t features) |
| 5612 | { |
| 5613 | int transport_offset = skb_transport_offset(skb); |
| 5614 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5615 | |
| 5616 | if (skb_is_gso(skb)) { |
| 5617 | if (transport_offset > GTTCPHO_MAX && |
| 5618 | rtl_chip_supports_csum_v2(tp)) |
| 5619 | features &= ~NETIF_F_ALL_TSO; |
| 5620 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5621 | if (skb->len < ETH_ZLEN) { |
| 5622 | switch (tp->mac_version) { |
| 5623 | case RTL_GIGA_MAC_VER_11: |
| 5624 | case RTL_GIGA_MAC_VER_12: |
| 5625 | case RTL_GIGA_MAC_VER_17: |
| 5626 | case RTL_GIGA_MAC_VER_34: |
| 5627 | features &= ~NETIF_F_CSUM_MASK; |
| 5628 | break; |
| 5629 | default: |
| 5630 | break; |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | if (transport_offset > TCPHO_MAX && |
| 5635 | rtl_chip_supports_csum_v2(tp)) |
| 5636 | features &= ~NETIF_F_CSUM_MASK; |
| 5637 | } |
| 5638 | |
| 5639 | return vlan_features_check(skb, features); |
| 5640 | } |
| 5641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 5643 | { |
| 5644 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5645 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5646 | u16 pci_status, pci_cmd; |
| 5647 | |
| 5648 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 5649 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 5650 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5651 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 5652 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | |
| 5654 | /* |
| 5655 | * The recovery sequence below admits a very elaborated explanation: |
| 5656 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5657 | * - I did not see what else could be done; |
| 5658 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | * |
| 5660 | * Feel free to adjust to your needs. |
| 5661 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 5662 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5663 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 5664 | else |
| 5665 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 5666 | |
| 5667 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5668 | |
| 5669 | pci_write_config_word(pdev, PCI_STATUS, |
| 5670 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 5671 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 5672 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 5673 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 5674 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5677 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, |
| 5678 | int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5680 | unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | dirty_tx = tp->dirty_tx; |
| 5683 | smp_rmb(); |
| 5684 | tx_left = tp->cur_tx - dirty_tx; |
| 5685 | |
| 5686 | while (tx_left > 0) { |
| 5687 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 5688 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | u32 status; |
| 5690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 5692 | if (status & DescOwn) |
| 5693 | break; |
| 5694 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5695 | /* This barrier is needed to keep us from reading |
| 5696 | * any other fields out of the Tx descriptor until |
| 5697 | * we know the status of DescOwn |
| 5698 | */ |
| 5699 | dma_rmb(); |
| 5700 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5701 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5702 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | if (status & LastFrag) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5704 | pkts_compl++; |
| 5705 | bytes_compl += tx_skb->skb->len; |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5706 | napi_consume_skb(tx_skb->skb, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | tx_skb->skb = NULL; |
| 5708 | } |
| 5709 | dirty_tx++; |
| 5710 | tx_left--; |
| 5711 | } |
| 5712 | |
| 5713 | if (tp->dirty_tx != dirty_tx) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5714 | netdev_completed_queue(dev, pkts_compl, bytes_compl); |
| 5715 | |
| 5716 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 5717 | tp->tx_stats.packets += pkts_compl; |
| 5718 | tp->tx_stats.bytes += bytes_compl; |
| 5719 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 5720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5722 | /* Sync with rtl8169_start_xmit: |
| 5723 | * - publish dirty_tx ring index (write barrier) |
| 5724 | * - refresh cur_tx ring index and queue status (read barrier) |
| 5725 | * May the current thread miss the stopped queue condition, |
| 5726 | * a racing xmit thread can only have a right view of the |
| 5727 | * ring status. |
| 5728 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5729 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | if (netif_queue_stopped(dev) && |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5731 | rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | netif_wake_queue(dev); |
| 5733 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5734 | /* |
| 5735 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 5736 | * too close. Let's kick an extra TxPoll request when a burst |
| 5737 | * of start_xmit activity is detected (if it is not detected, |
| 5738 | * it is slow enough). -- FR |
| 5739 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5740 | if (tp->cur_tx != dirty_tx) |
| 5741 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | } |
| 5744 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5745 | static inline int rtl8169_fragmented_frame(u32 status) |
| 5746 | { |
| 5747 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 5748 | } |
| 5749 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5750 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | u32 status = opts1 & RxProtoMask; |
| 5753 | |
| 5754 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 5755 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5757 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5758 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5761 | 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] | 5762 | { |
| 5763 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5764 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5766 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 5768 | 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] | 5769 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5770 | const void *rx_buf = page_address(tp->Rx_databuff[entry]); |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5771 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5772 | u32 status; |
| 5773 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 5774 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | if (status & DescOwn) |
| 5776 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5777 | |
| 5778 | /* This barrier is needed to keep us from reading |
| 5779 | * any other fields out of the Rx descriptor until |
| 5780 | * we know the status of DescOwn |
| 5781 | */ |
| 5782 | dma_rmb(); |
| 5783 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5784 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5785 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 5786 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5787 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5789 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5791 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 5792 | if (status & (RxRUNT | RxCRC) && !(status & RxRWT) && |
| 5793 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 5794 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 5795 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5796 | } else { |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5797 | unsigned int pkt_size; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5798 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 5799 | |
| 5800 | process_pkt: |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5801 | pkt_size = status & GENMASK(13, 0); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 5802 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5803 | pkt_size -= ETH_FCS_LEN; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5804 | /* |
| 5805 | * The driver does not support incoming fragmented |
| 5806 | * frames. They are seen as a symptom of over-mtu |
| 5807 | * sized frames. |
| 5808 | */ |
| 5809 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5810 | dev->stats.rx_dropped++; |
| 5811 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5812 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5813 | } |
| 5814 | |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5815 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
| 5816 | if (unlikely(!skb)) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5817 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5818 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | } |
| 5820 | |
Heiner Kallweit | 3c95e50 | 2019-08-26 22:52:36 +0200 | [diff] [blame] | 5821 | dma_sync_single_for_cpu(tp_to_dev(tp), |
| 5822 | le64_to_cpu(desc->addr), |
| 5823 | pkt_size, DMA_FROM_DEVICE); |
Heiner Kallweit | 32879f0 | 2019-08-07 21:38:22 +0200 | [diff] [blame] | 5824 | prefetch(rx_buf); |
| 5825 | skb_copy_to_linear_data(skb, rx_buf, pkt_size); |
Heiner Kallweit | fcd4e60 | 2019-07-22 22:01:15 +0200 | [diff] [blame] | 5826 | skb->tail += pkt_size; |
| 5827 | skb->len = pkt_size; |
| 5828 | |
Heiner Kallweit | d4ed746 | 2019-08-23 20:07:26 +0200 | [diff] [blame] | 5829 | dma_sync_single_for_device(tp_to_dev(tp), |
| 5830 | le64_to_cpu(desc->addr), |
| 5831 | pkt_size, DMA_FROM_DEVICE); |
| 5832 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5833 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | skb->protocol = eth_type_trans(skb, dev); |
| 5835 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 5836 | rtl8169_rx_vlan_tag(desc, skb); |
| 5837 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 5838 | if (skb->pkt_type == PACKET_MULTICAST) |
| 5839 | dev->stats.multicast++; |
| 5840 | |
Heiner Kallweit | 448a241 | 2019-04-03 19:54:12 +0200 | [diff] [blame] | 5841 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 5843 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 5844 | tp->rx_stats.packets++; |
| 5845 | tp->rx_stats.bytes += pkt_size; |
| 5846 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 5848 | release_descriptor: |
| 5849 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5850 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | count = cur_rx - tp->cur_rx; |
| 5854 | tp->cur_rx = cur_rx; |
| 5855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5856 | return count; |
| 5857 | } |
| 5858 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5859 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5860 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 5861 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame^] | 5862 | u32 status = rtl_get_events(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5863 | |
Heiner Kallweit | c1d532d | 2019-08-28 22:24:13 +0200 | [diff] [blame^] | 5864 | if (!tp->irq_enabled || (status & 0xffff) == 0xffff || |
| 5865 | !(status & tp->irq_mask)) |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 5866 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5867 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5868 | if (unlikely(status & SYSErr)) { |
| 5869 | rtl8169_pcierr_interrupt(tp->dev); |
| 5870 | goto out; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5871 | } |
| 5872 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5873 | if (status & LinkChg) |
| 5874 | phy_mac_interrupt(tp->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5875 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5876 | if (unlikely(status & RxFIFOOver && |
| 5877 | tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
| 5878 | netif_stop_queue(tp->dev); |
| 5879 | /* XXX - Hack alert. See rtl_task(). */ |
| 5880 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
| 5881 | } |
| 5882 | |
Heiner Kallweit | e62b2fd | 2019-04-14 11:48:39 +0200 | [diff] [blame] | 5883 | rtl_irq_disable(tp); |
| 5884 | napi_schedule_irqoff(&tp->napi); |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 5885 | out: |
| 5886 | rtl_ack_events(tp, status); |
| 5887 | |
| 5888 | return IRQ_HANDLED; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5889 | } |
| 5890 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5891 | static void rtl_task(struct work_struct *work) |
| 5892 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5893 | static const struct { |
| 5894 | int bitnr; |
| 5895 | void (*action)(struct rtl8169_private *); |
| 5896 | } rtl_work[] = { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5897 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5898 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5899 | struct rtl8169_private *tp = |
| 5900 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5901 | struct net_device *dev = tp->dev; |
| 5902 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5903 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5904 | rtl_lock_work(tp); |
| 5905 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 5906 | if (!netif_running(dev) || |
| 5907 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5908 | goto out_unlock; |
| 5909 | |
| 5910 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 5911 | bool pending; |
| 5912 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5913 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5914 | if (pending) |
| 5915 | rtl_work[i].action(tp); |
| 5916 | } |
| 5917 | |
| 5918 | out_unlock: |
| 5919 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5920 | } |
| 5921 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5922 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5923 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5924 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 5925 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 5926 | int work_done; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5927 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 5928 | work_done = rtl_rx(dev, tp, (u32) budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5929 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 5930 | rtl_tx(dev, tp, budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5931 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5932 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 5933 | napi_complete_done(napi, work_done); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 5934 | rtl_irq_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5937 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5940 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5941 | { |
| 5942 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5943 | |
| 5944 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 5945 | return; |
| 5946 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5947 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 5948 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5949 | } |
| 5950 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5951 | static void r8169_phylink_handler(struct net_device *ndev) |
| 5952 | { |
| 5953 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 5954 | |
| 5955 | if (netif_carrier_ok(ndev)) { |
| 5956 | rtl_link_chg_patch(tp); |
| 5957 | pm_request_resume(&tp->pci_dev->dev); |
| 5958 | } else { |
| 5959 | pm_runtime_idle(&tp->pci_dev->dev); |
| 5960 | } |
| 5961 | |
| 5962 | if (net_ratelimit()) |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5963 | phy_print_status(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 5967 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5968 | struct phy_device *phydev = tp->phydev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5969 | phy_interface_t phy_mode; |
| 5970 | int ret; |
| 5971 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 5972 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5973 | PHY_INTERFACE_MODE_MII; |
| 5974 | |
| 5975 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 5976 | phy_mode); |
| 5977 | if (ret) |
| 5978 | return ret; |
| 5979 | |
Heiner Kallweit | 66058b1 | 2019-07-27 12:32:28 +0200 | [diff] [blame] | 5980 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5981 | phy_set_max_speed(phydev, SPEED_100); |
| 5982 | |
Heiner Kallweit | 9cf9b84 | 2019-05-04 12:01:03 +0200 | [diff] [blame] | 5983 | phy_support_asym_pause(phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5984 | |
| 5985 | phy_attached_info(phydev); |
| 5986 | |
| 5987 | return 0; |
| 5988 | } |
| 5989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | static void rtl8169_down(struct net_device *dev) |
| 5991 | { |
| 5992 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 5994 | phy_stop(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 5995 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5996 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5997 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5999 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6000 | /* |
| 6001 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6002 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6003 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6004 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6005 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6007 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 6008 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | rtl8169_tx_clear(tp); |
| 6011 | |
| 6012 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6013 | |
| 6014 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | static int rtl8169_close(struct net_device *dev) |
| 6018 | { |
| 6019 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6020 | struct pci_dev *pdev = tp->pci_dev; |
| 6021 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6022 | pm_runtime_get_sync(&pdev->dev); |
| 6023 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6024 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6025 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6026 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6027 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6028 | /* Clear all task flags */ |
| 6029 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6032 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6033 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6034 | cancel_work_sync(&tp->wk.work); |
| 6035 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6036 | phy_disconnect(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6037 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6038 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6039 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6040 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6041 | tp->RxPhyAddr); |
| 6042 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6043 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | tp->TxDescArray = NULL; |
| 6045 | tp->RxDescArray = NULL; |
| 6046 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6047 | pm_runtime_put_sync(&pdev->dev); |
| 6048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6049 | return 0; |
| 6050 | } |
| 6051 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6052 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6053 | static void rtl8169_netpoll(struct net_device *dev) |
| 6054 | { |
| 6055 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6056 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6057 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6058 | } |
| 6059 | #endif |
| 6060 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6061 | static int rtl_open(struct net_device *dev) |
| 6062 | { |
| 6063 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6064 | struct pci_dev *pdev = tp->pci_dev; |
| 6065 | int retval = -ENOMEM; |
| 6066 | |
| 6067 | pm_runtime_get_sync(&pdev->dev); |
| 6068 | |
| 6069 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6070 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6071 | * dma_alloc_coherent provides more. |
| 6072 | */ |
| 6073 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6074 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6075 | if (!tp->TxDescArray) |
| 6076 | goto err_pm_runtime_put; |
| 6077 | |
| 6078 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6079 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6080 | if (!tp->RxDescArray) |
| 6081 | goto err_free_tx_0; |
| 6082 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6083 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6084 | if (retval < 0) |
| 6085 | goto err_free_rx_1; |
| 6086 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6087 | rtl_request_firmware(tp); |
| 6088 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6089 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6090 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6091 | if (retval < 0) |
| 6092 | goto err_release_fw_2; |
| 6093 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6094 | retval = r8169_phy_connect(tp); |
| 6095 | if (retval) |
| 6096 | goto err_free_irq; |
| 6097 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6098 | rtl_lock_work(tp); |
| 6099 | |
| 6100 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6101 | |
| 6102 | napi_enable(&tp->napi); |
| 6103 | |
| 6104 | rtl8169_init_phy(dev, tp); |
| 6105 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6106 | rtl_pll_power_up(tp); |
| 6107 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6108 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6109 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6110 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6111 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6112 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6113 | phy_start(tp->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6114 | netif_start_queue(dev); |
| 6115 | |
| 6116 | rtl_unlock_work(tp); |
| 6117 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6118 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6119 | out: |
| 6120 | return retval; |
| 6121 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6122 | err_free_irq: |
| 6123 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6124 | err_release_fw_2: |
| 6125 | rtl_release_firmware(tp); |
| 6126 | rtl8169_rx_clear(tp); |
| 6127 | err_free_rx_1: |
| 6128 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6129 | tp->RxPhyAddr); |
| 6130 | tp->RxDescArray = NULL; |
| 6131 | err_free_tx_0: |
| 6132 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6133 | tp->TxPhyAddr); |
| 6134 | tp->TxDescArray = NULL; |
| 6135 | err_pm_runtime_put: |
| 6136 | pm_runtime_put_noidle(&pdev->dev); |
| 6137 | goto out; |
| 6138 | } |
| 6139 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6140 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6141 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | { |
| 6143 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6144 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6145 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6146 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6147 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6148 | pm_runtime_get_noresume(&pdev->dev); |
| 6149 | |
| 6150 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6151 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6152 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6153 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6154 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6155 | stats->rx_packets = tp->rx_stats.packets; |
| 6156 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6157 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6158 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6159 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6160 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6161 | stats->tx_packets = tp->tx_stats.packets; |
| 6162 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6163 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6164 | |
| 6165 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6166 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6167 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6168 | stats->rx_errors = dev->stats.rx_errors; |
| 6169 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6170 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6171 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6172 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6173 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6174 | /* |
Corentin Musard | ed72a9b | 2019-07-24 14:34:43 +0200 | [diff] [blame] | 6175 | * Fetch additional counter values missing in stats collected by driver |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6176 | * from tally counters. |
| 6177 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6178 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6179 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6180 | |
| 6181 | /* |
| 6182 | * Subtract values fetched during initalization. |
| 6183 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6184 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6185 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6186 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6187 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6188 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6189 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6190 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6191 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6192 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6195 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6196 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6197 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6198 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6199 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6200 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6201 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6202 | phy_stop(tp->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6203 | netif_device_detach(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6204 | |
| 6205 | rtl_lock_work(tp); |
| 6206 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6207 | /* Clear all task flags */ |
| 6208 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6209 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6210 | rtl_unlock_work(tp); |
| 6211 | |
| 6212 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6213 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6214 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6215 | #ifdef CONFIG_PM |
| 6216 | |
| 6217 | static int rtl8169_suspend(struct device *device) |
| 6218 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6219 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6220 | struct rtl8169_private *tp = netdev_priv(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6221 | |
| 6222 | rtl8169_net_suspend(dev); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6223 | clk_disable_unprepare(tp->clk); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6224 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6225 | return 0; |
| 6226 | } |
| 6227 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6228 | static void __rtl8169_resume(struct net_device *dev) |
| 6229 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6230 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6231 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6232 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6233 | |
| 6234 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6235 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6236 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6237 | phy_start(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6238 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6239 | rtl_lock_work(tp); |
| 6240 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6241 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Heiner Kallweit | 58ba566 | 2019-01-19 22:06:25 +0100 | [diff] [blame] | 6242 | rtl_reset_work(tp); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6243 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6244 | } |
| 6245 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6246 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6247 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6248 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6249 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6250 | |
Heiner Kallweit | 5971517 | 2019-05-29 07:44:01 +0200 | [diff] [blame] | 6251 | rtl_rar_set(tp, dev->dev_addr); |
| 6252 | |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6253 | clk_prepare_enable(tp->clk); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6254 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6255 | if (netif_running(dev)) |
| 6256 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6257 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6258 | return 0; |
| 6259 | } |
| 6260 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6261 | static int rtl8169_runtime_suspend(struct device *device) |
| 6262 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6263 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6264 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6265 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6266 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6267 | return 0; |
| 6268 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6269 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6270 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6271 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6272 | |
| 6273 | rtl8169_net_suspend(dev); |
| 6274 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6275 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6276 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6277 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6278 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6279 | return 0; |
| 6280 | } |
| 6281 | |
| 6282 | static int rtl8169_runtime_resume(struct device *device) |
| 6283 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6284 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6285 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 5971517 | 2019-05-29 07:44:01 +0200 | [diff] [blame] | 6286 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6287 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6288 | |
| 6289 | if (!tp->TxDescArray) |
| 6290 | return 0; |
| 6291 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6292 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6293 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6294 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6295 | |
| 6296 | __rtl8169_resume(dev); |
| 6297 | |
| 6298 | return 0; |
| 6299 | } |
| 6300 | |
| 6301 | static int rtl8169_runtime_idle(struct device *device) |
| 6302 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6303 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6304 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6305 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6306 | pm_schedule_suspend(device, 10000); |
| 6307 | |
| 6308 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6311 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6312 | .suspend = rtl8169_suspend, |
| 6313 | .resume = rtl8169_resume, |
| 6314 | .freeze = rtl8169_suspend, |
| 6315 | .thaw = rtl8169_resume, |
| 6316 | .poweroff = rtl8169_suspend, |
| 6317 | .restore = rtl8169_resume, |
| 6318 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6319 | .runtime_resume = rtl8169_runtime_resume, |
| 6320 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6321 | }; |
| 6322 | |
| 6323 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6324 | |
| 6325 | #else /* !CONFIG_PM */ |
| 6326 | |
| 6327 | #define RTL8169_PM_OPS NULL |
| 6328 | |
| 6329 | #endif /* !CONFIG_PM */ |
| 6330 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6331 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6332 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6333 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6334 | switch (tp->mac_version) { |
| 6335 | case RTL_GIGA_MAC_VER_11: |
| 6336 | case RTL_GIGA_MAC_VER_12: |
| 6337 | case RTL_GIGA_MAC_VER_17: |
| 6338 | pci_clear_master(tp->pci_dev); |
| 6339 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6340 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6341 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6342 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6343 | break; |
| 6344 | default: |
| 6345 | break; |
| 6346 | } |
| 6347 | } |
| 6348 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6349 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6350 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6351 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6352 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6353 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6354 | rtl8169_net_suspend(dev); |
| 6355 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6356 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6357 | rtl_rar_set(tp, dev->perm_addr); |
| 6358 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6359 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6360 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6361 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6362 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6363 | rtl_wol_suspend_quirk(tp); |
| 6364 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6365 | } |
| 6366 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6367 | pci_wake_from_d3(pdev, true); |
| 6368 | pci_set_power_state(pdev, PCI_D3hot); |
| 6369 | } |
| 6370 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6371 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6372 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6373 | { |
| 6374 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6375 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6376 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6377 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6378 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6379 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6380 | netif_napi_del(&tp->napi); |
| 6381 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6382 | unregister_netdev(dev); |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6383 | mdiobus_unregister(tp->phydev->mdio.bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6384 | |
| 6385 | rtl_release_firmware(tp); |
| 6386 | |
| 6387 | if (pci_dev_run_wake(pdev)) |
| 6388 | pm_runtime_get_noresume(&pdev->dev); |
| 6389 | |
| 6390 | /* restore original MAC address */ |
| 6391 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6392 | } |
| 6393 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6394 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6395 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6396 | .ndo_stop = rtl8169_close, |
| 6397 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6398 | .ndo_start_xmit = rtl8169_start_xmit, |
Heiner Kallweit | e64e0c8 | 2019-07-26 21:49:22 +0200 | [diff] [blame] | 6399 | .ndo_features_check = rtl8169_features_check, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6400 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 6401 | .ndo_validate_addr = eth_validate_addr, |
| 6402 | .ndo_change_mtu = rtl8169_change_mtu, |
| 6403 | .ndo_fix_features = rtl8169_fix_features, |
| 6404 | .ndo_set_features = rtl8169_set_features, |
| 6405 | .ndo_set_mac_address = rtl_set_mac_address, |
| 6406 | .ndo_do_ioctl = rtl8169_ioctl, |
| 6407 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 6408 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6409 | .ndo_poll_controller = rtl8169_netpoll, |
| 6410 | #endif |
| 6411 | |
| 6412 | }; |
| 6413 | |
Heiner Kallweit | ec9a408 | 2019-06-10 18:21:50 +0200 | [diff] [blame] | 6414 | static void rtl_set_irq_mask(struct rtl8169_private *tp) |
| 6415 | { |
| 6416 | tp->irq_mask = RTL_EVENT_NAPI | LinkChg; |
| 6417 | |
| 6418 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 6419 | tp->irq_mask |= SYSErr | RxOverflow | RxFIFOOver; |
| 6420 | else if (tp->mac_version == RTL_GIGA_MAC_VER_11) |
| 6421 | /* special workaround needed */ |
| 6422 | tp->irq_mask |= RxFIFOOver; |
| 6423 | else |
| 6424 | tp->irq_mask |= RxOverflow; |
| 6425 | } |
| 6426 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6427 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6428 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6429 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6430 | |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6431 | switch (tp->mac_version) { |
| 6432 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6433 | rtl_unlock_config_regs(tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6434 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6435 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6436 | /* fall through */ |
| 6437 | case RTL_GIGA_MAC_VER_07 ... RTL_GIGA_MAC_VER_24: |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6438 | flags = PCI_IRQ_LEGACY; |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6439 | break; |
| 6440 | default: |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6441 | flags = PCI_IRQ_ALL_TYPES; |
Heiner Kallweit | 003bd5b | 2019-07-27 12:43:31 +0200 | [diff] [blame] | 6442 | break; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6443 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6444 | |
| 6445 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6446 | } |
| 6447 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6448 | static void rtl_read_mac_address(struct rtl8169_private *tp, |
| 6449 | u8 mac_addr[ETH_ALEN]) |
| 6450 | { |
| 6451 | /* Get MAC address */ |
Heiner Kallweit | 9e9f33b | 2019-06-14 07:54:07 +0200 | [diff] [blame] | 6452 | if (rtl_is_8168evl_up(tp) && tp->mac_version != RTL_GIGA_MAC_VER_34) { |
| 6453 | u32 value = rtl_eri_read(tp, 0xe0); |
| 6454 | |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6455 | mac_addr[0] = (value >> 0) & 0xff; |
| 6456 | mac_addr[1] = (value >> 8) & 0xff; |
| 6457 | mac_addr[2] = (value >> 16) & 0xff; |
| 6458 | mac_addr[3] = (value >> 24) & 0xff; |
| 6459 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 6460 | value = rtl_eri_read(tp, 0xe4); |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6461 | mac_addr[4] = (value >> 0) & 0xff; |
| 6462 | mac_addr[5] = (value >> 8) & 0xff; |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6463 | } |
| 6464 | } |
| 6465 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6466 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 6467 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6468 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 6472 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6473 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6474 | } |
| 6475 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6476 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 6477 | { |
| 6478 | struct rtl8169_private *tp = mii_bus->priv; |
| 6479 | |
| 6480 | if (phyaddr > 0) |
| 6481 | return -ENODEV; |
| 6482 | |
| 6483 | return rtl_readphy(tp, phyreg); |
| 6484 | } |
| 6485 | |
| 6486 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 6487 | int phyreg, u16 val) |
| 6488 | { |
| 6489 | struct rtl8169_private *tp = mii_bus->priv; |
| 6490 | |
| 6491 | if (phyaddr > 0) |
| 6492 | return -ENODEV; |
| 6493 | |
| 6494 | rtl_writephy(tp, phyreg, val); |
| 6495 | |
| 6496 | return 0; |
| 6497 | } |
| 6498 | |
| 6499 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 6500 | { |
| 6501 | struct pci_dev *pdev = tp->pci_dev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6502 | struct mii_bus *new_bus; |
| 6503 | int ret; |
| 6504 | |
| 6505 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 6506 | if (!new_bus) |
| 6507 | return -ENOMEM; |
| 6508 | |
| 6509 | new_bus->name = "r8169"; |
| 6510 | new_bus->priv = tp; |
| 6511 | new_bus->parent = &pdev->dev; |
| 6512 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
Heiner Kallweit | a195016 | 2019-04-24 21:13:25 +0200 | [diff] [blame] | 6513 | 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] | 6514 | |
| 6515 | new_bus->read = r8169_mdio_read_reg; |
| 6516 | new_bus->write = r8169_mdio_write_reg; |
| 6517 | |
| 6518 | ret = mdiobus_register(new_bus); |
| 6519 | if (ret) |
| 6520 | return ret; |
| 6521 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6522 | tp->phydev = mdiobus_get_phy(new_bus, 0); |
| 6523 | if (!tp->phydev) { |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6524 | mdiobus_unregister(new_bus); |
| 6525 | return -ENODEV; |
| 6526 | } |
| 6527 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 6528 | /* PHY will be woken up in rtl_open() */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6529 | phy_suspend(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6530 | |
| 6531 | return 0; |
| 6532 | } |
| 6533 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6534 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6535 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6536 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 6537 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6538 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6539 | |
| 6540 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 6541 | return; |
| 6542 | |
| 6543 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 6544 | return; |
| 6545 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6546 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6547 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6548 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6549 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 6550 | r8168_mac_ocp_modify(tp, 0xe8de, BIT(14), 0); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6551 | |
| 6552 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 6553 | return; |
| 6554 | |
Heiner Kallweit | ef712ed | 2019-08-04 09:47:51 +0200 | [diff] [blame] | 6555 | r8168_mac_ocp_modify(tp, 0xe8de, 0, BIT(15)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6556 | |
Heiner Kallweit | 7160be2 | 2019-05-25 20:44:01 +0200 | [diff] [blame] | 6557 | 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] | 6558 | } |
| 6559 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6560 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6561 | { |
| 6562 | switch (tp->mac_version) { |
Heiner Kallweit | 29ec048 | 2019-05-25 20:43:25 +0200 | [diff] [blame] | 6563 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
| 6564 | rtl8168ep_stop_cmac(tp); |
| 6565 | /* fall through */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 6566 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 6567 | rtl_hw_init_8168g(tp); |
| 6568 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6569 | default: |
| 6570 | break; |
| 6571 | } |
| 6572 | } |
| 6573 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6574 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 6575 | { |
| 6576 | /* Non-GBit versions don't support jumbo frames */ |
| 6577 | if (!tp->supports_gmii) |
| 6578 | return JUMBO_1K; |
| 6579 | |
| 6580 | switch (tp->mac_version) { |
| 6581 | /* RTL8169 */ |
Heiner Kallweit | e9588eb | 2019-05-25 21:14:39 +0200 | [diff] [blame] | 6582 | case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06: |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6583 | return JUMBO_7K; |
| 6584 | /* RTL8168b */ |
| 6585 | case RTL_GIGA_MAC_VER_11: |
| 6586 | case RTL_GIGA_MAC_VER_12: |
| 6587 | case RTL_GIGA_MAC_VER_17: |
| 6588 | return JUMBO_4K; |
| 6589 | /* RTL8168c */ |
| 6590 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 6591 | return JUMBO_6K; |
| 6592 | default: |
| 6593 | return JUMBO_9K; |
| 6594 | } |
| 6595 | } |
| 6596 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6597 | static void rtl_disable_clk(void *data) |
| 6598 | { |
| 6599 | clk_disable_unprepare(data); |
| 6600 | } |
| 6601 | |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 6602 | static int rtl_get_ether_clk(struct rtl8169_private *tp) |
| 6603 | { |
| 6604 | struct device *d = tp_to_dev(tp); |
| 6605 | struct clk *clk; |
| 6606 | int rc; |
| 6607 | |
| 6608 | clk = devm_clk_get(d, "ether_clk"); |
| 6609 | if (IS_ERR(clk)) { |
| 6610 | rc = PTR_ERR(clk); |
| 6611 | if (rc == -ENOENT) |
| 6612 | /* clk-core allows NULL (for suspend / resume) */ |
| 6613 | rc = 0; |
| 6614 | else if (rc != -EPROBE_DEFER) |
| 6615 | dev_err(d, "failed to get clk: %d\n", rc); |
| 6616 | } else { |
| 6617 | tp->clk = clk; |
| 6618 | rc = clk_prepare_enable(clk); |
| 6619 | if (rc) |
| 6620 | dev_err(d, "failed to enable clk: %d\n", rc); |
| 6621 | else |
| 6622 | rc = devm_add_action_or_reset(d, rtl_disable_clk, clk); |
| 6623 | } |
| 6624 | |
| 6625 | return rc; |
| 6626 | } |
| 6627 | |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6628 | static void rtl_init_mac_address(struct rtl8169_private *tp) |
| 6629 | { |
| 6630 | struct net_device *dev = tp->dev; |
| 6631 | u8 *mac_addr = dev->dev_addr; |
| 6632 | int rc, i; |
| 6633 | |
| 6634 | rc = eth_platform_get_mac_address(tp_to_dev(tp), mac_addr); |
| 6635 | if (!rc) |
| 6636 | goto done; |
| 6637 | |
| 6638 | rtl_read_mac_address(tp, mac_addr); |
| 6639 | if (is_valid_ether_addr(mac_addr)) |
| 6640 | goto done; |
| 6641 | |
| 6642 | for (i = 0; i < ETH_ALEN; i++) |
| 6643 | mac_addr[i] = RTL_R8(tp, MAC0 + i); |
| 6644 | if (is_valid_ether_addr(mac_addr)) |
| 6645 | goto done; |
| 6646 | |
| 6647 | eth_hw_addr_random(dev); |
| 6648 | dev_warn(tp_to_dev(tp), "can't read MAC address, setting random one\n"); |
| 6649 | done: |
| 6650 | rtl_rar_set(tp, mac_addr); |
| 6651 | } |
| 6652 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6653 | 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] | 6654 | { |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6655 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6656 | struct net_device *dev; |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6657 | int chipset, region; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6658 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6659 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6660 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 6661 | if (!dev) |
| 6662 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6663 | |
| 6664 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6665 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6666 | tp = netdev_priv(dev); |
| 6667 | tp->dev = dev; |
| 6668 | tp->pci_dev = pdev; |
| 6669 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | 145a40e | 2019-06-10 18:25:29 +0200 | [diff] [blame] | 6670 | tp->supports_gmii = ent->driver_data == RTL_CFG_NO_GBIT ? 0 : 1; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6671 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6672 | /* Get the *optional* external "ether_clk" used on some boards */ |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 6673 | rc = rtl_get_ether_clk(tp); |
| 6674 | if (rc) |
| 6675 | return rc; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 6676 | |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 6677 | /* Disable ASPM completely as that cause random device stop working |
| 6678 | * problems as well as full system hangs for some PCIe devices users. |
| 6679 | */ |
Heiner Kallweit | 62b1b3b | 2019-06-18 23:14:50 +0200 | [diff] [blame] | 6680 | rc = pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | |
| 6681 | PCIE_LINK_STATE_L1); |
| 6682 | tp->aspm_manageable = !rc; |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 6683 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6684 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6685 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6686 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6687 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6688 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6689 | } |
| 6690 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6691 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6692 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6693 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 6694 | /* use first MMIO region */ |
| 6695 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 6696 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6697 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6698 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6699 | } |
| 6700 | |
| 6701 | /* check for weird/broken PCI region reporting */ |
| 6702 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6703 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6704 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6705 | } |
| 6706 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 6707 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6708 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6709 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6710 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6711 | } |
| 6712 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 6713 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6714 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6715 | /* Identify chip attached to board */ |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 6716 | rtl8169_get_mac_version(tp); |
| 6717 | if (tp->mac_version == RTL_GIGA_MAC_NONE) |
| 6718 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6719 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 6720 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6721 | |
Heiner Kallweit | 10b63e8 | 2019-01-20 11:45:20 +0100 | [diff] [blame] | 6722 | 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] | 6723 | !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6724 | dev->features |= NETIF_F_HIGHDMA; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 6725 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6726 | rtl_init_rxcfg(tp); |
| 6727 | |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 6728 | rtl8169_irq_mask_and_ack(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6729 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6730 | rtl_hw_initialize(tp); |
| 6731 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6732 | rtl_hw_reset(tp); |
| 6733 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6734 | pci_set_master(pdev); |
| 6735 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6736 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6737 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6738 | rc = rtl_alloc_irq(tp); |
| 6739 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 6740 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6741 | return rc; |
| 6742 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6743 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6744 | mutex_init(&tp->wk.mutex); |
Heiner Kallweit | 5c41e78 | 2019-01-19 22:03:49 +0100 | [diff] [blame] | 6745 | INIT_WORK(&tp->wk.work, rtl_task); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 6746 | u64_stats_init(&tp->rx_stats.syncp); |
| 6747 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6748 | |
Heiner Kallweit | c782e20 | 2019-07-02 20:46:09 +0200 | [diff] [blame] | 6749 | rtl_init_mac_address(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6750 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 6751 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6752 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 6753 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6754 | |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6755 | dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6756 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 6757 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6758 | 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] | 6759 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 6760 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6761 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6762 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 6763 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6764 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6765 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 6766 | |
| 6767 | /* |
| 6768 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 6769 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 6770 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6771 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 6772 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 6773 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6774 | |
Heiner Kallweit | 0170d59 | 2019-07-26 21:48:32 +0200 | [diff] [blame] | 6775 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6776 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6777 | dev->features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | 0170d59 | 2019-07-26 21:48:32 +0200 | [diff] [blame] | 6778 | dev->gso_max_size = RTL_GSO_MAX_SIZE_V2; |
| 6779 | dev->gso_max_segs = RTL_GSO_MAX_SEGS_V2; |
| 6780 | } else { |
| 6781 | dev->gso_max_size = RTL_GSO_MAX_SIZE_V1; |
| 6782 | dev->gso_max_segs = RTL_GSO_MAX_SEGS_V1; |
| 6783 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6784 | |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6785 | /* RTL8168e-vl has a HW issue with TSO */ |
| 6786 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
Holger Hoffstätte | a7eb6a4 | 2019-08-09 00:02:40 +0200 | [diff] [blame] | 6787 | dev->vlan_features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
| 6788 | dev->hw_features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
| 6789 | dev->features &= ~(NETIF_F_ALL_TSO | NETIF_F_SG); |
Heiner Kallweit | 93681cd | 2019-07-26 21:51:36 +0200 | [diff] [blame] | 6790 | } |
| 6791 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6792 | dev->hw_features |= NETIF_F_RXALL; |
| 6793 | dev->hw_features |= NETIF_F_RXFCS; |
| 6794 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 6795 | /* MTU range: 60 - hw-specific max */ |
| 6796 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6797 | jumbo_max = rtl_jumbo_max(tp); |
| 6798 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 6799 | |
Heiner Kallweit | ec9a408 | 2019-06-10 18:21:50 +0200 | [diff] [blame] | 6800 | rtl_set_irq_mask(tp); |
Heiner Kallweit | 9fa0a8e | 2019-06-10 18:24:25 +0200 | [diff] [blame] | 6801 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 6802 | tp->fw_name = rtl_chip_infos[chipset].fw_name; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6803 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6804 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 6805 | &tp->counters_phys_addr, |
| 6806 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 6807 | if (!tp->counters) |
| 6808 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6809 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 6810 | pci_set_drvdata(pdev, dev); |
| 6811 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6812 | rc = r8169_mdio_register(tp); |
| 6813 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 6814 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6815 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6816 | /* chip gets powered up in rtl_open() */ |
| 6817 | rtl_pll_power_down(tp); |
| 6818 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6819 | rc = register_netdev(dev); |
| 6820 | if (rc) |
| 6821 | goto err_mdio_unregister; |
| 6822 | |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 6823 | netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n", |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 6824 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 6825 | (RTL_R32(tp, TxConfig) >> 20) & 0xfcf, |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 6826 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 6827 | |
| 6828 | if (jumbo_max > JUMBO_1K) |
| 6829 | netif_info(tp, probe, dev, |
| 6830 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 6831 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 6832 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6833 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6834 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6835 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6836 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6837 | if (pci_dev_run_wake(pdev)) |
| 6838 | pm_runtime_put_sync(&pdev->dev); |
| 6839 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 6840 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6841 | |
| 6842 | err_mdio_unregister: |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6843 | mdiobus_unregister(tp->phydev->mdio.bus); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6844 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6845 | } |
| 6846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6847 | static struct pci_driver rtl8169_pci_driver = { |
| 6848 | .name = MODULENAME, |
| 6849 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6850 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6851 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6852 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6853 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6854 | }; |
| 6855 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 6856 | module_pci_driver(rtl8169_pci_driver); |