Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2 | * r8169.c: RealTek 8169/8168/8101 ethernet driver. |
| 3 | * |
| 4 | * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw> |
| 5 | * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com> |
| 6 | * Copyright (c) a lot of people too. Please respect their work. |
| 7 | * |
| 8 | * See MAINTAINERS file for support contact information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/etherdevice.h> |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 16 | #include <linux/clk.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/delay.h> |
| 18 | #include <linux/ethtool.h> |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 19 | #include <linux/phy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/if_vlan.h> |
| 21 | #include <linux/crc32.h> |
| 22 | #include <linux/in.h> |
Heiner Kallweit | 098b01a | 2018-08-10 22:37:31 +0200 | [diff] [blame] | 23 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/ip.h> |
| 25 | #include <linux/tcp.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 28 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 29 | #include <linux/firmware.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 30 | #include <linux/prefetch.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 31 | #include <linux/ipv6.h> |
| 32 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define MODULENAME "r8169" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 36 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 37 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 38 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 39 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 40 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 41 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 42 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 48 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 49 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 50 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 51 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 52 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 53 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 54 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 55 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 56 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 57 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 58 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 59 | #define TX_SLOTS_AVAIL(tp) \ |
| 60 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 61 | |
| 62 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 63 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 64 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 67 | 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] | 68 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 70 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 72 | |
| 73 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 74 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 76 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 78 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 81 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 82 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 83 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 84 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 85 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 86 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 89 | RTL_GIGA_MAC_VER_01 = 0, |
| 90 | RTL_GIGA_MAC_VER_02, |
| 91 | RTL_GIGA_MAC_VER_03, |
| 92 | RTL_GIGA_MAC_VER_04, |
| 93 | RTL_GIGA_MAC_VER_05, |
| 94 | RTL_GIGA_MAC_VER_06, |
| 95 | RTL_GIGA_MAC_VER_07, |
| 96 | RTL_GIGA_MAC_VER_08, |
| 97 | RTL_GIGA_MAC_VER_09, |
| 98 | RTL_GIGA_MAC_VER_10, |
| 99 | RTL_GIGA_MAC_VER_11, |
| 100 | RTL_GIGA_MAC_VER_12, |
| 101 | RTL_GIGA_MAC_VER_13, |
| 102 | RTL_GIGA_MAC_VER_14, |
| 103 | RTL_GIGA_MAC_VER_15, |
| 104 | RTL_GIGA_MAC_VER_16, |
| 105 | RTL_GIGA_MAC_VER_17, |
| 106 | RTL_GIGA_MAC_VER_18, |
| 107 | RTL_GIGA_MAC_VER_19, |
| 108 | RTL_GIGA_MAC_VER_20, |
| 109 | RTL_GIGA_MAC_VER_21, |
| 110 | RTL_GIGA_MAC_VER_22, |
| 111 | RTL_GIGA_MAC_VER_23, |
| 112 | RTL_GIGA_MAC_VER_24, |
| 113 | RTL_GIGA_MAC_VER_25, |
| 114 | RTL_GIGA_MAC_VER_26, |
| 115 | RTL_GIGA_MAC_VER_27, |
| 116 | RTL_GIGA_MAC_VER_28, |
| 117 | RTL_GIGA_MAC_VER_29, |
| 118 | RTL_GIGA_MAC_VER_30, |
| 119 | RTL_GIGA_MAC_VER_31, |
| 120 | RTL_GIGA_MAC_VER_32, |
| 121 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 122 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 123 | RTL_GIGA_MAC_VER_35, |
| 124 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 125 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 126 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 127 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_40, |
| 129 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 130 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 131 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 132 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 133 | RTL_GIGA_MAC_VER_45, |
| 134 | RTL_GIGA_MAC_VER_46, |
| 135 | RTL_GIGA_MAC_VER_47, |
| 136 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 137 | RTL_GIGA_MAC_VER_49, |
| 138 | RTL_GIGA_MAC_VER_50, |
| 139 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 140 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 143 | #define JUMBO_1K ETH_DATA_LEN |
| 144 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 145 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 146 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 147 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 148 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 149 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | const char *name; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 151 | const char *fw_name; |
| 152 | } rtl_chip_infos[] = { |
| 153 | /* PCI devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 154 | [RTL_GIGA_MAC_VER_01] = {"RTL8169" }, |
| 155 | [RTL_GIGA_MAC_VER_02] = {"RTL8169s" }, |
| 156 | [RTL_GIGA_MAC_VER_03] = {"RTL8110s" }, |
| 157 | [RTL_GIGA_MAC_VER_04] = {"RTL8169sb/8110sb" }, |
| 158 | [RTL_GIGA_MAC_VER_05] = {"RTL8169sc/8110sc" }, |
| 159 | [RTL_GIGA_MAC_VER_06] = {"RTL8169sc/8110sc" }, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 160 | /* PCI-E devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 161 | [RTL_GIGA_MAC_VER_07] = {"RTL8102e" }, |
| 162 | [RTL_GIGA_MAC_VER_08] = {"RTL8102e" }, |
| 163 | [RTL_GIGA_MAC_VER_09] = {"RTL8102e" }, |
| 164 | [RTL_GIGA_MAC_VER_10] = {"RTL8101e" }, |
| 165 | [RTL_GIGA_MAC_VER_11] = {"RTL8168b/8111b" }, |
| 166 | [RTL_GIGA_MAC_VER_12] = {"RTL8168b/8111b" }, |
| 167 | [RTL_GIGA_MAC_VER_13] = {"RTL8101e" }, |
| 168 | [RTL_GIGA_MAC_VER_14] = {"RTL8100e" }, |
| 169 | [RTL_GIGA_MAC_VER_15] = {"RTL8100e" }, |
| 170 | [RTL_GIGA_MAC_VER_16] = {"RTL8101e" }, |
| 171 | [RTL_GIGA_MAC_VER_17] = {"RTL8168b/8111b" }, |
| 172 | [RTL_GIGA_MAC_VER_18] = {"RTL8168cp/8111cp" }, |
| 173 | [RTL_GIGA_MAC_VER_19] = {"RTL8168c/8111c" }, |
| 174 | [RTL_GIGA_MAC_VER_20] = {"RTL8168c/8111c" }, |
| 175 | [RTL_GIGA_MAC_VER_21] = {"RTL8168c/8111c" }, |
| 176 | [RTL_GIGA_MAC_VER_22] = {"RTL8168c/8111c" }, |
| 177 | [RTL_GIGA_MAC_VER_23] = {"RTL8168cp/8111cp" }, |
| 178 | [RTL_GIGA_MAC_VER_24] = {"RTL8168cp/8111cp" }, |
| 179 | [RTL_GIGA_MAC_VER_25] = {"RTL8168d/8111d", FIRMWARE_8168D_1}, |
| 180 | [RTL_GIGA_MAC_VER_26] = {"RTL8168d/8111d", FIRMWARE_8168D_2}, |
| 181 | [RTL_GIGA_MAC_VER_27] = {"RTL8168dp/8111dp" }, |
| 182 | [RTL_GIGA_MAC_VER_28] = {"RTL8168dp/8111dp" }, |
| 183 | [RTL_GIGA_MAC_VER_29] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 184 | [RTL_GIGA_MAC_VER_30] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 185 | [RTL_GIGA_MAC_VER_31] = {"RTL8168dp/8111dp" }, |
| 186 | [RTL_GIGA_MAC_VER_32] = {"RTL8168e/8111e", FIRMWARE_8168E_1}, |
| 187 | [RTL_GIGA_MAC_VER_33] = {"RTL8168e/8111e", FIRMWARE_8168E_2}, |
| 188 | [RTL_GIGA_MAC_VER_34] = {"RTL8168evl/8111evl", FIRMWARE_8168E_3}, |
| 189 | [RTL_GIGA_MAC_VER_35] = {"RTL8168f/8111f", FIRMWARE_8168F_1}, |
| 190 | [RTL_GIGA_MAC_VER_36] = {"RTL8168f/8111f", FIRMWARE_8168F_2}, |
| 191 | [RTL_GIGA_MAC_VER_37] = {"RTL8402", FIRMWARE_8402_1 }, |
| 192 | [RTL_GIGA_MAC_VER_38] = {"RTL8411", FIRMWARE_8411_1 }, |
| 193 | [RTL_GIGA_MAC_VER_39] = {"RTL8106e", FIRMWARE_8106E_1}, |
| 194 | [RTL_GIGA_MAC_VER_40] = {"RTL8168g/8111g", FIRMWARE_8168G_2}, |
| 195 | [RTL_GIGA_MAC_VER_41] = {"RTL8168g/8111g" }, |
| 196 | [RTL_GIGA_MAC_VER_42] = {"RTL8168g/8111g", FIRMWARE_8168G_3}, |
| 197 | [RTL_GIGA_MAC_VER_43] = {"RTL8106e", FIRMWARE_8106E_2}, |
| 198 | [RTL_GIGA_MAC_VER_44] = {"RTL8411", FIRMWARE_8411_2 }, |
| 199 | [RTL_GIGA_MAC_VER_45] = {"RTL8168h/8111h", FIRMWARE_8168H_1}, |
| 200 | [RTL_GIGA_MAC_VER_46] = {"RTL8168h/8111h", FIRMWARE_8168H_2}, |
| 201 | [RTL_GIGA_MAC_VER_47] = {"RTL8107e", FIRMWARE_8107E_1}, |
| 202 | [RTL_GIGA_MAC_VER_48] = {"RTL8107e", FIRMWARE_8107E_2}, |
| 203 | [RTL_GIGA_MAC_VER_49] = {"RTL8168ep/8111ep" }, |
| 204 | [RTL_GIGA_MAC_VER_50] = {"RTL8168ep/8111ep" }, |
| 205 | [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 208 | enum cfg_version { |
| 209 | RTL_CFG_0 = 0x00, |
| 210 | RTL_CFG_1, |
| 211 | RTL_CFG_2 |
| 212 | }; |
| 213 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 214 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 215 | { PCI_VDEVICE(REALTEK, 0x8129), RTL_CFG_0 }, |
| 216 | { PCI_VDEVICE(REALTEK, 0x8136), RTL_CFG_2 }, |
| 217 | { PCI_VDEVICE(REALTEK, 0x8161), RTL_CFG_1 }, |
| 218 | { PCI_VDEVICE(REALTEK, 0x8167), RTL_CFG_0 }, |
| 219 | { PCI_VDEVICE(REALTEK, 0x8168), RTL_CFG_1 }, |
| 220 | { PCI_VDEVICE(NCUBE, 0x8168), RTL_CFG_1 }, |
| 221 | { PCI_VDEVICE(REALTEK, 0x8169), RTL_CFG_0 }, |
| 222 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 223 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
| 224 | { PCI_VDEVICE(DLINK, 0x4300), RTL_CFG_0 }, |
| 225 | { PCI_VDEVICE(DLINK, 0x4302), RTL_CFG_0 }, |
| 226 | { PCI_VDEVICE(AT, 0xc107), RTL_CFG_0 }, |
| 227 | { PCI_VDEVICE(USR, 0x0116), RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 228 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 229 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 230 | { 0x0001, 0x8168, |
| 231 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Heiner Kallweit | 6f0d308 | 2018-11-19 22:35:08 +0100 | [diff] [blame] | 232 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 236 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 237 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 238 | static struct { |
| 239 | u32 msg_enable; |
| 240 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 242 | enum rtl_registers { |
| 243 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 244 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 245 | MAR0 = 8, /* Multicast filter. */ |
| 246 | CounterAddrLow = 0x10, |
| 247 | CounterAddrHigh = 0x14, |
| 248 | TxDescStartAddrLow = 0x20, |
| 249 | TxDescStartAddrHigh = 0x24, |
| 250 | TxHDescStartAddrLow = 0x28, |
| 251 | TxHDescStartAddrHigh = 0x2c, |
| 252 | FLASH = 0x30, |
| 253 | ERSR = 0x36, |
| 254 | ChipCmd = 0x37, |
| 255 | TxPoll = 0x38, |
| 256 | IntrMask = 0x3c, |
| 257 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 258 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 259 | TxConfig = 0x40, |
| 260 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 261 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 262 | |
| 263 | RxConfig = 0x44, |
| 264 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 265 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 266 | #define RXCFG_FIFO_SHIFT 13 |
| 267 | /* No threshold before first PCI xfer */ |
| 268 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 269 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 270 | #define RXCFG_DMA_SHIFT 8 |
| 271 | /* Unlimited maximum PCI burst. */ |
| 272 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 273 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 274 | RxMissed = 0x4c, |
| 275 | Cfg9346 = 0x50, |
| 276 | Config0 = 0x51, |
| 277 | Config1 = 0x52, |
| 278 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 279 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 280 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 281 | Config3 = 0x54, |
| 282 | Config4 = 0x55, |
| 283 | Config5 = 0x56, |
| 284 | MultiIntr = 0x5c, |
| 285 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 286 | PHYstatus = 0x6c, |
| 287 | RxMaxSize = 0xda, |
| 288 | CPlusCmd = 0xe0, |
| 289 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 290 | |
| 291 | #define RTL_COALESCE_MASK 0x0f |
| 292 | #define RTL_COALESCE_SHIFT 4 |
| 293 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 294 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 295 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 296 | RxDescAddrLow = 0xe4, |
| 297 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 298 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 299 | |
| 300 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 301 | |
| 302 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 303 | |
| 304 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 305 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 306 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 307 | FuncEvent = 0xf0, |
| 308 | FuncEventMask = 0xf4, |
| 309 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 310 | IBCR0 = 0xf8, |
| 311 | IBCR2 = 0xf9, |
| 312 | IBIMR0 = 0xfa, |
| 313 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 314 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | }; |
| 316 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 317 | enum rtl8168_8101_registers { |
| 318 | CSIDR = 0x64, |
| 319 | CSIAR = 0x68, |
| 320 | #define CSIAR_FLAG 0x80000000 |
| 321 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 322 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 323 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 324 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 325 | EPHYAR = 0x80, |
| 326 | #define EPHYAR_FLAG 0x80000000 |
| 327 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 328 | #define EPHYAR_REG_MASK 0x1f |
| 329 | #define EPHYAR_REG_SHIFT 16 |
| 330 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 331 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 332 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 333 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 334 | DBG_REG = 0xd1, |
| 335 | #define FIX_NAK_1 (1 << 4) |
| 336 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 337 | TWSI = 0xd2, |
| 338 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 339 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 340 | #define TX_EMPTY (1 << 5) |
| 341 | #define RX_EMPTY (1 << 4) |
| 342 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 343 | #define EN_NDP (1 << 3) |
| 344 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 345 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 346 | EFUSEAR = 0xdc, |
| 347 | #define EFUSEAR_FLAG 0x80000000 |
| 348 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 349 | #define EFUSEAR_READ_CMD 0x00000000 |
| 350 | #define EFUSEAR_REG_MASK 0x03ff |
| 351 | #define EFUSEAR_REG_SHIFT 8 |
| 352 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 353 | MISC_1 = 0xf2, |
| 354 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 355 | }; |
| 356 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 357 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 358 | LED_FREQ = 0x1a, |
| 359 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 360 | ERIDR = 0x70, |
| 361 | ERIAR = 0x74, |
| 362 | #define ERIAR_FLAG 0x80000000 |
| 363 | #define ERIAR_WRITE_CMD 0x80000000 |
| 364 | #define ERIAR_READ_CMD 0x00000000 |
| 365 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 366 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 367 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 368 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 369 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 370 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 371 | #define ERIAR_MASK_SHIFT 12 |
| 372 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 373 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 374 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 375 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 376 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 377 | EPHY_RXER_NUM = 0x7c, |
| 378 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 379 | #define OCPDR_WRITE_CMD 0x80000000 |
| 380 | #define OCPDR_READ_CMD 0x00000000 |
| 381 | #define OCPDR_REG_MASK 0x7f |
| 382 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 383 | #define OCPDR_DATA_MASK 0xffff |
| 384 | OCPAR = 0xb4, |
| 385 | #define OCPAR_FLAG 0x80000000 |
| 386 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 387 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 388 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 389 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 390 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 391 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 392 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 393 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 394 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 395 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 398 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 400 | SYSErr = 0x8000, |
| 401 | PCSTimeout = 0x4000, |
| 402 | SWInt = 0x0100, |
| 403 | TxDescUnavail = 0x0080, |
| 404 | RxFIFOOver = 0x0040, |
| 405 | LinkChg = 0x0020, |
| 406 | RxOverflow = 0x0010, |
| 407 | TxErr = 0x0008, |
| 408 | TxOK = 0x0004, |
| 409 | RxErr = 0x0002, |
| 410 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 413 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 414 | RxFOVF = (1 << 23), |
| 415 | RxRWT = (1 << 22), |
| 416 | RxRES = (1 << 21), |
| 417 | RxRUNT = (1 << 20), |
| 418 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 421 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 422 | CmdReset = 0x10, |
| 423 | CmdRxEnb = 0x08, |
| 424 | CmdTxEnb = 0x04, |
| 425 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 427 | /* TXPoll register p.5 */ |
| 428 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 429 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 430 | FSWInt = 0x01, /* Forced software interrupt */ |
| 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 433 | Cfg9346_Lock = 0x00, |
| 434 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 437 | AcceptErr = 0x20, |
| 438 | AcceptRunt = 0x10, |
| 439 | AcceptBroadcast = 0x08, |
| 440 | AcceptMulticast = 0x04, |
| 441 | AcceptMyPhys = 0x02, |
| 442 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 443 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | /* TxConfigBits */ |
| 446 | TxInterFrameGapShift = 24, |
| 447 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 448 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 449 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 450 | LEDS1 = (1 << 7), |
| 451 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 452 | Speed_down = (1 << 4), |
| 453 | MEMMAP = (1 << 3), |
| 454 | IOMAP = (1 << 2), |
| 455 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 456 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 457 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 458 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 459 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 460 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 461 | PCI_Clock_66MHz = 0x01, |
| 462 | PCI_Clock_33MHz = 0x00, |
| 463 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 464 | /* Config3 register p.25 */ |
| 465 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 466 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 467 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 468 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 469 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 470 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 471 | /* Config4 register */ |
| 472 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 473 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 474 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 475 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 476 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 477 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 478 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 479 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 480 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 481 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 484 | EnableBist = (1 << 15), // 8168 8101 |
| 485 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 486 | Normal_mode = (1 << 13), // unused |
| 487 | Force_half_dup = (1 << 12), // 8168 8101 |
| 488 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 489 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 490 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 491 | ASF = (1 << 8), // 8168 8101 |
| 492 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 493 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | RxVlan = (1 << 6), |
| 495 | RxChkSum = (1 << 5), |
| 496 | PCIDAC = (1 << 4), |
| 497 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 498 | #define INTT_MASK GENMASK(1, 0) |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 499 | INTT_0 = 0x0000, // 8168 |
| 500 | INTT_1 = 0x0001, // 8168 |
| 501 | INTT_2 = 0x0002, // 8168 |
| 502 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 505 | TBI_Enable = 0x80, |
| 506 | TxFlowCtrl = 0x40, |
| 507 | RxFlowCtrl = 0x20, |
| 508 | _1000bpsF = 0x10, |
| 509 | _100bps = 0x08, |
| 510 | _10bps = 0x04, |
| 511 | LinkStatus = 0x02, |
| 512 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 515 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 516 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 517 | /* ResetCounterCommand */ |
| 518 | CounterReset = 0x1, |
| 519 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 520 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 521 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 522 | |
| 523 | /* magic enable v2 */ |
| 524 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | }; |
| 526 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 527 | enum rtl_desc_bit { |
| 528 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 530 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 531 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 532 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 533 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 535 | /* Generic case. */ |
| 536 | enum rtl_tx_desc_bit { |
| 537 | /* First doubleword. */ |
| 538 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 539 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 541 | /* Second doubleword. */ |
| 542 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 543 | }; |
| 544 | |
| 545 | /* 8169, 8168b and 810x except 8102e. */ |
| 546 | enum rtl_tx_desc_bit_0 { |
| 547 | /* First doubleword. */ |
| 548 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 549 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 550 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 551 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 552 | }; |
| 553 | |
| 554 | /* 8102e, 8168c and beyond. */ |
| 555 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 556 | /* First doubleword. */ |
| 557 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 558 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 559 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 560 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 561 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 562 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 563 | #define TCPHO_SHIFT 18 |
| 564 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 565 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 566 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 567 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 568 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 569 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 570 | }; |
| 571 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 572 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* Rx private */ |
| 574 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 575 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | #define RxProtoUDP (PID1) |
| 578 | #define RxProtoTCP (PID0) |
| 579 | #define RxProtoIP (PID1 | PID0) |
| 580 | #define RxProtoMask RxProtoIP |
| 581 | |
| 582 | IPFail = (1 << 16), /* IP checksum failed */ |
| 583 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 584 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 585 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 586 | }; |
| 587 | |
| 588 | #define RsvdMask 0x3fffc000 |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 589 | #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 592 | __le32 opts1; |
| 593 | __le32 opts2; |
| 594 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 598 | __le32 opts1; |
| 599 | __le32 opts2; |
| 600 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | struct ring_info { |
| 604 | struct sk_buff *skb; |
| 605 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | }; |
| 607 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 608 | struct rtl8169_counters { |
| 609 | __le64 tx_packets; |
| 610 | __le64 rx_packets; |
| 611 | __le64 tx_errors; |
| 612 | __le32 rx_errors; |
| 613 | __le16 rx_missed; |
| 614 | __le16 align_errors; |
| 615 | __le32 tx_one_collision; |
| 616 | __le32 tx_multi_collision; |
| 617 | __le64 rx_unicast; |
| 618 | __le64 rx_broadcast; |
| 619 | __le32 rx_multicast; |
| 620 | __le16 tx_aborted; |
| 621 | __le16 tx_underun; |
| 622 | }; |
| 623 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 624 | struct rtl8169_tc_offsets { |
| 625 | bool inited; |
| 626 | __le64 tx_errors; |
| 627 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 628 | __le16 tx_aborted; |
| 629 | }; |
| 630 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 631 | enum rtl_flag { |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 632 | RTL_FLAG_TASK_ENABLED = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 633 | RTL_FLAG_TASK_RESET_PENDING, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 634 | RTL_FLAG_MAX |
| 635 | }; |
| 636 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 637 | struct rtl8169_stats { |
| 638 | u64 packets; |
| 639 | u64 bytes; |
| 640 | struct u64_stats_sync syncp; |
| 641 | }; |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | struct rtl8169_private { |
| 644 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 645 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 646 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 647 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 648 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 649 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 651 | 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] | 652 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 653 | struct rtl8169_stats rx_stats; |
| 654 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 656 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 657 | dma_addr_t TxPhyAddr; |
| 658 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 659 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 662 | |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 663 | u16 irq_mask; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 664 | const struct rtl_coalesce_info *coalesce_info; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 665 | struct clk *clk; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 666 | |
| 667 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 668 | void (*write)(struct rtl8169_private *, int, int); |
| 669 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 670 | } mdio_ops; |
| 671 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 672 | struct jumbo_ops { |
| 673 | void (*enable)(struct rtl8169_private *); |
| 674 | void (*disable)(struct rtl8169_private *); |
| 675 | } jumbo_ops; |
| 676 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 677 | void (*hw_start)(struct rtl8169_private *tp); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 678 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 679 | |
| 680 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 681 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 682 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 683 | struct work_struct work; |
| 684 | } wk; |
| 685 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 686 | unsigned supports_gmii:1; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 687 | struct mii_bus *mii_bus; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 688 | dma_addr_t counters_phys_addr; |
| 689 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 690 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 691 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 692 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 693 | struct rtl_fw { |
| 694 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 695 | |
| 696 | #define RTL_VER_SIZE 32 |
| 697 | |
| 698 | char version[RTL_VER_SIZE]; |
| 699 | |
| 700 | struct rtl_fw_phy_action { |
| 701 | __le32 *code; |
| 702 | size_t size; |
| 703 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 704 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 705 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 706 | |
| 707 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | }; |
| 709 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 710 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 713 | MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 714 | module_param_named(debug, debug.msg_enable, int, 0); |
| 715 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | MODULE_LICENSE("GPL"); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 717 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 718 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 719 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 720 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 721 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 722 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 723 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 724 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 725 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 726 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 727 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 728 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 729 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 730 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 731 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 732 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 733 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 734 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 735 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 737 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 738 | { |
| 739 | return &tp->pci_dev->dev; |
| 740 | } |
| 741 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 742 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 743 | { |
| 744 | mutex_lock(&tp->wk.mutex); |
| 745 | } |
| 746 | |
| 747 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 748 | { |
| 749 | mutex_unlock(&tp->wk.mutex); |
| 750 | } |
| 751 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 752 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 753 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 754 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 755 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 758 | struct rtl_cond { |
| 759 | bool (*check)(struct rtl8169_private *); |
| 760 | const char *msg; |
| 761 | }; |
| 762 | |
| 763 | static void rtl_udelay(unsigned int d) |
| 764 | { |
| 765 | udelay(d); |
| 766 | } |
| 767 | |
| 768 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 769 | void (*delay)(unsigned int), unsigned int d, int n, |
| 770 | bool high) |
| 771 | { |
| 772 | int i; |
| 773 | |
| 774 | for (i = 0; i < n; i++) { |
| 775 | delay(d); |
| 776 | if (c->check(tp) == high) |
| 777 | return true; |
| 778 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 779 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 780 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 781 | return false; |
| 782 | } |
| 783 | |
| 784 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 785 | const struct rtl_cond *c, |
| 786 | unsigned int d, int n) |
| 787 | { |
| 788 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 789 | } |
| 790 | |
| 791 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 792 | const struct rtl_cond *c, |
| 793 | unsigned int d, int n) |
| 794 | { |
| 795 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 796 | } |
| 797 | |
| 798 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 799 | const struct rtl_cond *c, |
| 800 | unsigned int d, int n) |
| 801 | { |
| 802 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 803 | } |
| 804 | |
| 805 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 806 | const struct rtl_cond *c, |
| 807 | unsigned int d, int n) |
| 808 | { |
| 809 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 810 | } |
| 811 | |
| 812 | #define DECLARE_RTL_COND(name) \ |
| 813 | static bool name ## _check(struct rtl8169_private *); \ |
| 814 | \ |
| 815 | static const struct rtl_cond name = { \ |
| 816 | .check = name ## _check, \ |
| 817 | .msg = #name \ |
| 818 | }; \ |
| 819 | \ |
| 820 | static bool name ## _check(struct rtl8169_private *tp) |
| 821 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 822 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 823 | { |
| 824 | if (reg & 0xffff0001) { |
| 825 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 826 | return true; |
| 827 | } |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 832 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 833 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 837 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 838 | if (rtl_ocp_reg_failure(tp, reg)) |
| 839 | return; |
| 840 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 841 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 842 | |
| 843 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 844 | } |
| 845 | |
| 846 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 847 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 848 | if (rtl_ocp_reg_failure(tp, reg)) |
| 849 | return 0; |
| 850 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 851 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 852 | |
| 853 | 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] | 854 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 855 | } |
| 856 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 857 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 858 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 859 | if (rtl_ocp_reg_failure(tp, reg)) |
| 860 | return; |
| 861 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 862 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 866 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 867 | if (rtl_ocp_reg_failure(tp, reg)) |
| 868 | return 0; |
| 869 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 870 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 871 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 872 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | #define OCP_STD_PHY_BASE 0xa400 |
| 876 | |
| 877 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 878 | { |
| 879 | if (reg == 0x1f) { |
| 880 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 881 | return; |
| 882 | } |
| 883 | |
| 884 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 885 | reg -= 0x10; |
| 886 | |
| 887 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 888 | } |
| 889 | |
| 890 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 891 | { |
| 892 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 893 | reg -= 0x10; |
| 894 | |
| 895 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 896 | } |
| 897 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 898 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 899 | { |
| 900 | if (reg == 0x1f) { |
| 901 | tp->ocp_base = value << 4; |
| 902 | return; |
| 903 | } |
| 904 | |
| 905 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 906 | } |
| 907 | |
| 908 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 909 | { |
| 910 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 911 | } |
| 912 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 913 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 914 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 915 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 916 | } |
| 917 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 918 | 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] | 919 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 920 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 922 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 923 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 924 | * According to hardware specs a 20us delay is required after write |
| 925 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 926 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 927 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 930 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 932 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 934 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
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 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 937 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 938 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 939 | /* |
| 940 | * According to hardware specs a 20us delay is required after read |
| 941 | * complete indication, but before sending next command. |
| 942 | */ |
| 943 | udelay(20); |
| 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | return value; |
| 946 | } |
| 947 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 948 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 949 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 950 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 951 | } |
| 952 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 953 | 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] | 954 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 955 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 956 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 957 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 958 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 959 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 962 | static 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] | 963 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 964 | r8168dp_1_mdio_access(tp, reg, |
| 965 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 968 | 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] | 969 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 970 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 971 | |
| 972 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 973 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 974 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 975 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 976 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 977 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 978 | } |
| 979 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 980 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 981 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 982 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 983 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 984 | 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] | 985 | } |
| 986 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 987 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 988 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 989 | 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] | 990 | } |
| 991 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 992 | 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] | 993 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 994 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 995 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 996 | r8169_mdio_write(tp, reg, 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_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1001 | 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] | 1002 | { |
| 1003 | int value; |
| 1004 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1005 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1006 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1007 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1008 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1009 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1010 | |
| 1011 | return value; |
| 1012 | } |
| 1013 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1014 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1015 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1016 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1019 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1020 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1021 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1025 | { |
| 1026 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1027 | } |
| 1028 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1029 | 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] | 1030 | { |
| 1031 | int val; |
| 1032 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1033 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1034 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1037 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1038 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1039 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1040 | } |
| 1041 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1042 | 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] | 1043 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1044 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1045 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1046 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1047 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1048 | |
| 1049 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1052 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1053 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1054 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1055 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1056 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1057 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1058 | } |
| 1059 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1060 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1061 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1062 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1063 | } |
| 1064 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1065 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1066 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1067 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1068 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1069 | RTL_W32(tp, ERIDR, val); |
| 1070 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1071 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1072 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1075 | 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] | 1076 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1077 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1078 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1079 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1080 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1083 | static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p, |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1084 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1085 | { |
| 1086 | u32 val; |
| 1087 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1088 | val = rtl_eri_read(tp, addr, type); |
| 1089 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1092 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1093 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1094 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1095 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1096 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1100 | { |
| 1101 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1102 | } |
| 1103 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1104 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1105 | u32 data) |
| 1106 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1107 | RTL_W32(tp, OCPDR, data); |
| 1108 | 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] | 1109 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1110 | } |
| 1111 | |
| 1112 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1113 | u32 data) |
| 1114 | { |
| 1115 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1116 | data, ERIAR_OOB); |
| 1117 | } |
| 1118 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1119 | static void r8168dp_oob_notify(struct rtl8169_private *tp, u8 cmd) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1120 | { |
| 1121 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1122 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1123 | r8168dp_ocp_write(tp, 0x1, 0x30, 0x00000001); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | #define OOB_CMD_RESET 0x00 |
| 1127 | #define OOB_CMD_DRIVER_START 0x05 |
| 1128 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1129 | |
| 1130 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1131 | { |
| 1132 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1133 | } |
| 1134 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1135 | DECLARE_RTL_COND(rtl_dp_ocp_read_cond) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1136 | { |
| 1137 | u16 reg; |
| 1138 | |
| 1139 | reg = rtl8168_get_ocp_reg(tp); |
| 1140 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1141 | return r8168dp_ocp_read(tp, 0x0f, reg) & 0x00000800; |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1144 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1145 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1146 | return r8168ep_ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1150 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1151 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1152 | } |
| 1153 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1154 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1155 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1156 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1157 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1158 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1159 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1160 | } |
| 1161 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1162 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1163 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1164 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 1165 | 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] | 1166 | } |
| 1167 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1168 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1169 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1170 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1171 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1172 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1173 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1174 | } |
| 1175 | |
| 1176 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1177 | { |
| 1178 | switch (tp->mac_version) { |
| 1179 | case RTL_GIGA_MAC_VER_27: |
| 1180 | case RTL_GIGA_MAC_VER_28: |
| 1181 | case RTL_GIGA_MAC_VER_31: |
| 1182 | rtl8168dp_driver_start(tp); |
| 1183 | break; |
| 1184 | case RTL_GIGA_MAC_VER_49: |
| 1185 | case RTL_GIGA_MAC_VER_50: |
| 1186 | case RTL_GIGA_MAC_VER_51: |
| 1187 | rtl8168ep_driver_start(tp); |
| 1188 | break; |
| 1189 | default: |
| 1190 | BUG(); |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1196 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1197 | r8168dp_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1198 | 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] | 1199 | } |
| 1200 | |
| 1201 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1202 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1203 | rtl8168ep_stop_cmac(tp); |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1204 | r8168ep_ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1205 | r8168ep_ocp_write(tp, 0x01, 0x30, |
| 1206 | r8168ep_ocp_read(tp, 0x01, 0x30) | 0x01); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1207 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1208 | } |
| 1209 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1210 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1211 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1212 | switch (tp->mac_version) { |
| 1213 | case RTL_GIGA_MAC_VER_27: |
| 1214 | case RTL_GIGA_MAC_VER_28: |
| 1215 | case RTL_GIGA_MAC_VER_31: |
| 1216 | rtl8168dp_driver_stop(tp); |
| 1217 | break; |
| 1218 | case RTL_GIGA_MAC_VER_49: |
| 1219 | case RTL_GIGA_MAC_VER_50: |
| 1220 | case RTL_GIGA_MAC_VER_51: |
| 1221 | rtl8168ep_driver_stop(tp); |
| 1222 | break; |
| 1223 | default: |
| 1224 | BUG(); |
| 1225 | break; |
| 1226 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1229 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1230 | { |
| 1231 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1232 | |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1233 | return !!(r8168dp_ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1234 | } |
| 1235 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1236 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1237 | { |
Heiner Kallweit | 3c72bf7 | 2018-11-19 22:40:04 +0100 | [diff] [blame] | 1238 | return !!(r8168ep_ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1241 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1242 | { |
| 1243 | switch (tp->mac_version) { |
| 1244 | case RTL_GIGA_MAC_VER_27: |
| 1245 | case RTL_GIGA_MAC_VER_28: |
| 1246 | case RTL_GIGA_MAC_VER_31: |
| 1247 | return r8168dp_check_dash(tp); |
| 1248 | case RTL_GIGA_MAC_VER_49: |
| 1249 | case RTL_GIGA_MAC_VER_50: |
| 1250 | case RTL_GIGA_MAC_VER_51: |
| 1251 | return r8168ep_check_dash(tp); |
| 1252 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1253 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1257 | struct exgmac_reg { |
| 1258 | u16 addr; |
| 1259 | u16 mask; |
| 1260 | u32 val; |
| 1261 | }; |
| 1262 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1263 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1264 | const struct exgmac_reg *r, int len) |
| 1265 | { |
| 1266 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1267 | rtl_eri_write(tp, r->addr, r->mask, r->val, ERIAR_EXGMAC); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1268 | r++; |
| 1269 | } |
| 1270 | } |
| 1271 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1272 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1273 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1274 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1277 | 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] | 1278 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1279 | 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] | 1280 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1281 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1282 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1285 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1286 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1287 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1291 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1292 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1293 | mmiowb(); |
| 1294 | } |
| 1295 | |
| 1296 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1297 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1298 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1299 | mmiowb(); |
| 1300 | } |
| 1301 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1302 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1303 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1304 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1305 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1306 | static void rtl_irq_enable(struct rtl8169_private *tp) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1307 | { |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 1308 | RTL_W16(tp, IntrMask, tp->irq_mask); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1309 | } |
| 1310 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1311 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1313 | rtl_irq_disable(tp); |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 1314 | rtl_ack_events(tp, 0xffff); |
| 1315 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1316 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1319 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1320 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1321 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1322 | struct phy_device *phydev = dev->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1323 | |
| 1324 | if (!netif_running(dev)) |
| 1325 | return; |
| 1326 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1327 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1328 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1329 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1330 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1331 | ERIAR_EXGMAC); |
| 1332 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1333 | ERIAR_EXGMAC); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1334 | } else if (phydev->speed == SPEED_100) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1335 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1336 | ERIAR_EXGMAC); |
| 1337 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1338 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1339 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1340 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1341 | ERIAR_EXGMAC); |
| 1342 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1343 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1344 | } |
| 1345 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1346 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1347 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1348 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1349 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1350 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1351 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1352 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1353 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1354 | ERIAR_EXGMAC); |
| 1355 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1356 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1357 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1358 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1359 | ERIAR_EXGMAC); |
| 1360 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1361 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1362 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1363 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1364 | if (phydev->speed == SPEED_10) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1365 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1366 | ERIAR_EXGMAC); |
| 1367 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1368 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1369 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1370 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1371 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1372 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1376 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1377 | |
| 1378 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1379 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1380 | u8 options; |
| 1381 | u32 wolopts = 0; |
| 1382 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1383 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1384 | if (!(options & PMEnable)) |
| 1385 | return 0; |
| 1386 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1387 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1388 | if (options & LinkUp) |
| 1389 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1390 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1391 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1392 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1393 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1394 | wolopts |= WAKE_MAGIC; |
| 1395 | break; |
| 1396 | default: |
| 1397 | if (options & MagicPacket) |
| 1398 | wolopts |= WAKE_MAGIC; |
| 1399 | break; |
| 1400 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1401 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1402 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1403 | if (options & UWF) |
| 1404 | wolopts |= WAKE_UCAST; |
| 1405 | if (options & BWF) |
| 1406 | wolopts |= WAKE_BCAST; |
| 1407 | if (options & MWF) |
| 1408 | wolopts |= WAKE_MCAST; |
| 1409 | |
| 1410 | return wolopts; |
| 1411 | } |
| 1412 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1413 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1414 | { |
| 1415 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1416 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1417 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1418 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1419 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1420 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1423 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1424 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1425 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1426 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1427 | u32 opt; |
| 1428 | u16 reg; |
| 1429 | u8 mask; |
| 1430 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1431 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1432 | { WAKE_UCAST, Config5, UWF }, |
| 1433 | { WAKE_BCAST, Config5, BWF }, |
| 1434 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1435 | { WAKE_ANY, Config5, LanWake }, |
| 1436 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1437 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1438 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1439 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1440 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1441 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1442 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1443 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1444 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1445 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1446 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1447 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1448 | 0x0dc, |
| 1449 | ERIAR_MASK_0100, |
| 1450 | MagicPacket_v2, |
| 1451 | 0x0000, |
| 1452 | ERIAR_EXGMAC); |
| 1453 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1454 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1455 | 0x0dc, |
| 1456 | ERIAR_MASK_0100, |
| 1457 | 0x0000, |
| 1458 | MagicPacket_v2, |
| 1459 | ERIAR_EXGMAC); |
| 1460 | break; |
| 1461 | default: |
| 1462 | tmp = ARRAY_SIZE(cfg); |
| 1463 | break; |
| 1464 | } |
| 1465 | |
| 1466 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1467 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1468 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1469 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1470 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1473 | switch (tp->mac_version) { |
| 1474 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1475 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1476 | if (wolopts) |
| 1477 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1478 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1479 | break; |
| 1480 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1481 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1482 | if (wolopts) |
| 1483 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1484 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1485 | break; |
| 1486 | } |
| 1487 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1488 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1492 | { |
| 1493 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1494 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1495 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1496 | if (wol->wolopts & ~WAKE_ANY) |
| 1497 | return -EINVAL; |
| 1498 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1499 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1500 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1501 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1502 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1503 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1504 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1505 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1506 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1507 | |
| 1508 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1509 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1510 | device_set_wakeup_enable(d, tp->saved_wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1511 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1512 | pm_runtime_put_noidle(d); |
| 1513 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1514 | return 0; |
| 1515 | } |
| 1516 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1517 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1518 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1519 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1520 | } |
| 1521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1523 | struct ethtool_drvinfo *info) |
| 1524 | { |
| 1525 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1526 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1528 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1529 | 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] | 1530 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1531 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1532 | strlcpy(info->fw_version, rtl_fw->version, |
| 1533 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1537 | { |
| 1538 | return R8169_REGS_SIZE; |
| 1539 | } |
| 1540 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1541 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1542 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1544 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1545 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1546 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1547 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1549 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1550 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1551 | features &= ~NETIF_F_IP_CSUM; |
| 1552 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1553 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1556 | static int rtl8169_set_features(struct net_device *dev, |
| 1557 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { |
| 1559 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1560 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1562 | rtl_lock_work(tp); |
| 1563 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1564 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1565 | if (features & NETIF_F_RXALL) |
| 1566 | rx_config |= (AcceptErr | AcceptRunt); |
| 1567 | else |
| 1568 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1570 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1571 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1572 | if (features & NETIF_F_RXCSUM) |
| 1573 | tp->cp_cmd |= RxChkSum; |
| 1574 | else |
| 1575 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1576 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1577 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1578 | tp->cp_cmd |= RxVlan; |
| 1579 | else |
| 1580 | tp->cp_cmd &= ~RxVlan; |
| 1581 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1582 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1583 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1585 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1590 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1592 | return (skb_vlan_tag_present(skb)) ? |
| 1593 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1596 | 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] | 1597 | { |
| 1598 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1600 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1601 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1605 | void *p) |
| 1606 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1607 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1608 | u32 __iomem *data = tp->mmio_addr; |
| 1609 | u32 *dw = p; |
| 1610 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1612 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1613 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1614 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1615 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1618 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1619 | { |
| 1620 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1621 | |
| 1622 | return tp->msg_enable; |
| 1623 | } |
| 1624 | |
| 1625 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1626 | { |
| 1627 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1628 | |
| 1629 | tp->msg_enable = value; |
| 1630 | } |
| 1631 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1632 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1633 | "tx_packets", |
| 1634 | "rx_packets", |
| 1635 | "tx_errors", |
| 1636 | "rx_errors", |
| 1637 | "rx_missed", |
| 1638 | "align_errors", |
| 1639 | "tx_single_collisions", |
| 1640 | "tx_multi_collisions", |
| 1641 | "unicast", |
| 1642 | "broadcast", |
| 1643 | "multicast", |
| 1644 | "tx_aborted", |
| 1645 | "tx_underrun", |
| 1646 | }; |
| 1647 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1648 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1649 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1650 | switch (sset) { |
| 1651 | case ETH_SS_STATS: |
| 1652 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1653 | default: |
| 1654 | return -EOPNOTSUPP; |
| 1655 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1656 | } |
| 1657 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1658 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1659 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1660 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1661 | } |
| 1662 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1663 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1664 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1665 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1666 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1667 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1668 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1669 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1670 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1671 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1672 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1673 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1674 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1675 | } |
| 1676 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1677 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1678 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1679 | /* |
| 1680 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1681 | * tally counters. |
| 1682 | */ |
| 1683 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1684 | return true; |
| 1685 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1686 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1687 | } |
| 1688 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1689 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1690 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1691 | /* |
| 1692 | * Some chips are unable to dump tally counters when the receiver |
| 1693 | * is disabled. |
| 1694 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1695 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1696 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1697 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1698 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1699 | } |
| 1700 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1701 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1702 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1703 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1704 | bool ret = false; |
| 1705 | |
| 1706 | /* |
| 1707 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1708 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1709 | * reset by a power cycle, while the counter values collected by the |
| 1710 | * driver are reset at every driver unload/load cycle. |
| 1711 | * |
| 1712 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1713 | * values, we collect the initial values at first open(*) and use them |
| 1714 | * as offsets to normalize the values returned by @get_stats64. |
| 1715 | * |
| 1716 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1717 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1718 | * set at open time by rtl_hw_start. |
| 1719 | */ |
| 1720 | |
| 1721 | if (tp->tc_offset.inited) |
| 1722 | return true; |
| 1723 | |
| 1724 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1725 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1726 | ret = true; |
| 1727 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1728 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1729 | ret = true; |
| 1730 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1731 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1732 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1733 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1734 | tp->tc_offset.inited = true; |
| 1735 | |
| 1736 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1739 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1740 | struct ethtool_stats *stats, u64 *data) |
| 1741 | { |
| 1742 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1743 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1744 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1745 | |
| 1746 | ASSERT_RTNL(); |
| 1747 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1748 | pm_runtime_get_noresume(d); |
| 1749 | |
| 1750 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1751 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1752 | |
| 1753 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1754 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1755 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1756 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1757 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1758 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1759 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1760 | data[5] = le16_to_cpu(counters->align_errors); |
| 1761 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1762 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1763 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1764 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1765 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1766 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1767 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1770 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1771 | { |
| 1772 | switch(stringset) { |
| 1773 | case ETH_SS_STATS: |
| 1774 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1775 | break; |
| 1776 | } |
| 1777 | } |
| 1778 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1779 | /* |
| 1780 | * Interrupt coalescing |
| 1781 | * |
| 1782 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1783 | * > 8169, 8168 and 810x line of chipsets |
| 1784 | * |
| 1785 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1786 | * |
| 1787 | * > 2 - the Tx timer unit at gigabit speed |
| 1788 | * |
| 1789 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1790 | * (0xe0) bit 1 and bit 0. |
| 1791 | * |
| 1792 | * For 8169 |
| 1793 | * bit[1:0] \ speed 1000M 100M 10M |
| 1794 | * 0 0 320ns 2.56us 40.96us |
| 1795 | * 0 1 2.56us 20.48us 327.7us |
| 1796 | * 1 0 5.12us 40.96us 655.4us |
| 1797 | * 1 1 10.24us 81.92us 1.31ms |
| 1798 | * |
| 1799 | * For the other |
| 1800 | * bit[1:0] \ speed 1000M 100M 10M |
| 1801 | * 0 0 5us 2.56us 40.96us |
| 1802 | * 0 1 40us 20.48us 327.7us |
| 1803 | * 1 0 80us 40.96us 655.4us |
| 1804 | * 1 1 160us 81.92us 1.31ms |
| 1805 | */ |
| 1806 | |
| 1807 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1808 | struct rtl_coalesce_scale { |
| 1809 | /* Rx / Tx */ |
| 1810 | u32 nsecs[2]; |
| 1811 | }; |
| 1812 | |
| 1813 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1814 | struct rtl_coalesce_info { |
| 1815 | u32 speed; |
| 1816 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1817 | }; |
| 1818 | |
| 1819 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1820 | #define rxtx_x1822(r, t) { \ |
| 1821 | {{(r), (t)}}, \ |
| 1822 | {{(r)*8, (t)*8}}, \ |
| 1823 | {{(r)*8*2, (t)*8*2}}, \ |
| 1824 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1825 | } |
| 1826 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1827 | /* speed delays: rx00 tx00 */ |
| 1828 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1829 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1830 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1831 | { 0 }, |
| 1832 | }; |
| 1833 | |
| 1834 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1835 | /* speed delays: rx00 tx00 */ |
| 1836 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1837 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1838 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1839 | { 0 }, |
| 1840 | }; |
| 1841 | #undef rxtx_x1822 |
| 1842 | |
| 1843 | /* get rx/tx scale vector corresponding to current speed */ |
| 1844 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1845 | { |
| 1846 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1847 | struct ethtool_link_ksettings ecmd; |
| 1848 | const struct rtl_coalesce_info *ci; |
| 1849 | int rc; |
| 1850 | |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 1851 | rc = phy_ethtool_get_link_ksettings(dev, &ecmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1852 | if (rc < 0) |
| 1853 | return ERR_PTR(rc); |
| 1854 | |
| 1855 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 1856 | if (ecmd.base.speed == ci->speed) { |
| 1857 | return ci; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | return ERR_PTR(-ELNRNG); |
| 1862 | } |
| 1863 | |
| 1864 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1865 | { |
| 1866 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1867 | const struct rtl_coalesce_info *ci; |
| 1868 | const struct rtl_coalesce_scale *scale; |
| 1869 | struct { |
| 1870 | u32 *max_frames; |
| 1871 | u32 *usecs; |
| 1872 | } coal_settings [] = { |
| 1873 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1874 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1875 | }, *p = coal_settings; |
| 1876 | int i; |
| 1877 | u16 w; |
| 1878 | |
| 1879 | memset(ec, 0, sizeof(*ec)); |
| 1880 | |
| 1881 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1882 | ci = rtl_coalesce_info(dev); |
| 1883 | if (IS_ERR(ci)) |
| 1884 | return PTR_ERR(ci); |
| 1885 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1886 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1887 | |
| 1888 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1889 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1890 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1891 | w >>= RTL_COALESCE_SHIFT; |
| 1892 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1893 | } |
| 1894 | |
| 1895 | for (i = 0; i < 2; i++) { |
| 1896 | p = coal_settings + i; |
| 1897 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1898 | |
| 1899 | /* |
| 1900 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1901 | * max_frames to 0. |
| 1902 | */ |
| 1903 | if (!*p->usecs && !*p->max_frames) |
| 1904 | *p->max_frames = 1; |
| 1905 | } |
| 1906 | |
| 1907 | return 0; |
| 1908 | } |
| 1909 | |
| 1910 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1911 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1912 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1913 | { |
| 1914 | const struct rtl_coalesce_info *ci; |
| 1915 | u16 i; |
| 1916 | |
| 1917 | ci = rtl_coalesce_info(dev); |
| 1918 | if (IS_ERR(ci)) |
| 1919 | return ERR_CAST(ci); |
| 1920 | |
| 1921 | for (i = 0; i < 4; i++) { |
| 1922 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1923 | ci->scalev[i].nsecs[1]); |
| 1924 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1925 | *cp01 = i; |
| 1926 | return &ci->scalev[i]; |
| 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | return ERR_PTR(-EINVAL); |
| 1931 | } |
| 1932 | |
| 1933 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1934 | { |
| 1935 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1936 | const struct rtl_coalesce_scale *scale; |
| 1937 | struct { |
| 1938 | u32 frames; |
| 1939 | u32 usecs; |
| 1940 | } coal_settings [] = { |
| 1941 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1942 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1943 | }, *p = coal_settings; |
| 1944 | u16 w = 0, cp01; |
| 1945 | int i; |
| 1946 | |
| 1947 | scale = rtl_coalesce_choose_scale(dev, |
| 1948 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1949 | if (IS_ERR(scale)) |
| 1950 | return PTR_ERR(scale); |
| 1951 | |
| 1952 | for (i = 0; i < 2; i++, p++) { |
| 1953 | u32 units; |
| 1954 | |
| 1955 | /* |
| 1956 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1957 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1958 | * |
| 1959 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 1960 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 1961 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 1962 | * |
| 1963 | * since ethtool sends to kernel whole ethtool_coalesce |
| 1964 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 1965 | * we'll reject it below in `frames % 4 != 0`. |
| 1966 | */ |
| 1967 | if (p->frames == 1) { |
| 1968 | p->frames = 0; |
| 1969 | } |
| 1970 | |
| 1971 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 1972 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 1973 | return -EINVAL; |
| 1974 | |
| 1975 | w <<= RTL_COALESCE_SHIFT; |
| 1976 | w |= units; |
| 1977 | w <<= RTL_COALESCE_SHIFT; |
| 1978 | w |= p->frames >> 2; |
| 1979 | } |
| 1980 | |
| 1981 | rtl_lock_work(tp); |
| 1982 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1983 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1984 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 1985 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1986 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1987 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1988 | |
| 1989 | rtl_unlock_work(tp); |
| 1990 | |
| 1991 | return 0; |
| 1992 | } |
| 1993 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1994 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | .get_drvinfo = rtl8169_get_drvinfo, |
| 1996 | .get_regs_len = rtl8169_get_regs_len, |
| 1997 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1998 | .get_coalesce = rtl_get_coalesce, |
| 1999 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2000 | .get_msglevel = rtl8169_get_msglevel, |
| 2001 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2003 | .get_wol = rtl8169_get_wol, |
| 2004 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2005 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2006 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2007 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2008 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2009 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2010 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2011 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | }; |
| 2013 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2014 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2015 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2017 | /* |
| 2018 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2019 | * but they can be identified more specifically through the test below |
| 2020 | * if needed: |
| 2021 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2022 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2023 | * |
| 2024 | * Same thing for the 8101Eb and the 8101Ec: |
| 2025 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2026 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2027 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2028 | static const struct rtl_mac_info { |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2029 | u16 mask; |
| 2030 | u16 val; |
| 2031 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2033 | /* 8168EP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2034 | { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51 }, |
| 2035 | { 0x7cf, 0x501, RTL_GIGA_MAC_VER_50 }, |
| 2036 | { 0x7cf, 0x500, RTL_GIGA_MAC_VER_49 }, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2037 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2038 | /* 8168H family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2039 | { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46 }, |
| 2040 | { 0x7cf, 0x540, RTL_GIGA_MAC_VER_45 }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2041 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2042 | /* 8168G family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2043 | { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44 }, |
| 2044 | { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42 }, |
| 2045 | { 0x7cf, 0x4c1, RTL_GIGA_MAC_VER_41 }, |
| 2046 | { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2047 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2048 | /* 8168F family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2049 | { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38 }, |
| 2050 | { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36 }, |
| 2051 | { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2052 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2053 | /* 8168E family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2054 | { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34 }, |
| 2055 | { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32 }, |
| 2056 | { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2057 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2058 | /* 8168D family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2059 | { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25 }, |
| 2060 | { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2061 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2062 | /* 8168DP family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2063 | { 0x7cf, 0x288, RTL_GIGA_MAC_VER_27 }, |
| 2064 | { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28 }, |
| 2065 | { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2066 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2067 | /* 8168C family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2068 | { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23 }, |
| 2069 | { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18 }, |
| 2070 | { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24 }, |
| 2071 | { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19 }, |
| 2072 | { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20 }, |
| 2073 | { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21 }, |
| 2074 | { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2075 | |
| 2076 | /* 8168B family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2077 | { 0x7cf, 0x380, RTL_GIGA_MAC_VER_12 }, |
| 2078 | { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17 }, |
| 2079 | { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2080 | |
| 2081 | /* 8101 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2082 | { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39 }, |
| 2083 | { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37 }, |
| 2084 | { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29 }, |
| 2085 | { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30 }, |
| 2086 | { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08 }, |
| 2087 | { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08 }, |
| 2088 | { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07 }, |
| 2089 | { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07 }, |
| 2090 | { 0x7cf, 0x340, RTL_GIGA_MAC_VER_13 }, |
| 2091 | { 0x7cf, 0x343, RTL_GIGA_MAC_VER_10 }, |
| 2092 | { 0x7cf, 0x342, RTL_GIGA_MAC_VER_16 }, |
| 2093 | { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09 }, |
| 2094 | { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09 }, |
| 2095 | { 0x7c8, 0x340, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2096 | /* FIXME: where did these entries come from ? -- FR */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2097 | { 0xfc8, 0x388, RTL_GIGA_MAC_VER_15 }, |
| 2098 | { 0xfc8, 0x308, RTL_GIGA_MAC_VER_14 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2099 | |
| 2100 | /* 8110 family. */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2101 | { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06 }, |
| 2102 | { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05 }, |
| 2103 | { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04 }, |
| 2104 | { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03 }, |
| 2105 | { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02 }, |
| 2106 | { 0xfc8, 0x000, RTL_GIGA_MAC_VER_01 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2107 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2108 | /* Catch-all */ |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2109 | { 0x000, 0x000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2110 | }; |
| 2111 | const struct rtl_mac_info *p = mac_info; |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 2112 | u16 reg = RTL_R32(tp, TxConfig) >> 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2114 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | p++; |
| 2116 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2117 | |
| 2118 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2119 | dev_notice(tp_to_dev(tp), |
| 2120 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2121 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2122 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2123 | tp->mac_version = tp->supports_gmii ? |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2124 | RTL_GIGA_MAC_VER_42 : |
| 2125 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2126 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2127 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2128 | RTL_GIGA_MAC_VER_45 : |
| 2129 | RTL_GIGA_MAC_VER_47; |
| 2130 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2131 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2132 | RTL_GIGA_MAC_VER_46 : |
| 2133 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2137 | struct phy_reg { |
| 2138 | u16 reg; |
| 2139 | u16 val; |
| 2140 | }; |
| 2141 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2142 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2143 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2144 | { |
| 2145 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2146 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2147 | regs++; |
| 2148 | } |
| 2149 | } |
| 2150 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2151 | #define PHY_READ 0x00000000 |
| 2152 | #define PHY_DATA_OR 0x10000000 |
| 2153 | #define PHY_DATA_AND 0x20000000 |
| 2154 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2155 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2156 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2157 | #define PHY_WRITE 0x80000000 |
| 2158 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2159 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2160 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2161 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2162 | #define PHY_SKIPN 0xd0000000 |
| 2163 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2164 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2165 | struct fw_info { |
| 2166 | u32 magic; |
| 2167 | char version[RTL_VER_SIZE]; |
| 2168 | __le32 fw_start; |
| 2169 | __le32 fw_len; |
| 2170 | u8 chksum; |
| 2171 | } __packed; |
| 2172 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2173 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2174 | |
| 2175 | 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] | 2176 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2177 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2178 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2179 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2180 | char *version = rtl_fw->version; |
| 2181 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2182 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2183 | if (fw->size < FW_OPCODE_SIZE) |
| 2184 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2185 | |
| 2186 | if (!fw_info->magic) { |
| 2187 | size_t i, size, start; |
| 2188 | u8 checksum = 0; |
| 2189 | |
| 2190 | if (fw->size < sizeof(*fw_info)) |
| 2191 | goto out; |
| 2192 | |
| 2193 | for (i = 0; i < fw->size; i++) |
| 2194 | checksum += fw->data[i]; |
| 2195 | if (checksum != 0) |
| 2196 | goto out; |
| 2197 | |
| 2198 | start = le32_to_cpu(fw_info->fw_start); |
| 2199 | if (start > fw->size) |
| 2200 | goto out; |
| 2201 | |
| 2202 | size = le32_to_cpu(fw_info->fw_len); |
| 2203 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2204 | goto out; |
| 2205 | |
| 2206 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2207 | |
| 2208 | pa->code = (__le32 *)(fw->data + start); |
| 2209 | pa->size = size; |
| 2210 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2211 | if (fw->size % FW_OPCODE_SIZE) |
| 2212 | goto out; |
| 2213 | |
| 2214 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2215 | |
| 2216 | pa->code = (__le32 *)fw->data; |
| 2217 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2218 | } |
| 2219 | version[RTL_VER_SIZE - 1] = 0; |
| 2220 | |
| 2221 | rc = true; |
| 2222 | out: |
| 2223 | return rc; |
| 2224 | } |
| 2225 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2226 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2227 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2228 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2229 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2230 | size_t index; |
| 2231 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2232 | for (index = 0; index < pa->size; index++) { |
| 2233 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2234 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2235 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2236 | switch(action & 0xf0000000) { |
| 2237 | case PHY_READ: |
| 2238 | case PHY_DATA_OR: |
| 2239 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2240 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2241 | case PHY_CLEAR_READCOUNT: |
| 2242 | case PHY_WRITE: |
| 2243 | case PHY_WRITE_PREVIOUS: |
| 2244 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2245 | break; |
| 2246 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2247 | case PHY_BJMPN: |
| 2248 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2249 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2250 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2251 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2252 | } |
| 2253 | break; |
| 2254 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2255 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2256 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2257 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2258 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2259 | } |
| 2260 | break; |
| 2261 | case PHY_COMP_EQ_SKIPN: |
| 2262 | case PHY_COMP_NEQ_SKIPN: |
| 2263 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2264 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2265 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2266 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2267 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2268 | } |
| 2269 | break; |
| 2270 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2271 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2272 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2273 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2274 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2275 | } |
| 2276 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2277 | rc = true; |
| 2278 | out: |
| 2279 | return rc; |
| 2280 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2281 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2282 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2283 | { |
| 2284 | struct net_device *dev = tp->dev; |
| 2285 | int rc = -EINVAL; |
| 2286 | |
| 2287 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2288 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2289 | goto out; |
| 2290 | } |
| 2291 | |
| 2292 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2293 | rc = 0; |
| 2294 | out: |
| 2295 | return rc; |
| 2296 | } |
| 2297 | |
| 2298 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2299 | { |
| 2300 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2301 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2302 | u32 predata, count; |
| 2303 | size_t index; |
| 2304 | |
| 2305 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2306 | org.write = ops->write; |
| 2307 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2308 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2309 | for (index = 0; index < pa->size; ) { |
| 2310 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2311 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2312 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2313 | |
| 2314 | if (!action) |
| 2315 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2316 | |
| 2317 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2318 | case PHY_READ: |
| 2319 | predata = rtl_readphy(tp, regno); |
| 2320 | count++; |
| 2321 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2322 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2323 | case PHY_DATA_OR: |
| 2324 | predata |= data; |
| 2325 | index++; |
| 2326 | break; |
| 2327 | case PHY_DATA_AND: |
| 2328 | predata &= data; |
| 2329 | index++; |
| 2330 | break; |
| 2331 | case PHY_BJMPN: |
| 2332 | index -= regno; |
| 2333 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2334 | case PHY_MDIO_CHG: |
| 2335 | if (data == 0) { |
| 2336 | ops->write = org.write; |
| 2337 | ops->read = org.read; |
| 2338 | } else if (data == 1) { |
| 2339 | ops->write = mac_mcu_write; |
| 2340 | ops->read = mac_mcu_read; |
| 2341 | } |
| 2342 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2343 | index++; |
| 2344 | break; |
| 2345 | case PHY_CLEAR_READCOUNT: |
| 2346 | count = 0; |
| 2347 | index++; |
| 2348 | break; |
| 2349 | case PHY_WRITE: |
| 2350 | rtl_writephy(tp, regno, data); |
| 2351 | index++; |
| 2352 | break; |
| 2353 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2354 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2355 | break; |
| 2356 | case PHY_COMP_EQ_SKIPN: |
| 2357 | if (predata == data) |
| 2358 | index += regno; |
| 2359 | index++; |
| 2360 | break; |
| 2361 | case PHY_COMP_NEQ_SKIPN: |
| 2362 | if (predata != data) |
| 2363 | index += regno; |
| 2364 | index++; |
| 2365 | break; |
| 2366 | case PHY_WRITE_PREVIOUS: |
| 2367 | rtl_writephy(tp, regno, predata); |
| 2368 | index++; |
| 2369 | break; |
| 2370 | case PHY_SKIPN: |
| 2371 | index += regno + 1; |
| 2372 | break; |
| 2373 | case PHY_DELAY_MS: |
| 2374 | mdelay(data); |
| 2375 | index++; |
| 2376 | break; |
| 2377 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2378 | default: |
| 2379 | BUG(); |
| 2380 | } |
| 2381 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2382 | |
| 2383 | ops->write = org.write; |
| 2384 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2387 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2388 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2389 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2390 | release_firmware(tp->rtl_fw->fw); |
| 2391 | kfree(tp->rtl_fw); |
| 2392 | } |
| 2393 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2396 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2397 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2398 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2399 | |
| 2400 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2401 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2402 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2406 | { |
| 2407 | if (rtl_readphy(tp, reg) != val) |
| 2408 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2409 | else |
| 2410 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2413 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2415 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2416 | { 0x1f, 0x0001 }, |
| 2417 | { 0x06, 0x006e }, |
| 2418 | { 0x08, 0x0708 }, |
| 2419 | { 0x15, 0x4000 }, |
| 2420 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2422 | { 0x1f, 0x0001 }, |
| 2423 | { 0x03, 0x00a1 }, |
| 2424 | { 0x02, 0x0008 }, |
| 2425 | { 0x01, 0x0120 }, |
| 2426 | { 0x00, 0x1000 }, |
| 2427 | { 0x04, 0x0800 }, |
| 2428 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2430 | { 0x03, 0xff41 }, |
| 2431 | { 0x02, 0xdf60 }, |
| 2432 | { 0x01, 0x0140 }, |
| 2433 | { 0x00, 0x0077 }, |
| 2434 | { 0x04, 0x7800 }, |
| 2435 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2437 | { 0x03, 0x802f }, |
| 2438 | { 0x02, 0x4f02 }, |
| 2439 | { 0x01, 0x0409 }, |
| 2440 | { 0x00, 0xf0f9 }, |
| 2441 | { 0x04, 0x9800 }, |
| 2442 | { 0x04, 0x9000 }, |
| 2443 | |
| 2444 | { 0x03, 0xdf01 }, |
| 2445 | { 0x02, 0xdf20 }, |
| 2446 | { 0x01, 0xff95 }, |
| 2447 | { 0x00, 0xba00 }, |
| 2448 | { 0x04, 0xa800 }, |
| 2449 | { 0x04, 0xa000 }, |
| 2450 | |
| 2451 | { 0x03, 0xff41 }, |
| 2452 | { 0x02, 0xdf20 }, |
| 2453 | { 0x01, 0x0140 }, |
| 2454 | { 0x00, 0x00bb }, |
| 2455 | { 0x04, 0xb800 }, |
| 2456 | { 0x04, 0xb000 }, |
| 2457 | |
| 2458 | { 0x03, 0xdf41 }, |
| 2459 | { 0x02, 0xdc60 }, |
| 2460 | { 0x01, 0x6340 }, |
| 2461 | { 0x00, 0x007d }, |
| 2462 | { 0x04, 0xd800 }, |
| 2463 | { 0x04, 0xd000 }, |
| 2464 | |
| 2465 | { 0x03, 0xdf01 }, |
| 2466 | { 0x02, 0xdf20 }, |
| 2467 | { 0x01, 0x100a }, |
| 2468 | { 0x00, 0xa0ff }, |
| 2469 | { 0x04, 0xf800 }, |
| 2470 | { 0x04, 0xf000 }, |
| 2471 | |
| 2472 | { 0x1f, 0x0000 }, |
| 2473 | { 0x0b, 0x0000 }, |
| 2474 | { 0x00, 0x9200 } |
| 2475 | }; |
| 2476 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2477 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2480 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2481 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2482 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2483 | { 0x1f, 0x0002 }, |
| 2484 | { 0x01, 0x90d0 }, |
| 2485 | { 0x1f, 0x0000 } |
| 2486 | }; |
| 2487 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2488 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2491 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2492 | { |
| 2493 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2494 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2495 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2496 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2497 | return; |
| 2498 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2499 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2500 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2501 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2504 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2505 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2506 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2507 | { 0x1f, 0x0001 }, |
| 2508 | { 0x04, 0x0000 }, |
| 2509 | { 0x03, 0x00a1 }, |
| 2510 | { 0x02, 0x0008 }, |
| 2511 | { 0x01, 0x0120 }, |
| 2512 | { 0x00, 0x1000 }, |
| 2513 | { 0x04, 0x0800 }, |
| 2514 | { 0x04, 0x9000 }, |
| 2515 | { 0x03, 0x802f }, |
| 2516 | { 0x02, 0x4f02 }, |
| 2517 | { 0x01, 0x0409 }, |
| 2518 | { 0x00, 0xf099 }, |
| 2519 | { 0x04, 0x9800 }, |
| 2520 | { 0x04, 0xa000 }, |
| 2521 | { 0x03, 0xdf01 }, |
| 2522 | { 0x02, 0xdf20 }, |
| 2523 | { 0x01, 0xff95 }, |
| 2524 | { 0x00, 0xba00 }, |
| 2525 | { 0x04, 0xa800 }, |
| 2526 | { 0x04, 0xf000 }, |
| 2527 | { 0x03, 0xdf01 }, |
| 2528 | { 0x02, 0xdf20 }, |
| 2529 | { 0x01, 0x101a }, |
| 2530 | { 0x00, 0xa0ff }, |
| 2531 | { 0x04, 0xf800 }, |
| 2532 | { 0x04, 0x0000 }, |
| 2533 | { 0x1f, 0x0000 }, |
| 2534 | |
| 2535 | { 0x1f, 0x0001 }, |
| 2536 | { 0x10, 0xf41b }, |
| 2537 | { 0x14, 0xfb54 }, |
| 2538 | { 0x18, 0xf5c7 }, |
| 2539 | { 0x1f, 0x0000 }, |
| 2540 | |
| 2541 | { 0x1f, 0x0001 }, |
| 2542 | { 0x17, 0x0cc0 }, |
| 2543 | { 0x1f, 0x0000 } |
| 2544 | }; |
| 2545 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2546 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2547 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2548 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2551 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2552 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2553 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2554 | { 0x1f, 0x0001 }, |
| 2555 | { 0x04, 0x0000 }, |
| 2556 | { 0x03, 0x00a1 }, |
| 2557 | { 0x02, 0x0008 }, |
| 2558 | { 0x01, 0x0120 }, |
| 2559 | { 0x00, 0x1000 }, |
| 2560 | { 0x04, 0x0800 }, |
| 2561 | { 0x04, 0x9000 }, |
| 2562 | { 0x03, 0x802f }, |
| 2563 | { 0x02, 0x4f02 }, |
| 2564 | { 0x01, 0x0409 }, |
| 2565 | { 0x00, 0xf099 }, |
| 2566 | { 0x04, 0x9800 }, |
| 2567 | { 0x04, 0xa000 }, |
| 2568 | { 0x03, 0xdf01 }, |
| 2569 | { 0x02, 0xdf20 }, |
| 2570 | { 0x01, 0xff95 }, |
| 2571 | { 0x00, 0xba00 }, |
| 2572 | { 0x04, 0xa800 }, |
| 2573 | { 0x04, 0xf000 }, |
| 2574 | { 0x03, 0xdf01 }, |
| 2575 | { 0x02, 0xdf20 }, |
| 2576 | { 0x01, 0x101a }, |
| 2577 | { 0x00, 0xa0ff }, |
| 2578 | { 0x04, 0xf800 }, |
| 2579 | { 0x04, 0x0000 }, |
| 2580 | { 0x1f, 0x0000 }, |
| 2581 | |
| 2582 | { 0x1f, 0x0001 }, |
| 2583 | { 0x0b, 0x8480 }, |
| 2584 | { 0x1f, 0x0000 }, |
| 2585 | |
| 2586 | { 0x1f, 0x0001 }, |
| 2587 | { 0x18, 0x67c7 }, |
| 2588 | { 0x04, 0x2000 }, |
| 2589 | { 0x03, 0x002f }, |
| 2590 | { 0x02, 0x4360 }, |
| 2591 | { 0x01, 0x0109 }, |
| 2592 | { 0x00, 0x3022 }, |
| 2593 | { 0x04, 0x2800 }, |
| 2594 | { 0x1f, 0x0000 }, |
| 2595 | |
| 2596 | { 0x1f, 0x0001 }, |
| 2597 | { 0x17, 0x0cc0 }, |
| 2598 | { 0x1f, 0x0000 } |
| 2599 | }; |
| 2600 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2601 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2604 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2605 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2606 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2607 | { 0x10, 0xf41b }, |
| 2608 | { 0x1f, 0x0000 } |
| 2609 | }; |
| 2610 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2611 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2612 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2613 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2614 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2615 | } |
| 2616 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2617 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2618 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2619 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2620 | { 0x1f, 0x0001 }, |
| 2621 | { 0x10, 0xf41b }, |
| 2622 | { 0x1f, 0x0000 } |
| 2623 | }; |
| 2624 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2625 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2626 | } |
| 2627 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2628 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2629 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2630 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2631 | { 0x1f, 0x0000 }, |
| 2632 | { 0x1d, 0x0f00 }, |
| 2633 | { 0x1f, 0x0002 }, |
| 2634 | { 0x0c, 0x1ec8 }, |
| 2635 | { 0x1f, 0x0000 } |
| 2636 | }; |
| 2637 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2638 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2639 | } |
| 2640 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2641 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2642 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2643 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2644 | { 0x1f, 0x0001 }, |
| 2645 | { 0x1d, 0x3d98 }, |
| 2646 | { 0x1f, 0x0000 } |
| 2647 | }; |
| 2648 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2649 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2650 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2651 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2652 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2653 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2654 | } |
| 2655 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2656 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2657 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2658 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2659 | { 0x1f, 0x0001 }, |
| 2660 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2661 | { 0x1f, 0x0002 }, |
| 2662 | { 0x00, 0x88d4 }, |
| 2663 | { 0x01, 0x82b1 }, |
| 2664 | { 0x03, 0x7002 }, |
| 2665 | { 0x08, 0x9e30 }, |
| 2666 | { 0x09, 0x01f0 }, |
| 2667 | { 0x0a, 0x5500 }, |
| 2668 | { 0x0c, 0x00c8 }, |
| 2669 | { 0x1f, 0x0003 }, |
| 2670 | { 0x12, 0xc096 }, |
| 2671 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2672 | { 0x1f, 0x0000 }, |
| 2673 | { 0x1f, 0x0000 }, |
| 2674 | { 0x09, 0x2000 }, |
| 2675 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2676 | }; |
| 2677 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2678 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2679 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2680 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2681 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2682 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2683 | } |
| 2684 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2685 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2686 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2687 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2688 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2689 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2690 | { 0x03, 0x802f }, |
| 2691 | { 0x02, 0x4f02 }, |
| 2692 | { 0x01, 0x0409 }, |
| 2693 | { 0x00, 0xf099 }, |
| 2694 | { 0x04, 0x9800 }, |
| 2695 | { 0x04, 0x9000 }, |
| 2696 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2697 | { 0x1f, 0x0002 }, |
| 2698 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2699 | { 0x06, 0x0761 }, |
| 2700 | { 0x1f, 0x0003 }, |
| 2701 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2702 | { 0x1f, 0x0000 } |
| 2703 | }; |
| 2704 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2705 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2706 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2707 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2708 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2709 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2710 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2711 | } |
| 2712 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2713 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2714 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2715 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2716 | { 0x1f, 0x0001 }, |
| 2717 | { 0x12, 0x2300 }, |
| 2718 | { 0x1d, 0x3d98 }, |
| 2719 | { 0x1f, 0x0002 }, |
| 2720 | { 0x0c, 0x7eb8 }, |
| 2721 | { 0x06, 0x5461 }, |
| 2722 | { 0x1f, 0x0003 }, |
| 2723 | { 0x16, 0x0f0a }, |
| 2724 | { 0x1f, 0x0000 } |
| 2725 | }; |
| 2726 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2727 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2728 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2729 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2730 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2731 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2732 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2733 | } |
| 2734 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2735 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2736 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2737 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2738 | } |
| 2739 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2740 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2741 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2742 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2743 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2744 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2745 | { 0x06, 0x4064 }, |
| 2746 | { 0x07, 0x2863 }, |
| 2747 | { 0x08, 0x059c }, |
| 2748 | { 0x09, 0x26b4 }, |
| 2749 | { 0x0a, 0x6a19 }, |
| 2750 | { 0x0b, 0xdcc8 }, |
| 2751 | { 0x10, 0xf06d }, |
| 2752 | { 0x14, 0x7f68 }, |
| 2753 | { 0x18, 0x7fd9 }, |
| 2754 | { 0x1c, 0xf0ff }, |
| 2755 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2756 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2757 | { 0x12, 0xf49f }, |
| 2758 | { 0x13, 0x070b }, |
| 2759 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2760 | { 0x14, 0x94c0 }, |
| 2761 | |
| 2762 | /* |
| 2763 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2764 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2765 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2766 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2767 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2768 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2769 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2770 | { 0x06, 0x5561 }, |
| 2771 | |
| 2772 | /* |
| 2773 | * Can not link to 1Gbps with bad cable |
| 2774 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2775 | */ |
| 2776 | { 0x1f, 0x0001 }, |
| 2777 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2778 | |
| 2779 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2780 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2781 | }; |
| 2782 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2783 | rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2784 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2785 | /* |
| 2786 | * Rx Error Issue |
| 2787 | * Fine Tune Switching regulator parameter |
| 2788 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2789 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2790 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2791 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2792 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2793 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2794 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2795 | { 0x1f, 0x0002 }, |
| 2796 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2797 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2798 | { 0x05, 0x8330 }, |
| 2799 | { 0x06, 0x669a }, |
| 2800 | { 0x1f, 0x0002 } |
| 2801 | }; |
| 2802 | int val; |
| 2803 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2804 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2805 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2806 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2807 | |
| 2808 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2809 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2810 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2811 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2812 | }; |
| 2813 | int i; |
| 2814 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2815 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2816 | |
| 2817 | val &= 0xff00; |
| 2818 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2819 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2820 | } |
| 2821 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2822 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2823 | { 0x1f, 0x0002 }, |
| 2824 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2825 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2826 | { 0x05, 0x8330 }, |
| 2827 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2828 | }; |
| 2829 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2830 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2831 | } |
| 2832 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2833 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2834 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2835 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2836 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2837 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2838 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2839 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2840 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2841 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2842 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2843 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2844 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2845 | |
| 2846 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2847 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2848 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2851 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2852 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2853 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2854 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2855 | { 0x1f, 0x0001 }, |
| 2856 | { 0x06, 0x4064 }, |
| 2857 | { 0x07, 0x2863 }, |
| 2858 | { 0x08, 0x059c }, |
| 2859 | { 0x09, 0x26b4 }, |
| 2860 | { 0x0a, 0x6a19 }, |
| 2861 | { 0x0b, 0xdcc8 }, |
| 2862 | { 0x10, 0xf06d }, |
| 2863 | { 0x14, 0x7f68 }, |
| 2864 | { 0x18, 0x7fd9 }, |
| 2865 | { 0x1c, 0xf0ff }, |
| 2866 | { 0x1d, 0x3d9c }, |
| 2867 | { 0x1f, 0x0003 }, |
| 2868 | { 0x12, 0xf49f }, |
| 2869 | { 0x13, 0x070b }, |
| 2870 | { 0x1a, 0x05ad }, |
| 2871 | { 0x14, 0x94c0 }, |
| 2872 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2873 | /* |
| 2874 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2875 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2876 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2877 | { 0x1f, 0x0002 }, |
| 2878 | { 0x06, 0x5561 }, |
| 2879 | { 0x1f, 0x0005 }, |
| 2880 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2881 | { 0x06, 0x5561 }, |
| 2882 | |
| 2883 | /* |
| 2884 | * Can not link to 1Gbps with bad cable |
| 2885 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2886 | */ |
| 2887 | { 0x1f, 0x0001 }, |
| 2888 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2889 | |
| 2890 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2891 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2892 | }; |
| 2893 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2894 | rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2895 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2896 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2897 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2898 | { 0x1f, 0x0002 }, |
| 2899 | { 0x05, 0x669a }, |
| 2900 | { 0x1f, 0x0005 }, |
| 2901 | { 0x05, 0x8330 }, |
| 2902 | { 0x06, 0x669a }, |
| 2903 | |
| 2904 | { 0x1f, 0x0002 } |
| 2905 | }; |
| 2906 | int val; |
| 2907 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2908 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2909 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2910 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2911 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2912 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2913 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2914 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2915 | }; |
| 2916 | int i; |
| 2917 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2918 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2919 | |
| 2920 | val &= 0xff00; |
| 2921 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2922 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2923 | } |
| 2924 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2925 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2926 | { 0x1f, 0x0002 }, |
| 2927 | { 0x05, 0x2642 }, |
| 2928 | { 0x1f, 0x0005 }, |
| 2929 | { 0x05, 0x8330 }, |
| 2930 | { 0x06, 0x2642 } |
| 2931 | }; |
| 2932 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2933 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2934 | } |
| 2935 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2936 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2937 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2938 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2939 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2940 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2941 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2942 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2943 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2944 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2945 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2946 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2947 | |
| 2948 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2949 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2950 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2953 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2954 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2955 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2956 | { 0x1f, 0x0002 }, |
| 2957 | { 0x10, 0x0008 }, |
| 2958 | { 0x0d, 0x006c }, |
| 2959 | |
| 2960 | { 0x1f, 0x0000 }, |
| 2961 | { 0x0d, 0xf880 }, |
| 2962 | |
| 2963 | { 0x1f, 0x0001 }, |
| 2964 | { 0x17, 0x0cc0 }, |
| 2965 | |
| 2966 | { 0x1f, 0x0001 }, |
| 2967 | { 0x0b, 0xa4d8 }, |
| 2968 | { 0x09, 0x281c }, |
| 2969 | { 0x07, 0x2883 }, |
| 2970 | { 0x0a, 0x6b35 }, |
| 2971 | { 0x1d, 0x3da4 }, |
| 2972 | { 0x1c, 0xeffd }, |
| 2973 | { 0x14, 0x7f52 }, |
| 2974 | { 0x18, 0x7fc6 }, |
| 2975 | { 0x08, 0x0601 }, |
| 2976 | { 0x06, 0x4063 }, |
| 2977 | { 0x10, 0xf074 }, |
| 2978 | { 0x1f, 0x0003 }, |
| 2979 | { 0x13, 0x0789 }, |
| 2980 | { 0x12, 0xf4bd }, |
| 2981 | { 0x1a, 0x04fd }, |
| 2982 | { 0x14, 0x84b0 }, |
| 2983 | { 0x1f, 0x0000 }, |
| 2984 | { 0x00, 0x9200 }, |
| 2985 | |
| 2986 | { 0x1f, 0x0005 }, |
| 2987 | { 0x01, 0x0340 }, |
| 2988 | { 0x1f, 0x0001 }, |
| 2989 | { 0x04, 0x4000 }, |
| 2990 | { 0x03, 0x1d21 }, |
| 2991 | { 0x02, 0x0c32 }, |
| 2992 | { 0x01, 0x0200 }, |
| 2993 | { 0x00, 0x5554 }, |
| 2994 | { 0x04, 0x4800 }, |
| 2995 | { 0x04, 0x4000 }, |
| 2996 | { 0x04, 0xf000 }, |
| 2997 | { 0x03, 0xdf01 }, |
| 2998 | { 0x02, 0xdf20 }, |
| 2999 | { 0x01, 0x101a }, |
| 3000 | { 0x00, 0xa0ff }, |
| 3001 | { 0x04, 0xf800 }, |
| 3002 | { 0x04, 0xf000 }, |
| 3003 | { 0x1f, 0x0000 }, |
| 3004 | |
| 3005 | { 0x1f, 0x0007 }, |
| 3006 | { 0x1e, 0x0023 }, |
| 3007 | { 0x16, 0x0000 }, |
| 3008 | { 0x1f, 0x0000 } |
| 3009 | }; |
| 3010 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3011 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3012 | } |
| 3013 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3014 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3015 | { |
| 3016 | static const struct phy_reg phy_reg_init[] = { |
| 3017 | { 0x1f, 0x0001 }, |
| 3018 | { 0x17, 0x0cc0 }, |
| 3019 | |
| 3020 | { 0x1f, 0x0007 }, |
| 3021 | { 0x1e, 0x002d }, |
| 3022 | { 0x18, 0x0040 }, |
| 3023 | { 0x1f, 0x0000 } |
| 3024 | }; |
| 3025 | |
| 3026 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3027 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3028 | } |
| 3029 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3030 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3031 | { |
| 3032 | static const struct phy_reg phy_reg_init[] = { |
| 3033 | /* Enable Delay cap */ |
| 3034 | { 0x1f, 0x0005 }, |
| 3035 | { 0x05, 0x8b80 }, |
| 3036 | { 0x06, 0xc896 }, |
| 3037 | { 0x1f, 0x0000 }, |
| 3038 | |
| 3039 | /* Channel estimation fine tune */ |
| 3040 | { 0x1f, 0x0001 }, |
| 3041 | { 0x0b, 0x6c20 }, |
| 3042 | { 0x07, 0x2872 }, |
| 3043 | { 0x1c, 0xefff }, |
| 3044 | { 0x1f, 0x0003 }, |
| 3045 | { 0x14, 0x6420 }, |
| 3046 | { 0x1f, 0x0000 }, |
| 3047 | |
| 3048 | /* Update PFM & 10M TX idle timer */ |
| 3049 | { 0x1f, 0x0007 }, |
| 3050 | { 0x1e, 0x002f }, |
| 3051 | { 0x15, 0x1919 }, |
| 3052 | { 0x1f, 0x0000 }, |
| 3053 | |
| 3054 | { 0x1f, 0x0007 }, |
| 3055 | { 0x1e, 0x00ac }, |
| 3056 | { 0x18, 0x0006 }, |
| 3057 | { 0x1f, 0x0000 } |
| 3058 | }; |
| 3059 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3060 | rtl_apply_firmware(tp); |
| 3061 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3062 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3063 | |
| 3064 | /* DCO enable for 10M IDLE Power */ |
| 3065 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3066 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3067 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3068 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3069 | |
| 3070 | /* For impedance matching */ |
| 3071 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3072 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3073 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3074 | |
| 3075 | /* PHY auto speed down */ |
| 3076 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3077 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3078 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3079 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3080 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3081 | |
| 3082 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3083 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3084 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3085 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3086 | |
| 3087 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3088 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3089 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3090 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3091 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3092 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3093 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3094 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3095 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3096 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3097 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3098 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3099 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3100 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3101 | } |
| 3102 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3103 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3104 | { |
| 3105 | const u16 w[] = { |
| 3106 | addr[0] | (addr[1] << 8), |
| 3107 | addr[2] | (addr[3] << 8), |
| 3108 | addr[4] | (addr[5] << 8) |
| 3109 | }; |
| 3110 | const struct exgmac_reg e[] = { |
| 3111 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3112 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3113 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3114 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3115 | }; |
| 3116 | |
| 3117 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3118 | } |
| 3119 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3120 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3121 | { |
| 3122 | static const struct phy_reg phy_reg_init[] = { |
| 3123 | /* Enable Delay cap */ |
| 3124 | { 0x1f, 0x0004 }, |
| 3125 | { 0x1f, 0x0007 }, |
| 3126 | { 0x1e, 0x00ac }, |
| 3127 | { 0x18, 0x0006 }, |
| 3128 | { 0x1f, 0x0002 }, |
| 3129 | { 0x1f, 0x0000 }, |
| 3130 | { 0x1f, 0x0000 }, |
| 3131 | |
| 3132 | /* Channel estimation fine tune */ |
| 3133 | { 0x1f, 0x0003 }, |
| 3134 | { 0x09, 0xa20f }, |
| 3135 | { 0x1f, 0x0000 }, |
| 3136 | { 0x1f, 0x0000 }, |
| 3137 | |
| 3138 | /* Green Setting */ |
| 3139 | { 0x1f, 0x0005 }, |
| 3140 | { 0x05, 0x8b5b }, |
| 3141 | { 0x06, 0x9222 }, |
| 3142 | { 0x05, 0x8b6d }, |
| 3143 | { 0x06, 0x8000 }, |
| 3144 | { 0x05, 0x8b76 }, |
| 3145 | { 0x06, 0x8000 }, |
| 3146 | { 0x1f, 0x0000 } |
| 3147 | }; |
| 3148 | |
| 3149 | rtl_apply_firmware(tp); |
| 3150 | |
| 3151 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3152 | |
| 3153 | /* For 4-corner performance improve */ |
| 3154 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3155 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3156 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3157 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3158 | |
| 3159 | /* PHY auto speed down */ |
| 3160 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3161 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3162 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3163 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3164 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3165 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3166 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3167 | |
| 3168 | /* improve 10M EEE waveform */ |
| 3169 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3170 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3171 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3172 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3173 | |
| 3174 | /* Improve 2-pair detection performance */ |
| 3175 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3176 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3177 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3178 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3179 | |
| 3180 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3181 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3182 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3183 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3184 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3185 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3186 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3187 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3188 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3189 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3190 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3191 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3192 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3193 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3194 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3195 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3196 | |
| 3197 | /* Green feature */ |
| 3198 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3199 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3200 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3201 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3202 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3203 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3204 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3205 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3206 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3207 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3208 | } |
| 3209 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3210 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3211 | { |
| 3212 | /* For 4-corner performance improve */ |
| 3213 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3214 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3215 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3216 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3217 | |
| 3218 | /* PHY auto speed down */ |
| 3219 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3220 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3221 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3222 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3223 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3224 | |
| 3225 | /* Improve 10M EEE waveform */ |
| 3226 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3227 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3228 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3229 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3230 | } |
| 3231 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3232 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3233 | { |
| 3234 | static const struct phy_reg phy_reg_init[] = { |
| 3235 | /* Channel estimation fine tune */ |
| 3236 | { 0x1f, 0x0003 }, |
| 3237 | { 0x09, 0xa20f }, |
| 3238 | { 0x1f, 0x0000 }, |
| 3239 | |
| 3240 | /* Modify green table for giga & fnet */ |
| 3241 | { 0x1f, 0x0005 }, |
| 3242 | { 0x05, 0x8b55 }, |
| 3243 | { 0x06, 0x0000 }, |
| 3244 | { 0x05, 0x8b5e }, |
| 3245 | { 0x06, 0x0000 }, |
| 3246 | { 0x05, 0x8b67 }, |
| 3247 | { 0x06, 0x0000 }, |
| 3248 | { 0x05, 0x8b70 }, |
| 3249 | { 0x06, 0x0000 }, |
| 3250 | { 0x1f, 0x0000 }, |
| 3251 | { 0x1f, 0x0007 }, |
| 3252 | { 0x1e, 0x0078 }, |
| 3253 | { 0x17, 0x0000 }, |
| 3254 | { 0x19, 0x00fb }, |
| 3255 | { 0x1f, 0x0000 }, |
| 3256 | |
| 3257 | /* Modify green table for 10M */ |
| 3258 | { 0x1f, 0x0005 }, |
| 3259 | { 0x05, 0x8b79 }, |
| 3260 | { 0x06, 0xaa00 }, |
| 3261 | { 0x1f, 0x0000 }, |
| 3262 | |
| 3263 | /* Disable hiimpedance detection (RTCT) */ |
| 3264 | { 0x1f, 0x0003 }, |
| 3265 | { 0x01, 0x328a }, |
| 3266 | { 0x1f, 0x0000 } |
| 3267 | }; |
| 3268 | |
| 3269 | rtl_apply_firmware(tp); |
| 3270 | |
| 3271 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3272 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3273 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3274 | |
| 3275 | /* Improve 2-pair detection performance */ |
| 3276 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3277 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3278 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3279 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3280 | } |
| 3281 | |
| 3282 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3283 | { |
| 3284 | rtl_apply_firmware(tp); |
| 3285 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3286 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3287 | } |
| 3288 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3289 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3290 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3291 | static const struct phy_reg phy_reg_init[] = { |
| 3292 | /* Channel estimation fine tune */ |
| 3293 | { 0x1f, 0x0003 }, |
| 3294 | { 0x09, 0xa20f }, |
| 3295 | { 0x1f, 0x0000 }, |
| 3296 | |
| 3297 | /* Modify green table for giga & fnet */ |
| 3298 | { 0x1f, 0x0005 }, |
| 3299 | { 0x05, 0x8b55 }, |
| 3300 | { 0x06, 0x0000 }, |
| 3301 | { 0x05, 0x8b5e }, |
| 3302 | { 0x06, 0x0000 }, |
| 3303 | { 0x05, 0x8b67 }, |
| 3304 | { 0x06, 0x0000 }, |
| 3305 | { 0x05, 0x8b70 }, |
| 3306 | { 0x06, 0x0000 }, |
| 3307 | { 0x1f, 0x0000 }, |
| 3308 | { 0x1f, 0x0007 }, |
| 3309 | { 0x1e, 0x0078 }, |
| 3310 | { 0x17, 0x0000 }, |
| 3311 | { 0x19, 0x00aa }, |
| 3312 | { 0x1f, 0x0000 }, |
| 3313 | |
| 3314 | /* Modify green table for 10M */ |
| 3315 | { 0x1f, 0x0005 }, |
| 3316 | { 0x05, 0x8b79 }, |
| 3317 | { 0x06, 0xaa00 }, |
| 3318 | { 0x1f, 0x0000 }, |
| 3319 | |
| 3320 | /* Disable hiimpedance detection (RTCT) */ |
| 3321 | { 0x1f, 0x0003 }, |
| 3322 | { 0x01, 0x328a }, |
| 3323 | { 0x1f, 0x0000 } |
| 3324 | }; |
| 3325 | |
| 3326 | |
| 3327 | rtl_apply_firmware(tp); |
| 3328 | |
| 3329 | rtl8168f_hw_phy_config(tp); |
| 3330 | |
| 3331 | /* Improve 2-pair detection performance */ |
| 3332 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3333 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3334 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3335 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3336 | |
| 3337 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3338 | |
| 3339 | /* Modify green table for giga */ |
| 3340 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3341 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3342 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3343 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3344 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3345 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3346 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3347 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3348 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3349 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3350 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3351 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3352 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3353 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3354 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3355 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3356 | |
| 3357 | /* uc same-seed solution */ |
| 3358 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3359 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3360 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3361 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3362 | |
| 3363 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3364 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3365 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3366 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3367 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3368 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3369 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3370 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3371 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3372 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3373 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3374 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3375 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3376 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3377 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3378 | |
| 3379 | /* Green feature */ |
| 3380 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3381 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3382 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3383 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3384 | } |
| 3385 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3386 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3387 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3388 | rtl_apply_firmware(tp); |
| 3389 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3390 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3391 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3392 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3393 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3394 | } else { |
| 3395 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3396 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3397 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3398 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3399 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3400 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3401 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3402 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3403 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3404 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3405 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3406 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3407 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3408 | /* Enable PHY auto speed down */ |
| 3409 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3410 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3411 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3412 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3413 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3414 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3415 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3416 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3417 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3418 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3419 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3420 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3421 | /* EEE auto-fallback function */ |
| 3422 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3423 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3424 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3425 | /* Enable UC LPF tune function */ |
| 3426 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3427 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3428 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3429 | |
| 3430 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3431 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3432 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3433 | /* Improve SWR Efficiency */ |
| 3434 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3435 | rtl_writephy(tp, 0x14, 0x5065); |
| 3436 | rtl_writephy(tp, 0x14, 0xd065); |
| 3437 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3438 | rtl_writephy(tp, 0x11, 0x5655); |
| 3439 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3440 | rtl_writephy(tp, 0x14, 0x1065); |
| 3441 | rtl_writephy(tp, 0x14, 0x9065); |
| 3442 | rtl_writephy(tp, 0x14, 0x1065); |
| 3443 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3444 | /* Check ALDPS bit, disable it if enabled */ |
| 3445 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3446 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3447 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3448 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3449 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3450 | } |
| 3451 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3452 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3453 | { |
| 3454 | rtl_apply_firmware(tp); |
| 3455 | } |
| 3456 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3457 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3458 | { |
| 3459 | u16 dout_tapbin; |
| 3460 | u32 data; |
| 3461 | |
| 3462 | rtl_apply_firmware(tp); |
| 3463 | |
| 3464 | /* CHN EST parameters adjust - giga master */ |
| 3465 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3466 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3467 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3468 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3469 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3470 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3471 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3472 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3473 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3474 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3475 | |
| 3476 | /* CHN EST parameters adjust - giga slave */ |
| 3477 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3478 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3479 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3480 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3481 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3482 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3483 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3484 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3485 | |
| 3486 | /* CHN EST parameters adjust - fnet */ |
| 3487 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3488 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3489 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3490 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3491 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3492 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3493 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3494 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3495 | |
| 3496 | /* enable R-tune & PGA-retune function */ |
| 3497 | dout_tapbin = 0; |
| 3498 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3499 | data = rtl_readphy(tp, 0x13); |
| 3500 | data &= 3; |
| 3501 | data <<= 2; |
| 3502 | dout_tapbin |= data; |
| 3503 | data = rtl_readphy(tp, 0x12); |
| 3504 | data &= 0xc000; |
| 3505 | data >>= 14; |
| 3506 | dout_tapbin |= data; |
| 3507 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3508 | dout_tapbin <<= 12; |
| 3509 | dout_tapbin &= 0xf000; |
| 3510 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3511 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3512 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3513 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3514 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3515 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3516 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3517 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3518 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3519 | |
| 3520 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3521 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3522 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3523 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3524 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3525 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3526 | |
| 3527 | /* enable GPHY 10M */ |
| 3528 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3529 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3530 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3531 | |
| 3532 | /* SAR ADC performance */ |
| 3533 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3534 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3535 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3536 | |
| 3537 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3538 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3539 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3540 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3541 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3542 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3543 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3544 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3545 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3546 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3547 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3548 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3549 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3550 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3551 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3552 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3553 | |
| 3554 | /* disable phy pfm mode */ |
| 3555 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3556 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3557 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3558 | |
| 3559 | /* Check ALDPS bit, disable it if enabled */ |
| 3560 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3561 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3562 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3563 | |
| 3564 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3565 | } |
| 3566 | |
| 3567 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3568 | { |
| 3569 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3570 | u16 rlen; |
| 3571 | u32 data; |
| 3572 | |
| 3573 | rtl_apply_firmware(tp); |
| 3574 | |
| 3575 | /* CHIN EST parameter update */ |
| 3576 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3577 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3578 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3579 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3580 | |
| 3581 | /* enable R-tune & PGA-retune function */ |
| 3582 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3583 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3584 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3585 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3586 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3587 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3588 | |
| 3589 | /* enable GPHY 10M */ |
| 3590 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3591 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3592 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3593 | |
| 3594 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3595 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3596 | ioffset_p3 = ((data & 0x80)>>7); |
| 3597 | ioffset_p3 <<= 3; |
| 3598 | |
| 3599 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3600 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3601 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3602 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3603 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3604 | ioffset_p0 <<= 3; |
| 3605 | ioffset_p0 |= (data & (0x07)); |
| 3606 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3607 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3608 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3609 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3610 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3611 | rtl_writephy(tp, 0x16, data); |
| 3612 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3613 | } |
| 3614 | |
| 3615 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3616 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3617 | data = rtl_readphy(tp, 0x16); |
| 3618 | data &= 0x000f; |
| 3619 | rlen = 0; |
| 3620 | if (data > 3) |
| 3621 | rlen = data - 3; |
| 3622 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3623 | rtl_writephy(tp, 0x17, data); |
| 3624 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3625 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3626 | |
| 3627 | /* disable phy pfm mode */ |
| 3628 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3629 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3630 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3631 | |
| 3632 | /* Check ALDPS bit, disable it if enabled */ |
| 3633 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3634 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3635 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3636 | |
| 3637 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3638 | } |
| 3639 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3640 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3641 | { |
| 3642 | /* Enable PHY auto speed down */ |
| 3643 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3644 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 3645 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3646 | |
| 3647 | /* patch 10M & ALDPS */ |
| 3648 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3649 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3650 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3651 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3652 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3653 | rtl_writephy(tp, 0x13, 0x8084); |
| 3654 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3655 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3656 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3657 | |
| 3658 | /* Enable EEE auto-fallback function */ |
| 3659 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 3660 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 3661 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3662 | |
| 3663 | /* Enable UC LPF tune function */ |
| 3664 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3665 | rtl_writephy(tp, 0x13, 0x8012); |
| 3666 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3667 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3668 | |
| 3669 | /* set rg_sel_sdm_rate */ |
| 3670 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3671 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3672 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3673 | |
| 3674 | /* Check ALDPS bit, disable it if enabled */ |
| 3675 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3676 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3677 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3678 | |
| 3679 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3680 | } |
| 3681 | |
| 3682 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3683 | { |
| 3684 | /* patch 10M & ALDPS */ |
| 3685 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3686 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3687 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3688 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3689 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3690 | rtl_writephy(tp, 0x13, 0x8084); |
| 3691 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3692 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3693 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3694 | |
| 3695 | /* Enable UC LPF tune function */ |
| 3696 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3697 | rtl_writephy(tp, 0x13, 0x8012); |
| 3698 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3699 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3700 | |
| 3701 | /* Set rg_sel_sdm_rate */ |
| 3702 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3703 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3704 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3705 | |
| 3706 | /* Channel estimation parameters */ |
| 3707 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3708 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3709 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3710 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3711 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3712 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3713 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3714 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3715 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3716 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3717 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3718 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3719 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3720 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3721 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3722 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3723 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3724 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3725 | rtl_writephy(tp, 0x13, 0x8110); |
| 3726 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3727 | rtl_writephy(tp, 0x13, 0x810f); |
| 3728 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3729 | rtl_writephy(tp, 0x13, 0x8111); |
| 3730 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3731 | rtl_writephy(tp, 0x13, 0x8113); |
| 3732 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3733 | rtl_writephy(tp, 0x13, 0x8115); |
| 3734 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3735 | rtl_writephy(tp, 0x13, 0x810e); |
| 3736 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3737 | rtl_writephy(tp, 0x13, 0x810c); |
| 3738 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3739 | rtl_writephy(tp, 0x13, 0x810b); |
| 3740 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3741 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3742 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3743 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3744 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3745 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3746 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3747 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3748 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3749 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3750 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3751 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3752 | |
| 3753 | /* Force PWM-mode */ |
| 3754 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3755 | rtl_writephy(tp, 0x14, 0x5065); |
| 3756 | rtl_writephy(tp, 0x14, 0xd065); |
| 3757 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3758 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3759 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3760 | rtl_writephy(tp, 0x14, 0x1065); |
| 3761 | rtl_writephy(tp, 0x14, 0x9065); |
| 3762 | rtl_writephy(tp, 0x14, 0x1065); |
| 3763 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3764 | |
| 3765 | /* Check ALDPS bit, disable it if enabled */ |
| 3766 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3767 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3768 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3769 | |
| 3770 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3771 | } |
| 3772 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3773 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3774 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3775 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3776 | { 0x1f, 0x0003 }, |
| 3777 | { 0x08, 0x441d }, |
| 3778 | { 0x01, 0x9100 }, |
| 3779 | { 0x1f, 0x0000 } |
| 3780 | }; |
| 3781 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3782 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3783 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3784 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3785 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3786 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3787 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3788 | } |
| 3789 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3790 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3791 | { |
| 3792 | static const struct phy_reg phy_reg_init[] = { |
| 3793 | { 0x1f, 0x0005 }, |
| 3794 | { 0x1a, 0x0000 }, |
| 3795 | { 0x1f, 0x0000 }, |
| 3796 | |
| 3797 | { 0x1f, 0x0004 }, |
| 3798 | { 0x1c, 0x0000 }, |
| 3799 | { 0x1f, 0x0000 }, |
| 3800 | |
| 3801 | { 0x1f, 0x0001 }, |
| 3802 | { 0x15, 0x7701 }, |
| 3803 | { 0x1f, 0x0000 } |
| 3804 | }; |
| 3805 | |
| 3806 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3807 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3808 | rtl_writephy(tp, 0x18, 0x0310); |
| 3809 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3810 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3811 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3812 | |
| 3813 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3814 | } |
| 3815 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3816 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3817 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3818 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3819 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3820 | rtl_writephy(tp, 0x18, 0x0310); |
| 3821 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3822 | |
| 3823 | rtl_apply_firmware(tp); |
| 3824 | |
| 3825 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3826 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3827 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3828 | rtl_writephy(tp, 0x10, 0x401f); |
| 3829 | rtl_writephy(tp, 0x19, 0x7030); |
| 3830 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3831 | } |
| 3832 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3833 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3834 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3835 | static const struct phy_reg phy_reg_init[] = { |
| 3836 | { 0x1f, 0x0004 }, |
| 3837 | { 0x10, 0xc07f }, |
| 3838 | { 0x19, 0x7030 }, |
| 3839 | { 0x1f, 0x0000 } |
| 3840 | }; |
| 3841 | |
| 3842 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3843 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3844 | rtl_writephy(tp, 0x18, 0x0310); |
| 3845 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3846 | |
| 3847 | rtl_apply_firmware(tp); |
| 3848 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3849 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3850 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3851 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3852 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3853 | } |
| 3854 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3855 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3856 | { |
| 3857 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3858 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3859 | switch (tp->mac_version) { |
| 3860 | case RTL_GIGA_MAC_VER_01: |
| 3861 | break; |
| 3862 | case RTL_GIGA_MAC_VER_02: |
| 3863 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3864 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3865 | break; |
| 3866 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3867 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3868 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3869 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3870 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3871 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3872 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3873 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3874 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3875 | case RTL_GIGA_MAC_VER_07: |
| 3876 | case RTL_GIGA_MAC_VER_08: |
| 3877 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3878 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3879 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3880 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3881 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3882 | break; |
| 3883 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3884 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3885 | break; |
| 3886 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3887 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3888 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3889 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3890 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3891 | break; |
| 3892 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3893 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3894 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3895 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3896 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3897 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3898 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3899 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3900 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3901 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3902 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3903 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3904 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3905 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3906 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3907 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3908 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3909 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3910 | break; |
| 3911 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3912 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3913 | break; |
| 3914 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3915 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3916 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3917 | case RTL_GIGA_MAC_VER_28: |
| 3918 | rtl8168d_4_hw_phy_config(tp); |
| 3919 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3920 | case RTL_GIGA_MAC_VER_29: |
| 3921 | case RTL_GIGA_MAC_VER_30: |
| 3922 | rtl8105e_hw_phy_config(tp); |
| 3923 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3924 | case RTL_GIGA_MAC_VER_31: |
| 3925 | /* None. */ |
| 3926 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3927 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3928 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3929 | rtl8168e_1_hw_phy_config(tp); |
| 3930 | break; |
| 3931 | case RTL_GIGA_MAC_VER_34: |
| 3932 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3933 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3934 | case RTL_GIGA_MAC_VER_35: |
| 3935 | rtl8168f_1_hw_phy_config(tp); |
| 3936 | break; |
| 3937 | case RTL_GIGA_MAC_VER_36: |
| 3938 | rtl8168f_2_hw_phy_config(tp); |
| 3939 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3940 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3941 | case RTL_GIGA_MAC_VER_37: |
| 3942 | rtl8402_hw_phy_config(tp); |
| 3943 | break; |
| 3944 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3945 | case RTL_GIGA_MAC_VER_38: |
| 3946 | rtl8411_hw_phy_config(tp); |
| 3947 | break; |
| 3948 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3949 | case RTL_GIGA_MAC_VER_39: |
| 3950 | rtl8106e_hw_phy_config(tp); |
| 3951 | break; |
| 3952 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3953 | case RTL_GIGA_MAC_VER_40: |
| 3954 | rtl8168g_1_hw_phy_config(tp); |
| 3955 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3956 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 3957 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 3958 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3959 | rtl8168g_2_hw_phy_config(tp); |
| 3960 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3961 | case RTL_GIGA_MAC_VER_45: |
| 3962 | case RTL_GIGA_MAC_VER_47: |
| 3963 | rtl8168h_1_hw_phy_config(tp); |
| 3964 | break; |
| 3965 | case RTL_GIGA_MAC_VER_46: |
| 3966 | case RTL_GIGA_MAC_VER_48: |
| 3967 | rtl8168h_2_hw_phy_config(tp); |
| 3968 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3969 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3970 | case RTL_GIGA_MAC_VER_49: |
| 3971 | rtl8168ep_1_hw_phy_config(tp); |
| 3972 | break; |
| 3973 | case RTL_GIGA_MAC_VER_50: |
| 3974 | case RTL_GIGA_MAC_VER_51: |
| 3975 | rtl8168ep_2_hw_phy_config(tp); |
| 3976 | break; |
| 3977 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3978 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3979 | default: |
| 3980 | break; |
| 3981 | } |
| 3982 | } |
| 3983 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3984 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3985 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3986 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3987 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3990 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 3991 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3992 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 3993 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3994 | } |
| 3995 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3996 | 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] | 3997 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3998 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3999 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4000 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 7a67e11 | 2018-09-19 22:00:24 +0200 | [diff] [blame] | 4001 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4002 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4003 | netif_dbg(tp, drv, dev, |
| 4004 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4005 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4006 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4007 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4008 | /* We may have called phy_speed_down before */ |
| 4009 | phy_speed_up(dev->phydev); |
| 4010 | |
Heiner Kallweit | f75222b | 2018-07-17 22:51:41 +0200 | [diff] [blame] | 4011 | genphy_soft_reset(dev->phydev); |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4012 | |
Alex Xu (Hello71) | 9003b36 | 2018-09-30 11:06:39 -0400 | [diff] [blame] | 4013 | /* It was reported that several chips end up with 10MBit/Half on a |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4014 | * 1GBit link after resuming from S3. For whatever reason the PHY on |
Alex Xu (Hello71) | 9003b36 | 2018-09-30 11:06:39 -0400 | [diff] [blame] | 4015 | * these chips doesn't properly start a renegotiation when soft-reset. |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4016 | * Explicitly requesting a renegotiation fixes this. |
| 4017 | */ |
Alex Xu (Hello71) | 9003b36 | 2018-09-30 11:06:39 -0400 | [diff] [blame] | 4018 | if (dev->phydev->autoneg == AUTONEG_ENABLE) |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4019 | phy_restart_aneg(dev->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4020 | } |
| 4021 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4022 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4023 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4024 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4025 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4026 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4027 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4028 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4029 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4030 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4031 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4032 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4033 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4034 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4035 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4036 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4037 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4038 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4039 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4043 | { |
| 4044 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4045 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4046 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4047 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4048 | ret = eth_mac_addr(dev, p); |
| 4049 | if (ret) |
| 4050 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4051 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4052 | pm_runtime_get_noresume(d); |
| 4053 | |
| 4054 | if (pm_runtime_active(d)) |
| 4055 | rtl_rar_set(tp, dev->dev_addr); |
| 4056 | |
| 4057 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4058 | |
| 4059 | return 0; |
| 4060 | } |
| 4061 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4062 | 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] | 4063 | { |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4064 | if (!netif_running(dev)) |
| 4065 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4066 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4067 | return phy_mii_ioctl(dev->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4068 | } |
| 4069 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4070 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4071 | { |
| 4072 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4073 | |
| 4074 | switch (tp->mac_version) { |
| 4075 | case RTL_GIGA_MAC_VER_27: |
| 4076 | ops->write = r8168dp_1_mdio_write; |
| 4077 | ops->read = r8168dp_1_mdio_read; |
| 4078 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4079 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4080 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4081 | ops->write = r8168dp_2_mdio_write; |
| 4082 | ops->read = r8168dp_2_mdio_read; |
| 4083 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4084 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4085 | ops->write = r8168g_mdio_write; |
| 4086 | ops->read = r8168g_mdio_read; |
| 4087 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4088 | default: |
| 4089 | ops->write = r8169_mdio_write; |
| 4090 | ops->read = r8169_mdio_read; |
| 4091 | break; |
| 4092 | } |
| 4093 | } |
| 4094 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4095 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4096 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4097 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4098 | case RTL_GIGA_MAC_VER_25: |
| 4099 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4100 | case RTL_GIGA_MAC_VER_29: |
| 4101 | case RTL_GIGA_MAC_VER_30: |
| 4102 | case RTL_GIGA_MAC_VER_32: |
| 4103 | case RTL_GIGA_MAC_VER_33: |
| 4104 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4105 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4106 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4107 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4108 | break; |
| 4109 | default: |
| 4110 | break; |
| 4111 | } |
| 4112 | } |
| 4113 | |
| 4114 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4115 | { |
Heiner Kallweit | 649f083 | 2018-10-25 18:40:19 +0200 | [diff] [blame] | 4116 | struct phy_device *phydev; |
| 4117 | |
| 4118 | if (!__rtl8169_get_wol(tp)) |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4119 | return false; |
| 4120 | |
Heiner Kallweit | 649f083 | 2018-10-25 18:40:19 +0200 | [diff] [blame] | 4121 | /* phydev may not be attached to netdevice */ |
| 4122 | phydev = mdiobus_get_phy(tp->mii_bus, 0); |
| 4123 | |
| 4124 | phy_speed_down(phydev, false); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4125 | rtl_wol_suspend_quirk(tp); |
| 4126 | |
| 4127 | return true; |
| 4128 | } |
| 4129 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4130 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4131 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4132 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4133 | return; |
| 4134 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4135 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4136 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4137 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4138 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4139 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4140 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4141 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4142 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4143 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4144 | case RTL_GIGA_MAC_VER_37: |
| 4145 | case RTL_GIGA_MAC_VER_39: |
| 4146 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4147 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4148 | case RTL_GIGA_MAC_VER_45: |
| 4149 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4150 | case RTL_GIGA_MAC_VER_47: |
| 4151 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4152 | case RTL_GIGA_MAC_VER_50: |
| 4153 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4154 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4155 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4156 | case RTL_GIGA_MAC_VER_40: |
| 4157 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4158 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4159 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4160 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4161 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4162 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4167 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4168 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4169 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4170 | case RTL_GIGA_MAC_VER_37: |
| 4171 | case RTL_GIGA_MAC_VER_39: |
| 4172 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4173 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4174 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4175 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4176 | case RTL_GIGA_MAC_VER_45: |
| 4177 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4178 | case RTL_GIGA_MAC_VER_47: |
| 4179 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4180 | case RTL_GIGA_MAC_VER_50: |
| 4181 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4182 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4183 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4184 | case RTL_GIGA_MAC_VER_40: |
| 4185 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4186 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4187 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4188 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4189 | 0x00000000, ERIAR_EXGMAC); |
| 4190 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4191 | } |
| 4192 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 4193 | phy_resume(tp->dev->phydev); |
| 4194 | /* give MAC/PHY some time to resume */ |
| 4195 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4196 | } |
| 4197 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4198 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4199 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4200 | switch (tp->mac_version) { |
| 4201 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4202 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4203 | break; |
| 4204 | default: |
| 4205 | r8168_pll_power_down(tp); |
| 4206 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | static void rtl_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 | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4212 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4213 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4214 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4215 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4216 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4217 | } |
| 4218 | } |
| 4219 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4220 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4221 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4222 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4223 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4224 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4225 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4226 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4227 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
Maciej S. Szmigiero | 511cfd5 | 2018-10-11 16:02:10 +0200 | [diff] [blame] | 4228 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36: |
| 4229 | case RTL_GIGA_MAC_VER_38: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4230 | 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] | 4231 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4232 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4233 | 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] | 4234 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4235 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4236 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4237 | break; |
| 4238 | } |
| 4239 | } |
| 4240 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4241 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4242 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4243 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4244 | } |
| 4245 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4246 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4247 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4248 | if (tp->jumbo_ops.enable) { |
| 4249 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4250 | tp->jumbo_ops.enable(tp); |
| 4251 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4252 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4256 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4257 | if (tp->jumbo_ops.disable) { |
| 4258 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4259 | tp->jumbo_ops.disable(tp); |
| 4260 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4261 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4265 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4266 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4267 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4268 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4272 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4273 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4274 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4275 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4279 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4280 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4284 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4285 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4289 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4290 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4291 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4292 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4293 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4297 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4298 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4299 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4300 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4301 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4305 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4306 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4307 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4311 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4312 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4313 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4317 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4318 | r8168b_0_hw_jumbo_enable(tp); |
| 4319 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4320 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4324 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4325 | r8168b_0_hw_jumbo_disable(tp); |
| 4326 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4327 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4328 | } |
| 4329 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4330 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4331 | { |
| 4332 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4333 | |
| 4334 | switch (tp->mac_version) { |
| 4335 | case RTL_GIGA_MAC_VER_11: |
| 4336 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4337 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4338 | break; |
| 4339 | case RTL_GIGA_MAC_VER_12: |
| 4340 | case RTL_GIGA_MAC_VER_17: |
| 4341 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4342 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4343 | break; |
| 4344 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4345 | case RTL_GIGA_MAC_VER_19: |
| 4346 | case RTL_GIGA_MAC_VER_20: |
| 4347 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4348 | case RTL_GIGA_MAC_VER_22: |
| 4349 | case RTL_GIGA_MAC_VER_23: |
| 4350 | case RTL_GIGA_MAC_VER_24: |
| 4351 | case RTL_GIGA_MAC_VER_25: |
| 4352 | case RTL_GIGA_MAC_VER_26: |
| 4353 | ops->disable = r8168c_hw_jumbo_disable; |
| 4354 | ops->enable = r8168c_hw_jumbo_enable; |
| 4355 | break; |
| 4356 | case RTL_GIGA_MAC_VER_27: |
| 4357 | case RTL_GIGA_MAC_VER_28: |
| 4358 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4359 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4360 | break; |
| 4361 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4362 | case RTL_GIGA_MAC_VER_32: |
| 4363 | case RTL_GIGA_MAC_VER_33: |
| 4364 | case RTL_GIGA_MAC_VER_34: |
| 4365 | ops->disable = r8168e_hw_jumbo_disable; |
| 4366 | ops->enable = r8168e_hw_jumbo_enable; |
| 4367 | break; |
| 4368 | |
| 4369 | /* |
| 4370 | * No action needed for jumbo frames with 8169. |
| 4371 | * No jumbo for 810x at all. |
| 4372 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4373 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4374 | default: |
| 4375 | ops->disable = NULL; |
| 4376 | ops->enable = NULL; |
| 4377 | break; |
| 4378 | } |
| 4379 | } |
| 4380 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4381 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4382 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4383 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4384 | } |
| 4385 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4386 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4387 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4388 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4389 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4390 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4391 | } |
| 4392 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4393 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4394 | { |
| 4395 | struct rtl_fw *rtl_fw; |
| 4396 | const char *name; |
| 4397 | int rc = -ENOMEM; |
| 4398 | |
| 4399 | name = rtl_lookup_firmware_name(tp); |
| 4400 | if (!name) |
| 4401 | goto out_no_firmware; |
| 4402 | |
| 4403 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4404 | if (!rtl_fw) |
| 4405 | goto err_warn; |
| 4406 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4407 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4408 | if (rc < 0) |
| 4409 | goto err_free; |
| 4410 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4411 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4412 | if (rc < 0) |
| 4413 | goto err_release_firmware; |
| 4414 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4415 | tp->rtl_fw = rtl_fw; |
| 4416 | out: |
| 4417 | return; |
| 4418 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4419 | err_release_firmware: |
| 4420 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4421 | err_free: |
| 4422 | kfree(rtl_fw); |
| 4423 | err_warn: |
| 4424 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4425 | name, rc); |
| 4426 | out_no_firmware: |
| 4427 | tp->rtl_fw = NULL; |
| 4428 | goto out; |
| 4429 | } |
| 4430 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4431 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4432 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4433 | if (IS_ERR(tp->rtl_fw)) |
| 4434 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4435 | } |
| 4436 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4437 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4438 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4439 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4440 | } |
| 4441 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4442 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4443 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4444 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4448 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4449 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4452 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | { |
| 4454 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4455 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4457 | rtl_rx_close(tp); |
| 4458 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4459 | switch (tp->mac_version) { |
| 4460 | case RTL_GIGA_MAC_VER_27: |
| 4461 | case RTL_GIGA_MAC_VER_28: |
| 4462 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4463 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4464 | break; |
| 4465 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 4466 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4467 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4468 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4469 | break; |
| 4470 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4471 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4472 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4473 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4474 | } |
| 4475 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4476 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4479 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4480 | { |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4481 | u32 val = TX_DMA_BURST << TxDMAShift | |
| 4482 | InterFrameGap << TxInterFrameGapShift; |
| 4483 | |
| 4484 | if (tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
| 4485 | tp->mac_version != RTL_GIGA_MAC_VER_39) |
| 4486 | val |= TXCFG_AUTO_FIFO; |
| 4487 | |
| 4488 | RTL_W32(tp, TxConfig, val); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4489 | } |
| 4490 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4491 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4493 | /* Low hurts. Let's disable the filtering. */ |
| 4494 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4495 | } |
| 4496 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4497 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4498 | { |
| 4499 | /* |
| 4500 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4501 | * register to be written before TxDescAddrLow to work. |
| 4502 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4503 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4504 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4505 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4506 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4507 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4508 | } |
| 4509 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4510 | 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] | 4511 | { |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4512 | u32 val; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4513 | |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4514 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4515 | val = 0x000fff00; |
| 4516 | else if (tp->mac_version == RTL_GIGA_MAC_VER_06) |
| 4517 | val = 0x00ffff00; |
| 4518 | else |
| 4519 | return; |
| 4520 | |
| 4521 | if (RTL_R8(tp, Config2) & PCI_Clock_66MHz) |
| 4522 | val |= 0xff; |
| 4523 | |
| 4524 | RTL_W32(tp, 0x7c, val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4525 | } |
| 4526 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4527 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4528 | { |
| 4529 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4530 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4531 | int rx_mode; |
| 4532 | u32 tmp = 0; |
| 4533 | |
| 4534 | if (dev->flags & IFF_PROMISC) { |
| 4535 | /* Unconditionally log net taps. */ |
| 4536 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4537 | rx_mode = |
| 4538 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4539 | AcceptAllPhys; |
| 4540 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4541 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4542 | (dev->flags & IFF_ALLMULTI)) { |
| 4543 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4544 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4545 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4546 | } else { |
| 4547 | struct netdev_hw_addr *ha; |
| 4548 | |
| 4549 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4550 | mc_filter[1] = mc_filter[0] = 0; |
| 4551 | netdev_for_each_mc_addr(ha, dev) { |
| 4552 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4553 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4554 | rx_mode |= AcceptMulticast; |
| 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | if (dev->features & NETIF_F_RXALL) |
| 4559 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4560 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4561 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4562 | |
| 4563 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4564 | u32 data = mc_filter[0]; |
| 4565 | |
| 4566 | mc_filter[0] = swab32(mc_filter[1]); |
| 4567 | mc_filter[1] = swab32(data); |
| 4568 | } |
| 4569 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 4570 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 4571 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4572 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4573 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4574 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4575 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4576 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4577 | } |
| 4578 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4579 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 4580 | { |
| 4581 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4582 | |
| 4583 | tp->hw_start(tp); |
| 4584 | |
| 4585 | rtl_set_rx_max_size(tp); |
| 4586 | rtl_set_rx_tx_desc_registers(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4587 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4588 | |
| 4589 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4590 | RTL_R8(tp, IntrMask); |
| 4591 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4592 | rtl_init_rxcfg(tp); |
Maciej S. Szmigiero | f74dd48 | 2018-09-07 20:15:22 +0200 | [diff] [blame] | 4593 | rtl_set_tx_config_registers(tp); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4594 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4595 | rtl_set_rx_mode(tp->dev); |
| 4596 | /* no early-rx interrupts */ |
| 4597 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 4598 | rtl_irq_enable(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4599 | } |
| 4600 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4601 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4602 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4603 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4604 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4605 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4606 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4608 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4609 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4610 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4611 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4612 | netif_dbg(tp, drv, tp->dev, |
| 4613 | "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] | 4614 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4617 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4618 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4619 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | /* |
| 4622 | * Undocumented corner. Supposedly: |
| 4623 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4624 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4625 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4627 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4630 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4631 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4632 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4633 | } |
| 4634 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4635 | 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] | 4636 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4637 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4638 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4639 | RTL_W32(tp, CSIDR, value); |
| 4640 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4641 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4642 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4643 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4644 | } |
| 4645 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4646 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4647 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4648 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4649 | |
| 4650 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4651 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4652 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4653 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4654 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4655 | } |
| 4656 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4657 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4658 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4659 | struct pci_dev *pdev = tp->pci_dev; |
| 4660 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4661 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4662 | /* According to Realtek the value at config space address 0x070f |
| 4663 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4664 | * first and if it fails fall back to CSI. |
| 4665 | */ |
| 4666 | if (pdev->cfg_size > 0x070f && |
| 4667 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4668 | return; |
| 4669 | |
| 4670 | netdev_notice_once(tp->dev, |
| 4671 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4672 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4673 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4674 | } |
| 4675 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4676 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4677 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4678 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | struct ephy_info { |
| 4682 | unsigned int offset; |
| 4683 | u16 mask; |
| 4684 | u16 bits; |
| 4685 | }; |
| 4686 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4687 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 4688 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4689 | { |
| 4690 | u16 w; |
| 4691 | |
| 4692 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4693 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4694 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4695 | e++; |
| 4696 | } |
| 4697 | } |
| 4698 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4699 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4700 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4701 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4702 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4703 | } |
| 4704 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4705 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4706 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4707 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4708 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4709 | } |
| 4710 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4711 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 4712 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4713 | u8 data; |
| 4714 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4715 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4716 | |
| 4717 | if (enable) |
| 4718 | data |= Rdy_to_L23; |
| 4719 | else |
| 4720 | data &= ~Rdy_to_L23; |
| 4721 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4722 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4723 | } |
| 4724 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4725 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4726 | { |
| 4727 | if (enable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4728 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4729 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4730 | } else { |
| 4731 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4732 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4733 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4734 | |
| 4735 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4736 | } |
| 4737 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4738 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4739 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4740 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4741 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4742 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4743 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4744 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4745 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4746 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4747 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4748 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4749 | } |
| 4750 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4751 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4752 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4753 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4754 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4755 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4756 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4757 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4758 | } |
| 4759 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4760 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4761 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4762 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4763 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4764 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4765 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4766 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4767 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4768 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4769 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4770 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4771 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4772 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4773 | } |
| 4774 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4775 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4776 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4777 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4778 | { 0x01, 0, 0x0001 }, |
| 4779 | { 0x02, 0x0800, 0x1000 }, |
| 4780 | { 0x03, 0, 0x0042 }, |
| 4781 | { 0x06, 0x0080, 0x0000 }, |
| 4782 | { 0x07, 0, 0x2000 } |
| 4783 | }; |
| 4784 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4785 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4786 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4787 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4788 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4789 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4790 | } |
| 4791 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4792 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4793 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4794 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4795 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4796 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4797 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4798 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4799 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4800 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4801 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4802 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4803 | } |
| 4804 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4805 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4806 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4807 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4808 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4809 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4810 | |
| 4811 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4812 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4813 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4814 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4815 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4816 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4817 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4818 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4819 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4820 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4821 | } |
| 4822 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4823 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4824 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4825 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4826 | { 0x02, 0x0800, 0x1000 }, |
| 4827 | { 0x03, 0, 0x0002 }, |
| 4828 | { 0x06, 0x0080, 0x0000 } |
| 4829 | }; |
| 4830 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4831 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4832 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4833 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4834 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4835 | rtl_ephy_init(tp, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4836 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4837 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4840 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4841 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4842 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4843 | { 0x01, 0, 0x0001 }, |
| 4844 | { 0x03, 0x0400, 0x0220 } |
| 4845 | }; |
| 4846 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4847 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4848 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4849 | rtl_ephy_init(tp, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4850 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4851 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4852 | } |
| 4853 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4854 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4855 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4856 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4857 | } |
| 4858 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4859 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4860 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4861 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4862 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4863 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4866 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4867 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4868 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4869 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4870 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4871 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4872 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4873 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4874 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4875 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4876 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4877 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4878 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4879 | } |
| 4880 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4881 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4882 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4883 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4884 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4885 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4886 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4887 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4888 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4889 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4890 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4893 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4894 | { |
| 4895 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4896 | { 0x0b, 0x0000, 0x0048 }, |
| 4897 | { 0x19, 0x0020, 0x0050 }, |
| 4898 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4899 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4900 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4901 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4902 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4903 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4904 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4905 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4906 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4907 | rtl_ephy_init(tp, e_info_8168d_4, ARRAY_SIZE(e_info_8168d_4)); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4908 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4909 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4912 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4913 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4914 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4915 | { 0x00, 0x0200, 0x0100 }, |
| 4916 | { 0x00, 0x0000, 0x0004 }, |
| 4917 | { 0x06, 0x0002, 0x0001 }, |
| 4918 | { 0x06, 0x0000, 0x0030 }, |
| 4919 | { 0x07, 0x0000, 0x2000 }, |
| 4920 | { 0x00, 0x0000, 0x0020 }, |
| 4921 | { 0x03, 0x5800, 0x2000 }, |
| 4922 | { 0x03, 0x0000, 0x0001 }, |
| 4923 | { 0x01, 0x0800, 0x1000 }, |
| 4924 | { 0x07, 0x0000, 0x4000 }, |
| 4925 | { 0x1e, 0x0000, 0x2000 }, |
| 4926 | { 0x19, 0xffff, 0xfe6c }, |
| 4927 | { 0x0a, 0x0000, 0x0040 } |
| 4928 | }; |
| 4929 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4930 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4931 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4932 | rtl_ephy_init(tp, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1)); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4933 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4934 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4935 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4936 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4937 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4938 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4939 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4940 | |
| 4941 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4942 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4943 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4944 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4945 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4948 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4949 | { |
| 4950 | static const struct ephy_info e_info_8168e_2[] = { |
| 4951 | { 0x09, 0x0000, 0x0080 }, |
| 4952 | { 0x19, 0x0000, 0x0224 } |
| 4953 | }; |
| 4954 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4955 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4956 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4957 | rtl_ephy_init(tp, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4958 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4959 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4960 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4961 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4962 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4963 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4964 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 4965 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 4966 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 4967 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4968 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 4969 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4970 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4971 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4972 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4973 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 4974 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4975 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4976 | |
| 4977 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4978 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4979 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4980 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 4981 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 4982 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 4983 | |
| 4984 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4985 | } |
| 4986 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 4987 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4988 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4989 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4990 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4991 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4992 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4993 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4994 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4995 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 4996 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4997 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 4998 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 4999 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5000 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5001 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5002 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5003 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5004 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5005 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5006 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5007 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5008 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5009 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5010 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5011 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5012 | } |
| 5013 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5014 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5015 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5016 | static const struct ephy_info e_info_8168f_1[] = { |
| 5017 | { 0x06, 0x00c0, 0x0020 }, |
| 5018 | { 0x08, 0x0001, 0x0002 }, |
| 5019 | { 0x09, 0x0000, 0x0080 }, |
| 5020 | { 0x19, 0x0000, 0x0224 } |
| 5021 | }; |
| 5022 | |
| 5023 | rtl_hw_start_8168f(tp); |
| 5024 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5025 | rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5026 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5027 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5028 | |
| 5029 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5030 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5031 | } |
| 5032 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5033 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5034 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5035 | static const struct ephy_info e_info_8168f_1[] = { |
| 5036 | { 0x06, 0x00c0, 0x0020 }, |
| 5037 | { 0x0f, 0xffff, 0x5200 }, |
| 5038 | { 0x1e, 0x0000, 0x4000 }, |
| 5039 | { 0x19, 0x0000, 0x0224 } |
| 5040 | }; |
| 5041 | |
| 5042 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5043 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5044 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5045 | rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5046 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5047 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5048 | } |
| 5049 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5050 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5051 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5052 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5053 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5054 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5055 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5056 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5057 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5058 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5059 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5060 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5061 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5062 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5063 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5064 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5065 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5066 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5067 | |
| 5068 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5069 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5070 | |
| 5071 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5072 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5073 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5074 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5075 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5076 | |
| 5077 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5078 | } |
| 5079 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5080 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5081 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5082 | static const struct ephy_info e_info_8168g_1[] = { |
| 5083 | { 0x00, 0x0000, 0x0008 }, |
| 5084 | { 0x0c, 0x37d0, 0x0820 }, |
| 5085 | { 0x1e, 0x0000, 0x0001 }, |
| 5086 | { 0x19, 0x8000, 0x0000 } |
| 5087 | }; |
| 5088 | |
| 5089 | rtl_hw_start_8168g(tp); |
| 5090 | |
| 5091 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5092 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5093 | rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1)); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5094 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5095 | } |
| 5096 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5097 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5098 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5099 | static const struct ephy_info e_info_8168g_2[] = { |
| 5100 | { 0x00, 0x0000, 0x0008 }, |
| 5101 | { 0x0c, 0x3df0, 0x0200 }, |
| 5102 | { 0x19, 0xffff, 0xfc00 }, |
| 5103 | { 0x1e, 0xffff, 0x20eb } |
| 5104 | }; |
| 5105 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5106 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5107 | |
| 5108 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5109 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5110 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5111 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5112 | } |
| 5113 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5114 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5115 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5116 | static const struct ephy_info e_info_8411_2[] = { |
| 5117 | { 0x00, 0x0000, 0x0008 }, |
| 5118 | { 0x0c, 0x3df0, 0x0200 }, |
| 5119 | { 0x0f, 0xffff, 0x5200 }, |
| 5120 | { 0x19, 0x0020, 0x0000 }, |
| 5121 | { 0x1e, 0x0000, 0x2000 } |
| 5122 | }; |
| 5123 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5124 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5125 | |
| 5126 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5127 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5128 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5129 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5130 | } |
| 5131 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5132 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5133 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5134 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5135 | u32 data; |
| 5136 | static const struct ephy_info e_info_8168h_1[] = { |
| 5137 | { 0x1e, 0x0800, 0x0001 }, |
| 5138 | { 0x1d, 0x0000, 0x0800 }, |
| 5139 | { 0x05, 0xffff, 0x2089 }, |
| 5140 | { 0x06, 0xffff, 0x5881 }, |
| 5141 | { 0x04, 0xffff, 0x154a }, |
| 5142 | { 0x01, 0xffff, 0x068b } |
| 5143 | }; |
| 5144 | |
| 5145 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5146 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5147 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5148 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5149 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5150 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5151 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5152 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5153 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5154 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5155 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5156 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5157 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5158 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5159 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5160 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5161 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_1111, 0x0010, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5162 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5163 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f00, 0x00, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5164 | |
| 5165 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5166 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5167 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5168 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5169 | |
| 5170 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5171 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5172 | |
| 5173 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5174 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5175 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5176 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5177 | 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] | 5178 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5179 | 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] | 5180 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5181 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5182 | |
| 5183 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5184 | |
| 5185 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5186 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5187 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5188 | if (rg_saw_cnt > 0) { |
| 5189 | u16 sw_cnt_1ms_ini; |
| 5190 | |
| 5191 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5192 | sw_cnt_1ms_ini &= 0x0fff; |
| 5193 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5194 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5195 | data |= sw_cnt_1ms_ini; |
| 5196 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5197 | } |
| 5198 | |
| 5199 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5200 | data &= ~0xf0; |
| 5201 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5202 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5203 | |
| 5204 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5205 | data &= ~0x6000; |
| 5206 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5207 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5208 | |
| 5209 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5210 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5211 | data |= 0x017f; |
| 5212 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5213 | |
| 5214 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5215 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5216 | data |= 0x047f; |
| 5217 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5218 | |
| 5219 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5220 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5221 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5222 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5223 | |
| 5224 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5225 | } |
| 5226 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5227 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5228 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5229 | rtl8168ep_stop_cmac(tp); |
| 5230 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5231 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5232 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5233 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5234 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5235 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5236 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5237 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5238 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5239 | |
| 5240 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5241 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5242 | |
| 5243 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5244 | |
| 5245 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5246 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5247 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5248 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5249 | |
| 5250 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5251 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5252 | |
| 5253 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5254 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5255 | |
| 5256 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5257 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5258 | 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] | 5259 | |
| 5260 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5261 | } |
| 5262 | |
| 5263 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5264 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5265 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5266 | { 0x00, 0xffff, 0x10ab }, |
| 5267 | { 0x06, 0xffff, 0xf030 }, |
| 5268 | { 0x08, 0xffff, 0x2006 }, |
| 5269 | { 0x0d, 0xffff, 0x1666 }, |
| 5270 | { 0x0c, 0x3ff0, 0x0000 } |
| 5271 | }; |
| 5272 | |
| 5273 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5274 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5275 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5276 | |
| 5277 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5278 | |
| 5279 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5283 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5284 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5285 | { 0x00, 0xffff, 0x10a3 }, |
| 5286 | { 0x19, 0xffff, 0xfc00 }, |
| 5287 | { 0x1e, 0xffff, 0x20ea } |
| 5288 | }; |
| 5289 | |
| 5290 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5291 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5292 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5293 | |
| 5294 | rtl_hw_start_8168ep(tp); |
| 5295 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5296 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5297 | 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] | 5298 | |
| 5299 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5303 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5304 | u32 data; |
| 5305 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5306 | { 0x00, 0xffff, 0x10a3 }, |
| 5307 | { 0x19, 0xffff, 0x7c00 }, |
| 5308 | { 0x1e, 0xffff, 0x20eb }, |
| 5309 | { 0x0d, 0xffff, 0x1666 } |
| 5310 | }; |
| 5311 | |
| 5312 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5313 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5314 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5315 | |
| 5316 | rtl_hw_start_8168ep(tp); |
| 5317 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5318 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5319 | 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] | 5320 | |
| 5321 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5322 | data &= 0xf000; |
| 5323 | data |= 0x0271; |
| 5324 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5325 | |
| 5326 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5327 | data &= 0xff00; |
| 5328 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5329 | |
| 5330 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5331 | data |= 0x0080; |
| 5332 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5333 | |
| 5334 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5335 | } |
| 5336 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5337 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5338 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5339 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5340 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5341 | tp->cp_cmd &= ~INTT_MASK; |
| 5342 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5343 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5344 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5345 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5346 | |
| 5347 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5348 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 5349 | tp->irq_mask |= RxFIFOOver; |
| 5350 | tp->irq_mask &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5351 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5352 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5353 | switch (tp->mac_version) { |
| 5354 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5355 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5356 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5357 | |
| 5358 | case RTL_GIGA_MAC_VER_12: |
| 5359 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5360 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5361 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5362 | |
| 5363 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5364 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5365 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5366 | |
| 5367 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5368 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5369 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5370 | |
| 5371 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5372 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5373 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5374 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5375 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5376 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5377 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5378 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5379 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5380 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5381 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5382 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5383 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5384 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5385 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5386 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5387 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5388 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5389 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5390 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5391 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5392 | case RTL_GIGA_MAC_VER_26: |
| 5393 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5394 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5395 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5396 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5397 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5398 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5399 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5400 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5401 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5402 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5403 | break; |
| 5404 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5405 | case RTL_GIGA_MAC_VER_32: |
| 5406 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5407 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5408 | break; |
| 5409 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5410 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5411 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5412 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5413 | case RTL_GIGA_MAC_VER_35: |
| 5414 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5415 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5416 | break; |
| 5417 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5418 | case RTL_GIGA_MAC_VER_38: |
| 5419 | rtl_hw_start_8411(tp); |
| 5420 | break; |
| 5421 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5422 | case RTL_GIGA_MAC_VER_40: |
| 5423 | case RTL_GIGA_MAC_VER_41: |
| 5424 | rtl_hw_start_8168g_1(tp); |
| 5425 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5426 | case RTL_GIGA_MAC_VER_42: |
| 5427 | rtl_hw_start_8168g_2(tp); |
| 5428 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5429 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5430 | case RTL_GIGA_MAC_VER_44: |
| 5431 | rtl_hw_start_8411_2(tp); |
| 5432 | break; |
| 5433 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5434 | case RTL_GIGA_MAC_VER_45: |
| 5435 | case RTL_GIGA_MAC_VER_46: |
| 5436 | rtl_hw_start_8168h_1(tp); |
| 5437 | break; |
| 5438 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5439 | case RTL_GIGA_MAC_VER_49: |
| 5440 | rtl_hw_start_8168ep_1(tp); |
| 5441 | break; |
| 5442 | |
| 5443 | case RTL_GIGA_MAC_VER_50: |
| 5444 | rtl_hw_start_8168ep_2(tp); |
| 5445 | break; |
| 5446 | |
| 5447 | case RTL_GIGA_MAC_VER_51: |
| 5448 | rtl_hw_start_8168ep_3(tp); |
| 5449 | break; |
| 5450 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5451 | default: |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 5452 | netif_err(tp, drv, tp->dev, |
| 5453 | "unknown chipset (mac_version = %d)\n", |
| 5454 | tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5455 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5456 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5459 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5460 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5461 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5462 | { 0x01, 0, 0x6e65 }, |
| 5463 | { 0x02, 0, 0x091f }, |
| 5464 | { 0x03, 0, 0xc2f9 }, |
| 5465 | { 0x06, 0, 0xafb5 }, |
| 5466 | { 0x07, 0, 0x0e00 }, |
| 5467 | { 0x19, 0, 0xec80 }, |
| 5468 | { 0x01, 0, 0x2e65 }, |
| 5469 | { 0x01, 0, 0x6e65 } |
| 5470 | }; |
| 5471 | u8 cfg1; |
| 5472 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5473 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5474 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5475 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5476 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5477 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5478 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5479 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5480 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5481 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5482 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5483 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5484 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5485 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5486 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5487 | rtl_ephy_init(tp, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5488 | } |
| 5489 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5490 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5491 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5492 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5493 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5494 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5495 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5496 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5497 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5498 | } |
| 5499 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5500 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5501 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5502 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5503 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5504 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5505 | } |
| 5506 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5507 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5508 | { |
| 5509 | static const struct ephy_info e_info_8105e_1[] = { |
| 5510 | { 0x07, 0, 0x4000 }, |
| 5511 | { 0x19, 0, 0x0200 }, |
| 5512 | { 0x19, 0, 0x0020 }, |
| 5513 | { 0x1e, 0, 0x2000 }, |
| 5514 | { 0x03, 0, 0x0001 }, |
| 5515 | { 0x19, 0, 0x0100 }, |
| 5516 | { 0x19, 0, 0x0004 }, |
| 5517 | { 0x0a, 0, 0x0020 } |
| 5518 | }; |
| 5519 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5520 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5521 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5522 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5523 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5524 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5525 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5526 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5527 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5528 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5529 | rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5530 | |
| 5531 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5532 | } |
| 5533 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5534 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5535 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5536 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5537 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5538 | } |
| 5539 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5540 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5541 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5542 | static const struct ephy_info e_info_8402[] = { |
| 5543 | { 0x19, 0xffff, 0xff64 }, |
| 5544 | { 0x1e, 0, 0x4000 } |
| 5545 | }; |
| 5546 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5547 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5548 | |
| 5549 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5550 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5551 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5552 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5553 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5554 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5555 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5556 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5557 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5558 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 5559 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5560 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5561 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5562 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5563 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5564 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5565 | |
| 5566 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5567 | } |
| 5568 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5569 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5570 | { |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5571 | rtl_hw_aspm_clkreq_enable(tp, false); |
| 5572 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5573 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5574 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5575 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5576 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5577 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5578 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5579 | |
| 5580 | rtl_pcie_state_l2l3_enable(tp, false); |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5581 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5582 | } |
| 5583 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5584 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5585 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5586 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 5587 | tp->irq_mask &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5588 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5589 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5590 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5591 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5592 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5593 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5594 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5595 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5596 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5597 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5598 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5599 | switch (tp->mac_version) { |
| 5600 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5601 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5602 | break; |
| 5603 | |
| 5604 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5605 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5606 | break; |
| 5607 | |
| 5608 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5609 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5610 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5611 | |
| 5612 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5613 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5614 | break; |
| 5615 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5616 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5617 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5618 | |
| 5619 | case RTL_GIGA_MAC_VER_37: |
| 5620 | rtl_hw_start_8402(tp); |
| 5621 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5622 | |
| 5623 | case RTL_GIGA_MAC_VER_39: |
| 5624 | rtl_hw_start_8106(tp); |
| 5625 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5626 | case RTL_GIGA_MAC_VER_43: |
| 5627 | rtl_hw_start_8168g_2(tp); |
| 5628 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5629 | case RTL_GIGA_MAC_VER_47: |
| 5630 | case RTL_GIGA_MAC_VER_48: |
| 5631 | rtl_hw_start_8168h_1(tp); |
| 5632 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5633 | } |
| 5634 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5635 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5639 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5640 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5641 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5642 | if (new_mtu > ETH_DATA_LEN) |
| 5643 | rtl_hw_jumbo_enable(tp); |
| 5644 | else |
| 5645 | rtl_hw_jumbo_disable(tp); |
| 5646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5648 | netdev_update_features(dev); |
| 5649 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5650 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5654 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5655 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5657 | } |
| 5658 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5659 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5660 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5662 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 5663 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5664 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5665 | kfree(*data_buff); |
| 5666 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | rtl8169_make_unusable_by_asic(desc); |
| 5668 | } |
| 5669 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5670 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | { |
| 5672 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5673 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5674 | /* Force memory writes to complete before releasing descriptor */ |
| 5675 | dma_wmb(); |
| 5676 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5677 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5678 | } |
| 5679 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5680 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5682 | return (void *)ALIGN((long)data, 16); |
| 5683 | } |
| 5684 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5685 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5686 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5687 | { |
| 5688 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5689 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5690 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5691 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5693 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5694 | if (!data) |
| 5695 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5696 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5697 | if (rtl8169_align(data) != data) { |
| 5698 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5699 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5700 | if (!data) |
| 5701 | return NULL; |
| 5702 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5703 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5704 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 5705 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5706 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5707 | if (net_ratelimit()) |
| 5708 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5709 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5712 | desc->addr = cpu_to_le64(mapping); |
| 5713 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5714 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5715 | |
| 5716 | err_out: |
| 5717 | kfree(data); |
| 5718 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5722 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5723 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | |
| 5725 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5726 | if (tp->Rx_databuff[i]) { |
| 5727 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | tp->RxDescArray + i); |
| 5729 | } |
| 5730 | } |
| 5731 | } |
| 5732 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5733 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5735 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5736 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5737 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5738 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5739 | { |
| 5740 | unsigned int i; |
| 5741 | |
| 5742 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5743 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5744 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5745 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5746 | if (!data) { |
| 5747 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5748 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5749 | } |
| 5750 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5753 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5754 | return 0; |
| 5755 | |
| 5756 | err_out: |
| 5757 | rtl8169_rx_clear(tp); |
| 5758 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5761 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | rtl8169_init_ring_indexes(tp); |
| 5764 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5765 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5766 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5768 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | } |
| 5770 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5771 | 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] | 5772 | struct TxDesc *desc) |
| 5773 | { |
| 5774 | unsigned int len = tx_skb->len; |
| 5775 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5776 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | desc->opts1 = 0x00; |
| 5779 | desc->opts2 = 0x00; |
| 5780 | desc->addr = 0x00; |
| 5781 | tx_skb->len = 0; |
| 5782 | } |
| 5783 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5784 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5785 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | { |
| 5787 | unsigned int i; |
| 5788 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5789 | for (i = 0; i < n; i++) { |
| 5790 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5791 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5792 | unsigned int len = tx_skb->len; |
| 5793 | |
| 5794 | if (len) { |
| 5795 | struct sk_buff *skb = tx_skb->skb; |
| 5796 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5797 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5798 | tp->TxDescArray + entry); |
| 5799 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5800 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5801 | tx_skb->skb = NULL; |
| 5802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5803 | } |
| 5804 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5808 | { |
| 5809 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | tp->cur_tx = tp->dirty_tx = 0; |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5811 | netdev_reset_queue(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5814 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5816 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5817 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5819 | napi_disable(&tp->napi); |
| 5820 | netif_stop_queue(dev); |
| 5821 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5823 | rtl8169_hw_reset(tp); |
| 5824 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5825 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5826 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5829 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5830 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5831 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5832 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5833 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5837 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5838 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5839 | |
| 5840 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | } |
| 5842 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame^] | 5843 | static __le32 rtl8169_get_txd_opts1(u32 opts0, u32 len, unsigned int entry) |
| 5844 | { |
| 5845 | u32 status = opts0 | len; |
| 5846 | |
| 5847 | if (entry == NUM_TX_DESC - 1) |
| 5848 | status |= RingEnd; |
| 5849 | |
| 5850 | return cpu_to_le32(status); |
| 5851 | } |
| 5852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | 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] | 5854 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | { |
| 5856 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5857 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5858 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5859 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5860 | |
| 5861 | entry = tp->cur_tx; |
| 5862 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5863 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5864 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame^] | 5865 | u32 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | void *addr; |
| 5867 | |
| 5868 | entry = (entry + 1) % NUM_TX_DESC; |
| 5869 | |
| 5870 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5871 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5872 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5873 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5874 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5875 | if (net_ratelimit()) |
| 5876 | netif_err(tp, drv, tp->dev, |
| 5877 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5878 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame^] | 5881 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5882 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | txd->addr = cpu_to_le64(mapping); |
| 5884 | |
| 5885 | tp->tx_skb[entry].len = len; |
| 5886 | } |
| 5887 | |
| 5888 | if (cur_frag) { |
| 5889 | tp->tx_skb[entry].skb = skb; |
| 5890 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5891 | } |
| 5892 | |
| 5893 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5894 | |
| 5895 | err_out: |
| 5896 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5897 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5900 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5901 | { |
| 5902 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5903 | } |
| 5904 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5905 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5906 | struct net_device *dev); |
| 5907 | /* r8169_csum_workaround() |
| 5908 | * The hw limites the value the transport offset. When the offset is out of the |
| 5909 | * range, calculate the checksum by sw. |
| 5910 | */ |
| 5911 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 5912 | struct sk_buff *skb) |
| 5913 | { |
| 5914 | if (skb_shinfo(skb)->gso_size) { |
| 5915 | netdev_features_t features = tp->dev->features; |
| 5916 | struct sk_buff *segs, *nskb; |
| 5917 | |
| 5918 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 5919 | segs = skb_gso_segment(skb, features); |
| 5920 | if (IS_ERR(segs) || !segs) |
| 5921 | goto drop; |
| 5922 | |
| 5923 | do { |
| 5924 | nskb = segs; |
| 5925 | segs = segs->next; |
| 5926 | nskb->next = NULL; |
| 5927 | rtl8169_start_xmit(nskb, tp->dev); |
| 5928 | } while (segs); |
| 5929 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5930 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5931 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5932 | if (skb_checksum_help(skb) < 0) |
| 5933 | goto drop; |
| 5934 | |
| 5935 | rtl8169_start_xmit(skb, tp->dev); |
| 5936 | } else { |
| 5937 | struct net_device_stats *stats; |
| 5938 | |
| 5939 | drop: |
| 5940 | stats = &tp->dev->stats; |
| 5941 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5942 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | /* msdn_giant_send_check() |
| 5947 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5948 | * packet length for IPv6 TCP large packets. |
| 5949 | */ |
| 5950 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 5951 | { |
| 5952 | const struct ipv6hdr *ipv6h; |
| 5953 | struct tcphdr *th; |
| 5954 | int ret; |
| 5955 | |
| 5956 | ret = skb_cow_head(skb, 0); |
| 5957 | if (ret) |
| 5958 | return ret; |
| 5959 | |
| 5960 | ipv6h = ipv6_hdr(skb); |
| 5961 | th = tcp_hdr(skb); |
| 5962 | |
| 5963 | th->check = 0; |
| 5964 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 5965 | |
| 5966 | return ret; |
| 5967 | } |
| 5968 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5969 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 5970 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5971 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5972 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5973 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5974 | if (mss) { |
| 5975 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5976 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 5977 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5978 | const struct iphdr *ip = ip_hdr(skb); |
| 5979 | |
| 5980 | if (ip->protocol == IPPROTO_TCP) |
| 5981 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 5982 | else if (ip->protocol == IPPROTO_UDP) |
| 5983 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 5984 | else |
| 5985 | WARN_ON_ONCE(1); |
| 5986 | } |
| 5987 | |
| 5988 | return true; |
| 5989 | } |
| 5990 | |
| 5991 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 5992 | struct sk_buff *skb, u32 *opts) |
| 5993 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 5994 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 5995 | u32 mss = skb_shinfo(skb)->gso_size; |
| 5996 | |
| 5997 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5998 | if (transport_offset > GTTCPHO_MAX) { |
| 5999 | netif_warn(tp, tx_err, tp->dev, |
| 6000 | "Invalid transport offset 0x%x for TSO\n", |
| 6001 | transport_offset); |
| 6002 | return false; |
| 6003 | } |
| 6004 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6005 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6006 | case htons(ETH_P_IP): |
| 6007 | opts[0] |= TD1_GTSENV4; |
| 6008 | break; |
| 6009 | |
| 6010 | case htons(ETH_P_IPV6): |
| 6011 | if (msdn_giant_send_check(skb)) |
| 6012 | return false; |
| 6013 | |
| 6014 | opts[0] |= TD1_GTSENV6; |
| 6015 | break; |
| 6016 | |
| 6017 | default: |
| 6018 | WARN_ON_ONCE(1); |
| 6019 | break; |
| 6020 | } |
| 6021 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6022 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6023 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6024 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6025 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6026 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6027 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6028 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6029 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6030 | if (transport_offset > TCPHO_MAX) { |
| 6031 | netif_warn(tp, tx_err, tp->dev, |
| 6032 | "Invalid transport offset 0x%x\n", |
| 6033 | transport_offset); |
| 6034 | return false; |
| 6035 | } |
| 6036 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6037 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6038 | case htons(ETH_P_IP): |
| 6039 | opts[1] |= TD1_IPv4_CS; |
| 6040 | ip_protocol = ip_hdr(skb)->protocol; |
| 6041 | break; |
| 6042 | |
| 6043 | case htons(ETH_P_IPV6): |
| 6044 | opts[1] |= TD1_IPv6_CS; |
| 6045 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6046 | break; |
| 6047 | |
| 6048 | default: |
| 6049 | ip_protocol = IPPROTO_RAW; |
| 6050 | break; |
| 6051 | } |
| 6052 | |
| 6053 | if (ip_protocol == IPPROTO_TCP) |
| 6054 | opts[1] |= TD1_TCP_CS; |
| 6055 | else if (ip_protocol == IPPROTO_UDP) |
| 6056 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6057 | else |
| 6058 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6059 | |
| 6060 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6061 | } else { |
| 6062 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6063 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6064 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6065 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6066 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6067 | } |
| 6068 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6069 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6070 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6071 | { |
| 6072 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6073 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6074 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6075 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6076 | dma_addr_t mapping; |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame^] | 6077 | u32 opts[2], len; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6078 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6079 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6080 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6081 | 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] | 6082 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6086 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6088 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6089 | opts[0] = DescOwn; |
| 6090 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6091 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6092 | r8169_csum_workaround(tp, skb); |
| 6093 | return NETDEV_TX_OK; |
| 6094 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6095 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6096 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6097 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6098 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6099 | if (net_ratelimit()) |
| 6100 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6101 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6102 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6103 | |
| 6104 | tp->tx_skb[entry].len = len; |
| 6105 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6107 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6108 | if (frags < 0) |
| 6109 | goto err_dma_1; |
| 6110 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6111 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6112 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6113 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6114 | tp->tx_skb[entry].skb = skb; |
| 6115 | } |
| 6116 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6117 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6118 | |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6119 | netdev_sent_queue(dev, skb->len); |
| 6120 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6121 | skb_tx_timestamp(skb); |
| 6122 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6123 | /* Force memory writes to complete before releasing descriptor */ |
| 6124 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | |
Heiner Kallweit | 734c140 | 2018-11-22 21:56:48 +0100 | [diff] [blame^] | 6126 | txd->opts1 = rtl8169_get_txd_opts1(opts[0], len, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6127 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6128 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6129 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6131 | tp->cur_tx += frags + 1; |
| 6132 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6133 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6135 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6136 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6137 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6138 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6139 | * not miss a ring update when it notices a stopped queue. |
| 6140 | */ |
| 6141 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6143 | /* Sync with rtl_tx: |
| 6144 | * - publish queue status and cur_tx ring index (write barrier) |
| 6145 | * - refresh dirty_tx ring index (read barrier). |
| 6146 | * May the current thread have a pessimistic view of the ring |
| 6147 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6148 | * can't. |
| 6149 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6150 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6151 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6152 | netif_wake_queue(dev); |
| 6153 | } |
| 6154 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6155 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6157 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6158 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6159 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6160 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6161 | dev->stats.tx_dropped++; |
| 6162 | return NETDEV_TX_OK; |
| 6163 | |
| 6164 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6166 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6167 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6171 | { |
| 6172 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6173 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | u16 pci_status, pci_cmd; |
| 6175 | |
| 6176 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6177 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6178 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6179 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6180 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | |
| 6182 | /* |
| 6183 | * The recovery sequence below admits a very elaborated explanation: |
| 6184 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6185 | * - I did not see what else could be done; |
| 6186 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6187 | * |
| 6188 | * Feel free to adjust to your needs. |
| 6189 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6190 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6191 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6192 | else |
| 6193 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6194 | |
| 6195 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | |
| 6197 | pci_write_config_word(pdev, PCI_STATUS, |
| 6198 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6199 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6200 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6201 | |
| 6202 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6203 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6204 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6206 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6207 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | } |
| 6209 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6210 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6211 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6212 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6213 | } |
| 6214 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6215 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6217 | unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | dirty_tx = tp->dirty_tx; |
| 6220 | smp_rmb(); |
| 6221 | tx_left = tp->cur_tx - dirty_tx; |
| 6222 | |
| 6223 | while (tx_left > 0) { |
| 6224 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6225 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6226 | u32 status; |
| 6227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6229 | if (status & DescOwn) |
| 6230 | break; |
| 6231 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6232 | /* This barrier is needed to keep us from reading |
| 6233 | * any other fields out of the Tx descriptor until |
| 6234 | * we know the status of DescOwn |
| 6235 | */ |
| 6236 | dma_rmb(); |
| 6237 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6238 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6239 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | if (status & LastFrag) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6241 | pkts_compl++; |
| 6242 | bytes_compl += tx_skb->skb->len; |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6243 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | tx_skb->skb = NULL; |
| 6245 | } |
| 6246 | dirty_tx++; |
| 6247 | tx_left--; |
| 6248 | } |
| 6249 | |
| 6250 | if (tp->dirty_tx != dirty_tx) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6251 | netdev_completed_queue(dev, pkts_compl, bytes_compl); |
| 6252 | |
| 6253 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6254 | tp->tx_stats.packets += pkts_compl; |
| 6255 | tp->tx_stats.bytes += bytes_compl; |
| 6256 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 6257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6259 | /* Sync with rtl8169_start_xmit: |
| 6260 | * - publish dirty_tx ring index (write barrier) |
| 6261 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6262 | * May the current thread miss the stopped queue condition, |
| 6263 | * a racing xmit thread can only have a right view of the |
| 6264 | * ring status. |
| 6265 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6266 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6267 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6268 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | netif_wake_queue(dev); |
| 6270 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6271 | /* |
| 6272 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6273 | * too close. Let's kick an extra TxPoll request when a burst |
| 6274 | * of start_xmit activity is detected (if it is not detected, |
| 6275 | * it is slow enough). -- FR |
| 6276 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6277 | if (tp->cur_tx != dirty_tx) |
| 6278 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6279 | } |
| 6280 | } |
| 6281 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6282 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6283 | { |
| 6284 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6285 | } |
| 6286 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6287 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6288 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | u32 status = opts1 & RxProtoMask; |
| 6290 | |
| 6291 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6292 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6293 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6294 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6295 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | } |
| 6297 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6298 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6299 | struct rtl8169_private *tp, |
| 6300 | int pkt_size, |
| 6301 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6303 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6304 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6305 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6306 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6307 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6308 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6309 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6310 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6311 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6312 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6313 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6314 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | } |
| 6316 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6317 | 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] | 6318 | { |
| 6319 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6320 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6323 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6324 | 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] | 6325 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6326 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6327 | u32 status; |
| 6328 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6329 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | if (status & DescOwn) |
| 6331 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6332 | |
| 6333 | /* This barrier is needed to keep us from reading |
| 6334 | * any other fields out of the Rx descriptor until |
| 6335 | * we know the status of DescOwn |
| 6336 | */ |
| 6337 | dma_rmb(); |
| 6338 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6339 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6340 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6341 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6342 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6343 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6344 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6346 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6347 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6348 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6349 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6350 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6351 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6352 | } else if (status & (RxRUNT | RxCRC) && |
| 6353 | !(status & RxRWT) && |
| 6354 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6355 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6357 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6358 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6359 | dma_addr_t addr; |
| 6360 | int pkt_size; |
| 6361 | |
| 6362 | process_pkt: |
| 6363 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6364 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6365 | pkt_size = (status & 0x00003fff) - 4; |
| 6366 | else |
| 6367 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6368 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6369 | /* |
| 6370 | * The driver does not support incoming fragmented |
| 6371 | * frames. They are seen as a symptom of over-mtu |
| 6372 | * sized frames. |
| 6373 | */ |
| 6374 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6375 | dev->stats.rx_dropped++; |
| 6376 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6377 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6380 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6381 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6382 | if (!skb) { |
| 6383 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6384 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6387 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | skb_put(skb, pkt_size); |
| 6389 | skb->protocol = eth_type_trans(skb, dev); |
| 6390 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6391 | rtl8169_rx_vlan_tag(desc, skb); |
| 6392 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6393 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6394 | dev->stats.multicast++; |
| 6395 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6396 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6398 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6399 | tp->rx_stats.packets++; |
| 6400 | tp->rx_stats.bytes += pkt_size; |
| 6401 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6402 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6403 | release_descriptor: |
| 6404 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6405 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | count = cur_rx - tp->cur_rx; |
| 6409 | tp->cur_rx = cur_rx; |
| 6410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6411 | return count; |
| 6412 | } |
| 6413 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6414 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6415 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6416 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6417 | u16 status = rtl_get_events(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6418 | |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6419 | if (status == 0xffff || !(status & tp->irq_mask)) |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6420 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6421 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6422 | if (unlikely(status & SYSErr)) { |
| 6423 | rtl8169_pcierr_interrupt(tp->dev); |
| 6424 | goto out; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6425 | } |
| 6426 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6427 | if (status & LinkChg) |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6428 | phy_mac_interrupt(tp->dev->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6429 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6430 | if (unlikely(status & RxFIFOOver && |
| 6431 | tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
| 6432 | netif_stop_queue(tp->dev); |
| 6433 | /* XXX - Hack alert. See rtl_task(). */ |
| 6434 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
| 6435 | } |
| 6436 | |
| 6437 | if (status & RTL_EVENT_NAPI) { |
| 6438 | rtl_irq_disable(tp); |
| 6439 | napi_schedule_irqoff(&tp->napi); |
| 6440 | } |
| 6441 | out: |
| 6442 | rtl_ack_events(tp, status); |
| 6443 | |
| 6444 | return IRQ_HANDLED; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6445 | } |
| 6446 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6447 | static void rtl_task(struct work_struct *work) |
| 6448 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6449 | static const struct { |
| 6450 | int bitnr; |
| 6451 | void (*action)(struct rtl8169_private *); |
| 6452 | } rtl_work[] = { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6453 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6454 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6455 | struct rtl8169_private *tp = |
| 6456 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6457 | struct net_device *dev = tp->dev; |
| 6458 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6459 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6460 | rtl_lock_work(tp); |
| 6461 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6462 | if (!netif_running(dev) || |
| 6463 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6464 | goto out_unlock; |
| 6465 | |
| 6466 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6467 | bool pending; |
| 6468 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6469 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6470 | if (pending) |
| 6471 | rtl_work[i].action(tp); |
| 6472 | } |
| 6473 | |
| 6474 | out_unlock: |
| 6475 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6476 | } |
| 6477 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6478 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6479 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6480 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6481 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6482 | int work_done; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6483 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6484 | work_done = rtl_rx(dev, tp, (u32) budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6485 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6486 | rtl_tx(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6487 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6488 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 6489 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 6490 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 6491 | rtl_irq_enable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6492 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6495 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6497 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6498 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6499 | { |
| 6500 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6501 | |
| 6502 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6503 | return; |
| 6504 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6505 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 6506 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6507 | } |
| 6508 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6509 | static void r8169_phylink_handler(struct net_device *ndev) |
| 6510 | { |
| 6511 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 6512 | |
| 6513 | if (netif_carrier_ok(ndev)) { |
| 6514 | rtl_link_chg_patch(tp); |
| 6515 | pm_request_resume(&tp->pci_dev->dev); |
| 6516 | } else { |
| 6517 | pm_runtime_idle(&tp->pci_dev->dev); |
| 6518 | } |
| 6519 | |
| 6520 | if (net_ratelimit()) |
| 6521 | phy_print_status(ndev->phydev); |
| 6522 | } |
| 6523 | |
| 6524 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 6525 | { |
| 6526 | struct phy_device *phydev = mdiobus_get_phy(tp->mii_bus, 0); |
| 6527 | phy_interface_t phy_mode; |
| 6528 | int ret; |
| 6529 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6530 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6531 | PHY_INTERFACE_MODE_MII; |
| 6532 | |
| 6533 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 6534 | phy_mode); |
| 6535 | if (ret) |
| 6536 | return ret; |
| 6537 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6538 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6539 | phy_set_max_speed(phydev, SPEED_100); |
| 6540 | |
| 6541 | /* Ensure to advertise everything, incl. pause */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 6542 | linkmode_copy(phydev->advertising, phydev->supported); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6543 | |
| 6544 | phy_attached_info(phydev); |
| 6545 | |
| 6546 | return 0; |
| 6547 | } |
| 6548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6549 | static void rtl8169_down(struct net_device *dev) |
| 6550 | { |
| 6551 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6552 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6553 | phy_stop(dev->phydev); |
| 6554 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6555 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6556 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6557 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6558 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6559 | /* |
| 6560 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6561 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6562 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6563 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6564 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6567 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | rtl8169_tx_clear(tp); |
| 6570 | |
| 6571 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6572 | |
| 6573 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | static int rtl8169_close(struct net_device *dev) |
| 6577 | { |
| 6578 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6579 | struct pci_dev *pdev = tp->pci_dev; |
| 6580 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6581 | pm_runtime_get_sync(&pdev->dev); |
| 6582 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6583 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6584 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6585 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6586 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6587 | /* Clear all task flags */ |
| 6588 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6590 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6591 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6593 | cancel_work_sync(&tp->wk.work); |
| 6594 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6595 | phy_disconnect(dev->phydev); |
| 6596 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6597 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6598 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6599 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6600 | tp->RxPhyAddr); |
| 6601 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6602 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6603 | tp->TxDescArray = NULL; |
| 6604 | tp->RxDescArray = NULL; |
| 6605 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6606 | pm_runtime_put_sync(&pdev->dev); |
| 6607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6608 | return 0; |
| 6609 | } |
| 6610 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6611 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6612 | static void rtl8169_netpoll(struct net_device *dev) |
| 6613 | { |
| 6614 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6615 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6616 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6617 | } |
| 6618 | #endif |
| 6619 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6620 | static int rtl_open(struct net_device *dev) |
| 6621 | { |
| 6622 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6623 | struct pci_dev *pdev = tp->pci_dev; |
| 6624 | int retval = -ENOMEM; |
| 6625 | |
| 6626 | pm_runtime_get_sync(&pdev->dev); |
| 6627 | |
| 6628 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6629 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6630 | * dma_alloc_coherent provides more. |
| 6631 | */ |
| 6632 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6633 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6634 | if (!tp->TxDescArray) |
| 6635 | goto err_pm_runtime_put; |
| 6636 | |
| 6637 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6638 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6639 | if (!tp->RxDescArray) |
| 6640 | goto err_free_tx_0; |
| 6641 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6642 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6643 | if (retval < 0) |
| 6644 | goto err_free_rx_1; |
| 6645 | |
| 6646 | INIT_WORK(&tp->wk.work, rtl_task); |
| 6647 | |
| 6648 | smp_mb(); |
| 6649 | |
| 6650 | rtl_request_firmware(tp); |
| 6651 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6652 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6653 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6654 | if (retval < 0) |
| 6655 | goto err_release_fw_2; |
| 6656 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6657 | retval = r8169_phy_connect(tp); |
| 6658 | if (retval) |
| 6659 | goto err_free_irq; |
| 6660 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6661 | rtl_lock_work(tp); |
| 6662 | |
| 6663 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6664 | |
| 6665 | napi_enable(&tp->napi); |
| 6666 | |
| 6667 | rtl8169_init_phy(dev, tp); |
| 6668 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6669 | rtl_pll_power_up(tp); |
| 6670 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6671 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6672 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6673 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6674 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6675 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6676 | phy_start(dev->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6677 | netif_start_queue(dev); |
| 6678 | |
| 6679 | rtl_unlock_work(tp); |
| 6680 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6681 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6682 | out: |
| 6683 | return retval; |
| 6684 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6685 | err_free_irq: |
| 6686 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6687 | err_release_fw_2: |
| 6688 | rtl_release_firmware(tp); |
| 6689 | rtl8169_rx_clear(tp); |
| 6690 | err_free_rx_1: |
| 6691 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6692 | tp->RxPhyAddr); |
| 6693 | tp->RxDescArray = NULL; |
| 6694 | err_free_tx_0: |
| 6695 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6696 | tp->TxPhyAddr); |
| 6697 | tp->TxDescArray = NULL; |
| 6698 | err_pm_runtime_put: |
| 6699 | pm_runtime_put_noidle(&pdev->dev); |
| 6700 | goto out; |
| 6701 | } |
| 6702 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6703 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6704 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6705 | { |
| 6706 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6707 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6708 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6709 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6710 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6711 | pm_runtime_get_noresume(&pdev->dev); |
| 6712 | |
| 6713 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6714 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6715 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6716 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6717 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6718 | stats->rx_packets = tp->rx_stats.packets; |
| 6719 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6720 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6721 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6722 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6723 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6724 | stats->tx_packets = tp->tx_stats.packets; |
| 6725 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6726 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6727 | |
| 6728 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6729 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6730 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6731 | stats->rx_errors = dev->stats.rx_errors; |
| 6732 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6733 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6734 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6735 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6736 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6737 | /* |
| 6738 | * Fetch additonal counter values missing in stats collected by driver |
| 6739 | * from tally counters. |
| 6740 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6741 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6742 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6743 | |
| 6744 | /* |
| 6745 | * Subtract values fetched during initalization. |
| 6746 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6747 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6748 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6749 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6750 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6751 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6752 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6753 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6754 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6755 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6758 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6759 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6760 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6761 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6762 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6763 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6764 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6765 | phy_stop(dev->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6766 | netif_device_detach(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6767 | |
| 6768 | rtl_lock_work(tp); |
| 6769 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6770 | /* Clear all task flags */ |
| 6771 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6772 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6773 | rtl_unlock_work(tp); |
| 6774 | |
| 6775 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6776 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6777 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6778 | #ifdef CONFIG_PM |
| 6779 | |
| 6780 | static int rtl8169_suspend(struct device *device) |
| 6781 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6782 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6783 | struct rtl8169_private *tp = netdev_priv(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6784 | |
| 6785 | rtl8169_net_suspend(dev); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6786 | clk_disable_unprepare(tp->clk); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6787 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6788 | return 0; |
| 6789 | } |
| 6790 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6791 | static void __rtl8169_resume(struct net_device *dev) |
| 6792 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6793 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6794 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6795 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6796 | |
| 6797 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6798 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6799 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6800 | phy_start(tp->dev->phydev); |
| 6801 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6802 | rtl_lock_work(tp); |
| 6803 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6804 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6805 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6806 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6807 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6808 | } |
| 6809 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6810 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6811 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6812 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6813 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6814 | |
| 6815 | clk_prepare_enable(tp->clk); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6816 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6817 | if (netif_running(dev)) |
| 6818 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6819 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6820 | return 0; |
| 6821 | } |
| 6822 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6823 | static int rtl8169_runtime_suspend(struct device *device) |
| 6824 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6825 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6826 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6827 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6828 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6829 | return 0; |
| 6830 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6831 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6832 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6833 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6834 | |
| 6835 | rtl8169_net_suspend(dev); |
| 6836 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6837 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6838 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6839 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6840 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6841 | return 0; |
| 6842 | } |
| 6843 | |
| 6844 | static int rtl8169_runtime_resume(struct device *device) |
| 6845 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6846 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6847 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6848 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6849 | |
| 6850 | if (!tp->TxDescArray) |
| 6851 | return 0; |
| 6852 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6853 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6854 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6855 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6856 | |
| 6857 | __rtl8169_resume(dev); |
| 6858 | |
| 6859 | return 0; |
| 6860 | } |
| 6861 | |
| 6862 | static int rtl8169_runtime_idle(struct device *device) |
| 6863 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame] | 6864 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6865 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6866 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6867 | pm_schedule_suspend(device, 10000); |
| 6868 | |
| 6869 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6870 | } |
| 6871 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6872 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6873 | .suspend = rtl8169_suspend, |
| 6874 | .resume = rtl8169_resume, |
| 6875 | .freeze = rtl8169_suspend, |
| 6876 | .thaw = rtl8169_resume, |
| 6877 | .poweroff = rtl8169_suspend, |
| 6878 | .restore = rtl8169_resume, |
| 6879 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6880 | .runtime_resume = rtl8169_runtime_resume, |
| 6881 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6882 | }; |
| 6883 | |
| 6884 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6885 | |
| 6886 | #else /* !CONFIG_PM */ |
| 6887 | |
| 6888 | #define RTL8169_PM_OPS NULL |
| 6889 | |
| 6890 | #endif /* !CONFIG_PM */ |
| 6891 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6892 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6893 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6894 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6895 | switch (tp->mac_version) { |
| 6896 | case RTL_GIGA_MAC_VER_11: |
| 6897 | case RTL_GIGA_MAC_VER_12: |
| 6898 | case RTL_GIGA_MAC_VER_17: |
| 6899 | pci_clear_master(tp->pci_dev); |
| 6900 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6901 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6902 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6903 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6904 | break; |
| 6905 | default: |
| 6906 | break; |
| 6907 | } |
| 6908 | } |
| 6909 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6910 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6911 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6912 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6913 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6914 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6915 | rtl8169_net_suspend(dev); |
| 6916 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6917 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6918 | rtl_rar_set(tp, dev->perm_addr); |
| 6919 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6920 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6921 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6922 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6923 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6924 | rtl_wol_suspend_quirk(tp); |
| 6925 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6926 | } |
| 6927 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6928 | pci_wake_from_d3(pdev, true); |
| 6929 | pci_set_power_state(pdev, PCI_D3hot); |
| 6930 | } |
| 6931 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6932 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6933 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6934 | { |
| 6935 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6936 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6937 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6938 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6939 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6940 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6941 | netif_napi_del(&tp->napi); |
| 6942 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6943 | unregister_netdev(dev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6944 | mdiobus_unregister(tp->mii_bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6945 | |
| 6946 | rtl_release_firmware(tp); |
| 6947 | |
| 6948 | if (pci_dev_run_wake(pdev)) |
| 6949 | pm_runtime_get_noresume(&pdev->dev); |
| 6950 | |
| 6951 | /* restore original MAC address */ |
| 6952 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6953 | } |
| 6954 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6955 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6956 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6957 | .ndo_stop = rtl8169_close, |
| 6958 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6959 | .ndo_start_xmit = rtl8169_start_xmit, |
| 6960 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 6961 | .ndo_validate_addr = eth_validate_addr, |
| 6962 | .ndo_change_mtu = rtl8169_change_mtu, |
| 6963 | .ndo_fix_features = rtl8169_fix_features, |
| 6964 | .ndo_set_features = rtl8169_set_features, |
| 6965 | .ndo_set_mac_address = rtl_set_mac_address, |
| 6966 | .ndo_do_ioctl = rtl8169_ioctl, |
| 6967 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 6968 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6969 | .ndo_poll_controller = rtl8169_netpoll, |
| 6970 | #endif |
| 6971 | |
| 6972 | }; |
| 6973 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6974 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6975 | void (*hw_start)(struct rtl8169_private *tp); |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6976 | u16 irq_mask; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6977 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6978 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6979 | u8 default_ver; |
| 6980 | } rtl_cfg_infos [] = { |
| 6981 | [RTL_CFG_0] = { |
| 6982 | .hw_start = rtl_hw_start_8169, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6983 | .irq_mask = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6984 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6985 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6986 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 6987 | }, |
| 6988 | [RTL_CFG_1] = { |
| 6989 | .hw_start = rtl_hw_start_8168, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6990 | .irq_mask = LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 6991 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6992 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6993 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 6994 | }, |
| 6995 | [RTL_CFG_2] = { |
| 6996 | .hw_start = rtl_hw_start_8101, |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 6997 | .irq_mask = LinkChg | RxOverflow | RxFIFOOver, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 6998 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6999 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7000 | } |
| 7001 | }; |
| 7002 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7003 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7004 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7005 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7006 | |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 7007 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7008 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7009 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7010 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7011 | flags = PCI_IRQ_LEGACY; |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 7012 | } else { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7013 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7014 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7015 | |
| 7016 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7017 | } |
| 7018 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7019 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7020 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7021 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7025 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7026 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7027 | } |
| 7028 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7029 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 7030 | { |
| 7031 | struct rtl8169_private *tp = mii_bus->priv; |
| 7032 | |
| 7033 | if (phyaddr > 0) |
| 7034 | return -ENODEV; |
| 7035 | |
| 7036 | return rtl_readphy(tp, phyreg); |
| 7037 | } |
| 7038 | |
| 7039 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 7040 | int phyreg, u16 val) |
| 7041 | { |
| 7042 | struct rtl8169_private *tp = mii_bus->priv; |
| 7043 | |
| 7044 | if (phyaddr > 0) |
| 7045 | return -ENODEV; |
| 7046 | |
| 7047 | rtl_writephy(tp, phyreg, val); |
| 7048 | |
| 7049 | return 0; |
| 7050 | } |
| 7051 | |
| 7052 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 7053 | { |
| 7054 | struct pci_dev *pdev = tp->pci_dev; |
| 7055 | struct phy_device *phydev; |
| 7056 | struct mii_bus *new_bus; |
| 7057 | int ret; |
| 7058 | |
| 7059 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 7060 | if (!new_bus) |
| 7061 | return -ENOMEM; |
| 7062 | |
| 7063 | new_bus->name = "r8169"; |
| 7064 | new_bus->priv = tp; |
| 7065 | new_bus->parent = &pdev->dev; |
| 7066 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
| 7067 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x", |
| 7068 | PCI_DEVID(pdev->bus->number, pdev->devfn)); |
| 7069 | |
| 7070 | new_bus->read = r8169_mdio_read_reg; |
| 7071 | new_bus->write = r8169_mdio_write_reg; |
| 7072 | |
| 7073 | ret = mdiobus_register(new_bus); |
| 7074 | if (ret) |
| 7075 | return ret; |
| 7076 | |
| 7077 | phydev = mdiobus_get_phy(new_bus, 0); |
| 7078 | if (!phydev) { |
| 7079 | mdiobus_unregister(new_bus); |
| 7080 | return -ENODEV; |
| 7081 | } |
| 7082 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 7083 | /* PHY will be woken up in rtl_open() */ |
| 7084 | phy_suspend(phydev); |
| 7085 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7086 | tp->mii_bus = new_bus; |
| 7087 | |
| 7088 | return 0; |
| 7089 | } |
| 7090 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7091 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7092 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7093 | u32 data; |
| 7094 | |
| 7095 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7096 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7097 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7098 | |
| 7099 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7100 | return; |
| 7101 | |
| 7102 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7103 | return; |
| 7104 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7105 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7106 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7107 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7108 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7109 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7110 | data &= ~(1 << 14); |
| 7111 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7112 | |
| 7113 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7114 | return; |
| 7115 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7116 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7117 | data |= (1 << 15); |
| 7118 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7119 | |
| 7120 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7121 | return; |
| 7122 | } |
| 7123 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7124 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7125 | { |
| 7126 | rtl8168ep_stop_cmac(tp); |
| 7127 | rtl_hw_init_8168g(tp); |
| 7128 | } |
| 7129 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7130 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7131 | { |
| 7132 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7133 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7134 | rtl_hw_init_8168g(tp); |
| 7135 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7136 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7137 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7138 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7139 | default: |
| 7140 | break; |
| 7141 | } |
| 7142 | } |
| 7143 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7144 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 7145 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 7146 | { |
| 7147 | switch (tp->mac_version) { |
| 7148 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7149 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 7150 | return false; |
| 7151 | default: |
| 7152 | return true; |
| 7153 | } |
| 7154 | } |
| 7155 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7156 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 7157 | { |
| 7158 | /* Non-GBit versions don't support jumbo frames */ |
| 7159 | if (!tp->supports_gmii) |
| 7160 | return JUMBO_1K; |
| 7161 | |
| 7162 | switch (tp->mac_version) { |
| 7163 | /* RTL8169 */ |
| 7164 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7165 | return JUMBO_7K; |
| 7166 | /* RTL8168b */ |
| 7167 | case RTL_GIGA_MAC_VER_11: |
| 7168 | case RTL_GIGA_MAC_VER_12: |
| 7169 | case RTL_GIGA_MAC_VER_17: |
| 7170 | return JUMBO_4K; |
| 7171 | /* RTL8168c */ |
| 7172 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 7173 | return JUMBO_6K; |
| 7174 | default: |
| 7175 | return JUMBO_9K; |
| 7176 | } |
| 7177 | } |
| 7178 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7179 | static void rtl_disable_clk(void *data) |
| 7180 | { |
| 7181 | clk_disable_unprepare(data); |
| 7182 | } |
| 7183 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7184 | 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] | 7185 | { |
| 7186 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7187 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7188 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7189 | int chipset, region, i; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7190 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7191 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7192 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7193 | if (!dev) |
| 7194 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7195 | |
| 7196 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7197 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7198 | tp = netdev_priv(dev); |
| 7199 | tp->dev = dev; |
| 7200 | tp->pci_dev = pdev; |
| 7201 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 7202 | tp->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7203 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7204 | /* Get the *optional* external "ether_clk" used on some boards */ |
| 7205 | tp->clk = devm_clk_get(&pdev->dev, "ether_clk"); |
| 7206 | if (IS_ERR(tp->clk)) { |
| 7207 | rc = PTR_ERR(tp->clk); |
| 7208 | if (rc == -ENOENT) { |
| 7209 | /* clk-core allows NULL (for suspend / resume) */ |
| 7210 | tp->clk = NULL; |
| 7211 | } else if (rc == -EPROBE_DEFER) { |
| 7212 | return rc; |
| 7213 | } else { |
| 7214 | dev_err(&pdev->dev, "failed to get clk: %d\n", rc); |
| 7215 | return rc; |
| 7216 | } |
| 7217 | } else { |
| 7218 | rc = clk_prepare_enable(tp->clk); |
| 7219 | if (rc) { |
| 7220 | dev_err(&pdev->dev, "failed to enable clk: %d\n", rc); |
| 7221 | return rc; |
| 7222 | } |
| 7223 | |
| 7224 | rc = devm_add_action_or_reset(&pdev->dev, rtl_disable_clk, |
| 7225 | tp->clk); |
| 7226 | if (rc) |
| 7227 | return rc; |
| 7228 | } |
| 7229 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7230 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7231 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7232 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7233 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7234 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7235 | } |
| 7236 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7237 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7238 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7239 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7240 | /* use first MMIO region */ |
| 7241 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7242 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7243 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7244 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | /* check for weird/broken PCI region reporting */ |
| 7248 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7249 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7250 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7251 | } |
| 7252 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7253 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7254 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7255 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7256 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7257 | } |
| 7258 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7259 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7260 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7261 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7262 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7263 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 7264 | if (rtl_tbi_enabled(tp)) { |
| 7265 | dev_err(&pdev->dev, "TBI fiber mode not supported\n"); |
| 7266 | return -ENODEV; |
| 7267 | } |
| 7268 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7269 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7270 | |
Heiner Kallweit | a045679 | 2018-09-25 07:59:36 +0200 | [diff] [blame] | 7271 | if (sizeof(dma_addr_t) > 4 && (use_dac == 1 || (use_dac == -1 && |
| 7272 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
| 7273 | !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7274 | |
| 7275 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7276 | if (!pci_is_pcie(pdev)) |
| 7277 | tp->cp_cmd |= PCIDAC; |
| 7278 | dev->features |= NETIF_F_HIGHDMA; |
| 7279 | } else { |
| 7280 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7281 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7282 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7283 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7284 | } |
| 7285 | } |
| 7286 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7287 | rtl_init_rxcfg(tp); |
| 7288 | |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 7289 | rtl8169_irq_mask_and_ack(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7290 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7291 | rtl_hw_initialize(tp); |
| 7292 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7293 | rtl_hw_reset(tp); |
| 7294 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7295 | pci_set_master(pdev); |
| 7296 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7297 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7298 | rtl_init_jumbo_ops(tp); |
| 7299 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7300 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7301 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7302 | rc = rtl_alloc_irq(tp); |
| 7303 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7304 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7305 | return rc; |
| 7306 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7307 | |
Heiner Kallweit | 18041b5 | 2018-07-24 22:21:04 +0200 | [diff] [blame] | 7308 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7309 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7310 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7311 | u64_stats_init(&tp->rx_stats.syncp); |
| 7312 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7313 | |
| 7314 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7315 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7316 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7317 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7318 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7319 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7320 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7321 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7322 | if (is_valid_ether_addr(mac_addr)) |
| 7323 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7324 | break; |
| 7325 | default: |
| 7326 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7327 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7328 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7329 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7330 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7331 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7332 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7333 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7334 | |
| 7335 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7336 | * properly for all devices */ |
| 7337 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7338 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7339 | |
| 7340 | 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] | 7341 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7342 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7343 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7344 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 7345 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7346 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7347 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7348 | |
| 7349 | /* |
| 7350 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7351 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7352 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7353 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7354 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7355 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7356 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7357 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7358 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7359 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7360 | } else { |
| 7361 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7362 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7363 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7364 | dev->hw_features |= NETIF_F_RXALL; |
| 7365 | dev->hw_features |= NETIF_F_RXFCS; |
| 7366 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7367 | /* MTU range: 60 - hw-specific max */ |
| 7368 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7369 | jumbo_max = rtl_jumbo_max(tp); |
| 7370 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7371 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7372 | tp->hw_start = cfg->hw_start; |
Heiner Kallweit | 559c3c0 | 2018-11-19 22:34:17 +0100 | [diff] [blame] | 7373 | tp->irq_mask = RTL_EVENT_NAPI | cfg->irq_mask; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7374 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7375 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7376 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7377 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7378 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7379 | &tp->counters_phys_addr, |
| 7380 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7381 | if (!tp->counters) |
| 7382 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7383 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7384 | pci_set_drvdata(pdev, dev); |
| 7385 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7386 | rc = r8169_mdio_register(tp); |
| 7387 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7388 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7389 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 7390 | /* chip gets powered up in rtl_open() */ |
| 7391 | rtl_pll_power_down(tp); |
| 7392 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7393 | rc = register_netdev(dev); |
| 7394 | if (rc) |
| 7395 | goto err_mdio_unregister; |
| 7396 | |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 7397 | netif_info(tp, probe, dev, "%s, %pM, XID %03x, IRQ %d\n", |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7398 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 55d2ad7 | 2018-11-19 22:41:35 +0100 | [diff] [blame] | 7399 | (RTL_R32(tp, TxConfig) >> 20) & 0xfcf, |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7400 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7401 | |
| 7402 | if (jumbo_max > JUMBO_1K) |
| 7403 | netif_info(tp, probe, dev, |
| 7404 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 7405 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 7406 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7407 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7408 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7409 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7410 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7411 | if (pci_dev_run_wake(pdev)) |
| 7412 | pm_runtime_put_sync(&pdev->dev); |
| 7413 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7414 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7415 | |
| 7416 | err_mdio_unregister: |
| 7417 | mdiobus_unregister(tp->mii_bus); |
| 7418 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7419 | } |
| 7420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7421 | static struct pci_driver rtl8169_pci_driver = { |
| 7422 | .name = MODULENAME, |
| 7423 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7424 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7425 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7426 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7427 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7428 | }; |
| 7429 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7430 | module_pci_driver(rtl8169_pci_driver); |