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[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 215 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 216 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Chun-Hao Lin | 610c908 | 2016-12-27 16:29:43 +0800 | [diff] [blame] | 217 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 218 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 219 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Anthony Wong | 9fd0e09 | 2018-08-31 20:06:42 +0800 | [diff] [blame] | 220 | { PCI_DEVICE(PCI_VENDOR_ID_NCUBE, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 221 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 222 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 223 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 224 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 225 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 226 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Heiner Kallweit | 9206eb0 | 2018-11-11 20:31:21 +0100 | [diff] [blame] | 227 | { PCI_DEVICE(PCI_VENDOR_ID_USR, 0x0116), 0, 0, 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 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | {0,}, |
| 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; |
| 606 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 607 | }; |
| 608 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 609 | struct rtl8169_counters { |
| 610 | __le64 tx_packets; |
| 611 | __le64 rx_packets; |
| 612 | __le64 tx_errors; |
| 613 | __le32 rx_errors; |
| 614 | __le16 rx_missed; |
| 615 | __le16 align_errors; |
| 616 | __le32 tx_one_collision; |
| 617 | __le32 tx_multi_collision; |
| 618 | __le64 rx_unicast; |
| 619 | __le64 rx_broadcast; |
| 620 | __le32 rx_multicast; |
| 621 | __le16 tx_aborted; |
| 622 | __le16 tx_underun; |
| 623 | }; |
| 624 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 625 | struct rtl8169_tc_offsets { |
| 626 | bool inited; |
| 627 | __le64 tx_errors; |
| 628 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 629 | __le16 tx_aborted; |
| 630 | }; |
| 631 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 632 | enum rtl_flag { |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 633 | RTL_FLAG_TASK_ENABLED = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 634 | RTL_FLAG_TASK_RESET_PENDING, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 635 | RTL_FLAG_MAX |
| 636 | }; |
| 637 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 638 | struct rtl8169_stats { |
| 639 | u64 packets; |
| 640 | u64 bytes; |
| 641 | struct u64_stats_sync syncp; |
| 642 | }; |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | struct rtl8169_private { |
| 645 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 646 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 647 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 648 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 649 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 650 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 652 | 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] | 653 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 654 | struct rtl8169_stats rx_stats; |
| 655 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 657 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 658 | dma_addr_t TxPhyAddr; |
| 659 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 660 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 663 | |
| 664 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 665 | const struct rtl_coalesce_info *coalesce_info; |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 666 | struct clk *clk; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 667 | |
| 668 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 669 | void (*write)(struct rtl8169_private *, int, int); |
| 670 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 671 | } mdio_ops; |
| 672 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 673 | struct jumbo_ops { |
| 674 | void (*enable)(struct rtl8169_private *); |
| 675 | void (*disable)(struct rtl8169_private *); |
| 676 | } jumbo_ops; |
| 677 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 678 | void (*hw_start)(struct rtl8169_private *tp); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 679 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 680 | |
| 681 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 682 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 683 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 684 | struct work_struct work; |
| 685 | } wk; |
| 686 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 687 | unsigned supports_gmii:1; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 688 | struct mii_bus *mii_bus; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 689 | dma_addr_t counters_phys_addr; |
| 690 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 691 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 692 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 693 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 694 | struct rtl_fw { |
| 695 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 696 | |
| 697 | #define RTL_VER_SIZE 32 |
| 698 | |
| 699 | char version[RTL_VER_SIZE]; |
| 700 | |
| 701 | struct rtl_fw_phy_action { |
| 702 | __le32 *code; |
| 703 | size_t size; |
| 704 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 705 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 706 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 707 | |
| 708 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | }; |
| 710 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 711 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 714 | 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] | 715 | module_param_named(debug, debug.msg_enable, int, 0); |
| 716 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | MODULE_LICENSE("GPL"); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 718 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 719 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 720 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 721 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 722 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 723 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 724 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 725 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 726 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 727 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 728 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 729 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 730 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 731 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 732 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 733 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 734 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 735 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 736 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 738 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 739 | { |
| 740 | return &tp->pci_dev->dev; |
| 741 | } |
| 742 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 743 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 744 | { |
| 745 | mutex_lock(&tp->wk.mutex); |
| 746 | } |
| 747 | |
| 748 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 749 | { |
| 750 | mutex_unlock(&tp->wk.mutex); |
| 751 | } |
| 752 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 753 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 754 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 755 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 756 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 757 | } |
| 758 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 759 | struct rtl_cond { |
| 760 | bool (*check)(struct rtl8169_private *); |
| 761 | const char *msg; |
| 762 | }; |
| 763 | |
| 764 | static void rtl_udelay(unsigned int d) |
| 765 | { |
| 766 | udelay(d); |
| 767 | } |
| 768 | |
| 769 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 770 | void (*delay)(unsigned int), unsigned int d, int n, |
| 771 | bool high) |
| 772 | { |
| 773 | int i; |
| 774 | |
| 775 | for (i = 0; i < n; i++) { |
| 776 | delay(d); |
| 777 | if (c->check(tp) == high) |
| 778 | return true; |
| 779 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 780 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 781 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 782 | return false; |
| 783 | } |
| 784 | |
| 785 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 786 | const struct rtl_cond *c, |
| 787 | unsigned int d, int n) |
| 788 | { |
| 789 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 790 | } |
| 791 | |
| 792 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 793 | const struct rtl_cond *c, |
| 794 | unsigned int d, int n) |
| 795 | { |
| 796 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 797 | } |
| 798 | |
| 799 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 800 | const struct rtl_cond *c, |
| 801 | unsigned int d, int n) |
| 802 | { |
| 803 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 804 | } |
| 805 | |
| 806 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 807 | const struct rtl_cond *c, |
| 808 | unsigned int d, int n) |
| 809 | { |
| 810 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 811 | } |
| 812 | |
| 813 | #define DECLARE_RTL_COND(name) \ |
| 814 | static bool name ## _check(struct rtl8169_private *); \ |
| 815 | \ |
| 816 | static const struct rtl_cond name = { \ |
| 817 | .check = name ## _check, \ |
| 818 | .msg = #name \ |
| 819 | }; \ |
| 820 | \ |
| 821 | static bool name ## _check(struct rtl8169_private *tp) |
| 822 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 823 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 824 | { |
| 825 | if (reg & 0xffff0001) { |
| 826 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 827 | return true; |
| 828 | } |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 833 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 834 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 838 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 839 | if (rtl_ocp_reg_failure(tp, reg)) |
| 840 | return; |
| 841 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 842 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 843 | |
| 844 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 845 | } |
| 846 | |
| 847 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 848 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 849 | if (rtl_ocp_reg_failure(tp, reg)) |
| 850 | return 0; |
| 851 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 852 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 853 | |
| 854 | 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] | 855 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 856 | } |
| 857 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 858 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 859 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 860 | if (rtl_ocp_reg_failure(tp, reg)) |
| 861 | return; |
| 862 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 863 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 867 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 868 | if (rtl_ocp_reg_failure(tp, reg)) |
| 869 | return 0; |
| 870 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 871 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 872 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 873 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | #define OCP_STD_PHY_BASE 0xa400 |
| 877 | |
| 878 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 879 | { |
| 880 | if (reg == 0x1f) { |
| 881 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 882 | return; |
| 883 | } |
| 884 | |
| 885 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 886 | reg -= 0x10; |
| 887 | |
| 888 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 889 | } |
| 890 | |
| 891 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 892 | { |
| 893 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 894 | reg -= 0x10; |
| 895 | |
| 896 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 897 | } |
| 898 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 899 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 900 | { |
| 901 | if (reg == 0x1f) { |
| 902 | tp->ocp_base = value << 4; |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 907 | } |
| 908 | |
| 909 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 910 | { |
| 911 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 912 | } |
| 913 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 914 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 915 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 916 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 917 | } |
| 918 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 919 | 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] | 920 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 921 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 923 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 924 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 925 | * According to hardware specs a 20us delay is required after write |
| 926 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 927 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 928 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 931 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 933 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 935 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 937 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 938 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 939 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 940 | /* |
| 941 | * According to hardware specs a 20us delay is required after read |
| 942 | * complete indication, but before sending next command. |
| 943 | */ |
| 944 | udelay(20); |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | return value; |
| 947 | } |
| 948 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 949 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 950 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 951 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 952 | } |
| 953 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 954 | 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] | 955 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 956 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 957 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 958 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 959 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 960 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 961 | } |
| 962 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 963 | 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] | 964 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 965 | r8168dp_1_mdio_access(tp, reg, |
| 966 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 969 | 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] | 970 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 971 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 972 | |
| 973 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 974 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 975 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 976 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 977 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 978 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 979 | } |
| 980 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 981 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 982 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 983 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 984 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 985 | 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] | 986 | } |
| 987 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 988 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 989 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 990 | 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] | 991 | } |
| 992 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 993 | 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] | 994 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 995 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 996 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 997 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 998 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 999 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1002 | 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] | 1003 | { |
| 1004 | int value; |
| 1005 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1006 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1007 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1008 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1009 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1010 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1011 | |
| 1012 | return value; |
| 1013 | } |
| 1014 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1015 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1016 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1017 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1018 | } |
| 1019 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1020 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1021 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1022 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1026 | { |
| 1027 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1028 | } |
| 1029 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1030 | 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] | 1031 | { |
| 1032 | int val; |
| 1033 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1034 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1035 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1038 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1039 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1040 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1043 | 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] | 1044 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1045 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1046 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1047 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1048 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1049 | |
| 1050 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1053 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1054 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1055 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1056 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1057 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1058 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1061 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1062 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1063 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1064 | } |
| 1065 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1066 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1067 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1068 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1069 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1070 | RTL_W32(tp, ERIDR, val); |
| 1071 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1072 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1073 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1076 | 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] | 1077 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1078 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1079 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1080 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1081 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1082 | } |
| 1083 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1084 | 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] | 1085 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1086 | { |
| 1087 | u32 val; |
| 1088 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1089 | val = rtl_eri_read(tp, addr, type); |
| 1090 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1091 | } |
| 1092 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1093 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1094 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1095 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1096 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1097 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1101 | { |
| 1102 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1103 | } |
| 1104 | |
| 1105 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1106 | { |
| 1107 | switch (tp->mac_version) { |
| 1108 | case RTL_GIGA_MAC_VER_27: |
| 1109 | case RTL_GIGA_MAC_VER_28: |
| 1110 | case RTL_GIGA_MAC_VER_31: |
| 1111 | return r8168dp_ocp_read(tp, mask, reg); |
| 1112 | case RTL_GIGA_MAC_VER_49: |
| 1113 | case RTL_GIGA_MAC_VER_50: |
| 1114 | case RTL_GIGA_MAC_VER_51: |
| 1115 | return r8168ep_ocp_read(tp, mask, reg); |
| 1116 | default: |
| 1117 | BUG(); |
| 1118 | return ~0; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1123 | u32 data) |
| 1124 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1125 | RTL_W32(tp, OCPDR, data); |
| 1126 | 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] | 1127 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1128 | } |
| 1129 | |
| 1130 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1131 | u32 data) |
| 1132 | { |
| 1133 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1134 | data, ERIAR_OOB); |
| 1135 | } |
| 1136 | |
| 1137 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1138 | { |
| 1139 | switch (tp->mac_version) { |
| 1140 | case RTL_GIGA_MAC_VER_27: |
| 1141 | case RTL_GIGA_MAC_VER_28: |
| 1142 | case RTL_GIGA_MAC_VER_31: |
| 1143 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1144 | break; |
| 1145 | case RTL_GIGA_MAC_VER_49: |
| 1146 | case RTL_GIGA_MAC_VER_50: |
| 1147 | case RTL_GIGA_MAC_VER_51: |
| 1148 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1149 | break; |
| 1150 | default: |
| 1151 | BUG(); |
| 1152 | break; |
| 1153 | } |
| 1154 | } |
| 1155 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1156 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1157 | { |
| 1158 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1159 | |
| 1160 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1161 | } |
| 1162 | |
| 1163 | #define OOB_CMD_RESET 0x00 |
| 1164 | #define OOB_CMD_DRIVER_START 0x05 |
| 1165 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1166 | |
| 1167 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1168 | { |
| 1169 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1170 | } |
| 1171 | |
| 1172 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1173 | { |
| 1174 | u16 reg; |
| 1175 | |
| 1176 | reg = rtl8168_get_ocp_reg(tp); |
| 1177 | |
| 1178 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1179 | } |
| 1180 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1181 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1182 | { |
| 1183 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1184 | } |
| 1185 | |
| 1186 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1187 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1188 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1189 | } |
| 1190 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1191 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1192 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1193 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1194 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1195 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1196 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1197 | } |
| 1198 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1199 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1200 | { |
| 1201 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1202 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1203 | } |
| 1204 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1205 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1206 | { |
| 1207 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1208 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1209 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1210 | } |
| 1211 | |
| 1212 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1213 | { |
| 1214 | switch (tp->mac_version) { |
| 1215 | case RTL_GIGA_MAC_VER_27: |
| 1216 | case RTL_GIGA_MAC_VER_28: |
| 1217 | case RTL_GIGA_MAC_VER_31: |
| 1218 | rtl8168dp_driver_start(tp); |
| 1219 | break; |
| 1220 | case RTL_GIGA_MAC_VER_49: |
| 1221 | case RTL_GIGA_MAC_VER_50: |
| 1222 | case RTL_GIGA_MAC_VER_51: |
| 1223 | rtl8168ep_driver_start(tp); |
| 1224 | break; |
| 1225 | default: |
| 1226 | BUG(); |
| 1227 | break; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1232 | { |
| 1233 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1234 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1235 | } |
| 1236 | |
| 1237 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1238 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1239 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1240 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1241 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1242 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1243 | } |
| 1244 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1245 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1246 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1247 | switch (tp->mac_version) { |
| 1248 | case RTL_GIGA_MAC_VER_27: |
| 1249 | case RTL_GIGA_MAC_VER_28: |
| 1250 | case RTL_GIGA_MAC_VER_31: |
| 1251 | rtl8168dp_driver_stop(tp); |
| 1252 | break; |
| 1253 | case RTL_GIGA_MAC_VER_49: |
| 1254 | case RTL_GIGA_MAC_VER_50: |
| 1255 | case RTL_GIGA_MAC_VER_51: |
| 1256 | rtl8168ep_driver_stop(tp); |
| 1257 | break; |
| 1258 | default: |
| 1259 | BUG(); |
| 1260 | break; |
| 1261 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1264 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1265 | { |
| 1266 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1267 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1268 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1269 | } |
| 1270 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1271 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1272 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1273 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1276 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1277 | { |
| 1278 | switch (tp->mac_version) { |
| 1279 | case RTL_GIGA_MAC_VER_27: |
| 1280 | case RTL_GIGA_MAC_VER_28: |
| 1281 | case RTL_GIGA_MAC_VER_31: |
| 1282 | return r8168dp_check_dash(tp); |
| 1283 | case RTL_GIGA_MAC_VER_49: |
| 1284 | case RTL_GIGA_MAC_VER_50: |
| 1285 | case RTL_GIGA_MAC_VER_51: |
| 1286 | return r8168ep_check_dash(tp); |
| 1287 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1288 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1292 | struct exgmac_reg { |
| 1293 | u16 addr; |
| 1294 | u16 mask; |
| 1295 | u32 val; |
| 1296 | }; |
| 1297 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1298 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1299 | const struct exgmac_reg *r, int len) |
| 1300 | { |
| 1301 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1302 | 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] | 1303 | r++; |
| 1304 | } |
| 1305 | } |
| 1306 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1307 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1308 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1309 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1310 | } |
| 1311 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1312 | 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] | 1313 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1314 | 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] | 1315 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1316 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1317 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1320 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1321 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1322 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1326 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1327 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1328 | mmiowb(); |
| 1329 | } |
| 1330 | |
| 1331 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1332 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1333 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1334 | mmiowb(); |
| 1335 | } |
| 1336 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1337 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1338 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1339 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1340 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1341 | static void rtl_irq_enable(struct rtl8169_private *tp) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1342 | { |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 1343 | RTL_W16(tp, IntrMask, RTL_EVENT_NAPI | tp->event_slow); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1344 | } |
| 1345 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1346 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1348 | rtl_irq_disable(tp); |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 1349 | rtl_ack_events(tp, 0xffff); |
| 1350 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1351 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1354 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1355 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1356 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1357 | struct phy_device *phydev = dev->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1358 | |
| 1359 | if (!netif_running(dev)) |
| 1360 | return; |
| 1361 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1362 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1363 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1364 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1365 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1366 | ERIAR_EXGMAC); |
| 1367 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1368 | ERIAR_EXGMAC); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1369 | } else if (phydev->speed == SPEED_100) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1370 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1371 | ERIAR_EXGMAC); |
| 1372 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1373 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1374 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1375 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1376 | ERIAR_EXGMAC); |
| 1377 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1378 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1379 | } |
| 1380 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1381 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1382 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1383 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1384 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1385 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1386 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1387 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1388 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1389 | ERIAR_EXGMAC); |
| 1390 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1391 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1392 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1393 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1394 | ERIAR_EXGMAC); |
| 1395 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1396 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1397 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1398 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1399 | if (phydev->speed == SPEED_10) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1400 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1401 | ERIAR_EXGMAC); |
| 1402 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1403 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1404 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1405 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1406 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1407 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1411 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1412 | |
| 1413 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1414 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1415 | u8 options; |
| 1416 | u32 wolopts = 0; |
| 1417 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1418 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1419 | if (!(options & PMEnable)) |
| 1420 | return 0; |
| 1421 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1422 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1423 | if (options & LinkUp) |
| 1424 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1425 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1426 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1427 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1428 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1429 | wolopts |= WAKE_MAGIC; |
| 1430 | break; |
| 1431 | default: |
| 1432 | if (options & MagicPacket) |
| 1433 | wolopts |= WAKE_MAGIC; |
| 1434 | break; |
| 1435 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1436 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1437 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1438 | if (options & UWF) |
| 1439 | wolopts |= WAKE_UCAST; |
| 1440 | if (options & BWF) |
| 1441 | wolopts |= WAKE_BCAST; |
| 1442 | if (options & MWF) |
| 1443 | wolopts |= WAKE_MCAST; |
| 1444 | |
| 1445 | return wolopts; |
| 1446 | } |
| 1447 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1448 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1449 | { |
| 1450 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1451 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1452 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1453 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1454 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1455 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1456 | } |
| 1457 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1458 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1459 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1460 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1461 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1462 | u32 opt; |
| 1463 | u16 reg; |
| 1464 | u8 mask; |
| 1465 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1466 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1467 | { WAKE_UCAST, Config5, UWF }, |
| 1468 | { WAKE_BCAST, Config5, BWF }, |
| 1469 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1470 | { WAKE_ANY, Config5, LanWake }, |
| 1471 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1472 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1473 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1474 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1475 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1476 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1477 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1478 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1479 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1480 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1481 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1482 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1483 | 0x0dc, |
| 1484 | ERIAR_MASK_0100, |
| 1485 | MagicPacket_v2, |
| 1486 | 0x0000, |
| 1487 | ERIAR_EXGMAC); |
| 1488 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1489 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1490 | 0x0dc, |
| 1491 | ERIAR_MASK_0100, |
| 1492 | 0x0000, |
| 1493 | MagicPacket_v2, |
| 1494 | ERIAR_EXGMAC); |
| 1495 | break; |
| 1496 | default: |
| 1497 | tmp = ARRAY_SIZE(cfg); |
| 1498 | break; |
| 1499 | } |
| 1500 | |
| 1501 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1502 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1503 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1504 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1505 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1508 | switch (tp->mac_version) { |
| 1509 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1510 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1511 | if (wolopts) |
| 1512 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1513 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1514 | break; |
| 1515 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1516 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1517 | if (wolopts) |
| 1518 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1519 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1520 | break; |
| 1521 | } |
| 1522 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1523 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1527 | { |
| 1528 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1529 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1530 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1531 | if (wol->wolopts & ~WAKE_ANY) |
| 1532 | return -EINVAL; |
| 1533 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1534 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1535 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1536 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1537 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1538 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1539 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1540 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1541 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1542 | |
| 1543 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1544 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1545 | device_set_wakeup_enable(d, tp->saved_wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1546 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1547 | pm_runtime_put_noidle(d); |
| 1548 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1549 | return 0; |
| 1550 | } |
| 1551 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1552 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1553 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1554 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1555 | } |
| 1556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1558 | struct ethtool_drvinfo *info) |
| 1559 | { |
| 1560 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1561 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1563 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1564 | 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] | 1565 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1566 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1567 | strlcpy(info->fw_version, rtl_fw->version, |
| 1568 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1572 | { |
| 1573 | return R8169_REGS_SIZE; |
| 1574 | } |
| 1575 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1576 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1577 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1579 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1580 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1581 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1582 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1584 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1585 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1586 | features &= ~NETIF_F_IP_CSUM; |
| 1587 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1588 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1591 | static int rtl8169_set_features(struct net_device *dev, |
| 1592 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | { |
| 1594 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1595 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1597 | rtl_lock_work(tp); |
| 1598 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1599 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1600 | if (features & NETIF_F_RXALL) |
| 1601 | rx_config |= (AcceptErr | AcceptRunt); |
| 1602 | else |
| 1603 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1605 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1606 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1607 | if (features & NETIF_F_RXCSUM) |
| 1608 | tp->cp_cmd |= RxChkSum; |
| 1609 | else |
| 1610 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1611 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1612 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1613 | tp->cp_cmd |= RxVlan; |
| 1614 | else |
| 1615 | tp->cp_cmd &= ~RxVlan; |
| 1616 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1617 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1618 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1620 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | |
| 1622 | return 0; |
| 1623 | } |
| 1624 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1625 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1627 | return (skb_vlan_tag_present(skb)) ? |
| 1628 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1631 | 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] | 1632 | { |
| 1633 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1635 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1636 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1640 | void *p) |
| 1641 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1642 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1643 | u32 __iomem *data = tp->mmio_addr; |
| 1644 | u32 *dw = p; |
| 1645 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1647 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1648 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1649 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1650 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1653 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1654 | { |
| 1655 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1656 | |
| 1657 | return tp->msg_enable; |
| 1658 | } |
| 1659 | |
| 1660 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1661 | { |
| 1662 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1663 | |
| 1664 | tp->msg_enable = value; |
| 1665 | } |
| 1666 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1667 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1668 | "tx_packets", |
| 1669 | "rx_packets", |
| 1670 | "tx_errors", |
| 1671 | "rx_errors", |
| 1672 | "rx_missed", |
| 1673 | "align_errors", |
| 1674 | "tx_single_collisions", |
| 1675 | "tx_multi_collisions", |
| 1676 | "unicast", |
| 1677 | "broadcast", |
| 1678 | "multicast", |
| 1679 | "tx_aborted", |
| 1680 | "tx_underrun", |
| 1681 | }; |
| 1682 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1683 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1684 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1685 | switch (sset) { |
| 1686 | case ETH_SS_STATS: |
| 1687 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1688 | default: |
| 1689 | return -EOPNOTSUPP; |
| 1690 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1691 | } |
| 1692 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1693 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1694 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1695 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1696 | } |
| 1697 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1698 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1699 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1700 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1701 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1702 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1703 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1704 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1705 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1706 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1707 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1708 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1709 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1710 | } |
| 1711 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1712 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1713 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1714 | /* |
| 1715 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1716 | * tally counters. |
| 1717 | */ |
| 1718 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1719 | return true; |
| 1720 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1721 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1722 | } |
| 1723 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1724 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1725 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1726 | /* |
| 1727 | * Some chips are unable to dump tally counters when the receiver |
| 1728 | * is disabled. |
| 1729 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1730 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1731 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1732 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1733 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1734 | } |
| 1735 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1736 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1737 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1738 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1739 | bool ret = false; |
| 1740 | |
| 1741 | /* |
| 1742 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1743 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1744 | * reset by a power cycle, while the counter values collected by the |
| 1745 | * driver are reset at every driver unload/load cycle. |
| 1746 | * |
| 1747 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1748 | * values, we collect the initial values at first open(*) and use them |
| 1749 | * as offsets to normalize the values returned by @get_stats64. |
| 1750 | * |
| 1751 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1752 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1753 | * set at open time by rtl_hw_start. |
| 1754 | */ |
| 1755 | |
| 1756 | if (tp->tc_offset.inited) |
| 1757 | return true; |
| 1758 | |
| 1759 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1760 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1761 | ret = true; |
| 1762 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1763 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1764 | ret = true; |
| 1765 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1766 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1767 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1768 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1769 | tp->tc_offset.inited = true; |
| 1770 | |
| 1771 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1772 | } |
| 1773 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1774 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1775 | struct ethtool_stats *stats, u64 *data) |
| 1776 | { |
| 1777 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1778 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1779 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1780 | |
| 1781 | ASSERT_RTNL(); |
| 1782 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1783 | pm_runtime_get_noresume(d); |
| 1784 | |
| 1785 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1786 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1787 | |
| 1788 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1789 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1790 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1791 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1792 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1793 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1794 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1795 | data[5] = le16_to_cpu(counters->align_errors); |
| 1796 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1797 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1798 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1799 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1800 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1801 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1802 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1805 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1806 | { |
| 1807 | switch(stringset) { |
| 1808 | case ETH_SS_STATS: |
| 1809 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1810 | break; |
| 1811 | } |
| 1812 | } |
| 1813 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1814 | /* |
| 1815 | * Interrupt coalescing |
| 1816 | * |
| 1817 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1818 | * > 8169, 8168 and 810x line of chipsets |
| 1819 | * |
| 1820 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1821 | * |
| 1822 | * > 2 - the Tx timer unit at gigabit speed |
| 1823 | * |
| 1824 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1825 | * (0xe0) bit 1 and bit 0. |
| 1826 | * |
| 1827 | * For 8169 |
| 1828 | * bit[1:0] \ speed 1000M 100M 10M |
| 1829 | * 0 0 320ns 2.56us 40.96us |
| 1830 | * 0 1 2.56us 20.48us 327.7us |
| 1831 | * 1 0 5.12us 40.96us 655.4us |
| 1832 | * 1 1 10.24us 81.92us 1.31ms |
| 1833 | * |
| 1834 | * For the other |
| 1835 | * bit[1:0] \ speed 1000M 100M 10M |
| 1836 | * 0 0 5us 2.56us 40.96us |
| 1837 | * 0 1 40us 20.48us 327.7us |
| 1838 | * 1 0 80us 40.96us 655.4us |
| 1839 | * 1 1 160us 81.92us 1.31ms |
| 1840 | */ |
| 1841 | |
| 1842 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1843 | struct rtl_coalesce_scale { |
| 1844 | /* Rx / Tx */ |
| 1845 | u32 nsecs[2]; |
| 1846 | }; |
| 1847 | |
| 1848 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1849 | struct rtl_coalesce_info { |
| 1850 | u32 speed; |
| 1851 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1852 | }; |
| 1853 | |
| 1854 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1855 | #define rxtx_x1822(r, t) { \ |
| 1856 | {{(r), (t)}}, \ |
| 1857 | {{(r)*8, (t)*8}}, \ |
| 1858 | {{(r)*8*2, (t)*8*2}}, \ |
| 1859 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1860 | } |
| 1861 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1862 | /* speed delays: rx00 tx00 */ |
| 1863 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1864 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1865 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1866 | { 0 }, |
| 1867 | }; |
| 1868 | |
| 1869 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1870 | /* speed delays: rx00 tx00 */ |
| 1871 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1872 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1873 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1874 | { 0 }, |
| 1875 | }; |
| 1876 | #undef rxtx_x1822 |
| 1877 | |
| 1878 | /* get rx/tx scale vector corresponding to current speed */ |
| 1879 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1880 | { |
| 1881 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1882 | struct ethtool_link_ksettings ecmd; |
| 1883 | const struct rtl_coalesce_info *ci; |
| 1884 | int rc; |
| 1885 | |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 1886 | rc = phy_ethtool_get_link_ksettings(dev, &ecmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1887 | if (rc < 0) |
| 1888 | return ERR_PTR(rc); |
| 1889 | |
| 1890 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 1891 | if (ecmd.base.speed == ci->speed) { |
| 1892 | return ci; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | return ERR_PTR(-ELNRNG); |
| 1897 | } |
| 1898 | |
| 1899 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1900 | { |
| 1901 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1902 | const struct rtl_coalesce_info *ci; |
| 1903 | const struct rtl_coalesce_scale *scale; |
| 1904 | struct { |
| 1905 | u32 *max_frames; |
| 1906 | u32 *usecs; |
| 1907 | } coal_settings [] = { |
| 1908 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1909 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1910 | }, *p = coal_settings; |
| 1911 | int i; |
| 1912 | u16 w; |
| 1913 | |
| 1914 | memset(ec, 0, sizeof(*ec)); |
| 1915 | |
| 1916 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1917 | ci = rtl_coalesce_info(dev); |
| 1918 | if (IS_ERR(ci)) |
| 1919 | return PTR_ERR(ci); |
| 1920 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1921 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1922 | |
| 1923 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1924 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1925 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1926 | w >>= RTL_COALESCE_SHIFT; |
| 1927 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1928 | } |
| 1929 | |
| 1930 | for (i = 0; i < 2; i++) { |
| 1931 | p = coal_settings + i; |
| 1932 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1933 | |
| 1934 | /* |
| 1935 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1936 | * max_frames to 0. |
| 1937 | */ |
| 1938 | if (!*p->usecs && !*p->max_frames) |
| 1939 | *p->max_frames = 1; |
| 1940 | } |
| 1941 | |
| 1942 | return 0; |
| 1943 | } |
| 1944 | |
| 1945 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1946 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1947 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1948 | { |
| 1949 | const struct rtl_coalesce_info *ci; |
| 1950 | u16 i; |
| 1951 | |
| 1952 | ci = rtl_coalesce_info(dev); |
| 1953 | if (IS_ERR(ci)) |
| 1954 | return ERR_CAST(ci); |
| 1955 | |
| 1956 | for (i = 0; i < 4; i++) { |
| 1957 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1958 | ci->scalev[i].nsecs[1]); |
| 1959 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1960 | *cp01 = i; |
| 1961 | return &ci->scalev[i]; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | return ERR_PTR(-EINVAL); |
| 1966 | } |
| 1967 | |
| 1968 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1969 | { |
| 1970 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1971 | const struct rtl_coalesce_scale *scale; |
| 1972 | struct { |
| 1973 | u32 frames; |
| 1974 | u32 usecs; |
| 1975 | } coal_settings [] = { |
| 1976 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1977 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1978 | }, *p = coal_settings; |
| 1979 | u16 w = 0, cp01; |
| 1980 | int i; |
| 1981 | |
| 1982 | scale = rtl_coalesce_choose_scale(dev, |
| 1983 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1984 | if (IS_ERR(scale)) |
| 1985 | return PTR_ERR(scale); |
| 1986 | |
| 1987 | for (i = 0; i < 2; i++, p++) { |
| 1988 | u32 units; |
| 1989 | |
| 1990 | /* |
| 1991 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1992 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1993 | * |
| 1994 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 1995 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 1996 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 1997 | * |
| 1998 | * since ethtool sends to kernel whole ethtool_coalesce |
| 1999 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2000 | * we'll reject it below in `frames % 4 != 0`. |
| 2001 | */ |
| 2002 | if (p->frames == 1) { |
| 2003 | p->frames = 0; |
| 2004 | } |
| 2005 | |
| 2006 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2007 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2008 | return -EINVAL; |
| 2009 | |
| 2010 | w <<= RTL_COALESCE_SHIFT; |
| 2011 | w |= units; |
| 2012 | w <<= RTL_COALESCE_SHIFT; |
| 2013 | w |= p->frames >> 2; |
| 2014 | } |
| 2015 | |
| 2016 | rtl_lock_work(tp); |
| 2017 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2018 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2019 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 2020 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2021 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2022 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2023 | |
| 2024 | rtl_unlock_work(tp); |
| 2025 | |
| 2026 | return 0; |
| 2027 | } |
| 2028 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2029 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2031 | .get_regs_len = rtl8169_get_regs_len, |
| 2032 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2033 | .get_coalesce = rtl_get_coalesce, |
| 2034 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2035 | .get_msglevel = rtl8169_get_msglevel, |
| 2036 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2038 | .get_wol = rtl8169_get_wol, |
| 2039 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2040 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2041 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2042 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2043 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2044 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2045 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2046 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | }; |
| 2048 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2049 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2050 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2052 | /* |
| 2053 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2054 | * but they can be identified more specifically through the test below |
| 2055 | * if needed: |
| 2056 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2057 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2058 | * |
| 2059 | * Same thing for the 8101Eb and the 8101Ec: |
| 2060 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2061 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2062 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2063 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2065 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | int mac_version; |
| 2067 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2068 | /* 8168EP family. */ |
| 2069 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2070 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2071 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2072 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2073 | /* 8168H family. */ |
| 2074 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2075 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2076 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2077 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2078 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2079 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2080 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2081 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2082 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2083 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2084 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2085 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2086 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2087 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2088 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2089 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2090 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2091 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2092 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2093 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2094 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2095 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2096 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2097 | /* 8168DP family. */ |
| 2098 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2099 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2100 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2101 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2102 | /* 8168C family. */ |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2103 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2104 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2105 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2106 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2107 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2108 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2109 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2110 | |
| 2111 | /* 8168B family. */ |
| 2112 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2113 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2114 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2115 | |
| 2116 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2117 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2118 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2119 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2120 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2121 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2122 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2123 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2124 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2125 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2126 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2127 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2128 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2129 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2130 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2131 | /* FIXME: where did these entries come from ? -- FR */ |
| 2132 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2133 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2134 | |
| 2135 | /* 8110 family. */ |
| 2136 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2137 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2138 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2139 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2140 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2141 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2142 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2143 | /* Catch-all */ |
| 2144 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2145 | }; |
| 2146 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | u32 reg; |
| 2148 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2149 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2150 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | p++; |
| 2152 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2153 | |
| 2154 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2155 | dev_notice(tp_to_dev(tp), |
| 2156 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2157 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2158 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2159 | tp->mac_version = tp->supports_gmii ? |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2160 | RTL_GIGA_MAC_VER_42 : |
| 2161 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2162 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2163 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2164 | RTL_GIGA_MAC_VER_45 : |
| 2165 | RTL_GIGA_MAC_VER_47; |
| 2166 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2167 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2168 | RTL_GIGA_MAC_VER_46 : |
| 2169 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2174 | { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 2175 | netif_dbg(tp, drv, tp->dev, "mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2178 | struct phy_reg { |
| 2179 | u16 reg; |
| 2180 | u16 val; |
| 2181 | }; |
| 2182 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2183 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2184 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2185 | { |
| 2186 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2187 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2188 | regs++; |
| 2189 | } |
| 2190 | } |
| 2191 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2192 | #define PHY_READ 0x00000000 |
| 2193 | #define PHY_DATA_OR 0x10000000 |
| 2194 | #define PHY_DATA_AND 0x20000000 |
| 2195 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2196 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2197 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2198 | #define PHY_WRITE 0x80000000 |
| 2199 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2200 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2201 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2202 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2203 | #define PHY_SKIPN 0xd0000000 |
| 2204 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2205 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2206 | struct fw_info { |
| 2207 | u32 magic; |
| 2208 | char version[RTL_VER_SIZE]; |
| 2209 | __le32 fw_start; |
| 2210 | __le32 fw_len; |
| 2211 | u8 chksum; |
| 2212 | } __packed; |
| 2213 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2214 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2215 | |
| 2216 | 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] | 2217 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2218 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2219 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2220 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2221 | char *version = rtl_fw->version; |
| 2222 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2223 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2224 | if (fw->size < FW_OPCODE_SIZE) |
| 2225 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2226 | |
| 2227 | if (!fw_info->magic) { |
| 2228 | size_t i, size, start; |
| 2229 | u8 checksum = 0; |
| 2230 | |
| 2231 | if (fw->size < sizeof(*fw_info)) |
| 2232 | goto out; |
| 2233 | |
| 2234 | for (i = 0; i < fw->size; i++) |
| 2235 | checksum += fw->data[i]; |
| 2236 | if (checksum != 0) |
| 2237 | goto out; |
| 2238 | |
| 2239 | start = le32_to_cpu(fw_info->fw_start); |
| 2240 | if (start > fw->size) |
| 2241 | goto out; |
| 2242 | |
| 2243 | size = le32_to_cpu(fw_info->fw_len); |
| 2244 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2245 | goto out; |
| 2246 | |
| 2247 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2248 | |
| 2249 | pa->code = (__le32 *)(fw->data + start); |
| 2250 | pa->size = size; |
| 2251 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2252 | if (fw->size % FW_OPCODE_SIZE) |
| 2253 | goto out; |
| 2254 | |
| 2255 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2256 | |
| 2257 | pa->code = (__le32 *)fw->data; |
| 2258 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2259 | } |
| 2260 | version[RTL_VER_SIZE - 1] = 0; |
| 2261 | |
| 2262 | rc = true; |
| 2263 | out: |
| 2264 | return rc; |
| 2265 | } |
| 2266 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2267 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2268 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2269 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2270 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2271 | size_t index; |
| 2272 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2273 | for (index = 0; index < pa->size; index++) { |
| 2274 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2275 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2276 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2277 | switch(action & 0xf0000000) { |
| 2278 | case PHY_READ: |
| 2279 | case PHY_DATA_OR: |
| 2280 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2281 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2282 | case PHY_CLEAR_READCOUNT: |
| 2283 | case PHY_WRITE: |
| 2284 | case PHY_WRITE_PREVIOUS: |
| 2285 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2288 | case PHY_BJMPN: |
| 2289 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2290 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2291 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2292 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2293 | } |
| 2294 | break; |
| 2295 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2296 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2297 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2298 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2299 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2300 | } |
| 2301 | break; |
| 2302 | case PHY_COMP_EQ_SKIPN: |
| 2303 | case PHY_COMP_NEQ_SKIPN: |
| 2304 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2305 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2306 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2307 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2308 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2309 | } |
| 2310 | break; |
| 2311 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2312 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2313 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2314 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2315 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2316 | } |
| 2317 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2318 | rc = true; |
| 2319 | out: |
| 2320 | return rc; |
| 2321 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2322 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2323 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2324 | { |
| 2325 | struct net_device *dev = tp->dev; |
| 2326 | int rc = -EINVAL; |
| 2327 | |
| 2328 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2329 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2330 | goto out; |
| 2331 | } |
| 2332 | |
| 2333 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2334 | rc = 0; |
| 2335 | out: |
| 2336 | return rc; |
| 2337 | } |
| 2338 | |
| 2339 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2340 | { |
| 2341 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2342 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2343 | u32 predata, count; |
| 2344 | size_t index; |
| 2345 | |
| 2346 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2347 | org.write = ops->write; |
| 2348 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2349 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2350 | for (index = 0; index < pa->size; ) { |
| 2351 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2352 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2353 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2354 | |
| 2355 | if (!action) |
| 2356 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2357 | |
| 2358 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2359 | case PHY_READ: |
| 2360 | predata = rtl_readphy(tp, regno); |
| 2361 | count++; |
| 2362 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2363 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2364 | case PHY_DATA_OR: |
| 2365 | predata |= data; |
| 2366 | index++; |
| 2367 | break; |
| 2368 | case PHY_DATA_AND: |
| 2369 | predata &= data; |
| 2370 | index++; |
| 2371 | break; |
| 2372 | case PHY_BJMPN: |
| 2373 | index -= regno; |
| 2374 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2375 | case PHY_MDIO_CHG: |
| 2376 | if (data == 0) { |
| 2377 | ops->write = org.write; |
| 2378 | ops->read = org.read; |
| 2379 | } else if (data == 1) { |
| 2380 | ops->write = mac_mcu_write; |
| 2381 | ops->read = mac_mcu_read; |
| 2382 | } |
| 2383 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2384 | index++; |
| 2385 | break; |
| 2386 | case PHY_CLEAR_READCOUNT: |
| 2387 | count = 0; |
| 2388 | index++; |
| 2389 | break; |
| 2390 | case PHY_WRITE: |
| 2391 | rtl_writephy(tp, regno, data); |
| 2392 | index++; |
| 2393 | break; |
| 2394 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2395 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2396 | break; |
| 2397 | case PHY_COMP_EQ_SKIPN: |
| 2398 | if (predata == data) |
| 2399 | index += regno; |
| 2400 | index++; |
| 2401 | break; |
| 2402 | case PHY_COMP_NEQ_SKIPN: |
| 2403 | if (predata != data) |
| 2404 | index += regno; |
| 2405 | index++; |
| 2406 | break; |
| 2407 | case PHY_WRITE_PREVIOUS: |
| 2408 | rtl_writephy(tp, regno, predata); |
| 2409 | index++; |
| 2410 | break; |
| 2411 | case PHY_SKIPN: |
| 2412 | index += regno + 1; |
| 2413 | break; |
| 2414 | case PHY_DELAY_MS: |
| 2415 | mdelay(data); |
| 2416 | index++; |
| 2417 | break; |
| 2418 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2419 | default: |
| 2420 | BUG(); |
| 2421 | } |
| 2422 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2423 | |
| 2424 | ops->write = org.write; |
| 2425 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2428 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2429 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2430 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2431 | release_firmware(tp->rtl_fw->fw); |
| 2432 | kfree(tp->rtl_fw); |
| 2433 | } |
| 2434 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2437 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2438 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2439 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2440 | |
| 2441 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2442 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2443 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2447 | { |
| 2448 | if (rtl_readphy(tp, reg) != val) |
| 2449 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2450 | else |
| 2451 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2454 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2456 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2457 | { 0x1f, 0x0001 }, |
| 2458 | { 0x06, 0x006e }, |
| 2459 | { 0x08, 0x0708 }, |
| 2460 | { 0x15, 0x4000 }, |
| 2461 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2463 | { 0x1f, 0x0001 }, |
| 2464 | { 0x03, 0x00a1 }, |
| 2465 | { 0x02, 0x0008 }, |
| 2466 | { 0x01, 0x0120 }, |
| 2467 | { 0x00, 0x1000 }, |
| 2468 | { 0x04, 0x0800 }, |
| 2469 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2471 | { 0x03, 0xff41 }, |
| 2472 | { 0x02, 0xdf60 }, |
| 2473 | { 0x01, 0x0140 }, |
| 2474 | { 0x00, 0x0077 }, |
| 2475 | { 0x04, 0x7800 }, |
| 2476 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2478 | { 0x03, 0x802f }, |
| 2479 | { 0x02, 0x4f02 }, |
| 2480 | { 0x01, 0x0409 }, |
| 2481 | { 0x00, 0xf0f9 }, |
| 2482 | { 0x04, 0x9800 }, |
| 2483 | { 0x04, 0x9000 }, |
| 2484 | |
| 2485 | { 0x03, 0xdf01 }, |
| 2486 | { 0x02, 0xdf20 }, |
| 2487 | { 0x01, 0xff95 }, |
| 2488 | { 0x00, 0xba00 }, |
| 2489 | { 0x04, 0xa800 }, |
| 2490 | { 0x04, 0xa000 }, |
| 2491 | |
| 2492 | { 0x03, 0xff41 }, |
| 2493 | { 0x02, 0xdf20 }, |
| 2494 | { 0x01, 0x0140 }, |
| 2495 | { 0x00, 0x00bb }, |
| 2496 | { 0x04, 0xb800 }, |
| 2497 | { 0x04, 0xb000 }, |
| 2498 | |
| 2499 | { 0x03, 0xdf41 }, |
| 2500 | { 0x02, 0xdc60 }, |
| 2501 | { 0x01, 0x6340 }, |
| 2502 | { 0x00, 0x007d }, |
| 2503 | { 0x04, 0xd800 }, |
| 2504 | { 0x04, 0xd000 }, |
| 2505 | |
| 2506 | { 0x03, 0xdf01 }, |
| 2507 | { 0x02, 0xdf20 }, |
| 2508 | { 0x01, 0x100a }, |
| 2509 | { 0x00, 0xa0ff }, |
| 2510 | { 0x04, 0xf800 }, |
| 2511 | { 0x04, 0xf000 }, |
| 2512 | |
| 2513 | { 0x1f, 0x0000 }, |
| 2514 | { 0x0b, 0x0000 }, |
| 2515 | { 0x00, 0x9200 } |
| 2516 | }; |
| 2517 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2518 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2521 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2522 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2523 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2524 | { 0x1f, 0x0002 }, |
| 2525 | { 0x01, 0x90d0 }, |
| 2526 | { 0x1f, 0x0000 } |
| 2527 | }; |
| 2528 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2529 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2530 | } |
| 2531 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2532 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2533 | { |
| 2534 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2535 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2536 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2537 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2538 | return; |
| 2539 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2540 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2541 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2542 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2543 | } |
| 2544 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2545 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2546 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2547 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2548 | { 0x1f, 0x0001 }, |
| 2549 | { 0x04, 0x0000 }, |
| 2550 | { 0x03, 0x00a1 }, |
| 2551 | { 0x02, 0x0008 }, |
| 2552 | { 0x01, 0x0120 }, |
| 2553 | { 0x00, 0x1000 }, |
| 2554 | { 0x04, 0x0800 }, |
| 2555 | { 0x04, 0x9000 }, |
| 2556 | { 0x03, 0x802f }, |
| 2557 | { 0x02, 0x4f02 }, |
| 2558 | { 0x01, 0x0409 }, |
| 2559 | { 0x00, 0xf099 }, |
| 2560 | { 0x04, 0x9800 }, |
| 2561 | { 0x04, 0xa000 }, |
| 2562 | { 0x03, 0xdf01 }, |
| 2563 | { 0x02, 0xdf20 }, |
| 2564 | { 0x01, 0xff95 }, |
| 2565 | { 0x00, 0xba00 }, |
| 2566 | { 0x04, 0xa800 }, |
| 2567 | { 0x04, 0xf000 }, |
| 2568 | { 0x03, 0xdf01 }, |
| 2569 | { 0x02, 0xdf20 }, |
| 2570 | { 0x01, 0x101a }, |
| 2571 | { 0x00, 0xa0ff }, |
| 2572 | { 0x04, 0xf800 }, |
| 2573 | { 0x04, 0x0000 }, |
| 2574 | { 0x1f, 0x0000 }, |
| 2575 | |
| 2576 | { 0x1f, 0x0001 }, |
| 2577 | { 0x10, 0xf41b }, |
| 2578 | { 0x14, 0xfb54 }, |
| 2579 | { 0x18, 0xf5c7 }, |
| 2580 | { 0x1f, 0x0000 }, |
| 2581 | |
| 2582 | { 0x1f, 0x0001 }, |
| 2583 | { 0x17, 0x0cc0 }, |
| 2584 | { 0x1f, 0x0000 } |
| 2585 | }; |
| 2586 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2587 | 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] | 2588 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2589 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2592 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2593 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2594 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2595 | { 0x1f, 0x0001 }, |
| 2596 | { 0x04, 0x0000 }, |
| 2597 | { 0x03, 0x00a1 }, |
| 2598 | { 0x02, 0x0008 }, |
| 2599 | { 0x01, 0x0120 }, |
| 2600 | { 0x00, 0x1000 }, |
| 2601 | { 0x04, 0x0800 }, |
| 2602 | { 0x04, 0x9000 }, |
| 2603 | { 0x03, 0x802f }, |
| 2604 | { 0x02, 0x4f02 }, |
| 2605 | { 0x01, 0x0409 }, |
| 2606 | { 0x00, 0xf099 }, |
| 2607 | { 0x04, 0x9800 }, |
| 2608 | { 0x04, 0xa000 }, |
| 2609 | { 0x03, 0xdf01 }, |
| 2610 | { 0x02, 0xdf20 }, |
| 2611 | { 0x01, 0xff95 }, |
| 2612 | { 0x00, 0xba00 }, |
| 2613 | { 0x04, 0xa800 }, |
| 2614 | { 0x04, 0xf000 }, |
| 2615 | { 0x03, 0xdf01 }, |
| 2616 | { 0x02, 0xdf20 }, |
| 2617 | { 0x01, 0x101a }, |
| 2618 | { 0x00, 0xa0ff }, |
| 2619 | { 0x04, 0xf800 }, |
| 2620 | { 0x04, 0x0000 }, |
| 2621 | { 0x1f, 0x0000 }, |
| 2622 | |
| 2623 | { 0x1f, 0x0001 }, |
| 2624 | { 0x0b, 0x8480 }, |
| 2625 | { 0x1f, 0x0000 }, |
| 2626 | |
| 2627 | { 0x1f, 0x0001 }, |
| 2628 | { 0x18, 0x67c7 }, |
| 2629 | { 0x04, 0x2000 }, |
| 2630 | { 0x03, 0x002f }, |
| 2631 | { 0x02, 0x4360 }, |
| 2632 | { 0x01, 0x0109 }, |
| 2633 | { 0x00, 0x3022 }, |
| 2634 | { 0x04, 0x2800 }, |
| 2635 | { 0x1f, 0x0000 }, |
| 2636 | |
| 2637 | { 0x1f, 0x0001 }, |
| 2638 | { 0x17, 0x0cc0 }, |
| 2639 | { 0x1f, 0x0000 } |
| 2640 | }; |
| 2641 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2642 | 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] | 2643 | } |
| 2644 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2645 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2646 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2647 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2648 | { 0x10, 0xf41b }, |
| 2649 | { 0x1f, 0x0000 } |
| 2650 | }; |
| 2651 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2652 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2653 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2654 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2655 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2656 | } |
| 2657 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2658 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2659 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2660 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2661 | { 0x1f, 0x0001 }, |
| 2662 | { 0x10, 0xf41b }, |
| 2663 | { 0x1f, 0x0000 } |
| 2664 | }; |
| 2665 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2666 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2667 | } |
| 2668 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2669 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2670 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2671 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2672 | { 0x1f, 0x0000 }, |
| 2673 | { 0x1d, 0x0f00 }, |
| 2674 | { 0x1f, 0x0002 }, |
| 2675 | { 0x0c, 0x1ec8 }, |
| 2676 | { 0x1f, 0x0000 } |
| 2677 | }; |
| 2678 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2679 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2680 | } |
| 2681 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2682 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2683 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2684 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2685 | { 0x1f, 0x0001 }, |
| 2686 | { 0x1d, 0x3d98 }, |
| 2687 | { 0x1f, 0x0000 } |
| 2688 | }; |
| 2689 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2690 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2691 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2692 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2693 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2694 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2695 | } |
| 2696 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2697 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2698 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2699 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2700 | { 0x1f, 0x0001 }, |
| 2701 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2702 | { 0x1f, 0x0002 }, |
| 2703 | { 0x00, 0x88d4 }, |
| 2704 | { 0x01, 0x82b1 }, |
| 2705 | { 0x03, 0x7002 }, |
| 2706 | { 0x08, 0x9e30 }, |
| 2707 | { 0x09, 0x01f0 }, |
| 2708 | { 0x0a, 0x5500 }, |
| 2709 | { 0x0c, 0x00c8 }, |
| 2710 | { 0x1f, 0x0003 }, |
| 2711 | { 0x12, 0xc096 }, |
| 2712 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2713 | { 0x1f, 0x0000 }, |
| 2714 | { 0x1f, 0x0000 }, |
| 2715 | { 0x09, 0x2000 }, |
| 2716 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2717 | }; |
| 2718 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2719 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2720 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2721 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2722 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2723 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2724 | } |
| 2725 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2726 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2727 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2728 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2729 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2730 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2731 | { 0x03, 0x802f }, |
| 2732 | { 0x02, 0x4f02 }, |
| 2733 | { 0x01, 0x0409 }, |
| 2734 | { 0x00, 0xf099 }, |
| 2735 | { 0x04, 0x9800 }, |
| 2736 | { 0x04, 0x9000 }, |
| 2737 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2738 | { 0x1f, 0x0002 }, |
| 2739 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2740 | { 0x06, 0x0761 }, |
| 2741 | { 0x1f, 0x0003 }, |
| 2742 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2743 | { 0x1f, 0x0000 } |
| 2744 | }; |
| 2745 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2746 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2747 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2748 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2749 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2750 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2751 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2752 | } |
| 2753 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2754 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2755 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2756 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2757 | { 0x1f, 0x0001 }, |
| 2758 | { 0x12, 0x2300 }, |
| 2759 | { 0x1d, 0x3d98 }, |
| 2760 | { 0x1f, 0x0002 }, |
| 2761 | { 0x0c, 0x7eb8 }, |
| 2762 | { 0x06, 0x5461 }, |
| 2763 | { 0x1f, 0x0003 }, |
| 2764 | { 0x16, 0x0f0a }, |
| 2765 | { 0x1f, 0x0000 } |
| 2766 | }; |
| 2767 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2768 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2769 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2770 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2771 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2772 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2773 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2774 | } |
| 2775 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2776 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2777 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2778 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2779 | } |
| 2780 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2781 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2782 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2783 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2784 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2785 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2786 | { 0x06, 0x4064 }, |
| 2787 | { 0x07, 0x2863 }, |
| 2788 | { 0x08, 0x059c }, |
| 2789 | { 0x09, 0x26b4 }, |
| 2790 | { 0x0a, 0x6a19 }, |
| 2791 | { 0x0b, 0xdcc8 }, |
| 2792 | { 0x10, 0xf06d }, |
| 2793 | { 0x14, 0x7f68 }, |
| 2794 | { 0x18, 0x7fd9 }, |
| 2795 | { 0x1c, 0xf0ff }, |
| 2796 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2797 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2798 | { 0x12, 0xf49f }, |
| 2799 | { 0x13, 0x070b }, |
| 2800 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2801 | { 0x14, 0x94c0 }, |
| 2802 | |
| 2803 | /* |
| 2804 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2805 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2806 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2807 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2808 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2809 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2810 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2811 | { 0x06, 0x5561 }, |
| 2812 | |
| 2813 | /* |
| 2814 | * Can not link to 1Gbps with bad cable |
| 2815 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2816 | */ |
| 2817 | { 0x1f, 0x0001 }, |
| 2818 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2819 | |
| 2820 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2821 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2822 | }; |
| 2823 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2824 | 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] | 2825 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2826 | /* |
| 2827 | * Rx Error Issue |
| 2828 | * Fine Tune Switching regulator parameter |
| 2829 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2830 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2831 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2832 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2833 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2834 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2835 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2836 | { 0x1f, 0x0002 }, |
| 2837 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2838 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2839 | { 0x05, 0x8330 }, |
| 2840 | { 0x06, 0x669a }, |
| 2841 | { 0x1f, 0x0002 } |
| 2842 | }; |
| 2843 | int val; |
| 2844 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2845 | 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] | 2846 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2847 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2848 | |
| 2849 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2850 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2851 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2852 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2853 | }; |
| 2854 | int i; |
| 2855 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2856 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2857 | |
| 2858 | val &= 0xff00; |
| 2859 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2860 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2861 | } |
| 2862 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2863 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2864 | { 0x1f, 0x0002 }, |
| 2865 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2866 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2867 | { 0x05, 0x8330 }, |
| 2868 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2869 | }; |
| 2870 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2871 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2872 | } |
| 2873 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2874 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2875 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2876 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2877 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2878 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2879 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2880 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2881 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2882 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2883 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2884 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2885 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2886 | |
| 2887 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2888 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2889 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2892 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2893 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2894 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2895 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2896 | { 0x1f, 0x0001 }, |
| 2897 | { 0x06, 0x4064 }, |
| 2898 | { 0x07, 0x2863 }, |
| 2899 | { 0x08, 0x059c }, |
| 2900 | { 0x09, 0x26b4 }, |
| 2901 | { 0x0a, 0x6a19 }, |
| 2902 | { 0x0b, 0xdcc8 }, |
| 2903 | { 0x10, 0xf06d }, |
| 2904 | { 0x14, 0x7f68 }, |
| 2905 | { 0x18, 0x7fd9 }, |
| 2906 | { 0x1c, 0xf0ff }, |
| 2907 | { 0x1d, 0x3d9c }, |
| 2908 | { 0x1f, 0x0003 }, |
| 2909 | { 0x12, 0xf49f }, |
| 2910 | { 0x13, 0x070b }, |
| 2911 | { 0x1a, 0x05ad }, |
| 2912 | { 0x14, 0x94c0 }, |
| 2913 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2914 | /* |
| 2915 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2916 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2917 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2918 | { 0x1f, 0x0002 }, |
| 2919 | { 0x06, 0x5561 }, |
| 2920 | { 0x1f, 0x0005 }, |
| 2921 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2922 | { 0x06, 0x5561 }, |
| 2923 | |
| 2924 | /* |
| 2925 | * Can not link to 1Gbps with bad cable |
| 2926 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2927 | */ |
| 2928 | { 0x1f, 0x0001 }, |
| 2929 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2930 | |
| 2931 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2932 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2933 | }; |
| 2934 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2935 | 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] | 2936 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2937 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2938 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2939 | { 0x1f, 0x0002 }, |
| 2940 | { 0x05, 0x669a }, |
| 2941 | { 0x1f, 0x0005 }, |
| 2942 | { 0x05, 0x8330 }, |
| 2943 | { 0x06, 0x669a }, |
| 2944 | |
| 2945 | { 0x1f, 0x0002 } |
| 2946 | }; |
| 2947 | int val; |
| 2948 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2949 | 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] | 2950 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2951 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2952 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2953 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2954 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2955 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2956 | }; |
| 2957 | int i; |
| 2958 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2959 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2960 | |
| 2961 | val &= 0xff00; |
| 2962 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2963 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2964 | } |
| 2965 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2966 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2967 | { 0x1f, 0x0002 }, |
| 2968 | { 0x05, 0x2642 }, |
| 2969 | { 0x1f, 0x0005 }, |
| 2970 | { 0x05, 0x8330 }, |
| 2971 | { 0x06, 0x2642 } |
| 2972 | }; |
| 2973 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2974 | 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] | 2975 | } |
| 2976 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2977 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2978 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2979 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2980 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2981 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2982 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2983 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2984 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2985 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2986 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2987 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2988 | |
| 2989 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2990 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2991 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2994 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2995 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2996 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2997 | { 0x1f, 0x0002 }, |
| 2998 | { 0x10, 0x0008 }, |
| 2999 | { 0x0d, 0x006c }, |
| 3000 | |
| 3001 | { 0x1f, 0x0000 }, |
| 3002 | { 0x0d, 0xf880 }, |
| 3003 | |
| 3004 | { 0x1f, 0x0001 }, |
| 3005 | { 0x17, 0x0cc0 }, |
| 3006 | |
| 3007 | { 0x1f, 0x0001 }, |
| 3008 | { 0x0b, 0xa4d8 }, |
| 3009 | { 0x09, 0x281c }, |
| 3010 | { 0x07, 0x2883 }, |
| 3011 | { 0x0a, 0x6b35 }, |
| 3012 | { 0x1d, 0x3da4 }, |
| 3013 | { 0x1c, 0xeffd }, |
| 3014 | { 0x14, 0x7f52 }, |
| 3015 | { 0x18, 0x7fc6 }, |
| 3016 | { 0x08, 0x0601 }, |
| 3017 | { 0x06, 0x4063 }, |
| 3018 | { 0x10, 0xf074 }, |
| 3019 | { 0x1f, 0x0003 }, |
| 3020 | { 0x13, 0x0789 }, |
| 3021 | { 0x12, 0xf4bd }, |
| 3022 | { 0x1a, 0x04fd }, |
| 3023 | { 0x14, 0x84b0 }, |
| 3024 | { 0x1f, 0x0000 }, |
| 3025 | { 0x00, 0x9200 }, |
| 3026 | |
| 3027 | { 0x1f, 0x0005 }, |
| 3028 | { 0x01, 0x0340 }, |
| 3029 | { 0x1f, 0x0001 }, |
| 3030 | { 0x04, 0x4000 }, |
| 3031 | { 0x03, 0x1d21 }, |
| 3032 | { 0x02, 0x0c32 }, |
| 3033 | { 0x01, 0x0200 }, |
| 3034 | { 0x00, 0x5554 }, |
| 3035 | { 0x04, 0x4800 }, |
| 3036 | { 0x04, 0x4000 }, |
| 3037 | { 0x04, 0xf000 }, |
| 3038 | { 0x03, 0xdf01 }, |
| 3039 | { 0x02, 0xdf20 }, |
| 3040 | { 0x01, 0x101a }, |
| 3041 | { 0x00, 0xa0ff }, |
| 3042 | { 0x04, 0xf800 }, |
| 3043 | { 0x04, 0xf000 }, |
| 3044 | { 0x1f, 0x0000 }, |
| 3045 | |
| 3046 | { 0x1f, 0x0007 }, |
| 3047 | { 0x1e, 0x0023 }, |
| 3048 | { 0x16, 0x0000 }, |
| 3049 | { 0x1f, 0x0000 } |
| 3050 | }; |
| 3051 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3052 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3053 | } |
| 3054 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3055 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3056 | { |
| 3057 | static const struct phy_reg phy_reg_init[] = { |
| 3058 | { 0x1f, 0x0001 }, |
| 3059 | { 0x17, 0x0cc0 }, |
| 3060 | |
| 3061 | { 0x1f, 0x0007 }, |
| 3062 | { 0x1e, 0x002d }, |
| 3063 | { 0x18, 0x0040 }, |
| 3064 | { 0x1f, 0x0000 } |
| 3065 | }; |
| 3066 | |
| 3067 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3068 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3069 | } |
| 3070 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3071 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3072 | { |
| 3073 | static const struct phy_reg phy_reg_init[] = { |
| 3074 | /* Enable Delay cap */ |
| 3075 | { 0x1f, 0x0005 }, |
| 3076 | { 0x05, 0x8b80 }, |
| 3077 | { 0x06, 0xc896 }, |
| 3078 | { 0x1f, 0x0000 }, |
| 3079 | |
| 3080 | /* Channel estimation fine tune */ |
| 3081 | { 0x1f, 0x0001 }, |
| 3082 | { 0x0b, 0x6c20 }, |
| 3083 | { 0x07, 0x2872 }, |
| 3084 | { 0x1c, 0xefff }, |
| 3085 | { 0x1f, 0x0003 }, |
| 3086 | { 0x14, 0x6420 }, |
| 3087 | { 0x1f, 0x0000 }, |
| 3088 | |
| 3089 | /* Update PFM & 10M TX idle timer */ |
| 3090 | { 0x1f, 0x0007 }, |
| 3091 | { 0x1e, 0x002f }, |
| 3092 | { 0x15, 0x1919 }, |
| 3093 | { 0x1f, 0x0000 }, |
| 3094 | |
| 3095 | { 0x1f, 0x0007 }, |
| 3096 | { 0x1e, 0x00ac }, |
| 3097 | { 0x18, 0x0006 }, |
| 3098 | { 0x1f, 0x0000 } |
| 3099 | }; |
| 3100 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3101 | rtl_apply_firmware(tp); |
| 3102 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3103 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3104 | |
| 3105 | /* DCO enable for 10M IDLE Power */ |
| 3106 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3107 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3108 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3109 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3110 | |
| 3111 | /* For impedance matching */ |
| 3112 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3113 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3114 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3115 | |
| 3116 | /* PHY auto speed down */ |
| 3117 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3118 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3119 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3120 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3121 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3122 | |
| 3123 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3124 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3125 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3126 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3127 | |
| 3128 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3129 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3130 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3131 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3132 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3133 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3134 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3135 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3136 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3137 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3138 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3139 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3140 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3141 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3142 | } |
| 3143 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3144 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3145 | { |
| 3146 | const u16 w[] = { |
| 3147 | addr[0] | (addr[1] << 8), |
| 3148 | addr[2] | (addr[3] << 8), |
| 3149 | addr[4] | (addr[5] << 8) |
| 3150 | }; |
| 3151 | const struct exgmac_reg e[] = { |
| 3152 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3153 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3154 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3155 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3156 | }; |
| 3157 | |
| 3158 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3159 | } |
| 3160 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3161 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3162 | { |
| 3163 | static const struct phy_reg phy_reg_init[] = { |
| 3164 | /* Enable Delay cap */ |
| 3165 | { 0x1f, 0x0004 }, |
| 3166 | { 0x1f, 0x0007 }, |
| 3167 | { 0x1e, 0x00ac }, |
| 3168 | { 0x18, 0x0006 }, |
| 3169 | { 0x1f, 0x0002 }, |
| 3170 | { 0x1f, 0x0000 }, |
| 3171 | { 0x1f, 0x0000 }, |
| 3172 | |
| 3173 | /* Channel estimation fine tune */ |
| 3174 | { 0x1f, 0x0003 }, |
| 3175 | { 0x09, 0xa20f }, |
| 3176 | { 0x1f, 0x0000 }, |
| 3177 | { 0x1f, 0x0000 }, |
| 3178 | |
| 3179 | /* Green Setting */ |
| 3180 | { 0x1f, 0x0005 }, |
| 3181 | { 0x05, 0x8b5b }, |
| 3182 | { 0x06, 0x9222 }, |
| 3183 | { 0x05, 0x8b6d }, |
| 3184 | { 0x06, 0x8000 }, |
| 3185 | { 0x05, 0x8b76 }, |
| 3186 | { 0x06, 0x8000 }, |
| 3187 | { 0x1f, 0x0000 } |
| 3188 | }; |
| 3189 | |
| 3190 | rtl_apply_firmware(tp); |
| 3191 | |
| 3192 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3193 | |
| 3194 | /* For 4-corner performance improve */ |
| 3195 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3196 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3197 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3198 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3199 | |
| 3200 | /* PHY auto speed down */ |
| 3201 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3202 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3203 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3204 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3205 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3206 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3207 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3208 | |
| 3209 | /* improve 10M EEE waveform */ |
| 3210 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3211 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3212 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3213 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3214 | |
| 3215 | /* Improve 2-pair detection performance */ |
| 3216 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3217 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3218 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3219 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3220 | |
| 3221 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3222 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3223 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3224 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3225 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3226 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3227 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3228 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3229 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3230 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3231 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3232 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3233 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3234 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3235 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3236 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3237 | |
| 3238 | /* Green feature */ |
| 3239 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3240 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3241 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3242 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3243 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3244 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3245 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3246 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3247 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3248 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3249 | } |
| 3250 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3251 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3252 | { |
| 3253 | /* For 4-corner performance improve */ |
| 3254 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3255 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3256 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3257 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3258 | |
| 3259 | /* PHY auto speed down */ |
| 3260 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3261 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3262 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3263 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3264 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3265 | |
| 3266 | /* Improve 10M EEE waveform */ |
| 3267 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3268 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3269 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3270 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3271 | } |
| 3272 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3273 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3274 | { |
| 3275 | static const struct phy_reg phy_reg_init[] = { |
| 3276 | /* Channel estimation fine tune */ |
| 3277 | { 0x1f, 0x0003 }, |
| 3278 | { 0x09, 0xa20f }, |
| 3279 | { 0x1f, 0x0000 }, |
| 3280 | |
| 3281 | /* Modify green table for giga & fnet */ |
| 3282 | { 0x1f, 0x0005 }, |
| 3283 | { 0x05, 0x8b55 }, |
| 3284 | { 0x06, 0x0000 }, |
| 3285 | { 0x05, 0x8b5e }, |
| 3286 | { 0x06, 0x0000 }, |
| 3287 | { 0x05, 0x8b67 }, |
| 3288 | { 0x06, 0x0000 }, |
| 3289 | { 0x05, 0x8b70 }, |
| 3290 | { 0x06, 0x0000 }, |
| 3291 | { 0x1f, 0x0000 }, |
| 3292 | { 0x1f, 0x0007 }, |
| 3293 | { 0x1e, 0x0078 }, |
| 3294 | { 0x17, 0x0000 }, |
| 3295 | { 0x19, 0x00fb }, |
| 3296 | { 0x1f, 0x0000 }, |
| 3297 | |
| 3298 | /* Modify green table for 10M */ |
| 3299 | { 0x1f, 0x0005 }, |
| 3300 | { 0x05, 0x8b79 }, |
| 3301 | { 0x06, 0xaa00 }, |
| 3302 | { 0x1f, 0x0000 }, |
| 3303 | |
| 3304 | /* Disable hiimpedance detection (RTCT) */ |
| 3305 | { 0x1f, 0x0003 }, |
| 3306 | { 0x01, 0x328a }, |
| 3307 | { 0x1f, 0x0000 } |
| 3308 | }; |
| 3309 | |
| 3310 | rtl_apply_firmware(tp); |
| 3311 | |
| 3312 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3313 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3314 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3315 | |
| 3316 | /* Improve 2-pair detection performance */ |
| 3317 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3318 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3319 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3320 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3321 | } |
| 3322 | |
| 3323 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3324 | { |
| 3325 | rtl_apply_firmware(tp); |
| 3326 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3327 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3328 | } |
| 3329 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3330 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3331 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3332 | static const struct phy_reg phy_reg_init[] = { |
| 3333 | /* Channel estimation fine tune */ |
| 3334 | { 0x1f, 0x0003 }, |
| 3335 | { 0x09, 0xa20f }, |
| 3336 | { 0x1f, 0x0000 }, |
| 3337 | |
| 3338 | /* Modify green table for giga & fnet */ |
| 3339 | { 0x1f, 0x0005 }, |
| 3340 | { 0x05, 0x8b55 }, |
| 3341 | { 0x06, 0x0000 }, |
| 3342 | { 0x05, 0x8b5e }, |
| 3343 | { 0x06, 0x0000 }, |
| 3344 | { 0x05, 0x8b67 }, |
| 3345 | { 0x06, 0x0000 }, |
| 3346 | { 0x05, 0x8b70 }, |
| 3347 | { 0x06, 0x0000 }, |
| 3348 | { 0x1f, 0x0000 }, |
| 3349 | { 0x1f, 0x0007 }, |
| 3350 | { 0x1e, 0x0078 }, |
| 3351 | { 0x17, 0x0000 }, |
| 3352 | { 0x19, 0x00aa }, |
| 3353 | { 0x1f, 0x0000 }, |
| 3354 | |
| 3355 | /* Modify green table for 10M */ |
| 3356 | { 0x1f, 0x0005 }, |
| 3357 | { 0x05, 0x8b79 }, |
| 3358 | { 0x06, 0xaa00 }, |
| 3359 | { 0x1f, 0x0000 }, |
| 3360 | |
| 3361 | /* Disable hiimpedance detection (RTCT) */ |
| 3362 | { 0x1f, 0x0003 }, |
| 3363 | { 0x01, 0x328a }, |
| 3364 | { 0x1f, 0x0000 } |
| 3365 | }; |
| 3366 | |
| 3367 | |
| 3368 | rtl_apply_firmware(tp); |
| 3369 | |
| 3370 | rtl8168f_hw_phy_config(tp); |
| 3371 | |
| 3372 | /* Improve 2-pair detection performance */ |
| 3373 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3374 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3375 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3376 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3377 | |
| 3378 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3379 | |
| 3380 | /* Modify green table for giga */ |
| 3381 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3382 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3383 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3384 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3385 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3386 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3387 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3388 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3389 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3390 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3391 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3392 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3393 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3394 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3395 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3396 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3397 | |
| 3398 | /* uc same-seed solution */ |
| 3399 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3400 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3401 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3402 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3403 | |
| 3404 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3405 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3406 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3407 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3408 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3409 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3410 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3411 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3412 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3413 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3414 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3415 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3416 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3417 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3418 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3419 | |
| 3420 | /* Green feature */ |
| 3421 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3422 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3423 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3424 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3425 | } |
| 3426 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3427 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3428 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3429 | rtl_apply_firmware(tp); |
| 3430 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3431 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3432 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3433 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3434 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3435 | } else { |
| 3436 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3437 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3438 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3439 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3440 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3441 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3442 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3443 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3444 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3445 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3446 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3447 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3448 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3449 | /* Enable PHY auto speed down */ |
| 3450 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3451 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3452 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3453 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3454 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3455 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3456 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3457 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3458 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3459 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3460 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3461 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3462 | /* EEE auto-fallback function */ |
| 3463 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3464 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3465 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3466 | /* Enable UC LPF tune function */ |
| 3467 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3468 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3469 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3470 | |
| 3471 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3472 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3473 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3474 | /* Improve SWR Efficiency */ |
| 3475 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3476 | rtl_writephy(tp, 0x14, 0x5065); |
| 3477 | rtl_writephy(tp, 0x14, 0xd065); |
| 3478 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3479 | rtl_writephy(tp, 0x11, 0x5655); |
| 3480 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3481 | rtl_writephy(tp, 0x14, 0x1065); |
| 3482 | rtl_writephy(tp, 0x14, 0x9065); |
| 3483 | rtl_writephy(tp, 0x14, 0x1065); |
| 3484 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3485 | /* Check ALDPS bit, disable it if enabled */ |
| 3486 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3487 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3488 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3489 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3490 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3491 | } |
| 3492 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3493 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3494 | { |
| 3495 | rtl_apply_firmware(tp); |
| 3496 | } |
| 3497 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3498 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3499 | { |
| 3500 | u16 dout_tapbin; |
| 3501 | u32 data; |
| 3502 | |
| 3503 | rtl_apply_firmware(tp); |
| 3504 | |
| 3505 | /* CHN EST parameters adjust - giga master */ |
| 3506 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3507 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3508 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3509 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3510 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3511 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3512 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3513 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3514 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3515 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3516 | |
| 3517 | /* CHN EST parameters adjust - giga slave */ |
| 3518 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3519 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3520 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3521 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3522 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3523 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3524 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3525 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3526 | |
| 3527 | /* CHN EST parameters adjust - fnet */ |
| 3528 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3529 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3530 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3531 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3532 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3533 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3534 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3535 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3536 | |
| 3537 | /* enable R-tune & PGA-retune function */ |
| 3538 | dout_tapbin = 0; |
| 3539 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3540 | data = rtl_readphy(tp, 0x13); |
| 3541 | data &= 3; |
| 3542 | data <<= 2; |
| 3543 | dout_tapbin |= data; |
| 3544 | data = rtl_readphy(tp, 0x12); |
| 3545 | data &= 0xc000; |
| 3546 | data >>= 14; |
| 3547 | dout_tapbin |= data; |
| 3548 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3549 | dout_tapbin <<= 12; |
| 3550 | dout_tapbin &= 0xf000; |
| 3551 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3552 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3553 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3554 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3555 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3556 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3557 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3558 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3559 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3560 | |
| 3561 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3562 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3563 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3564 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3565 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3566 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3567 | |
| 3568 | /* enable GPHY 10M */ |
| 3569 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3570 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3571 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3572 | |
| 3573 | /* SAR ADC performance */ |
| 3574 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3575 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3576 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3577 | |
| 3578 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3579 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3580 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3581 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3582 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3583 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3584 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3585 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3586 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3587 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3588 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3589 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3590 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3591 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3592 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3593 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3594 | |
| 3595 | /* disable phy pfm mode */ |
| 3596 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3597 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3598 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3599 | |
| 3600 | /* Check ALDPS bit, disable it if enabled */ |
| 3601 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3602 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3603 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3604 | |
| 3605 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3606 | } |
| 3607 | |
| 3608 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3609 | { |
| 3610 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3611 | u16 rlen; |
| 3612 | u32 data; |
| 3613 | |
| 3614 | rtl_apply_firmware(tp); |
| 3615 | |
| 3616 | /* CHIN EST parameter update */ |
| 3617 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3618 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3619 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3620 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3621 | |
| 3622 | /* enable R-tune & PGA-retune function */ |
| 3623 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3624 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3625 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3626 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3627 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3628 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3629 | |
| 3630 | /* enable GPHY 10M */ |
| 3631 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3632 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3633 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3634 | |
| 3635 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3636 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3637 | ioffset_p3 = ((data & 0x80)>>7); |
| 3638 | ioffset_p3 <<= 3; |
| 3639 | |
| 3640 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3641 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3642 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3643 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3644 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3645 | ioffset_p0 <<= 3; |
| 3646 | ioffset_p0 |= (data & (0x07)); |
| 3647 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3648 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3649 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3650 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3651 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3652 | rtl_writephy(tp, 0x16, data); |
| 3653 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3654 | } |
| 3655 | |
| 3656 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3657 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3658 | data = rtl_readphy(tp, 0x16); |
| 3659 | data &= 0x000f; |
| 3660 | rlen = 0; |
| 3661 | if (data > 3) |
| 3662 | rlen = data - 3; |
| 3663 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3664 | rtl_writephy(tp, 0x17, data); |
| 3665 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3666 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3667 | |
| 3668 | /* disable phy pfm mode */ |
| 3669 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3670 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3671 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3672 | |
| 3673 | /* Check ALDPS bit, disable it if enabled */ |
| 3674 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3675 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3676 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3677 | |
| 3678 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3679 | } |
| 3680 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3681 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3682 | { |
| 3683 | /* Enable PHY auto speed down */ |
| 3684 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3685 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 3686 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3687 | |
| 3688 | /* patch 10M & ALDPS */ |
| 3689 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3690 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3691 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3692 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3693 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3694 | rtl_writephy(tp, 0x13, 0x8084); |
| 3695 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3696 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3697 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3698 | |
| 3699 | /* Enable EEE auto-fallback function */ |
| 3700 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 3701 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 3702 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3703 | |
| 3704 | /* Enable UC LPF tune function */ |
| 3705 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3706 | rtl_writephy(tp, 0x13, 0x8012); |
| 3707 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3708 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3709 | |
| 3710 | /* set rg_sel_sdm_rate */ |
| 3711 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3712 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3713 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3714 | |
| 3715 | /* Check ALDPS bit, disable it if enabled */ |
| 3716 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3717 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3718 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3719 | |
| 3720 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3721 | } |
| 3722 | |
| 3723 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3724 | { |
| 3725 | /* patch 10M & ALDPS */ |
| 3726 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3727 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3728 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3729 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3730 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3731 | rtl_writephy(tp, 0x13, 0x8084); |
| 3732 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3733 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3734 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3735 | |
| 3736 | /* Enable UC LPF tune function */ |
| 3737 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3738 | rtl_writephy(tp, 0x13, 0x8012); |
| 3739 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3740 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3741 | |
| 3742 | /* Set rg_sel_sdm_rate */ |
| 3743 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3744 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3745 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3746 | |
| 3747 | /* Channel estimation parameters */ |
| 3748 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3749 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3750 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3751 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3752 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3753 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3754 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3755 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3756 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3757 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3758 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3759 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3760 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3761 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3762 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3763 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3764 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3765 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3766 | rtl_writephy(tp, 0x13, 0x8110); |
| 3767 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3768 | rtl_writephy(tp, 0x13, 0x810f); |
| 3769 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3770 | rtl_writephy(tp, 0x13, 0x8111); |
| 3771 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3772 | rtl_writephy(tp, 0x13, 0x8113); |
| 3773 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3774 | rtl_writephy(tp, 0x13, 0x8115); |
| 3775 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3776 | rtl_writephy(tp, 0x13, 0x810e); |
| 3777 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3778 | rtl_writephy(tp, 0x13, 0x810c); |
| 3779 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3780 | rtl_writephy(tp, 0x13, 0x810b); |
| 3781 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3782 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3783 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3784 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3785 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3786 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3787 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3788 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3789 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3790 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3791 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3792 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3793 | |
| 3794 | /* Force PWM-mode */ |
| 3795 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3796 | rtl_writephy(tp, 0x14, 0x5065); |
| 3797 | rtl_writephy(tp, 0x14, 0xd065); |
| 3798 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3799 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3800 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3801 | rtl_writephy(tp, 0x14, 0x1065); |
| 3802 | rtl_writephy(tp, 0x14, 0x9065); |
| 3803 | rtl_writephy(tp, 0x14, 0x1065); |
| 3804 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3805 | |
| 3806 | /* Check ALDPS bit, disable it if enabled */ |
| 3807 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3808 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3809 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3810 | |
| 3811 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3812 | } |
| 3813 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3814 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3815 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3816 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3817 | { 0x1f, 0x0003 }, |
| 3818 | { 0x08, 0x441d }, |
| 3819 | { 0x01, 0x9100 }, |
| 3820 | { 0x1f, 0x0000 } |
| 3821 | }; |
| 3822 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3823 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3824 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3825 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3826 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3827 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3828 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3829 | } |
| 3830 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3831 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3832 | { |
| 3833 | static const struct phy_reg phy_reg_init[] = { |
| 3834 | { 0x1f, 0x0005 }, |
| 3835 | { 0x1a, 0x0000 }, |
| 3836 | { 0x1f, 0x0000 }, |
| 3837 | |
| 3838 | { 0x1f, 0x0004 }, |
| 3839 | { 0x1c, 0x0000 }, |
| 3840 | { 0x1f, 0x0000 }, |
| 3841 | |
| 3842 | { 0x1f, 0x0001 }, |
| 3843 | { 0x15, 0x7701 }, |
| 3844 | { 0x1f, 0x0000 } |
| 3845 | }; |
| 3846 | |
| 3847 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3848 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3849 | rtl_writephy(tp, 0x18, 0x0310); |
| 3850 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3851 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3852 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3853 | |
| 3854 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3855 | } |
| 3856 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3857 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3858 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3859 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3860 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3861 | rtl_writephy(tp, 0x18, 0x0310); |
| 3862 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3863 | |
| 3864 | rtl_apply_firmware(tp); |
| 3865 | |
| 3866 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3867 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3868 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3869 | rtl_writephy(tp, 0x10, 0x401f); |
| 3870 | rtl_writephy(tp, 0x19, 0x7030); |
| 3871 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3872 | } |
| 3873 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3874 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3875 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3876 | static const struct phy_reg phy_reg_init[] = { |
| 3877 | { 0x1f, 0x0004 }, |
| 3878 | { 0x10, 0xc07f }, |
| 3879 | { 0x19, 0x7030 }, |
| 3880 | { 0x1f, 0x0000 } |
| 3881 | }; |
| 3882 | |
| 3883 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3884 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3885 | rtl_writephy(tp, 0x18, 0x0310); |
| 3886 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3887 | |
| 3888 | rtl_apply_firmware(tp); |
| 3889 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3890 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3891 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3892 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3893 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3894 | } |
| 3895 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3896 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3897 | { |
| 3898 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3899 | |
| 3900 | rtl8169_print_mac_version(tp); |
| 3901 | |
| 3902 | switch (tp->mac_version) { |
| 3903 | case RTL_GIGA_MAC_VER_01: |
| 3904 | break; |
| 3905 | case RTL_GIGA_MAC_VER_02: |
| 3906 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3907 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3908 | break; |
| 3909 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3910 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3911 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3912 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3913 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3914 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3915 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3916 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3917 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3918 | case RTL_GIGA_MAC_VER_07: |
| 3919 | case RTL_GIGA_MAC_VER_08: |
| 3920 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3921 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3922 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3923 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3924 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3925 | break; |
| 3926 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3927 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3928 | break; |
| 3929 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3930 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3931 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3932 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3933 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3934 | break; |
| 3935 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3936 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3937 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3938 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3939 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3940 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3941 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3942 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3943 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3944 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3945 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3946 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3947 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3948 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3949 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3950 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3951 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3952 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3953 | break; |
| 3954 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3955 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3956 | break; |
| 3957 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3958 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3959 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3960 | case RTL_GIGA_MAC_VER_28: |
| 3961 | rtl8168d_4_hw_phy_config(tp); |
| 3962 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3963 | case RTL_GIGA_MAC_VER_29: |
| 3964 | case RTL_GIGA_MAC_VER_30: |
| 3965 | rtl8105e_hw_phy_config(tp); |
| 3966 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3967 | case RTL_GIGA_MAC_VER_31: |
| 3968 | /* None. */ |
| 3969 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3970 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3971 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3972 | rtl8168e_1_hw_phy_config(tp); |
| 3973 | break; |
| 3974 | case RTL_GIGA_MAC_VER_34: |
| 3975 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3976 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3977 | case RTL_GIGA_MAC_VER_35: |
| 3978 | rtl8168f_1_hw_phy_config(tp); |
| 3979 | break; |
| 3980 | case RTL_GIGA_MAC_VER_36: |
| 3981 | rtl8168f_2_hw_phy_config(tp); |
| 3982 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3983 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3984 | case RTL_GIGA_MAC_VER_37: |
| 3985 | rtl8402_hw_phy_config(tp); |
| 3986 | break; |
| 3987 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3988 | case RTL_GIGA_MAC_VER_38: |
| 3989 | rtl8411_hw_phy_config(tp); |
| 3990 | break; |
| 3991 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3992 | case RTL_GIGA_MAC_VER_39: |
| 3993 | rtl8106e_hw_phy_config(tp); |
| 3994 | break; |
| 3995 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3996 | case RTL_GIGA_MAC_VER_40: |
| 3997 | rtl8168g_1_hw_phy_config(tp); |
| 3998 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3999 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4000 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4001 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4002 | rtl8168g_2_hw_phy_config(tp); |
| 4003 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4004 | case RTL_GIGA_MAC_VER_45: |
| 4005 | case RTL_GIGA_MAC_VER_47: |
| 4006 | rtl8168h_1_hw_phy_config(tp); |
| 4007 | break; |
| 4008 | case RTL_GIGA_MAC_VER_46: |
| 4009 | case RTL_GIGA_MAC_VER_48: |
| 4010 | rtl8168h_2_hw_phy_config(tp); |
| 4011 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4012 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4013 | case RTL_GIGA_MAC_VER_49: |
| 4014 | rtl8168ep_1_hw_phy_config(tp); |
| 4015 | break; |
| 4016 | case RTL_GIGA_MAC_VER_50: |
| 4017 | case RTL_GIGA_MAC_VER_51: |
| 4018 | rtl8168ep_2_hw_phy_config(tp); |
| 4019 | break; |
| 4020 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4021 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4022 | default: |
| 4023 | break; |
| 4024 | } |
| 4025 | } |
| 4026 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4027 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4028 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4029 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4030 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4031 | } |
| 4032 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4033 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4034 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4035 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4036 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4037 | } |
| 4038 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4039 | 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] | 4040 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4041 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4042 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4043 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 7a67e11 | 2018-09-19 22:00:24 +0200 | [diff] [blame] | 4044 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4045 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4046 | netif_dbg(tp, drv, dev, |
| 4047 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4048 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4049 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4050 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4051 | /* We may have called phy_speed_down before */ |
| 4052 | phy_speed_up(dev->phydev); |
| 4053 | |
Heiner Kallweit | f75222b | 2018-07-17 22:51:41 +0200 | [diff] [blame] | 4054 | genphy_soft_reset(dev->phydev); |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4055 | |
Alex Xu (Hello71) | 9003b36 | 2018-09-30 11:06:39 -0400 | [diff] [blame] | 4056 | /* 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] | 4057 | * 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] | 4058 | * these chips doesn't properly start a renegotiation when soft-reset. |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4059 | * Explicitly requesting a renegotiation fixes this. |
| 4060 | */ |
Alex Xu (Hello71) | 9003b36 | 2018-09-30 11:06:39 -0400 | [diff] [blame] | 4061 | if (dev->phydev->autoneg == AUTONEG_ENABLE) |
Heiner Kallweit | 10bc6a6 | 2018-09-20 22:47:09 +0200 | [diff] [blame] | 4062 | phy_restart_aneg(dev->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4063 | } |
| 4064 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4065 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4066 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4067 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4068 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4069 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4070 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4071 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4072 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4073 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4074 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4075 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4076 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4077 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4078 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4079 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4080 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4081 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4082 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4086 | { |
| 4087 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4088 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4089 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4090 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4091 | ret = eth_mac_addr(dev, p); |
| 4092 | if (ret) |
| 4093 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4094 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4095 | pm_runtime_get_noresume(d); |
| 4096 | |
| 4097 | if (pm_runtime_active(d)) |
| 4098 | rtl_rar_set(tp, dev->dev_addr); |
| 4099 | |
| 4100 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4101 | |
| 4102 | return 0; |
| 4103 | } |
| 4104 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4105 | 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] | 4106 | { |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4107 | if (!netif_running(dev)) |
| 4108 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4109 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4110 | return phy_mii_ioctl(dev->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4111 | } |
| 4112 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4113 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4114 | { |
| 4115 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4116 | |
| 4117 | switch (tp->mac_version) { |
| 4118 | case RTL_GIGA_MAC_VER_27: |
| 4119 | ops->write = r8168dp_1_mdio_write; |
| 4120 | ops->read = r8168dp_1_mdio_read; |
| 4121 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4122 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4123 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4124 | ops->write = r8168dp_2_mdio_write; |
| 4125 | ops->read = r8168dp_2_mdio_read; |
| 4126 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4127 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4128 | ops->write = r8168g_mdio_write; |
| 4129 | ops->read = r8168g_mdio_read; |
| 4130 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4131 | default: |
| 4132 | ops->write = r8169_mdio_write; |
| 4133 | ops->read = r8169_mdio_read; |
| 4134 | break; |
| 4135 | } |
| 4136 | } |
| 4137 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4138 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4139 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4140 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4141 | case RTL_GIGA_MAC_VER_25: |
| 4142 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4143 | case RTL_GIGA_MAC_VER_29: |
| 4144 | case RTL_GIGA_MAC_VER_30: |
| 4145 | case RTL_GIGA_MAC_VER_32: |
| 4146 | case RTL_GIGA_MAC_VER_33: |
| 4147 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4148 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4149 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4150 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4151 | break; |
| 4152 | default: |
| 4153 | break; |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4158 | { |
Heiner Kallweit | 649f083 | 2018-10-25 18:40:19 +0200 | [diff] [blame] | 4159 | struct phy_device *phydev; |
| 4160 | |
| 4161 | if (!__rtl8169_get_wol(tp)) |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4162 | return false; |
| 4163 | |
Heiner Kallweit | 649f083 | 2018-10-25 18:40:19 +0200 | [diff] [blame] | 4164 | /* phydev may not be attached to netdevice */ |
| 4165 | phydev = mdiobus_get_phy(tp->mii_bus, 0); |
| 4166 | |
| 4167 | phy_speed_down(phydev, false); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4168 | rtl_wol_suspend_quirk(tp); |
| 4169 | |
| 4170 | return true; |
| 4171 | } |
| 4172 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4173 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4174 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4175 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4176 | return; |
| 4177 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4178 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4179 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4180 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4181 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4182 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4183 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4184 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4185 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4186 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4187 | case RTL_GIGA_MAC_VER_37: |
| 4188 | case RTL_GIGA_MAC_VER_39: |
| 4189 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4190 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4191 | case RTL_GIGA_MAC_VER_45: |
| 4192 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4193 | case RTL_GIGA_MAC_VER_47: |
| 4194 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4195 | case RTL_GIGA_MAC_VER_50: |
| 4196 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4197 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4198 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4199 | case RTL_GIGA_MAC_VER_40: |
| 4200 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4201 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4202 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4203 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4204 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4205 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4210 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4211 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4212 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4213 | case RTL_GIGA_MAC_VER_37: |
| 4214 | case RTL_GIGA_MAC_VER_39: |
| 4215 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4216 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4217 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4218 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4219 | case RTL_GIGA_MAC_VER_45: |
| 4220 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4221 | case RTL_GIGA_MAC_VER_47: |
| 4222 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4223 | case RTL_GIGA_MAC_VER_50: |
| 4224 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4225 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4226 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4227 | case RTL_GIGA_MAC_VER_40: |
| 4228 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4229 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4230 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4231 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4232 | 0x00000000, ERIAR_EXGMAC); |
| 4233 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4234 | } |
| 4235 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 4236 | phy_resume(tp->dev->phydev); |
| 4237 | /* give MAC/PHY some time to resume */ |
| 4238 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4241 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4242 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4243 | switch (tp->mac_version) { |
| 4244 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4245 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4246 | break; |
| 4247 | default: |
| 4248 | r8168_pll_power_down(tp); |
| 4249 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4253 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4254 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4255 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4256 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4257 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4258 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4259 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4260 | } |
| 4261 | } |
| 4262 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4263 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4264 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4265 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4266 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4267 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4268 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4269 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4270 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
Maciej S. Szmigiero | 511cfd5 | 2018-10-11 16:02:10 +0200 | [diff] [blame] | 4271 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_36: |
| 4272 | case RTL_GIGA_MAC_VER_38: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4273 | 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] | 4274 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4275 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4276 | 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] | 4277 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4278 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4279 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4280 | break; |
| 4281 | } |
| 4282 | } |
| 4283 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4284 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4285 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4286 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4287 | } |
| 4288 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4289 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4290 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4291 | if (tp->jumbo_ops.enable) { |
| 4292 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4293 | tp->jumbo_ops.enable(tp); |
| 4294 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4295 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4299 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4300 | if (tp->jumbo_ops.disable) { |
| 4301 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4302 | tp->jumbo_ops.disable(tp); |
| 4303 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4304 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4308 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4309 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4310 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4311 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4315 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4316 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4317 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4318 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4322 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4323 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4327 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4328 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4332 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4333 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4334 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4335 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4336 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4340 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4341 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4342 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4343 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4344 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4348 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4349 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4350 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4354 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4355 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4356 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4360 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4361 | r8168b_0_hw_jumbo_enable(tp); |
| 4362 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4363 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4367 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4368 | r8168b_0_hw_jumbo_disable(tp); |
| 4369 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4370 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4371 | } |
| 4372 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4373 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4374 | { |
| 4375 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4376 | |
| 4377 | switch (tp->mac_version) { |
| 4378 | case RTL_GIGA_MAC_VER_11: |
| 4379 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4380 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4381 | break; |
| 4382 | case RTL_GIGA_MAC_VER_12: |
| 4383 | case RTL_GIGA_MAC_VER_17: |
| 4384 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4385 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4386 | break; |
| 4387 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4388 | case RTL_GIGA_MAC_VER_19: |
| 4389 | case RTL_GIGA_MAC_VER_20: |
| 4390 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4391 | case RTL_GIGA_MAC_VER_22: |
| 4392 | case RTL_GIGA_MAC_VER_23: |
| 4393 | case RTL_GIGA_MAC_VER_24: |
| 4394 | case RTL_GIGA_MAC_VER_25: |
| 4395 | case RTL_GIGA_MAC_VER_26: |
| 4396 | ops->disable = r8168c_hw_jumbo_disable; |
| 4397 | ops->enable = r8168c_hw_jumbo_enable; |
| 4398 | break; |
| 4399 | case RTL_GIGA_MAC_VER_27: |
| 4400 | case RTL_GIGA_MAC_VER_28: |
| 4401 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4402 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4403 | break; |
| 4404 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4405 | case RTL_GIGA_MAC_VER_32: |
| 4406 | case RTL_GIGA_MAC_VER_33: |
| 4407 | case RTL_GIGA_MAC_VER_34: |
| 4408 | ops->disable = r8168e_hw_jumbo_disable; |
| 4409 | ops->enable = r8168e_hw_jumbo_enable; |
| 4410 | break; |
| 4411 | |
| 4412 | /* |
| 4413 | * No action needed for jumbo frames with 8169. |
| 4414 | * No jumbo for 810x at all. |
| 4415 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4416 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4417 | default: |
| 4418 | ops->disable = NULL; |
| 4419 | ops->enable = NULL; |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4424 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4425 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4426 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4427 | } |
| 4428 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4429 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4430 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4431 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4432 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4433 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4434 | } |
| 4435 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4436 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4437 | { |
| 4438 | struct rtl_fw *rtl_fw; |
| 4439 | const char *name; |
| 4440 | int rc = -ENOMEM; |
| 4441 | |
| 4442 | name = rtl_lookup_firmware_name(tp); |
| 4443 | if (!name) |
| 4444 | goto out_no_firmware; |
| 4445 | |
| 4446 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4447 | if (!rtl_fw) |
| 4448 | goto err_warn; |
| 4449 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4450 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4451 | if (rc < 0) |
| 4452 | goto err_free; |
| 4453 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4454 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4455 | if (rc < 0) |
| 4456 | goto err_release_firmware; |
| 4457 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4458 | tp->rtl_fw = rtl_fw; |
| 4459 | out: |
| 4460 | return; |
| 4461 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4462 | err_release_firmware: |
| 4463 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4464 | err_free: |
| 4465 | kfree(rtl_fw); |
| 4466 | err_warn: |
| 4467 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4468 | name, rc); |
| 4469 | out_no_firmware: |
| 4470 | tp->rtl_fw = NULL; |
| 4471 | goto out; |
| 4472 | } |
| 4473 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4474 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4475 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4476 | if (IS_ERR(tp->rtl_fw)) |
| 4477 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4478 | } |
| 4479 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4480 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4481 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4482 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4483 | } |
| 4484 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4485 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4486 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4487 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4491 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4492 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4493 | } |
| 4494 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4495 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | { |
| 4497 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4498 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4500 | rtl_rx_close(tp); |
| 4501 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4502 | switch (tp->mac_version) { |
| 4503 | case RTL_GIGA_MAC_VER_27: |
| 4504 | case RTL_GIGA_MAC_VER_28: |
| 4505 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4506 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4507 | break; |
| 4508 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 4509 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4510 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4511 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4512 | break; |
| 4513 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4514 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4515 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4516 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4519 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4522 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4523 | { |
Heiner Kallweit | ad5f97f | 2018-09-28 23:51:54 +0200 | [diff] [blame] | 4524 | u32 val = TX_DMA_BURST << TxDMAShift | |
| 4525 | InterFrameGap << TxInterFrameGapShift; |
| 4526 | |
| 4527 | if (tp->mac_version >= RTL_GIGA_MAC_VER_34 && |
| 4528 | tp->mac_version != RTL_GIGA_MAC_VER_39) |
| 4529 | val |= TXCFG_AUTO_FIFO; |
| 4530 | |
| 4531 | RTL_W32(tp, TxConfig, val); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4532 | } |
| 4533 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4534 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4536 | /* Low hurts. Let's disable the filtering. */ |
| 4537 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4538 | } |
| 4539 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4540 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4541 | { |
| 4542 | /* |
| 4543 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4544 | * register to be written before TxDescAddrLow to work. |
| 4545 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4546 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4547 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4548 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4549 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4550 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4551 | } |
| 4552 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4553 | 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] | 4554 | { |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4555 | u32 val; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4556 | |
Heiner Kallweit | 34bc009 | 2018-10-12 23:23:57 +0200 | [diff] [blame] | 4557 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4558 | val = 0x000fff00; |
| 4559 | else if (tp->mac_version == RTL_GIGA_MAC_VER_06) |
| 4560 | val = 0x00ffff00; |
| 4561 | else |
| 4562 | return; |
| 4563 | |
| 4564 | if (RTL_R8(tp, Config2) & PCI_Clock_66MHz) |
| 4565 | val |= 0xff; |
| 4566 | |
| 4567 | RTL_W32(tp, 0x7c, val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4568 | } |
| 4569 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4570 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4571 | { |
| 4572 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4573 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4574 | int rx_mode; |
| 4575 | u32 tmp = 0; |
| 4576 | |
| 4577 | if (dev->flags & IFF_PROMISC) { |
| 4578 | /* Unconditionally log net taps. */ |
| 4579 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4580 | rx_mode = |
| 4581 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4582 | AcceptAllPhys; |
| 4583 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4584 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4585 | (dev->flags & IFF_ALLMULTI)) { |
| 4586 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4587 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4588 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4589 | } else { |
| 4590 | struct netdev_hw_addr *ha; |
| 4591 | |
| 4592 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4593 | mc_filter[1] = mc_filter[0] = 0; |
| 4594 | netdev_for_each_mc_addr(ha, dev) { |
| 4595 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4596 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4597 | rx_mode |= AcceptMulticast; |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | if (dev->features & NETIF_F_RXALL) |
| 4602 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4603 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4604 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4605 | |
| 4606 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4607 | u32 data = mc_filter[0]; |
| 4608 | |
| 4609 | mc_filter[0] = swab32(mc_filter[1]); |
| 4610 | mc_filter[1] = swab32(data); |
| 4611 | } |
| 4612 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 4613 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 4614 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4615 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4616 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4617 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4618 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4619 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4620 | } |
| 4621 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4622 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 4623 | { |
| 4624 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4625 | |
| 4626 | tp->hw_start(tp); |
| 4627 | |
| 4628 | rtl_set_rx_max_size(tp); |
| 4629 | rtl_set_rx_tx_desc_registers(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4630 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4631 | |
| 4632 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4633 | RTL_R8(tp, IntrMask); |
| 4634 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4635 | rtl_init_rxcfg(tp); |
Maciej S. Szmigiero | f74dd48 | 2018-09-07 20:15:22 +0200 | [diff] [blame] | 4636 | rtl_set_tx_config_registers(tp); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4637 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4638 | rtl_set_rx_mode(tp->dev); |
| 4639 | /* no early-rx interrupts */ |
| 4640 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 4641 | rtl_irq_enable(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4642 | } |
| 4643 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4644 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4645 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4646 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4647 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4648 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4649 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4651 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4652 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4653 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4654 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4655 | netif_dbg(tp, drv, tp->dev, |
| 4656 | "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] | 4657 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4660 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4661 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4662 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4664 | /* |
| 4665 | * Undocumented corner. Supposedly: |
| 4666 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4667 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4668 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4670 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4673 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4674 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4675 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4676 | } |
| 4677 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4678 | 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] | 4679 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4680 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4681 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4682 | RTL_W32(tp, CSIDR, value); |
| 4683 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4684 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4685 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4686 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4687 | } |
| 4688 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4689 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4690 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4691 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4692 | |
| 4693 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4694 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4695 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4696 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4697 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4698 | } |
| 4699 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4700 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4701 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4702 | struct pci_dev *pdev = tp->pci_dev; |
| 4703 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4704 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4705 | /* According to Realtek the value at config space address 0x070f |
| 4706 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4707 | * first and if it fails fall back to CSI. |
| 4708 | */ |
| 4709 | if (pdev->cfg_size > 0x070f && |
| 4710 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4711 | return; |
| 4712 | |
| 4713 | netdev_notice_once(tp->dev, |
| 4714 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4715 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4716 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4717 | } |
| 4718 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4719 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4720 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4721 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | struct ephy_info { |
| 4725 | unsigned int offset; |
| 4726 | u16 mask; |
| 4727 | u16 bits; |
| 4728 | }; |
| 4729 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4730 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 4731 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4732 | { |
| 4733 | u16 w; |
| 4734 | |
| 4735 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4736 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4737 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4738 | e++; |
| 4739 | } |
| 4740 | } |
| 4741 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4742 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4743 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4744 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4745 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4746 | } |
| 4747 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4748 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4749 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4750 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4751 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4754 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 4755 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4756 | u8 data; |
| 4757 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4758 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4759 | |
| 4760 | if (enable) |
| 4761 | data |= Rdy_to_L23; |
| 4762 | else |
| 4763 | data &= ~Rdy_to_L23; |
| 4764 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4765 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4766 | } |
| 4767 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4768 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4769 | { |
| 4770 | if (enable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4771 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4772 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4773 | } else { |
| 4774 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4775 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4776 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame] | 4777 | |
| 4778 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4779 | } |
| 4780 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4781 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4782 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4783 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4784 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4785 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4786 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4787 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4788 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4789 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4790 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4791 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4792 | } |
| 4793 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4794 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4795 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4796 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4797 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4798 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4799 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4800 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4801 | } |
| 4802 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4803 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4804 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4805 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4806 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4807 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4808 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4809 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4810 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4811 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4812 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4813 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4814 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4815 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4816 | } |
| 4817 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4818 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4819 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4820 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4821 | { 0x01, 0, 0x0001 }, |
| 4822 | { 0x02, 0x0800, 0x1000 }, |
| 4823 | { 0x03, 0, 0x0042 }, |
| 4824 | { 0x06, 0x0080, 0x0000 }, |
| 4825 | { 0x07, 0, 0x2000 } |
| 4826 | }; |
| 4827 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4828 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4829 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4830 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4831 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4832 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4833 | } |
| 4834 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4835 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4836 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4837 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4838 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4839 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4840 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4841 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4842 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4843 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4844 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4845 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4846 | } |
| 4847 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4848 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4849 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4850 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4851 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4852 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4853 | |
| 4854 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4855 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4856 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4857 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4858 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4859 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4860 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4861 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4862 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4863 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4866 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4867 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4868 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4869 | { 0x02, 0x0800, 0x1000 }, |
| 4870 | { 0x03, 0, 0x0002 }, |
| 4871 | { 0x06, 0x0080, 0x0000 } |
| 4872 | }; |
| 4873 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4874 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4875 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4876 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4877 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4878 | 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] | 4879 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4880 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4881 | } |
| 4882 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4883 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4884 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4885 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4886 | { 0x01, 0, 0x0001 }, |
| 4887 | { 0x03, 0x0400, 0x0220 } |
| 4888 | }; |
| 4889 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4890 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4891 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4892 | 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] | 4893 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4894 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4895 | } |
| 4896 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4897 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4898 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4899 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4900 | } |
| 4901 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4902 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4903 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4904 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4905 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4906 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4907 | } |
| 4908 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4909 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4910 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4911 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4912 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4913 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4914 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4915 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4916 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4917 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4918 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4919 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4920 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4921 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4922 | } |
| 4923 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4924 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4925 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4926 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4927 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4928 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4929 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4930 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4931 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4932 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4933 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4936 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4937 | { |
| 4938 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4939 | { 0x0b, 0x0000, 0x0048 }, |
| 4940 | { 0x19, 0x0020, 0x0050 }, |
| 4941 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4942 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4943 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4944 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4945 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4946 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4947 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4948 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4949 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4950 | 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] | 4951 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4952 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4955 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4956 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4957 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4958 | { 0x00, 0x0200, 0x0100 }, |
| 4959 | { 0x00, 0x0000, 0x0004 }, |
| 4960 | { 0x06, 0x0002, 0x0001 }, |
| 4961 | { 0x06, 0x0000, 0x0030 }, |
| 4962 | { 0x07, 0x0000, 0x2000 }, |
| 4963 | { 0x00, 0x0000, 0x0020 }, |
| 4964 | { 0x03, 0x5800, 0x2000 }, |
| 4965 | { 0x03, 0x0000, 0x0001 }, |
| 4966 | { 0x01, 0x0800, 0x1000 }, |
| 4967 | { 0x07, 0x0000, 0x4000 }, |
| 4968 | { 0x1e, 0x0000, 0x2000 }, |
| 4969 | { 0x19, 0xffff, 0xfe6c }, |
| 4970 | { 0x0a, 0x0000, 0x0040 } |
| 4971 | }; |
| 4972 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4973 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4974 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4975 | 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] | 4976 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4977 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4978 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4979 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4980 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4981 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4982 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4983 | |
| 4984 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4985 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4986 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4987 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4988 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4989 | } |
| 4990 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4991 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4992 | { |
| 4993 | static const struct ephy_info e_info_8168e_2[] = { |
| 4994 | { 0x09, 0x0000, 0x0080 }, |
| 4995 | { 0x19, 0x0000, 0x0224 } |
| 4996 | }; |
| 4997 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4998 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4999 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5000 | 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] | 5001 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5002 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5003 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5004 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5005 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5006 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5007 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5008 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5009 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5010 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5011 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5012 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5013 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5014 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5015 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5016 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5017 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5018 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5019 | |
| 5020 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5021 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5022 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5023 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5024 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5025 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 5026 | |
| 5027 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5028 | } |
| 5029 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5030 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5031 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5032 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5033 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5034 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5035 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5036 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5037 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5038 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5039 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5040 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5041 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5042 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5043 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5044 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5045 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5046 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5047 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5048 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5049 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5050 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5051 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5052 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5053 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5054 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5055 | } |
| 5056 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5057 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5058 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5059 | static const struct ephy_info e_info_8168f_1[] = { |
| 5060 | { 0x06, 0x00c0, 0x0020 }, |
| 5061 | { 0x08, 0x0001, 0x0002 }, |
| 5062 | { 0x09, 0x0000, 0x0080 }, |
| 5063 | { 0x19, 0x0000, 0x0224 } |
| 5064 | }; |
| 5065 | |
| 5066 | rtl_hw_start_8168f(tp); |
| 5067 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5068 | 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] | 5069 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5070 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5071 | |
| 5072 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5073 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5076 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5077 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5078 | static const struct ephy_info e_info_8168f_1[] = { |
| 5079 | { 0x06, 0x00c0, 0x0020 }, |
| 5080 | { 0x0f, 0xffff, 0x5200 }, |
| 5081 | { 0x1e, 0x0000, 0x4000 }, |
| 5082 | { 0x19, 0x0000, 0x0224 } |
| 5083 | }; |
| 5084 | |
| 5085 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5086 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5087 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5088 | 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] | 5089 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5090 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5091 | } |
| 5092 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5093 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5094 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5095 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5096 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5097 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5098 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5099 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5100 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5101 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5102 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5103 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5104 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5105 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5106 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5107 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5108 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5109 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5110 | |
| 5111 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5112 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5113 | |
| 5114 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5115 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5116 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5117 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5118 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5119 | |
| 5120 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5121 | } |
| 5122 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5123 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5124 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5125 | static const struct ephy_info e_info_8168g_1[] = { |
| 5126 | { 0x00, 0x0000, 0x0008 }, |
| 5127 | { 0x0c, 0x37d0, 0x0820 }, |
| 5128 | { 0x1e, 0x0000, 0x0001 }, |
| 5129 | { 0x19, 0x8000, 0x0000 } |
| 5130 | }; |
| 5131 | |
| 5132 | rtl_hw_start_8168g(tp); |
| 5133 | |
| 5134 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5135 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5136 | 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] | 5137 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5138 | } |
| 5139 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5140 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5141 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5142 | static const struct ephy_info e_info_8168g_2[] = { |
| 5143 | { 0x00, 0x0000, 0x0008 }, |
| 5144 | { 0x0c, 0x3df0, 0x0200 }, |
| 5145 | { 0x19, 0xffff, 0xfc00 }, |
| 5146 | { 0x1e, 0xffff, 0x20eb } |
| 5147 | }; |
| 5148 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5149 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5150 | |
| 5151 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5152 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5153 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5154 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5155 | } |
| 5156 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5157 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5158 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5159 | static const struct ephy_info e_info_8411_2[] = { |
| 5160 | { 0x00, 0x0000, 0x0008 }, |
| 5161 | { 0x0c, 0x3df0, 0x0200 }, |
| 5162 | { 0x0f, 0xffff, 0x5200 }, |
| 5163 | { 0x19, 0x0020, 0x0000 }, |
| 5164 | { 0x1e, 0x0000, 0x2000 } |
| 5165 | }; |
| 5166 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5167 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5168 | |
| 5169 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5170 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5171 | 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] | 5172 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5173 | } |
| 5174 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5175 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5176 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5177 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5178 | u32 data; |
| 5179 | static const struct ephy_info e_info_8168h_1[] = { |
| 5180 | { 0x1e, 0x0800, 0x0001 }, |
| 5181 | { 0x1d, 0x0000, 0x0800 }, |
| 5182 | { 0x05, 0xffff, 0x2089 }, |
| 5183 | { 0x06, 0xffff, 0x5881 }, |
| 5184 | { 0x04, 0xffff, 0x154a }, |
| 5185 | { 0x01, 0xffff, 0x068b } |
| 5186 | }; |
| 5187 | |
| 5188 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5189 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5190 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5191 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5192 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5193 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5194 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5195 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5196 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5197 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5198 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5199 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5200 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5201 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5202 | 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] | 5203 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5204 | 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] | 5205 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5206 | 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] | 5207 | |
| 5208 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5209 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5210 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5211 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5212 | |
| 5213 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5214 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5215 | |
| 5216 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5217 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5218 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5219 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5220 | 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] | 5221 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5222 | 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] | 5223 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5224 | 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] | 5225 | |
| 5226 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5227 | |
| 5228 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5229 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5230 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5231 | if (rg_saw_cnt > 0) { |
| 5232 | u16 sw_cnt_1ms_ini; |
| 5233 | |
| 5234 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5235 | sw_cnt_1ms_ini &= 0x0fff; |
| 5236 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5237 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5238 | data |= sw_cnt_1ms_ini; |
| 5239 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5240 | } |
| 5241 | |
| 5242 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5243 | data &= ~0xf0; |
| 5244 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5245 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5246 | |
| 5247 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5248 | data &= ~0x6000; |
| 5249 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5250 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5251 | |
| 5252 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5253 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5254 | data |= 0x017f; |
| 5255 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5256 | |
| 5257 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5258 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5259 | data |= 0x047f; |
| 5260 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5261 | |
| 5262 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5263 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5264 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5265 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5266 | |
| 5267 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5268 | } |
| 5269 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5270 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5271 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5272 | rtl8168ep_stop_cmac(tp); |
| 5273 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5274 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5275 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5276 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5277 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5278 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5279 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5280 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5281 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5282 | |
| 5283 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5284 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5285 | |
| 5286 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5287 | |
| 5288 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5289 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5290 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5291 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5292 | |
| 5293 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5294 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5295 | |
| 5296 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5297 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5298 | |
| 5299 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5300 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5301 | 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] | 5302 | |
| 5303 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5304 | } |
| 5305 | |
| 5306 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5307 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5308 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5309 | { 0x00, 0xffff, 0x10ab }, |
| 5310 | { 0x06, 0xffff, 0xf030 }, |
| 5311 | { 0x08, 0xffff, 0x2006 }, |
| 5312 | { 0x0d, 0xffff, 0x1666 }, |
| 5313 | { 0x0c, 0x3ff0, 0x0000 } |
| 5314 | }; |
| 5315 | |
| 5316 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5317 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5318 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5319 | |
| 5320 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5321 | |
| 5322 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5326 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5327 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5328 | { 0x00, 0xffff, 0x10a3 }, |
| 5329 | { 0x19, 0xffff, 0xfc00 }, |
| 5330 | { 0x1e, 0xffff, 0x20ea } |
| 5331 | }; |
| 5332 | |
| 5333 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5334 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5335 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5336 | |
| 5337 | rtl_hw_start_8168ep(tp); |
| 5338 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5339 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5340 | 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] | 5341 | |
| 5342 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5343 | } |
| 5344 | |
| 5345 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5346 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5347 | u32 data; |
| 5348 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5349 | { 0x00, 0xffff, 0x10a3 }, |
| 5350 | { 0x19, 0xffff, 0x7c00 }, |
| 5351 | { 0x1e, 0xffff, 0x20eb }, |
| 5352 | { 0x0d, 0xffff, 0x1666 } |
| 5353 | }; |
| 5354 | |
| 5355 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5356 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5357 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5358 | |
| 5359 | rtl_hw_start_8168ep(tp); |
| 5360 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5361 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5362 | 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] | 5363 | |
| 5364 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5365 | data &= 0xf000; |
| 5366 | data |= 0x0271; |
| 5367 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5368 | |
| 5369 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5370 | data &= 0xff00; |
| 5371 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5372 | |
| 5373 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5374 | data |= 0x0080; |
| 5375 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5376 | |
| 5377 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5378 | } |
| 5379 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5380 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5381 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5382 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5383 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5384 | tp->cp_cmd &= ~INTT_MASK; |
| 5385 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5386 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5387 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5388 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5389 | |
| 5390 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5391 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5392 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5393 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5394 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5395 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5396 | switch (tp->mac_version) { |
| 5397 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5398 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5399 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5400 | |
| 5401 | case RTL_GIGA_MAC_VER_12: |
| 5402 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5403 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5404 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5405 | |
| 5406 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5407 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5408 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5409 | |
| 5410 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5411 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5412 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5413 | |
| 5414 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5415 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5416 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5417 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5418 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5419 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5420 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5421 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5422 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5423 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5424 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5425 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5426 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5427 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5428 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5429 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5430 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5431 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5432 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5433 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5434 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5435 | case RTL_GIGA_MAC_VER_26: |
| 5436 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5437 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5438 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5439 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5440 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5441 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5442 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5443 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5444 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5445 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5446 | break; |
| 5447 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5448 | case RTL_GIGA_MAC_VER_32: |
| 5449 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5450 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5451 | break; |
| 5452 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5453 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5454 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5455 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5456 | case RTL_GIGA_MAC_VER_35: |
| 5457 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5458 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5459 | break; |
| 5460 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5461 | case RTL_GIGA_MAC_VER_38: |
| 5462 | rtl_hw_start_8411(tp); |
| 5463 | break; |
| 5464 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5465 | case RTL_GIGA_MAC_VER_40: |
| 5466 | case RTL_GIGA_MAC_VER_41: |
| 5467 | rtl_hw_start_8168g_1(tp); |
| 5468 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5469 | case RTL_GIGA_MAC_VER_42: |
| 5470 | rtl_hw_start_8168g_2(tp); |
| 5471 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5472 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5473 | case RTL_GIGA_MAC_VER_44: |
| 5474 | rtl_hw_start_8411_2(tp); |
| 5475 | break; |
| 5476 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5477 | case RTL_GIGA_MAC_VER_45: |
| 5478 | case RTL_GIGA_MAC_VER_46: |
| 5479 | rtl_hw_start_8168h_1(tp); |
| 5480 | break; |
| 5481 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5482 | case RTL_GIGA_MAC_VER_49: |
| 5483 | rtl_hw_start_8168ep_1(tp); |
| 5484 | break; |
| 5485 | |
| 5486 | case RTL_GIGA_MAC_VER_50: |
| 5487 | rtl_hw_start_8168ep_2(tp); |
| 5488 | break; |
| 5489 | |
| 5490 | case RTL_GIGA_MAC_VER_51: |
| 5491 | rtl_hw_start_8168ep_3(tp); |
| 5492 | break; |
| 5493 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5494 | default: |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 5495 | netif_err(tp, drv, tp->dev, |
| 5496 | "unknown chipset (mac_version = %d)\n", |
| 5497 | tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5498 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5499 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5502 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5503 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5504 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5505 | { 0x01, 0, 0x6e65 }, |
| 5506 | { 0x02, 0, 0x091f }, |
| 5507 | { 0x03, 0, 0xc2f9 }, |
| 5508 | { 0x06, 0, 0xafb5 }, |
| 5509 | { 0x07, 0, 0x0e00 }, |
| 5510 | { 0x19, 0, 0xec80 }, |
| 5511 | { 0x01, 0, 0x2e65 }, |
| 5512 | { 0x01, 0, 0x6e65 } |
| 5513 | }; |
| 5514 | u8 cfg1; |
| 5515 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5516 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5517 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5518 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5519 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5520 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5521 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5522 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5523 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5524 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5525 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5526 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5527 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5528 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5529 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5530 | 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] | 5531 | } |
| 5532 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5533 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5534 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5535 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5536 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5537 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5538 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5539 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5540 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5541 | } |
| 5542 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5543 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5544 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5545 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5546 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5547 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5548 | } |
| 5549 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5550 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5551 | { |
| 5552 | static const struct ephy_info e_info_8105e_1[] = { |
| 5553 | { 0x07, 0, 0x4000 }, |
| 5554 | { 0x19, 0, 0x0200 }, |
| 5555 | { 0x19, 0, 0x0020 }, |
| 5556 | { 0x1e, 0, 0x2000 }, |
| 5557 | { 0x03, 0, 0x0001 }, |
| 5558 | { 0x19, 0, 0x0100 }, |
| 5559 | { 0x19, 0, 0x0004 }, |
| 5560 | { 0x0a, 0, 0x0020 } |
| 5561 | }; |
| 5562 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5563 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5564 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5565 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5566 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5567 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5568 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5569 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5570 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5571 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5572 | 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] | 5573 | |
| 5574 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5575 | } |
| 5576 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5577 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5578 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5579 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5580 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5581 | } |
| 5582 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5583 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5584 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5585 | static const struct ephy_info e_info_8402[] = { |
| 5586 | { 0x19, 0xffff, 0xff64 }, |
| 5587 | { 0x1e, 0, 0x4000 } |
| 5588 | }; |
| 5589 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5590 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5591 | |
| 5592 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5593 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5594 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5595 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5596 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5597 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5598 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5599 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5600 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5601 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 5602 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5603 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5604 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5605 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5606 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5607 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5608 | |
| 5609 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5610 | } |
| 5611 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5612 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5613 | { |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5614 | rtl_hw_aspm_clkreq_enable(tp, false); |
| 5615 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5616 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5617 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5618 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5619 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5620 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5621 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5622 | |
| 5623 | rtl_pcie_state_l2l3_enable(tp, false); |
Kai-Heng Feng | 0866cd1 | 2018-09-12 14:58:21 +0800 | [diff] [blame] | 5624 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5625 | } |
| 5626 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5627 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5628 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5629 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 5630 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5631 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5632 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5633 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5634 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5635 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5636 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5637 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5638 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5639 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5640 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5641 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5642 | switch (tp->mac_version) { |
| 5643 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5644 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5645 | break; |
| 5646 | |
| 5647 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5648 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5649 | break; |
| 5650 | |
| 5651 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5652 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5653 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5654 | |
| 5655 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5656 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5657 | break; |
| 5658 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5659 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5660 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5661 | |
| 5662 | case RTL_GIGA_MAC_VER_37: |
| 5663 | rtl_hw_start_8402(tp); |
| 5664 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5665 | |
| 5666 | case RTL_GIGA_MAC_VER_39: |
| 5667 | rtl_hw_start_8106(tp); |
| 5668 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5669 | case RTL_GIGA_MAC_VER_43: |
| 5670 | rtl_hw_start_8168g_2(tp); |
| 5671 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5672 | case RTL_GIGA_MAC_VER_47: |
| 5673 | case RTL_GIGA_MAC_VER_48: |
| 5674 | rtl_hw_start_8168h_1(tp); |
| 5675 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5676 | } |
| 5677 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5678 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
| 5681 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5682 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5683 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5684 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5685 | if (new_mtu > ETH_DATA_LEN) |
| 5686 | rtl_hw_jumbo_enable(tp); |
| 5687 | else |
| 5688 | rtl_hw_jumbo_disable(tp); |
| 5689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5691 | netdev_update_features(dev); |
| 5692 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5693 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5697 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5698 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5700 | } |
| 5701 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5702 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5703 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5705 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 5706 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5707 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5708 | kfree(*data_buff); |
| 5709 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | rtl8169_make_unusable_by_asic(desc); |
| 5711 | } |
| 5712 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5713 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5714 | { |
| 5715 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5716 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5717 | /* Force memory writes to complete before releasing descriptor */ |
| 5718 | dma_wmb(); |
| 5719 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5720 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | } |
| 5722 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5723 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5725 | return (void *)ALIGN((long)data, 16); |
| 5726 | } |
| 5727 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5728 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5729 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5730 | { |
| 5731 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5733 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5734 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5736 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5737 | if (!data) |
| 5738 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5739 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5740 | if (rtl8169_align(data) != data) { |
| 5741 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5742 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5743 | if (!data) |
| 5744 | return NULL; |
| 5745 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5746 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5747 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 5748 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5749 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5750 | if (net_ratelimit()) |
| 5751 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5752 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5755 | desc->addr = cpu_to_le64(mapping); |
| 5756 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5757 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5758 | |
| 5759 | err_out: |
| 5760 | kfree(data); |
| 5761 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5765 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5766 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | |
| 5768 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5769 | if (tp->Rx_databuff[i]) { |
| 5770 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | tp->RxDescArray + i); |
| 5772 | } |
| 5773 | } |
| 5774 | } |
| 5775 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5776 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5777 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5778 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5779 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5780 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5781 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5782 | { |
| 5783 | unsigned int i; |
| 5784 | |
| 5785 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5786 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5787 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5788 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5789 | if (!data) { |
| 5790 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5791 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5792 | } |
| 5793 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5796 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5797 | return 0; |
| 5798 | |
| 5799 | err_out: |
| 5800 | rtl8169_rx_clear(tp); |
| 5801 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | } |
| 5803 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5804 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | rtl8169_init_ring_indexes(tp); |
| 5807 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5808 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5809 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5811 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5814 | 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] | 5815 | struct TxDesc *desc) |
| 5816 | { |
| 5817 | unsigned int len = tx_skb->len; |
| 5818 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5819 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | desc->opts1 = 0x00; |
| 5822 | desc->opts2 = 0x00; |
| 5823 | desc->addr = 0x00; |
| 5824 | tx_skb->len = 0; |
| 5825 | } |
| 5826 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5827 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5828 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | { |
| 5830 | unsigned int i; |
| 5831 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5832 | for (i = 0; i < n; i++) { |
| 5833 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5835 | unsigned int len = tx_skb->len; |
| 5836 | |
| 5837 | if (len) { |
| 5838 | struct sk_buff *skb = tx_skb->skb; |
| 5839 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5840 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | tp->TxDescArray + entry); |
| 5842 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5843 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | tx_skb->skb = NULL; |
| 5845 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | } |
| 5847 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5851 | { |
| 5852 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | tp->cur_tx = tp->dirty_tx = 0; |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 5854 | netdev_reset_queue(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | } |
| 5856 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5857 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5859 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5860 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5861 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5862 | napi_disable(&tp->napi); |
| 5863 | netif_stop_queue(dev); |
| 5864 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5865 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5866 | rtl8169_hw_reset(tp); |
| 5867 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5868 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5869 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5872 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5873 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5874 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5875 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5876 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | } |
| 5878 | |
| 5879 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5880 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5881 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5882 | |
| 5883 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | 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] | 5887 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5888 | { |
| 5889 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5890 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5891 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5892 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5893 | |
| 5894 | entry = tp->cur_tx; |
| 5895 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5896 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5897 | dma_addr_t mapping; |
| 5898 | u32 status, len; |
| 5899 | void *addr; |
| 5900 | |
| 5901 | entry = (entry + 1) % NUM_TX_DESC; |
| 5902 | |
| 5903 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5904 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5905 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5906 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5907 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5908 | if (net_ratelimit()) |
| 5909 | netif_err(tp, drv, tp->dev, |
| 5910 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5911 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5913 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5914 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5915 | status = opts[0] | len | |
| 5916 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5917 | |
| 5918 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5919 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5920 | txd->addr = cpu_to_le64(mapping); |
| 5921 | |
| 5922 | tp->tx_skb[entry].len = len; |
| 5923 | } |
| 5924 | |
| 5925 | if (cur_frag) { |
| 5926 | tp->tx_skb[entry].skb = skb; |
| 5927 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5928 | } |
| 5929 | |
| 5930 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5931 | |
| 5932 | err_out: |
| 5933 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5934 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5937 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5938 | { |
| 5939 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5940 | } |
| 5941 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5942 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5943 | struct net_device *dev); |
| 5944 | /* r8169_csum_workaround() |
| 5945 | * The hw limites the value the transport offset. When the offset is out of the |
| 5946 | * range, calculate the checksum by sw. |
| 5947 | */ |
| 5948 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 5949 | struct sk_buff *skb) |
| 5950 | { |
| 5951 | if (skb_shinfo(skb)->gso_size) { |
| 5952 | netdev_features_t features = tp->dev->features; |
| 5953 | struct sk_buff *segs, *nskb; |
| 5954 | |
| 5955 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 5956 | segs = skb_gso_segment(skb, features); |
| 5957 | if (IS_ERR(segs) || !segs) |
| 5958 | goto drop; |
| 5959 | |
| 5960 | do { |
| 5961 | nskb = segs; |
| 5962 | segs = segs->next; |
| 5963 | nskb->next = NULL; |
| 5964 | rtl8169_start_xmit(nskb, tp->dev); |
| 5965 | } while (segs); |
| 5966 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5967 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5968 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5969 | if (skb_checksum_help(skb) < 0) |
| 5970 | goto drop; |
| 5971 | |
| 5972 | rtl8169_start_xmit(skb, tp->dev); |
| 5973 | } else { |
| 5974 | struct net_device_stats *stats; |
| 5975 | |
| 5976 | drop: |
| 5977 | stats = &tp->dev->stats; |
| 5978 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5979 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | /* msdn_giant_send_check() |
| 5984 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5985 | * packet length for IPv6 TCP large packets. |
| 5986 | */ |
| 5987 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 5988 | { |
| 5989 | const struct ipv6hdr *ipv6h; |
| 5990 | struct tcphdr *th; |
| 5991 | int ret; |
| 5992 | |
| 5993 | ret = skb_cow_head(skb, 0); |
| 5994 | if (ret) |
| 5995 | return ret; |
| 5996 | |
| 5997 | ipv6h = ipv6_hdr(skb); |
| 5998 | th = tcp_hdr(skb); |
| 5999 | |
| 6000 | th->check = 0; |
| 6001 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6002 | |
| 6003 | return ret; |
| 6004 | } |
| 6005 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6006 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6007 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6009 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6011 | if (mss) { |
| 6012 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6013 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6014 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6015 | const struct iphdr *ip = ip_hdr(skb); |
| 6016 | |
| 6017 | if (ip->protocol == IPPROTO_TCP) |
| 6018 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6019 | else if (ip->protocol == IPPROTO_UDP) |
| 6020 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6021 | else |
| 6022 | WARN_ON_ONCE(1); |
| 6023 | } |
| 6024 | |
| 6025 | return true; |
| 6026 | } |
| 6027 | |
| 6028 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6029 | struct sk_buff *skb, u32 *opts) |
| 6030 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6031 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6032 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6033 | |
| 6034 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6035 | if (transport_offset > GTTCPHO_MAX) { |
| 6036 | netif_warn(tp, tx_err, tp->dev, |
| 6037 | "Invalid transport offset 0x%x for TSO\n", |
| 6038 | transport_offset); |
| 6039 | return false; |
| 6040 | } |
| 6041 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6042 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6043 | case htons(ETH_P_IP): |
| 6044 | opts[0] |= TD1_GTSENV4; |
| 6045 | break; |
| 6046 | |
| 6047 | case htons(ETH_P_IPV6): |
| 6048 | if (msdn_giant_send_check(skb)) |
| 6049 | return false; |
| 6050 | |
| 6051 | opts[0] |= TD1_GTSENV6; |
| 6052 | break; |
| 6053 | |
| 6054 | default: |
| 6055 | WARN_ON_ONCE(1); |
| 6056 | break; |
| 6057 | } |
| 6058 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6059 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6060 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6061 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6062 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6064 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6065 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6066 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6067 | if (transport_offset > TCPHO_MAX) { |
| 6068 | netif_warn(tp, tx_err, tp->dev, |
| 6069 | "Invalid transport offset 0x%x\n", |
| 6070 | transport_offset); |
| 6071 | return false; |
| 6072 | } |
| 6073 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6074 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6075 | case htons(ETH_P_IP): |
| 6076 | opts[1] |= TD1_IPv4_CS; |
| 6077 | ip_protocol = ip_hdr(skb)->protocol; |
| 6078 | break; |
| 6079 | |
| 6080 | case htons(ETH_P_IPV6): |
| 6081 | opts[1] |= TD1_IPv6_CS; |
| 6082 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6083 | break; |
| 6084 | |
| 6085 | default: |
| 6086 | ip_protocol = IPPROTO_RAW; |
| 6087 | break; |
| 6088 | } |
| 6089 | |
| 6090 | if (ip_protocol == IPPROTO_TCP) |
| 6091 | opts[1] |= TD1_TCP_CS; |
| 6092 | else if (ip_protocol == IPPROTO_UDP) |
| 6093 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6094 | else |
| 6095 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6096 | |
| 6097 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6098 | } else { |
| 6099 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6100 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6102 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6103 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6104 | } |
| 6105 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6106 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6107 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | { |
| 6109 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6110 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6112 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | dma_addr_t mapping; |
| 6114 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6115 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6116 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6117 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6118 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6119 | 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] | 6120 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6124 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6126 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6127 | opts[0] = DescOwn; |
| 6128 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6129 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6130 | r8169_csum_workaround(tp, skb); |
| 6131 | return NETDEV_TX_OK; |
| 6132 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6133 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6134 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6135 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6136 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6137 | if (net_ratelimit()) |
| 6138 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6139 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6141 | |
| 6142 | tp->tx_skb[entry].len = len; |
| 6143 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6145 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6146 | if (frags < 0) |
| 6147 | goto err_dma_1; |
| 6148 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6149 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6150 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6151 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6152 | tp->tx_skb[entry].skb = skb; |
| 6153 | } |
| 6154 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6155 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6156 | |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6157 | netdev_sent_queue(dev, skb->len); |
| 6158 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6159 | skb_tx_timestamp(skb); |
| 6160 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6161 | /* Force memory writes to complete before releasing descriptor */ |
| 6162 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6163 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6164 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6165 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6166 | txd->opts1 = cpu_to_le32(status); |
| 6167 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6168 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6169 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6171 | tp->cur_tx += frags + 1; |
| 6172 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6173 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6175 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6176 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6177 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6178 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6179 | * not miss a ring update when it notices a stopped queue. |
| 6180 | */ |
| 6181 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6182 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6183 | /* Sync with rtl_tx: |
| 6184 | * - publish queue status and cur_tx ring index (write barrier) |
| 6185 | * - refresh dirty_tx ring index (read barrier). |
| 6186 | * May the current thread have a pessimistic view of the ring |
| 6187 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6188 | * can't. |
| 6189 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6190 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6191 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | netif_wake_queue(dev); |
| 6193 | } |
| 6194 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6195 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6197 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6198 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6199 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6200 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6201 | dev->stats.tx_dropped++; |
| 6202 | return NETDEV_TX_OK; |
| 6203 | |
| 6204 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6205 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6206 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6207 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6211 | { |
| 6212 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6213 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | u16 pci_status, pci_cmd; |
| 6215 | |
| 6216 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6217 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6218 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6219 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6220 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6221 | |
| 6222 | /* |
| 6223 | * The recovery sequence below admits a very elaborated explanation: |
| 6224 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6225 | * - I did not see what else could be done; |
| 6226 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6227 | * |
| 6228 | * Feel free to adjust to your needs. |
| 6229 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6230 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6231 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6232 | else |
| 6233 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6234 | |
| 6235 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6236 | |
| 6237 | pci_write_config_word(pdev, PCI_STATUS, |
| 6238 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6239 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6240 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6241 | |
| 6242 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6243 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6244 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6246 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6247 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | } |
| 6249 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6250 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6251 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6252 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6253 | } |
| 6254 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6255 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6257 | unsigned int dirty_tx, tx_left, bytes_compl = 0, pkts_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6259 | dirty_tx = tp->dirty_tx; |
| 6260 | smp_rmb(); |
| 6261 | tx_left = tp->cur_tx - dirty_tx; |
| 6262 | |
| 6263 | while (tx_left > 0) { |
| 6264 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6265 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | u32 status; |
| 6267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6269 | if (status & DescOwn) |
| 6270 | break; |
| 6271 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6272 | /* This barrier is needed to keep us from reading |
| 6273 | * any other fields out of the Tx descriptor until |
| 6274 | * we know the status of DescOwn |
| 6275 | */ |
| 6276 | dma_rmb(); |
| 6277 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6278 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6279 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | if (status & LastFrag) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6281 | pkts_compl++; |
| 6282 | bytes_compl += tx_skb->skb->len; |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6283 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | tx_skb->skb = NULL; |
| 6285 | } |
| 6286 | dirty_tx++; |
| 6287 | tx_left--; |
| 6288 | } |
| 6289 | |
| 6290 | if (tp->dirty_tx != dirty_tx) { |
Florian Westphal | d92060b | 2018-10-20 12:25:27 +0200 | [diff] [blame] | 6291 | netdev_completed_queue(dev, pkts_compl, bytes_compl); |
| 6292 | |
| 6293 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6294 | tp->tx_stats.packets += pkts_compl; |
| 6295 | tp->tx_stats.bytes += bytes_compl; |
| 6296 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 6297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6299 | /* Sync with rtl8169_start_xmit: |
| 6300 | * - publish dirty_tx ring index (write barrier) |
| 6301 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6302 | * May the current thread miss the stopped queue condition, |
| 6303 | * a racing xmit thread can only have a right view of the |
| 6304 | * ring status. |
| 6305 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6306 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6307 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6308 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | netif_wake_queue(dev); |
| 6310 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6311 | /* |
| 6312 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6313 | * too close. Let's kick an extra TxPoll request when a burst |
| 6314 | * of start_xmit activity is detected (if it is not detected, |
| 6315 | * it is slow enough). -- FR |
| 6316 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6317 | if (tp->cur_tx != dirty_tx) |
| 6318 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6319 | } |
| 6320 | } |
| 6321 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6322 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6323 | { |
| 6324 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6325 | } |
| 6326 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6327 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6328 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6329 | u32 status = opts1 & RxProtoMask; |
| 6330 | |
| 6331 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6332 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6334 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6335 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6338 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6339 | struct rtl8169_private *tp, |
| 6340 | int pkt_size, |
| 6341 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6343 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6344 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6346 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6347 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6348 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6349 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6350 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6351 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6352 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6353 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6354 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6355 | } |
| 6356 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6357 | 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] | 6358 | { |
| 6359 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6360 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6364 | 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] | 6365 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6366 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6367 | u32 status; |
| 6368 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6369 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6370 | if (status & DescOwn) |
| 6371 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6372 | |
| 6373 | /* This barrier is needed to keep us from reading |
| 6374 | * any other fields out of the Rx descriptor until |
| 6375 | * we know the status of DescOwn |
| 6376 | */ |
| 6377 | dma_rmb(); |
| 6378 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6379 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6380 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6381 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6382 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6384 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6385 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6386 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6387 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6388 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6389 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6390 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6391 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6392 | } else if (status & (RxRUNT | RxCRC) && |
| 6393 | !(status & RxRWT) && |
| 6394 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6395 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6398 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6399 | dma_addr_t addr; |
| 6400 | int pkt_size; |
| 6401 | |
| 6402 | process_pkt: |
| 6403 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6404 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6405 | pkt_size = (status & 0x00003fff) - 4; |
| 6406 | else |
| 6407 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6409 | /* |
| 6410 | * The driver does not support incoming fragmented |
| 6411 | * frames. They are seen as a symptom of over-mtu |
| 6412 | * sized frames. |
| 6413 | */ |
| 6414 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6415 | dev->stats.rx_dropped++; |
| 6416 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6417 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6418 | } |
| 6419 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6420 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6421 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6422 | if (!skb) { |
| 6423 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6424 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6425 | } |
| 6426 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6427 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6428 | skb_put(skb, pkt_size); |
| 6429 | skb->protocol = eth_type_trans(skb, dev); |
| 6430 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6431 | rtl8169_rx_vlan_tag(desc, skb); |
| 6432 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6433 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6434 | dev->stats.multicast++; |
| 6435 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6436 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6438 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6439 | tp->rx_stats.packets++; |
| 6440 | tp->rx_stats.bytes += pkt_size; |
| 6441 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6443 | release_descriptor: |
| 6444 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6445 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
| 6448 | count = cur_rx - tp->cur_rx; |
| 6449 | tp->cur_rx = cur_rx; |
| 6450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6451 | return count; |
| 6452 | } |
| 6453 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6454 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6456 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6457 | u16 status = rtl_get_events(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6458 | |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6459 | if (status == 0xffff || !(status & (RTL_EVENT_NAPI | tp->event_slow))) |
| 6460 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6461 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6462 | if (unlikely(status & SYSErr)) { |
| 6463 | rtl8169_pcierr_interrupt(tp->dev); |
| 6464 | goto out; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6465 | } |
| 6466 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6467 | if (status & LinkChg) |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6468 | phy_mac_interrupt(tp->dev->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6469 | |
Heiner Kallweit | 38caff5 | 2018-10-18 22:19:28 +0200 | [diff] [blame] | 6470 | if (unlikely(status & RxFIFOOver && |
| 6471 | tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
| 6472 | netif_stop_queue(tp->dev); |
| 6473 | /* XXX - Hack alert. See rtl_task(). */ |
| 6474 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
| 6475 | } |
| 6476 | |
| 6477 | if (status & RTL_EVENT_NAPI) { |
| 6478 | rtl_irq_disable(tp); |
| 6479 | napi_schedule_irqoff(&tp->napi); |
| 6480 | } |
| 6481 | out: |
| 6482 | rtl_ack_events(tp, status); |
| 6483 | |
| 6484 | return IRQ_HANDLED; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6485 | } |
| 6486 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6487 | static void rtl_task(struct work_struct *work) |
| 6488 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6489 | static const struct { |
| 6490 | int bitnr; |
| 6491 | void (*action)(struct rtl8169_private *); |
| 6492 | } rtl_work[] = { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6493 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6494 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6495 | struct rtl8169_private *tp = |
| 6496 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6497 | struct net_device *dev = tp->dev; |
| 6498 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6499 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6500 | rtl_lock_work(tp); |
| 6501 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6502 | if (!netif_running(dev) || |
| 6503 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6504 | goto out_unlock; |
| 6505 | |
| 6506 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6507 | bool pending; |
| 6508 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6509 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6510 | if (pending) |
| 6511 | rtl_work[i].action(tp); |
| 6512 | } |
| 6513 | |
| 6514 | out_unlock: |
| 6515 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6516 | } |
| 6517 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6518 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6519 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6520 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6521 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6522 | int work_done; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6523 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6524 | work_done = rtl_rx(dev, tp, (u32) budget); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6525 | |
Heiner Kallweit | 6b839b6 | 2018-10-18 19:56:01 +0200 | [diff] [blame] | 6526 | rtl_tx(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6527 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6528 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 6529 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 6530 | |
Heiner Kallweit | fe716f8 | 2018-11-19 22:31:32 +0100 | [diff] [blame] | 6531 | rtl_irq_enable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6532 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6533 | } |
| 6534 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6535 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6537 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6538 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6539 | { |
| 6540 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6541 | |
| 6542 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6543 | return; |
| 6544 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6545 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 6546 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6547 | } |
| 6548 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6549 | static void r8169_phylink_handler(struct net_device *ndev) |
| 6550 | { |
| 6551 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 6552 | |
| 6553 | if (netif_carrier_ok(ndev)) { |
| 6554 | rtl_link_chg_patch(tp); |
| 6555 | pm_request_resume(&tp->pci_dev->dev); |
| 6556 | } else { |
| 6557 | pm_runtime_idle(&tp->pci_dev->dev); |
| 6558 | } |
| 6559 | |
| 6560 | if (net_ratelimit()) |
| 6561 | phy_print_status(ndev->phydev); |
| 6562 | } |
| 6563 | |
| 6564 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 6565 | { |
| 6566 | struct phy_device *phydev = mdiobus_get_phy(tp->mii_bus, 0); |
| 6567 | phy_interface_t phy_mode; |
| 6568 | int ret; |
| 6569 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6570 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6571 | PHY_INTERFACE_MODE_MII; |
| 6572 | |
| 6573 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 6574 | phy_mode); |
| 6575 | if (ret) |
| 6576 | return ret; |
| 6577 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6578 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6579 | phy_set_max_speed(phydev, SPEED_100); |
| 6580 | |
| 6581 | /* Ensure to advertise everything, incl. pause */ |
Andrew Lunn | 3c1bcc8 | 2018-11-10 23:43:33 +0100 | [diff] [blame] | 6582 | linkmode_copy(phydev->advertising, phydev->supported); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6583 | |
| 6584 | phy_attached_info(phydev); |
| 6585 | |
| 6586 | return 0; |
| 6587 | } |
| 6588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6589 | static void rtl8169_down(struct net_device *dev) |
| 6590 | { |
| 6591 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6592 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6593 | phy_stop(dev->phydev); |
| 6594 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6595 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6596 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6597 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6598 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6599 | /* |
| 6600 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6601 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6602 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6603 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6604 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6606 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6607 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6609 | rtl8169_tx_clear(tp); |
| 6610 | |
| 6611 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6612 | |
| 6613 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6614 | } |
| 6615 | |
| 6616 | static int rtl8169_close(struct net_device *dev) |
| 6617 | { |
| 6618 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6619 | struct pci_dev *pdev = tp->pci_dev; |
| 6620 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6621 | pm_runtime_get_sync(&pdev->dev); |
| 6622 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6623 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6624 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6625 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6626 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6627 | /* Clear all task flags */ |
| 6628 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6630 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6631 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6632 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6633 | cancel_work_sync(&tp->wk.work); |
| 6634 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6635 | phy_disconnect(dev->phydev); |
| 6636 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6637 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6638 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6639 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6640 | tp->RxPhyAddr); |
| 6641 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6642 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6643 | tp->TxDescArray = NULL; |
| 6644 | tp->RxDescArray = NULL; |
| 6645 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6646 | pm_runtime_put_sync(&pdev->dev); |
| 6647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6648 | return 0; |
| 6649 | } |
| 6650 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6651 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6652 | static void rtl8169_netpoll(struct net_device *dev) |
| 6653 | { |
| 6654 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6655 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6656 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6657 | } |
| 6658 | #endif |
| 6659 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6660 | static int rtl_open(struct net_device *dev) |
| 6661 | { |
| 6662 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6663 | struct pci_dev *pdev = tp->pci_dev; |
| 6664 | int retval = -ENOMEM; |
| 6665 | |
| 6666 | pm_runtime_get_sync(&pdev->dev); |
| 6667 | |
| 6668 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6669 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6670 | * dma_alloc_coherent provides more. |
| 6671 | */ |
| 6672 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6673 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6674 | if (!tp->TxDescArray) |
| 6675 | goto err_pm_runtime_put; |
| 6676 | |
| 6677 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6678 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6679 | if (!tp->RxDescArray) |
| 6680 | goto err_free_tx_0; |
| 6681 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6682 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6683 | if (retval < 0) |
| 6684 | goto err_free_rx_1; |
| 6685 | |
| 6686 | INIT_WORK(&tp->wk.work, rtl_task); |
| 6687 | |
| 6688 | smp_mb(); |
| 6689 | |
| 6690 | rtl_request_firmware(tp); |
| 6691 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6692 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6693 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6694 | if (retval < 0) |
| 6695 | goto err_release_fw_2; |
| 6696 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6697 | retval = r8169_phy_connect(tp); |
| 6698 | if (retval) |
| 6699 | goto err_free_irq; |
| 6700 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6701 | rtl_lock_work(tp); |
| 6702 | |
| 6703 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6704 | |
| 6705 | napi_enable(&tp->napi); |
| 6706 | |
| 6707 | rtl8169_init_phy(dev, tp); |
| 6708 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6709 | rtl_pll_power_up(tp); |
| 6710 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6711 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6712 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6713 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6714 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6715 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6716 | phy_start(dev->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6717 | netif_start_queue(dev); |
| 6718 | |
| 6719 | rtl_unlock_work(tp); |
| 6720 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6721 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6722 | out: |
| 6723 | return retval; |
| 6724 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6725 | err_free_irq: |
| 6726 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6727 | err_release_fw_2: |
| 6728 | rtl_release_firmware(tp); |
| 6729 | rtl8169_rx_clear(tp); |
| 6730 | err_free_rx_1: |
| 6731 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6732 | tp->RxPhyAddr); |
| 6733 | tp->RxDescArray = NULL; |
| 6734 | err_free_tx_0: |
| 6735 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6736 | tp->TxPhyAddr); |
| 6737 | tp->TxDescArray = NULL; |
| 6738 | err_pm_runtime_put: |
| 6739 | pm_runtime_put_noidle(&pdev->dev); |
| 6740 | goto out; |
| 6741 | } |
| 6742 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6743 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6744 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | { |
| 6746 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6747 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6748 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6749 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6750 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6751 | pm_runtime_get_noresume(&pdev->dev); |
| 6752 | |
| 6753 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6754 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6755 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6756 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6757 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6758 | stats->rx_packets = tp->rx_stats.packets; |
| 6759 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6760 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6761 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6762 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6763 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6764 | stats->tx_packets = tp->tx_stats.packets; |
| 6765 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6766 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6767 | |
| 6768 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6769 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6770 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6771 | stats->rx_errors = dev->stats.rx_errors; |
| 6772 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6773 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6774 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6775 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6776 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6777 | /* |
| 6778 | * Fetch additonal counter values missing in stats collected by driver |
| 6779 | * from tally counters. |
| 6780 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6781 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6782 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6783 | |
| 6784 | /* |
| 6785 | * Subtract values fetched during initalization. |
| 6786 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6787 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6788 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6789 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6790 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6791 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6792 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6793 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6794 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6795 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6796 | } |
| 6797 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6798 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6799 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6800 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6801 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6802 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6803 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6804 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6805 | phy_stop(dev->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6806 | netif_device_detach(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6807 | |
| 6808 | rtl_lock_work(tp); |
| 6809 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6810 | /* Clear all task flags */ |
| 6811 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6812 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6813 | rtl_unlock_work(tp); |
| 6814 | |
| 6815 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6816 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6817 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6818 | #ifdef CONFIG_PM |
| 6819 | |
| 6820 | static int rtl8169_suspend(struct device *device) |
| 6821 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame^] | 6822 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6823 | struct rtl8169_private *tp = netdev_priv(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6824 | |
| 6825 | rtl8169_net_suspend(dev); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6826 | clk_disable_unprepare(tp->clk); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6827 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6828 | return 0; |
| 6829 | } |
| 6830 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6831 | static void __rtl8169_resume(struct net_device *dev) |
| 6832 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6833 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6834 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6835 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6836 | |
| 6837 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6838 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6839 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6840 | phy_start(tp->dev->phydev); |
| 6841 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6842 | rtl_lock_work(tp); |
| 6843 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6844 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6845 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6846 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6847 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6848 | } |
| 6849 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6850 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6851 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame^] | 6852 | struct net_device *dev = dev_get_drvdata(device); |
Hans de Goede | ac8bd9e | 2018-09-26 22:12:39 +0200 | [diff] [blame] | 6853 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6854 | |
| 6855 | clk_prepare_enable(tp->clk); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6856 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6857 | if (netif_running(dev)) |
| 6858 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6859 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6860 | return 0; |
| 6861 | } |
| 6862 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6863 | static int rtl8169_runtime_suspend(struct device *device) |
| 6864 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame^] | 6865 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6866 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6867 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6868 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6869 | return 0; |
| 6870 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6871 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6872 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6873 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6874 | |
| 6875 | rtl8169_net_suspend(dev); |
| 6876 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6877 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6878 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6879 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6880 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6881 | return 0; |
| 6882 | } |
| 6883 | |
| 6884 | static int rtl8169_runtime_resume(struct device *device) |
| 6885 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame^] | 6886 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6887 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6888 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6889 | |
| 6890 | if (!tp->TxDescArray) |
| 6891 | return 0; |
| 6892 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6893 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6894 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6895 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6896 | |
| 6897 | __rtl8169_resume(dev); |
| 6898 | |
| 6899 | return 0; |
| 6900 | } |
| 6901 | |
| 6902 | static int rtl8169_runtime_idle(struct device *device) |
| 6903 | { |
Heiner Kallweit | 0f07bd8 | 2018-11-19 22:32:18 +0100 | [diff] [blame^] | 6904 | struct net_device *dev = dev_get_drvdata(device); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6905 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6906 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6907 | pm_schedule_suspend(device, 10000); |
| 6908 | |
| 6909 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6910 | } |
| 6911 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6912 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6913 | .suspend = rtl8169_suspend, |
| 6914 | .resume = rtl8169_resume, |
| 6915 | .freeze = rtl8169_suspend, |
| 6916 | .thaw = rtl8169_resume, |
| 6917 | .poweroff = rtl8169_suspend, |
| 6918 | .restore = rtl8169_resume, |
| 6919 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6920 | .runtime_resume = rtl8169_runtime_resume, |
| 6921 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6922 | }; |
| 6923 | |
| 6924 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6925 | |
| 6926 | #else /* !CONFIG_PM */ |
| 6927 | |
| 6928 | #define RTL8169_PM_OPS NULL |
| 6929 | |
| 6930 | #endif /* !CONFIG_PM */ |
| 6931 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6932 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6933 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6934 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6935 | switch (tp->mac_version) { |
| 6936 | case RTL_GIGA_MAC_VER_11: |
| 6937 | case RTL_GIGA_MAC_VER_12: |
| 6938 | case RTL_GIGA_MAC_VER_17: |
| 6939 | pci_clear_master(tp->pci_dev); |
| 6940 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6941 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6942 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6943 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6944 | break; |
| 6945 | default: |
| 6946 | break; |
| 6947 | } |
| 6948 | } |
| 6949 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6950 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6951 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6952 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6953 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6954 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6955 | rtl8169_net_suspend(dev); |
| 6956 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6957 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6958 | rtl_rar_set(tp, dev->perm_addr); |
| 6959 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6960 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6961 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6962 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6963 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6964 | rtl_wol_suspend_quirk(tp); |
| 6965 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6966 | } |
| 6967 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6968 | pci_wake_from_d3(pdev, true); |
| 6969 | pci_set_power_state(pdev, PCI_D3hot); |
| 6970 | } |
| 6971 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6972 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 6973 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6974 | { |
| 6975 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6976 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6977 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 6978 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6979 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6980 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6981 | netif_napi_del(&tp->napi); |
| 6982 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6983 | unregister_netdev(dev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6984 | mdiobus_unregister(tp->mii_bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6985 | |
| 6986 | rtl_release_firmware(tp); |
| 6987 | |
| 6988 | if (pci_dev_run_wake(pdev)) |
| 6989 | pm_runtime_get_noresume(&pdev->dev); |
| 6990 | |
| 6991 | /* restore original MAC address */ |
| 6992 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6993 | } |
| 6994 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6995 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6996 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6997 | .ndo_stop = rtl8169_close, |
| 6998 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6999 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7000 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7001 | .ndo_validate_addr = eth_validate_addr, |
| 7002 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7003 | .ndo_fix_features = rtl8169_fix_features, |
| 7004 | .ndo_set_features = rtl8169_set_features, |
| 7005 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7006 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7007 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7008 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7009 | .ndo_poll_controller = rtl8169_netpoll, |
| 7010 | #endif |
| 7011 | |
| 7012 | }; |
| 7013 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7014 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7015 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7016 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7017 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7018 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7019 | u8 default_ver; |
| 7020 | } rtl_cfg_infos [] = { |
| 7021 | [RTL_CFG_0] = { |
| 7022 | .hw_start = rtl_hw_start_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7023 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7024 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7025 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7026 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7027 | }, |
| 7028 | [RTL_CFG_1] = { |
| 7029 | .hw_start = rtl_hw_start_8168, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7030 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7031 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7032 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7033 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7034 | }, |
| 7035 | [RTL_CFG_2] = { |
| 7036 | .hw_start = rtl_hw_start_8101, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7037 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7038 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7039 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7040 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7041 | } |
| 7042 | }; |
| 7043 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7044 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7045 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7046 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7047 | |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 7048 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7049 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7050 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7051 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7052 | flags = PCI_IRQ_LEGACY; |
Jian-Hong Pan | d49c88d | 2018-09-27 12:09:48 +0800 | [diff] [blame] | 7053 | } else { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7054 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7055 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7056 | |
| 7057 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7058 | } |
| 7059 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7060 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7061 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7062 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7066 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7067 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7068 | } |
| 7069 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7070 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 7071 | { |
| 7072 | struct rtl8169_private *tp = mii_bus->priv; |
| 7073 | |
| 7074 | if (phyaddr > 0) |
| 7075 | return -ENODEV; |
| 7076 | |
| 7077 | return rtl_readphy(tp, phyreg); |
| 7078 | } |
| 7079 | |
| 7080 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 7081 | int phyreg, u16 val) |
| 7082 | { |
| 7083 | struct rtl8169_private *tp = mii_bus->priv; |
| 7084 | |
| 7085 | if (phyaddr > 0) |
| 7086 | return -ENODEV; |
| 7087 | |
| 7088 | rtl_writephy(tp, phyreg, val); |
| 7089 | |
| 7090 | return 0; |
| 7091 | } |
| 7092 | |
| 7093 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 7094 | { |
| 7095 | struct pci_dev *pdev = tp->pci_dev; |
| 7096 | struct phy_device *phydev; |
| 7097 | struct mii_bus *new_bus; |
| 7098 | int ret; |
| 7099 | |
| 7100 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 7101 | if (!new_bus) |
| 7102 | return -ENOMEM; |
| 7103 | |
| 7104 | new_bus->name = "r8169"; |
| 7105 | new_bus->priv = tp; |
| 7106 | new_bus->parent = &pdev->dev; |
| 7107 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
| 7108 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x", |
| 7109 | PCI_DEVID(pdev->bus->number, pdev->devfn)); |
| 7110 | |
| 7111 | new_bus->read = r8169_mdio_read_reg; |
| 7112 | new_bus->write = r8169_mdio_write_reg; |
| 7113 | |
| 7114 | ret = mdiobus_register(new_bus); |
| 7115 | if (ret) |
| 7116 | return ret; |
| 7117 | |
| 7118 | phydev = mdiobus_get_phy(new_bus, 0); |
| 7119 | if (!phydev) { |
| 7120 | mdiobus_unregister(new_bus); |
| 7121 | return -ENODEV; |
| 7122 | } |
| 7123 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 7124 | /* PHY will be woken up in rtl_open() */ |
| 7125 | phy_suspend(phydev); |
| 7126 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7127 | tp->mii_bus = new_bus; |
| 7128 | |
| 7129 | return 0; |
| 7130 | } |
| 7131 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7132 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7133 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7134 | u32 data; |
| 7135 | |
| 7136 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7137 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7138 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7139 | |
| 7140 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7141 | return; |
| 7142 | |
| 7143 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7144 | return; |
| 7145 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7146 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7147 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7148 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7149 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7150 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7151 | data &= ~(1 << 14); |
| 7152 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7153 | |
| 7154 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7155 | return; |
| 7156 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7157 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7158 | data |= (1 << 15); |
| 7159 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7160 | |
| 7161 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7162 | return; |
| 7163 | } |
| 7164 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7165 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7166 | { |
| 7167 | rtl8168ep_stop_cmac(tp); |
| 7168 | rtl_hw_init_8168g(tp); |
| 7169 | } |
| 7170 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7171 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7172 | { |
| 7173 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7174 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7175 | rtl_hw_init_8168g(tp); |
| 7176 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7177 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7178 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7179 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7180 | default: |
| 7181 | break; |
| 7182 | } |
| 7183 | } |
| 7184 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7185 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 7186 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 7187 | { |
| 7188 | switch (tp->mac_version) { |
| 7189 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7190 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 7191 | return false; |
| 7192 | default: |
| 7193 | return true; |
| 7194 | } |
| 7195 | } |
| 7196 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7197 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 7198 | { |
| 7199 | /* Non-GBit versions don't support jumbo frames */ |
| 7200 | if (!tp->supports_gmii) |
| 7201 | return JUMBO_1K; |
| 7202 | |
| 7203 | switch (tp->mac_version) { |
| 7204 | /* RTL8169 */ |
| 7205 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7206 | return JUMBO_7K; |
| 7207 | /* RTL8168b */ |
| 7208 | case RTL_GIGA_MAC_VER_11: |
| 7209 | case RTL_GIGA_MAC_VER_12: |
| 7210 | case RTL_GIGA_MAC_VER_17: |
| 7211 | return JUMBO_4K; |
| 7212 | /* RTL8168c */ |
| 7213 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 7214 | return JUMBO_6K; |
| 7215 | default: |
| 7216 | return JUMBO_9K; |
| 7217 | } |
| 7218 | } |
| 7219 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7220 | static void rtl_disable_clk(void *data) |
| 7221 | { |
| 7222 | clk_disable_unprepare(data); |
| 7223 | } |
| 7224 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7225 | 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] | 7226 | { |
| 7227 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7228 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7229 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7230 | int chipset, region, i; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7231 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7232 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7233 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7234 | if (!dev) |
| 7235 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7236 | |
| 7237 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7238 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7239 | tp = netdev_priv(dev); |
| 7240 | tp->dev = dev; |
| 7241 | tp->pci_dev = pdev; |
| 7242 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 7243 | tp->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7244 | |
Hans de Goede | c2f6f3e | 2018-09-12 11:34:55 +0200 | [diff] [blame] | 7245 | /* Get the *optional* external "ether_clk" used on some boards */ |
| 7246 | tp->clk = devm_clk_get(&pdev->dev, "ether_clk"); |
| 7247 | if (IS_ERR(tp->clk)) { |
| 7248 | rc = PTR_ERR(tp->clk); |
| 7249 | if (rc == -ENOENT) { |
| 7250 | /* clk-core allows NULL (for suspend / resume) */ |
| 7251 | tp->clk = NULL; |
| 7252 | } else if (rc == -EPROBE_DEFER) { |
| 7253 | return rc; |
| 7254 | } else { |
| 7255 | dev_err(&pdev->dev, "failed to get clk: %d\n", rc); |
| 7256 | return rc; |
| 7257 | } |
| 7258 | } else { |
| 7259 | rc = clk_prepare_enable(tp->clk); |
| 7260 | if (rc) { |
| 7261 | dev_err(&pdev->dev, "failed to enable clk: %d\n", rc); |
| 7262 | return rc; |
| 7263 | } |
| 7264 | |
| 7265 | rc = devm_add_action_or_reset(&pdev->dev, rtl_disable_clk, |
| 7266 | tp->clk); |
| 7267 | if (rc) |
| 7268 | return rc; |
| 7269 | } |
| 7270 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7271 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7272 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7273 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7274 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7275 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7276 | } |
| 7277 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7278 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7279 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7280 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7281 | /* use first MMIO region */ |
| 7282 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7283 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7284 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7285 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7286 | } |
| 7287 | |
| 7288 | /* check for weird/broken PCI region reporting */ |
| 7289 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7290 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7291 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7292 | } |
| 7293 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7294 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7295 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7296 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7297 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7298 | } |
| 7299 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7300 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7301 | |
| 7302 | if (!pci_is_pcie(pdev)) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7303 | dev_info(&pdev->dev, "not PCI Express\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7304 | |
| 7305 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7306 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7307 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 7308 | if (rtl_tbi_enabled(tp)) { |
| 7309 | dev_err(&pdev->dev, "TBI fiber mode not supported\n"); |
| 7310 | return -ENODEV; |
| 7311 | } |
| 7312 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7313 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7314 | |
Heiner Kallweit | a045679 | 2018-09-25 07:59:36 +0200 | [diff] [blame] | 7315 | if (sizeof(dma_addr_t) > 4 && (use_dac == 1 || (use_dac == -1 && |
| 7316 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
| 7317 | !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7318 | |
| 7319 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7320 | if (!pci_is_pcie(pdev)) |
| 7321 | tp->cp_cmd |= PCIDAC; |
| 7322 | dev->features |= NETIF_F_HIGHDMA; |
| 7323 | } else { |
| 7324 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7325 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7326 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7327 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7328 | } |
| 7329 | } |
| 7330 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7331 | rtl_init_rxcfg(tp); |
| 7332 | |
Heiner Kallweit | de20e12 | 2018-09-25 07:58:00 +0200 | [diff] [blame] | 7333 | rtl8169_irq_mask_and_ack(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7334 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7335 | rtl_hw_initialize(tp); |
| 7336 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7337 | rtl_hw_reset(tp); |
| 7338 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7339 | pci_set_master(pdev); |
| 7340 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7341 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7342 | rtl_init_jumbo_ops(tp); |
| 7343 | |
| 7344 | rtl8169_print_mac_version(tp); |
| 7345 | |
| 7346 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7347 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7348 | rc = rtl_alloc_irq(tp); |
| 7349 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7350 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7351 | return rc; |
| 7352 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7353 | |
Heiner Kallweit | 18041b5 | 2018-07-24 22:21:04 +0200 | [diff] [blame] | 7354 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7355 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7356 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7357 | u64_stats_init(&tp->rx_stats.syncp); |
| 7358 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7359 | |
| 7360 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7361 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7362 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7363 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7364 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7365 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7366 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7367 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7368 | if (is_valid_ether_addr(mac_addr)) |
| 7369 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7370 | break; |
| 7371 | default: |
| 7372 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7373 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7374 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7375 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7376 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7377 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7378 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7379 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7380 | |
| 7381 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7382 | * properly for all devices */ |
| 7383 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7384 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7385 | |
| 7386 | 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] | 7387 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7388 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7389 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7390 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 7391 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7392 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7393 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7394 | |
| 7395 | /* |
| 7396 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7397 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7398 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7399 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7400 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7401 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7402 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7403 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7404 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7405 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7406 | } else { |
| 7407 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7408 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7409 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7410 | dev->hw_features |= NETIF_F_RXALL; |
| 7411 | dev->hw_features |= NETIF_F_RXFCS; |
| 7412 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7413 | /* MTU range: 60 - hw-specific max */ |
| 7414 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7415 | jumbo_max = rtl_jumbo_max(tp); |
| 7416 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7417 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7418 | tp->hw_start = cfg->hw_start; |
| 7419 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7420 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7421 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7422 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7423 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7424 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7425 | &tp->counters_phys_addr, |
| 7426 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7427 | if (!tp->counters) |
| 7428 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7429 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7430 | pci_set_drvdata(pdev, dev); |
| 7431 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7432 | rc = r8169_mdio_register(tp); |
| 7433 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7434 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7435 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 7436 | /* chip gets powered up in rtl_open() */ |
| 7437 | rtl_pll_power_down(tp); |
| 7438 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7439 | rc = register_netdev(dev); |
| 7440 | if (rc) |
| 7441 | goto err_mdio_unregister; |
| 7442 | |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7443 | netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n", |
| 7444 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 90b989c | 2018-04-17 23:32:15 +0200 | [diff] [blame] | 7445 | (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7446 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7447 | |
| 7448 | if (jumbo_max > JUMBO_1K) |
| 7449 | netif_info(tp, probe, dev, |
| 7450 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 7451 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 7452 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7453 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7454 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7455 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7456 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7457 | if (pci_dev_run_wake(pdev)) |
| 7458 | pm_runtime_put_sync(&pdev->dev); |
| 7459 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7460 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7461 | |
| 7462 | err_mdio_unregister: |
| 7463 | mdiobus_unregister(tp->mii_bus); |
| 7464 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7465 | } |
| 7466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7467 | static struct pci_driver rtl8169_pci_driver = { |
| 7468 | .name = MODULENAME, |
| 7469 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7470 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7471 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7472 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7473 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7474 | }; |
| 7475 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7476 | module_pci_driver(rtl8169_pci_driver); |