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> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 30 | #include <linux/firmware.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 31 | #include <linux/prefetch.h> |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 32 | #include <linux/pci-aspm.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 33 | #include <linux/ipv6.h> |
| 34 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MODULENAME "r8169" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 38 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 39 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 40 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 41 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 42 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 44 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 50 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 51 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 52 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 53 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 54 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 55 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 56 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 57 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 58 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 59 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 62 | The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 63 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 65 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 67 | |
| 68 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 69 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 71 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 73 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 76 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 77 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 78 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 79 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 80 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 81 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 84 | RTL_GIGA_MAC_VER_01 = 0, |
| 85 | RTL_GIGA_MAC_VER_02, |
| 86 | RTL_GIGA_MAC_VER_03, |
| 87 | RTL_GIGA_MAC_VER_04, |
| 88 | RTL_GIGA_MAC_VER_05, |
| 89 | RTL_GIGA_MAC_VER_06, |
| 90 | RTL_GIGA_MAC_VER_07, |
| 91 | RTL_GIGA_MAC_VER_08, |
| 92 | RTL_GIGA_MAC_VER_09, |
| 93 | RTL_GIGA_MAC_VER_10, |
| 94 | RTL_GIGA_MAC_VER_11, |
| 95 | RTL_GIGA_MAC_VER_12, |
| 96 | RTL_GIGA_MAC_VER_13, |
| 97 | RTL_GIGA_MAC_VER_14, |
| 98 | RTL_GIGA_MAC_VER_15, |
| 99 | RTL_GIGA_MAC_VER_16, |
| 100 | RTL_GIGA_MAC_VER_17, |
| 101 | RTL_GIGA_MAC_VER_18, |
| 102 | RTL_GIGA_MAC_VER_19, |
| 103 | RTL_GIGA_MAC_VER_20, |
| 104 | RTL_GIGA_MAC_VER_21, |
| 105 | RTL_GIGA_MAC_VER_22, |
| 106 | RTL_GIGA_MAC_VER_23, |
| 107 | RTL_GIGA_MAC_VER_24, |
| 108 | RTL_GIGA_MAC_VER_25, |
| 109 | RTL_GIGA_MAC_VER_26, |
| 110 | RTL_GIGA_MAC_VER_27, |
| 111 | RTL_GIGA_MAC_VER_28, |
| 112 | RTL_GIGA_MAC_VER_29, |
| 113 | RTL_GIGA_MAC_VER_30, |
| 114 | RTL_GIGA_MAC_VER_31, |
| 115 | RTL_GIGA_MAC_VER_32, |
| 116 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 117 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 118 | RTL_GIGA_MAC_VER_35, |
| 119 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 120 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 121 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 122 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 123 | RTL_GIGA_MAC_VER_40, |
| 124 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 125 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 126 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 127 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_45, |
| 129 | RTL_GIGA_MAC_VER_46, |
| 130 | RTL_GIGA_MAC_VER_47, |
| 131 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 132 | RTL_GIGA_MAC_VER_49, |
| 133 | RTL_GIGA_MAC_VER_50, |
| 134 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 135 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 138 | #define JUMBO_1K ETH_DATA_LEN |
| 139 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 140 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 141 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 142 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 143 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 144 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | const char *name; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 146 | const char *fw_name; |
| 147 | } rtl_chip_infos[] = { |
| 148 | /* PCI devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 149 | [RTL_GIGA_MAC_VER_01] = {"RTL8169" }, |
| 150 | [RTL_GIGA_MAC_VER_02] = {"RTL8169s" }, |
| 151 | [RTL_GIGA_MAC_VER_03] = {"RTL8110s" }, |
| 152 | [RTL_GIGA_MAC_VER_04] = {"RTL8169sb/8110sb" }, |
| 153 | [RTL_GIGA_MAC_VER_05] = {"RTL8169sc/8110sc" }, |
| 154 | [RTL_GIGA_MAC_VER_06] = {"RTL8169sc/8110sc" }, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 155 | /* PCI-E devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 156 | [RTL_GIGA_MAC_VER_07] = {"RTL8102e" }, |
| 157 | [RTL_GIGA_MAC_VER_08] = {"RTL8102e" }, |
| 158 | [RTL_GIGA_MAC_VER_09] = {"RTL8102e" }, |
| 159 | [RTL_GIGA_MAC_VER_10] = {"RTL8101e" }, |
| 160 | [RTL_GIGA_MAC_VER_11] = {"RTL8168b/8111b" }, |
| 161 | [RTL_GIGA_MAC_VER_12] = {"RTL8168b/8111b" }, |
| 162 | [RTL_GIGA_MAC_VER_13] = {"RTL8101e" }, |
| 163 | [RTL_GIGA_MAC_VER_14] = {"RTL8100e" }, |
| 164 | [RTL_GIGA_MAC_VER_15] = {"RTL8100e" }, |
| 165 | [RTL_GIGA_MAC_VER_16] = {"RTL8101e" }, |
| 166 | [RTL_GIGA_MAC_VER_17] = {"RTL8168b/8111b" }, |
| 167 | [RTL_GIGA_MAC_VER_18] = {"RTL8168cp/8111cp" }, |
| 168 | [RTL_GIGA_MAC_VER_19] = {"RTL8168c/8111c" }, |
| 169 | [RTL_GIGA_MAC_VER_20] = {"RTL8168c/8111c" }, |
| 170 | [RTL_GIGA_MAC_VER_21] = {"RTL8168c/8111c" }, |
| 171 | [RTL_GIGA_MAC_VER_22] = {"RTL8168c/8111c" }, |
| 172 | [RTL_GIGA_MAC_VER_23] = {"RTL8168cp/8111cp" }, |
| 173 | [RTL_GIGA_MAC_VER_24] = {"RTL8168cp/8111cp" }, |
| 174 | [RTL_GIGA_MAC_VER_25] = {"RTL8168d/8111d", FIRMWARE_8168D_1}, |
| 175 | [RTL_GIGA_MAC_VER_26] = {"RTL8168d/8111d", FIRMWARE_8168D_2}, |
| 176 | [RTL_GIGA_MAC_VER_27] = {"RTL8168dp/8111dp" }, |
| 177 | [RTL_GIGA_MAC_VER_28] = {"RTL8168dp/8111dp" }, |
| 178 | [RTL_GIGA_MAC_VER_29] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 179 | [RTL_GIGA_MAC_VER_30] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 180 | [RTL_GIGA_MAC_VER_31] = {"RTL8168dp/8111dp" }, |
| 181 | [RTL_GIGA_MAC_VER_32] = {"RTL8168e/8111e", FIRMWARE_8168E_1}, |
| 182 | [RTL_GIGA_MAC_VER_33] = {"RTL8168e/8111e", FIRMWARE_8168E_2}, |
| 183 | [RTL_GIGA_MAC_VER_34] = {"RTL8168evl/8111evl", FIRMWARE_8168E_3}, |
| 184 | [RTL_GIGA_MAC_VER_35] = {"RTL8168f/8111f", FIRMWARE_8168F_1}, |
| 185 | [RTL_GIGA_MAC_VER_36] = {"RTL8168f/8111f", FIRMWARE_8168F_2}, |
| 186 | [RTL_GIGA_MAC_VER_37] = {"RTL8402", FIRMWARE_8402_1 }, |
| 187 | [RTL_GIGA_MAC_VER_38] = {"RTL8411", FIRMWARE_8411_1 }, |
| 188 | [RTL_GIGA_MAC_VER_39] = {"RTL8106e", FIRMWARE_8106E_1}, |
| 189 | [RTL_GIGA_MAC_VER_40] = {"RTL8168g/8111g", FIRMWARE_8168G_2}, |
| 190 | [RTL_GIGA_MAC_VER_41] = {"RTL8168g/8111g" }, |
| 191 | [RTL_GIGA_MAC_VER_42] = {"RTL8168g/8111g", FIRMWARE_8168G_3}, |
| 192 | [RTL_GIGA_MAC_VER_43] = {"RTL8106e", FIRMWARE_8106E_2}, |
| 193 | [RTL_GIGA_MAC_VER_44] = {"RTL8411", FIRMWARE_8411_2 }, |
| 194 | [RTL_GIGA_MAC_VER_45] = {"RTL8168h/8111h", FIRMWARE_8168H_1}, |
| 195 | [RTL_GIGA_MAC_VER_46] = {"RTL8168h/8111h", FIRMWARE_8168H_2}, |
| 196 | [RTL_GIGA_MAC_VER_47] = {"RTL8107e", FIRMWARE_8107E_1}, |
| 197 | [RTL_GIGA_MAC_VER_48] = {"RTL8107e", FIRMWARE_8107E_2}, |
| 198 | [RTL_GIGA_MAC_VER_49] = {"RTL8168ep/8111ep" }, |
| 199 | [RTL_GIGA_MAC_VER_50] = {"RTL8168ep/8111ep" }, |
| 200 | [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 203 | enum cfg_version { |
| 204 | RTL_CFG_0 = 0x00, |
| 205 | RTL_CFG_1, |
| 206 | RTL_CFG_2 |
| 207 | }; |
| 208 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 209 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Kai-Heng Feng | 3635299 | 2019-01-02 14:45:07 +0800 | [diff] [blame] | 210 | { PCI_VDEVICE(REALTEK, 0x2502), RTL_CFG_1 }, |
| 211 | { PCI_VDEVICE(REALTEK, 0x2600), RTL_CFG_1 }, |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 212 | { PCI_VDEVICE(REALTEK, 0x8129), RTL_CFG_0 }, |
| 213 | { PCI_VDEVICE(REALTEK, 0x8136), RTL_CFG_2 }, |
| 214 | { PCI_VDEVICE(REALTEK, 0x8161), RTL_CFG_1 }, |
| 215 | { PCI_VDEVICE(REALTEK, 0x8167), RTL_CFG_0 }, |
| 216 | { PCI_VDEVICE(REALTEK, 0x8168), RTL_CFG_1 }, |
| 217 | { PCI_VDEVICE(NCUBE, 0x8168), RTL_CFG_1 }, |
| 218 | { PCI_VDEVICE(REALTEK, 0x8169), RTL_CFG_0 }, |
| 219 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 220 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
| 221 | { PCI_VDEVICE(DLINK, 0x4300), RTL_CFG_0 }, |
| 222 | { PCI_VDEVICE(DLINK, 0x4302), RTL_CFG_0 }, |
| 223 | { PCI_VDEVICE(AT, 0xc107), RTL_CFG_0 }, |
| 224 | { PCI_VDEVICE(USR, 0x0116), RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 225 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 226 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 227 | { 0x0001, 0x8168, |
| 228 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 229 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 233 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 234 | static struct { |
| 235 | u32 msg_enable; |
| 236 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 238 | enum rtl_registers { |
| 239 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 240 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 241 | MAR0 = 8, /* Multicast filter. */ |
| 242 | CounterAddrLow = 0x10, |
| 243 | CounterAddrHigh = 0x14, |
| 244 | TxDescStartAddrLow = 0x20, |
| 245 | TxDescStartAddrHigh = 0x24, |
| 246 | TxHDescStartAddrLow = 0x28, |
| 247 | TxHDescStartAddrHigh = 0x2c, |
| 248 | FLASH = 0x30, |
| 249 | ERSR = 0x36, |
| 250 | ChipCmd = 0x37, |
| 251 | TxPoll = 0x38, |
| 252 | IntrMask = 0x3c, |
| 253 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 254 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 255 | TxConfig = 0x40, |
| 256 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 257 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 258 | |
| 259 | RxConfig = 0x44, |
| 260 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 261 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 262 | #define RXCFG_FIFO_SHIFT 13 |
| 263 | /* No threshold before first PCI xfer */ |
| 264 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 265 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 266 | #define RXCFG_DMA_SHIFT 8 |
| 267 | /* Unlimited maximum PCI burst. */ |
| 268 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 269 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 270 | RxMissed = 0x4c, |
| 271 | Cfg9346 = 0x50, |
| 272 | Config0 = 0x51, |
| 273 | Config1 = 0x52, |
| 274 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 275 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 276 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 277 | Config3 = 0x54, |
| 278 | Config4 = 0x55, |
| 279 | Config5 = 0x56, |
| 280 | MultiIntr = 0x5c, |
| 281 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 282 | PHYstatus = 0x6c, |
| 283 | RxMaxSize = 0xda, |
| 284 | CPlusCmd = 0xe0, |
| 285 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 286 | |
| 287 | #define RTL_COALESCE_MASK 0x0f |
| 288 | #define RTL_COALESCE_SHIFT 4 |
| 289 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 290 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 291 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 292 | RxDescAddrLow = 0xe4, |
| 293 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 294 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 295 | |
| 296 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 297 | |
| 298 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 299 | |
| 300 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 301 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 302 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 303 | FuncEvent = 0xf0, |
| 304 | FuncEventMask = 0xf4, |
| 305 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 306 | IBCR0 = 0xf8, |
| 307 | IBCR2 = 0xf9, |
| 308 | IBIMR0 = 0xfa, |
| 309 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 310 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 313 | enum rtl8168_8101_registers { |
| 314 | CSIDR = 0x64, |
| 315 | CSIAR = 0x68, |
| 316 | #define CSIAR_FLAG 0x80000000 |
| 317 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 318 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 319 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 320 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 321 | EPHYAR = 0x80, |
| 322 | #define EPHYAR_FLAG 0x80000000 |
| 323 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 324 | #define EPHYAR_REG_MASK 0x1f |
| 325 | #define EPHYAR_REG_SHIFT 16 |
| 326 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 327 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 328 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 329 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 330 | DBG_REG = 0xd1, |
| 331 | #define FIX_NAK_1 (1 << 4) |
| 332 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 333 | TWSI = 0xd2, |
| 334 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 335 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 336 | #define TX_EMPTY (1 << 5) |
| 337 | #define RX_EMPTY (1 << 4) |
| 338 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 339 | #define EN_NDP (1 << 3) |
| 340 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 341 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 342 | EFUSEAR = 0xdc, |
| 343 | #define EFUSEAR_FLAG 0x80000000 |
| 344 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 345 | #define EFUSEAR_READ_CMD 0x00000000 |
| 346 | #define EFUSEAR_REG_MASK 0x03ff |
| 347 | #define EFUSEAR_REG_SHIFT 8 |
| 348 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 349 | MISC_1 = 0xf2, |
| 350 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 351 | }; |
| 352 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 353 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 354 | LED_FREQ = 0x1a, |
| 355 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 356 | ERIDR = 0x70, |
| 357 | ERIAR = 0x74, |
| 358 | #define ERIAR_FLAG 0x80000000 |
| 359 | #define ERIAR_WRITE_CMD 0x80000000 |
| 360 | #define ERIAR_READ_CMD 0x00000000 |
| 361 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 362 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 363 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 364 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 365 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 366 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 367 | #define ERIAR_MASK_SHIFT 12 |
| 368 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 369 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 370 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 371 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 372 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 373 | EPHY_RXER_NUM = 0x7c, |
| 374 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 375 | #define OCPDR_WRITE_CMD 0x80000000 |
| 376 | #define OCPDR_READ_CMD 0x00000000 |
| 377 | #define OCPDR_REG_MASK 0x7f |
| 378 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 379 | #define OCPDR_DATA_MASK 0xffff |
| 380 | OCPAR = 0xb4, |
| 381 | #define OCPAR_FLAG 0x80000000 |
| 382 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 383 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 384 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 385 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 386 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 387 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 388 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 389 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 390 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 391 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 392 | }; |
| 393 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 394 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 396 | SYSErr = 0x8000, |
| 397 | PCSTimeout = 0x4000, |
| 398 | SWInt = 0x0100, |
| 399 | TxDescUnavail = 0x0080, |
| 400 | RxFIFOOver = 0x0040, |
| 401 | LinkChg = 0x0020, |
| 402 | RxOverflow = 0x0010, |
| 403 | TxErr = 0x0008, |
| 404 | TxOK = 0x0004, |
| 405 | RxErr = 0x0002, |
| 406 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 409 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 410 | RxFOVF = (1 << 23), |
| 411 | RxRWT = (1 << 22), |
| 412 | RxRES = (1 << 21), |
| 413 | RxRUNT = (1 << 20), |
| 414 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 417 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 418 | CmdReset = 0x10, |
| 419 | CmdRxEnb = 0x08, |
| 420 | CmdTxEnb = 0x04, |
| 421 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 423 | /* TXPoll register p.5 */ |
| 424 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 425 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 426 | FSWInt = 0x01, /* Forced software interrupt */ |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 429 | Cfg9346_Lock = 0x00, |
| 430 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 433 | AcceptErr = 0x20, |
| 434 | AcceptRunt = 0x10, |
| 435 | AcceptBroadcast = 0x08, |
| 436 | AcceptMulticast = 0x04, |
| 437 | AcceptMyPhys = 0x02, |
| 438 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 439 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | /* TxConfigBits */ |
| 442 | TxInterFrameGapShift = 24, |
| 443 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 444 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 445 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 446 | LEDS1 = (1 << 7), |
| 447 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 448 | Speed_down = (1 << 4), |
| 449 | MEMMAP = (1 << 3), |
| 450 | IOMAP = (1 << 2), |
| 451 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 452 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 453 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 454 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 455 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 456 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 457 | PCI_Clock_66MHz = 0x01, |
| 458 | PCI_Clock_33MHz = 0x00, |
| 459 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 460 | /* Config3 register p.25 */ |
| 461 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 462 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 463 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 464 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 465 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 466 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 467 | /* Config4 register */ |
| 468 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 469 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 470 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 471 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 472 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 473 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 474 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 475 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 476 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 477 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 480 | EnableBist = (1 << 15), // 8168 8101 |
| 481 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 482 | Normal_mode = (1 << 13), // unused |
| 483 | Force_half_dup = (1 << 12), // 8168 8101 |
| 484 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 485 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 486 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 487 | ASF = (1 << 8), // 8168 8101 |
| 488 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 489 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | RxVlan = (1 << 6), |
| 491 | RxChkSum = (1 << 5), |
| 492 | PCIDAC = (1 << 4), |
| 493 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 494 | #define INTT_MASK GENMASK(1, 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 497 | TBI_Enable = 0x80, |
| 498 | TxFlowCtrl = 0x40, |
| 499 | RxFlowCtrl = 0x20, |
| 500 | _1000bpsF = 0x10, |
| 501 | _100bps = 0x08, |
| 502 | _10bps = 0x04, |
| 503 | LinkStatus = 0x02, |
| 504 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 507 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 508 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 509 | /* ResetCounterCommand */ |
| 510 | CounterReset = 0x1, |
| 511 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 512 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 513 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 514 | |
| 515 | /* magic enable v2 */ |
| 516 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | }; |
| 518 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 519 | enum rtl_desc_bit { |
| 520 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 522 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 523 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 524 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 525 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 527 | /* Generic case. */ |
| 528 | enum rtl_tx_desc_bit { |
| 529 | /* First doubleword. */ |
| 530 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 531 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 533 | /* Second doubleword. */ |
| 534 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 535 | }; |
| 536 | |
| 537 | /* 8169, 8168b and 810x except 8102e. */ |
| 538 | enum rtl_tx_desc_bit_0 { |
| 539 | /* First doubleword. */ |
| 540 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 541 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 542 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 543 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 544 | }; |
| 545 | |
| 546 | /* 8102e, 8168c and beyond. */ |
| 547 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 548 | /* First doubleword. */ |
| 549 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 550 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 551 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 552 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 553 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 554 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 555 | #define TCPHO_SHIFT 18 |
| 556 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 557 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 558 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 559 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 560 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 561 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 562 | }; |
| 563 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 564 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | /* Rx private */ |
| 566 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 567 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | #define RxProtoUDP (PID1) |
| 570 | #define RxProtoTCP (PID0) |
| 571 | #define RxProtoIP (PID1 | PID0) |
| 572 | #define RxProtoMask RxProtoIP |
| 573 | |
| 574 | IPFail = (1 << 16), /* IP checksum failed */ |
| 575 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 576 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 577 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 578 | }; |
| 579 | |
| 580 | #define RsvdMask 0x3fffc000 |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 581 | #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 584 | __le32 opts1; |
| 585 | __le32 opts2; |
| 586 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 590 | __le32 opts1; |
| 591 | __le32 opts2; |
| 592 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | struct ring_info { |
| 596 | struct sk_buff *skb; |
| 597 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 600 | struct rtl8169_counters { |
| 601 | __le64 tx_packets; |
| 602 | __le64 rx_packets; |
| 603 | __le64 tx_errors; |
| 604 | __le32 rx_errors; |
| 605 | __le16 rx_missed; |
| 606 | __le16 align_errors; |
| 607 | __le32 tx_one_collision; |
| 608 | __le32 tx_multi_collision; |
| 609 | __le64 rx_unicast; |
| 610 | __le64 rx_broadcast; |
| 611 | __le32 rx_multicast; |
| 612 | __le16 tx_aborted; |
| 613 | __le16 tx_underun; |
| 614 | }; |
| 615 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 616 | struct rtl8169_tc_offsets { |
| 617 | bool inited; |
| 618 | __le64 tx_errors; |
| 619 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 620 | __le16 tx_aborted; |
| 621 | }; |
| 622 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 623 | enum rtl_flag { |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 624 | RTL_FLAG_TASK_ENABLED = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 625 | RTL_FLAG_TASK_RESET_PENDING, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 626 | RTL_FLAG_MAX |
| 627 | }; |
| 628 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 629 | struct rtl8169_stats { |
| 630 | u64 packets; |
| 631 | u64 bytes; |
| 632 | struct u64_stats_sync syncp; |
| 633 | }; |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | struct rtl8169_private { |
| 636 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 637 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 638 | struct net_device *dev; |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 639 | struct phy_device *phydev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 640 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 641 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 642 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 644 | 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] | 645 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 646 | struct rtl8169_stats rx_stats; |
| 647 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 649 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 650 | dma_addr_t TxPhyAddr; |
| 651 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 652 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 655 | |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 656 | u16 irq_mask; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 657 | const struct rtl_coalesce_info *coalesce_info; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 658 | struct clk *clk; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 659 | |
| 660 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 661 | void (*write)(struct rtl8169_private *, int, int); |
| 662 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 663 | } mdio_ops; |
| 664 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 665 | struct jumbo_ops { |
| 666 | void (*enable)(struct rtl8169_private *); |
| 667 | void (*disable)(struct rtl8169_private *); |
| 668 | } jumbo_ops; |
| 669 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 670 | void (*hw_start)(struct rtl8169_private *tp); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 671 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 672 | |
| 673 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 674 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 675 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 676 | struct work_struct work; |
| 677 | } wk; |
| 678 | |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 679 | unsigned irq_enabled:1; |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 680 | unsigned supports_gmii:1; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 681 | dma_addr_t counters_phys_addr; |
| 682 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 683 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 684 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 685 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 686 | const char *fw_name; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 687 | struct rtl_fw { |
| 688 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 689 | |
| 690 | #define RTL_VER_SIZE 32 |
| 691 | |
| 692 | char version[RTL_VER_SIZE]; |
| 693 | |
| 694 | struct rtl_fw_phy_action { |
| 695 | __le32 *code; |
| 696 | size_t size; |
| 697 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 698 | } *rtl_fw; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 699 | |
| 700 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | }; |
| 702 | |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 703 | typedef void (*rtl_generic_fct)(struct rtl8169_private *tp); |
| 704 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 705 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 707 | module_param_named(debug, debug.msg_enable, int, 0); |
| 708 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Heiner Kallweit | 11287b6 | 2019-01-07 21:49:09 +0100 | [diff] [blame] | 709 | MODULE_SOFTDEP("pre: realtek"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | MODULE_LICENSE("GPL"); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 711 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 712 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 713 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 714 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 715 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 716 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 717 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 718 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 719 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 720 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 721 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 722 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 723 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 724 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 725 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 726 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 727 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 728 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 729 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 731 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 732 | { |
| 733 | return &tp->pci_dev->dev; |
| 734 | } |
| 735 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 736 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 737 | { |
| 738 | mutex_lock(&tp->wk.mutex); |
| 739 | } |
| 740 | |
| 741 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 742 | { |
| 743 | mutex_unlock(&tp->wk.mutex); |
| 744 | } |
| 745 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 746 | static void rtl_lock_config_regs(struct rtl8169_private *tp) |
| 747 | { |
| 748 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 749 | } |
| 750 | |
| 751 | static void rtl_unlock_config_regs(struct rtl8169_private *tp) |
| 752 | { |
| 753 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 754 | } |
| 755 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 756 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 757 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 758 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 759 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 760 | } |
| 761 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 762 | struct rtl_cond { |
| 763 | bool (*check)(struct rtl8169_private *); |
| 764 | const char *msg; |
| 765 | }; |
| 766 | |
| 767 | static void rtl_udelay(unsigned int d) |
| 768 | { |
| 769 | udelay(d); |
| 770 | } |
| 771 | |
| 772 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 773 | void (*delay)(unsigned int), unsigned int d, int n, |
| 774 | bool high) |
| 775 | { |
| 776 | int i; |
| 777 | |
| 778 | for (i = 0; i < n; i++) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 779 | if (c->check(tp) == high) |
| 780 | return true; |
Heiner Kallweit | d1f5050 | 2019-05-04 15:20:38 +0200 | [diff] [blame] | 781 | delay(d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 782 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 783 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 784 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | |
| 788 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 789 | const struct rtl_cond *c, |
| 790 | unsigned int d, int n) |
| 791 | { |
| 792 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 793 | } |
| 794 | |
| 795 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 796 | const struct rtl_cond *c, |
| 797 | unsigned int d, int n) |
| 798 | { |
| 799 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 800 | } |
| 801 | |
| 802 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 803 | const struct rtl_cond *c, |
| 804 | unsigned int d, int n) |
| 805 | { |
| 806 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 807 | } |
| 808 | |
| 809 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 810 | const struct rtl_cond *c, |
| 811 | unsigned int d, int n) |
| 812 | { |
| 813 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 814 | } |
| 815 | |
| 816 | #define DECLARE_RTL_COND(name) \ |
| 817 | static bool name ## _check(struct rtl8169_private *); \ |
| 818 | \ |
| 819 | static const struct rtl_cond name = { \ |
| 820 | .check = name ## _check, \ |
| 821 | .msg = #name \ |
| 822 | }; \ |
| 823 | \ |
| 824 | static bool name ## _check(struct rtl8169_private *tp) |
| 825 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 826 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 827 | { |
| 828 | if (reg & 0xffff0001) { |
| 829 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 830 | return true; |
| 831 | } |
| 832 | return false; |
| 833 | } |
| 834 | |
| 835 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 836 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 837 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 841 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 842 | if (rtl_ocp_reg_failure(tp, reg)) |
| 843 | return; |
| 844 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 845 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 846 | |
| 847 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 848 | } |
| 849 | |
| 850 | static u16 r8168_phy_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, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 856 | |
| 857 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 858 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 859 | } |
| 860 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 861 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 862 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 863 | if (rtl_ocp_reg_failure(tp, reg)) |
| 864 | return; |
| 865 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 866 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 870 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 871 | if (rtl_ocp_reg_failure(tp, reg)) |
| 872 | return 0; |
| 873 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 874 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 875 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 876 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | #define OCP_STD_PHY_BASE 0xa400 |
| 880 | |
| 881 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 882 | { |
| 883 | if (reg == 0x1f) { |
| 884 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 885 | return; |
| 886 | } |
| 887 | |
| 888 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 889 | reg -= 0x10; |
| 890 | |
| 891 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 892 | } |
| 893 | |
| 894 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 895 | { |
| 896 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 897 | reg -= 0x10; |
| 898 | |
| 899 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 900 | } |
| 901 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 902 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 903 | { |
| 904 | if (reg == 0x1f) { |
| 905 | tp->ocp_base = value << 4; |
| 906 | return; |
| 907 | } |
| 908 | |
| 909 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 910 | } |
| 911 | |
| 912 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 913 | { |
| 914 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 915 | } |
| 916 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 917 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 918 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 919 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 920 | } |
| 921 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 922 | 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] | 923 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 924 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 926 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 927 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 928 | * According to hardware specs a 20us delay is required after write |
| 929 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 930 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 931 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 934 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 936 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 938 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 940 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 941 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 942 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 943 | /* |
| 944 | * According to hardware specs a 20us delay is required after read |
| 945 | * complete indication, but before sending next command. |
| 946 | */ |
| 947 | udelay(20); |
| 948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | return value; |
| 950 | } |
| 951 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 952 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 953 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 954 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 955 | } |
| 956 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 957 | 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] | 958 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 959 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 960 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 961 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 962 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 963 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 966 | 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] | 967 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 968 | r8168dp_1_mdio_access(tp, reg, |
| 969 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 972 | 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] | 973 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 974 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 975 | |
| 976 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 977 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 978 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 979 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 980 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 981 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 982 | } |
| 983 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 984 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 985 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 986 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 987 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 988 | 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] | 989 | } |
| 990 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 991 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 992 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 993 | 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] | 994 | } |
| 995 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 996 | 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] | 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 | r8169_mdio_write(tp, reg, value); |
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 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1005 | 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] | 1006 | { |
| 1007 | int value; |
| 1008 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1009 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1010 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1011 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1012 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1013 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1014 | |
| 1015 | return value; |
| 1016 | } |
| 1017 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1018 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1019 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1020 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1021 | } |
| 1022 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1023 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1024 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1025 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1029 | { |
| 1030 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1031 | } |
| 1032 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1033 | 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] | 1034 | { |
| 1035 | int val; |
| 1036 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1037 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1038 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1041 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1042 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1043 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1046 | 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] | 1047 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1048 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1049 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1050 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1051 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1052 | |
| 1053 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1056 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1057 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1058 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1059 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1060 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1061 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1064 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1065 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1066 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1069 | static void _rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1070 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1071 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1072 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1073 | RTL_W32(tp, ERIDR, val); |
| 1074 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1075 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1076 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1079 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1080 | u32 val) |
| 1081 | { |
| 1082 | _rtl_eri_write(tp, addr, mask, val, ERIAR_EXGMAC); |
| 1083 | } |
| 1084 | |
| 1085 | 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] | 1086 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1087 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | 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 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1090 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1091 | } |
| 1092 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1093 | static u32 rtl_eri_read(struct rtl8169_private *tp, int addr) |
| 1094 | { |
| 1095 | return _rtl_eri_read(tp, addr, ERIAR_EXGMAC); |
| 1096 | } |
| 1097 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1098 | 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] | 1099 | u32 m) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1100 | { |
| 1101 | u32 val; |
| 1102 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1103 | val = rtl_eri_read(tp, addr); |
| 1104 | rtl_eri_write(tp, addr, mask, (val & ~m) | p); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1105 | } |
| 1106 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1107 | static void rtl_eri_set_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1108 | u32 p) |
| 1109 | { |
| 1110 | rtl_w0w1_eri(tp, addr, mask, p, 0); |
| 1111 | } |
| 1112 | |
| 1113 | static void rtl_eri_clear_bits(struct rtl8169_private *tp, int addr, u32 mask, |
| 1114 | u32 m) |
| 1115 | { |
| 1116 | rtl_w0w1_eri(tp, addr, mask, 0, m); |
| 1117 | } |
| 1118 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1119 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1120 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1121 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1122 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1123 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1127 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1128 | return _rtl_eri_read(tp, reg, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1129 | } |
| 1130 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1131 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1132 | u32 data) |
| 1133 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1134 | RTL_W32(tp, OCPDR, data); |
| 1135 | 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] | 1136 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1137 | } |
| 1138 | |
| 1139 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1140 | u32 data) |
| 1141 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1142 | _rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1143 | data, ERIAR_OOB); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1144 | } |
| 1145 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1146 | static void r8168dp_oob_notify(struct rtl8169_private *tp, u8 cmd) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1147 | { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1148 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1149 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1150 | r8168dp_ocp_write(tp, 0x1, 0x30, 0x00000001); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | #define OOB_CMD_RESET 0x00 |
| 1154 | #define OOB_CMD_DRIVER_START 0x05 |
| 1155 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1156 | |
| 1157 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1158 | { |
| 1159 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1160 | } |
| 1161 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1162 | DECLARE_RTL_COND(rtl_dp_ocp_read_cond) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1163 | { |
| 1164 | u16 reg; |
| 1165 | |
| 1166 | reg = rtl8168_get_ocp_reg(tp); |
| 1167 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1168 | return r8168dp_ocp_read(tp, 0x0f, reg) & 0x00000800; |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1171 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1172 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1173 | return r8168ep_ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1177 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1178 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1179 | } |
| 1180 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1181 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1182 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1183 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1184 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1185 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1186 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1189 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1190 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1191 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 1192 | 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] | 1193 | } |
| 1194 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1195 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1196 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1197 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1198 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1199 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1200 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1201 | } |
| 1202 | |
| 1203 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1204 | { |
| 1205 | switch (tp->mac_version) { |
| 1206 | case RTL_GIGA_MAC_VER_27: |
| 1207 | case RTL_GIGA_MAC_VER_28: |
| 1208 | case RTL_GIGA_MAC_VER_31: |
| 1209 | rtl8168dp_driver_start(tp); |
| 1210 | break; |
| 1211 | case RTL_GIGA_MAC_VER_49: |
| 1212 | case RTL_GIGA_MAC_VER_50: |
| 1213 | case RTL_GIGA_MAC_VER_51: |
| 1214 | rtl8168ep_driver_start(tp); |
| 1215 | break; |
| 1216 | default: |
| 1217 | BUG(); |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1223 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1224 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1225 | 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] | 1226 | } |
| 1227 | |
| 1228 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1229 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1230 | rtl8168ep_stop_cmac(tp); |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1231 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1232 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1233 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1234 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1235 | } |
| 1236 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1237 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1238 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1239 | switch (tp->mac_version) { |
| 1240 | case RTL_GIGA_MAC_VER_27: |
| 1241 | case RTL_GIGA_MAC_VER_28: |
| 1242 | case RTL_GIGA_MAC_VER_31: |
| 1243 | rtl8168dp_driver_stop(tp); |
| 1244 | break; |
| 1245 | case RTL_GIGA_MAC_VER_49: |
| 1246 | case RTL_GIGA_MAC_VER_50: |
| 1247 | case RTL_GIGA_MAC_VER_51: |
| 1248 | rtl8168ep_driver_stop(tp); |
| 1249 | break; |
| 1250 | default: |
| 1251 | BUG(); |
| 1252 | break; |
| 1253 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1254 | } |
| 1255 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1256 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1257 | { |
| 1258 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1259 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1260 | return !!(r8168dp_ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1263 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1264 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1265 | return !!(r8168ep_ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1266 | } |
| 1267 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1268 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1269 | { |
| 1270 | switch (tp->mac_version) { |
| 1271 | case RTL_GIGA_MAC_VER_27: |
| 1272 | case RTL_GIGA_MAC_VER_28: |
| 1273 | case RTL_GIGA_MAC_VER_31: |
| 1274 | return r8168dp_check_dash(tp); |
| 1275 | case RTL_GIGA_MAC_VER_49: |
| 1276 | case RTL_GIGA_MAC_VER_50: |
| 1277 | case RTL_GIGA_MAC_VER_51: |
| 1278 | return r8168ep_check_dash(tp); |
| 1279 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1280 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1281 | } |
| 1282 | } |
| 1283 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1284 | static void rtl_reset_packet_filter(struct rtl8169_private *tp) |
| 1285 | { |
| 1286 | rtl_eri_clear_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1287 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_0001, BIT(0)); |
| 1288 | } |
| 1289 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1290 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1291 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1292 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1295 | 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] | 1296 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1297 | 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] | 1298 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1299 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1300 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1303 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1304 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1305 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1309 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1310 | RTL_W16(tp, IntrMask, 0); |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1311 | tp->irq_enabled = 0; |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1312 | } |
| 1313 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1314 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1315 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1316 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1317 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1318 | static void rtl_irq_enable(struct rtl8169_private *tp) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1319 | { |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 1320 | tp->irq_enabled = 1; |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 1321 | RTL_W16(tp, IntrMask, tp->irq_mask); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1324 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1326 | rtl_irq_disable(tp); |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 1327 | rtl_ack_events(tp, 0xffff); |
| 1328 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1329 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1332 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1333 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1334 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 1335 | struct phy_device *phydev = tp->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1336 | |
| 1337 | if (!netif_running(dev)) |
| 1338 | return; |
| 1339 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1340 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1341 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1342 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1343 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1344 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1345 | } else if (phydev->speed == SPEED_100) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1346 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1347 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1348 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1349 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1350 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1351 | } |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 1352 | rtl_reset_packet_filter(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1353 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1354 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1355 | if (phydev->speed == SPEED_1000) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1356 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011); |
| 1357 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1358 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1359 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f); |
| 1360 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1361 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1362 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1363 | if (phydev->speed == SPEED_10) { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1364 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02); |
| 1365 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060a); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1366 | } else { |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 1367 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1368 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1372 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1373 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1374 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1375 | { |
| 1376 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1377 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1378 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1379 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1380 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1381 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1384 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1385 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1386 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1387 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1388 | u32 opt; |
| 1389 | u16 reg; |
| 1390 | u8 mask; |
| 1391 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1392 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1393 | { WAKE_UCAST, Config5, UWF }, |
| 1394 | { WAKE_BCAST, Config5, BWF }, |
| 1395 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1396 | { WAKE_ANY, Config5, LanWake }, |
| 1397 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1398 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1399 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1400 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1401 | rtl_unlock_config_regs(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1402 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1403 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1404 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1405 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1406 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1407 | if (wolopts & WAKE_MAGIC) |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1408 | rtl_eri_set_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1409 | MagicPacket_v2); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1410 | else |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 1411 | rtl_eri_clear_bits(tp, 0x0dc, ERIAR_MASK_0100, |
| 1412 | MagicPacket_v2); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1413 | break; |
| 1414 | default: |
| 1415 | tmp = ARRAY_SIZE(cfg); |
| 1416 | break; |
| 1417 | } |
| 1418 | |
| 1419 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1420 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1421 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1422 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1423 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1426 | switch (tp->mac_version) { |
| 1427 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1428 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1429 | if (wolopts) |
| 1430 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1431 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1432 | break; |
| 1433 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1434 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1435 | if (wolopts) |
| 1436 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1437 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1438 | break; |
| 1439 | } |
| 1440 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 1441 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 3bd8264 | 2018-12-30 13:16:12 +0100 | [diff] [blame] | 1442 | |
| 1443 | device_set_wakeup_enable(tp_to_dev(tp), wolopts); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1447 | { |
| 1448 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1449 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1450 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1451 | if (wol->wolopts & ~WAKE_ANY) |
| 1452 | return -EINVAL; |
| 1453 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1454 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1455 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1456 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1457 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1458 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1459 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1460 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1461 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1462 | |
| 1463 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1464 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1465 | pm_runtime_put_noidle(d); |
| 1466 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1467 | return 0; |
| 1468 | } |
| 1469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1471 | struct ethtool_drvinfo *info) |
| 1472 | { |
| 1473 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1474 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1476 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1477 | 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] | 1478 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 1479 | if (rtl_fw) |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1480 | strlcpy(info->fw_version, rtl_fw->version, |
| 1481 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1485 | { |
| 1486 | return R8169_REGS_SIZE; |
| 1487 | } |
| 1488 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1489 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1490 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1492 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1493 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1494 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1495 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1497 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1498 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1499 | features &= ~NETIF_F_IP_CSUM; |
| 1500 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1501 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1504 | static int rtl8169_set_features(struct net_device *dev, |
| 1505 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | { |
| 1507 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1508 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1510 | rtl_lock_work(tp); |
| 1511 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1512 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1513 | if (features & NETIF_F_RXALL) |
| 1514 | rx_config |= (AcceptErr | AcceptRunt); |
| 1515 | else |
| 1516 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1518 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1519 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1520 | if (features & NETIF_F_RXCSUM) |
| 1521 | tp->cp_cmd |= RxChkSum; |
| 1522 | else |
| 1523 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1524 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1525 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1526 | tp->cp_cmd |= RxVlan; |
| 1527 | else |
| 1528 | tp->cp_cmd &= ~RxVlan; |
| 1529 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1530 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1531 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1533 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1538 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1540 | return (skb_vlan_tag_present(skb)) ? |
| 1541 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1544 | 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] | 1545 | { |
| 1546 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1548 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1549 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1553 | void *p) |
| 1554 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1555 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1556 | u32 __iomem *data = tp->mmio_addr; |
| 1557 | u32 *dw = p; |
| 1558 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1560 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1561 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1562 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1563 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1566 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1567 | { |
| 1568 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1569 | |
| 1570 | return tp->msg_enable; |
| 1571 | } |
| 1572 | |
| 1573 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1574 | { |
| 1575 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1576 | |
| 1577 | tp->msg_enable = value; |
| 1578 | } |
| 1579 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1580 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1581 | "tx_packets", |
| 1582 | "rx_packets", |
| 1583 | "tx_errors", |
| 1584 | "rx_errors", |
| 1585 | "rx_missed", |
| 1586 | "align_errors", |
| 1587 | "tx_single_collisions", |
| 1588 | "tx_multi_collisions", |
| 1589 | "unicast", |
| 1590 | "broadcast", |
| 1591 | "multicast", |
| 1592 | "tx_aborted", |
| 1593 | "tx_underrun", |
| 1594 | }; |
| 1595 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1596 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1597 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1598 | switch (sset) { |
| 1599 | case ETH_SS_STATS: |
| 1600 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1601 | default: |
| 1602 | return -EOPNOTSUPP; |
| 1603 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1606 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1607 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1608 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1609 | } |
| 1610 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1611 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1612 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1613 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1614 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1615 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1616 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1617 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1618 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1619 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1620 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1621 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1622 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1623 | } |
| 1624 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1625 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1626 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1627 | /* |
| 1628 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1629 | * tally counters. |
| 1630 | */ |
| 1631 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1632 | return true; |
| 1633 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1634 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1637 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1638 | { |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1639 | u8 val = RTL_R8(tp, ChipCmd); |
| 1640 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1641 | /* |
| 1642 | * Some chips are unable to dump tally counters when the receiver |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1643 | * 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] | 1644 | */ |
Heiner Kallweit | 10262b0 | 2019-01-06 20:44:00 +0100 | [diff] [blame] | 1645 | if (!(val & CmdRxEnb) || val == 0xff) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1646 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1647 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1648 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1649 | } |
| 1650 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1651 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1652 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1653 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1654 | bool ret = false; |
| 1655 | |
| 1656 | /* |
| 1657 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1658 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1659 | * reset by a power cycle, while the counter values collected by the |
| 1660 | * driver are reset at every driver unload/load cycle. |
| 1661 | * |
| 1662 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1663 | * values, we collect the initial values at first open(*) and use them |
| 1664 | * as offsets to normalize the values returned by @get_stats64. |
| 1665 | * |
| 1666 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1667 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1668 | * set at open time by rtl_hw_start. |
| 1669 | */ |
| 1670 | |
| 1671 | if (tp->tc_offset.inited) |
| 1672 | return true; |
| 1673 | |
| 1674 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1675 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1676 | ret = true; |
| 1677 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1678 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1679 | ret = true; |
| 1680 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1681 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1682 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1683 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1684 | tp->tc_offset.inited = true; |
| 1685 | |
| 1686 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1687 | } |
| 1688 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1689 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1690 | struct ethtool_stats *stats, u64 *data) |
| 1691 | { |
| 1692 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1693 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1694 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1695 | |
| 1696 | ASSERT_RTNL(); |
| 1697 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1698 | pm_runtime_get_noresume(d); |
| 1699 | |
| 1700 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1701 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1702 | |
| 1703 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1704 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1705 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1706 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1707 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1708 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1709 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1710 | data[5] = le16_to_cpu(counters->align_errors); |
| 1711 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1712 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1713 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1714 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1715 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1716 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1717 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1720 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1721 | { |
| 1722 | switch(stringset) { |
| 1723 | case ETH_SS_STATS: |
| 1724 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1725 | break; |
| 1726 | } |
| 1727 | } |
| 1728 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1729 | /* |
| 1730 | * Interrupt coalescing |
| 1731 | * |
| 1732 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1733 | * > 8169, 8168 and 810x line of chipsets |
| 1734 | * |
| 1735 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1736 | * |
| 1737 | * > 2 - the Tx timer unit at gigabit speed |
| 1738 | * |
| 1739 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1740 | * (0xe0) bit 1 and bit 0. |
| 1741 | * |
| 1742 | * For 8169 |
| 1743 | * bit[1:0] \ speed 1000M 100M 10M |
| 1744 | * 0 0 320ns 2.56us 40.96us |
| 1745 | * 0 1 2.56us 20.48us 327.7us |
| 1746 | * 1 0 5.12us 40.96us 655.4us |
| 1747 | * 1 1 10.24us 81.92us 1.31ms |
| 1748 | * |
| 1749 | * For the other |
| 1750 | * bit[1:0] \ speed 1000M 100M 10M |
| 1751 | * 0 0 5us 2.56us 40.96us |
| 1752 | * 0 1 40us 20.48us 327.7us |
| 1753 | * 1 0 80us 40.96us 655.4us |
| 1754 | * 1 1 160us 81.92us 1.31ms |
| 1755 | */ |
| 1756 | |
| 1757 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1758 | struct rtl_coalesce_scale { |
| 1759 | /* Rx / Tx */ |
| 1760 | u32 nsecs[2]; |
| 1761 | }; |
| 1762 | |
| 1763 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1764 | struct rtl_coalesce_info { |
| 1765 | u32 speed; |
| 1766 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1767 | }; |
| 1768 | |
| 1769 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1770 | #define rxtx_x1822(r, t) { \ |
| 1771 | {{(r), (t)}}, \ |
| 1772 | {{(r)*8, (t)*8}}, \ |
| 1773 | {{(r)*8*2, (t)*8*2}}, \ |
| 1774 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1775 | } |
| 1776 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1777 | /* speed delays: rx00 tx00 */ |
| 1778 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1779 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1780 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1781 | { 0 }, |
| 1782 | }; |
| 1783 | |
| 1784 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1785 | /* speed delays: rx00 tx00 */ |
| 1786 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1787 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1788 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1789 | { 0 }, |
| 1790 | }; |
| 1791 | #undef rxtx_x1822 |
| 1792 | |
| 1793 | /* get rx/tx scale vector corresponding to current speed */ |
| 1794 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1795 | { |
| 1796 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1797 | struct ethtool_link_ksettings ecmd; |
| 1798 | const struct rtl_coalesce_info *ci; |
| 1799 | int rc; |
| 1800 | |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 1801 | rc = phy_ethtool_get_link_ksettings(dev, &ecmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1802 | if (rc < 0) |
| 1803 | return ERR_PTR(rc); |
| 1804 | |
| 1805 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 1806 | if (ecmd.base.speed == ci->speed) { |
| 1807 | return ci; |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | return ERR_PTR(-ELNRNG); |
| 1812 | } |
| 1813 | |
| 1814 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1815 | { |
| 1816 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1817 | const struct rtl_coalesce_info *ci; |
| 1818 | const struct rtl_coalesce_scale *scale; |
| 1819 | struct { |
| 1820 | u32 *max_frames; |
| 1821 | u32 *usecs; |
| 1822 | } coal_settings [] = { |
| 1823 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1824 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1825 | }, *p = coal_settings; |
| 1826 | int i; |
| 1827 | u16 w; |
| 1828 | |
| 1829 | memset(ec, 0, sizeof(*ec)); |
| 1830 | |
| 1831 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1832 | ci = rtl_coalesce_info(dev); |
| 1833 | if (IS_ERR(ci)) |
| 1834 | return PTR_ERR(ci); |
| 1835 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1836 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1837 | |
| 1838 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1839 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1840 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1841 | w >>= RTL_COALESCE_SHIFT; |
| 1842 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1843 | } |
| 1844 | |
| 1845 | for (i = 0; i < 2; i++) { |
| 1846 | p = coal_settings + i; |
| 1847 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1848 | |
| 1849 | /* |
| 1850 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1851 | * max_frames to 0. |
| 1852 | */ |
| 1853 | if (!*p->usecs && !*p->max_frames) |
| 1854 | *p->max_frames = 1; |
| 1855 | } |
| 1856 | |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
| 1860 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1861 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1862 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1863 | { |
| 1864 | const struct rtl_coalesce_info *ci; |
| 1865 | u16 i; |
| 1866 | |
| 1867 | ci = rtl_coalesce_info(dev); |
| 1868 | if (IS_ERR(ci)) |
| 1869 | return ERR_CAST(ci); |
| 1870 | |
| 1871 | for (i = 0; i < 4; i++) { |
| 1872 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1873 | ci->scalev[i].nsecs[1]); |
| 1874 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1875 | *cp01 = i; |
| 1876 | return &ci->scalev[i]; |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | return ERR_PTR(-EINVAL); |
| 1881 | } |
| 1882 | |
| 1883 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1884 | { |
| 1885 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1886 | const struct rtl_coalesce_scale *scale; |
| 1887 | struct { |
| 1888 | u32 frames; |
| 1889 | u32 usecs; |
| 1890 | } coal_settings [] = { |
| 1891 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1892 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1893 | }, *p = coal_settings; |
| 1894 | u16 w = 0, cp01; |
| 1895 | int i; |
| 1896 | |
| 1897 | scale = rtl_coalesce_choose_scale(dev, |
| 1898 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1899 | if (IS_ERR(scale)) |
| 1900 | return PTR_ERR(scale); |
| 1901 | |
| 1902 | for (i = 0; i < 2; i++, p++) { |
| 1903 | u32 units; |
| 1904 | |
| 1905 | /* |
| 1906 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1907 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1908 | * |
| 1909 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 1910 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 1911 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 1912 | * |
| 1913 | * since ethtool sends to kernel whole ethtool_coalesce |
| 1914 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 1915 | * we'll reject it below in `frames % 4 != 0`. |
| 1916 | */ |
| 1917 | if (p->frames == 1) { |
| 1918 | p->frames = 0; |
| 1919 | } |
| 1920 | |
| 1921 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 1922 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 1923 | return -EINVAL; |
| 1924 | |
| 1925 | w <<= RTL_COALESCE_SHIFT; |
| 1926 | w |= units; |
| 1927 | w <<= RTL_COALESCE_SHIFT; |
| 1928 | w |= p->frames >> 2; |
| 1929 | } |
| 1930 | |
| 1931 | rtl_lock_work(tp); |
| 1932 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1933 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1934 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 1935 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1936 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1937 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1938 | |
| 1939 | rtl_unlock_work(tp); |
| 1940 | |
| 1941 | return 0; |
| 1942 | } |
| 1943 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1944 | static int rtl_get_eee_supp(struct rtl8169_private *tp) |
| 1945 | { |
| 1946 | struct phy_device *phydev = tp->phydev; |
| 1947 | int ret; |
| 1948 | |
| 1949 | switch (tp->mac_version) { |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 1950 | case RTL_GIGA_MAC_VER_34: |
| 1951 | case RTL_GIGA_MAC_VER_35: |
| 1952 | case RTL_GIGA_MAC_VER_36: |
| 1953 | case RTL_GIGA_MAC_VER_38: |
| 1954 | ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE); |
| 1955 | break; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1956 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1957 | phy_write(phydev, 0x1f, 0x0a5c); |
| 1958 | ret = phy_read(phydev, 0x12); |
| 1959 | phy_write(phydev, 0x1f, 0x0000); |
| 1960 | break; |
| 1961 | default: |
| 1962 | ret = -EPROTONOSUPPORT; |
| 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | return ret; |
| 1967 | } |
| 1968 | |
| 1969 | static int rtl_get_eee_lpadv(struct rtl8169_private *tp) |
| 1970 | { |
| 1971 | struct phy_device *phydev = tp->phydev; |
| 1972 | int ret; |
| 1973 | |
| 1974 | switch (tp->mac_version) { |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 1975 | case RTL_GIGA_MAC_VER_34: |
| 1976 | case RTL_GIGA_MAC_VER_35: |
| 1977 | case RTL_GIGA_MAC_VER_36: |
| 1978 | case RTL_GIGA_MAC_VER_38: |
| 1979 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE); |
| 1980 | break; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 1981 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 1982 | phy_write(phydev, 0x1f, 0x0a5d); |
| 1983 | ret = phy_read(phydev, 0x11); |
| 1984 | phy_write(phydev, 0x1f, 0x0000); |
| 1985 | break; |
| 1986 | default: |
| 1987 | ret = -EPROTONOSUPPORT; |
| 1988 | break; |
| 1989 | } |
| 1990 | |
| 1991 | return ret; |
| 1992 | } |
| 1993 | |
| 1994 | static int rtl_get_eee_adv(struct rtl8169_private *tp) |
| 1995 | { |
| 1996 | struct phy_device *phydev = tp->phydev; |
| 1997 | int ret; |
| 1998 | |
| 1999 | switch (tp->mac_version) { |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2000 | case RTL_GIGA_MAC_VER_34: |
| 2001 | case RTL_GIGA_MAC_VER_35: |
| 2002 | case RTL_GIGA_MAC_VER_36: |
| 2003 | case RTL_GIGA_MAC_VER_38: |
| 2004 | ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV); |
| 2005 | break; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2006 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 2007 | phy_write(phydev, 0x1f, 0x0a5d); |
| 2008 | ret = phy_read(phydev, 0x10); |
| 2009 | phy_write(phydev, 0x1f, 0x0000); |
| 2010 | break; |
| 2011 | default: |
| 2012 | ret = -EPROTONOSUPPORT; |
| 2013 | break; |
| 2014 | } |
| 2015 | |
| 2016 | return ret; |
| 2017 | } |
| 2018 | |
| 2019 | static int rtl_set_eee_adv(struct rtl8169_private *tp, int val) |
| 2020 | { |
| 2021 | struct phy_device *phydev = tp->phydev; |
| 2022 | int ret = 0; |
| 2023 | |
| 2024 | switch (tp->mac_version) { |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2025 | case RTL_GIGA_MAC_VER_34: |
| 2026 | case RTL_GIGA_MAC_VER_35: |
| 2027 | case RTL_GIGA_MAC_VER_36: |
| 2028 | case RTL_GIGA_MAC_VER_38: |
| 2029 | ret = phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
| 2030 | break; |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2031 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
| 2032 | phy_write(phydev, 0x1f, 0x0a5d); |
| 2033 | phy_write(phydev, 0x10, val); |
| 2034 | phy_write(phydev, 0x1f, 0x0000); |
| 2035 | break; |
| 2036 | default: |
| 2037 | ret = -EPROTONOSUPPORT; |
| 2038 | break; |
| 2039 | } |
| 2040 | |
| 2041 | return ret; |
| 2042 | } |
| 2043 | |
| 2044 | static int rtl8169_get_eee(struct net_device *dev, struct ethtool_eee *data) |
| 2045 | { |
| 2046 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2047 | struct device *d = tp_to_dev(tp); |
| 2048 | int ret; |
| 2049 | |
| 2050 | pm_runtime_get_noresume(d); |
| 2051 | |
| 2052 | if (!pm_runtime_active(d)) { |
| 2053 | ret = -EOPNOTSUPP; |
| 2054 | goto out; |
| 2055 | } |
| 2056 | |
| 2057 | /* Get Supported EEE */ |
| 2058 | ret = rtl_get_eee_supp(tp); |
| 2059 | if (ret < 0) |
| 2060 | goto out; |
| 2061 | data->supported = mmd_eee_cap_to_ethtool_sup_t(ret); |
| 2062 | |
| 2063 | /* Get advertisement EEE */ |
| 2064 | ret = rtl_get_eee_adv(tp); |
| 2065 | if (ret < 0) |
| 2066 | goto out; |
| 2067 | data->advertised = mmd_eee_adv_to_ethtool_adv_t(ret); |
| 2068 | data->eee_enabled = !!data->advertised; |
| 2069 | |
| 2070 | /* Get LP advertisement EEE */ |
| 2071 | ret = rtl_get_eee_lpadv(tp); |
| 2072 | if (ret < 0) |
| 2073 | goto out; |
| 2074 | data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(ret); |
| 2075 | data->eee_active = !!(data->advertised & data->lp_advertised); |
| 2076 | out: |
| 2077 | pm_runtime_put_noidle(d); |
| 2078 | return ret < 0 ? ret : 0; |
| 2079 | } |
| 2080 | |
| 2081 | static int rtl8169_set_eee(struct net_device *dev, struct ethtool_eee *data) |
| 2082 | { |
| 2083 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2084 | struct device *d = tp_to_dev(tp); |
| 2085 | int old_adv, adv = 0, cap, ret; |
| 2086 | |
| 2087 | pm_runtime_get_noresume(d); |
| 2088 | |
| 2089 | if (!dev->phydev || !pm_runtime_active(d)) { |
| 2090 | ret = -EOPNOTSUPP; |
| 2091 | goto out; |
| 2092 | } |
| 2093 | |
| 2094 | if (dev->phydev->autoneg == AUTONEG_DISABLE || |
| 2095 | dev->phydev->duplex != DUPLEX_FULL) { |
| 2096 | ret = -EPROTONOSUPPORT; |
| 2097 | goto out; |
| 2098 | } |
| 2099 | |
| 2100 | /* Get Supported EEE */ |
| 2101 | ret = rtl_get_eee_supp(tp); |
| 2102 | if (ret < 0) |
| 2103 | goto out; |
| 2104 | cap = ret; |
| 2105 | |
| 2106 | ret = rtl_get_eee_adv(tp); |
| 2107 | if (ret < 0) |
| 2108 | goto out; |
| 2109 | old_adv = ret; |
| 2110 | |
| 2111 | if (data->eee_enabled) { |
| 2112 | adv = !data->advertised ? cap : |
| 2113 | ethtool_adv_to_mmd_eee_adv_t(data->advertised) & cap; |
| 2114 | /* Mask prohibited EEE modes */ |
| 2115 | adv &= ~dev->phydev->eee_broken_modes; |
| 2116 | } |
| 2117 | |
| 2118 | if (old_adv != adv) { |
| 2119 | ret = rtl_set_eee_adv(tp, adv); |
| 2120 | if (ret < 0) |
| 2121 | goto out; |
| 2122 | |
| 2123 | /* Restart autonegotiation so the new modes get sent to the |
| 2124 | * link partner. |
| 2125 | */ |
| 2126 | ret = phy_restart_aneg(dev->phydev); |
| 2127 | } |
| 2128 | |
| 2129 | out: |
| 2130 | pm_runtime_put_noidle(d); |
| 2131 | return ret < 0 ? ret : 0; |
| 2132 | } |
| 2133 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2134 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2136 | .get_regs_len = rtl8169_get_regs_len, |
| 2137 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2138 | .get_coalesce = rtl_get_coalesce, |
| 2139 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2140 | .get_msglevel = rtl8169_get_msglevel, |
| 2141 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2143 | .get_wol = rtl8169_get_wol, |
| 2144 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2145 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2146 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2147 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2148 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2149 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2150 | .get_eee = rtl8169_get_eee, |
| 2151 | .set_eee = rtl8169_set_eee, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2152 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2153 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | }; |
| 2155 | |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 2156 | static void rtl_enable_eee(struct rtl8169_private *tp) |
| 2157 | { |
| 2158 | int supported = rtl_get_eee_supp(tp); |
| 2159 | |
| 2160 | if (supported > 0) |
| 2161 | rtl_set_eee_adv(tp, supported); |
| 2162 | } |
| 2163 | |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2164 | static void rtl8169_get_mac_version(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2166 | /* |
| 2167 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2168 | * but they can be identified more specifically through the test below |
| 2169 | * if needed: |
| 2170 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2171 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2172 | * |
| 2173 | * Same thing for the 8101Eb and the 8101Ec: |
| 2174 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2175 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2176 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2177 | static const struct rtl_mac_info { |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2178 | u16 mask; |
| 2179 | u16 val; |
| 2180 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2182 | /* 8168EP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2183 | { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51 }, |
| 2184 | { 0x7cf, 0x501, RTL_GIGA_MAC_VER_50 }, |
| 2185 | { 0x7cf, 0x500, RTL_GIGA_MAC_VER_49 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2186 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2187 | /* 8168H family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2188 | { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46 }, |
| 2189 | { 0x7cf, 0x540, RTL_GIGA_MAC_VER_45 }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2190 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2191 | /* 8168G family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2192 | { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44 }, |
| 2193 | { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42 }, |
| 2194 | { 0x7cf, 0x4c1, RTL_GIGA_MAC_VER_41 }, |
| 2195 | { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2196 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2197 | /* 8168F family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2198 | { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38 }, |
| 2199 | { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36 }, |
| 2200 | { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2201 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2202 | /* 8168E family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2203 | { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34 }, |
| 2204 | { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32 }, |
| 2205 | { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2206 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2207 | /* 8168D family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2208 | { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25 }, |
| 2209 | { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2210 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2211 | /* 8168DP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2212 | { 0x7cf, 0x288, RTL_GIGA_MAC_VER_27 }, |
| 2213 | { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28 }, |
| 2214 | { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2215 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2216 | /* 8168C family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2217 | { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23 }, |
| 2218 | { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18 }, |
| 2219 | { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24 }, |
| 2220 | { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19 }, |
| 2221 | { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20 }, |
| 2222 | { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21 }, |
| 2223 | { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2224 | |
| 2225 | /* 8168B family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2226 | { 0x7cf, 0x380, RTL_GIGA_MAC_VER_12 }, |
| 2227 | { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17 }, |
| 2228 | { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2229 | |
| 2230 | /* 8101 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2231 | { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39 }, |
| 2232 | { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37 }, |
| 2233 | { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29 }, |
| 2234 | { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30 }, |
| 2235 | { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08 }, |
| 2236 | { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08 }, |
| 2237 | { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07 }, |
| 2238 | { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07 }, |
| 2239 | { 0x7cf, 0x340, RTL_GIGA_MAC_VER_13 }, |
| 2240 | { 0x7cf, 0x343, RTL_GIGA_MAC_VER_10 }, |
| 2241 | { 0x7cf, 0x342, RTL_GIGA_MAC_VER_16 }, |
| 2242 | { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09 }, |
| 2243 | { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09 }, |
| 2244 | { 0x7c8, 0x340, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2245 | /* FIXME: where did these entries come from ? -- FR */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2246 | { 0xfc8, 0x388, RTL_GIGA_MAC_VER_15 }, |
| 2247 | { 0xfc8, 0x308, RTL_GIGA_MAC_VER_14 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2248 | |
| 2249 | /* 8110 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2250 | { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06 }, |
| 2251 | { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05 }, |
| 2252 | { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04 }, |
| 2253 | { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03 }, |
| 2254 | { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02 }, |
| 2255 | { 0xfc8, 0x000, RTL_GIGA_MAC_VER_01 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2256 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2257 | /* Catch-all */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2258 | { 0x000, 0x000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2259 | }; |
| 2260 | const struct rtl_mac_info *p = mac_info; |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2261 | u16 reg = RTL_R32(tp, TxConfig) >> 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2263 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | p++; |
| 2265 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2266 | |
| 2267 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 2268 | 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] | 2269 | } else if (!tp->supports_gmii) { |
| 2270 | if (tp->mac_version == RTL_GIGA_MAC_VER_42) |
| 2271 | tp->mac_version = RTL_GIGA_MAC_VER_43; |
| 2272 | else if (tp->mac_version == RTL_GIGA_MAC_VER_45) |
| 2273 | tp->mac_version = RTL_GIGA_MAC_VER_47; |
| 2274 | else if (tp->mac_version == RTL_GIGA_MAC_VER_46) |
| 2275 | tp->mac_version = RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2279 | struct phy_reg { |
| 2280 | u16 reg; |
| 2281 | u16 val; |
| 2282 | }; |
| 2283 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2284 | static void __rtl_writephy_batch(struct rtl8169_private *tp, |
| 2285 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2286 | { |
| 2287 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2288 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2289 | regs++; |
| 2290 | } |
| 2291 | } |
| 2292 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2293 | #define rtl_writephy_batch(tp, a) __rtl_writephy_batch(tp, a, ARRAY_SIZE(a)) |
| 2294 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2295 | #define PHY_READ 0x00000000 |
| 2296 | #define PHY_DATA_OR 0x10000000 |
| 2297 | #define PHY_DATA_AND 0x20000000 |
| 2298 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2299 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2300 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2301 | #define PHY_WRITE 0x80000000 |
| 2302 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2303 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2304 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2305 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2306 | #define PHY_SKIPN 0xd0000000 |
| 2307 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2308 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2309 | struct fw_info { |
| 2310 | u32 magic; |
| 2311 | char version[RTL_VER_SIZE]; |
| 2312 | __le32 fw_start; |
| 2313 | __le32 fw_len; |
| 2314 | u8 chksum; |
| 2315 | } __packed; |
| 2316 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2317 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2318 | |
| 2319 | static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2320 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2321 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2322 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2323 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2324 | char *version = rtl_fw->version; |
| 2325 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2326 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2327 | if (fw->size < FW_OPCODE_SIZE) |
| 2328 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2329 | |
| 2330 | if (!fw_info->magic) { |
| 2331 | size_t i, size, start; |
| 2332 | u8 checksum = 0; |
| 2333 | |
| 2334 | if (fw->size < sizeof(*fw_info)) |
| 2335 | goto out; |
| 2336 | |
| 2337 | for (i = 0; i < fw->size; i++) |
| 2338 | checksum += fw->data[i]; |
| 2339 | if (checksum != 0) |
| 2340 | goto out; |
| 2341 | |
| 2342 | start = le32_to_cpu(fw_info->fw_start); |
| 2343 | if (start > fw->size) |
| 2344 | goto out; |
| 2345 | |
| 2346 | size = le32_to_cpu(fw_info->fw_len); |
| 2347 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2348 | goto out; |
| 2349 | |
| 2350 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2351 | |
| 2352 | pa->code = (__le32 *)(fw->data + start); |
| 2353 | pa->size = size; |
| 2354 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2355 | if (fw->size % FW_OPCODE_SIZE) |
| 2356 | goto out; |
| 2357 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2358 | strlcpy(version, tp->fw_name, RTL_VER_SIZE); |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2359 | |
| 2360 | pa->code = (__le32 *)fw->data; |
| 2361 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2362 | } |
| 2363 | version[RTL_VER_SIZE - 1] = 0; |
| 2364 | |
| 2365 | rc = true; |
| 2366 | out: |
| 2367 | return rc; |
| 2368 | } |
| 2369 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2370 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2371 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2372 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2373 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2374 | size_t index; |
| 2375 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2376 | for (index = 0; index < pa->size; index++) { |
| 2377 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2378 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2379 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2380 | switch(action & 0xf0000000) { |
| 2381 | case PHY_READ: |
| 2382 | case PHY_DATA_OR: |
| 2383 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2384 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2385 | case PHY_CLEAR_READCOUNT: |
| 2386 | case PHY_WRITE: |
| 2387 | case PHY_WRITE_PREVIOUS: |
| 2388 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2391 | case PHY_BJMPN: |
| 2392 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2393 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2394 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2395 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2396 | } |
| 2397 | break; |
| 2398 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2399 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2400 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2401 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2402 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2403 | } |
| 2404 | break; |
| 2405 | case PHY_COMP_EQ_SKIPN: |
| 2406 | case PHY_COMP_NEQ_SKIPN: |
| 2407 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2408 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2409 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2410 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2411 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2412 | } |
| 2413 | break; |
| 2414 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2415 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2416 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2417 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2418 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2419 | } |
| 2420 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2421 | rc = true; |
| 2422 | out: |
| 2423 | return rc; |
| 2424 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2425 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2426 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2427 | { |
| 2428 | struct net_device *dev = tp->dev; |
| 2429 | int rc = -EINVAL; |
| 2430 | |
| 2431 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2432 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2433 | goto out; |
| 2434 | } |
| 2435 | |
| 2436 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2437 | rc = 0; |
| 2438 | out: |
| 2439 | return rc; |
| 2440 | } |
| 2441 | |
| 2442 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2443 | { |
| 2444 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2445 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2446 | u32 predata, count; |
| 2447 | size_t index; |
| 2448 | |
| 2449 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2450 | org.write = ops->write; |
| 2451 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2452 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2453 | for (index = 0; index < pa->size; ) { |
| 2454 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2455 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2456 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2457 | |
| 2458 | if (!action) |
| 2459 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2460 | |
| 2461 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2462 | case PHY_READ: |
| 2463 | predata = rtl_readphy(tp, regno); |
| 2464 | count++; |
| 2465 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2466 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2467 | case PHY_DATA_OR: |
| 2468 | predata |= data; |
| 2469 | index++; |
| 2470 | break; |
| 2471 | case PHY_DATA_AND: |
| 2472 | predata &= data; |
| 2473 | index++; |
| 2474 | break; |
| 2475 | case PHY_BJMPN: |
| 2476 | index -= regno; |
| 2477 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2478 | case PHY_MDIO_CHG: |
| 2479 | if (data == 0) { |
| 2480 | ops->write = org.write; |
| 2481 | ops->read = org.read; |
| 2482 | } else if (data == 1) { |
| 2483 | ops->write = mac_mcu_write; |
| 2484 | ops->read = mac_mcu_read; |
| 2485 | } |
| 2486 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2487 | index++; |
| 2488 | break; |
| 2489 | case PHY_CLEAR_READCOUNT: |
| 2490 | count = 0; |
| 2491 | index++; |
| 2492 | break; |
| 2493 | case PHY_WRITE: |
| 2494 | rtl_writephy(tp, regno, data); |
| 2495 | index++; |
| 2496 | break; |
| 2497 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2498 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2499 | break; |
| 2500 | case PHY_COMP_EQ_SKIPN: |
| 2501 | if (predata == data) |
| 2502 | index += regno; |
| 2503 | index++; |
| 2504 | break; |
| 2505 | case PHY_COMP_NEQ_SKIPN: |
| 2506 | if (predata != data) |
| 2507 | index += regno; |
| 2508 | index++; |
| 2509 | break; |
| 2510 | case PHY_WRITE_PREVIOUS: |
| 2511 | rtl_writephy(tp, regno, predata); |
| 2512 | index++; |
| 2513 | break; |
| 2514 | case PHY_SKIPN: |
| 2515 | index += regno + 1; |
| 2516 | break; |
| 2517 | case PHY_DELAY_MS: |
| 2518 | mdelay(data); |
| 2519 | index++; |
| 2520 | break; |
| 2521 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2522 | default: |
| 2523 | BUG(); |
| 2524 | } |
| 2525 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2526 | |
| 2527 | ops->write = org.write; |
| 2528 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2529 | } |
| 2530 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2531 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2532 | { |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2533 | if (tp->rtl_fw) { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2534 | release_firmware(tp->rtl_fw->fw); |
| 2535 | kfree(tp->rtl_fw); |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2536 | tp->rtl_fw = NULL; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2537 | } |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2540 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2541 | { |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2542 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 2543 | if (tp->rtl_fw) |
| 2544 | rtl_phy_write_fw(tp, tp->rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2548 | { |
| 2549 | if (rtl_readphy(tp, reg) != val) |
| 2550 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2551 | else |
| 2552 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2555 | static void rtl8168_config_eee_mac(struct rtl8169_private *tp) |
| 2556 | { |
Heiner Kallweit | f452825 | 2019-05-04 17:13:09 +0200 | [diff] [blame] | 2557 | /* Adjust EEE LED frequency */ |
| 2558 | if (tp->mac_version != RTL_GIGA_MAC_VER_38) |
| 2559 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
| 2560 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 2561 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_1111, 0x0003); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2562 | } |
| 2563 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 2564 | static void rtl8168f_config_eee_phy(struct rtl8169_private *tp) |
| 2565 | { |
| 2566 | struct phy_device *phydev = tp->phydev; |
| 2567 | |
| 2568 | phy_write(phydev, 0x1f, 0x0007); |
| 2569 | phy_write(phydev, 0x1e, 0x0020); |
| 2570 | phy_set_bits(phydev, 0x15, BIT(8)); |
| 2571 | |
| 2572 | phy_write(phydev, 0x1f, 0x0005); |
| 2573 | phy_write(phydev, 0x05, 0x8b85); |
| 2574 | phy_set_bits(phydev, 0x06, BIT(13)); |
| 2575 | |
| 2576 | phy_write(phydev, 0x1f, 0x0000); |
| 2577 | } |
| 2578 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 2579 | static void rtl8168g_config_eee_phy(struct rtl8169_private *tp) |
| 2580 | { |
| 2581 | phy_write(tp->phydev, 0x1f, 0x0a43); |
| 2582 | phy_set_bits(tp->phydev, 0x11, BIT(4)); |
| 2583 | phy_write(tp->phydev, 0x1f, 0x0000); |
| 2584 | } |
| 2585 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2586 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2588 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2589 | { 0x1f, 0x0001 }, |
| 2590 | { 0x06, 0x006e }, |
| 2591 | { 0x08, 0x0708 }, |
| 2592 | { 0x15, 0x4000 }, |
| 2593 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2595 | { 0x1f, 0x0001 }, |
| 2596 | { 0x03, 0x00a1 }, |
| 2597 | { 0x02, 0x0008 }, |
| 2598 | { 0x01, 0x0120 }, |
| 2599 | { 0x00, 0x1000 }, |
| 2600 | { 0x04, 0x0800 }, |
| 2601 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2603 | { 0x03, 0xff41 }, |
| 2604 | { 0x02, 0xdf60 }, |
| 2605 | { 0x01, 0x0140 }, |
| 2606 | { 0x00, 0x0077 }, |
| 2607 | { 0x04, 0x7800 }, |
| 2608 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2610 | { 0x03, 0x802f }, |
| 2611 | { 0x02, 0x4f02 }, |
| 2612 | { 0x01, 0x0409 }, |
| 2613 | { 0x00, 0xf0f9 }, |
| 2614 | { 0x04, 0x9800 }, |
| 2615 | { 0x04, 0x9000 }, |
| 2616 | |
| 2617 | { 0x03, 0xdf01 }, |
| 2618 | { 0x02, 0xdf20 }, |
| 2619 | { 0x01, 0xff95 }, |
| 2620 | { 0x00, 0xba00 }, |
| 2621 | { 0x04, 0xa800 }, |
| 2622 | { 0x04, 0xa000 }, |
| 2623 | |
| 2624 | { 0x03, 0xff41 }, |
| 2625 | { 0x02, 0xdf20 }, |
| 2626 | { 0x01, 0x0140 }, |
| 2627 | { 0x00, 0x00bb }, |
| 2628 | { 0x04, 0xb800 }, |
| 2629 | { 0x04, 0xb000 }, |
| 2630 | |
| 2631 | { 0x03, 0xdf41 }, |
| 2632 | { 0x02, 0xdc60 }, |
| 2633 | { 0x01, 0x6340 }, |
| 2634 | { 0x00, 0x007d }, |
| 2635 | { 0x04, 0xd800 }, |
| 2636 | { 0x04, 0xd000 }, |
| 2637 | |
| 2638 | { 0x03, 0xdf01 }, |
| 2639 | { 0x02, 0xdf20 }, |
| 2640 | { 0x01, 0x100a }, |
| 2641 | { 0x00, 0xa0ff }, |
| 2642 | { 0x04, 0xf800 }, |
| 2643 | { 0x04, 0xf000 }, |
| 2644 | |
| 2645 | { 0x1f, 0x0000 }, |
| 2646 | { 0x0b, 0x0000 }, |
| 2647 | { 0x00, 0x9200 } |
| 2648 | }; |
| 2649 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2650 | rtl_writephy_batch(tp, phy_reg_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2653 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2654 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2655 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2656 | { 0x1f, 0x0002 }, |
| 2657 | { 0x01, 0x90d0 }, |
| 2658 | { 0x1f, 0x0000 } |
| 2659 | }; |
| 2660 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2661 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2662 | } |
| 2663 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2664 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2665 | { |
| 2666 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2667 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2668 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2669 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2670 | return; |
| 2671 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2672 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2673 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2674 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2677 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2678 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2679 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2680 | { 0x1f, 0x0001 }, |
| 2681 | { 0x04, 0x0000 }, |
| 2682 | { 0x03, 0x00a1 }, |
| 2683 | { 0x02, 0x0008 }, |
| 2684 | { 0x01, 0x0120 }, |
| 2685 | { 0x00, 0x1000 }, |
| 2686 | { 0x04, 0x0800 }, |
| 2687 | { 0x04, 0x9000 }, |
| 2688 | { 0x03, 0x802f }, |
| 2689 | { 0x02, 0x4f02 }, |
| 2690 | { 0x01, 0x0409 }, |
| 2691 | { 0x00, 0xf099 }, |
| 2692 | { 0x04, 0x9800 }, |
| 2693 | { 0x04, 0xa000 }, |
| 2694 | { 0x03, 0xdf01 }, |
| 2695 | { 0x02, 0xdf20 }, |
| 2696 | { 0x01, 0xff95 }, |
| 2697 | { 0x00, 0xba00 }, |
| 2698 | { 0x04, 0xa800 }, |
| 2699 | { 0x04, 0xf000 }, |
| 2700 | { 0x03, 0xdf01 }, |
| 2701 | { 0x02, 0xdf20 }, |
| 2702 | { 0x01, 0x101a }, |
| 2703 | { 0x00, 0xa0ff }, |
| 2704 | { 0x04, 0xf800 }, |
| 2705 | { 0x04, 0x0000 }, |
| 2706 | { 0x1f, 0x0000 }, |
| 2707 | |
| 2708 | { 0x1f, 0x0001 }, |
| 2709 | { 0x10, 0xf41b }, |
| 2710 | { 0x14, 0xfb54 }, |
| 2711 | { 0x18, 0xf5c7 }, |
| 2712 | { 0x1f, 0x0000 }, |
| 2713 | |
| 2714 | { 0x1f, 0x0001 }, |
| 2715 | { 0x17, 0x0cc0 }, |
| 2716 | { 0x1f, 0x0000 } |
| 2717 | }; |
| 2718 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2719 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2720 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2721 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2724 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2725 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2726 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2727 | { 0x1f, 0x0001 }, |
| 2728 | { 0x04, 0x0000 }, |
| 2729 | { 0x03, 0x00a1 }, |
| 2730 | { 0x02, 0x0008 }, |
| 2731 | { 0x01, 0x0120 }, |
| 2732 | { 0x00, 0x1000 }, |
| 2733 | { 0x04, 0x0800 }, |
| 2734 | { 0x04, 0x9000 }, |
| 2735 | { 0x03, 0x802f }, |
| 2736 | { 0x02, 0x4f02 }, |
| 2737 | { 0x01, 0x0409 }, |
| 2738 | { 0x00, 0xf099 }, |
| 2739 | { 0x04, 0x9800 }, |
| 2740 | { 0x04, 0xa000 }, |
| 2741 | { 0x03, 0xdf01 }, |
| 2742 | { 0x02, 0xdf20 }, |
| 2743 | { 0x01, 0xff95 }, |
| 2744 | { 0x00, 0xba00 }, |
| 2745 | { 0x04, 0xa800 }, |
| 2746 | { 0x04, 0xf000 }, |
| 2747 | { 0x03, 0xdf01 }, |
| 2748 | { 0x02, 0xdf20 }, |
| 2749 | { 0x01, 0x101a }, |
| 2750 | { 0x00, 0xa0ff }, |
| 2751 | { 0x04, 0xf800 }, |
| 2752 | { 0x04, 0x0000 }, |
| 2753 | { 0x1f, 0x0000 }, |
| 2754 | |
| 2755 | { 0x1f, 0x0001 }, |
| 2756 | { 0x0b, 0x8480 }, |
| 2757 | { 0x1f, 0x0000 }, |
| 2758 | |
| 2759 | { 0x1f, 0x0001 }, |
| 2760 | { 0x18, 0x67c7 }, |
| 2761 | { 0x04, 0x2000 }, |
| 2762 | { 0x03, 0x002f }, |
| 2763 | { 0x02, 0x4360 }, |
| 2764 | { 0x01, 0x0109 }, |
| 2765 | { 0x00, 0x3022 }, |
| 2766 | { 0x04, 0x2800 }, |
| 2767 | { 0x1f, 0x0000 }, |
| 2768 | |
| 2769 | { 0x1f, 0x0001 }, |
| 2770 | { 0x17, 0x0cc0 }, |
| 2771 | { 0x1f, 0x0000 } |
| 2772 | }; |
| 2773 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2774 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2777 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2778 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2779 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2780 | { 0x10, 0xf41b }, |
| 2781 | { 0x1f, 0x0000 } |
| 2782 | }; |
| 2783 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2784 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2785 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2786 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2787 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2788 | } |
| 2789 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2790 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2791 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2792 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2793 | { 0x1f, 0x0001 }, |
| 2794 | { 0x10, 0xf41b }, |
| 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); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2799 | } |
| 2800 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2801 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2802 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2803 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2804 | { 0x1f, 0x0000 }, |
| 2805 | { 0x1d, 0x0f00 }, |
| 2806 | { 0x1f, 0x0002 }, |
| 2807 | { 0x0c, 0x1ec8 }, |
| 2808 | { 0x1f, 0x0000 } |
| 2809 | }; |
| 2810 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2811 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2812 | } |
| 2813 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2814 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2815 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2816 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2817 | { 0x1f, 0x0001 }, |
| 2818 | { 0x1d, 0x3d98 }, |
| 2819 | { 0x1f, 0x0000 } |
| 2820 | }; |
| 2821 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2822 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2823 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2824 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2825 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2826 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2827 | } |
| 2828 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2829 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2830 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2831 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2832 | { 0x1f, 0x0001 }, |
| 2833 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2834 | { 0x1f, 0x0002 }, |
| 2835 | { 0x00, 0x88d4 }, |
| 2836 | { 0x01, 0x82b1 }, |
| 2837 | { 0x03, 0x7002 }, |
| 2838 | { 0x08, 0x9e30 }, |
| 2839 | { 0x09, 0x01f0 }, |
| 2840 | { 0x0a, 0x5500 }, |
| 2841 | { 0x0c, 0x00c8 }, |
| 2842 | { 0x1f, 0x0003 }, |
| 2843 | { 0x12, 0xc096 }, |
| 2844 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2845 | { 0x1f, 0x0000 }, |
| 2846 | { 0x1f, 0x0000 }, |
| 2847 | { 0x09, 0x2000 }, |
| 2848 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2849 | }; |
| 2850 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2851 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2852 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2853 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2854 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2855 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2856 | } |
| 2857 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2858 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2859 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2860 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2861 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2862 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2863 | { 0x03, 0x802f }, |
| 2864 | { 0x02, 0x4f02 }, |
| 2865 | { 0x01, 0x0409 }, |
| 2866 | { 0x00, 0xf099 }, |
| 2867 | { 0x04, 0x9800 }, |
| 2868 | { 0x04, 0x9000 }, |
| 2869 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2870 | { 0x1f, 0x0002 }, |
| 2871 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2872 | { 0x06, 0x0761 }, |
| 2873 | { 0x1f, 0x0003 }, |
| 2874 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2875 | { 0x1f, 0x0000 } |
| 2876 | }; |
| 2877 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2878 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2879 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2880 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2881 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2882 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2883 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2884 | } |
| 2885 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2886 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2887 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2888 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2889 | { 0x1f, 0x0001 }, |
| 2890 | { 0x12, 0x2300 }, |
| 2891 | { 0x1d, 0x3d98 }, |
| 2892 | { 0x1f, 0x0002 }, |
| 2893 | { 0x0c, 0x7eb8 }, |
| 2894 | { 0x06, 0x5461 }, |
| 2895 | { 0x1f, 0x0003 }, |
| 2896 | { 0x16, 0x0f0a }, |
| 2897 | { 0x1f, 0x0000 } |
| 2898 | }; |
| 2899 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2900 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2901 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2902 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2903 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2904 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2905 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2906 | } |
| 2907 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2908 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2909 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2910 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2913 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2914 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2915 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2916 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2917 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2918 | { 0x06, 0x4064 }, |
| 2919 | { 0x07, 0x2863 }, |
| 2920 | { 0x08, 0x059c }, |
| 2921 | { 0x09, 0x26b4 }, |
| 2922 | { 0x0a, 0x6a19 }, |
| 2923 | { 0x0b, 0xdcc8 }, |
| 2924 | { 0x10, 0xf06d }, |
| 2925 | { 0x14, 0x7f68 }, |
| 2926 | { 0x18, 0x7fd9 }, |
| 2927 | { 0x1c, 0xf0ff }, |
| 2928 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2929 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2930 | { 0x12, 0xf49f }, |
| 2931 | { 0x13, 0x070b }, |
| 2932 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2933 | { 0x14, 0x94c0 }, |
| 2934 | |
| 2935 | /* |
| 2936 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2937 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2938 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2939 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2940 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2941 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2942 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2943 | { 0x06, 0x5561 }, |
| 2944 | |
| 2945 | /* |
| 2946 | * Can not link to 1Gbps with bad cable |
| 2947 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2948 | */ |
| 2949 | { 0x1f, 0x0001 }, |
| 2950 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2951 | |
| 2952 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2953 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2954 | }; |
| 2955 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2956 | rtl_writephy_batch(tp, phy_reg_init_0); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2957 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2958 | /* |
| 2959 | * Rx Error Issue |
| 2960 | * Fine Tune Switching regulator parameter |
| 2961 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2962 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2963 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2964 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2965 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2966 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2967 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2968 | { 0x1f, 0x0002 }, |
| 2969 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2970 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2971 | { 0x05, 0x8330 }, |
| 2972 | { 0x06, 0x669a }, |
| 2973 | { 0x1f, 0x0002 } |
| 2974 | }; |
| 2975 | int val; |
| 2976 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 2977 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2978 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2979 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2980 | |
| 2981 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2982 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2983 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2984 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2985 | }; |
| 2986 | int i; |
| 2987 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2988 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2989 | |
| 2990 | val &= 0xff00; |
| 2991 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2992 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2993 | } |
| 2994 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2995 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2996 | { 0x1f, 0x0002 }, |
| 2997 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2998 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2999 | { 0x05, 0x8330 }, |
| 3000 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3001 | }; |
| 3002 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3003 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3004 | } |
| 3005 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3006 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3007 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3008 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3009 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3010 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3011 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3012 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3013 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3014 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3015 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3016 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3017 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3018 | |
| 3019 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3020 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3021 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3024 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3025 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3026 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3027 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3028 | { 0x1f, 0x0001 }, |
| 3029 | { 0x06, 0x4064 }, |
| 3030 | { 0x07, 0x2863 }, |
| 3031 | { 0x08, 0x059c }, |
| 3032 | { 0x09, 0x26b4 }, |
| 3033 | { 0x0a, 0x6a19 }, |
| 3034 | { 0x0b, 0xdcc8 }, |
| 3035 | { 0x10, 0xf06d }, |
| 3036 | { 0x14, 0x7f68 }, |
| 3037 | { 0x18, 0x7fd9 }, |
| 3038 | { 0x1c, 0xf0ff }, |
| 3039 | { 0x1d, 0x3d9c }, |
| 3040 | { 0x1f, 0x0003 }, |
| 3041 | { 0x12, 0xf49f }, |
| 3042 | { 0x13, 0x070b }, |
| 3043 | { 0x1a, 0x05ad }, |
| 3044 | { 0x14, 0x94c0 }, |
| 3045 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3046 | /* |
| 3047 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3048 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3049 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3050 | { 0x1f, 0x0002 }, |
| 3051 | { 0x06, 0x5561 }, |
| 3052 | { 0x1f, 0x0005 }, |
| 3053 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3054 | { 0x06, 0x5561 }, |
| 3055 | |
| 3056 | /* |
| 3057 | * Can not link to 1Gbps with bad cable |
| 3058 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3059 | */ |
| 3060 | { 0x1f, 0x0001 }, |
| 3061 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3062 | |
| 3063 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3064 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3065 | }; |
| 3066 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3067 | rtl_writephy_batch(tp, phy_reg_init_0); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3068 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3069 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3070 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3071 | { 0x1f, 0x0002 }, |
| 3072 | { 0x05, 0x669a }, |
| 3073 | { 0x1f, 0x0005 }, |
| 3074 | { 0x05, 0x8330 }, |
| 3075 | { 0x06, 0x669a }, |
| 3076 | |
| 3077 | { 0x1f, 0x0002 } |
| 3078 | }; |
| 3079 | int val; |
| 3080 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3081 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3082 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3083 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3084 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3085 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3086 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3087 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3088 | }; |
| 3089 | int i; |
| 3090 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3091 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3092 | |
| 3093 | val &= 0xff00; |
| 3094 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3095 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3096 | } |
| 3097 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3098 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3099 | { 0x1f, 0x0002 }, |
| 3100 | { 0x05, 0x2642 }, |
| 3101 | { 0x1f, 0x0005 }, |
| 3102 | { 0x05, 0x8330 }, |
| 3103 | { 0x06, 0x2642 } |
| 3104 | }; |
| 3105 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3106 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3109 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3110 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3111 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3112 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3113 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3114 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3115 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3116 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3117 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3118 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3119 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3120 | |
| 3121 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3122 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3123 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3124 | } |
| 3125 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3126 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3127 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3128 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3129 | { 0x1f, 0x0002 }, |
| 3130 | { 0x10, 0x0008 }, |
| 3131 | { 0x0d, 0x006c }, |
| 3132 | |
| 3133 | { 0x1f, 0x0000 }, |
| 3134 | { 0x0d, 0xf880 }, |
| 3135 | |
| 3136 | { 0x1f, 0x0001 }, |
| 3137 | { 0x17, 0x0cc0 }, |
| 3138 | |
| 3139 | { 0x1f, 0x0001 }, |
| 3140 | { 0x0b, 0xa4d8 }, |
| 3141 | { 0x09, 0x281c }, |
| 3142 | { 0x07, 0x2883 }, |
| 3143 | { 0x0a, 0x6b35 }, |
| 3144 | { 0x1d, 0x3da4 }, |
| 3145 | { 0x1c, 0xeffd }, |
| 3146 | { 0x14, 0x7f52 }, |
| 3147 | { 0x18, 0x7fc6 }, |
| 3148 | { 0x08, 0x0601 }, |
| 3149 | { 0x06, 0x4063 }, |
| 3150 | { 0x10, 0xf074 }, |
| 3151 | { 0x1f, 0x0003 }, |
| 3152 | { 0x13, 0x0789 }, |
| 3153 | { 0x12, 0xf4bd }, |
| 3154 | { 0x1a, 0x04fd }, |
| 3155 | { 0x14, 0x84b0 }, |
| 3156 | { 0x1f, 0x0000 }, |
| 3157 | { 0x00, 0x9200 }, |
| 3158 | |
| 3159 | { 0x1f, 0x0005 }, |
| 3160 | { 0x01, 0x0340 }, |
| 3161 | { 0x1f, 0x0001 }, |
| 3162 | { 0x04, 0x4000 }, |
| 3163 | { 0x03, 0x1d21 }, |
| 3164 | { 0x02, 0x0c32 }, |
| 3165 | { 0x01, 0x0200 }, |
| 3166 | { 0x00, 0x5554 }, |
| 3167 | { 0x04, 0x4800 }, |
| 3168 | { 0x04, 0x4000 }, |
| 3169 | { 0x04, 0xf000 }, |
| 3170 | { 0x03, 0xdf01 }, |
| 3171 | { 0x02, 0xdf20 }, |
| 3172 | { 0x01, 0x101a }, |
| 3173 | { 0x00, 0xa0ff }, |
| 3174 | { 0x04, 0xf800 }, |
| 3175 | { 0x04, 0xf000 }, |
| 3176 | { 0x1f, 0x0000 }, |
| 3177 | |
| 3178 | { 0x1f, 0x0007 }, |
| 3179 | { 0x1e, 0x0023 }, |
| 3180 | { 0x16, 0x0000 }, |
| 3181 | { 0x1f, 0x0000 } |
| 3182 | }; |
| 3183 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3184 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3185 | } |
| 3186 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3187 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3188 | { |
| 3189 | static const struct phy_reg phy_reg_init[] = { |
| 3190 | { 0x1f, 0x0001 }, |
| 3191 | { 0x17, 0x0cc0 }, |
| 3192 | |
| 3193 | { 0x1f, 0x0007 }, |
| 3194 | { 0x1e, 0x002d }, |
| 3195 | { 0x18, 0x0040 }, |
| 3196 | { 0x1f, 0x0000 } |
| 3197 | }; |
| 3198 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3199 | rtl_writephy_batch(tp, phy_reg_init); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3200 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3201 | } |
| 3202 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3203 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3204 | { |
| 3205 | static const struct phy_reg phy_reg_init[] = { |
| 3206 | /* Enable Delay cap */ |
| 3207 | { 0x1f, 0x0005 }, |
| 3208 | { 0x05, 0x8b80 }, |
| 3209 | { 0x06, 0xc896 }, |
| 3210 | { 0x1f, 0x0000 }, |
| 3211 | |
| 3212 | /* Channel estimation fine tune */ |
| 3213 | { 0x1f, 0x0001 }, |
| 3214 | { 0x0b, 0x6c20 }, |
| 3215 | { 0x07, 0x2872 }, |
| 3216 | { 0x1c, 0xefff }, |
| 3217 | { 0x1f, 0x0003 }, |
| 3218 | { 0x14, 0x6420 }, |
| 3219 | { 0x1f, 0x0000 }, |
| 3220 | |
| 3221 | /* Update PFM & 10M TX idle timer */ |
| 3222 | { 0x1f, 0x0007 }, |
| 3223 | { 0x1e, 0x002f }, |
| 3224 | { 0x15, 0x1919 }, |
| 3225 | { 0x1f, 0x0000 }, |
| 3226 | |
| 3227 | { 0x1f, 0x0007 }, |
| 3228 | { 0x1e, 0x00ac }, |
| 3229 | { 0x18, 0x0006 }, |
| 3230 | { 0x1f, 0x0000 } |
| 3231 | }; |
| 3232 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3233 | rtl_apply_firmware(tp); |
| 3234 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3235 | rtl_writephy_batch(tp, phy_reg_init); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3236 | |
| 3237 | /* DCO enable for 10M IDLE Power */ |
| 3238 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3239 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3240 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3241 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3242 | |
| 3243 | /* For impedance matching */ |
| 3244 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3245 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3246 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3247 | |
| 3248 | /* PHY auto speed down */ |
| 3249 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3250 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3251 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3252 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3253 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3254 | |
| 3255 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3256 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3257 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3258 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3259 | |
| 3260 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3261 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3262 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3263 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3264 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3265 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3266 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3267 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3268 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3269 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3270 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3271 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3272 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3273 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3274 | } |
| 3275 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3276 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3277 | { |
| 3278 | const u16 w[] = { |
| 3279 | addr[0] | (addr[1] << 8), |
| 3280 | addr[2] | (addr[3] << 8), |
| 3281 | addr[4] | (addr[5] << 8) |
| 3282 | }; |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3283 | |
Heiner Kallweit | 3aa4c49 | 2019-05-02 20:46:52 +0200 | [diff] [blame] | 3284 | rtl_eri_write(tp, 0xe0, ERIAR_MASK_1111, w[0] | (w[1] << 16)); |
| 3285 | rtl_eri_write(tp, 0xe4, ERIAR_MASK_1111, w[2]); |
| 3286 | rtl_eri_write(tp, 0xf0, ERIAR_MASK_1111, w[0] << 16); |
| 3287 | 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] | 3288 | } |
| 3289 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3290 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3291 | { |
| 3292 | static const struct phy_reg phy_reg_init[] = { |
| 3293 | /* Enable Delay cap */ |
| 3294 | { 0x1f, 0x0004 }, |
| 3295 | { 0x1f, 0x0007 }, |
| 3296 | { 0x1e, 0x00ac }, |
| 3297 | { 0x18, 0x0006 }, |
| 3298 | { 0x1f, 0x0002 }, |
| 3299 | { 0x1f, 0x0000 }, |
| 3300 | { 0x1f, 0x0000 }, |
| 3301 | |
| 3302 | /* Channel estimation fine tune */ |
| 3303 | { 0x1f, 0x0003 }, |
| 3304 | { 0x09, 0xa20f }, |
| 3305 | { 0x1f, 0x0000 }, |
| 3306 | { 0x1f, 0x0000 }, |
| 3307 | |
| 3308 | /* Green Setting */ |
| 3309 | { 0x1f, 0x0005 }, |
| 3310 | { 0x05, 0x8b5b }, |
| 3311 | { 0x06, 0x9222 }, |
| 3312 | { 0x05, 0x8b6d }, |
| 3313 | { 0x06, 0x8000 }, |
| 3314 | { 0x05, 0x8b76 }, |
| 3315 | { 0x06, 0x8000 }, |
| 3316 | { 0x1f, 0x0000 } |
| 3317 | }; |
| 3318 | |
| 3319 | rtl_apply_firmware(tp); |
| 3320 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3321 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3322 | |
| 3323 | /* For 4-corner performance improve */ |
| 3324 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3325 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3326 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3327 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3328 | |
| 3329 | /* PHY auto speed down */ |
| 3330 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3331 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3332 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3333 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3334 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3335 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3336 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3337 | |
| 3338 | /* improve 10M EEE waveform */ |
| 3339 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3340 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3341 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3342 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3343 | |
| 3344 | /* Improve 2-pair detection performance */ |
| 3345 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3346 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3347 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3348 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3349 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 3350 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 3351 | rtl_enable_eee(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3352 | |
| 3353 | /* Green feature */ |
| 3354 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3355 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3356 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3357 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3358 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3359 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3360 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3361 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3362 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3363 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3364 | } |
| 3365 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3366 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3367 | { |
| 3368 | /* For 4-corner performance improve */ |
| 3369 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3370 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3371 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3372 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3373 | |
| 3374 | /* PHY auto speed down */ |
| 3375 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3376 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3377 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3378 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3379 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3380 | |
| 3381 | /* Improve 10M EEE waveform */ |
| 3382 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3383 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3384 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3385 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 3386 | |
| 3387 | rtl8168f_config_eee_phy(tp); |
Heiner Kallweit | 1563daa | 2019-01-26 10:36:35 +0100 | [diff] [blame] | 3388 | rtl_enable_eee(tp); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3389 | } |
| 3390 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3391 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3392 | { |
| 3393 | static const struct phy_reg phy_reg_init[] = { |
| 3394 | /* Channel estimation fine tune */ |
| 3395 | { 0x1f, 0x0003 }, |
| 3396 | { 0x09, 0xa20f }, |
| 3397 | { 0x1f, 0x0000 }, |
| 3398 | |
| 3399 | /* Modify green table for giga & fnet */ |
| 3400 | { 0x1f, 0x0005 }, |
| 3401 | { 0x05, 0x8b55 }, |
| 3402 | { 0x06, 0x0000 }, |
| 3403 | { 0x05, 0x8b5e }, |
| 3404 | { 0x06, 0x0000 }, |
| 3405 | { 0x05, 0x8b67 }, |
| 3406 | { 0x06, 0x0000 }, |
| 3407 | { 0x05, 0x8b70 }, |
| 3408 | { 0x06, 0x0000 }, |
| 3409 | { 0x1f, 0x0000 }, |
| 3410 | { 0x1f, 0x0007 }, |
| 3411 | { 0x1e, 0x0078 }, |
| 3412 | { 0x17, 0x0000 }, |
| 3413 | { 0x19, 0x00fb }, |
| 3414 | { 0x1f, 0x0000 }, |
| 3415 | |
| 3416 | /* Modify green table for 10M */ |
| 3417 | { 0x1f, 0x0005 }, |
| 3418 | { 0x05, 0x8b79 }, |
| 3419 | { 0x06, 0xaa00 }, |
| 3420 | { 0x1f, 0x0000 }, |
| 3421 | |
| 3422 | /* Disable hiimpedance detection (RTCT) */ |
| 3423 | { 0x1f, 0x0003 }, |
| 3424 | { 0x01, 0x328a }, |
| 3425 | { 0x1f, 0x0000 } |
| 3426 | }; |
| 3427 | |
| 3428 | rtl_apply_firmware(tp); |
| 3429 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3430 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3431 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3432 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3433 | |
| 3434 | /* Improve 2-pair detection performance */ |
| 3435 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3436 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3437 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3438 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3439 | } |
| 3440 | |
| 3441 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3442 | { |
| 3443 | rtl_apply_firmware(tp); |
| 3444 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3445 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3446 | } |
| 3447 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3448 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3449 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3450 | static const struct phy_reg phy_reg_init[] = { |
| 3451 | /* Channel estimation fine tune */ |
| 3452 | { 0x1f, 0x0003 }, |
| 3453 | { 0x09, 0xa20f }, |
| 3454 | { 0x1f, 0x0000 }, |
| 3455 | |
| 3456 | /* Modify green table for giga & fnet */ |
| 3457 | { 0x1f, 0x0005 }, |
| 3458 | { 0x05, 0x8b55 }, |
| 3459 | { 0x06, 0x0000 }, |
| 3460 | { 0x05, 0x8b5e }, |
| 3461 | { 0x06, 0x0000 }, |
| 3462 | { 0x05, 0x8b67 }, |
| 3463 | { 0x06, 0x0000 }, |
| 3464 | { 0x05, 0x8b70 }, |
| 3465 | { 0x06, 0x0000 }, |
| 3466 | { 0x1f, 0x0000 }, |
| 3467 | { 0x1f, 0x0007 }, |
| 3468 | { 0x1e, 0x0078 }, |
| 3469 | { 0x17, 0x0000 }, |
| 3470 | { 0x19, 0x00aa }, |
| 3471 | { 0x1f, 0x0000 }, |
| 3472 | |
| 3473 | /* Modify green table for 10M */ |
| 3474 | { 0x1f, 0x0005 }, |
| 3475 | { 0x05, 0x8b79 }, |
| 3476 | { 0x06, 0xaa00 }, |
| 3477 | { 0x1f, 0x0000 }, |
| 3478 | |
| 3479 | /* Disable hiimpedance detection (RTCT) */ |
| 3480 | { 0x1f, 0x0003 }, |
| 3481 | { 0x01, 0x328a }, |
| 3482 | { 0x1f, 0x0000 } |
| 3483 | }; |
| 3484 | |
| 3485 | |
| 3486 | rtl_apply_firmware(tp); |
| 3487 | |
| 3488 | rtl8168f_hw_phy_config(tp); |
| 3489 | |
| 3490 | /* Improve 2-pair detection performance */ |
| 3491 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3492 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3493 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3494 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3495 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3496 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3497 | |
| 3498 | /* Modify green table for giga */ |
| 3499 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3500 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3501 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3502 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3503 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3504 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3505 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3506 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3507 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3508 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3509 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3510 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3511 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3512 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3513 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3514 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3515 | |
| 3516 | /* uc same-seed solution */ |
| 3517 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3518 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3519 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3520 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3521 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3522 | /* Green feature */ |
| 3523 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3524 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3525 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3526 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3527 | } |
| 3528 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3529 | static void rtl8168g_disable_aldps(struct rtl8169_private *tp) |
| 3530 | { |
| 3531 | phy_write(tp->phydev, 0x1f, 0x0a43); |
| 3532 | phy_clear_bits(tp->phydev, 0x10, BIT(2)); |
| 3533 | } |
| 3534 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3535 | static void rtl8168g_phy_adjust_10m_aldps(struct rtl8169_private *tp) |
| 3536 | { |
| 3537 | struct phy_device *phydev = tp->phydev; |
| 3538 | |
| 3539 | phy_write(phydev, 0x1f, 0x0bcc); |
| 3540 | phy_clear_bits(phydev, 0x14, BIT(8)); |
| 3541 | |
| 3542 | phy_write(phydev, 0x1f, 0x0a44); |
| 3543 | phy_set_bits(phydev, 0x11, BIT(7) | BIT(6)); |
| 3544 | |
| 3545 | phy_write(phydev, 0x1f, 0x0a43); |
| 3546 | phy_write(phydev, 0x13, 0x8084); |
| 3547 | phy_clear_bits(phydev, 0x14, BIT(14) | BIT(13)); |
| 3548 | phy_set_bits(phydev, 0x10, BIT(12) | BIT(1) | BIT(0)); |
| 3549 | |
| 3550 | phy_write(phydev, 0x1f, 0x0000); |
| 3551 | } |
| 3552 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3553 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3554 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3555 | rtl_apply_firmware(tp); |
| 3556 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3557 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3558 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3559 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3560 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3561 | } else { |
| 3562 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3563 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3564 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3565 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3566 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3567 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3568 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3569 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3570 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3571 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3572 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3573 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3574 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3575 | /* Enable PHY auto speed down */ |
| 3576 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3577 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3578 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3579 | rtl8168g_phy_adjust_10m_aldps(tp); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3580 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3581 | /* EEE auto-fallback function */ |
| 3582 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3583 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3584 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3585 | /* Enable UC LPF tune function */ |
| 3586 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3587 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3588 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3589 | |
| 3590 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3591 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3592 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3593 | /* Improve SWR Efficiency */ |
| 3594 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3595 | rtl_writephy(tp, 0x14, 0x5065); |
| 3596 | rtl_writephy(tp, 0x14, 0xd065); |
| 3597 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3598 | rtl_writephy(tp, 0x11, 0x5655); |
| 3599 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3600 | rtl_writephy(tp, 0x14, 0x1065); |
| 3601 | rtl_writephy(tp, 0x14, 0x9065); |
| 3602 | rtl_writephy(tp, 0x14, 0x1065); |
| 3603 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3604 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3605 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3606 | rtl_enable_eee(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3607 | } |
| 3608 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3609 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3610 | { |
| 3611 | rtl_apply_firmware(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3612 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3613 | rtl_enable_eee(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3614 | } |
| 3615 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3616 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3617 | { |
| 3618 | u16 dout_tapbin; |
| 3619 | u32 data; |
| 3620 | |
| 3621 | rtl_apply_firmware(tp); |
| 3622 | |
| 3623 | /* CHN EST parameters adjust - giga master */ |
| 3624 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3625 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3626 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3627 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3628 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3629 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3630 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3631 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3632 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3633 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3634 | |
| 3635 | /* CHN EST parameters adjust - giga slave */ |
| 3636 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3637 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3638 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3639 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3640 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3641 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3642 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3643 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3644 | |
| 3645 | /* CHN EST parameters adjust - fnet */ |
| 3646 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3647 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3648 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3649 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3650 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3651 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3652 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3653 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3654 | |
| 3655 | /* enable R-tune & PGA-retune function */ |
| 3656 | dout_tapbin = 0; |
| 3657 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3658 | data = rtl_readphy(tp, 0x13); |
| 3659 | data &= 3; |
| 3660 | data <<= 2; |
| 3661 | dout_tapbin |= data; |
| 3662 | data = rtl_readphy(tp, 0x12); |
| 3663 | data &= 0xc000; |
| 3664 | data >>= 14; |
| 3665 | dout_tapbin |= data; |
| 3666 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3667 | dout_tapbin <<= 12; |
| 3668 | dout_tapbin &= 0xf000; |
| 3669 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3670 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3671 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3672 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3673 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3674 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3675 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3676 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3677 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3678 | |
| 3679 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3680 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3681 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3682 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3683 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3684 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3685 | |
| 3686 | /* enable GPHY 10M */ |
| 3687 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3688 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3689 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3690 | |
| 3691 | /* SAR ADC performance */ |
| 3692 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3693 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3694 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3695 | |
| 3696 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3697 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3698 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3699 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3700 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3701 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3702 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3703 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3704 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3705 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3706 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3707 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3708 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3709 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3710 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3711 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3712 | |
| 3713 | /* disable phy pfm mode */ |
| 3714 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3715 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3716 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3717 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3718 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3719 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3720 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3724 | { |
| 3725 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3726 | u16 rlen; |
| 3727 | u32 data; |
| 3728 | |
| 3729 | rtl_apply_firmware(tp); |
| 3730 | |
| 3731 | /* CHIN EST parameter update */ |
| 3732 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3733 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3734 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3735 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3736 | |
| 3737 | /* enable R-tune & PGA-retune function */ |
| 3738 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3739 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3740 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3741 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3742 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3743 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3744 | |
| 3745 | /* enable GPHY 10M */ |
| 3746 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3747 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3748 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3749 | |
| 3750 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3751 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3752 | ioffset_p3 = ((data & 0x80)>>7); |
| 3753 | ioffset_p3 <<= 3; |
| 3754 | |
| 3755 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3756 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3757 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3758 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3759 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3760 | ioffset_p0 <<= 3; |
| 3761 | ioffset_p0 |= (data & (0x07)); |
| 3762 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3763 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3764 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3765 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3766 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3767 | rtl_writephy(tp, 0x16, data); |
| 3768 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3769 | } |
| 3770 | |
| 3771 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3772 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3773 | data = rtl_readphy(tp, 0x16); |
| 3774 | data &= 0x000f; |
| 3775 | rlen = 0; |
| 3776 | if (data > 3) |
| 3777 | rlen = data - 3; |
| 3778 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3779 | rtl_writephy(tp, 0x17, data); |
| 3780 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3781 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3782 | |
| 3783 | /* disable phy pfm mode */ |
| 3784 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3785 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3786 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3787 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3788 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3789 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3790 | rtl_enable_eee(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3791 | } |
| 3792 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3793 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3794 | { |
| 3795 | /* Enable PHY auto speed down */ |
| 3796 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3797 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 3798 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3799 | |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3800 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3801 | |
| 3802 | /* Enable EEE auto-fallback function */ |
| 3803 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 3804 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 3805 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3806 | |
| 3807 | /* Enable UC LPF tune function */ |
| 3808 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3809 | rtl_writephy(tp, 0x13, 0x8012); |
| 3810 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3811 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3812 | |
| 3813 | /* set rg_sel_sdm_rate */ |
| 3814 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3815 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3816 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3817 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3818 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3819 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3820 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3824 | { |
Heiner Kallweit | a1ead2e | 2019-01-23 20:47:30 +0100 | [diff] [blame] | 3825 | rtl8168g_phy_adjust_10m_aldps(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3826 | |
| 3827 | /* Enable UC LPF tune function */ |
| 3828 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3829 | rtl_writephy(tp, 0x13, 0x8012); |
| 3830 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3831 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3832 | |
| 3833 | /* Set rg_sel_sdm_rate */ |
| 3834 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3835 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3836 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3837 | |
| 3838 | /* Channel estimation parameters */ |
| 3839 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3840 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3841 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3842 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3843 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3844 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3845 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3846 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3847 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3848 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3849 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3850 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3851 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3852 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3853 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3854 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3855 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3856 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3857 | rtl_writephy(tp, 0x13, 0x8110); |
| 3858 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3859 | rtl_writephy(tp, 0x13, 0x810f); |
| 3860 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3861 | rtl_writephy(tp, 0x13, 0x8111); |
| 3862 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3863 | rtl_writephy(tp, 0x13, 0x8113); |
| 3864 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3865 | rtl_writephy(tp, 0x13, 0x8115); |
| 3866 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3867 | rtl_writephy(tp, 0x13, 0x810e); |
| 3868 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3869 | rtl_writephy(tp, 0x13, 0x810c); |
| 3870 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3871 | rtl_writephy(tp, 0x13, 0x810b); |
| 3872 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3873 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3874 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3875 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3876 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3877 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3878 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3879 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3880 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3881 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3882 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3883 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3884 | |
| 3885 | /* Force PWM-mode */ |
| 3886 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3887 | rtl_writephy(tp, 0x14, 0x5065); |
| 3888 | rtl_writephy(tp, 0x14, 0xd065); |
| 3889 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3890 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3891 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3892 | rtl_writephy(tp, 0x14, 0x1065); |
| 3893 | rtl_writephy(tp, 0x14, 0x9065); |
| 3894 | rtl_writephy(tp, 0x14, 0x1065); |
| 3895 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3896 | |
Heiner Kallweit | c46863a | 2019-01-23 20:39:09 +0100 | [diff] [blame] | 3897 | rtl8168g_disable_aldps(tp); |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 3898 | rtl8168g_config_eee_phy(tp); |
Heiner Kallweit | b6c7fa4 | 2019-01-25 20:39:42 +0100 | [diff] [blame] | 3899 | rtl_enable_eee(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3900 | } |
| 3901 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3902 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3903 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3904 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3905 | { 0x1f, 0x0003 }, |
| 3906 | { 0x08, 0x441d }, |
| 3907 | { 0x01, 0x9100 }, |
| 3908 | { 0x1f, 0x0000 } |
| 3909 | }; |
| 3910 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3911 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3912 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3913 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3914 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3915 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3916 | rtl_writephy_batch(tp, phy_reg_init); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3917 | } |
| 3918 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3919 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3920 | { |
| 3921 | static const struct phy_reg phy_reg_init[] = { |
| 3922 | { 0x1f, 0x0005 }, |
| 3923 | { 0x1a, 0x0000 }, |
| 3924 | { 0x1f, 0x0000 }, |
| 3925 | |
| 3926 | { 0x1f, 0x0004 }, |
| 3927 | { 0x1c, 0x0000 }, |
| 3928 | { 0x1f, 0x0000 }, |
| 3929 | |
| 3930 | { 0x1f, 0x0001 }, |
| 3931 | { 0x15, 0x7701 }, |
| 3932 | { 0x1f, 0x0000 } |
| 3933 | }; |
| 3934 | |
| 3935 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3936 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3937 | rtl_writephy(tp, 0x18, 0x0310); |
| 3938 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3939 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3940 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3941 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3942 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3943 | } |
| 3944 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3945 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3946 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3947 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3948 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3949 | rtl_writephy(tp, 0x18, 0x0310); |
| 3950 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3951 | |
| 3952 | rtl_apply_firmware(tp); |
| 3953 | |
| 3954 | /* EEE setting */ |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3955 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3956 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3957 | rtl_writephy(tp, 0x10, 0x401f); |
| 3958 | rtl_writephy(tp, 0x19, 0x7030); |
| 3959 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3960 | } |
| 3961 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3962 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3963 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3964 | static const struct phy_reg phy_reg_init[] = { |
| 3965 | { 0x1f, 0x0004 }, |
| 3966 | { 0x10, 0xc07f }, |
| 3967 | { 0x19, 0x7030 }, |
| 3968 | { 0x1f, 0x0000 } |
| 3969 | }; |
| 3970 | |
| 3971 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3972 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3973 | rtl_writephy(tp, 0x18, 0x0310); |
| 3974 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3975 | |
| 3976 | rtl_apply_firmware(tp); |
| 3977 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3978 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 3979 | rtl_writephy_batch(tp, phy_reg_init); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3980 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 3981 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3982 | } |
| 3983 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3984 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3985 | { |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 3986 | static const rtl_generic_fct phy_configs[] = { |
| 3987 | /* PCI devices. */ |
| 3988 | [RTL_GIGA_MAC_VER_01] = NULL, |
| 3989 | [RTL_GIGA_MAC_VER_02] = rtl8169s_hw_phy_config, |
| 3990 | [RTL_GIGA_MAC_VER_03] = rtl8169s_hw_phy_config, |
| 3991 | [RTL_GIGA_MAC_VER_04] = rtl8169sb_hw_phy_config, |
| 3992 | [RTL_GIGA_MAC_VER_05] = rtl8169scd_hw_phy_config, |
| 3993 | [RTL_GIGA_MAC_VER_06] = rtl8169sce_hw_phy_config, |
| 3994 | /* PCI-E devices. */ |
| 3995 | [RTL_GIGA_MAC_VER_07] = rtl8102e_hw_phy_config, |
| 3996 | [RTL_GIGA_MAC_VER_08] = rtl8102e_hw_phy_config, |
| 3997 | [RTL_GIGA_MAC_VER_09] = rtl8102e_hw_phy_config, |
| 3998 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 3999 | [RTL_GIGA_MAC_VER_11] = rtl8168bb_hw_phy_config, |
| 4000 | [RTL_GIGA_MAC_VER_12] = rtl8168bef_hw_phy_config, |
| 4001 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 4002 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 4003 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 4004 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 4005 | [RTL_GIGA_MAC_VER_17] = rtl8168bef_hw_phy_config, |
| 4006 | [RTL_GIGA_MAC_VER_18] = rtl8168cp_1_hw_phy_config, |
| 4007 | [RTL_GIGA_MAC_VER_19] = rtl8168c_1_hw_phy_config, |
| 4008 | [RTL_GIGA_MAC_VER_20] = rtl8168c_2_hw_phy_config, |
| 4009 | [RTL_GIGA_MAC_VER_21] = rtl8168c_3_hw_phy_config, |
| 4010 | [RTL_GIGA_MAC_VER_22] = rtl8168c_4_hw_phy_config, |
| 4011 | [RTL_GIGA_MAC_VER_23] = rtl8168cp_2_hw_phy_config, |
| 4012 | [RTL_GIGA_MAC_VER_24] = rtl8168cp_2_hw_phy_config, |
| 4013 | [RTL_GIGA_MAC_VER_25] = rtl8168d_1_hw_phy_config, |
| 4014 | [RTL_GIGA_MAC_VER_26] = rtl8168d_2_hw_phy_config, |
| 4015 | [RTL_GIGA_MAC_VER_27] = rtl8168d_3_hw_phy_config, |
| 4016 | [RTL_GIGA_MAC_VER_28] = rtl8168d_4_hw_phy_config, |
| 4017 | [RTL_GIGA_MAC_VER_29] = rtl8105e_hw_phy_config, |
| 4018 | [RTL_GIGA_MAC_VER_30] = rtl8105e_hw_phy_config, |
| 4019 | [RTL_GIGA_MAC_VER_31] = NULL, |
| 4020 | [RTL_GIGA_MAC_VER_32] = rtl8168e_1_hw_phy_config, |
| 4021 | [RTL_GIGA_MAC_VER_33] = rtl8168e_1_hw_phy_config, |
| 4022 | [RTL_GIGA_MAC_VER_34] = rtl8168e_2_hw_phy_config, |
| 4023 | [RTL_GIGA_MAC_VER_35] = rtl8168f_1_hw_phy_config, |
| 4024 | [RTL_GIGA_MAC_VER_36] = rtl8168f_2_hw_phy_config, |
| 4025 | [RTL_GIGA_MAC_VER_37] = rtl8402_hw_phy_config, |
| 4026 | [RTL_GIGA_MAC_VER_38] = rtl8411_hw_phy_config, |
| 4027 | [RTL_GIGA_MAC_VER_39] = rtl8106e_hw_phy_config, |
| 4028 | [RTL_GIGA_MAC_VER_40] = rtl8168g_1_hw_phy_config, |
| 4029 | [RTL_GIGA_MAC_VER_41] = NULL, |
| 4030 | [RTL_GIGA_MAC_VER_42] = rtl8168g_2_hw_phy_config, |
| 4031 | [RTL_GIGA_MAC_VER_43] = rtl8168g_2_hw_phy_config, |
| 4032 | [RTL_GIGA_MAC_VER_44] = rtl8168g_2_hw_phy_config, |
| 4033 | [RTL_GIGA_MAC_VER_45] = rtl8168h_1_hw_phy_config, |
| 4034 | [RTL_GIGA_MAC_VER_46] = rtl8168h_2_hw_phy_config, |
| 4035 | [RTL_GIGA_MAC_VER_47] = rtl8168h_1_hw_phy_config, |
| 4036 | [RTL_GIGA_MAC_VER_48] = rtl8168h_2_hw_phy_config, |
| 4037 | [RTL_GIGA_MAC_VER_49] = rtl8168ep_1_hw_phy_config, |
| 4038 | [RTL_GIGA_MAC_VER_50] = rtl8168ep_2_hw_phy_config, |
| 4039 | [RTL_GIGA_MAC_VER_51] = rtl8168ep_2_hw_phy_config, |
| 4040 | }; |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4041 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4042 | |
Heiner Kallweit | 1fcd165 | 2019-04-14 10:30:24 +0200 | [diff] [blame] | 4043 | if (phy_configs[tp->mac_version]) |
| 4044 | phy_configs[tp->mac_version](tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4045 | } |
| 4046 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4047 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4048 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4049 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4050 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4053 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4054 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4055 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4056 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4057 | } |
| 4058 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4059 | 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] | 4060 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4061 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4062 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4063 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 7a67e11 | 2018-09-19 22:00:24 +0200 | [diff] [blame] | 4064 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4065 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4066 | netif_dbg(tp, drv, dev, |
| 4067 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4068 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4069 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4070 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4071 | /* We may have called phy_speed_down before */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 4072 | phy_speed_up(tp->phydev); |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4073 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 4074 | genphy_soft_reset(tp->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4075 | } |
| 4076 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4077 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4078 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4079 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4080 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4081 | rtl_unlock_config_regs(tp); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4082 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4083 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4084 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4085 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4086 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4087 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4088 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4089 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4090 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4091 | |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4092 | rtl_lock_config_regs(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4093 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4094 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4098 | { |
| 4099 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4100 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4101 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4102 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4103 | ret = eth_mac_addr(dev, p); |
| 4104 | if (ret) |
| 4105 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4106 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4107 | pm_runtime_get_noresume(d); |
| 4108 | |
| 4109 | if (pm_runtime_active(d)) |
| 4110 | rtl_rar_set(tp, dev->dev_addr); |
| 4111 | |
| 4112 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4113 | |
| 4114 | return 0; |
| 4115 | } |
| 4116 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4117 | 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] | 4118 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 4119 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4120 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4121 | if (!netif_running(dev)) |
| 4122 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4123 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 4124 | return phy_mii_ioctl(tp->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4125 | } |
| 4126 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4127 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4128 | { |
| 4129 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4130 | |
| 4131 | switch (tp->mac_version) { |
| 4132 | case RTL_GIGA_MAC_VER_27: |
| 4133 | ops->write = r8168dp_1_mdio_write; |
| 4134 | ops->read = r8168dp_1_mdio_read; |
| 4135 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4136 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4137 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4138 | ops->write = r8168dp_2_mdio_write; |
| 4139 | ops->read = r8168dp_2_mdio_read; |
| 4140 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4141 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4142 | ops->write = r8168g_mdio_write; |
| 4143 | ops->read = r8168g_mdio_read; |
| 4144 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4145 | default: |
| 4146 | ops->write = r8169_mdio_write; |
| 4147 | ops->read = r8169_mdio_read; |
| 4148 | break; |
| 4149 | } |
| 4150 | } |
| 4151 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4152 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4153 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4154 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4155 | case RTL_GIGA_MAC_VER_25: |
| 4156 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4157 | case RTL_GIGA_MAC_VER_29: |
| 4158 | case RTL_GIGA_MAC_VER_30: |
| 4159 | case RTL_GIGA_MAC_VER_32: |
| 4160 | case RTL_GIGA_MAC_VER_33: |
| 4161 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4162 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4163 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4164 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4165 | break; |
| 4166 | default: |
| 4167 | break; |
| 4168 | } |
| 4169 | } |
| 4170 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4171 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4172 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4173 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4174 | return; |
| 4175 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4176 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4177 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4178 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4179 | |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 4180 | if (device_may_wakeup(tp_to_dev(tp))) { |
| 4181 | phy_speed_down(tp->phydev, false); |
| 4182 | rtl_wol_suspend_quirk(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4183 | return; |
Heiner Kallweit | 5ea25b1 | 2019-01-31 22:03:48 +0100 | [diff] [blame] | 4184 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4185 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4186 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4187 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4188 | case RTL_GIGA_MAC_VER_37: |
| 4189 | case RTL_GIGA_MAC_VER_39: |
| 4190 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4191 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4192 | case RTL_GIGA_MAC_VER_45: |
| 4193 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4194 | case RTL_GIGA_MAC_VER_47: |
| 4195 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4196 | case RTL_GIGA_MAC_VER_50: |
| 4197 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4198 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4199 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4200 | case RTL_GIGA_MAC_VER_40: |
| 4201 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4202 | case RTL_GIGA_MAC_VER_49: |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4203 | rtl_eri_clear_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4204 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4205 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4210 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4211 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4212 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4213 | case RTL_GIGA_MAC_VER_37: |
| 4214 | case RTL_GIGA_MAC_VER_39: |
| 4215 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4216 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4217 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4218 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4219 | case RTL_GIGA_MAC_VER_45: |
| 4220 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4221 | case RTL_GIGA_MAC_VER_47: |
| 4222 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4223 | case RTL_GIGA_MAC_VER_50: |
| 4224 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4225 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4226 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4227 | case RTL_GIGA_MAC_VER_40: |
| 4228 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4229 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4230 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 4231 | rtl_eri_set_bits(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4232 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 4235 | phy_resume(tp->phydev); |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 4236 | /* give MAC/PHY some time to resume */ |
| 4237 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4240 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4241 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4242 | switch (tp->mac_version) { |
| 4243 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4244 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4245 | break; |
| 4246 | default: |
| 4247 | r8168_pll_power_down(tp); |
| 4248 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4252 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4253 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4254 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4255 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4256 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4257 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4258 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4262 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4263 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4264 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4265 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4266 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4267 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4268 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4269 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
Maciej S. Szmigiero | 511cfd5 | 2018-10-11 16:02:10 +0200 | [diff] [blame] | 4270 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36: |
| 4271 | case RTL_GIGA_MAC_VER_38: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4272 | 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] | 4273 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4274 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4275 | 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] | 4276 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4277 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4278 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4279 | break; |
| 4280 | } |
| 4281 | } |
| 4282 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4283 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4284 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4285 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4288 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4289 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4290 | if (tp->jumbo_ops.enable) { |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4291 | rtl_unlock_config_regs(tp); |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4292 | tp->jumbo_ops.enable(tp); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4293 | rtl_lock_config_regs(tp); |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4294 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4298 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4299 | if (tp->jumbo_ops.disable) { |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4300 | rtl_unlock_config_regs(tp); |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4301 | tp->jumbo_ops.disable(tp); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4302 | rtl_lock_config_regs(tp); |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4303 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4307 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4308 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4309 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4310 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4311 | } |
| 4312 | |
| 4313 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4314 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4315 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4316 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4317 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4321 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4322 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4326 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4327 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4331 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4332 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4333 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4334 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4335 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4339 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4340 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4341 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4342 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4343 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4347 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4348 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4349 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4353 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4354 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4355 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4359 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4360 | r8168b_0_hw_jumbo_enable(tp); |
| 4361 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4362 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4366 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4367 | r8168b_0_hw_jumbo_disable(tp); |
| 4368 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4369 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4370 | } |
| 4371 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4372 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4373 | { |
| 4374 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4375 | |
| 4376 | switch (tp->mac_version) { |
| 4377 | case RTL_GIGA_MAC_VER_11: |
| 4378 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4379 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4380 | break; |
| 4381 | case RTL_GIGA_MAC_VER_12: |
| 4382 | case RTL_GIGA_MAC_VER_17: |
| 4383 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4384 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4385 | break; |
| 4386 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4387 | case RTL_GIGA_MAC_VER_19: |
| 4388 | case RTL_GIGA_MAC_VER_20: |
| 4389 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4390 | case RTL_GIGA_MAC_VER_22: |
| 4391 | case RTL_GIGA_MAC_VER_23: |
| 4392 | case RTL_GIGA_MAC_VER_24: |
| 4393 | case RTL_GIGA_MAC_VER_25: |
| 4394 | case RTL_GIGA_MAC_VER_26: |
| 4395 | ops->disable = r8168c_hw_jumbo_disable; |
| 4396 | ops->enable = r8168c_hw_jumbo_enable; |
| 4397 | break; |
| 4398 | case RTL_GIGA_MAC_VER_27: |
| 4399 | case RTL_GIGA_MAC_VER_28: |
| 4400 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4401 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4402 | break; |
| 4403 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4404 | case RTL_GIGA_MAC_VER_32: |
| 4405 | case RTL_GIGA_MAC_VER_33: |
| 4406 | case RTL_GIGA_MAC_VER_34: |
| 4407 | ops->disable = r8168e_hw_jumbo_disable; |
| 4408 | ops->enable = r8168e_hw_jumbo_enable; |
| 4409 | break; |
| 4410 | |
| 4411 | /* |
| 4412 | * No action needed for jumbo frames with 8169. |
| 4413 | * No jumbo for 810x at all. |
| 4414 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4415 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4416 | default: |
| 4417 | ops->disable = NULL; |
| 4418 | ops->enable = NULL; |
| 4419 | break; |
| 4420 | } |
| 4421 | } |
| 4422 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4423 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4424 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4425 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4426 | } |
| 4427 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4428 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4429 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4430 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4431 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4432 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4433 | } |
| 4434 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 4435 | static void rtl_request_firmware(struct rtl8169_private *tp) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4436 | { |
| 4437 | struct rtl_fw *rtl_fw; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4438 | int rc = -ENOMEM; |
| 4439 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 4440 | /* firmware loaded already or no firmware available */ |
| 4441 | if (tp->rtl_fw || !tp->fw_name) |
| 4442 | return; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4443 | |
| 4444 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4445 | if (!rtl_fw) |
| 4446 | goto err_warn; |
| 4447 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 4448 | rc = request_firmware(&rtl_fw->fw, tp->fw_name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4449 | if (rc < 0) |
| 4450 | goto err_free; |
| 4451 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4452 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4453 | if (rc < 0) |
| 4454 | goto err_release_firmware; |
| 4455 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4456 | tp->rtl_fw = rtl_fw; |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 4457 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4458 | return; |
| 4459 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4460 | err_release_firmware: |
| 4461 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4462 | err_free: |
| 4463 | kfree(rtl_fw); |
| 4464 | err_warn: |
| 4465 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 4466 | tp->fw_name, rc); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4469 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4470 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4471 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4472 | } |
| 4473 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4474 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4475 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4476 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4480 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4481 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4482 | } |
| 4483 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4484 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | { |
| 4486 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4487 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4489 | rtl_rx_close(tp); |
| 4490 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4491 | switch (tp->mac_version) { |
| 4492 | case RTL_GIGA_MAC_VER_27: |
| 4493 | case RTL_GIGA_MAC_VER_28: |
| 4494 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4495 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4496 | break; |
| 4497 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 4498 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4499 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4500 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4501 | break; |
| 4502 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4503 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4504 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4505 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4506 | } |
| 4507 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4508 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4511 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4512 | { |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4513 | u32 val = TX_DMA_BURST << TxDMAShift | |
| 4514 | InterFrameGap << TxInterFrameGapShift; |
| 4515 | |
| 4516 | if (tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
| 4517 | tp->mac_version != RTL_GIGA_MAC_VER_39) |
| 4518 | val |= TXCFG_AUTO_FIFO; |
| 4519 | |
| 4520 | RTL_W32(tp, TxConfig, val); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4523 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4525 | /* Low hurts. Let's disable the filtering. */ |
| 4526 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4527 | } |
| 4528 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4529 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4530 | { |
| 4531 | /* |
| 4532 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4533 | * register to be written before TxDescAddrLow to work. |
| 4534 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4535 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4536 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4537 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4538 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4539 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4540 | } |
| 4541 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4542 | 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] | 4543 | { |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4544 | u32 val; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4545 | |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4546 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4547 | val = 0x000fff00; |
| 4548 | else if (tp->mac_version == RTL_GIGA_MAC_VER_06) |
| 4549 | val = 0x00ffff00; |
| 4550 | else |
| 4551 | return; |
| 4552 | |
| 4553 | if (RTL_R8(tp, Config2) & PCI_Clock_66MHz) |
| 4554 | val |= 0xff; |
| 4555 | |
| 4556 | RTL_W32(tp, 0x7c, val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4559 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4560 | { |
| 4561 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4562 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4563 | int rx_mode; |
| 4564 | u32 tmp = 0; |
| 4565 | |
| 4566 | if (dev->flags & IFF_PROMISC) { |
| 4567 | /* Unconditionally log net taps. */ |
| 4568 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4569 | rx_mode = |
| 4570 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4571 | AcceptAllPhys; |
| 4572 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4573 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4574 | (dev->flags & IFF_ALLMULTI)) { |
| 4575 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4576 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4577 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4578 | } else { |
| 4579 | struct netdev_hw_addr *ha; |
| 4580 | |
| 4581 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4582 | mc_filter[1] = mc_filter[0] = 0; |
| 4583 | netdev_for_each_mc_addr(ha, dev) { |
| 4584 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4585 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4586 | rx_mode |= AcceptMulticast; |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | if (dev->features & NETIF_F_RXALL) |
| 4591 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4592 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4593 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4594 | |
| 4595 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4596 | u32 data = mc_filter[0]; |
| 4597 | |
| 4598 | mc_filter[0] = swab32(mc_filter[1]); |
| 4599 | mc_filter[1] = swab32(data); |
| 4600 | } |
| 4601 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 4602 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 4603 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4604 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4605 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4606 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4607 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4608 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4609 | } |
| 4610 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4611 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 4612 | { |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4613 | rtl_unlock_config_regs(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4614 | |
| 4615 | tp->hw_start(tp); |
| 4616 | |
| 4617 | rtl_set_rx_max_size(tp); |
| 4618 | rtl_set_rx_tx_desc_registers(tp); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 4619 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4620 | |
Heiner Kallweit | eb94dc9 | 2019-03-31 15:43:59 +0200 | [diff] [blame] | 4621 | /* disable interrupt coalescing */ |
| 4622 | RTL_W16(tp, IntrMitigate, 0x0000); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4623 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4624 | RTL_R8(tp, IntrMask); |
| 4625 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4626 | rtl_init_rxcfg(tp); |
Maciej S. Szmigiero | f74dd48 | 2018-09-07 20:15:22 +0200 | [diff] [blame] | 4627 | rtl_set_tx_config_registers(tp); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4628 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4629 | rtl_set_rx_mode(tp->dev); |
| 4630 | /* no early-rx interrupts */ |
| 4631 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 4632 | rtl_irq_enable(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4633 | } |
| 4634 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4635 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4636 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4637 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4638 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4639 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4640 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4642 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4643 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4644 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4645 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4646 | netif_dbg(tp, drv, tp->dev, |
| 4647 | "Set MAC Reg C+CR Offset 0xe0. Bit 3 and Bit 14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4648 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4651 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4652 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4653 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4654 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4655 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4658 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4659 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4660 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4661 | } |
| 4662 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4663 | 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] | 4664 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4665 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4666 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4667 | RTL_W32(tp, CSIDR, value); |
| 4668 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4669 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4670 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4671 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4672 | } |
| 4673 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4674 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4675 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4676 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4677 | |
| 4678 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4679 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4680 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4681 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4682 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4683 | } |
| 4684 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4685 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4686 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4687 | struct pci_dev *pdev = tp->pci_dev; |
| 4688 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4689 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4690 | /* According to Realtek the value at config space address 0x070f |
| 4691 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4692 | * first and if it fails fall back to CSI. |
| 4693 | */ |
| 4694 | if (pdev->cfg_size > 0x070f && |
| 4695 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4696 | return; |
| 4697 | |
| 4698 | netdev_notice_once(tp->dev, |
| 4699 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4700 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4701 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4702 | } |
| 4703 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4704 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4705 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4706 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | struct ephy_info { |
| 4710 | unsigned int offset; |
| 4711 | u16 mask; |
| 4712 | u16 bits; |
| 4713 | }; |
| 4714 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4715 | static void __rtl_ephy_init(struct rtl8169_private *tp, |
| 4716 | const struct ephy_info *e, int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4717 | { |
| 4718 | u16 w; |
| 4719 | |
| 4720 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4721 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4722 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4723 | e++; |
| 4724 | } |
| 4725 | } |
| 4726 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4727 | #define rtl_ephy_init(tp, a) __rtl_ephy_init(tp, a, ARRAY_SIZE(a)) |
| 4728 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4729 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4730 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4731 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4732 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4733 | } |
| 4734 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4735 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4736 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4737 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4738 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4739 | } |
| 4740 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4741 | static void rtl_pcie_state_l2l3_disable(struct rtl8169_private *tp) |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4742 | { |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 4743 | /* work around an issue when PCI reset occurs during L2/L3 state */ |
| 4744 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Rdy_to_L23); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4745 | } |
| 4746 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4747 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4748 | { |
| 4749 | if (enable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4750 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4751 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4752 | } else { |
| 4753 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4754 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4755 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4756 | |
| 4757 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4758 | } |
| 4759 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 4760 | static void rtl_set_fifo_size(struct rtl8169_private *tp, u16 rx_stat, |
| 4761 | u16 tx_stat, u16 rx_dyn, u16 tx_dyn) |
| 4762 | { |
| 4763 | /* Usage of dynamic vs. static FIFO is controlled by bit |
| 4764 | * TXCFG_AUTO_FIFO. Exact meaning of FIFO values isn't known. |
| 4765 | */ |
| 4766 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, (rx_stat << 16) | rx_dyn); |
| 4767 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, (tx_stat << 16) | tx_dyn); |
| 4768 | } |
| 4769 | |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 4770 | static void rtl8168g_set_pause_thresholds(struct rtl8169_private *tp, |
| 4771 | u8 low, u8 high) |
| 4772 | { |
| 4773 | /* FIFO thresholds for pause flow control */ |
| 4774 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, low); |
| 4775 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, high); |
| 4776 | } |
| 4777 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4778 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4779 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4780 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4781 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4782 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4783 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4784 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4785 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4786 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4787 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4788 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4789 | } |
| 4790 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4791 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4792 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4793 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4794 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4795 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4796 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4797 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4798 | } |
| 4799 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4800 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4801 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4802 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4803 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4804 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4805 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4806 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4807 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4808 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4809 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4810 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4811 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4812 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4813 | } |
| 4814 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4815 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4816 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4817 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4818 | { 0x01, 0, 0x0001 }, |
| 4819 | { 0x02, 0x0800, 0x1000 }, |
| 4820 | { 0x03, 0, 0x0042 }, |
| 4821 | { 0x06, 0x0080, 0x0000 }, |
| 4822 | { 0x07, 0, 0x2000 } |
| 4823 | }; |
| 4824 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4825 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4826 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4827 | rtl_ephy_init(tp, e_info_8168cp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4828 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4829 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4830 | } |
| 4831 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4832 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4833 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4834 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4835 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4836 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4837 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4838 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4839 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4840 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4841 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4842 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4843 | } |
| 4844 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4845 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4846 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4847 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4848 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4849 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4850 | |
| 4851 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4852 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4853 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4854 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4855 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4856 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4857 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4858 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4859 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4860 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4861 | } |
| 4862 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4863 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4864 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4865 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4866 | { 0x02, 0x0800, 0x1000 }, |
| 4867 | { 0x03, 0, 0x0002 }, |
| 4868 | { 0x06, 0x0080, 0x0000 } |
| 4869 | }; |
| 4870 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4871 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4872 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4873 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4874 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4875 | rtl_ephy_init(tp, e_info_8168c_1); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4876 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4877 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4878 | } |
| 4879 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4880 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4881 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4882 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4883 | { 0x01, 0, 0x0001 }, |
| 4884 | { 0x03, 0x0400, 0x0220 } |
| 4885 | }; |
| 4886 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4887 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4888 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4889 | rtl_ephy_init(tp, e_info_8168c_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4890 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4891 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4892 | } |
| 4893 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4894 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4895 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4896 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4897 | } |
| 4898 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4899 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4900 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4901 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4902 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4903 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4904 | } |
| 4905 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4906 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4907 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4908 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4909 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4910 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4911 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4912 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4913 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4914 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4915 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4916 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4917 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4918 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4919 | } |
| 4920 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4921 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4922 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4923 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4924 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4925 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4926 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4927 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4928 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4929 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4930 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4933 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4934 | { |
| 4935 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4936 | { 0x0b, 0x0000, 0x0048 }, |
| 4937 | { 0x19, 0x0020, 0x0050 }, |
| 4938 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4939 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4940 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4941 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4942 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4943 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4944 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4945 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4946 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4947 | rtl_ephy_init(tp, e_info_8168d_4); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4948 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4949 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4950 | } |
| 4951 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4952 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4953 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4954 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4955 | { 0x00, 0x0200, 0x0100 }, |
| 4956 | { 0x00, 0x0000, 0x0004 }, |
| 4957 | { 0x06, 0x0002, 0x0001 }, |
| 4958 | { 0x06, 0x0000, 0x0030 }, |
| 4959 | { 0x07, 0x0000, 0x2000 }, |
| 4960 | { 0x00, 0x0000, 0x0020 }, |
| 4961 | { 0x03, 0x5800, 0x2000 }, |
| 4962 | { 0x03, 0x0000, 0x0001 }, |
| 4963 | { 0x01, 0x0800, 0x1000 }, |
| 4964 | { 0x07, 0x0000, 0x4000 }, |
| 4965 | { 0x1e, 0x0000, 0x2000 }, |
| 4966 | { 0x19, 0xffff, 0xfe6c }, |
| 4967 | { 0x0a, 0x0000, 0x0040 } |
| 4968 | }; |
| 4969 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4970 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4971 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4972 | rtl_ephy_init(tp, e_info_8168e_1); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4973 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4974 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4975 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4976 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4977 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4978 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4979 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4980 | |
| 4981 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4982 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4983 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4984 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4985 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4988 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4989 | { |
| 4990 | static const struct ephy_info e_info_8168e_2[] = { |
| 4991 | { 0x09, 0x0000, 0x0080 }, |
| 4992 | { 0x19, 0x0000, 0x0224 } |
| 4993 | }; |
| 4994 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4995 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4996 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 4997 | rtl_ephy_init(tp, e_info_8168e_2); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4998 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4999 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5000 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5001 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5002 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5003 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5004 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5005 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 5006 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5007 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5008 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5009 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5010 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5011 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5012 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5013 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5014 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5015 | |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 5016 | rtl8168_config_eee_mac(tp); |
| 5017 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5018 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5019 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5020 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 5021 | |
| 5022 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5023 | } |
| 5024 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5025 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5026 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5027 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5028 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5029 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5030 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5031 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5032 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5033 | rtl_set_fifo_size(tp, 0x10, 0x10, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 5034 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5035 | rtl_eri_set_bits(tp, 0x1b0, ERIAR_MASK_0001, BIT(4)); |
| 5036 | rtl_eri_set_bits(tp, 0x1d0, ERIAR_MASK_0001, BIT(4)); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5037 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050); |
| 5038 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5039 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5040 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5041 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5042 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5043 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5044 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5045 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5046 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5047 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | cc07d271 | 2019-01-26 10:35:30 +0100 | [diff] [blame] | 5048 | |
| 5049 | rtl8168_config_eee_mac(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5050 | } |
| 5051 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5052 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5053 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5054 | static const struct ephy_info e_info_8168f_1[] = { |
| 5055 | { 0x06, 0x00c0, 0x0020 }, |
| 5056 | { 0x08, 0x0001, 0x0002 }, |
| 5057 | { 0x09, 0x0000, 0x0080 }, |
| 5058 | { 0x19, 0x0000, 0x0224 } |
| 5059 | }; |
| 5060 | |
| 5061 | rtl_hw_start_8168f(tp); |
| 5062 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5063 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5064 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5065 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5066 | } |
| 5067 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5068 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5069 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5070 | static const struct ephy_info e_info_8168f_1[] = { |
| 5071 | { 0x06, 0x00c0, 0x0020 }, |
| 5072 | { 0x0f, 0xffff, 0x5200 }, |
| 5073 | { 0x1e, 0x0000, 0x4000 }, |
| 5074 | { 0x19, 0x0000, 0x0224 } |
| 5075 | }; |
| 5076 | |
| 5077 | rtl_hw_start_8168f(tp); |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5078 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5079 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5080 | rtl_ephy_init(tp, e_info_8168f_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5081 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5082 | rtl_eri_set_bits(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5083 | } |
| 5084 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5085 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5086 | { |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5087 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 5088 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5089 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5090 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5091 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5092 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5093 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 5094 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5095 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5096 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5097 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5098 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5099 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5100 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5101 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5102 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 5103 | rtl8168_config_eee_mac(tp); |
| 5104 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5105 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5106 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5107 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5108 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5109 | } |
| 5110 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5111 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5112 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5113 | static const struct ephy_info e_info_8168g_1[] = { |
| 5114 | { 0x00, 0x0000, 0x0008 }, |
| 5115 | { 0x0c, 0x37d0, 0x0820 }, |
| 5116 | { 0x1e, 0x0000, 0x0001 }, |
| 5117 | { 0x19, 0x8000, 0x0000 } |
| 5118 | }; |
| 5119 | |
| 5120 | rtl_hw_start_8168g(tp); |
| 5121 | |
| 5122 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5123 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5124 | rtl_ephy_init(tp, e_info_8168g_1); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5125 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5126 | } |
| 5127 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5128 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5129 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5130 | static const struct ephy_info e_info_8168g_2[] = { |
| 5131 | { 0x00, 0x0000, 0x0008 }, |
| 5132 | { 0x0c, 0x3df0, 0x0200 }, |
| 5133 | { 0x19, 0xffff, 0xfc00 }, |
| 5134 | { 0x1e, 0xffff, 0x20eb } |
| 5135 | }; |
| 5136 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5137 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5138 | |
| 5139 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5140 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5141 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5142 | rtl_ephy_init(tp, e_info_8168g_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5145 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5146 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5147 | static const struct ephy_info e_info_8411_2[] = { |
| 5148 | { 0x00, 0x0000, 0x0008 }, |
| 5149 | { 0x0c, 0x3df0, 0x0200 }, |
| 5150 | { 0x0f, 0xffff, 0x5200 }, |
| 5151 | { 0x19, 0x0020, 0x0000 }, |
| 5152 | { 0x1e, 0x0000, 0x2000 } |
| 5153 | }; |
| 5154 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5155 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5156 | |
| 5157 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5158 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5159 | rtl_ephy_init(tp, e_info_8411_2); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5160 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5161 | } |
| 5162 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5163 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5164 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5165 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5166 | u32 data; |
| 5167 | static const struct ephy_info e_info_8168h_1[] = { |
| 5168 | { 0x1e, 0x0800, 0x0001 }, |
| 5169 | { 0x1d, 0x0000, 0x0800 }, |
| 5170 | { 0x05, 0xffff, 0x2089 }, |
| 5171 | { 0x06, 0xffff, 0x5881 }, |
| 5172 | { 0x04, 0xffff, 0x154a }, |
| 5173 | { 0x01, 0xffff, 0x068b } |
| 5174 | }; |
| 5175 | |
| 5176 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5177 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5178 | rtl_ephy_init(tp, e_info_8168h_1); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5179 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5180 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 5181 | rtl8168g_set_pause_thresholds(tp, 0x38, 0x48); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5182 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5183 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5184 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5185 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5186 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 5187 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5188 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5189 | rtl_eri_set_bits(tp, 0xdc, ERIAR_MASK_1111, BIT(4)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5190 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5191 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5192 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5193 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5194 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5195 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5196 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5197 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5198 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5199 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5200 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 5201 | rtl8168_config_eee_mac(tp); |
| 5202 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5203 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5204 | 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] | 5205 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5206 | 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] | 5207 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5208 | rtl_eri_clear_bits(tp, 0x1b0, ERIAR_MASK_0011, BIT(12)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5209 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5210 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5211 | |
| 5212 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5213 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5214 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5215 | if (rg_saw_cnt > 0) { |
| 5216 | u16 sw_cnt_1ms_ini; |
| 5217 | |
| 5218 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5219 | sw_cnt_1ms_ini &= 0x0fff; |
| 5220 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5221 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5222 | data |= sw_cnt_1ms_ini; |
| 5223 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5224 | } |
| 5225 | |
| 5226 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5227 | data &= ~0xf0; |
| 5228 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5229 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5230 | |
| 5231 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5232 | data &= ~0x6000; |
| 5233 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5234 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5235 | |
| 5236 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5237 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5238 | data |= 0x017f; |
| 5239 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5240 | |
| 5241 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5242 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5243 | data |= 0x047f; |
| 5244 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5245 | |
| 5246 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5247 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5248 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5249 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5250 | |
| 5251 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5252 | } |
| 5253 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5254 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5255 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5256 | rtl8168ep_stop_cmac(tp); |
| 5257 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5258 | rtl_set_fifo_size(tp, 0x08, 0x10, 0x02, 0x06); |
Heiner Kallweit | 0ebacd1 | 2019-05-05 12:34:25 +0200 | [diff] [blame] | 5259 | rtl8168g_set_pause_thresholds(tp, 0x2f, 0x5f); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5260 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5261 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5262 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5263 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5264 | |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 5265 | rtl_reset_packet_filter(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5266 | |
Heiner Kallweit | e719b3e | 2019-04-28 11:11:47 +0200 | [diff] [blame] | 5267 | rtl_eri_set_bits(tp, 0xd4, ERIAR_MASK_1111, 0x1f80); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5268 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5269 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5270 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5271 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5272 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5273 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5274 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5275 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5276 | |
Heiner Kallweit | df6f185 | 2019-01-25 20:38:38 +0100 | [diff] [blame] | 5277 | rtl8168_config_eee_mac(tp); |
| 5278 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5279 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5280 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5281 | 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] | 5282 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5283 | rtl_pcie_state_l2l3_disable(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5287 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5288 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5289 | { 0x00, 0xffff, 0x10ab }, |
| 5290 | { 0x06, 0xffff, 0xf030 }, |
| 5291 | { 0x08, 0xffff, 0x2006 }, |
| 5292 | { 0x0d, 0xffff, 0x1666 }, |
| 5293 | { 0x0c, 0x3ff0, 0x0000 } |
| 5294 | }; |
| 5295 | |
| 5296 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5297 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5298 | rtl_ephy_init(tp, e_info_8168ep_1); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5299 | |
| 5300 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5301 | |
| 5302 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5306 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5307 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5308 | { 0x00, 0xffff, 0x10a3 }, |
| 5309 | { 0x19, 0xffff, 0xfc00 }, |
| 5310 | { 0x1e, 0xffff, 0x20ea } |
| 5311 | }; |
| 5312 | |
| 5313 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5314 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5315 | rtl_ephy_init(tp, e_info_8168ep_2); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5316 | |
| 5317 | rtl_hw_start_8168ep(tp); |
| 5318 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5319 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5320 | 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] | 5321 | |
| 5322 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5326 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5327 | u32 data; |
| 5328 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5329 | { 0x00, 0xffff, 0x10a3 }, |
| 5330 | { 0x19, 0xffff, 0x7c00 }, |
| 5331 | { 0x1e, 0xffff, 0x20eb }, |
| 5332 | { 0x0d, 0xffff, 0x1666 } |
| 5333 | }; |
| 5334 | |
| 5335 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5336 | rtl_hw_aspm_clkreq_enable(tp, false); |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5337 | rtl_ephy_init(tp, e_info_8168ep_3); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5338 | |
| 5339 | rtl_hw_start_8168ep(tp); |
| 5340 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5341 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5342 | 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] | 5343 | |
| 5344 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5345 | data &= 0xf000; |
| 5346 | data |= 0x0271; |
| 5347 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5348 | |
| 5349 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5350 | data &= 0xff00; |
| 5351 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5352 | |
| 5353 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5354 | data |= 0x0080; |
| 5355 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5356 | |
| 5357 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5358 | } |
| 5359 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5360 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5361 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5362 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5363 | { 0x01, 0, 0x6e65 }, |
| 5364 | { 0x02, 0, 0x091f }, |
| 5365 | { 0x03, 0, 0xc2f9 }, |
| 5366 | { 0x06, 0, 0xafb5 }, |
| 5367 | { 0x07, 0, 0x0e00 }, |
| 5368 | { 0x19, 0, 0xec80 }, |
| 5369 | { 0x01, 0, 0x2e65 }, |
| 5370 | { 0x01, 0, 0x6e65 } |
| 5371 | }; |
| 5372 | u8 cfg1; |
| 5373 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5374 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5375 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5376 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5377 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5378 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5379 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5380 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5381 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5382 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5383 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5384 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5385 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5386 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5387 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5388 | rtl_ephy_init(tp, e_info_8102e_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5389 | } |
| 5390 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5391 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5392 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5393 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5394 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5395 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5396 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5397 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5398 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5399 | } |
| 5400 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5401 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5402 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5403 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5404 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5405 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5406 | } |
| 5407 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5408 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5409 | { |
| 5410 | static const struct ephy_info e_info_8105e_1[] = { |
| 5411 | { 0x07, 0, 0x4000 }, |
| 5412 | { 0x19, 0, 0x0200 }, |
| 5413 | { 0x19, 0, 0x0020 }, |
| 5414 | { 0x1e, 0, 0x2000 }, |
| 5415 | { 0x03, 0, 0x0001 }, |
| 5416 | { 0x19, 0, 0x0100 }, |
| 5417 | { 0x19, 0, 0x0004 }, |
| 5418 | { 0x0a, 0, 0x0020 } |
| 5419 | }; |
| 5420 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5421 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5422 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5423 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5424 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5425 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5426 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5427 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5428 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5429 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5430 | rtl_ephy_init(tp, e_info_8105e_1); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5431 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5432 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5433 | } |
| 5434 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5435 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5436 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5437 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5438 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5439 | } |
| 5440 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5441 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5442 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5443 | static const struct ephy_info e_info_8402[] = { |
| 5444 | { 0x19, 0xffff, 0xff64 }, |
| 5445 | { 0x1e, 0, 0x4000 } |
| 5446 | }; |
| 5447 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5448 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5449 | |
| 5450 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5451 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5452 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5453 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5454 | |
Heiner Kallweit | 1791ad5 | 2019-05-04 16:57:49 +0200 | [diff] [blame] | 5455 | rtl_ephy_init(tp, e_info_8402); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5456 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5457 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5458 | |
Heiner Kallweit | 6b1bd24 | 2019-05-05 12:33:40 +0200 | [diff] [blame] | 5459 | rtl_set_fifo_size(tp, 0x00, 0x00, 0x02, 0x06); |
Heiner Kallweit | 4e7e462 | 2019-04-28 11:12:56 +0200 | [diff] [blame] | 5460 | rtl_reset_packet_filter(tp); |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 5461 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000); |
| 5462 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000); |
| 5463 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5464 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5465 | rtl_pcie_state_l2l3_disable(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5466 | } |
| 5467 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5468 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5469 | { |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5470 | rtl_hw_aspm_clkreq_enable(tp, false); |
| 5471 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5472 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5473 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5474 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5475 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5476 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5477 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5478 | |
Heiner Kallweit | c259b7f | 2019-01-19 22:05:14 +0100 | [diff] [blame] | 5479 | rtl_pcie_state_l2l3_disable(tp); |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5480 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5481 | } |
| 5482 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5483 | static void rtl_hw_config(struct rtl8169_private *tp) |
| 5484 | { |
| 5485 | static const rtl_generic_fct hw_configs[] = { |
| 5486 | [RTL_GIGA_MAC_VER_07] = rtl_hw_start_8102e_1, |
| 5487 | [RTL_GIGA_MAC_VER_08] = rtl_hw_start_8102e_3, |
| 5488 | [RTL_GIGA_MAC_VER_09] = rtl_hw_start_8102e_2, |
| 5489 | [RTL_GIGA_MAC_VER_10] = NULL, |
| 5490 | [RTL_GIGA_MAC_VER_11] = rtl_hw_start_8168bb, |
| 5491 | [RTL_GIGA_MAC_VER_12] = rtl_hw_start_8168bef, |
| 5492 | [RTL_GIGA_MAC_VER_13] = NULL, |
| 5493 | [RTL_GIGA_MAC_VER_14] = NULL, |
| 5494 | [RTL_GIGA_MAC_VER_15] = NULL, |
| 5495 | [RTL_GIGA_MAC_VER_16] = NULL, |
| 5496 | [RTL_GIGA_MAC_VER_17] = rtl_hw_start_8168bef, |
| 5497 | [RTL_GIGA_MAC_VER_18] = rtl_hw_start_8168cp_1, |
| 5498 | [RTL_GIGA_MAC_VER_19] = rtl_hw_start_8168c_1, |
| 5499 | [RTL_GIGA_MAC_VER_20] = rtl_hw_start_8168c_2, |
| 5500 | [RTL_GIGA_MAC_VER_21] = rtl_hw_start_8168c_3, |
| 5501 | [RTL_GIGA_MAC_VER_22] = rtl_hw_start_8168c_4, |
| 5502 | [RTL_GIGA_MAC_VER_23] = rtl_hw_start_8168cp_2, |
| 5503 | [RTL_GIGA_MAC_VER_24] = rtl_hw_start_8168cp_3, |
| 5504 | [RTL_GIGA_MAC_VER_25] = rtl_hw_start_8168d, |
| 5505 | [RTL_GIGA_MAC_VER_26] = rtl_hw_start_8168d, |
| 5506 | [RTL_GIGA_MAC_VER_27] = rtl_hw_start_8168d, |
| 5507 | [RTL_GIGA_MAC_VER_28] = rtl_hw_start_8168d_4, |
| 5508 | [RTL_GIGA_MAC_VER_29] = rtl_hw_start_8105e_1, |
| 5509 | [RTL_GIGA_MAC_VER_30] = rtl_hw_start_8105e_2, |
| 5510 | [RTL_GIGA_MAC_VER_31] = rtl_hw_start_8168dp, |
| 5511 | [RTL_GIGA_MAC_VER_32] = rtl_hw_start_8168e_1, |
| 5512 | [RTL_GIGA_MAC_VER_33] = rtl_hw_start_8168e_1, |
| 5513 | [RTL_GIGA_MAC_VER_34] = rtl_hw_start_8168e_2, |
| 5514 | [RTL_GIGA_MAC_VER_35] = rtl_hw_start_8168f_1, |
| 5515 | [RTL_GIGA_MAC_VER_36] = rtl_hw_start_8168f_1, |
| 5516 | [RTL_GIGA_MAC_VER_37] = rtl_hw_start_8402, |
| 5517 | [RTL_GIGA_MAC_VER_38] = rtl_hw_start_8411, |
| 5518 | [RTL_GIGA_MAC_VER_39] = rtl_hw_start_8106, |
| 5519 | [RTL_GIGA_MAC_VER_40] = rtl_hw_start_8168g_1, |
| 5520 | [RTL_GIGA_MAC_VER_41] = rtl_hw_start_8168g_1, |
| 5521 | [RTL_GIGA_MAC_VER_42] = rtl_hw_start_8168g_2, |
| 5522 | [RTL_GIGA_MAC_VER_43] = rtl_hw_start_8168g_2, |
| 5523 | [RTL_GIGA_MAC_VER_44] = rtl_hw_start_8411_2, |
| 5524 | [RTL_GIGA_MAC_VER_45] = rtl_hw_start_8168h_1, |
| 5525 | [RTL_GIGA_MAC_VER_46] = rtl_hw_start_8168h_1, |
| 5526 | [RTL_GIGA_MAC_VER_47] = rtl_hw_start_8168h_1, |
| 5527 | [RTL_GIGA_MAC_VER_48] = rtl_hw_start_8168h_1, |
| 5528 | [RTL_GIGA_MAC_VER_49] = rtl_hw_start_8168ep_1, |
| 5529 | [RTL_GIGA_MAC_VER_50] = rtl_hw_start_8168ep_2, |
| 5530 | [RTL_GIGA_MAC_VER_51] = rtl_hw_start_8168ep_3, |
| 5531 | }; |
| 5532 | |
| 5533 | if (hw_configs[tp->mac_version]) |
| 5534 | hw_configs[tp->mac_version](tp); |
| 5535 | } |
| 5536 | |
| 5537 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
| 5538 | { |
| 5539 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
| 5540 | |
| 5541 | /* Workaround for RxFIFO overflow. */ |
| 5542 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
| 5543 | tp->irq_mask |= RxFIFOOver; |
| 5544 | tp->irq_mask &= ~RxOverflow; |
| 5545 | } |
| 5546 | |
| 5547 | rtl_hw_config(tp); |
| 5548 | } |
| 5549 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5550 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5551 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5552 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 5553 | tp->irq_mask &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5554 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5555 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5556 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5557 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5558 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5559 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5560 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5561 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5562 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5563 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5564 | |
Heiner Kallweit | 8344fff | 2019-04-14 10:32:07 +0200 | [diff] [blame] | 5565 | rtl_hw_config(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | } |
| 5567 | |
| 5568 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5569 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5570 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5571 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5572 | if (new_mtu > ETH_DATA_LEN) |
| 5573 | rtl_hw_jumbo_enable(tp); |
| 5574 | else |
| 5575 | rtl_hw_jumbo_disable(tp); |
| 5576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5578 | netdev_update_features(dev); |
| 5579 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5580 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5584 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5585 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5587 | } |
| 5588 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5589 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5590 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5592 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 5593 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5594 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5595 | kfree(*data_buff); |
| 5596 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | rtl8169_make_unusable_by_asic(desc); |
| 5598 | } |
| 5599 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5600 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5601 | { |
| 5602 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5603 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5604 | /* Force memory writes to complete before releasing descriptor */ |
| 5605 | dma_wmb(); |
| 5606 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5607 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5610 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5611 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5612 | { |
| 5613 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5615 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5616 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5618 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5619 | if (!data) |
| 5620 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5621 | |
Heiner Kallweit | 6dc8b74 | 2019-01-20 11:12:01 +0100 | [diff] [blame] | 5622 | /* Memory should be properly aligned, but better check. */ |
| 5623 | if (!IS_ALIGNED((unsigned long)data, 8)) { |
| 5624 | netdev_err_once(tp->dev, "RX buffer not 8-byte-aligned\n"); |
| 5625 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5626 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5627 | |
Heiner Kallweit | 6dc8b74 | 2019-01-20 11:12:01 +0100 | [diff] [blame] | 5628 | mapping = dma_map_single(d, data, R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5629 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5630 | if (net_ratelimit()) |
| 5631 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5632 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5635 | desc->addr = cpu_to_le64(mapping); |
| 5636 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5637 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5638 | |
| 5639 | err_out: |
| 5640 | kfree(data); |
| 5641 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5645 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5646 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | |
| 5648 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5649 | if (tp->Rx_databuff[i]) { |
| 5650 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | tp->RxDescArray + i); |
| 5652 | } |
| 5653 | } |
| 5654 | } |
| 5655 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5656 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5658 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5659 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5660 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5661 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5662 | { |
| 5663 | unsigned int i; |
| 5664 | |
| 5665 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5666 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5667 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5668 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5669 | if (!data) { |
| 5670 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5671 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5672 | } |
| 5673 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5676 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5677 | return 0; |
| 5678 | |
| 5679 | err_out: |
| 5680 | rtl8169_rx_clear(tp); |
| 5681 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | } |
| 5683 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5684 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5686 | rtl8169_init_ring_indexes(tp); |
| 5687 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5688 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5689 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5691 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | } |
| 5693 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5694 | 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] | 5695 | struct TxDesc *desc) |
| 5696 | { |
| 5697 | unsigned int len = tx_skb->len; |
| 5698 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5699 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | desc->opts1 = 0x00; |
| 5702 | desc->opts2 = 0x00; |
| 5703 | desc->addr = 0x00; |
| 5704 | tx_skb->len = 0; |
| 5705 | } |
| 5706 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5707 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5708 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | { |
| 5710 | unsigned int i; |
| 5711 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5712 | for (i = 0; i < n; i++) { |
| 5713 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5714 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5715 | unsigned int len = tx_skb->len; |
| 5716 | |
| 5717 | if (len) { |
| 5718 | struct sk_buff *skb = tx_skb->skb; |
| 5719 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5720 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | tp->TxDescArray + entry); |
| 5722 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5723 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | tx_skb->skb = NULL; |
| 5725 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5726 | } |
| 5727 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5731 | { |
| 5732 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | tp->cur_tx = tp->dirty_tx = 0; |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5734 | netdev_reset_queue(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5737 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5739 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5740 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5742 | napi_disable(&tp->napi); |
| 5743 | netif_stop_queue(dev); |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 5744 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5746 | rtl8169_hw_reset(tp); |
| 5747 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5748 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5749 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5752 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5754 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5755 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5756 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5760 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5761 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5762 | |
| 5763 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5766 | static __le32 rtl8169_get_txd_opts1(u32 opts0, u32 len, unsigned int entry) |
| 5767 | { |
| 5768 | u32 status = opts0 | len; |
| 5769 | |
| 5770 | if (entry == NUM_TX_DESC - 1) |
| 5771 | status |= RingEnd; |
| 5772 | |
| 5773 | return cpu_to_le32(status); |
| 5774 | } |
| 5775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | 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] | 5777 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | { |
| 5779 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5780 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5781 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5782 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5783 | |
| 5784 | entry = tp->cur_tx; |
| 5785 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5786 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5787 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5788 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | void *addr; |
| 5790 | |
| 5791 | entry = (entry + 1) % NUM_TX_DESC; |
| 5792 | |
| 5793 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5794 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5795 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5796 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5797 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5798 | if (net_ratelimit()) |
| 5799 | netif_err(tp, drv, tp->dev, |
| 5800 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5801 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 5804 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5805 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | txd->addr = cpu_to_le64(mapping); |
| 5807 | |
| 5808 | tp->tx_skb[entry].len = len; |
| 5809 | } |
| 5810 | |
| 5811 | if (cur_frag) { |
| 5812 | tp->tx_skb[entry].skb = skb; |
| 5813 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5814 | } |
| 5815 | |
| 5816 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5817 | |
| 5818 | err_out: |
| 5819 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5820 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | } |
| 5822 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5823 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5824 | { |
| 5825 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5826 | } |
| 5827 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5828 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5829 | struct net_device *dev); |
| 5830 | /* r8169_csum_workaround() |
| 5831 | * The hw limites the value the transport offset. When the offset is out of the |
| 5832 | * range, calculate the checksum by sw. |
| 5833 | */ |
| 5834 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 5835 | struct sk_buff *skb) |
| 5836 | { |
| 5837 | if (skb_shinfo(skb)->gso_size) { |
| 5838 | netdev_features_t features = tp->dev->features; |
| 5839 | struct sk_buff *segs, *nskb; |
| 5840 | |
| 5841 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 5842 | segs = skb_gso_segment(skb, features); |
| 5843 | if (IS_ERR(segs) || !segs) |
| 5844 | goto drop; |
| 5845 | |
| 5846 | do { |
| 5847 | nskb = segs; |
| 5848 | segs = segs->next; |
| 5849 | nskb->next = NULL; |
| 5850 | rtl8169_start_xmit(nskb, tp->dev); |
| 5851 | } while (segs); |
| 5852 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5853 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5854 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5855 | if (skb_checksum_help(skb) < 0) |
| 5856 | goto drop; |
| 5857 | |
| 5858 | rtl8169_start_xmit(skb, tp->dev); |
| 5859 | } else { |
| 5860 | struct net_device_stats *stats; |
| 5861 | |
| 5862 | drop: |
| 5863 | stats = &tp->dev->stats; |
| 5864 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5865 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | /* msdn_giant_send_check() |
| 5870 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5871 | * packet length for IPv6 TCP large packets. |
| 5872 | */ |
| 5873 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 5874 | { |
| 5875 | const struct ipv6hdr *ipv6h; |
| 5876 | struct tcphdr *th; |
| 5877 | int ret; |
| 5878 | |
| 5879 | ret = skb_cow_head(skb, 0); |
| 5880 | if (ret) |
| 5881 | return ret; |
| 5882 | |
| 5883 | ipv6h = ipv6_hdr(skb); |
| 5884 | th = tcp_hdr(skb); |
| 5885 | |
| 5886 | th->check = 0; |
| 5887 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 5888 | |
| 5889 | return ret; |
| 5890 | } |
| 5891 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5892 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 5893 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5894 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5895 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5896 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5897 | if (mss) { |
| 5898 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5899 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 5900 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5901 | const struct iphdr *ip = ip_hdr(skb); |
| 5902 | |
| 5903 | if (ip->protocol == IPPROTO_TCP) |
| 5904 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 5905 | else if (ip->protocol == IPPROTO_UDP) |
| 5906 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 5907 | else |
| 5908 | WARN_ON_ONCE(1); |
| 5909 | } |
| 5910 | |
| 5911 | return true; |
| 5912 | } |
| 5913 | |
| 5914 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 5915 | struct sk_buff *skb, u32 *opts) |
| 5916 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5917 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5918 | u32 mss = skb_shinfo(skb)->gso_size; |
| 5919 | |
| 5920 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5921 | if (transport_offset > GTTCPHO_MAX) { |
| 5922 | netif_warn(tp, tx_err, tp->dev, |
| 5923 | "Invalid transport offset 0x%x for TSO\n", |
| 5924 | transport_offset); |
| 5925 | return false; |
| 5926 | } |
| 5927 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5928 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5929 | case htons(ETH_P_IP): |
| 5930 | opts[0] |= TD1_GTSENV4; |
| 5931 | break; |
| 5932 | |
| 5933 | case htons(ETH_P_IPV6): |
| 5934 | if (msdn_giant_send_check(skb)) |
| 5935 | return false; |
| 5936 | |
| 5937 | opts[0] |= TD1_GTSENV6; |
| 5938 | break; |
| 5939 | |
| 5940 | default: |
| 5941 | WARN_ON_ONCE(1); |
| 5942 | break; |
| 5943 | } |
| 5944 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5945 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5946 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5947 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5948 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5950 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 5951 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5952 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5953 | if (transport_offset > TCPHO_MAX) { |
| 5954 | netif_warn(tp, tx_err, tp->dev, |
| 5955 | "Invalid transport offset 0x%x\n", |
| 5956 | transport_offset); |
| 5957 | return false; |
| 5958 | } |
| 5959 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 5960 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5961 | case htons(ETH_P_IP): |
| 5962 | opts[1] |= TD1_IPv4_CS; |
| 5963 | ip_protocol = ip_hdr(skb)->protocol; |
| 5964 | break; |
| 5965 | |
| 5966 | case htons(ETH_P_IPV6): |
| 5967 | opts[1] |= TD1_IPv6_CS; |
| 5968 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 5969 | break; |
| 5970 | |
| 5971 | default: |
| 5972 | ip_protocol = IPPROTO_RAW; |
| 5973 | break; |
| 5974 | } |
| 5975 | |
| 5976 | if (ip_protocol == IPPROTO_TCP) |
| 5977 | opts[1] |= TD1_TCP_CS; |
| 5978 | else if (ip_protocol == IPPROTO_UDP) |
| 5979 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5980 | else |
| 5981 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5982 | |
| 5983 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5984 | } else { |
| 5985 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 5986 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5988 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5989 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5990 | } |
| 5991 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 5992 | static bool rtl_tx_slots_avail(struct rtl8169_private *tp, |
| 5993 | unsigned int nr_frags) |
| 5994 | { |
| 5995 | unsigned int slots_avail = tp->dirty_tx + NUM_TX_DESC - tp->cur_tx; |
| 5996 | |
| 5997 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 5998 | return slots_avail > nr_frags; |
| 5999 | } |
| 6000 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6001 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6002 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6003 | { |
| 6004 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6005 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6006 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6007 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 6009 | u32 opts[2], len; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6010 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6011 | |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 6012 | if (unlikely(!rtl_tx_slots_avail(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6013 | 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] | 6014 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6018 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6020 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6021 | opts[0] = DescOwn; |
| 6022 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6023 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6024 | r8169_csum_workaround(tp, skb); |
| 6025 | return NETDEV_TX_OK; |
| 6026 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6027 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6028 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6029 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6030 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6031 | if (net_ratelimit()) |
| 6032 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6033 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | |
| 6036 | tp->tx_skb[entry].len = len; |
| 6037 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6038 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6039 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6040 | if (frags < 0) |
| 6041 | goto err_dma_1; |
| 6042 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6043 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6044 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6045 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6046 | tp->tx_skb[entry].skb = skb; |
| 6047 | } |
| 6048 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6049 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6050 | |
Heiner Kallweit | 0255d59 | 2019-02-10 15:28:04 +0100 | [diff] [blame] | 6051 | netdev_sent_queue(dev, skb->len); |
| 6052 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6053 | skb_tx_timestamp(skb); |
| 6054 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6055 | /* Force memory writes to complete before releasing descriptor */ |
| 6056 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6057 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame] | 6058 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6059 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6060 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6061 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6062 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6063 | tp->cur_tx += frags + 1; |
| 6064 | |
Heiner Kallweit | 0255d59 | 2019-02-10 15:28:04 +0100 | [diff] [blame] | 6065 | RTL_W8(tp, TxPoll, NPQ); |
| 6066 | |
Heiner Kallweit | 0255d59 | 2019-02-10 15:28:04 +0100 | [diff] [blame] | 6067 | if (!rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) { |
| 6068 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6069 | * not miss a ring update when it notices a stopped queue. |
| 6070 | */ |
| 6071 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6072 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6073 | /* Sync with rtl_tx: |
| 6074 | * - publish queue status and cur_tx ring index (write barrier) |
| 6075 | * - refresh dirty_tx ring index (read barrier). |
| 6076 | * May the current thread have a pessimistic view of the ring |
| 6077 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6078 | * can't. |
| 6079 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6080 | smp_mb(); |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 6081 | if (rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) |
Heiner Kallweit | 601ed4d | 2019-03-21 21:41:48 +0100 | [diff] [blame] | 6082 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6085 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6086 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6087 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6088 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6089 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6090 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6091 | dev->stats.tx_dropped++; |
| 6092 | return NETDEV_TX_OK; |
| 6093 | |
| 6094 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6096 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6097 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6101 | { |
| 6102 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6103 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | u16 pci_status, pci_cmd; |
| 6105 | |
| 6106 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6107 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6108 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6109 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6110 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | |
| 6112 | /* |
| 6113 | * The recovery sequence below admits a very elaborated explanation: |
| 6114 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6115 | * - I did not see what else could be done; |
| 6116 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | * |
| 6118 | * Feel free to adjust to your needs. |
| 6119 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6120 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6121 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6122 | else |
| 6123 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6124 | |
| 6125 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | |
| 6127 | pci_write_config_word(pdev, PCI_STATUS, |
| 6128 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6129 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6130 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6131 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6132 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | } |
| 6134 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 6135 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, |
| 6136 | int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6138 | unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | dirty_tx = tp->dirty_tx; |
| 6141 | smp_rmb(); |
| 6142 | tx_left = tp->cur_tx - dirty_tx; |
| 6143 | |
| 6144 | while (tx_left > 0) { |
| 6145 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6146 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6147 | u32 status; |
| 6148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6150 | if (status & DescOwn) |
| 6151 | break; |
| 6152 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6153 | /* This barrier is needed to keep us from reading |
| 6154 | * any other fields out of the Tx descriptor until |
| 6155 | * we know the status of DescOwn |
| 6156 | */ |
| 6157 | dma_rmb(); |
| 6158 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6159 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6160 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6161 | if (status & LastFrag) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6162 | pkts_compl++; |
| 6163 | bytes_compl += tx_skb->skb->len; |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 6164 | napi_consume_skb(tx_skb->skb, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | tx_skb->skb = NULL; |
| 6166 | } |
| 6167 | dirty_tx++; |
| 6168 | tx_left--; |
| 6169 | } |
| 6170 | |
| 6171 | if (tp->dirty_tx != dirty_tx) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6172 | netdev_completed_queue(dev, pkts_compl, bytes_compl); |
| 6173 | |
| 6174 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6175 | tp->tx_stats.packets += pkts_compl; |
| 6176 | tp->tx_stats.bytes += bytes_compl; |
| 6177 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 6178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6180 | /* Sync with rtl8169_start_xmit: |
| 6181 | * - publish dirty_tx ring index (write barrier) |
| 6182 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6183 | * May the current thread miss the stopped queue condition, |
| 6184 | * a racing xmit thread can only have a right view of the |
| 6185 | * ring status. |
| 6186 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6187 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | if (netif_queue_stopped(dev) && |
Heiner Kallweit | 76085c9 | 2018-11-22 22:03:08 +0100 | [diff] [blame] | 6189 | rtl_tx_slots_avail(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6190 | netif_wake_queue(dev); |
| 6191 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6192 | /* |
| 6193 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6194 | * too close. Let's kick an extra TxPoll request when a burst |
| 6195 | * of start_xmit activity is detected (if it is not detected, |
| 6196 | * it is slow enough). -- FR |
| 6197 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6198 | if (tp->cur_tx != dirty_tx) |
| 6199 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | } |
| 6201 | } |
| 6202 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6203 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6204 | { |
| 6205 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6206 | } |
| 6207 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6208 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | u32 status = opts1 & RxProtoMask; |
| 6211 | |
| 6212 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6213 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6215 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6216 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6219 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6220 | struct rtl8169_private *tp, |
| 6221 | int pkt_size, |
| 6222 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6224 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6225 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6227 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6228 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6229 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6230 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6231 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6232 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6233 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6234 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | } |
| 6236 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6237 | 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] | 6238 | { |
| 6239 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6240 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6242 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6244 | 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] | 6245 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6246 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | u32 status; |
| 6248 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6249 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6250 | if (status & DescOwn) |
| 6251 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6252 | |
| 6253 | /* This barrier is needed to keep us from reading |
| 6254 | * any other fields out of the Rx descriptor until |
| 6255 | * we know the status of DescOwn |
| 6256 | */ |
| 6257 | dma_rmb(); |
| 6258 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6259 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6260 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6261 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6262 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6263 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6264 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6266 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6267 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6268 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6269 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6270 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6271 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6272 | } else if (status & (RxRUNT | RxCRC) && |
| 6273 | !(status & RxRWT) && |
| 6274 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6275 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6278 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6279 | dma_addr_t addr; |
| 6280 | int pkt_size; |
| 6281 | |
| 6282 | process_pkt: |
| 6283 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6284 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6285 | pkt_size = (status & 0x00003fff) - 4; |
| 6286 | else |
| 6287 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6288 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6289 | /* |
| 6290 | * The driver does not support incoming fragmented |
| 6291 | * frames. They are seen as a symptom of over-mtu |
| 6292 | * sized frames. |
| 6293 | */ |
| 6294 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6295 | dev->stats.rx_dropped++; |
| 6296 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6297 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6298 | } |
| 6299 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6300 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6301 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6302 | if (!skb) { |
| 6303 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6304 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6305 | } |
| 6306 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6307 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | skb_put(skb, pkt_size); |
| 6309 | skb->protocol = eth_type_trans(skb, dev); |
| 6310 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6311 | rtl8169_rx_vlan_tag(desc, skb); |
| 6312 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6313 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6314 | dev->stats.multicast++; |
| 6315 | |
Heiner Kallweit | 448a241 | 2019-04-03 19:54:12 +0200 | [diff] [blame] | 6316 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6318 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6319 | tp->rx_stats.packets++; |
| 6320 | tp->rx_stats.bytes += pkt_size; |
| 6321 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6323 | release_descriptor: |
| 6324 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6325 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
| 6328 | count = cur_rx - tp->cur_rx; |
| 6329 | tp->cur_rx = cur_rx; |
| 6330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | return count; |
| 6332 | } |
| 6333 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6334 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6335 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6336 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | 3ff752c | 2019-01-19 22:02:40 +0100 | [diff] [blame] | 6337 | u16 status = RTL_R16(tp, IntrStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | |
Heiner Kallweit | c8248c6 | 2019-03-21 21:23:14 +0100 | [diff] [blame] | 6339 | if (!tp->irq_enabled || status == 0xffff || !(status & tp->irq_mask)) |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6340 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6341 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6342 | if (unlikely(status & SYSErr)) { |
| 6343 | rtl8169_pcierr_interrupt(tp->dev); |
| 6344 | goto out; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6345 | } |
| 6346 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6347 | if (status & LinkChg) |
| 6348 | phy_mac_interrupt(tp->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6349 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6350 | if (unlikely(status & RxFIFOOver && |
| 6351 | tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
| 6352 | netif_stop_queue(tp->dev); |
| 6353 | /* XXX - Hack alert. See rtl_task(). */ |
| 6354 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
| 6355 | } |
| 6356 | |
Heiner Kallweit | e62b2fd | 2019-04-14 11:48:39 +0200 | [diff] [blame] | 6357 | rtl_irq_disable(tp); |
| 6358 | napi_schedule_irqoff(&tp->napi); |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6359 | out: |
| 6360 | rtl_ack_events(tp, status); |
| 6361 | |
| 6362 | return IRQ_HANDLED; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6363 | } |
| 6364 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6365 | static void rtl_task(struct work_struct *work) |
| 6366 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6367 | static const struct { |
| 6368 | int bitnr; |
| 6369 | void (*action)(struct rtl8169_private *); |
| 6370 | } rtl_work[] = { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6371 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6372 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6373 | struct rtl8169_private *tp = |
| 6374 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6375 | struct net_device *dev = tp->dev; |
| 6376 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6377 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6378 | rtl_lock_work(tp); |
| 6379 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6380 | if (!netif_running(dev) || |
| 6381 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6382 | goto out_unlock; |
| 6383 | |
| 6384 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6385 | bool pending; |
| 6386 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6387 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6388 | if (pending) |
| 6389 | rtl_work[i].action(tp); |
| 6390 | } |
| 6391 | |
| 6392 | out_unlock: |
| 6393 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6394 | } |
| 6395 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6396 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6398 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6399 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6400 | int work_done; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6401 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6402 | work_done = rtl_rx(dev, tp, (u32) budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6403 | |
Heiner Kallweit | 5317d5c | 2018-11-22 22:02:00 +0100 | [diff] [blame] | 6404 | rtl_tx(dev, tp, budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6405 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6406 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 6407 | napi_complete_done(napi, work_done); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 6408 | rtl_irq_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6409 | } |
| 6410 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6411 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6414 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6415 | { |
| 6416 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6417 | |
| 6418 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6419 | return; |
| 6420 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6421 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 6422 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6423 | } |
| 6424 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6425 | static void r8169_phylink_handler(struct net_device *ndev) |
| 6426 | { |
| 6427 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 6428 | |
| 6429 | if (netif_carrier_ok(ndev)) { |
| 6430 | rtl_link_chg_patch(tp); |
| 6431 | pm_request_resume(&tp->pci_dev->dev); |
| 6432 | } else { |
| 6433 | pm_runtime_idle(&tp->pci_dev->dev); |
| 6434 | } |
| 6435 | |
| 6436 | if (net_ratelimit()) |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6437 | phy_print_status(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6438 | } |
| 6439 | |
| 6440 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 6441 | { |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6442 | struct phy_device *phydev = tp->phydev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6443 | phy_interface_t phy_mode; |
| 6444 | int ret; |
| 6445 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6446 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6447 | PHY_INTERFACE_MODE_MII; |
| 6448 | |
| 6449 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 6450 | phy_mode); |
| 6451 | if (ret) |
| 6452 | return ret; |
| 6453 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6454 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6455 | phy_set_max_speed(phydev, SPEED_100); |
| 6456 | |
Heiner Kallweit | 9cf9b84 | 2019-05-04 12:01:03 +0200 | [diff] [blame] | 6457 | phy_support_asym_pause(phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6458 | |
| 6459 | phy_attached_info(phydev); |
| 6460 | |
| 6461 | return 0; |
| 6462 | } |
| 6463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6464 | static void rtl8169_down(struct net_device *dev) |
| 6465 | { |
| 6466 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6467 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6468 | phy_stop(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6469 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6470 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6471 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6472 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6473 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6474 | /* |
| 6475 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6476 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6477 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6478 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6479 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6481 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Paul E. McKenney | 16f1150 | 2018-11-05 17:07:39 -0800 | [diff] [blame] | 6482 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6484 | rtl8169_tx_clear(tp); |
| 6485 | |
| 6486 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6487 | |
| 6488 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
| 6491 | static int rtl8169_close(struct net_device *dev) |
| 6492 | { |
| 6493 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6494 | struct pci_dev *pdev = tp->pci_dev; |
| 6495 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6496 | pm_runtime_get_sync(&pdev->dev); |
| 6497 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6498 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6499 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6500 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6501 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6502 | /* Clear all task flags */ |
| 6503 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6505 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6506 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6507 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6508 | cancel_work_sync(&tp->wk.work); |
| 6509 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6510 | phy_disconnect(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6511 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6512 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6513 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6514 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6515 | tp->RxPhyAddr); |
| 6516 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6517 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6518 | tp->TxDescArray = NULL; |
| 6519 | tp->RxDescArray = NULL; |
| 6520 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6521 | pm_runtime_put_sync(&pdev->dev); |
| 6522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6523 | return 0; |
| 6524 | } |
| 6525 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6526 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6527 | static void rtl8169_netpoll(struct net_device *dev) |
| 6528 | { |
| 6529 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6530 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6531 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6532 | } |
| 6533 | #endif |
| 6534 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6535 | static int rtl_open(struct net_device *dev) |
| 6536 | { |
| 6537 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6538 | struct pci_dev *pdev = tp->pci_dev; |
| 6539 | int retval = -ENOMEM; |
| 6540 | |
| 6541 | pm_runtime_get_sync(&pdev->dev); |
| 6542 | |
| 6543 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6544 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6545 | * dma_alloc_coherent provides more. |
| 6546 | */ |
| 6547 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6548 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6549 | if (!tp->TxDescArray) |
| 6550 | goto err_pm_runtime_put; |
| 6551 | |
| 6552 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6553 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6554 | if (!tp->RxDescArray) |
| 6555 | goto err_free_tx_0; |
| 6556 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6557 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6558 | if (retval < 0) |
| 6559 | goto err_free_rx_1; |
| 6560 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6561 | rtl_request_firmware(tp); |
| 6562 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6563 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6564 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6565 | if (retval < 0) |
| 6566 | goto err_release_fw_2; |
| 6567 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6568 | retval = r8169_phy_connect(tp); |
| 6569 | if (retval) |
| 6570 | goto err_free_irq; |
| 6571 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6572 | rtl_lock_work(tp); |
| 6573 | |
| 6574 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6575 | |
| 6576 | napi_enable(&tp->napi); |
| 6577 | |
| 6578 | rtl8169_init_phy(dev, tp); |
| 6579 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6580 | rtl_pll_power_up(tp); |
| 6581 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6582 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6583 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6584 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6585 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6586 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6587 | phy_start(tp->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6588 | netif_start_queue(dev); |
| 6589 | |
| 6590 | rtl_unlock_work(tp); |
| 6591 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6592 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6593 | out: |
| 6594 | return retval; |
| 6595 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6596 | err_free_irq: |
| 6597 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6598 | err_release_fw_2: |
| 6599 | rtl_release_firmware(tp); |
| 6600 | rtl8169_rx_clear(tp); |
| 6601 | err_free_rx_1: |
| 6602 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6603 | tp->RxPhyAddr); |
| 6604 | tp->RxDescArray = NULL; |
| 6605 | err_free_tx_0: |
| 6606 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6607 | tp->TxPhyAddr); |
| 6608 | tp->TxDescArray = NULL; |
| 6609 | err_pm_runtime_put: |
| 6610 | pm_runtime_put_noidle(&pdev->dev); |
| 6611 | goto out; |
| 6612 | } |
| 6613 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6614 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6615 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6616 | { |
| 6617 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6618 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6619 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6620 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6622 | pm_runtime_get_noresume(&pdev->dev); |
| 6623 | |
| 6624 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6625 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6626 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6627 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6628 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6629 | stats->rx_packets = tp->rx_stats.packets; |
| 6630 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6631 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6632 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6633 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6634 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6635 | stats->tx_packets = tp->tx_stats.packets; |
| 6636 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6637 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6638 | |
| 6639 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6640 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6641 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6642 | stats->rx_errors = dev->stats.rx_errors; |
| 6643 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6644 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6645 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6646 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6647 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6648 | /* |
| 6649 | * Fetch additonal counter values missing in stats collected by driver |
| 6650 | * from tally counters. |
| 6651 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6652 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6653 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6654 | |
| 6655 | /* |
| 6656 | * Subtract values fetched during initalization. |
| 6657 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6658 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6659 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6660 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6661 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6662 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6663 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6664 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6665 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6666 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | } |
| 6668 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6669 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6670 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6671 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6672 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6673 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6674 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6675 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6676 | phy_stop(tp->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6677 | netif_device_detach(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6678 | |
| 6679 | rtl_lock_work(tp); |
| 6680 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6681 | /* Clear all task flags */ |
| 6682 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6683 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6684 | rtl_unlock_work(tp); |
| 6685 | |
| 6686 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6687 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6688 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6689 | #ifdef CONFIG_PM |
| 6690 | |
| 6691 | static int rtl8169_suspend(struct device *device) |
| 6692 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6693 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6694 | struct rtl8169_private *tp = netdev_priv(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6695 | |
| 6696 | rtl8169_net_suspend(dev); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6697 | clk_disable_unprepare(tp->clk); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6698 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6699 | return 0; |
| 6700 | } |
| 6701 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6702 | static void __rtl8169_resume(struct net_device *dev) |
| 6703 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6704 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6705 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6706 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6707 | |
| 6708 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6709 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6710 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6711 | phy_start(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6712 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6713 | rtl_lock_work(tp); |
| 6714 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6715 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Heiner Kallweit | 58ba566 | 2019-01-19 22:06:25 +0100 | [diff] [blame] | 6716 | rtl_reset_work(tp); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6717 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6718 | } |
| 6719 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6720 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6721 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6722 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6723 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6724 | |
| 6725 | clk_prepare_enable(tp->clk); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6726 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6727 | if (netif_running(dev)) |
| 6728 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6729 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6730 | return 0; |
| 6731 | } |
| 6732 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6733 | static int rtl8169_runtime_suspend(struct device *device) |
| 6734 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6735 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6736 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6737 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6738 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6739 | return 0; |
| 6740 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6741 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6742 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6743 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6744 | |
| 6745 | rtl8169_net_suspend(dev); |
| 6746 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6747 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6748 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6749 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6750 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6751 | return 0; |
| 6752 | } |
| 6753 | |
| 6754 | static int rtl8169_runtime_resume(struct device *device) |
| 6755 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6756 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6757 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6758 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6759 | |
| 6760 | if (!tp->TxDescArray) |
| 6761 | return 0; |
| 6762 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6763 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6764 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6765 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6766 | |
| 6767 | __rtl8169_resume(dev); |
| 6768 | |
| 6769 | return 0; |
| 6770 | } |
| 6771 | |
| 6772 | static int rtl8169_runtime_idle(struct device *device) |
| 6773 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6774 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6775 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6776 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6777 | pm_schedule_suspend(device, 10000); |
| 6778 | |
| 6779 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6780 | } |
| 6781 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6782 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6783 | .suspend = rtl8169_suspend, |
| 6784 | .resume = rtl8169_resume, |
| 6785 | .freeze = rtl8169_suspend, |
| 6786 | .thaw = rtl8169_resume, |
| 6787 | .poweroff = rtl8169_suspend, |
| 6788 | .restore = rtl8169_resume, |
| 6789 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6790 | .runtime_resume = rtl8169_runtime_resume, |
| 6791 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6792 | }; |
| 6793 | |
| 6794 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6795 | |
| 6796 | #else /* !CONFIG_PM */ |
| 6797 | |
| 6798 | #define RTL8169_PM_OPS NULL |
| 6799 | |
| 6800 | #endif /* !CONFIG_PM */ |
| 6801 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6802 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6803 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6804 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6805 | switch (tp->mac_version) { |
| 6806 | case RTL_GIGA_MAC_VER_11: |
| 6807 | case RTL_GIGA_MAC_VER_12: |
| 6808 | case RTL_GIGA_MAC_VER_17: |
| 6809 | pci_clear_master(tp->pci_dev); |
| 6810 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6811 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6812 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6813 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6814 | break; |
| 6815 | default: |
| 6816 | break; |
| 6817 | } |
| 6818 | } |
| 6819 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6820 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6821 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6822 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6823 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6824 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6825 | rtl8169_net_suspend(dev); |
| 6826 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6827 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6828 | rtl_rar_set(tp, dev->perm_addr); |
| 6829 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6830 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6831 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6832 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6833 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6834 | rtl_wol_suspend_quirk(tp); |
| 6835 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6836 | } |
| 6837 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6838 | pci_wake_from_d3(pdev, true); |
| 6839 | pci_set_power_state(pdev, PCI_D3hot); |
| 6840 | } |
| 6841 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6842 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6843 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6844 | { |
| 6845 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6846 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6847 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6848 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6849 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6850 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6851 | netif_napi_del(&tp->napi); |
| 6852 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6853 | unregister_netdev(dev); |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 6854 | mdiobus_unregister(tp->phydev->mdio.bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6855 | |
| 6856 | rtl_release_firmware(tp); |
| 6857 | |
| 6858 | if (pci_dev_run_wake(pdev)) |
| 6859 | pm_runtime_get_noresume(&pdev->dev); |
| 6860 | |
| 6861 | /* restore original MAC address */ |
| 6862 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6863 | } |
| 6864 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6865 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6866 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6867 | .ndo_stop = rtl8169_close, |
| 6868 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6869 | .ndo_start_xmit = rtl8169_start_xmit, |
| 6870 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 6871 | .ndo_validate_addr = eth_validate_addr, |
| 6872 | .ndo_change_mtu = rtl8169_change_mtu, |
| 6873 | .ndo_fix_features = rtl8169_fix_features, |
| 6874 | .ndo_set_features = rtl8169_set_features, |
| 6875 | .ndo_set_mac_address = rtl_set_mac_address, |
| 6876 | .ndo_do_ioctl = rtl8169_ioctl, |
| 6877 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 6878 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6879 | .ndo_poll_controller = rtl8169_netpoll, |
| 6880 | #endif |
| 6881 | |
| 6882 | }; |
| 6883 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6884 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6885 | void (*hw_start)(struct rtl8169_private *tp); |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6886 | u16 irq_mask; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6887 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6888 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6889 | } rtl_cfg_infos [] = { |
| 6890 | [RTL_CFG_0] = { |
| 6891 | .hw_start = rtl_hw_start_8169, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6892 | .irq_mask = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6893 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6894 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6895 | }, |
| 6896 | [RTL_CFG_1] = { |
| 6897 | .hw_start = rtl_hw_start_8168, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6898 | .irq_mask = LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6899 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6900 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6901 | }, |
| 6902 | [RTL_CFG_2] = { |
| 6903 | .hw_start = rtl_hw_start_8101, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6904 | .irq_mask = LinkChg | RxOverflow | RxFIFOOver, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6905 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6906 | } |
| 6907 | }; |
| 6908 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6909 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6910 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6911 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6912 | |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 6913 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6914 | rtl_unlock_config_regs(tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6915 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
Heiner Kallweit | df320ed | 2019-01-19 22:05:48 +0100 | [diff] [blame] | 6916 | rtl_lock_config_regs(tp); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6917 | flags = PCI_IRQ_LEGACY; |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 6918 | } else { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6919 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6920 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6921 | |
| 6922 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6923 | } |
| 6924 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6925 | static void rtl_read_mac_address(struct rtl8169_private *tp, |
| 6926 | u8 mac_addr[ETH_ALEN]) |
| 6927 | { |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6928 | u32 value; |
| 6929 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6930 | /* Get MAC address */ |
| 6931 | switch (tp->mac_version) { |
| 6932 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 6933 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 6934 | value = rtl_eri_read(tp, 0xe0); |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6935 | mac_addr[0] = (value >> 0) & 0xff; |
| 6936 | mac_addr[1] = (value >> 8) & 0xff; |
| 6937 | mac_addr[2] = (value >> 16) & 0xff; |
| 6938 | mac_addr[3] = (value >> 24) & 0xff; |
| 6939 | |
Heiner Kallweit | 724c6fd | 2019-04-28 11:10:50 +0200 | [diff] [blame] | 6940 | value = rtl_eri_read(tp, 0xe4); |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 6941 | mac_addr[4] = (value >> 0) & 0xff; |
| 6942 | mac_addr[5] = (value >> 8) & 0xff; |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 6943 | break; |
| 6944 | default: |
| 6945 | break; |
| 6946 | } |
| 6947 | } |
| 6948 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6949 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 6950 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6951 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 6955 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6956 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6957 | } |
| 6958 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6959 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 6960 | { |
| 6961 | struct rtl8169_private *tp = mii_bus->priv; |
| 6962 | |
| 6963 | if (phyaddr > 0) |
| 6964 | return -ENODEV; |
| 6965 | |
| 6966 | return rtl_readphy(tp, phyreg); |
| 6967 | } |
| 6968 | |
| 6969 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 6970 | int phyreg, u16 val) |
| 6971 | { |
| 6972 | struct rtl8169_private *tp = mii_bus->priv; |
| 6973 | |
| 6974 | if (phyaddr > 0) |
| 6975 | return -ENODEV; |
| 6976 | |
| 6977 | rtl_writephy(tp, phyreg, val); |
| 6978 | |
| 6979 | return 0; |
| 6980 | } |
| 6981 | |
| 6982 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 6983 | { |
| 6984 | struct pci_dev *pdev = tp->pci_dev; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6985 | struct mii_bus *new_bus; |
| 6986 | int ret; |
| 6987 | |
| 6988 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 6989 | if (!new_bus) |
| 6990 | return -ENOMEM; |
| 6991 | |
| 6992 | new_bus->name = "r8169"; |
| 6993 | new_bus->priv = tp; |
| 6994 | new_bus->parent = &pdev->dev; |
| 6995 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
Heiner Kallweit | a195016 | 2019-04-24 21:13:25 +0200 | [diff] [blame] | 6996 | 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] | 6997 | |
| 6998 | new_bus->read = r8169_mdio_read_reg; |
| 6999 | new_bus->write = r8169_mdio_write_reg; |
| 7000 | |
| 7001 | ret = mdiobus_register(new_bus); |
| 7002 | if (ret) |
| 7003 | return ret; |
| 7004 | |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 7005 | tp->phydev = mdiobus_get_phy(new_bus, 0); |
| 7006 | if (!tp->phydev) { |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7007 | mdiobus_unregister(new_bus); |
| 7008 | return -ENODEV; |
| 7009 | } |
| 7010 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 7011 | /* PHY will be woken up in rtl_open() */ |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 7012 | phy_suspend(tp->phydev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7013 | |
| 7014 | return 0; |
| 7015 | } |
| 7016 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7017 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7018 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7019 | u32 data; |
| 7020 | |
| 7021 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7022 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7023 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7024 | |
| 7025 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7026 | return; |
| 7027 | |
| 7028 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7029 | return; |
| 7030 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7031 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7032 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7033 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7034 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7035 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7036 | data &= ~(1 << 14); |
| 7037 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7038 | |
| 7039 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7040 | return; |
| 7041 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7042 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7043 | data |= (1 << 15); |
| 7044 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7045 | |
| 7046 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7047 | return; |
| 7048 | } |
| 7049 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7050 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7051 | { |
| 7052 | rtl8168ep_stop_cmac(tp); |
| 7053 | rtl_hw_init_8168g(tp); |
| 7054 | } |
| 7055 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7056 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7057 | { |
| 7058 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7059 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7060 | rtl_hw_init_8168g(tp); |
| 7061 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7062 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7063 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7064 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7065 | default: |
| 7066 | break; |
| 7067 | } |
| 7068 | } |
| 7069 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7070 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 7071 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 7072 | { |
| 7073 | switch (tp->mac_version) { |
| 7074 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7075 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 7076 | return false; |
| 7077 | default: |
| 7078 | return true; |
| 7079 | } |
| 7080 | } |
| 7081 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7082 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 7083 | { |
| 7084 | /* Non-GBit versions don't support jumbo frames */ |
| 7085 | if (!tp->supports_gmii) |
| 7086 | return JUMBO_1K; |
| 7087 | |
| 7088 | switch (tp->mac_version) { |
| 7089 | /* RTL8169 */ |
| 7090 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7091 | return JUMBO_7K; |
| 7092 | /* RTL8168b */ |
| 7093 | case RTL_GIGA_MAC_VER_11: |
| 7094 | case RTL_GIGA_MAC_VER_12: |
| 7095 | case RTL_GIGA_MAC_VER_17: |
| 7096 | return JUMBO_4K; |
| 7097 | /* RTL8168c */ |
| 7098 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 7099 | return JUMBO_6K; |
| 7100 | default: |
| 7101 | return JUMBO_9K; |
| 7102 | } |
| 7103 | } |
| 7104 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7105 | static void rtl_disable_clk(void *data) |
| 7106 | { |
| 7107 | clk_disable_unprepare(data); |
| 7108 | } |
| 7109 | |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 7110 | static int rtl_get_ether_clk(struct rtl8169_private *tp) |
| 7111 | { |
| 7112 | struct device *d = tp_to_dev(tp); |
| 7113 | struct clk *clk; |
| 7114 | int rc; |
| 7115 | |
| 7116 | clk = devm_clk_get(d, "ether_clk"); |
| 7117 | if (IS_ERR(clk)) { |
| 7118 | rc = PTR_ERR(clk); |
| 7119 | if (rc == -ENOENT) |
| 7120 | /* clk-core allows NULL (for suspend / resume) */ |
| 7121 | rc = 0; |
| 7122 | else if (rc != -EPROBE_DEFER) |
| 7123 | dev_err(d, "failed to get clk: %d\n", rc); |
| 7124 | } else { |
| 7125 | tp->clk = clk; |
| 7126 | rc = clk_prepare_enable(clk); |
| 7127 | if (rc) |
| 7128 | dev_err(d, "failed to enable clk: %d\n", rc); |
| 7129 | else |
| 7130 | rc = devm_add_action_or_reset(d, rtl_disable_clk, clk); |
| 7131 | } |
| 7132 | |
| 7133 | return rc; |
| 7134 | } |
| 7135 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7136 | 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] | 7137 | { |
| 7138 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Thierry Reding | deedf1f | 2019-02-06 13:30:18 +0100 | [diff] [blame] | 7139 | /* align to u16 for is_valid_ether_addr() */ |
| 7140 | u8 mac_addr[ETH_ALEN] __aligned(2) = {}; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7141 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7142 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7143 | int chipset, region, i; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7144 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7145 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7146 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7147 | if (!dev) |
| 7148 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7149 | |
| 7150 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7151 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7152 | tp = netdev_priv(dev); |
| 7153 | tp->dev = dev; |
| 7154 | tp->pci_dev = pdev; |
| 7155 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 7156 | tp->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7157 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7158 | /* Get the *optional* external "ether_clk" used on some boards */ |
Heiner Kallweit | b779dae | 2019-01-19 22:07:34 +0100 | [diff] [blame] | 7159 | rc = rtl_get_ether_clk(tp); |
| 7160 | if (rc) |
| 7161 | return rc; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7162 | |
Heiner Kallweit | b75bb8a | 2019-04-05 20:46:46 +0200 | [diff] [blame] | 7163 | /* Disable ASPM completely as that cause random device stop working |
| 7164 | * problems as well as full system hangs for some PCIe devices users. |
| 7165 | */ |
| 7166 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); |
| 7167 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7168 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7169 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7170 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7171 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7172 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7173 | } |
| 7174 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7175 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7176 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7177 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7178 | /* use first MMIO region */ |
| 7179 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7180 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7181 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7182 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | /* check for weird/broken PCI region reporting */ |
| 7186 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7187 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7188 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7189 | } |
| 7190 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7191 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7192 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7193 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7194 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7195 | } |
| 7196 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7197 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7198 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7199 | /* Identify chip attached to board */ |
Heiner Kallweit | b4cc2dc | 2018-11-22 21:58:48 +0100 | [diff] [blame] | 7200 | rtl8169_get_mac_version(tp); |
| 7201 | if (tp->mac_version == RTL_GIGA_MAC_NONE) |
| 7202 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7203 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 7204 | if (rtl_tbi_enabled(tp)) { |
| 7205 | dev_err(&pdev->dev, "TBI fiber mode not supported\n"); |
| 7206 | return -ENODEV; |
| 7207 | } |
| 7208 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7209 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7210 | |
Heiner Kallweit | 10b63e8 | 2019-01-20 11:45:20 +0100 | [diff] [blame] | 7211 | if (sizeof(dma_addr_t) > 4 && tp->mac_version >= RTL_GIGA_MAC_VER_18 && |
Heiner Kallweit | a045679 | 2018-09-25 07:59:36 +0200 | [diff] [blame] | 7212 | !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7213 | dev->features |= NETIF_F_HIGHDMA; |
| 7214 | } else { |
| 7215 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7216 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7217 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7218 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7219 | } |
| 7220 | } |
| 7221 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7222 | rtl_init_rxcfg(tp); |
| 7223 | |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 7224 | rtl8169_irq_mask_and_ack(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7225 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7226 | rtl_hw_initialize(tp); |
| 7227 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7228 | rtl_hw_reset(tp); |
| 7229 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7230 | pci_set_master(pdev); |
| 7231 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7232 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7233 | rtl_init_jumbo_ops(tp); |
| 7234 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7235 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7236 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7237 | rc = rtl_alloc_irq(tp); |
| 7238 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7239 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7240 | return rc; |
| 7241 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7242 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7243 | mutex_init(&tp->wk.mutex); |
Heiner Kallweit | 5c41e78 | 2019-01-19 22:03:49 +0100 | [diff] [blame] | 7244 | INIT_WORK(&tp->wk.work, rtl_task); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7245 | u64_stats_init(&tp->rx_stats.syncp); |
| 7246 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7247 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 7248 | /* get MAC address */ |
| 7249 | rc = eth_platform_get_mac_address(&pdev->dev, mac_addr); |
| 7250 | if (rc) |
| 7251 | rtl_read_mac_address(tp, mac_addr); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7252 | |
Thierry Reding | 04c7788 | 2019-02-06 13:30:17 +0100 | [diff] [blame] | 7253 | if (is_valid_ether_addr(mac_addr)) |
| 7254 | rtl_rar_set(tp, mac_addr); |
| 7255 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7256 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7257 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7258 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7259 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7260 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7261 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7262 | |
| 7263 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7264 | * properly for all devices */ |
| 7265 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7266 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7267 | |
| 7268 | 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] | 7269 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7270 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7271 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7272 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 7273 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7274 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7275 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7276 | |
| 7277 | /* |
| 7278 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7279 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7280 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7281 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7282 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7283 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7284 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7285 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7286 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7287 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7288 | } else { |
| 7289 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7290 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7291 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7292 | dev->hw_features |= NETIF_F_RXALL; |
| 7293 | dev->hw_features |= NETIF_F_RXFCS; |
| 7294 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7295 | /* MTU range: 60 - hw-specific max */ |
| 7296 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7297 | jumbo_max = rtl_jumbo_max(tp); |
| 7298 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7299 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7300 | tp->hw_start = cfg->hw_start; |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 7301 | tp->irq_mask = RTL_EVENT_NAPI | cfg->irq_mask; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7302 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7303 | |
Heiner Kallweit | 254764e | 2019-01-22 22:23:41 +0100 | [diff] [blame] | 7304 | tp->fw_name = rtl_chip_infos[chipset].fw_name; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7305 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7306 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7307 | &tp->counters_phys_addr, |
| 7308 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7309 | if (!tp->counters) |
| 7310 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7311 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7312 | pci_set_drvdata(pdev, dev); |
| 7313 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7314 | rc = r8169_mdio_register(tp); |
| 7315 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7316 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7317 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 7318 | /* chip gets powered up in rtl_open() */ |
| 7319 | rtl_pll_power_down(tp); |
| 7320 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7321 | rc = register_netdev(dev); |
| 7322 | if (rc) |
| 7323 | goto err_mdio_unregister; |
| 7324 | |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 7325 | netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n", |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7326 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 7327 | (RTL_R32(tp, TxConfig) >> 20) & 0xfcf, |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7328 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7329 | |
| 7330 | if (jumbo_max > JUMBO_1K) |
| 7331 | netif_info(tp, probe, dev, |
| 7332 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 7333 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 7334 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7335 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7336 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7337 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7338 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7339 | if (pci_dev_run_wake(pdev)) |
| 7340 | pm_runtime_put_sync(&pdev->dev); |
| 7341 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7342 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7343 | |
| 7344 | err_mdio_unregister: |
Heiner Kallweit | 703732f | 2019-01-19 22:07:05 +0100 | [diff] [blame] | 7345 | mdiobus_unregister(tp->phydev->mdio.bus); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7346 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7347 | } |
| 7348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7349 | static struct pci_driver rtl8169_pci_driver = { |
| 7350 | .name = MODULENAME, |
| 7351 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7352 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7353 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7354 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7355 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7356 | }; |
| 7357 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7358 | module_pci_driver(rtl8169_pci_driver); |