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> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/ethtool.h> |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 18 | #include <linux/phy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/if_vlan.h> |
| 20 | #include <linux/crc32.h> |
| 21 | #include <linux/in.h> |
Heiner Kallweit | 098b01a | 2018-08-10 22:37:31 +0200 | [diff] [blame] | 22 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/ip.h> |
| 24 | #include <linux/tcp.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 28 | #include <linux/firmware.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 29 | #include <linux/prefetch.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 30 | #include <linux/ipv6.h> |
| 31 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define MODULENAME "r8169" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 35 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 36 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 37 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 38 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 39 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 40 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 41 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 42 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 47 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 48 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 49 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 50 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 51 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 52 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 53 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 54 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 55 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 56 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 57 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 58 | #define TX_SLOTS_AVAIL(tp) \ |
| 59 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 60 | |
| 61 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 62 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 63 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 66 | 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] | 67 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 69 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 71 | |
| 72 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 73 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 75 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 77 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 78 | |
| 79 | #define RTL8169_TX_TIMEOUT (6*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 82 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 83 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 84 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 85 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 86 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 87 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 90 | RTL_GIGA_MAC_VER_01 = 0, |
| 91 | RTL_GIGA_MAC_VER_02, |
| 92 | RTL_GIGA_MAC_VER_03, |
| 93 | RTL_GIGA_MAC_VER_04, |
| 94 | RTL_GIGA_MAC_VER_05, |
| 95 | RTL_GIGA_MAC_VER_06, |
| 96 | RTL_GIGA_MAC_VER_07, |
| 97 | RTL_GIGA_MAC_VER_08, |
| 98 | RTL_GIGA_MAC_VER_09, |
| 99 | RTL_GIGA_MAC_VER_10, |
| 100 | RTL_GIGA_MAC_VER_11, |
| 101 | RTL_GIGA_MAC_VER_12, |
| 102 | RTL_GIGA_MAC_VER_13, |
| 103 | RTL_GIGA_MAC_VER_14, |
| 104 | RTL_GIGA_MAC_VER_15, |
| 105 | RTL_GIGA_MAC_VER_16, |
| 106 | RTL_GIGA_MAC_VER_17, |
| 107 | RTL_GIGA_MAC_VER_18, |
| 108 | RTL_GIGA_MAC_VER_19, |
| 109 | RTL_GIGA_MAC_VER_20, |
| 110 | RTL_GIGA_MAC_VER_21, |
| 111 | RTL_GIGA_MAC_VER_22, |
| 112 | RTL_GIGA_MAC_VER_23, |
| 113 | RTL_GIGA_MAC_VER_24, |
| 114 | RTL_GIGA_MAC_VER_25, |
| 115 | RTL_GIGA_MAC_VER_26, |
| 116 | RTL_GIGA_MAC_VER_27, |
| 117 | RTL_GIGA_MAC_VER_28, |
| 118 | RTL_GIGA_MAC_VER_29, |
| 119 | RTL_GIGA_MAC_VER_30, |
| 120 | RTL_GIGA_MAC_VER_31, |
| 121 | RTL_GIGA_MAC_VER_32, |
| 122 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 123 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 124 | RTL_GIGA_MAC_VER_35, |
| 125 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 126 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 127 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 129 | RTL_GIGA_MAC_VER_40, |
| 130 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 131 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 132 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 133 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 134 | RTL_GIGA_MAC_VER_45, |
| 135 | RTL_GIGA_MAC_VER_46, |
| 136 | RTL_GIGA_MAC_VER_47, |
| 137 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 138 | RTL_GIGA_MAC_VER_49, |
| 139 | RTL_GIGA_MAC_VER_50, |
| 140 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 141 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 144 | #define JUMBO_1K ETH_DATA_LEN |
| 145 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 146 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 147 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 148 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 149 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 150 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | const char *name; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 152 | const char *fw_name; |
| 153 | } rtl_chip_infos[] = { |
| 154 | /* PCI devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 155 | [RTL_GIGA_MAC_VER_01] = {"RTL8169" }, |
| 156 | [RTL_GIGA_MAC_VER_02] = {"RTL8169s" }, |
| 157 | [RTL_GIGA_MAC_VER_03] = {"RTL8110s" }, |
| 158 | [RTL_GIGA_MAC_VER_04] = {"RTL8169sb/8110sb" }, |
| 159 | [RTL_GIGA_MAC_VER_05] = {"RTL8169sc/8110sc" }, |
| 160 | [RTL_GIGA_MAC_VER_06] = {"RTL8169sc/8110sc" }, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 161 | /* PCI-E devices. */ |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 162 | [RTL_GIGA_MAC_VER_07] = {"RTL8102e" }, |
| 163 | [RTL_GIGA_MAC_VER_08] = {"RTL8102e" }, |
| 164 | [RTL_GIGA_MAC_VER_09] = {"RTL8102e" }, |
| 165 | [RTL_GIGA_MAC_VER_10] = {"RTL8101e" }, |
| 166 | [RTL_GIGA_MAC_VER_11] = {"RTL8168b/8111b" }, |
| 167 | [RTL_GIGA_MAC_VER_12] = {"RTL8168b/8111b" }, |
| 168 | [RTL_GIGA_MAC_VER_13] = {"RTL8101e" }, |
| 169 | [RTL_GIGA_MAC_VER_14] = {"RTL8100e" }, |
| 170 | [RTL_GIGA_MAC_VER_15] = {"RTL8100e" }, |
| 171 | [RTL_GIGA_MAC_VER_16] = {"RTL8101e" }, |
| 172 | [RTL_GIGA_MAC_VER_17] = {"RTL8168b/8111b" }, |
| 173 | [RTL_GIGA_MAC_VER_18] = {"RTL8168cp/8111cp" }, |
| 174 | [RTL_GIGA_MAC_VER_19] = {"RTL8168c/8111c" }, |
| 175 | [RTL_GIGA_MAC_VER_20] = {"RTL8168c/8111c" }, |
| 176 | [RTL_GIGA_MAC_VER_21] = {"RTL8168c/8111c" }, |
| 177 | [RTL_GIGA_MAC_VER_22] = {"RTL8168c/8111c" }, |
| 178 | [RTL_GIGA_MAC_VER_23] = {"RTL8168cp/8111cp" }, |
| 179 | [RTL_GIGA_MAC_VER_24] = {"RTL8168cp/8111cp" }, |
| 180 | [RTL_GIGA_MAC_VER_25] = {"RTL8168d/8111d", FIRMWARE_8168D_1}, |
| 181 | [RTL_GIGA_MAC_VER_26] = {"RTL8168d/8111d", FIRMWARE_8168D_2}, |
| 182 | [RTL_GIGA_MAC_VER_27] = {"RTL8168dp/8111dp" }, |
| 183 | [RTL_GIGA_MAC_VER_28] = {"RTL8168dp/8111dp" }, |
| 184 | [RTL_GIGA_MAC_VER_29] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 185 | [RTL_GIGA_MAC_VER_30] = {"RTL8105e", FIRMWARE_8105E_1}, |
| 186 | [RTL_GIGA_MAC_VER_31] = {"RTL8168dp/8111dp" }, |
| 187 | [RTL_GIGA_MAC_VER_32] = {"RTL8168e/8111e", FIRMWARE_8168E_1}, |
| 188 | [RTL_GIGA_MAC_VER_33] = {"RTL8168e/8111e", FIRMWARE_8168E_2}, |
| 189 | [RTL_GIGA_MAC_VER_34] = {"RTL8168evl/8111evl", FIRMWARE_8168E_3}, |
| 190 | [RTL_GIGA_MAC_VER_35] = {"RTL8168f/8111f", FIRMWARE_8168F_1}, |
| 191 | [RTL_GIGA_MAC_VER_36] = {"RTL8168f/8111f", FIRMWARE_8168F_2}, |
| 192 | [RTL_GIGA_MAC_VER_37] = {"RTL8402", FIRMWARE_8402_1 }, |
| 193 | [RTL_GIGA_MAC_VER_38] = {"RTL8411", FIRMWARE_8411_1 }, |
| 194 | [RTL_GIGA_MAC_VER_39] = {"RTL8106e", FIRMWARE_8106E_1}, |
| 195 | [RTL_GIGA_MAC_VER_40] = {"RTL8168g/8111g", FIRMWARE_8168G_2}, |
| 196 | [RTL_GIGA_MAC_VER_41] = {"RTL8168g/8111g" }, |
| 197 | [RTL_GIGA_MAC_VER_42] = {"RTL8168g/8111g", FIRMWARE_8168G_3}, |
| 198 | [RTL_GIGA_MAC_VER_43] = {"RTL8106e", FIRMWARE_8106E_2}, |
| 199 | [RTL_GIGA_MAC_VER_44] = {"RTL8411", FIRMWARE_8411_2 }, |
| 200 | [RTL_GIGA_MAC_VER_45] = {"RTL8168h/8111h", FIRMWARE_8168H_1}, |
| 201 | [RTL_GIGA_MAC_VER_46] = {"RTL8168h/8111h", FIRMWARE_8168H_2}, |
| 202 | [RTL_GIGA_MAC_VER_47] = {"RTL8107e", FIRMWARE_8107E_1}, |
| 203 | [RTL_GIGA_MAC_VER_48] = {"RTL8107e", FIRMWARE_8107E_2}, |
| 204 | [RTL_GIGA_MAC_VER_49] = {"RTL8168ep/8111ep" }, |
| 205 | [RTL_GIGA_MAC_VER_50] = {"RTL8168ep/8111ep" }, |
| 206 | [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 209 | enum cfg_version { |
| 210 | RTL_CFG_0 = 0x00, |
| 211 | RTL_CFG_1, |
| 212 | RTL_CFG_2 |
| 213 | }; |
| 214 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 215 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 216 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 217 | { 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] | 218 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 219 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 220 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Anthony Wong | 9fd0e09 | 2018-08-31 20:06:42 +0800 | [diff] [blame] | 221 | { PCI_DEVICE(PCI_VENDOR_ID_NCUBE, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 222 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 223 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 224 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 225 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 226 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 227 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 228 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 229 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 230 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 231 | { 0x0001, 0x8168, |
| 232 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | {0,}, |
| 234 | }; |
| 235 | |
| 236 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 237 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 238 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 239 | static struct { |
| 240 | u32 msg_enable; |
| 241 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 243 | enum rtl_registers { |
| 244 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 245 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 246 | MAR0 = 8, /* Multicast filter. */ |
| 247 | CounterAddrLow = 0x10, |
| 248 | CounterAddrHigh = 0x14, |
| 249 | TxDescStartAddrLow = 0x20, |
| 250 | TxDescStartAddrHigh = 0x24, |
| 251 | TxHDescStartAddrLow = 0x28, |
| 252 | TxHDescStartAddrHigh = 0x2c, |
| 253 | FLASH = 0x30, |
| 254 | ERSR = 0x36, |
| 255 | ChipCmd = 0x37, |
| 256 | TxPoll = 0x38, |
| 257 | IntrMask = 0x3c, |
| 258 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 259 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 260 | TxConfig = 0x40, |
| 261 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 262 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 263 | |
| 264 | RxConfig = 0x44, |
| 265 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 266 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 267 | #define RXCFG_FIFO_SHIFT 13 |
| 268 | /* No threshold before first PCI xfer */ |
| 269 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 270 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 271 | #define RXCFG_DMA_SHIFT 8 |
| 272 | /* Unlimited maximum PCI burst. */ |
| 273 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 274 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 275 | RxMissed = 0x4c, |
| 276 | Cfg9346 = 0x50, |
| 277 | Config0 = 0x51, |
| 278 | Config1 = 0x52, |
| 279 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 280 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 281 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 282 | Config3 = 0x54, |
| 283 | Config4 = 0x55, |
| 284 | Config5 = 0x56, |
| 285 | MultiIntr = 0x5c, |
| 286 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 287 | PHYstatus = 0x6c, |
| 288 | RxMaxSize = 0xda, |
| 289 | CPlusCmd = 0xe0, |
| 290 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 291 | |
| 292 | #define RTL_COALESCE_MASK 0x0f |
| 293 | #define RTL_COALESCE_SHIFT 4 |
| 294 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 295 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 296 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 297 | RxDescAddrLow = 0xe4, |
| 298 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 299 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 300 | |
| 301 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 302 | |
| 303 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 304 | |
| 305 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 306 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 307 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 308 | FuncEvent = 0xf0, |
| 309 | FuncEventMask = 0xf4, |
| 310 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 311 | IBCR0 = 0xf8, |
| 312 | IBCR2 = 0xf9, |
| 313 | IBIMR0 = 0xfa, |
| 314 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 315 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 318 | enum rtl8168_8101_registers { |
| 319 | CSIDR = 0x64, |
| 320 | CSIAR = 0x68, |
| 321 | #define CSIAR_FLAG 0x80000000 |
| 322 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 323 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 324 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 325 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 326 | EPHYAR = 0x80, |
| 327 | #define EPHYAR_FLAG 0x80000000 |
| 328 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 329 | #define EPHYAR_REG_MASK 0x1f |
| 330 | #define EPHYAR_REG_SHIFT 16 |
| 331 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 332 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 333 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 334 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 335 | DBG_REG = 0xd1, |
| 336 | #define FIX_NAK_1 (1 << 4) |
| 337 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 338 | TWSI = 0xd2, |
| 339 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 340 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 341 | #define TX_EMPTY (1 << 5) |
| 342 | #define RX_EMPTY (1 << 4) |
| 343 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 344 | #define EN_NDP (1 << 3) |
| 345 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 346 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 347 | EFUSEAR = 0xdc, |
| 348 | #define EFUSEAR_FLAG 0x80000000 |
| 349 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 350 | #define EFUSEAR_READ_CMD 0x00000000 |
| 351 | #define EFUSEAR_REG_MASK 0x03ff |
| 352 | #define EFUSEAR_REG_SHIFT 8 |
| 353 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 354 | MISC_1 = 0xf2, |
| 355 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 356 | }; |
| 357 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 358 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 359 | LED_FREQ = 0x1a, |
| 360 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 361 | ERIDR = 0x70, |
| 362 | ERIAR = 0x74, |
| 363 | #define ERIAR_FLAG 0x80000000 |
| 364 | #define ERIAR_WRITE_CMD 0x80000000 |
| 365 | #define ERIAR_READ_CMD 0x00000000 |
| 366 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 367 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 368 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 369 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 370 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 371 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 372 | #define ERIAR_MASK_SHIFT 12 |
| 373 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 374 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 375 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 376 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 377 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 378 | EPHY_RXER_NUM = 0x7c, |
| 379 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 380 | #define OCPDR_WRITE_CMD 0x80000000 |
| 381 | #define OCPDR_READ_CMD 0x00000000 |
| 382 | #define OCPDR_REG_MASK 0x7f |
| 383 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 384 | #define OCPDR_DATA_MASK 0xffff |
| 385 | OCPAR = 0xb4, |
| 386 | #define OCPAR_FLAG 0x80000000 |
| 387 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 388 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 389 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 390 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 391 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 392 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 393 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 394 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 395 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 396 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 397 | }; |
| 398 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 399 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 401 | SYSErr = 0x8000, |
| 402 | PCSTimeout = 0x4000, |
| 403 | SWInt = 0x0100, |
| 404 | TxDescUnavail = 0x0080, |
| 405 | RxFIFOOver = 0x0040, |
| 406 | LinkChg = 0x0020, |
| 407 | RxOverflow = 0x0010, |
| 408 | TxErr = 0x0008, |
| 409 | TxOK = 0x0004, |
| 410 | RxErr = 0x0002, |
| 411 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 414 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 415 | RxFOVF = (1 << 23), |
| 416 | RxRWT = (1 << 22), |
| 417 | RxRES = (1 << 21), |
| 418 | RxRUNT = (1 << 20), |
| 419 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 422 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 423 | CmdReset = 0x10, |
| 424 | CmdRxEnb = 0x08, |
| 425 | CmdTxEnb = 0x04, |
| 426 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 428 | /* TXPoll register p.5 */ |
| 429 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 430 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 431 | FSWInt = 0x01, /* Forced software interrupt */ |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 434 | Cfg9346_Lock = 0x00, |
| 435 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 438 | AcceptErr = 0x20, |
| 439 | AcceptRunt = 0x10, |
| 440 | AcceptBroadcast = 0x08, |
| 441 | AcceptMulticast = 0x04, |
| 442 | AcceptMyPhys = 0x02, |
| 443 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 444 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | /* TxConfigBits */ |
| 447 | TxInterFrameGapShift = 24, |
| 448 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 449 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 450 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 451 | LEDS1 = (1 << 7), |
| 452 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 453 | Speed_down = (1 << 4), |
| 454 | MEMMAP = (1 << 3), |
| 455 | IOMAP = (1 << 2), |
| 456 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 457 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 458 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 459 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 460 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 461 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 462 | PCI_Clock_66MHz = 0x01, |
| 463 | PCI_Clock_33MHz = 0x00, |
| 464 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 465 | /* Config3 register p.25 */ |
| 466 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 467 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 468 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 469 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 470 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 471 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 472 | /* Config4 register */ |
| 473 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 474 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 475 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 476 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 477 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 478 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 479 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 480 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 481 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 482 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 485 | EnableBist = (1 << 15), // 8168 8101 |
| 486 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 487 | Normal_mode = (1 << 13), // unused |
| 488 | Force_half_dup = (1 << 12), // 8168 8101 |
| 489 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 490 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 491 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 492 | ASF = (1 << 8), // 8168 8101 |
| 493 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 494 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | RxVlan = (1 << 6), |
| 496 | RxChkSum = (1 << 5), |
| 497 | PCIDAC = (1 << 4), |
| 498 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 499 | #define INTT_MASK GENMASK(1, 0) |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 500 | INTT_0 = 0x0000, // 8168 |
| 501 | INTT_1 = 0x0001, // 8168 |
| 502 | INTT_2 = 0x0002, // 8168 |
| 503 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 506 | TBI_Enable = 0x80, |
| 507 | TxFlowCtrl = 0x40, |
| 508 | RxFlowCtrl = 0x20, |
| 509 | _1000bpsF = 0x10, |
| 510 | _100bps = 0x08, |
| 511 | _10bps = 0x04, |
| 512 | LinkStatus = 0x02, |
| 513 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 516 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 517 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 518 | /* ResetCounterCommand */ |
| 519 | CounterReset = 0x1, |
| 520 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 521 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 522 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 523 | |
| 524 | /* magic enable v2 */ |
| 525 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | }; |
| 527 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 528 | enum rtl_desc_bit { |
| 529 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 531 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 532 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 533 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 534 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 536 | /* Generic case. */ |
| 537 | enum rtl_tx_desc_bit { |
| 538 | /* First doubleword. */ |
| 539 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 540 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 542 | /* Second doubleword. */ |
| 543 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 544 | }; |
| 545 | |
| 546 | /* 8169, 8168b and 810x except 8102e. */ |
| 547 | enum rtl_tx_desc_bit_0 { |
| 548 | /* First doubleword. */ |
| 549 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 550 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 551 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 552 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 553 | }; |
| 554 | |
| 555 | /* 8102e, 8168c and beyond. */ |
| 556 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 557 | /* First doubleword. */ |
| 558 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 559 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 560 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 561 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 562 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 563 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 564 | #define TCPHO_SHIFT 18 |
| 565 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 566 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 567 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 568 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 569 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 570 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 571 | }; |
| 572 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 573 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | /* Rx private */ |
| 575 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 576 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | #define RxProtoUDP (PID1) |
| 579 | #define RxProtoTCP (PID0) |
| 580 | #define RxProtoIP (PID1 | PID0) |
| 581 | #define RxProtoMask RxProtoIP |
| 582 | |
| 583 | IPFail = (1 << 16), /* IP checksum failed */ |
| 584 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 585 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 586 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 587 | }; |
| 588 | |
| 589 | #define RsvdMask 0x3fffc000 |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 590 | #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 593 | __le32 opts1; |
| 594 | __le32 opts2; |
| 595 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 599 | __le32 opts1; |
| 600 | __le32 opts2; |
| 601 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | struct ring_info { |
| 605 | struct sk_buff *skb; |
| 606 | u32 len; |
| 607 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 608 | }; |
| 609 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 610 | struct rtl8169_counters { |
| 611 | __le64 tx_packets; |
| 612 | __le64 rx_packets; |
| 613 | __le64 tx_errors; |
| 614 | __le32 rx_errors; |
| 615 | __le16 rx_missed; |
| 616 | __le16 align_errors; |
| 617 | __le32 tx_one_collision; |
| 618 | __le32 tx_multi_collision; |
| 619 | __le64 rx_unicast; |
| 620 | __le64 rx_broadcast; |
| 621 | __le32 rx_multicast; |
| 622 | __le16 tx_aborted; |
| 623 | __le16 tx_underun; |
| 624 | }; |
| 625 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 626 | struct rtl8169_tc_offsets { |
| 627 | bool inited; |
| 628 | __le64 tx_errors; |
| 629 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 630 | __le16 tx_aborted; |
| 631 | }; |
| 632 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 633 | enum rtl_flag { |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 634 | RTL_FLAG_TASK_ENABLED = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 635 | RTL_FLAG_TASK_SLOW_PENDING, |
| 636 | RTL_FLAG_TASK_RESET_PENDING, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 637 | RTL_FLAG_MAX |
| 638 | }; |
| 639 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 640 | struct rtl8169_stats { |
| 641 | u64 packets; |
| 642 | u64 bytes; |
| 643 | struct u64_stats_sync syncp; |
| 644 | }; |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | struct rtl8169_private { |
| 647 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 648 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 649 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 650 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 651 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 652 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 654 | 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] | 655 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 656 | struct rtl8169_stats rx_stats; |
| 657 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 659 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 660 | dma_addr_t TxPhyAddr; |
| 661 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 662 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 665 | |
| 666 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 667 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 668 | |
| 669 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 670 | void (*write)(struct rtl8169_private *, int, int); |
| 671 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 672 | } mdio_ops; |
| 673 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 674 | struct jumbo_ops { |
| 675 | void (*enable)(struct rtl8169_private *); |
| 676 | void (*disable)(struct rtl8169_private *); |
| 677 | } jumbo_ops; |
| 678 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 679 | void (*hw_start)(struct rtl8169_private *tp); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 680 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 681 | |
| 682 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 683 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 684 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 685 | struct work_struct work; |
| 686 | } wk; |
| 687 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 688 | unsigned supports_gmii:1; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 689 | struct mii_bus *mii_bus; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 690 | dma_addr_t counters_phys_addr; |
| 691 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 692 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 693 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 694 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 695 | struct rtl_fw { |
| 696 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 697 | |
| 698 | #define RTL_VER_SIZE 32 |
| 699 | |
| 700 | char version[RTL_VER_SIZE]; |
| 701 | |
| 702 | struct rtl_fw_phy_action { |
| 703 | __le32 *code; |
| 704 | size_t size; |
| 705 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 706 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 707 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 708 | |
| 709 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | }; |
| 711 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 712 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 715 | 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] | 716 | module_param_named(debug, debug.msg_enable, int, 0); |
| 717 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | MODULE_LICENSE("GPL"); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 719 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 720 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 721 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 722 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 723 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 724 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 725 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 726 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 727 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 728 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 729 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 730 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 731 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 732 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 733 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 734 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 735 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 736 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 737 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 739 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 740 | { |
| 741 | return &tp->pci_dev->dev; |
| 742 | } |
| 743 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 744 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 745 | { |
| 746 | mutex_lock(&tp->wk.mutex); |
| 747 | } |
| 748 | |
| 749 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 750 | { |
| 751 | mutex_unlock(&tp->wk.mutex); |
| 752 | } |
| 753 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 754 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 755 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 756 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 757 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 758 | } |
| 759 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 760 | struct rtl_cond { |
| 761 | bool (*check)(struct rtl8169_private *); |
| 762 | const char *msg; |
| 763 | }; |
| 764 | |
| 765 | static void rtl_udelay(unsigned int d) |
| 766 | { |
| 767 | udelay(d); |
| 768 | } |
| 769 | |
| 770 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 771 | void (*delay)(unsigned int), unsigned int d, int n, |
| 772 | bool high) |
| 773 | { |
| 774 | int i; |
| 775 | |
| 776 | for (i = 0; i < n; i++) { |
| 777 | delay(d); |
| 778 | if (c->check(tp) == high) |
| 779 | return true; |
| 780 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 781 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 782 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 783 | return false; |
| 784 | } |
| 785 | |
| 786 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 787 | const struct rtl_cond *c, |
| 788 | unsigned int d, int n) |
| 789 | { |
| 790 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 791 | } |
| 792 | |
| 793 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 794 | const struct rtl_cond *c, |
| 795 | unsigned int d, int n) |
| 796 | { |
| 797 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 798 | } |
| 799 | |
| 800 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 801 | const struct rtl_cond *c, |
| 802 | unsigned int d, int n) |
| 803 | { |
| 804 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 805 | } |
| 806 | |
| 807 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 808 | const struct rtl_cond *c, |
| 809 | unsigned int d, int n) |
| 810 | { |
| 811 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 812 | } |
| 813 | |
| 814 | #define DECLARE_RTL_COND(name) \ |
| 815 | static bool name ## _check(struct rtl8169_private *); \ |
| 816 | \ |
| 817 | static const struct rtl_cond name = { \ |
| 818 | .check = name ## _check, \ |
| 819 | .msg = #name \ |
| 820 | }; \ |
| 821 | \ |
| 822 | static bool name ## _check(struct rtl8169_private *tp) |
| 823 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 824 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 825 | { |
| 826 | if (reg & 0xffff0001) { |
| 827 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 828 | return true; |
| 829 | } |
| 830 | return false; |
| 831 | } |
| 832 | |
| 833 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 834 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 835 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 839 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 840 | if (rtl_ocp_reg_failure(tp, reg)) |
| 841 | return; |
| 842 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 843 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 844 | |
| 845 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 846 | } |
| 847 | |
| 848 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 849 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 850 | if (rtl_ocp_reg_failure(tp, reg)) |
| 851 | return 0; |
| 852 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 853 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 854 | |
| 855 | 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] | 856 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 857 | } |
| 858 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 859 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 860 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 861 | if (rtl_ocp_reg_failure(tp, reg)) |
| 862 | return; |
| 863 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 864 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 868 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 869 | if (rtl_ocp_reg_failure(tp, reg)) |
| 870 | return 0; |
| 871 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 872 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 873 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 874 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | #define OCP_STD_PHY_BASE 0xa400 |
| 878 | |
| 879 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 880 | { |
| 881 | if (reg == 0x1f) { |
| 882 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 887 | reg -= 0x10; |
| 888 | |
| 889 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 890 | } |
| 891 | |
| 892 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 893 | { |
| 894 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 895 | reg -= 0x10; |
| 896 | |
| 897 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 898 | } |
| 899 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 900 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 901 | { |
| 902 | if (reg == 0x1f) { |
| 903 | tp->ocp_base = value << 4; |
| 904 | return; |
| 905 | } |
| 906 | |
| 907 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 908 | } |
| 909 | |
| 910 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 911 | { |
| 912 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 913 | } |
| 914 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 915 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 916 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 917 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 918 | } |
| 919 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 920 | 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] | 921 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 922 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 924 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 925 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 926 | * According to hardware specs a 20us delay is required after write |
| 927 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 928 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 929 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 932 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 934 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 936 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 938 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 939 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 940 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 941 | /* |
| 942 | * According to hardware specs a 20us delay is required after read |
| 943 | * complete indication, but before sending next command. |
| 944 | */ |
| 945 | udelay(20); |
| 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | return value; |
| 948 | } |
| 949 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 950 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 951 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 952 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 953 | } |
| 954 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 955 | 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] | 956 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 957 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 958 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 959 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 960 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 961 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 964 | 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] | 965 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 966 | r8168dp_1_mdio_access(tp, reg, |
| 967 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 970 | 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] | 971 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 972 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 973 | |
| 974 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 975 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 976 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 977 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 978 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 979 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 980 | } |
| 981 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 982 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 983 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 984 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 985 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 986 | 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] | 987 | } |
| 988 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 989 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 990 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 991 | 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] | 992 | } |
| 993 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 994 | 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] | 995 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 996 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 997 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 998 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 999 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1000 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1003 | 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] | 1004 | { |
| 1005 | int value; |
| 1006 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1007 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1008 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1009 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1010 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1011 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1012 | |
| 1013 | return value; |
| 1014 | } |
| 1015 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1016 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1017 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1018 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1021 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1022 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1023 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1027 | { |
| 1028 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1029 | } |
| 1030 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1031 | 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] | 1032 | { |
| 1033 | int val; |
| 1034 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1035 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1036 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1039 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1040 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1041 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1042 | } |
| 1043 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1044 | 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] | 1045 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1046 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1047 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1048 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1049 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1050 | |
| 1051 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1052 | } |
| 1053 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1054 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1055 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1056 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1057 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1058 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1059 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1062 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1063 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1064 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1067 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1068 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1069 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1070 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1071 | RTL_W32(tp, ERIDR, val); |
| 1072 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1073 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1074 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1077 | 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] | 1078 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1079 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1080 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1081 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1082 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1085 | 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] | 1086 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1087 | { |
| 1088 | u32 val; |
| 1089 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1090 | val = rtl_eri_read(tp, addr, type); |
| 1091 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1094 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1095 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1096 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1097 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1098 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1102 | { |
| 1103 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1104 | } |
| 1105 | |
| 1106 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1107 | { |
| 1108 | switch (tp->mac_version) { |
| 1109 | case RTL_GIGA_MAC_VER_27: |
| 1110 | case RTL_GIGA_MAC_VER_28: |
| 1111 | case RTL_GIGA_MAC_VER_31: |
| 1112 | return r8168dp_ocp_read(tp, mask, reg); |
| 1113 | case RTL_GIGA_MAC_VER_49: |
| 1114 | case RTL_GIGA_MAC_VER_50: |
| 1115 | case RTL_GIGA_MAC_VER_51: |
| 1116 | return r8168ep_ocp_read(tp, mask, reg); |
| 1117 | default: |
| 1118 | BUG(); |
| 1119 | return ~0; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1124 | u32 data) |
| 1125 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1126 | RTL_W32(tp, OCPDR, data); |
| 1127 | 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] | 1128 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1129 | } |
| 1130 | |
| 1131 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1132 | u32 data) |
| 1133 | { |
| 1134 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1135 | data, ERIAR_OOB); |
| 1136 | } |
| 1137 | |
| 1138 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1139 | { |
| 1140 | switch (tp->mac_version) { |
| 1141 | case RTL_GIGA_MAC_VER_27: |
| 1142 | case RTL_GIGA_MAC_VER_28: |
| 1143 | case RTL_GIGA_MAC_VER_31: |
| 1144 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1145 | break; |
| 1146 | case RTL_GIGA_MAC_VER_49: |
| 1147 | case RTL_GIGA_MAC_VER_50: |
| 1148 | case RTL_GIGA_MAC_VER_51: |
| 1149 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1150 | break; |
| 1151 | default: |
| 1152 | BUG(); |
| 1153 | break; |
| 1154 | } |
| 1155 | } |
| 1156 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1157 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1158 | { |
| 1159 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1160 | |
| 1161 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1162 | } |
| 1163 | |
| 1164 | #define OOB_CMD_RESET 0x00 |
| 1165 | #define OOB_CMD_DRIVER_START 0x05 |
| 1166 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1167 | |
| 1168 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1169 | { |
| 1170 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1171 | } |
| 1172 | |
| 1173 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1174 | { |
| 1175 | u16 reg; |
| 1176 | |
| 1177 | reg = rtl8168_get_ocp_reg(tp); |
| 1178 | |
| 1179 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1180 | } |
| 1181 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1182 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1183 | { |
| 1184 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1185 | } |
| 1186 | |
| 1187 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1188 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1189 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1190 | } |
| 1191 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1192 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1193 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1194 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1195 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1196 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1197 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1200 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1201 | { |
| 1202 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1203 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1204 | } |
| 1205 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1206 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1207 | { |
| 1208 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1209 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1210 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1211 | } |
| 1212 | |
| 1213 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1214 | { |
| 1215 | switch (tp->mac_version) { |
| 1216 | case RTL_GIGA_MAC_VER_27: |
| 1217 | case RTL_GIGA_MAC_VER_28: |
| 1218 | case RTL_GIGA_MAC_VER_31: |
| 1219 | rtl8168dp_driver_start(tp); |
| 1220 | break; |
| 1221 | case RTL_GIGA_MAC_VER_49: |
| 1222 | case RTL_GIGA_MAC_VER_50: |
| 1223 | case RTL_GIGA_MAC_VER_51: |
| 1224 | rtl8168ep_driver_start(tp); |
| 1225 | break; |
| 1226 | default: |
| 1227 | BUG(); |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1233 | { |
| 1234 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1235 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1236 | } |
| 1237 | |
| 1238 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1239 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1240 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1241 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1242 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1243 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1244 | } |
| 1245 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1246 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1247 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1248 | switch (tp->mac_version) { |
| 1249 | case RTL_GIGA_MAC_VER_27: |
| 1250 | case RTL_GIGA_MAC_VER_28: |
| 1251 | case RTL_GIGA_MAC_VER_31: |
| 1252 | rtl8168dp_driver_stop(tp); |
| 1253 | break; |
| 1254 | case RTL_GIGA_MAC_VER_49: |
| 1255 | case RTL_GIGA_MAC_VER_50: |
| 1256 | case RTL_GIGA_MAC_VER_51: |
| 1257 | rtl8168ep_driver_stop(tp); |
| 1258 | break; |
| 1259 | default: |
| 1260 | BUG(); |
| 1261 | break; |
| 1262 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1263 | } |
| 1264 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1265 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1266 | { |
| 1267 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1268 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1269 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1270 | } |
| 1271 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1272 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1273 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1274 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1277 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1278 | { |
| 1279 | switch (tp->mac_version) { |
| 1280 | case RTL_GIGA_MAC_VER_27: |
| 1281 | case RTL_GIGA_MAC_VER_28: |
| 1282 | case RTL_GIGA_MAC_VER_31: |
| 1283 | return r8168dp_check_dash(tp); |
| 1284 | case RTL_GIGA_MAC_VER_49: |
| 1285 | case RTL_GIGA_MAC_VER_50: |
| 1286 | case RTL_GIGA_MAC_VER_51: |
| 1287 | return r8168ep_check_dash(tp); |
| 1288 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1289 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1293 | struct exgmac_reg { |
| 1294 | u16 addr; |
| 1295 | u16 mask; |
| 1296 | u32 val; |
| 1297 | }; |
| 1298 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1299 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1300 | const struct exgmac_reg *r, int len) |
| 1301 | { |
| 1302 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1303 | 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] | 1304 | r++; |
| 1305 | } |
| 1306 | } |
| 1307 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1308 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1309 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1310 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1311 | } |
| 1312 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1313 | 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] | 1314 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1315 | 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] | 1316 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1317 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1318 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1321 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1322 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1323 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1327 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1328 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1329 | mmiowb(); |
| 1330 | } |
| 1331 | |
| 1332 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1333 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1334 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1335 | mmiowb(); |
| 1336 | } |
| 1337 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1338 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1339 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1340 | RTL_W16(tp, IntrMask, bits); |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1343 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1344 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1345 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1346 | |
| 1347 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1348 | { |
| 1349 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1350 | } |
| 1351 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1352 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1354 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1355 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1356 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1359 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1360 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1361 | struct net_device *dev = tp->dev; |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1362 | struct phy_device *phydev = dev->phydev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1363 | |
| 1364 | if (!netif_running(dev)) |
| 1365 | return; |
| 1366 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1367 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1368 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1369 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1370 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1371 | ERIAR_EXGMAC); |
| 1372 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1373 | ERIAR_EXGMAC); |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1374 | } else if (phydev->speed == SPEED_100) { |
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, 0x00000005, |
| 1378 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1379 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1380 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1381 | ERIAR_EXGMAC); |
| 1382 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1383 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1384 | } |
| 1385 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1386 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1387 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1388 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1389 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1390 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1391 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1392 | if (phydev->speed == SPEED_1000) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1393 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1394 | ERIAR_EXGMAC); |
| 1395 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1396 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1397 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1398 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1399 | ERIAR_EXGMAC); |
| 1400 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1401 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1402 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1403 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Heiner Kallweit | 29a12b4 | 2018-07-17 22:52:14 +0200 | [diff] [blame] | 1404 | if (phydev->speed == SPEED_10) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1405 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1406 | ERIAR_EXGMAC); |
| 1407 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1408 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1409 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1410 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1411 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1412 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1416 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1417 | |
| 1418 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1419 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1420 | u8 options; |
| 1421 | u32 wolopts = 0; |
| 1422 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1423 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1424 | if (!(options & PMEnable)) |
| 1425 | return 0; |
| 1426 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1427 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1428 | if (options & LinkUp) |
| 1429 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1430 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1431 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1432 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1433 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1434 | wolopts |= WAKE_MAGIC; |
| 1435 | break; |
| 1436 | default: |
| 1437 | if (options & MagicPacket) |
| 1438 | wolopts |= WAKE_MAGIC; |
| 1439 | break; |
| 1440 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1441 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1442 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1443 | if (options & UWF) |
| 1444 | wolopts |= WAKE_UCAST; |
| 1445 | if (options & BWF) |
| 1446 | wolopts |= WAKE_BCAST; |
| 1447 | if (options & MWF) |
| 1448 | wolopts |= WAKE_MCAST; |
| 1449 | |
| 1450 | return wolopts; |
| 1451 | } |
| 1452 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1453 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1454 | { |
| 1455 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1456 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1457 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1458 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1459 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1460 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1461 | } |
| 1462 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1463 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1464 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1465 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1466 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1467 | u32 opt; |
| 1468 | u16 reg; |
| 1469 | u8 mask; |
| 1470 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1471 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1472 | { WAKE_UCAST, Config5, UWF }, |
| 1473 | { WAKE_BCAST, Config5, BWF }, |
| 1474 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1475 | { WAKE_ANY, Config5, LanWake }, |
| 1476 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1477 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1478 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1479 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1480 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1481 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1482 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1483 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1484 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1485 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1486 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1487 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1488 | 0x0dc, |
| 1489 | ERIAR_MASK_0100, |
| 1490 | MagicPacket_v2, |
| 1491 | 0x0000, |
| 1492 | ERIAR_EXGMAC); |
| 1493 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1494 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1495 | 0x0dc, |
| 1496 | ERIAR_MASK_0100, |
| 1497 | 0x0000, |
| 1498 | MagicPacket_v2, |
| 1499 | ERIAR_EXGMAC); |
| 1500 | break; |
| 1501 | default: |
| 1502 | tmp = ARRAY_SIZE(cfg); |
| 1503 | break; |
| 1504 | } |
| 1505 | |
| 1506 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1507 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1508 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1509 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1510 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1513 | switch (tp->mac_version) { |
| 1514 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1515 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1516 | if (wolopts) |
| 1517 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1518 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1519 | break; |
| 1520 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1521 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1522 | if (wolopts) |
| 1523 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1524 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1525 | break; |
| 1526 | } |
| 1527 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1528 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1532 | { |
| 1533 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1534 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1535 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1536 | if (wol->wolopts & ~WAKE_ANY) |
| 1537 | return -EINVAL; |
| 1538 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1539 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1540 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1541 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1542 | |
Heiner Kallweit | 2f533f6 | 2018-06-25 20:34:41 +0200 | [diff] [blame] | 1543 | tp->saved_wolopts = wol->wolopts; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1544 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1545 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1546 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1547 | |
| 1548 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1549 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1550 | device_set_wakeup_enable(d, tp->saved_wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1551 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1552 | pm_runtime_put_noidle(d); |
| 1553 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1554 | return 0; |
| 1555 | } |
| 1556 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1557 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1558 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1559 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1560 | } |
| 1561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1563 | struct ethtool_drvinfo *info) |
| 1564 | { |
| 1565 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1566 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1568 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1569 | 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] | 1570 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1571 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1572 | strlcpy(info->fw_version, rtl_fw->version, |
| 1573 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1577 | { |
| 1578 | return R8169_REGS_SIZE; |
| 1579 | } |
| 1580 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1581 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1582 | netdev_features_t features) |
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 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1585 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1586 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1587 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1589 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1590 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1591 | features &= ~NETIF_F_IP_CSUM; |
| 1592 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1593 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1596 | static int rtl8169_set_features(struct net_device *dev, |
| 1597 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
| 1599 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1600 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1602 | rtl_lock_work(tp); |
| 1603 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1604 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1605 | if (features & NETIF_F_RXALL) |
| 1606 | rx_config |= (AcceptErr | AcceptRunt); |
| 1607 | else |
| 1608 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1610 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1611 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1612 | if (features & NETIF_F_RXCSUM) |
| 1613 | tp->cp_cmd |= RxChkSum; |
| 1614 | else |
| 1615 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1616 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1617 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1618 | tp->cp_cmd |= RxVlan; |
| 1619 | else |
| 1620 | tp->cp_cmd &= ~RxVlan; |
| 1621 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1622 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1623 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1625 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1630 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1632 | return (skb_vlan_tag_present(skb)) ? |
| 1633 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1636 | 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] | 1637 | { |
| 1638 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1640 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1641 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1645 | void *p) |
| 1646 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1647 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1648 | u32 __iomem *data = tp->mmio_addr; |
| 1649 | u32 *dw = p; |
| 1650 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1652 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1653 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1654 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1655 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1658 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1659 | { |
| 1660 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1661 | |
| 1662 | return tp->msg_enable; |
| 1663 | } |
| 1664 | |
| 1665 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1666 | { |
| 1667 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1668 | |
| 1669 | tp->msg_enable = value; |
| 1670 | } |
| 1671 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1672 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1673 | "tx_packets", |
| 1674 | "rx_packets", |
| 1675 | "tx_errors", |
| 1676 | "rx_errors", |
| 1677 | "rx_missed", |
| 1678 | "align_errors", |
| 1679 | "tx_single_collisions", |
| 1680 | "tx_multi_collisions", |
| 1681 | "unicast", |
| 1682 | "broadcast", |
| 1683 | "multicast", |
| 1684 | "tx_aborted", |
| 1685 | "tx_underrun", |
| 1686 | }; |
| 1687 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1688 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1689 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1690 | switch (sset) { |
| 1691 | case ETH_SS_STATS: |
| 1692 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1693 | default: |
| 1694 | return -EOPNOTSUPP; |
| 1695 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1696 | } |
| 1697 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1698 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1699 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1700 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1701 | } |
| 1702 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1703 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1704 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1705 | dma_addr_t paddr = tp->counters_phys_addr; |
| 1706 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1707 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1708 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 1709 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1710 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1711 | RTL_W32(tp, CounterAddrLow, cmd); |
| 1712 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1713 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 1714 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1717 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1718 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1719 | /* |
| 1720 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 1721 | * tally counters. |
| 1722 | */ |
| 1723 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 1724 | return true; |
| 1725 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1726 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1727 | } |
| 1728 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1729 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1730 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1731 | /* |
| 1732 | * Some chips are unable to dump tally counters when the receiver |
| 1733 | * is disabled. |
| 1734 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1735 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1736 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1737 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1738 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1741 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1742 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1743 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1744 | bool ret = false; |
| 1745 | |
| 1746 | /* |
| 1747 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 1748 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 1749 | * reset by a power cycle, while the counter values collected by the |
| 1750 | * driver are reset at every driver unload/load cycle. |
| 1751 | * |
| 1752 | * To make sure the HW values returned by @get_stats64 match the SW |
| 1753 | * values, we collect the initial values at first open(*) and use them |
| 1754 | * as offsets to normalize the values returned by @get_stats64. |
| 1755 | * |
| 1756 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 1757 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 1758 | * set at open time by rtl_hw_start. |
| 1759 | */ |
| 1760 | |
| 1761 | if (tp->tc_offset.inited) |
| 1762 | return true; |
| 1763 | |
| 1764 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1765 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1766 | ret = true; |
| 1767 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1768 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1769 | ret = true; |
| 1770 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1771 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 1772 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 1773 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 1774 | tp->tc_offset.inited = true; |
| 1775 | |
| 1776 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1779 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1780 | struct ethtool_stats *stats, u64 *data) |
| 1781 | { |
| 1782 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1783 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1784 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1785 | |
| 1786 | ASSERT_RTNL(); |
| 1787 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1788 | pm_runtime_get_noresume(d); |
| 1789 | |
| 1790 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 1791 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 1792 | |
| 1793 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1794 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 1795 | data[0] = le64_to_cpu(counters->tx_packets); |
| 1796 | data[1] = le64_to_cpu(counters->rx_packets); |
| 1797 | data[2] = le64_to_cpu(counters->tx_errors); |
| 1798 | data[3] = le32_to_cpu(counters->rx_errors); |
| 1799 | data[4] = le16_to_cpu(counters->rx_missed); |
| 1800 | data[5] = le16_to_cpu(counters->align_errors); |
| 1801 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 1802 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 1803 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 1804 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 1805 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 1806 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 1807 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1810 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1811 | { |
| 1812 | switch(stringset) { |
| 1813 | case ETH_SS_STATS: |
| 1814 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1815 | break; |
| 1816 | } |
| 1817 | } |
| 1818 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1819 | /* |
| 1820 | * Interrupt coalescing |
| 1821 | * |
| 1822 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 1823 | * > 8169, 8168 and 810x line of chipsets |
| 1824 | * |
| 1825 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 1826 | * |
| 1827 | * > 2 - the Tx timer unit at gigabit speed |
| 1828 | * |
| 1829 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 1830 | * (0xe0) bit 1 and bit 0. |
| 1831 | * |
| 1832 | * For 8169 |
| 1833 | * bit[1:0] \ speed 1000M 100M 10M |
| 1834 | * 0 0 320ns 2.56us 40.96us |
| 1835 | * 0 1 2.56us 20.48us 327.7us |
| 1836 | * 1 0 5.12us 40.96us 655.4us |
| 1837 | * 1 1 10.24us 81.92us 1.31ms |
| 1838 | * |
| 1839 | * For the other |
| 1840 | * bit[1:0] \ speed 1000M 100M 10M |
| 1841 | * 0 0 5us 2.56us 40.96us |
| 1842 | * 0 1 40us 20.48us 327.7us |
| 1843 | * 1 0 80us 40.96us 655.4us |
| 1844 | * 1 1 160us 81.92us 1.31ms |
| 1845 | */ |
| 1846 | |
| 1847 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 1848 | struct rtl_coalesce_scale { |
| 1849 | /* Rx / Tx */ |
| 1850 | u32 nsecs[2]; |
| 1851 | }; |
| 1852 | |
| 1853 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 1854 | struct rtl_coalesce_info { |
| 1855 | u32 speed; |
| 1856 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 1857 | }; |
| 1858 | |
| 1859 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 1860 | #define rxtx_x1822(r, t) { \ |
| 1861 | {{(r), (t)}}, \ |
| 1862 | {{(r)*8, (t)*8}}, \ |
| 1863 | {{(r)*8*2, (t)*8*2}}, \ |
| 1864 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 1865 | } |
| 1866 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 1867 | /* speed delays: rx00 tx00 */ |
| 1868 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1869 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1870 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 1871 | { 0 }, |
| 1872 | }; |
| 1873 | |
| 1874 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 1875 | /* speed delays: rx00 tx00 */ |
| 1876 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 1877 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 1878 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 1879 | { 0 }, |
| 1880 | }; |
| 1881 | #undef rxtx_x1822 |
| 1882 | |
| 1883 | /* get rx/tx scale vector corresponding to current speed */ |
| 1884 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 1885 | { |
| 1886 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1887 | struct ethtool_link_ksettings ecmd; |
| 1888 | const struct rtl_coalesce_info *ci; |
| 1889 | int rc; |
| 1890 | |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 1891 | rc = phy_ethtool_get_link_ksettings(dev, &ecmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1892 | if (rc < 0) |
| 1893 | return ERR_PTR(rc); |
| 1894 | |
| 1895 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 1896 | if (ecmd.base.speed == ci->speed) { |
| 1897 | return ci; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | return ERR_PTR(-ELNRNG); |
| 1902 | } |
| 1903 | |
| 1904 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1905 | { |
| 1906 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1907 | const struct rtl_coalesce_info *ci; |
| 1908 | const struct rtl_coalesce_scale *scale; |
| 1909 | struct { |
| 1910 | u32 *max_frames; |
| 1911 | u32 *usecs; |
| 1912 | } coal_settings [] = { |
| 1913 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 1914 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 1915 | }, *p = coal_settings; |
| 1916 | int i; |
| 1917 | u16 w; |
| 1918 | |
| 1919 | memset(ec, 0, sizeof(*ec)); |
| 1920 | |
| 1921 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 1922 | ci = rtl_coalesce_info(dev); |
| 1923 | if (IS_ERR(ci)) |
| 1924 | return PTR_ERR(ci); |
| 1925 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 1926 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1927 | |
| 1928 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1929 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1930 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 1931 | w >>= RTL_COALESCE_SHIFT; |
| 1932 | *p->usecs = w & RTL_COALESCE_MASK; |
| 1933 | } |
| 1934 | |
| 1935 | for (i = 0; i < 2; i++) { |
| 1936 | p = coal_settings + i; |
| 1937 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 1938 | |
| 1939 | /* |
| 1940 | * ethtool_coalesce says it is illegal to set both usecs and |
| 1941 | * max_frames to 0. |
| 1942 | */ |
| 1943 | if (!*p->usecs && !*p->max_frames) |
| 1944 | *p->max_frames = 1; |
| 1945 | } |
| 1946 | |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
| 1950 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 1951 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 1952 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 1953 | { |
| 1954 | const struct rtl_coalesce_info *ci; |
| 1955 | u16 i; |
| 1956 | |
| 1957 | ci = rtl_coalesce_info(dev); |
| 1958 | if (IS_ERR(ci)) |
| 1959 | return ERR_CAST(ci); |
| 1960 | |
| 1961 | for (i = 0; i < 4; i++) { |
| 1962 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 1963 | ci->scalev[i].nsecs[1]); |
| 1964 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 1965 | *cp01 = i; |
| 1966 | return &ci->scalev[i]; |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | return ERR_PTR(-EINVAL); |
| 1971 | } |
| 1972 | |
| 1973 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 1974 | { |
| 1975 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 1976 | const struct rtl_coalesce_scale *scale; |
| 1977 | struct { |
| 1978 | u32 frames; |
| 1979 | u32 usecs; |
| 1980 | } coal_settings [] = { |
| 1981 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 1982 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 1983 | }, *p = coal_settings; |
| 1984 | u16 w = 0, cp01; |
| 1985 | int i; |
| 1986 | |
| 1987 | scale = rtl_coalesce_choose_scale(dev, |
| 1988 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 1989 | if (IS_ERR(scale)) |
| 1990 | return PTR_ERR(scale); |
| 1991 | |
| 1992 | for (i = 0; i < 2; i++, p++) { |
| 1993 | u32 units; |
| 1994 | |
| 1995 | /* |
| 1996 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 1997 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 1998 | * |
| 1999 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2000 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2001 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2002 | * |
| 2003 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2004 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2005 | * we'll reject it below in `frames % 4 != 0`. |
| 2006 | */ |
| 2007 | if (p->frames == 1) { |
| 2008 | p->frames = 0; |
| 2009 | } |
| 2010 | |
| 2011 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2012 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2013 | return -EINVAL; |
| 2014 | |
| 2015 | w <<= RTL_COALESCE_SHIFT; |
| 2016 | w |= units; |
| 2017 | w <<= RTL_COALESCE_SHIFT; |
| 2018 | w |= p->frames >> 2; |
| 2019 | } |
| 2020 | |
| 2021 | rtl_lock_work(tp); |
| 2022 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2023 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2024 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 2025 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2026 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2027 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2028 | |
| 2029 | rtl_unlock_work(tp); |
| 2030 | |
| 2031 | return 0; |
| 2032 | } |
| 2033 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2034 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2036 | .get_regs_len = rtl8169_get_regs_len, |
| 2037 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2038 | .get_coalesce = rtl_get_coalesce, |
| 2039 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2040 | .get_msglevel = rtl8169_get_msglevel, |
| 2041 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2043 | .get_wol = rtl8169_get_wol, |
| 2044 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2045 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2046 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2047 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2048 | .get_ts_info = ethtool_op_get_ts_info, |
Heiner Kallweit | dd84957 | 2018-07-17 22:51:48 +0200 | [diff] [blame] | 2049 | .nway_reset = phy_ethtool_nway_reset, |
Heiner Kallweit | 4577243 | 2018-07-17 22:51:44 +0200 | [diff] [blame] | 2050 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
| 2051 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | }; |
| 2053 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2054 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2055 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2057 | /* |
| 2058 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2059 | * but they can be identified more specifically through the test below |
| 2060 | * if needed: |
| 2061 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2062 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2063 | * |
| 2064 | * Same thing for the 8101Eb and the 8101Ec: |
| 2065 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2066 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2067 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2068 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2070 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | int mac_version; |
| 2072 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2073 | /* 8168EP family. */ |
| 2074 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2075 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2076 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2077 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2078 | /* 8168H family. */ |
| 2079 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2080 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2081 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2082 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2083 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2084 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2085 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2086 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2087 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2088 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2089 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2090 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2091 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2092 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2093 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2094 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2095 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2096 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2097 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2098 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2099 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2100 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2101 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2102 | /* 8168DP family. */ |
| 2103 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2104 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2105 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2106 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2107 | /* 8168C family. */ |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2108 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2109 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2110 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2111 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2112 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2113 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2114 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2115 | |
| 2116 | /* 8168B family. */ |
| 2117 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2118 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2119 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2120 | |
| 2121 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2122 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2123 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2124 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2125 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2126 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2127 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2128 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2129 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2130 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2131 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2132 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2133 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2134 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2135 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2136 | /* FIXME: where did these entries come from ? -- FR */ |
| 2137 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2138 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2139 | |
| 2140 | /* 8110 family. */ |
| 2141 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2142 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2143 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2144 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2145 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2146 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2147 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2148 | /* Catch-all */ |
| 2149 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2150 | }; |
| 2151 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | u32 reg; |
| 2153 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2154 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2155 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | p++; |
| 2157 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2158 | |
| 2159 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2160 | dev_notice(tp_to_dev(tp), |
| 2161 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2162 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2163 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2164 | tp->mac_version = tp->supports_gmii ? |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2165 | RTL_GIGA_MAC_VER_42 : |
| 2166 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2167 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2168 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2169 | RTL_GIGA_MAC_VER_45 : |
| 2170 | RTL_GIGA_MAC_VER_47; |
| 2171 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 2172 | tp->mac_version = tp->supports_gmii ? |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2173 | RTL_GIGA_MAC_VER_46 : |
| 2174 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2179 | { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 2180 | 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] | 2181 | } |
| 2182 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2183 | struct phy_reg { |
| 2184 | u16 reg; |
| 2185 | u16 val; |
| 2186 | }; |
| 2187 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2188 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2189 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2190 | { |
| 2191 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2192 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2193 | regs++; |
| 2194 | } |
| 2195 | } |
| 2196 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2197 | #define PHY_READ 0x00000000 |
| 2198 | #define PHY_DATA_OR 0x10000000 |
| 2199 | #define PHY_DATA_AND 0x20000000 |
| 2200 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2201 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2202 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2203 | #define PHY_WRITE 0x80000000 |
| 2204 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2205 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2206 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2207 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2208 | #define PHY_SKIPN 0xd0000000 |
| 2209 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2210 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2211 | struct fw_info { |
| 2212 | u32 magic; |
| 2213 | char version[RTL_VER_SIZE]; |
| 2214 | __le32 fw_start; |
| 2215 | __le32 fw_len; |
| 2216 | u8 chksum; |
| 2217 | } __packed; |
| 2218 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2219 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2220 | |
| 2221 | 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] | 2222 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2223 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2224 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2225 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2226 | char *version = rtl_fw->version; |
| 2227 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2228 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2229 | if (fw->size < FW_OPCODE_SIZE) |
| 2230 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2231 | |
| 2232 | if (!fw_info->magic) { |
| 2233 | size_t i, size, start; |
| 2234 | u8 checksum = 0; |
| 2235 | |
| 2236 | if (fw->size < sizeof(*fw_info)) |
| 2237 | goto out; |
| 2238 | |
| 2239 | for (i = 0; i < fw->size; i++) |
| 2240 | checksum += fw->data[i]; |
| 2241 | if (checksum != 0) |
| 2242 | goto out; |
| 2243 | |
| 2244 | start = le32_to_cpu(fw_info->fw_start); |
| 2245 | if (start > fw->size) |
| 2246 | goto out; |
| 2247 | |
| 2248 | size = le32_to_cpu(fw_info->fw_len); |
| 2249 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2250 | goto out; |
| 2251 | |
| 2252 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2253 | |
| 2254 | pa->code = (__le32 *)(fw->data + start); |
| 2255 | pa->size = size; |
| 2256 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2257 | if (fw->size % FW_OPCODE_SIZE) |
| 2258 | goto out; |
| 2259 | |
| 2260 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2261 | |
| 2262 | pa->code = (__le32 *)fw->data; |
| 2263 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2264 | } |
| 2265 | version[RTL_VER_SIZE - 1] = 0; |
| 2266 | |
| 2267 | rc = true; |
| 2268 | out: |
| 2269 | return rc; |
| 2270 | } |
| 2271 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2272 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2273 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2274 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2275 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2276 | size_t index; |
| 2277 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2278 | for (index = 0; index < pa->size; index++) { |
| 2279 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2280 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2281 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2282 | switch(action & 0xf0000000) { |
| 2283 | case PHY_READ: |
| 2284 | case PHY_DATA_OR: |
| 2285 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2286 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2287 | case PHY_CLEAR_READCOUNT: |
| 2288 | case PHY_WRITE: |
| 2289 | case PHY_WRITE_PREVIOUS: |
| 2290 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2293 | case PHY_BJMPN: |
| 2294 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2295 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2296 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2297 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2298 | } |
| 2299 | break; |
| 2300 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2301 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2302 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2303 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2304 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2305 | } |
| 2306 | break; |
| 2307 | case PHY_COMP_EQ_SKIPN: |
| 2308 | case PHY_COMP_NEQ_SKIPN: |
| 2309 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2310 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2311 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2312 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2313 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2314 | } |
| 2315 | break; |
| 2316 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2317 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2318 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2319 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2320 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2321 | } |
| 2322 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2323 | rc = true; |
| 2324 | out: |
| 2325 | return rc; |
| 2326 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2327 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2328 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2329 | { |
| 2330 | struct net_device *dev = tp->dev; |
| 2331 | int rc = -EINVAL; |
| 2332 | |
| 2333 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2334 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2335 | goto out; |
| 2336 | } |
| 2337 | |
| 2338 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2339 | rc = 0; |
| 2340 | out: |
| 2341 | return rc; |
| 2342 | } |
| 2343 | |
| 2344 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2345 | { |
| 2346 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2347 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2348 | u32 predata, count; |
| 2349 | size_t index; |
| 2350 | |
| 2351 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2352 | org.write = ops->write; |
| 2353 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2354 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2355 | for (index = 0; index < pa->size; ) { |
| 2356 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2357 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2358 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2359 | |
| 2360 | if (!action) |
| 2361 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2362 | |
| 2363 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2364 | case PHY_READ: |
| 2365 | predata = rtl_readphy(tp, regno); |
| 2366 | count++; |
| 2367 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2368 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2369 | case PHY_DATA_OR: |
| 2370 | predata |= data; |
| 2371 | index++; |
| 2372 | break; |
| 2373 | case PHY_DATA_AND: |
| 2374 | predata &= data; |
| 2375 | index++; |
| 2376 | break; |
| 2377 | case PHY_BJMPN: |
| 2378 | index -= regno; |
| 2379 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2380 | case PHY_MDIO_CHG: |
| 2381 | if (data == 0) { |
| 2382 | ops->write = org.write; |
| 2383 | ops->read = org.read; |
| 2384 | } else if (data == 1) { |
| 2385 | ops->write = mac_mcu_write; |
| 2386 | ops->read = mac_mcu_read; |
| 2387 | } |
| 2388 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2389 | index++; |
| 2390 | break; |
| 2391 | case PHY_CLEAR_READCOUNT: |
| 2392 | count = 0; |
| 2393 | index++; |
| 2394 | break; |
| 2395 | case PHY_WRITE: |
| 2396 | rtl_writephy(tp, regno, data); |
| 2397 | index++; |
| 2398 | break; |
| 2399 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2400 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | case PHY_COMP_EQ_SKIPN: |
| 2403 | if (predata == data) |
| 2404 | index += regno; |
| 2405 | index++; |
| 2406 | break; |
| 2407 | case PHY_COMP_NEQ_SKIPN: |
| 2408 | if (predata != data) |
| 2409 | index += regno; |
| 2410 | index++; |
| 2411 | break; |
| 2412 | case PHY_WRITE_PREVIOUS: |
| 2413 | rtl_writephy(tp, regno, predata); |
| 2414 | index++; |
| 2415 | break; |
| 2416 | case PHY_SKIPN: |
| 2417 | index += regno + 1; |
| 2418 | break; |
| 2419 | case PHY_DELAY_MS: |
| 2420 | mdelay(data); |
| 2421 | index++; |
| 2422 | break; |
| 2423 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2424 | default: |
| 2425 | BUG(); |
| 2426 | } |
| 2427 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2428 | |
| 2429 | ops->write = org.write; |
| 2430 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2433 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2434 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2435 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2436 | release_firmware(tp->rtl_fw->fw); |
| 2437 | kfree(tp->rtl_fw); |
| 2438 | } |
| 2439 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2442 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2443 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2444 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2445 | |
| 2446 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2447 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2448 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2452 | { |
| 2453 | if (rtl_readphy(tp, reg) != val) |
| 2454 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2455 | else |
| 2456 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2459 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2461 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2462 | { 0x1f, 0x0001 }, |
| 2463 | { 0x06, 0x006e }, |
| 2464 | { 0x08, 0x0708 }, |
| 2465 | { 0x15, 0x4000 }, |
| 2466 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2468 | { 0x1f, 0x0001 }, |
| 2469 | { 0x03, 0x00a1 }, |
| 2470 | { 0x02, 0x0008 }, |
| 2471 | { 0x01, 0x0120 }, |
| 2472 | { 0x00, 0x1000 }, |
| 2473 | { 0x04, 0x0800 }, |
| 2474 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2476 | { 0x03, 0xff41 }, |
| 2477 | { 0x02, 0xdf60 }, |
| 2478 | { 0x01, 0x0140 }, |
| 2479 | { 0x00, 0x0077 }, |
| 2480 | { 0x04, 0x7800 }, |
| 2481 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2483 | { 0x03, 0x802f }, |
| 2484 | { 0x02, 0x4f02 }, |
| 2485 | { 0x01, 0x0409 }, |
| 2486 | { 0x00, 0xf0f9 }, |
| 2487 | { 0x04, 0x9800 }, |
| 2488 | { 0x04, 0x9000 }, |
| 2489 | |
| 2490 | { 0x03, 0xdf01 }, |
| 2491 | { 0x02, 0xdf20 }, |
| 2492 | { 0x01, 0xff95 }, |
| 2493 | { 0x00, 0xba00 }, |
| 2494 | { 0x04, 0xa800 }, |
| 2495 | { 0x04, 0xa000 }, |
| 2496 | |
| 2497 | { 0x03, 0xff41 }, |
| 2498 | { 0x02, 0xdf20 }, |
| 2499 | { 0x01, 0x0140 }, |
| 2500 | { 0x00, 0x00bb }, |
| 2501 | { 0x04, 0xb800 }, |
| 2502 | { 0x04, 0xb000 }, |
| 2503 | |
| 2504 | { 0x03, 0xdf41 }, |
| 2505 | { 0x02, 0xdc60 }, |
| 2506 | { 0x01, 0x6340 }, |
| 2507 | { 0x00, 0x007d }, |
| 2508 | { 0x04, 0xd800 }, |
| 2509 | { 0x04, 0xd000 }, |
| 2510 | |
| 2511 | { 0x03, 0xdf01 }, |
| 2512 | { 0x02, 0xdf20 }, |
| 2513 | { 0x01, 0x100a }, |
| 2514 | { 0x00, 0xa0ff }, |
| 2515 | { 0x04, 0xf800 }, |
| 2516 | { 0x04, 0xf000 }, |
| 2517 | |
| 2518 | { 0x1f, 0x0000 }, |
| 2519 | { 0x0b, 0x0000 }, |
| 2520 | { 0x00, 0x9200 } |
| 2521 | }; |
| 2522 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2523 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2526 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2527 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2528 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2529 | { 0x1f, 0x0002 }, |
| 2530 | { 0x01, 0x90d0 }, |
| 2531 | { 0x1f, 0x0000 } |
| 2532 | }; |
| 2533 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2534 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2537 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2538 | { |
| 2539 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2540 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2541 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2542 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2543 | return; |
| 2544 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2545 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2546 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2547 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2550 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2551 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2552 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2553 | { 0x1f, 0x0001 }, |
| 2554 | { 0x04, 0x0000 }, |
| 2555 | { 0x03, 0x00a1 }, |
| 2556 | { 0x02, 0x0008 }, |
| 2557 | { 0x01, 0x0120 }, |
| 2558 | { 0x00, 0x1000 }, |
| 2559 | { 0x04, 0x0800 }, |
| 2560 | { 0x04, 0x9000 }, |
| 2561 | { 0x03, 0x802f }, |
| 2562 | { 0x02, 0x4f02 }, |
| 2563 | { 0x01, 0x0409 }, |
| 2564 | { 0x00, 0xf099 }, |
| 2565 | { 0x04, 0x9800 }, |
| 2566 | { 0x04, 0xa000 }, |
| 2567 | { 0x03, 0xdf01 }, |
| 2568 | { 0x02, 0xdf20 }, |
| 2569 | { 0x01, 0xff95 }, |
| 2570 | { 0x00, 0xba00 }, |
| 2571 | { 0x04, 0xa800 }, |
| 2572 | { 0x04, 0xf000 }, |
| 2573 | { 0x03, 0xdf01 }, |
| 2574 | { 0x02, 0xdf20 }, |
| 2575 | { 0x01, 0x101a }, |
| 2576 | { 0x00, 0xa0ff }, |
| 2577 | { 0x04, 0xf800 }, |
| 2578 | { 0x04, 0x0000 }, |
| 2579 | { 0x1f, 0x0000 }, |
| 2580 | |
| 2581 | { 0x1f, 0x0001 }, |
| 2582 | { 0x10, 0xf41b }, |
| 2583 | { 0x14, 0xfb54 }, |
| 2584 | { 0x18, 0xf5c7 }, |
| 2585 | { 0x1f, 0x0000 }, |
| 2586 | |
| 2587 | { 0x1f, 0x0001 }, |
| 2588 | { 0x17, 0x0cc0 }, |
| 2589 | { 0x1f, 0x0000 } |
| 2590 | }; |
| 2591 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2592 | 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] | 2593 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2594 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2597 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2598 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2599 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2600 | { 0x1f, 0x0001 }, |
| 2601 | { 0x04, 0x0000 }, |
| 2602 | { 0x03, 0x00a1 }, |
| 2603 | { 0x02, 0x0008 }, |
| 2604 | { 0x01, 0x0120 }, |
| 2605 | { 0x00, 0x1000 }, |
| 2606 | { 0x04, 0x0800 }, |
| 2607 | { 0x04, 0x9000 }, |
| 2608 | { 0x03, 0x802f }, |
| 2609 | { 0x02, 0x4f02 }, |
| 2610 | { 0x01, 0x0409 }, |
| 2611 | { 0x00, 0xf099 }, |
| 2612 | { 0x04, 0x9800 }, |
| 2613 | { 0x04, 0xa000 }, |
| 2614 | { 0x03, 0xdf01 }, |
| 2615 | { 0x02, 0xdf20 }, |
| 2616 | { 0x01, 0xff95 }, |
| 2617 | { 0x00, 0xba00 }, |
| 2618 | { 0x04, 0xa800 }, |
| 2619 | { 0x04, 0xf000 }, |
| 2620 | { 0x03, 0xdf01 }, |
| 2621 | { 0x02, 0xdf20 }, |
| 2622 | { 0x01, 0x101a }, |
| 2623 | { 0x00, 0xa0ff }, |
| 2624 | { 0x04, 0xf800 }, |
| 2625 | { 0x04, 0x0000 }, |
| 2626 | { 0x1f, 0x0000 }, |
| 2627 | |
| 2628 | { 0x1f, 0x0001 }, |
| 2629 | { 0x0b, 0x8480 }, |
| 2630 | { 0x1f, 0x0000 }, |
| 2631 | |
| 2632 | { 0x1f, 0x0001 }, |
| 2633 | { 0x18, 0x67c7 }, |
| 2634 | { 0x04, 0x2000 }, |
| 2635 | { 0x03, 0x002f }, |
| 2636 | { 0x02, 0x4360 }, |
| 2637 | { 0x01, 0x0109 }, |
| 2638 | { 0x00, 0x3022 }, |
| 2639 | { 0x04, 0x2800 }, |
| 2640 | { 0x1f, 0x0000 }, |
| 2641 | |
| 2642 | { 0x1f, 0x0001 }, |
| 2643 | { 0x17, 0x0cc0 }, |
| 2644 | { 0x1f, 0x0000 } |
| 2645 | }; |
| 2646 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2647 | 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] | 2648 | } |
| 2649 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2650 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2651 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2652 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2653 | { 0x10, 0xf41b }, |
| 2654 | { 0x1f, 0x0000 } |
| 2655 | }; |
| 2656 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2657 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2658 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2659 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2660 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2663 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2664 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2665 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2666 | { 0x1f, 0x0001 }, |
| 2667 | { 0x10, 0xf41b }, |
| 2668 | { 0x1f, 0x0000 } |
| 2669 | }; |
| 2670 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2671 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2672 | } |
| 2673 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2674 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2675 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2676 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2677 | { 0x1f, 0x0000 }, |
| 2678 | { 0x1d, 0x0f00 }, |
| 2679 | { 0x1f, 0x0002 }, |
| 2680 | { 0x0c, 0x1ec8 }, |
| 2681 | { 0x1f, 0x0000 } |
| 2682 | }; |
| 2683 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2684 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2685 | } |
| 2686 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2687 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2688 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2689 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2690 | { 0x1f, 0x0001 }, |
| 2691 | { 0x1d, 0x3d98 }, |
| 2692 | { 0x1f, 0x0000 } |
| 2693 | }; |
| 2694 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2695 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2696 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2697 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2698 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2699 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2700 | } |
| 2701 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2702 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2703 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2704 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2705 | { 0x1f, 0x0001 }, |
| 2706 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2707 | { 0x1f, 0x0002 }, |
| 2708 | { 0x00, 0x88d4 }, |
| 2709 | { 0x01, 0x82b1 }, |
| 2710 | { 0x03, 0x7002 }, |
| 2711 | { 0x08, 0x9e30 }, |
| 2712 | { 0x09, 0x01f0 }, |
| 2713 | { 0x0a, 0x5500 }, |
| 2714 | { 0x0c, 0x00c8 }, |
| 2715 | { 0x1f, 0x0003 }, |
| 2716 | { 0x12, 0xc096 }, |
| 2717 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2718 | { 0x1f, 0x0000 }, |
| 2719 | { 0x1f, 0x0000 }, |
| 2720 | { 0x09, 0x2000 }, |
| 2721 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2722 | }; |
| 2723 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2724 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2725 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2726 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2727 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2728 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2729 | } |
| 2730 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2731 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2732 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2733 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2734 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2735 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2736 | { 0x03, 0x802f }, |
| 2737 | { 0x02, 0x4f02 }, |
| 2738 | { 0x01, 0x0409 }, |
| 2739 | { 0x00, 0xf099 }, |
| 2740 | { 0x04, 0x9800 }, |
| 2741 | { 0x04, 0x9000 }, |
| 2742 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2743 | { 0x1f, 0x0002 }, |
| 2744 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2745 | { 0x06, 0x0761 }, |
| 2746 | { 0x1f, 0x0003 }, |
| 2747 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2748 | { 0x1f, 0x0000 } |
| 2749 | }; |
| 2750 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2751 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2752 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2753 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2754 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2755 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2756 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2757 | } |
| 2758 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2759 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2760 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2761 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2762 | { 0x1f, 0x0001 }, |
| 2763 | { 0x12, 0x2300 }, |
| 2764 | { 0x1d, 0x3d98 }, |
| 2765 | { 0x1f, 0x0002 }, |
| 2766 | { 0x0c, 0x7eb8 }, |
| 2767 | { 0x06, 0x5461 }, |
| 2768 | { 0x1f, 0x0003 }, |
| 2769 | { 0x16, 0x0f0a }, |
| 2770 | { 0x1f, 0x0000 } |
| 2771 | }; |
| 2772 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2773 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2774 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2775 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2776 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2777 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2778 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2779 | } |
| 2780 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2781 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2782 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2783 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2784 | } |
| 2785 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2786 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2787 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2788 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2789 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2790 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2791 | { 0x06, 0x4064 }, |
| 2792 | { 0x07, 0x2863 }, |
| 2793 | { 0x08, 0x059c }, |
| 2794 | { 0x09, 0x26b4 }, |
| 2795 | { 0x0a, 0x6a19 }, |
| 2796 | { 0x0b, 0xdcc8 }, |
| 2797 | { 0x10, 0xf06d }, |
| 2798 | { 0x14, 0x7f68 }, |
| 2799 | { 0x18, 0x7fd9 }, |
| 2800 | { 0x1c, 0xf0ff }, |
| 2801 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2802 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2803 | { 0x12, 0xf49f }, |
| 2804 | { 0x13, 0x070b }, |
| 2805 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2806 | { 0x14, 0x94c0 }, |
| 2807 | |
| 2808 | /* |
| 2809 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2810 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2811 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2812 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2813 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2814 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2815 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2816 | { 0x06, 0x5561 }, |
| 2817 | |
| 2818 | /* |
| 2819 | * Can not link to 1Gbps with bad cable |
| 2820 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2821 | */ |
| 2822 | { 0x1f, 0x0001 }, |
| 2823 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2824 | |
| 2825 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2826 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2827 | }; |
| 2828 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2829 | 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] | 2830 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2831 | /* |
| 2832 | * Rx Error Issue |
| 2833 | * Fine Tune Switching regulator parameter |
| 2834 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2835 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2836 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2837 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2838 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2839 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2840 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2841 | { 0x1f, 0x0002 }, |
| 2842 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2843 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2844 | { 0x05, 0x8330 }, |
| 2845 | { 0x06, 0x669a }, |
| 2846 | { 0x1f, 0x0002 } |
| 2847 | }; |
| 2848 | int val; |
| 2849 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2850 | 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] | 2851 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2852 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2853 | |
| 2854 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2855 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2856 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2857 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2858 | }; |
| 2859 | int i; |
| 2860 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2861 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2862 | |
| 2863 | val &= 0xff00; |
| 2864 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2865 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2866 | } |
| 2867 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2868 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2869 | { 0x1f, 0x0002 }, |
| 2870 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2871 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2872 | { 0x05, 0x8330 }, |
| 2873 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2874 | }; |
| 2875 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2876 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2877 | } |
| 2878 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2879 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2880 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2881 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2882 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2883 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2884 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2885 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2886 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2887 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2888 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2889 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2890 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2891 | |
| 2892 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2893 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2894 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2897 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2898 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2899 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2900 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2901 | { 0x1f, 0x0001 }, |
| 2902 | { 0x06, 0x4064 }, |
| 2903 | { 0x07, 0x2863 }, |
| 2904 | { 0x08, 0x059c }, |
| 2905 | { 0x09, 0x26b4 }, |
| 2906 | { 0x0a, 0x6a19 }, |
| 2907 | { 0x0b, 0xdcc8 }, |
| 2908 | { 0x10, 0xf06d }, |
| 2909 | { 0x14, 0x7f68 }, |
| 2910 | { 0x18, 0x7fd9 }, |
| 2911 | { 0x1c, 0xf0ff }, |
| 2912 | { 0x1d, 0x3d9c }, |
| 2913 | { 0x1f, 0x0003 }, |
| 2914 | { 0x12, 0xf49f }, |
| 2915 | { 0x13, 0x070b }, |
| 2916 | { 0x1a, 0x05ad }, |
| 2917 | { 0x14, 0x94c0 }, |
| 2918 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2919 | /* |
| 2920 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2921 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2922 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2923 | { 0x1f, 0x0002 }, |
| 2924 | { 0x06, 0x5561 }, |
| 2925 | { 0x1f, 0x0005 }, |
| 2926 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2927 | { 0x06, 0x5561 }, |
| 2928 | |
| 2929 | /* |
| 2930 | * Can not link to 1Gbps with bad cable |
| 2931 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2932 | */ |
| 2933 | { 0x1f, 0x0001 }, |
| 2934 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2935 | |
| 2936 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2937 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2938 | }; |
| 2939 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2940 | 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] | 2941 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2942 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2943 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2944 | { 0x1f, 0x0002 }, |
| 2945 | { 0x05, 0x669a }, |
| 2946 | { 0x1f, 0x0005 }, |
| 2947 | { 0x05, 0x8330 }, |
| 2948 | { 0x06, 0x669a }, |
| 2949 | |
| 2950 | { 0x1f, 0x0002 } |
| 2951 | }; |
| 2952 | int val; |
| 2953 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2954 | 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] | 2955 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2956 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2957 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2958 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2959 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2960 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2961 | }; |
| 2962 | int i; |
| 2963 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2964 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2965 | |
| 2966 | val &= 0xff00; |
| 2967 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2968 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2969 | } |
| 2970 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2971 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2972 | { 0x1f, 0x0002 }, |
| 2973 | { 0x05, 0x2642 }, |
| 2974 | { 0x1f, 0x0005 }, |
| 2975 | { 0x05, 0x8330 }, |
| 2976 | { 0x06, 0x2642 } |
| 2977 | }; |
| 2978 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2979 | 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] | 2980 | } |
| 2981 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2982 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2983 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2984 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2985 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2986 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2987 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2988 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2989 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2990 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2991 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2992 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2993 | |
| 2994 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2995 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2996 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2999 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3000 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3001 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3002 | { 0x1f, 0x0002 }, |
| 3003 | { 0x10, 0x0008 }, |
| 3004 | { 0x0d, 0x006c }, |
| 3005 | |
| 3006 | { 0x1f, 0x0000 }, |
| 3007 | { 0x0d, 0xf880 }, |
| 3008 | |
| 3009 | { 0x1f, 0x0001 }, |
| 3010 | { 0x17, 0x0cc0 }, |
| 3011 | |
| 3012 | { 0x1f, 0x0001 }, |
| 3013 | { 0x0b, 0xa4d8 }, |
| 3014 | { 0x09, 0x281c }, |
| 3015 | { 0x07, 0x2883 }, |
| 3016 | { 0x0a, 0x6b35 }, |
| 3017 | { 0x1d, 0x3da4 }, |
| 3018 | { 0x1c, 0xeffd }, |
| 3019 | { 0x14, 0x7f52 }, |
| 3020 | { 0x18, 0x7fc6 }, |
| 3021 | { 0x08, 0x0601 }, |
| 3022 | { 0x06, 0x4063 }, |
| 3023 | { 0x10, 0xf074 }, |
| 3024 | { 0x1f, 0x0003 }, |
| 3025 | { 0x13, 0x0789 }, |
| 3026 | { 0x12, 0xf4bd }, |
| 3027 | { 0x1a, 0x04fd }, |
| 3028 | { 0x14, 0x84b0 }, |
| 3029 | { 0x1f, 0x0000 }, |
| 3030 | { 0x00, 0x9200 }, |
| 3031 | |
| 3032 | { 0x1f, 0x0005 }, |
| 3033 | { 0x01, 0x0340 }, |
| 3034 | { 0x1f, 0x0001 }, |
| 3035 | { 0x04, 0x4000 }, |
| 3036 | { 0x03, 0x1d21 }, |
| 3037 | { 0x02, 0x0c32 }, |
| 3038 | { 0x01, 0x0200 }, |
| 3039 | { 0x00, 0x5554 }, |
| 3040 | { 0x04, 0x4800 }, |
| 3041 | { 0x04, 0x4000 }, |
| 3042 | { 0x04, 0xf000 }, |
| 3043 | { 0x03, 0xdf01 }, |
| 3044 | { 0x02, 0xdf20 }, |
| 3045 | { 0x01, 0x101a }, |
| 3046 | { 0x00, 0xa0ff }, |
| 3047 | { 0x04, 0xf800 }, |
| 3048 | { 0x04, 0xf000 }, |
| 3049 | { 0x1f, 0x0000 }, |
| 3050 | |
| 3051 | { 0x1f, 0x0007 }, |
| 3052 | { 0x1e, 0x0023 }, |
| 3053 | { 0x16, 0x0000 }, |
| 3054 | { 0x1f, 0x0000 } |
| 3055 | }; |
| 3056 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3057 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3060 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3061 | { |
| 3062 | static const struct phy_reg phy_reg_init[] = { |
| 3063 | { 0x1f, 0x0001 }, |
| 3064 | { 0x17, 0x0cc0 }, |
| 3065 | |
| 3066 | { 0x1f, 0x0007 }, |
| 3067 | { 0x1e, 0x002d }, |
| 3068 | { 0x18, 0x0040 }, |
| 3069 | { 0x1f, 0x0000 } |
| 3070 | }; |
| 3071 | |
| 3072 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3073 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3074 | } |
| 3075 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3076 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3077 | { |
| 3078 | static const struct phy_reg phy_reg_init[] = { |
| 3079 | /* Enable Delay cap */ |
| 3080 | { 0x1f, 0x0005 }, |
| 3081 | { 0x05, 0x8b80 }, |
| 3082 | { 0x06, 0xc896 }, |
| 3083 | { 0x1f, 0x0000 }, |
| 3084 | |
| 3085 | /* Channel estimation fine tune */ |
| 3086 | { 0x1f, 0x0001 }, |
| 3087 | { 0x0b, 0x6c20 }, |
| 3088 | { 0x07, 0x2872 }, |
| 3089 | { 0x1c, 0xefff }, |
| 3090 | { 0x1f, 0x0003 }, |
| 3091 | { 0x14, 0x6420 }, |
| 3092 | { 0x1f, 0x0000 }, |
| 3093 | |
| 3094 | /* Update PFM & 10M TX idle timer */ |
| 3095 | { 0x1f, 0x0007 }, |
| 3096 | { 0x1e, 0x002f }, |
| 3097 | { 0x15, 0x1919 }, |
| 3098 | { 0x1f, 0x0000 }, |
| 3099 | |
| 3100 | { 0x1f, 0x0007 }, |
| 3101 | { 0x1e, 0x00ac }, |
| 3102 | { 0x18, 0x0006 }, |
| 3103 | { 0x1f, 0x0000 } |
| 3104 | }; |
| 3105 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3106 | rtl_apply_firmware(tp); |
| 3107 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3108 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3109 | |
| 3110 | /* DCO enable for 10M IDLE Power */ |
| 3111 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3112 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3113 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3114 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3115 | |
| 3116 | /* For impedance matching */ |
| 3117 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3118 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3119 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3120 | |
| 3121 | /* PHY auto speed down */ |
| 3122 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3123 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3124 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3125 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3126 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3127 | |
| 3128 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3129 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3130 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3131 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3132 | |
| 3133 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3134 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3135 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3136 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3137 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3138 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3139 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3140 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3141 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3142 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3143 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3144 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3145 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3146 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3147 | } |
| 3148 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3149 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3150 | { |
| 3151 | const u16 w[] = { |
| 3152 | addr[0] | (addr[1] << 8), |
| 3153 | addr[2] | (addr[3] << 8), |
| 3154 | addr[4] | (addr[5] << 8) |
| 3155 | }; |
| 3156 | const struct exgmac_reg e[] = { |
| 3157 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3158 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3159 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3160 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3161 | }; |
| 3162 | |
| 3163 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3164 | } |
| 3165 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3166 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3167 | { |
| 3168 | static const struct phy_reg phy_reg_init[] = { |
| 3169 | /* Enable Delay cap */ |
| 3170 | { 0x1f, 0x0004 }, |
| 3171 | { 0x1f, 0x0007 }, |
| 3172 | { 0x1e, 0x00ac }, |
| 3173 | { 0x18, 0x0006 }, |
| 3174 | { 0x1f, 0x0002 }, |
| 3175 | { 0x1f, 0x0000 }, |
| 3176 | { 0x1f, 0x0000 }, |
| 3177 | |
| 3178 | /* Channel estimation fine tune */ |
| 3179 | { 0x1f, 0x0003 }, |
| 3180 | { 0x09, 0xa20f }, |
| 3181 | { 0x1f, 0x0000 }, |
| 3182 | { 0x1f, 0x0000 }, |
| 3183 | |
| 3184 | /* Green Setting */ |
| 3185 | { 0x1f, 0x0005 }, |
| 3186 | { 0x05, 0x8b5b }, |
| 3187 | { 0x06, 0x9222 }, |
| 3188 | { 0x05, 0x8b6d }, |
| 3189 | { 0x06, 0x8000 }, |
| 3190 | { 0x05, 0x8b76 }, |
| 3191 | { 0x06, 0x8000 }, |
| 3192 | { 0x1f, 0x0000 } |
| 3193 | }; |
| 3194 | |
| 3195 | rtl_apply_firmware(tp); |
| 3196 | |
| 3197 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3198 | |
| 3199 | /* For 4-corner performance improve */ |
| 3200 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3201 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3202 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3203 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3204 | |
| 3205 | /* PHY auto speed down */ |
| 3206 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3207 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3208 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3209 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3210 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3211 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3212 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3213 | |
| 3214 | /* improve 10M EEE waveform */ |
| 3215 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3216 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3217 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3218 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3219 | |
| 3220 | /* Improve 2-pair detection performance */ |
| 3221 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3222 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3223 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3224 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3225 | |
| 3226 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3227 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3228 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3229 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3230 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3231 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3232 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3233 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3234 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3235 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3236 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3237 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3238 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3239 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3240 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3241 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3242 | |
| 3243 | /* Green feature */ |
| 3244 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3245 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3246 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3247 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3248 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3249 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3250 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3251 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3252 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3253 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3254 | } |
| 3255 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3256 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3257 | { |
| 3258 | /* For 4-corner performance improve */ |
| 3259 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3260 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3261 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3262 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3263 | |
| 3264 | /* PHY auto speed down */ |
| 3265 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3266 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3267 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3268 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3269 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3270 | |
| 3271 | /* Improve 10M EEE waveform */ |
| 3272 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3273 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3274 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3275 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3276 | } |
| 3277 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3278 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3279 | { |
| 3280 | static const struct phy_reg phy_reg_init[] = { |
| 3281 | /* Channel estimation fine tune */ |
| 3282 | { 0x1f, 0x0003 }, |
| 3283 | { 0x09, 0xa20f }, |
| 3284 | { 0x1f, 0x0000 }, |
| 3285 | |
| 3286 | /* Modify green table for giga & fnet */ |
| 3287 | { 0x1f, 0x0005 }, |
| 3288 | { 0x05, 0x8b55 }, |
| 3289 | { 0x06, 0x0000 }, |
| 3290 | { 0x05, 0x8b5e }, |
| 3291 | { 0x06, 0x0000 }, |
| 3292 | { 0x05, 0x8b67 }, |
| 3293 | { 0x06, 0x0000 }, |
| 3294 | { 0x05, 0x8b70 }, |
| 3295 | { 0x06, 0x0000 }, |
| 3296 | { 0x1f, 0x0000 }, |
| 3297 | { 0x1f, 0x0007 }, |
| 3298 | { 0x1e, 0x0078 }, |
| 3299 | { 0x17, 0x0000 }, |
| 3300 | { 0x19, 0x00fb }, |
| 3301 | { 0x1f, 0x0000 }, |
| 3302 | |
| 3303 | /* Modify green table for 10M */ |
| 3304 | { 0x1f, 0x0005 }, |
| 3305 | { 0x05, 0x8b79 }, |
| 3306 | { 0x06, 0xaa00 }, |
| 3307 | { 0x1f, 0x0000 }, |
| 3308 | |
| 3309 | /* Disable hiimpedance detection (RTCT) */ |
| 3310 | { 0x1f, 0x0003 }, |
| 3311 | { 0x01, 0x328a }, |
| 3312 | { 0x1f, 0x0000 } |
| 3313 | }; |
| 3314 | |
| 3315 | rtl_apply_firmware(tp); |
| 3316 | |
| 3317 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3318 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3319 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3320 | |
| 3321 | /* Improve 2-pair detection performance */ |
| 3322 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3323 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3324 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3325 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3326 | } |
| 3327 | |
| 3328 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3329 | { |
| 3330 | rtl_apply_firmware(tp); |
| 3331 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3332 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3333 | } |
| 3334 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3335 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3336 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3337 | static const struct phy_reg phy_reg_init[] = { |
| 3338 | /* Channel estimation fine tune */ |
| 3339 | { 0x1f, 0x0003 }, |
| 3340 | { 0x09, 0xa20f }, |
| 3341 | { 0x1f, 0x0000 }, |
| 3342 | |
| 3343 | /* Modify green table for giga & fnet */ |
| 3344 | { 0x1f, 0x0005 }, |
| 3345 | { 0x05, 0x8b55 }, |
| 3346 | { 0x06, 0x0000 }, |
| 3347 | { 0x05, 0x8b5e }, |
| 3348 | { 0x06, 0x0000 }, |
| 3349 | { 0x05, 0x8b67 }, |
| 3350 | { 0x06, 0x0000 }, |
| 3351 | { 0x05, 0x8b70 }, |
| 3352 | { 0x06, 0x0000 }, |
| 3353 | { 0x1f, 0x0000 }, |
| 3354 | { 0x1f, 0x0007 }, |
| 3355 | { 0x1e, 0x0078 }, |
| 3356 | { 0x17, 0x0000 }, |
| 3357 | { 0x19, 0x00aa }, |
| 3358 | { 0x1f, 0x0000 }, |
| 3359 | |
| 3360 | /* Modify green table for 10M */ |
| 3361 | { 0x1f, 0x0005 }, |
| 3362 | { 0x05, 0x8b79 }, |
| 3363 | { 0x06, 0xaa00 }, |
| 3364 | { 0x1f, 0x0000 }, |
| 3365 | |
| 3366 | /* Disable hiimpedance detection (RTCT) */ |
| 3367 | { 0x1f, 0x0003 }, |
| 3368 | { 0x01, 0x328a }, |
| 3369 | { 0x1f, 0x0000 } |
| 3370 | }; |
| 3371 | |
| 3372 | |
| 3373 | rtl_apply_firmware(tp); |
| 3374 | |
| 3375 | rtl8168f_hw_phy_config(tp); |
| 3376 | |
| 3377 | /* Improve 2-pair detection performance */ |
| 3378 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3379 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3380 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3381 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3382 | |
| 3383 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3384 | |
| 3385 | /* Modify green table for giga */ |
| 3386 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3387 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3388 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3389 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3390 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3391 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3392 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3393 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3394 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3395 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3396 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3397 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3398 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3399 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3400 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3401 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3402 | |
| 3403 | /* uc same-seed solution */ |
| 3404 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3405 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3406 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3407 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3408 | |
| 3409 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3410 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3411 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3412 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3413 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3414 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3415 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3416 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3417 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3418 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3419 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3420 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3421 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3422 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3423 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3424 | |
| 3425 | /* Green feature */ |
| 3426 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3427 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3428 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3429 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3430 | } |
| 3431 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3432 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3433 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3434 | rtl_apply_firmware(tp); |
| 3435 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3436 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3437 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3438 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3439 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3440 | } else { |
| 3441 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3442 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3443 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3444 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3445 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3446 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3447 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3448 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3449 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3450 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3451 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3452 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3453 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3454 | /* Enable PHY auto speed down */ |
| 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, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3457 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3458 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3459 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3460 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3461 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3462 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3463 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3464 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3465 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3466 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3467 | /* EEE auto-fallback function */ |
| 3468 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3469 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3470 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3471 | /* Enable UC LPF tune function */ |
| 3472 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3473 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3474 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3475 | |
| 3476 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3477 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3478 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3479 | /* Improve SWR Efficiency */ |
| 3480 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3481 | rtl_writephy(tp, 0x14, 0x5065); |
| 3482 | rtl_writephy(tp, 0x14, 0xd065); |
| 3483 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3484 | rtl_writephy(tp, 0x11, 0x5655); |
| 3485 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3486 | rtl_writephy(tp, 0x14, 0x1065); |
| 3487 | rtl_writephy(tp, 0x14, 0x9065); |
| 3488 | rtl_writephy(tp, 0x14, 0x1065); |
| 3489 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3490 | /* Check ALDPS bit, disable it if enabled */ |
| 3491 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3492 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3493 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3494 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3495 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3496 | } |
| 3497 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3498 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3499 | { |
| 3500 | rtl_apply_firmware(tp); |
| 3501 | } |
| 3502 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3503 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3504 | { |
| 3505 | u16 dout_tapbin; |
| 3506 | u32 data; |
| 3507 | |
| 3508 | rtl_apply_firmware(tp); |
| 3509 | |
| 3510 | /* CHN EST parameters adjust - giga master */ |
| 3511 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3512 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3513 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3514 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3515 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3516 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3517 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3518 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3519 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3520 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3521 | |
| 3522 | /* CHN EST parameters adjust - giga slave */ |
| 3523 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3524 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3525 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3526 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3527 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3528 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3529 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3530 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3531 | |
| 3532 | /* CHN EST parameters adjust - fnet */ |
| 3533 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3534 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3535 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3536 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3537 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3538 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3539 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3540 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3541 | |
| 3542 | /* enable R-tune & PGA-retune function */ |
| 3543 | dout_tapbin = 0; |
| 3544 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3545 | data = rtl_readphy(tp, 0x13); |
| 3546 | data &= 3; |
| 3547 | data <<= 2; |
| 3548 | dout_tapbin |= data; |
| 3549 | data = rtl_readphy(tp, 0x12); |
| 3550 | data &= 0xc000; |
| 3551 | data >>= 14; |
| 3552 | dout_tapbin |= data; |
| 3553 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3554 | dout_tapbin <<= 12; |
| 3555 | dout_tapbin &= 0xf000; |
| 3556 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3557 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3558 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3559 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3560 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3561 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3562 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3563 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3564 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3565 | |
| 3566 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3567 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3568 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3569 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3570 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3571 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3572 | |
| 3573 | /* enable GPHY 10M */ |
| 3574 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3575 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3576 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3577 | |
| 3578 | /* SAR ADC performance */ |
| 3579 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3580 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3581 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3582 | |
| 3583 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3584 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3585 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3586 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3587 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3588 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3589 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3590 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3591 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3592 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3593 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3594 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3595 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3596 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3597 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3598 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3599 | |
| 3600 | /* disable phy pfm mode */ |
| 3601 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3602 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3603 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3604 | |
| 3605 | /* Check ALDPS bit, disable it if enabled */ |
| 3606 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3607 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3608 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3609 | |
| 3610 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3611 | } |
| 3612 | |
| 3613 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3614 | { |
| 3615 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3616 | u16 rlen; |
| 3617 | u32 data; |
| 3618 | |
| 3619 | rtl_apply_firmware(tp); |
| 3620 | |
| 3621 | /* CHIN EST parameter update */ |
| 3622 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3623 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3624 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3625 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3626 | |
| 3627 | /* enable R-tune & PGA-retune function */ |
| 3628 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3629 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3630 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3631 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3632 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3633 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3634 | |
| 3635 | /* enable GPHY 10M */ |
| 3636 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3637 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3638 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3639 | |
| 3640 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3641 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3642 | ioffset_p3 = ((data & 0x80)>>7); |
| 3643 | ioffset_p3 <<= 3; |
| 3644 | |
| 3645 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3646 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3647 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3648 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3649 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3650 | ioffset_p0 <<= 3; |
| 3651 | ioffset_p0 |= (data & (0x07)); |
| 3652 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3653 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3654 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 3655 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3656 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3657 | rtl_writephy(tp, 0x16, data); |
| 3658 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3659 | } |
| 3660 | |
| 3661 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3662 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3663 | data = rtl_readphy(tp, 0x16); |
| 3664 | data &= 0x000f; |
| 3665 | rlen = 0; |
| 3666 | if (data > 3) |
| 3667 | rlen = data - 3; |
| 3668 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3669 | rtl_writephy(tp, 0x17, data); |
| 3670 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3671 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3672 | |
| 3673 | /* disable phy pfm mode */ |
| 3674 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3675 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3676 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3677 | |
| 3678 | /* Check ALDPS bit, disable it if enabled */ |
| 3679 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3680 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3681 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3682 | |
| 3683 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3684 | } |
| 3685 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 3686 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 3687 | { |
| 3688 | /* Enable PHY auto speed down */ |
| 3689 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3690 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 3691 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3692 | |
| 3693 | /* patch 10M & ALDPS */ |
| 3694 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3695 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3696 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3697 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3698 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3699 | rtl_writephy(tp, 0x13, 0x8084); |
| 3700 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3701 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3702 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3703 | |
| 3704 | /* Enable EEE auto-fallback function */ |
| 3705 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 3706 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 3707 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3708 | |
| 3709 | /* Enable UC LPF tune function */ |
| 3710 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3711 | rtl_writephy(tp, 0x13, 0x8012); |
| 3712 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3713 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3714 | |
| 3715 | /* set rg_sel_sdm_rate */ |
| 3716 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3717 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3718 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3719 | |
| 3720 | /* Check ALDPS bit, disable it if enabled */ |
| 3721 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3722 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3723 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3724 | |
| 3725 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3726 | } |
| 3727 | |
| 3728 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 3729 | { |
| 3730 | /* patch 10M & ALDPS */ |
| 3731 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 3732 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 3733 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 3734 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 3735 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3736 | rtl_writephy(tp, 0x13, 0x8084); |
| 3737 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3738 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 3739 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3740 | |
| 3741 | /* Enable UC LPF tune function */ |
| 3742 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3743 | rtl_writephy(tp, 0x13, 0x8012); |
| 3744 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 3745 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3746 | |
| 3747 | /* Set rg_sel_sdm_rate */ |
| 3748 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 3749 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 3750 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3751 | |
| 3752 | /* Channel estimation parameters */ |
| 3753 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3754 | rtl_writephy(tp, 0x13, 0x80f3); |
| 3755 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 3756 | rtl_writephy(tp, 0x13, 0x80f0); |
| 3757 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 3758 | rtl_writephy(tp, 0x13, 0x80ef); |
| 3759 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 3760 | rtl_writephy(tp, 0x13, 0x80f6); |
| 3761 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 3762 | rtl_writephy(tp, 0x13, 0x80ec); |
| 3763 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 3764 | rtl_writephy(tp, 0x13, 0x80ed); |
| 3765 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3766 | rtl_writephy(tp, 0x13, 0x80f2); |
| 3767 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 3768 | rtl_writephy(tp, 0x13, 0x80f4); |
| 3769 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 3770 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3771 | rtl_writephy(tp, 0x13, 0x8110); |
| 3772 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 3773 | rtl_writephy(tp, 0x13, 0x810f); |
| 3774 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 3775 | rtl_writephy(tp, 0x13, 0x8111); |
| 3776 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 3777 | rtl_writephy(tp, 0x13, 0x8113); |
| 3778 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 3779 | rtl_writephy(tp, 0x13, 0x8115); |
| 3780 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 3781 | rtl_writephy(tp, 0x13, 0x810e); |
| 3782 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 3783 | rtl_writephy(tp, 0x13, 0x810c); |
| 3784 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 3785 | rtl_writephy(tp, 0x13, 0x810b); |
| 3786 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 3787 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3788 | rtl_writephy(tp, 0x13, 0x80d1); |
| 3789 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 3790 | rtl_writephy(tp, 0x13, 0x80cd); |
| 3791 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 3792 | rtl_writephy(tp, 0x13, 0x80d3); |
| 3793 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 3794 | rtl_writephy(tp, 0x13, 0x80d5); |
| 3795 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 3796 | rtl_writephy(tp, 0x13, 0x80d7); |
| 3797 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 3798 | |
| 3799 | /* Force PWM-mode */ |
| 3800 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3801 | rtl_writephy(tp, 0x14, 0x5065); |
| 3802 | rtl_writephy(tp, 0x14, 0xd065); |
| 3803 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3804 | rtl_writephy(tp, 0x12, 0x00ed); |
| 3805 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3806 | rtl_writephy(tp, 0x14, 0x1065); |
| 3807 | rtl_writephy(tp, 0x14, 0x9065); |
| 3808 | rtl_writephy(tp, 0x14, 0x1065); |
| 3809 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3810 | |
| 3811 | /* Check ALDPS bit, disable it if enabled */ |
| 3812 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3813 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 3814 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 3815 | |
| 3816 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3817 | } |
| 3818 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3819 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3820 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3821 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3822 | { 0x1f, 0x0003 }, |
| 3823 | { 0x08, 0x441d }, |
| 3824 | { 0x01, 0x9100 }, |
| 3825 | { 0x1f, 0x0000 } |
| 3826 | }; |
| 3827 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3828 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3829 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3830 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3831 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3832 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3833 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3834 | } |
| 3835 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3836 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3837 | { |
| 3838 | static const struct phy_reg phy_reg_init[] = { |
| 3839 | { 0x1f, 0x0005 }, |
| 3840 | { 0x1a, 0x0000 }, |
| 3841 | { 0x1f, 0x0000 }, |
| 3842 | |
| 3843 | { 0x1f, 0x0004 }, |
| 3844 | { 0x1c, 0x0000 }, |
| 3845 | { 0x1f, 0x0000 }, |
| 3846 | |
| 3847 | { 0x1f, 0x0001 }, |
| 3848 | { 0x15, 0x7701 }, |
| 3849 | { 0x1f, 0x0000 } |
| 3850 | }; |
| 3851 | |
| 3852 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3853 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3854 | rtl_writephy(tp, 0x18, 0x0310); |
| 3855 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3856 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3857 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3858 | |
| 3859 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3860 | } |
| 3861 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3862 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3863 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3864 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3865 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3866 | rtl_writephy(tp, 0x18, 0x0310); |
| 3867 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3868 | |
| 3869 | rtl_apply_firmware(tp); |
| 3870 | |
| 3871 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3872 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3873 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3874 | rtl_writephy(tp, 0x10, 0x401f); |
| 3875 | rtl_writephy(tp, 0x19, 0x7030); |
| 3876 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3877 | } |
| 3878 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3879 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3880 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3881 | static const struct phy_reg phy_reg_init[] = { |
| 3882 | { 0x1f, 0x0004 }, |
| 3883 | { 0x10, 0xc07f }, |
| 3884 | { 0x19, 0x7030 }, |
| 3885 | { 0x1f, 0x0000 } |
| 3886 | }; |
| 3887 | |
| 3888 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3889 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3890 | rtl_writephy(tp, 0x18, 0x0310); |
| 3891 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3892 | |
| 3893 | rtl_apply_firmware(tp); |
| 3894 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3895 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3896 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3897 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3898 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3899 | } |
| 3900 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3901 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3902 | { |
| 3903 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3904 | |
| 3905 | rtl8169_print_mac_version(tp); |
| 3906 | |
| 3907 | switch (tp->mac_version) { |
| 3908 | case RTL_GIGA_MAC_VER_01: |
| 3909 | break; |
| 3910 | case RTL_GIGA_MAC_VER_02: |
| 3911 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3912 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3913 | break; |
| 3914 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3915 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3916 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3917 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3918 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3919 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3920 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3921 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3922 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3923 | case RTL_GIGA_MAC_VER_07: |
| 3924 | case RTL_GIGA_MAC_VER_08: |
| 3925 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3926 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3927 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3928 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3929 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3930 | break; |
| 3931 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3932 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3933 | break; |
| 3934 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3935 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3936 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3937 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3938 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3939 | break; |
| 3940 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3941 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3942 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3943 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3944 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3945 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3946 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3947 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3948 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3949 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3950 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3951 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3952 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3953 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3954 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3955 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3956 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3957 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3958 | break; |
| 3959 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3960 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3961 | break; |
| 3962 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3963 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3964 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3965 | case RTL_GIGA_MAC_VER_28: |
| 3966 | rtl8168d_4_hw_phy_config(tp); |
| 3967 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3968 | case RTL_GIGA_MAC_VER_29: |
| 3969 | case RTL_GIGA_MAC_VER_30: |
| 3970 | rtl8105e_hw_phy_config(tp); |
| 3971 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3972 | case RTL_GIGA_MAC_VER_31: |
| 3973 | /* None. */ |
| 3974 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3975 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3976 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3977 | rtl8168e_1_hw_phy_config(tp); |
| 3978 | break; |
| 3979 | case RTL_GIGA_MAC_VER_34: |
| 3980 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3981 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3982 | case RTL_GIGA_MAC_VER_35: |
| 3983 | rtl8168f_1_hw_phy_config(tp); |
| 3984 | break; |
| 3985 | case RTL_GIGA_MAC_VER_36: |
| 3986 | rtl8168f_2_hw_phy_config(tp); |
| 3987 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3988 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3989 | case RTL_GIGA_MAC_VER_37: |
| 3990 | rtl8402_hw_phy_config(tp); |
| 3991 | break; |
| 3992 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3993 | case RTL_GIGA_MAC_VER_38: |
| 3994 | rtl8411_hw_phy_config(tp); |
| 3995 | break; |
| 3996 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3997 | case RTL_GIGA_MAC_VER_39: |
| 3998 | rtl8106e_hw_phy_config(tp); |
| 3999 | break; |
| 4000 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4001 | case RTL_GIGA_MAC_VER_40: |
| 4002 | rtl8168g_1_hw_phy_config(tp); |
| 4003 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4004 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4005 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4006 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4007 | rtl8168g_2_hw_phy_config(tp); |
| 4008 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4009 | case RTL_GIGA_MAC_VER_45: |
| 4010 | case RTL_GIGA_MAC_VER_47: |
| 4011 | rtl8168h_1_hw_phy_config(tp); |
| 4012 | break; |
| 4013 | case RTL_GIGA_MAC_VER_46: |
| 4014 | case RTL_GIGA_MAC_VER_48: |
| 4015 | rtl8168h_2_hw_phy_config(tp); |
| 4016 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4017 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4018 | case RTL_GIGA_MAC_VER_49: |
| 4019 | rtl8168ep_1_hw_phy_config(tp); |
| 4020 | break; |
| 4021 | case RTL_GIGA_MAC_VER_50: |
| 4022 | case RTL_GIGA_MAC_VER_51: |
| 4023 | rtl8168ep_2_hw_phy_config(tp); |
| 4024 | break; |
| 4025 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4026 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4027 | default: |
| 4028 | break; |
| 4029 | } |
| 4030 | } |
| 4031 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4032 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4033 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4034 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4035 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4038 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4039 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4040 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4041 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4042 | } |
| 4043 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4044 | 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] | 4045 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4046 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4047 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4048 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4049 | netif_dbg(tp, drv, dev, |
| 4050 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4051 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4052 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4053 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4054 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4055 | |
| 4056 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4057 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4058 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4059 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4060 | netif_dbg(tp, drv, dev, |
| 4061 | "Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4062 | RTL_W8(tp, 0x82, 0x01); |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4063 | netif_dbg(tp, drv, dev, |
| 4064 | "Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4065 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4066 | } |
| 4067 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4068 | /* We may have called phy_speed_down before */ |
| 4069 | phy_speed_up(dev->phydev); |
| 4070 | |
Heiner Kallweit | f75222b | 2018-07-17 22:51:41 +0200 | [diff] [blame] | 4071 | genphy_soft_reset(dev->phydev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4072 | } |
| 4073 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4074 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4075 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4076 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4077 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4078 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4079 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4080 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4081 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4082 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4083 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4084 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4085 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4086 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4087 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4088 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4089 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4090 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4091 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4095 | { |
| 4096 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4097 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4098 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4099 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4100 | ret = eth_mac_addr(dev, p); |
| 4101 | if (ret) |
| 4102 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4103 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4104 | pm_runtime_get_noresume(d); |
| 4105 | |
| 4106 | if (pm_runtime_active(d)) |
| 4107 | rtl_rar_set(tp, dev->dev_addr); |
| 4108 | |
| 4109 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4110 | |
| 4111 | return 0; |
| 4112 | } |
| 4113 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4114 | 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] | 4115 | { |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4116 | if (!netif_running(dev)) |
| 4117 | return -ENODEV; |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 4118 | |
Heiner Kallweit | 69b3c59 | 2018-07-17 22:51:53 +0200 | [diff] [blame] | 4119 | return phy_mii_ioctl(dev->phydev, ifr, cmd); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4120 | } |
| 4121 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4122 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4123 | { |
| 4124 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4125 | |
| 4126 | switch (tp->mac_version) { |
| 4127 | case RTL_GIGA_MAC_VER_27: |
| 4128 | ops->write = r8168dp_1_mdio_write; |
| 4129 | ops->read = r8168dp_1_mdio_read; |
| 4130 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4131 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4132 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4133 | ops->write = r8168dp_2_mdio_write; |
| 4134 | ops->read = r8168dp_2_mdio_read; |
| 4135 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4136 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4137 | ops->write = r8168g_mdio_write; |
| 4138 | ops->read = r8168g_mdio_read; |
| 4139 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4140 | default: |
| 4141 | ops->write = r8169_mdio_write; |
| 4142 | ops->read = r8169_mdio_read; |
| 4143 | break; |
| 4144 | } |
| 4145 | } |
| 4146 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4147 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4148 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4149 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4150 | case RTL_GIGA_MAC_VER_25: |
| 4151 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4152 | case RTL_GIGA_MAC_VER_29: |
| 4153 | case RTL_GIGA_MAC_VER_30: |
| 4154 | case RTL_GIGA_MAC_VER_32: |
| 4155 | case RTL_GIGA_MAC_VER_33: |
| 4156 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4157 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4158 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4159 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4160 | break; |
| 4161 | default: |
| 4162 | break; |
| 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4167 | { |
Heiner Kallweit | 6fcf9b1 | 2018-07-04 21:11:29 +0200 | [diff] [blame] | 4168 | if (!netif_running(tp->dev) || !__rtl8169_get_wol(tp)) |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4169 | return false; |
| 4170 | |
Heiner Kallweit | 5b7ad4b | 2018-07-17 22:51:57 +0200 | [diff] [blame] | 4171 | phy_speed_down(tp->dev->phydev, false); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4172 | rtl_wol_suspend_quirk(tp); |
| 4173 | |
| 4174 | return true; |
| 4175 | } |
| 4176 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4177 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4178 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4179 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4180 | return; |
| 4181 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4182 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4183 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4184 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4185 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4186 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4187 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4188 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4189 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4190 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4191 | case RTL_GIGA_MAC_VER_37: |
| 4192 | case RTL_GIGA_MAC_VER_39: |
| 4193 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4194 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4195 | case RTL_GIGA_MAC_VER_45: |
| 4196 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4197 | case RTL_GIGA_MAC_VER_47: |
| 4198 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4199 | case RTL_GIGA_MAC_VER_50: |
| 4200 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4201 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4202 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4203 | case RTL_GIGA_MAC_VER_40: |
| 4204 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4205 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4206 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4207 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4208 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4209 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4214 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4215 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4216 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4217 | case RTL_GIGA_MAC_VER_37: |
| 4218 | case RTL_GIGA_MAC_VER_39: |
| 4219 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4220 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4221 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4222 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4223 | case RTL_GIGA_MAC_VER_45: |
| 4224 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4225 | case RTL_GIGA_MAC_VER_47: |
| 4226 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4227 | case RTL_GIGA_MAC_VER_50: |
| 4228 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4229 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4230 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4231 | case RTL_GIGA_MAC_VER_40: |
| 4232 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4233 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4234 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4235 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4236 | 0x00000000, ERIAR_EXGMAC); |
| 4237 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4238 | } |
| 4239 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 4240 | phy_resume(tp->dev->phydev); |
| 4241 | /* give MAC/PHY some time to resume */ |
| 4242 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4245 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4246 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4247 | switch (tp->mac_version) { |
| 4248 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4249 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4250 | break; |
| 4251 | default: |
| 4252 | r8168_pll_power_down(tp); |
| 4253 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4257 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4258 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4259 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4260 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4261 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4262 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4263 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4267 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4268 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4269 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4270 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4271 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4272 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4273 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4274 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4275 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 4276 | case RTL_GIGA_MAC_VER_35: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4277 | 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] | 4278 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4279 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4280 | 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] | 4281 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4282 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4283 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4284 | break; |
| 4285 | } |
| 4286 | } |
| 4287 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4288 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4289 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4290 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4291 | } |
| 4292 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4293 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4294 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4295 | if (tp->jumbo_ops.enable) { |
| 4296 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4297 | tp->jumbo_ops.enable(tp); |
| 4298 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4299 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4303 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4304 | if (tp->jumbo_ops.disable) { |
| 4305 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4306 | tp->jumbo_ops.disable(tp); |
| 4307 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4308 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4312 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4313 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4314 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4315 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4319 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4320 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4321 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4322 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4326 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4327 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4331 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4332 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4336 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4337 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4338 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4339 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4340 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4344 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4345 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4346 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4347 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4348 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4352 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4353 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4354 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4358 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4359 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4360 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4364 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4365 | r8168b_0_hw_jumbo_enable(tp); |
| 4366 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4367 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4371 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4372 | r8168b_0_hw_jumbo_disable(tp); |
| 4373 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4374 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4375 | } |
| 4376 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4377 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4378 | { |
| 4379 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4380 | |
| 4381 | switch (tp->mac_version) { |
| 4382 | case RTL_GIGA_MAC_VER_11: |
| 4383 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4384 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4385 | break; |
| 4386 | case RTL_GIGA_MAC_VER_12: |
| 4387 | case RTL_GIGA_MAC_VER_17: |
| 4388 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4389 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4390 | break; |
| 4391 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4392 | case RTL_GIGA_MAC_VER_19: |
| 4393 | case RTL_GIGA_MAC_VER_20: |
| 4394 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4395 | case RTL_GIGA_MAC_VER_22: |
| 4396 | case RTL_GIGA_MAC_VER_23: |
| 4397 | case RTL_GIGA_MAC_VER_24: |
| 4398 | case RTL_GIGA_MAC_VER_25: |
| 4399 | case RTL_GIGA_MAC_VER_26: |
| 4400 | ops->disable = r8168c_hw_jumbo_disable; |
| 4401 | ops->enable = r8168c_hw_jumbo_enable; |
| 4402 | break; |
| 4403 | case RTL_GIGA_MAC_VER_27: |
| 4404 | case RTL_GIGA_MAC_VER_28: |
| 4405 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4406 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4407 | break; |
| 4408 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4409 | case RTL_GIGA_MAC_VER_32: |
| 4410 | case RTL_GIGA_MAC_VER_33: |
| 4411 | case RTL_GIGA_MAC_VER_34: |
| 4412 | ops->disable = r8168e_hw_jumbo_disable; |
| 4413 | ops->enable = r8168e_hw_jumbo_enable; |
| 4414 | break; |
| 4415 | |
| 4416 | /* |
| 4417 | * No action needed for jumbo frames with 8169. |
| 4418 | * No jumbo for 810x at all. |
| 4419 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4420 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4421 | default: |
| 4422 | ops->disable = NULL; |
| 4423 | ops->enable = NULL; |
| 4424 | break; |
| 4425 | } |
| 4426 | } |
| 4427 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4428 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4429 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4430 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4431 | } |
| 4432 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4433 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4434 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4435 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4436 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4437 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4438 | } |
| 4439 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4440 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4441 | { |
| 4442 | struct rtl_fw *rtl_fw; |
| 4443 | const char *name; |
| 4444 | int rc = -ENOMEM; |
| 4445 | |
| 4446 | name = rtl_lookup_firmware_name(tp); |
| 4447 | if (!name) |
| 4448 | goto out_no_firmware; |
| 4449 | |
| 4450 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4451 | if (!rtl_fw) |
| 4452 | goto err_warn; |
| 4453 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4454 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4455 | if (rc < 0) |
| 4456 | goto err_free; |
| 4457 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4458 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4459 | if (rc < 0) |
| 4460 | goto err_release_firmware; |
| 4461 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4462 | tp->rtl_fw = rtl_fw; |
| 4463 | out: |
| 4464 | return; |
| 4465 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4466 | err_release_firmware: |
| 4467 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4468 | err_free: |
| 4469 | kfree(rtl_fw); |
| 4470 | err_warn: |
| 4471 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4472 | name, rc); |
| 4473 | out_no_firmware: |
| 4474 | tp->rtl_fw = NULL; |
| 4475 | goto out; |
| 4476 | } |
| 4477 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4478 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4479 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4480 | if (IS_ERR(tp->rtl_fw)) |
| 4481 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4482 | } |
| 4483 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4484 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4485 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4486 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4487 | } |
| 4488 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4489 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4490 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4491 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4495 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4496 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4497 | } |
| 4498 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4499 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | { |
| 4501 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4502 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4504 | rtl_rx_close(tp); |
| 4505 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4506 | switch (tp->mac_version) { |
| 4507 | case RTL_GIGA_MAC_VER_27: |
| 4508 | case RTL_GIGA_MAC_VER_28: |
| 4509 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4510 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4511 | break; |
| 4512 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 4513 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4514 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4515 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4516 | break; |
| 4517 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4518 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4519 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 4520 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4521 | } |
| 4522 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4523 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4526 | static void rtl_set_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4527 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4528 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4529 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4530 | (InterFrameGap << TxInterFrameGapShift)); |
| 4531 | } |
| 4532 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4533 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 4535 | /* Low hurts. Let's disable the filtering. */ |
| 4536 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4537 | } |
| 4538 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4539 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4540 | { |
| 4541 | /* |
| 4542 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4543 | * register to be written before TxDescAddrLow to work. |
| 4544 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4545 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4546 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 4547 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 4548 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 4549 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4550 | } |
| 4551 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4552 | 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] | 4553 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4554 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4555 | u32 mac_version; |
| 4556 | u32 clk; |
| 4557 | u32 val; |
| 4558 | } cfg2_info [] = { |
| 4559 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4560 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4561 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4562 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4563 | }; |
| 4564 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4565 | unsigned int i; |
| 4566 | u32 clk; |
| 4567 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4568 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4569 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4570 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4571 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4572 | break; |
| 4573 | } |
| 4574 | } |
| 4575 | } |
| 4576 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4577 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4578 | { |
| 4579 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4580 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4581 | int rx_mode; |
| 4582 | u32 tmp = 0; |
| 4583 | |
| 4584 | if (dev->flags & IFF_PROMISC) { |
| 4585 | /* Unconditionally log net taps. */ |
| 4586 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4587 | rx_mode = |
| 4588 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4589 | AcceptAllPhys; |
| 4590 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4591 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4592 | (dev->flags & IFF_ALLMULTI)) { |
| 4593 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4594 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4595 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4596 | } else { |
| 4597 | struct netdev_hw_addr *ha; |
| 4598 | |
| 4599 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4600 | mc_filter[1] = mc_filter[0] = 0; |
| 4601 | netdev_for_each_mc_addr(ha, dev) { |
| 4602 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4603 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4604 | rx_mode |= AcceptMulticast; |
| 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | if (dev->features & NETIF_F_RXALL) |
| 4609 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4610 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4611 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4612 | |
| 4613 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4614 | u32 data = mc_filter[0]; |
| 4615 | |
| 4616 | mc_filter[0] = swab32(mc_filter[1]); |
| 4617 | mc_filter[1] = swab32(data); |
| 4618 | } |
| 4619 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 4620 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 4621 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4622 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4623 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 4624 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4625 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4626 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4627 | } |
| 4628 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4629 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 4630 | { |
| 4631 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4632 | |
| 4633 | tp->hw_start(tp); |
| 4634 | |
| 4635 | rtl_set_rx_max_size(tp); |
| 4636 | rtl_set_rx_tx_desc_registers(tp); |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4637 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4638 | |
| 4639 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4640 | RTL_R8(tp, IntrMask); |
| 4641 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4642 | rtl_init_rxcfg(tp); |
Maciej S. Szmigiero | f74dd48 | 2018-09-07 20:15:22 +0200 | [diff] [blame] | 4643 | rtl_set_tx_config_registers(tp); |
Azat Khuzhin | 05212ba | 2018-08-26 17:03:09 +0300 | [diff] [blame] | 4644 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 4645 | rtl_set_rx_mode(tp->dev); |
| 4646 | /* no early-rx interrupts */ |
| 4647 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
| 4648 | rtl_irq_enable_all(tp); |
| 4649 | } |
| 4650 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4651 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4652 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4653 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 4654 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4655 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4656 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4658 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4659 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4660 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4661 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 4662 | netif_dbg(tp, drv, tp->dev, |
| 4663 | "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] | 4664 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4667 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4668 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4669 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | /* |
| 4672 | * Undocumented corner. Supposedly: |
| 4673 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4674 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4675 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4677 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4680 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4681 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4682 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4683 | } |
| 4684 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4685 | 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] | 4686 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4687 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4688 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4689 | RTL_W32(tp, CSIDR, value); |
| 4690 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4691 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4692 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4693 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4694 | } |
| 4695 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4696 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4697 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4698 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 4699 | |
| 4700 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 4701 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4702 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4703 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4704 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4705 | } |
| 4706 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4707 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4708 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4709 | struct pci_dev *pdev = tp->pci_dev; |
| 4710 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4711 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4712 | /* According to Realtek the value at config space address 0x070f |
| 4713 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 4714 | * first and if it fails fall back to CSI. |
| 4715 | */ |
| 4716 | if (pdev->cfg_size > 0x070f && |
| 4717 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 4718 | return; |
| 4719 | |
| 4720 | netdev_notice_once(tp->dev, |
| 4721 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 4722 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4723 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4724 | } |
| 4725 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4726 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4727 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 4728 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | struct ephy_info { |
| 4732 | unsigned int offset; |
| 4733 | u16 mask; |
| 4734 | u16 bits; |
| 4735 | }; |
| 4736 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4737 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 4738 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4739 | { |
| 4740 | u16 w; |
| 4741 | |
| 4742 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4743 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4744 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4745 | e++; |
| 4746 | } |
| 4747 | } |
| 4748 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4749 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4750 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4751 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4752 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4753 | } |
| 4754 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4755 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4756 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4757 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 4758 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4761 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 4762 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4763 | u8 data; |
| 4764 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4765 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4766 | |
| 4767 | if (enable) |
| 4768 | data |= Rdy_to_L23; |
| 4769 | else |
| 4770 | data &= ~Rdy_to_L23; |
| 4771 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4772 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 4773 | } |
| 4774 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4775 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 4776 | { |
| 4777 | if (enable) { |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4778 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame^] | 4779 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4780 | } else { |
| 4781 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 4782 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 4783 | } |
Kai-Heng Feng | 9423546 | 2018-09-12 14:58:20 +0800 | [diff] [blame^] | 4784 | |
| 4785 | udelay(10); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 4786 | } |
| 4787 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4788 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4789 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4790 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4791 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4792 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4793 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4794 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4795 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4796 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4797 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4798 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4799 | } |
| 4800 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4801 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4802 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4803 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4804 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4805 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
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, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4808 | } |
| 4809 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4810 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4811 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4812 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4813 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4814 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4815 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4816 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4817 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4818 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4819 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4820 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4821 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4822 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4823 | } |
| 4824 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4825 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4826 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4827 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4828 | { 0x01, 0, 0x0001 }, |
| 4829 | { 0x02, 0x0800, 0x1000 }, |
| 4830 | { 0x03, 0, 0x0042 }, |
| 4831 | { 0x06, 0x0080, 0x0000 }, |
| 4832 | { 0x07, 0, 0x2000 } |
| 4833 | }; |
| 4834 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4835 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4836 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4837 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4838 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4839 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4840 | } |
| 4841 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4842 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4843 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4844 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4845 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4846 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4847 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4848 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4849 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4850 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4851 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4852 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4853 | } |
| 4854 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4855 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4856 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4857 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4858 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4859 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4860 | |
| 4861 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4862 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4863 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4864 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4865 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4866 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4867 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4868 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4869 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4870 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4871 | } |
| 4872 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4873 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4874 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4875 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4876 | { 0x02, 0x0800, 0x1000 }, |
| 4877 | { 0x03, 0, 0x0002 }, |
| 4878 | { 0x06, 0x0080, 0x0000 } |
| 4879 | }; |
| 4880 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4881 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4882 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4883 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4884 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4885 | 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] | 4886 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4887 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4888 | } |
| 4889 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4890 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4891 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4892 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4893 | { 0x01, 0, 0x0001 }, |
| 4894 | { 0x03, 0x0400, 0x0220 } |
| 4895 | }; |
| 4896 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4897 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4898 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4899 | 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] | 4900 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4901 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4902 | } |
| 4903 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4904 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4905 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4906 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4907 | } |
| 4908 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4909 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +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 | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4912 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4913 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4914 | } |
| 4915 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4916 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4917 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4918 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4919 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4920 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4921 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4922 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4923 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4924 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4925 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4926 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 4927 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 4928 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4929 | } |
| 4930 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4931 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4932 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4933 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4934 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4935 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4936 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4937 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4938 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4939 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4940 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4941 | } |
| 4942 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4943 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4944 | { |
| 4945 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4946 | { 0x0b, 0x0000, 0x0048 }, |
| 4947 | { 0x19, 0x0020, 0x0050 }, |
| 4948 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4949 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4950 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4951 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4952 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4953 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4954 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4955 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4956 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 4957 | 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] | 4958 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4959 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4960 | } |
| 4961 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4962 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4963 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4964 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4965 | { 0x00, 0x0200, 0x0100 }, |
| 4966 | { 0x00, 0x0000, 0x0004 }, |
| 4967 | { 0x06, 0x0002, 0x0001 }, |
| 4968 | { 0x06, 0x0000, 0x0030 }, |
| 4969 | { 0x07, 0x0000, 0x2000 }, |
| 4970 | { 0x00, 0x0000, 0x0020 }, |
| 4971 | { 0x03, 0x5800, 0x2000 }, |
| 4972 | { 0x03, 0x0000, 0x0001 }, |
| 4973 | { 0x01, 0x0800, 0x1000 }, |
| 4974 | { 0x07, 0x0000, 0x4000 }, |
| 4975 | { 0x1e, 0x0000, 0x2000 }, |
| 4976 | { 0x19, 0xffff, 0xfe6c }, |
| 4977 | { 0x0a, 0x0000, 0x0040 } |
| 4978 | }; |
| 4979 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 4980 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4981 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4982 | 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] | 4983 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 4984 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4985 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4986 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4987 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4988 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 4989 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4990 | |
| 4991 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4992 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 4993 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4994 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4995 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4998 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4999 | { |
| 5000 | static const struct ephy_info e_info_8168e_2[] = { |
| 5001 | { 0x09, 0x0000, 0x0080 }, |
| 5002 | { 0x19, 0x0000, 0x0224 } |
| 5003 | }; |
| 5004 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5005 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5006 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5007 | 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] | 5008 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5009 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5010 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5011 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5012 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5013 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5014 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5015 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5016 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5017 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5018 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5019 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5020 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5021 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5022 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5023 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5024 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5025 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5026 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5027 | |
| 5028 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5029 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5030 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5031 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5032 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5033 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 5034 | |
| 5035 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5036 | } |
| 5037 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5038 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5039 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5040 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5041 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5042 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5043 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5044 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5045 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5046 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5047 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5048 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5049 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5050 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5051 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5052 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5053 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5054 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5055 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5056 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5057 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5058 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5059 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5060 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5061 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5062 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5063 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5064 | } |
| 5065 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5066 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5067 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5068 | static const struct ephy_info e_info_8168f_1[] = { |
| 5069 | { 0x06, 0x00c0, 0x0020 }, |
| 5070 | { 0x08, 0x0001, 0x0002 }, |
| 5071 | { 0x09, 0x0000, 0x0080 }, |
| 5072 | { 0x19, 0x0000, 0x0224 } |
| 5073 | }; |
| 5074 | |
| 5075 | rtl_hw_start_8168f(tp); |
| 5076 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5077 | 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] | 5078 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5079 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5080 | |
| 5081 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5082 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5083 | } |
| 5084 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5085 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5086 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5087 | static const struct ephy_info e_info_8168f_1[] = { |
| 5088 | { 0x06, 0x00c0, 0x0020 }, |
| 5089 | { 0x0f, 0xffff, 0x5200 }, |
| 5090 | { 0x1e, 0x0000, 0x4000 }, |
| 5091 | { 0x19, 0x0000, 0x0224 } |
| 5092 | }; |
| 5093 | |
| 5094 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5095 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5096 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5097 | 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] | 5098 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5099 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5100 | } |
| 5101 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5102 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5103 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5104 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5105 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5106 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5107 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5108 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5109 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5110 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5111 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5112 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5113 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5114 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5115 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5116 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5117 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5118 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5119 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5120 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5121 | |
| 5122 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5123 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5124 | |
| 5125 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5126 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5127 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5128 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5129 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5130 | |
| 5131 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5132 | } |
| 5133 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5134 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5135 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5136 | static const struct ephy_info e_info_8168g_1[] = { |
| 5137 | { 0x00, 0x0000, 0x0008 }, |
| 5138 | { 0x0c, 0x37d0, 0x0820 }, |
| 5139 | { 0x1e, 0x0000, 0x0001 }, |
| 5140 | { 0x19, 0x8000, 0x0000 } |
| 5141 | }; |
| 5142 | |
| 5143 | rtl_hw_start_8168g(tp); |
| 5144 | |
| 5145 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5146 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5147 | 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] | 5148 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5149 | } |
| 5150 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5151 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5152 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5153 | static const struct ephy_info e_info_8168g_2[] = { |
| 5154 | { 0x00, 0x0000, 0x0008 }, |
| 5155 | { 0x0c, 0x3df0, 0x0200 }, |
| 5156 | { 0x19, 0xffff, 0xfc00 }, |
| 5157 | { 0x1e, 0xffff, 0x20eb } |
| 5158 | }; |
| 5159 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5160 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5161 | |
| 5162 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5163 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5164 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5165 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5166 | } |
| 5167 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5168 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5169 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5170 | static const struct ephy_info e_info_8411_2[] = { |
| 5171 | { 0x00, 0x0000, 0x0008 }, |
| 5172 | { 0x0c, 0x3df0, 0x0200 }, |
| 5173 | { 0x0f, 0xffff, 0x5200 }, |
| 5174 | { 0x19, 0x0020, 0x0000 }, |
| 5175 | { 0x1e, 0x0000, 0x2000 } |
| 5176 | }; |
| 5177 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5178 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5179 | |
| 5180 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5181 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5182 | 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] | 5183 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5184 | } |
| 5185 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5186 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5187 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5188 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5189 | u32 data; |
| 5190 | static const struct ephy_info e_info_8168h_1[] = { |
| 5191 | { 0x1e, 0x0800, 0x0001 }, |
| 5192 | { 0x1d, 0x0000, 0x0800 }, |
| 5193 | { 0x05, 0xffff, 0x2089 }, |
| 5194 | { 0x06, 0xffff, 0x5881 }, |
| 5195 | { 0x04, 0xffff, 0x154a }, |
| 5196 | { 0x01, 0xffff, 0x068b } |
| 5197 | }; |
| 5198 | |
| 5199 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5200 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5201 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5202 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5203 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5204 | |
| 5205 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5206 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5207 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5208 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5209 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5210 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5211 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5212 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5213 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5214 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5215 | 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] | 5216 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5217 | 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] | 5218 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5219 | 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] | 5220 | |
| 5221 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5222 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5223 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5224 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5225 | |
| 5226 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5227 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5228 | |
| 5229 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5230 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5231 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5232 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5233 | 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] | 5234 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5235 | 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] | 5236 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5237 | 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] | 5238 | |
| 5239 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5240 | |
| 5241 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5242 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5243 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5244 | if (rg_saw_cnt > 0) { |
| 5245 | u16 sw_cnt_1ms_ini; |
| 5246 | |
| 5247 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5248 | sw_cnt_1ms_ini &= 0x0fff; |
| 5249 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5250 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5251 | data |= sw_cnt_1ms_ini; |
| 5252 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5253 | } |
| 5254 | |
| 5255 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5256 | data &= ~0xf0; |
| 5257 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5258 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5259 | |
| 5260 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5261 | data &= ~0x6000; |
| 5262 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5263 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5264 | |
| 5265 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5266 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5267 | data |= 0x017f; |
| 5268 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5269 | |
| 5270 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5271 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5272 | data |= 0x047f; |
| 5273 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5274 | |
| 5275 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5276 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5277 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5278 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5279 | |
| 5280 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5281 | } |
| 5282 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5283 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5284 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5285 | rtl8168ep_stop_cmac(tp); |
| 5286 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5287 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5288 | |
| 5289 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5290 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5291 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5292 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5293 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5294 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5295 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5296 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5297 | |
| 5298 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5299 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5300 | |
| 5301 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5302 | |
| 5303 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5304 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5305 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5306 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5307 | |
| 5308 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5309 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5310 | |
| 5311 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5312 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5313 | |
| 5314 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5315 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5316 | 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] | 5317 | |
| 5318 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5319 | } |
| 5320 | |
| 5321 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5322 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5323 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5324 | { 0x00, 0xffff, 0x10ab }, |
| 5325 | { 0x06, 0xffff, 0xf030 }, |
| 5326 | { 0x08, 0xffff, 0x2006 }, |
| 5327 | { 0x0d, 0xffff, 0x1666 }, |
| 5328 | { 0x0c, 0x3ff0, 0x0000 } |
| 5329 | }; |
| 5330 | |
| 5331 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5332 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5333 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5334 | |
| 5335 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5336 | |
| 5337 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5341 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5342 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5343 | { 0x00, 0xffff, 0x10a3 }, |
| 5344 | { 0x19, 0xffff, 0xfc00 }, |
| 5345 | { 0x1e, 0xffff, 0x20ea } |
| 5346 | }; |
| 5347 | |
| 5348 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5349 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5350 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5351 | |
| 5352 | rtl_hw_start_8168ep(tp); |
| 5353 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5354 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5355 | 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] | 5356 | |
| 5357 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5361 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5362 | u32 data; |
| 5363 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5364 | { 0x00, 0xffff, 0x10a3 }, |
| 5365 | { 0x19, 0xffff, 0x7c00 }, |
| 5366 | { 0x1e, 0xffff, 0x20eb }, |
| 5367 | { 0x0d, 0xffff, 0x1666 } |
| 5368 | }; |
| 5369 | |
| 5370 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5371 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5372 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5373 | |
| 5374 | rtl_hw_start_8168ep(tp); |
| 5375 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5376 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5377 | 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] | 5378 | |
| 5379 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5380 | data &= 0xf000; |
| 5381 | data |= 0x0271; |
| 5382 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5383 | |
| 5384 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5385 | data &= 0xff00; |
| 5386 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5387 | |
| 5388 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5389 | data |= 0x0080; |
| 5390 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5391 | |
| 5392 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5393 | } |
| 5394 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5395 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5396 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5397 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5398 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5399 | tp->cp_cmd &= ~INTT_MASK; |
| 5400 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5401 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5402 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5403 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5404 | |
| 5405 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5406 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5407 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5408 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5409 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5410 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5411 | switch (tp->mac_version) { |
| 5412 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5413 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5414 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5415 | |
| 5416 | case RTL_GIGA_MAC_VER_12: |
| 5417 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5418 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5419 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5420 | |
| 5421 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5422 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5423 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5424 | |
| 5425 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5426 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5427 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5428 | |
| 5429 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5430 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5431 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5432 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5433 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5434 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5435 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5436 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5437 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5438 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5439 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5440 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5441 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5442 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5443 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5444 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5445 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5446 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5447 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5448 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5449 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5450 | case RTL_GIGA_MAC_VER_26: |
| 5451 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5452 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5453 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5454 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5455 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5456 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5457 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5458 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5459 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5460 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5461 | break; |
| 5462 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5463 | case RTL_GIGA_MAC_VER_32: |
| 5464 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5465 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5466 | break; |
| 5467 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5468 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5469 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5470 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5471 | case RTL_GIGA_MAC_VER_35: |
| 5472 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5473 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5474 | break; |
| 5475 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5476 | case RTL_GIGA_MAC_VER_38: |
| 5477 | rtl_hw_start_8411(tp); |
| 5478 | break; |
| 5479 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5480 | case RTL_GIGA_MAC_VER_40: |
| 5481 | case RTL_GIGA_MAC_VER_41: |
| 5482 | rtl_hw_start_8168g_1(tp); |
| 5483 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5484 | case RTL_GIGA_MAC_VER_42: |
| 5485 | rtl_hw_start_8168g_2(tp); |
| 5486 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5487 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5488 | case RTL_GIGA_MAC_VER_44: |
| 5489 | rtl_hw_start_8411_2(tp); |
| 5490 | break; |
| 5491 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5492 | case RTL_GIGA_MAC_VER_45: |
| 5493 | case RTL_GIGA_MAC_VER_46: |
| 5494 | rtl_hw_start_8168h_1(tp); |
| 5495 | break; |
| 5496 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5497 | case RTL_GIGA_MAC_VER_49: |
| 5498 | rtl_hw_start_8168ep_1(tp); |
| 5499 | break; |
| 5500 | |
| 5501 | case RTL_GIGA_MAC_VER_50: |
| 5502 | rtl_hw_start_8168ep_2(tp); |
| 5503 | break; |
| 5504 | |
| 5505 | case RTL_GIGA_MAC_VER_51: |
| 5506 | rtl_hw_start_8168ep_3(tp); |
| 5507 | break; |
| 5508 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5509 | default: |
Heiner Kallweit | 49d1751 | 2018-06-28 20:36:15 +0200 | [diff] [blame] | 5510 | netif_err(tp, drv, tp->dev, |
| 5511 | "unknown chipset (mac_version = %d)\n", |
| 5512 | tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5513 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5514 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5517 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5518 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5519 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5520 | { 0x01, 0, 0x6e65 }, |
| 5521 | { 0x02, 0, 0x091f }, |
| 5522 | { 0x03, 0, 0xc2f9 }, |
| 5523 | { 0x06, 0, 0xafb5 }, |
| 5524 | { 0x07, 0, 0x0e00 }, |
| 5525 | { 0x19, 0, 0xec80 }, |
| 5526 | { 0x01, 0, 0x2e65 }, |
| 5527 | { 0x01, 0, 0x6e65 } |
| 5528 | }; |
| 5529 | u8 cfg1; |
| 5530 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5531 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5532 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5533 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5534 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5535 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5536 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5537 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5538 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5539 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5540 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5541 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5542 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5543 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5544 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5545 | 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] | 5546 | } |
| 5547 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5548 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5549 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5550 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5551 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5552 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5553 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5554 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5555 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5556 | } |
| 5557 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5558 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5559 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5560 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5561 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5562 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5563 | } |
| 5564 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5565 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5566 | { |
| 5567 | static const struct ephy_info e_info_8105e_1[] = { |
| 5568 | { 0x07, 0, 0x4000 }, |
| 5569 | { 0x19, 0, 0x0200 }, |
| 5570 | { 0x19, 0, 0x0020 }, |
| 5571 | { 0x1e, 0, 0x2000 }, |
| 5572 | { 0x03, 0, 0x0001 }, |
| 5573 | { 0x19, 0, 0x0100 }, |
| 5574 | { 0x19, 0, 0x0004 }, |
| 5575 | { 0x0a, 0, 0x0020 } |
| 5576 | }; |
| 5577 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5578 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5579 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5580 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5581 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5582 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5583 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5584 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5585 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5586 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5587 | 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] | 5588 | |
| 5589 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5590 | } |
| 5591 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5592 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5593 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5594 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5595 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5596 | } |
| 5597 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5598 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5599 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5600 | static const struct ephy_info e_info_8402[] = { |
| 5601 | { 0x19, 0xffff, 0xff64 }, |
| 5602 | { 0x1e, 0, 0x4000 } |
| 5603 | }; |
| 5604 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5605 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5606 | |
| 5607 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5608 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5609 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5610 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5611 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5612 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5613 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5614 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5615 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5616 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5617 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 5618 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5619 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5620 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5621 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5622 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5623 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5624 | |
| 5625 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5626 | } |
| 5627 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5628 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5629 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5630 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5631 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5632 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5633 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5634 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 5635 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5636 | |
| 5637 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5638 | } |
| 5639 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5640 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5641 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5642 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 5643 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5644 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5645 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5646 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5647 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 5648 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5649 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5650 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5651 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5652 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5653 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5654 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5655 | switch (tp->mac_version) { |
| 5656 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5657 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5658 | break; |
| 5659 | |
| 5660 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5661 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5662 | break; |
| 5663 | |
| 5664 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5665 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5666 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5667 | |
| 5668 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5669 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5670 | break; |
| 5671 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5672 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5673 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5674 | |
| 5675 | case RTL_GIGA_MAC_VER_37: |
| 5676 | rtl_hw_start_8402(tp); |
| 5677 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5678 | |
| 5679 | case RTL_GIGA_MAC_VER_39: |
| 5680 | rtl_hw_start_8106(tp); |
| 5681 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5682 | case RTL_GIGA_MAC_VER_43: |
| 5683 | rtl_hw_start_8168g_2(tp); |
| 5684 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5685 | case RTL_GIGA_MAC_VER_47: |
| 5686 | case RTL_GIGA_MAC_VER_48: |
| 5687 | rtl_hw_start_8168h_1(tp); |
| 5688 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5689 | } |
| 5690 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5691 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5695 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5696 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5697 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5698 | if (new_mtu > ETH_DATA_LEN) |
| 5699 | rtl_hw_jumbo_enable(tp); |
| 5700 | else |
| 5701 | rtl_hw_jumbo_disable(tp); |
| 5702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5704 | netdev_update_features(dev); |
| 5705 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5706 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5710 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5711 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5713 | } |
| 5714 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5715 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5716 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5718 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 5719 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5720 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5721 | kfree(*data_buff); |
| 5722 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | rtl8169_make_unusable_by_asic(desc); |
| 5724 | } |
| 5725 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5726 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | { |
| 5728 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5729 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 5730 | /* Force memory writes to complete before releasing descriptor */ |
| 5731 | dma_wmb(); |
| 5732 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5733 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5734 | } |
| 5735 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5736 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5738 | return (void *)ALIGN((long)data, 16); |
| 5739 | } |
| 5740 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5741 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5742 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5743 | { |
| 5744 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5746 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 5747 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5749 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5750 | if (!data) |
| 5751 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5752 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5753 | if (rtl8169_align(data) != data) { |
| 5754 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5755 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5756 | if (!data) |
| 5757 | return NULL; |
| 5758 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5759 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5760 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 5761 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5762 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5763 | if (net_ratelimit()) |
| 5764 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5765 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 5768 | desc->addr = cpu_to_le64(mapping); |
| 5769 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5770 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5771 | |
| 5772 | err_out: |
| 5773 | kfree(data); |
| 5774 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5778 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5779 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5780 | |
| 5781 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5782 | if (tp->Rx_databuff[i]) { |
| 5783 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | tp->RxDescArray + i); |
| 5785 | } |
| 5786 | } |
| 5787 | } |
| 5788 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5789 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5791 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5792 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5793 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5794 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5795 | { |
| 5796 | unsigned int i; |
| 5797 | |
| 5798 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5799 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5800 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5801 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5802 | if (!data) { |
| 5803 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5804 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5805 | } |
| 5806 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5809 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5810 | return 0; |
| 5811 | |
| 5812 | err_out: |
| 5813 | rtl8169_rx_clear(tp); |
| 5814 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5815 | } |
| 5816 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5817 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | rtl8169_init_ring_indexes(tp); |
| 5820 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 5821 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 5822 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5824 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | } |
| 5826 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5827 | 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] | 5828 | struct TxDesc *desc) |
| 5829 | { |
| 5830 | unsigned int len = tx_skb->len; |
| 5831 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5832 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | desc->opts1 = 0x00; |
| 5835 | desc->opts2 = 0x00; |
| 5836 | desc->addr = 0x00; |
| 5837 | tx_skb->len = 0; |
| 5838 | } |
| 5839 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5840 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5841 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | { |
| 5843 | unsigned int i; |
| 5844 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5845 | for (i = 0; i < n; i++) { |
| 5846 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5847 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5848 | unsigned int len = tx_skb->len; |
| 5849 | |
| 5850 | if (len) { |
| 5851 | struct sk_buff *skb = tx_skb->skb; |
| 5852 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5853 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5854 | tp->TxDescArray + entry); |
| 5855 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 5856 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5857 | tx_skb->skb = NULL; |
| 5858 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | } |
| 5860 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5864 | { |
| 5865 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5866 | tp->cur_tx = tp->dirty_tx = 0; |
| 5867 | } |
| 5868 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5869 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5870 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5871 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5872 | int i; |
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_disable(&tp->napi); |
| 5875 | netif_stop_queue(dev); |
| 5876 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5877 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5878 | rtl8169_hw_reset(tp); |
| 5879 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5880 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5881 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5883 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5884 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5885 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5886 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5887 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5888 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5892 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5893 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5894 | |
| 5895 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
| 5898 | 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] | 5899 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | { |
| 5901 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5902 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5903 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5904 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5905 | |
| 5906 | entry = tp->cur_tx; |
| 5907 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5908 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5909 | dma_addr_t mapping; |
| 5910 | u32 status, len; |
| 5911 | void *addr; |
| 5912 | |
| 5913 | entry = (entry + 1) % NUM_TX_DESC; |
| 5914 | |
| 5915 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5916 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5917 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5918 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5919 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5920 | if (net_ratelimit()) |
| 5921 | netif_err(tp, drv, tp->dev, |
| 5922 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5923 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5926 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5927 | status = opts[0] | len | |
| 5928 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5929 | |
| 5930 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5931 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | txd->addr = cpu_to_le64(mapping); |
| 5933 | |
| 5934 | tp->tx_skb[entry].len = len; |
| 5935 | } |
| 5936 | |
| 5937 | if (cur_frag) { |
| 5938 | tp->tx_skb[entry].skb = skb; |
| 5939 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5940 | } |
| 5941 | |
| 5942 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5943 | |
| 5944 | err_out: |
| 5945 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5946 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 5949 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 5950 | { |
| 5951 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 5952 | } |
| 5953 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5954 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5955 | struct net_device *dev); |
| 5956 | /* r8169_csum_workaround() |
| 5957 | * The hw limites the value the transport offset. When the offset is out of the |
| 5958 | * range, calculate the checksum by sw. |
| 5959 | */ |
| 5960 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 5961 | struct sk_buff *skb) |
| 5962 | { |
| 5963 | if (skb_shinfo(skb)->gso_size) { |
| 5964 | netdev_features_t features = tp->dev->features; |
| 5965 | struct sk_buff *segs, *nskb; |
| 5966 | |
| 5967 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 5968 | segs = skb_gso_segment(skb, features); |
| 5969 | if (IS_ERR(segs) || !segs) |
| 5970 | goto drop; |
| 5971 | |
| 5972 | do { |
| 5973 | nskb = segs; |
| 5974 | segs = segs->next; |
| 5975 | nskb->next = NULL; |
| 5976 | rtl8169_start_xmit(nskb, tp->dev); |
| 5977 | } while (segs); |
| 5978 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5979 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5980 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 5981 | if (skb_checksum_help(skb) < 0) |
| 5982 | goto drop; |
| 5983 | |
| 5984 | rtl8169_start_xmit(skb, tp->dev); |
| 5985 | } else { |
| 5986 | struct net_device_stats *stats; |
| 5987 | |
| 5988 | drop: |
| 5989 | stats = &tp->dev->stats; |
| 5990 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 5991 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | /* msdn_giant_send_check() |
| 5996 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 5997 | * packet length for IPv6 TCP large packets. |
| 5998 | */ |
| 5999 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6000 | { |
| 6001 | const struct ipv6hdr *ipv6h; |
| 6002 | struct tcphdr *th; |
| 6003 | int ret; |
| 6004 | |
| 6005 | ret = skb_cow_head(skb, 0); |
| 6006 | if (ret) |
| 6007 | return ret; |
| 6008 | |
| 6009 | ipv6h = ipv6_hdr(skb); |
| 6010 | th = tcp_hdr(skb); |
| 6011 | |
| 6012 | th->check = 0; |
| 6013 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6014 | |
| 6015 | return ret; |
| 6016 | } |
| 6017 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6018 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6019 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6021 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6022 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6023 | if (mss) { |
| 6024 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6025 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6026 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6027 | const struct iphdr *ip = ip_hdr(skb); |
| 6028 | |
| 6029 | if (ip->protocol == IPPROTO_TCP) |
| 6030 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6031 | else if (ip->protocol == IPPROTO_UDP) |
| 6032 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6033 | else |
| 6034 | WARN_ON_ONCE(1); |
| 6035 | } |
| 6036 | |
| 6037 | return true; |
| 6038 | } |
| 6039 | |
| 6040 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6041 | struct sk_buff *skb, u32 *opts) |
| 6042 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6043 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6044 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6045 | |
| 6046 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6047 | if (transport_offset > GTTCPHO_MAX) { |
| 6048 | netif_warn(tp, tx_err, tp->dev, |
| 6049 | "Invalid transport offset 0x%x for TSO\n", |
| 6050 | transport_offset); |
| 6051 | return false; |
| 6052 | } |
| 6053 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6054 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6055 | case htons(ETH_P_IP): |
| 6056 | opts[0] |= TD1_GTSENV4; |
| 6057 | break; |
| 6058 | |
| 6059 | case htons(ETH_P_IPV6): |
| 6060 | if (msdn_giant_send_check(skb)) |
| 6061 | return false; |
| 6062 | |
| 6063 | opts[0] |= TD1_GTSENV6; |
| 6064 | break; |
| 6065 | |
| 6066 | default: |
| 6067 | WARN_ON_ONCE(1); |
| 6068 | break; |
| 6069 | } |
| 6070 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6071 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6072 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6073 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6074 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6075 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6076 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6077 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6078 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6079 | if (transport_offset > TCPHO_MAX) { |
| 6080 | netif_warn(tp, tx_err, tp->dev, |
| 6081 | "Invalid transport offset 0x%x\n", |
| 6082 | transport_offset); |
| 6083 | return false; |
| 6084 | } |
| 6085 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6086 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6087 | case htons(ETH_P_IP): |
| 6088 | opts[1] |= TD1_IPv4_CS; |
| 6089 | ip_protocol = ip_hdr(skb)->protocol; |
| 6090 | break; |
| 6091 | |
| 6092 | case htons(ETH_P_IPV6): |
| 6093 | opts[1] |= TD1_IPv6_CS; |
| 6094 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6095 | break; |
| 6096 | |
| 6097 | default: |
| 6098 | ip_protocol = IPPROTO_RAW; |
| 6099 | break; |
| 6100 | } |
| 6101 | |
| 6102 | if (ip_protocol == IPPROTO_TCP) |
| 6103 | opts[1] |= TD1_TCP_CS; |
| 6104 | else if (ip_protocol == IPPROTO_UDP) |
| 6105 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6106 | else |
| 6107 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6108 | |
| 6109 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6110 | } else { |
| 6111 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6112 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6113 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6114 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6115 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | } |
| 6117 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6118 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6119 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6120 | { |
| 6121 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6122 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6123 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6124 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6125 | dma_addr_t mapping; |
| 6126 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6127 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6128 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6129 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6130 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6131 | 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] | 6132 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | } |
| 6134 | |
| 6135 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6136 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6138 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6139 | opts[0] = DescOwn; |
| 6140 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6141 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6142 | r8169_csum_workaround(tp, skb); |
| 6143 | return NETDEV_TX_OK; |
| 6144 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6145 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6146 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6147 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6148 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6149 | if (net_ratelimit()) |
| 6150 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6151 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6153 | |
| 6154 | tp->tx_skb[entry].len = len; |
| 6155 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6157 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6158 | if (frags < 0) |
| 6159 | goto err_dma_1; |
| 6160 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6161 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6162 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6163 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6164 | tp->tx_skb[entry].skb = skb; |
| 6165 | } |
| 6166 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6167 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6168 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6169 | skb_tx_timestamp(skb); |
| 6170 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6171 | /* Force memory writes to complete before releasing descriptor */ |
| 6172 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6173 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6174 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6175 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6176 | txd->opts1 = cpu_to_le32(status); |
| 6177 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6178 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6179 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6180 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6181 | tp->cur_tx += frags + 1; |
| 6182 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6183 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6185 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6186 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6187 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6188 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6189 | * not miss a ring update when it notices a stopped queue. |
| 6190 | */ |
| 6191 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6193 | /* Sync with rtl_tx: |
| 6194 | * - publish queue status and cur_tx ring index (write barrier) |
| 6195 | * - refresh dirty_tx ring index (read barrier). |
| 6196 | * May the current thread have a pessimistic view of the ring |
| 6197 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6198 | * can't. |
| 6199 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6200 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6201 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6202 | netif_wake_queue(dev); |
| 6203 | } |
| 6204 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6205 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6206 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6207 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6208 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6209 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6210 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6211 | dev->stats.tx_dropped++; |
| 6212 | return NETDEV_TX_OK; |
| 6213 | |
| 6214 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6216 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6217 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6221 | { |
| 6222 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6223 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6224 | u16 pci_status, pci_cmd; |
| 6225 | |
| 6226 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6227 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6228 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6229 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6230 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6231 | |
| 6232 | /* |
| 6233 | * The recovery sequence below admits a very elaborated explanation: |
| 6234 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6235 | * - I did not see what else could be done; |
| 6236 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | * |
| 6238 | * Feel free to adjust to your needs. |
| 6239 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6240 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6241 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6242 | else |
| 6243 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6244 | |
| 6245 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | |
| 6247 | pci_write_config_word(pdev, PCI_STATUS, |
| 6248 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6249 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6250 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6251 | |
| 6252 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6253 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6254 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6256 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6257 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6258 | } |
| 6259 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6260 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6261 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6262 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6265 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | { |
| 6267 | unsigned int dirty_tx, tx_left; |
| 6268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | dirty_tx = tp->dirty_tx; |
| 6270 | smp_rmb(); |
| 6271 | tx_left = tp->cur_tx - dirty_tx; |
| 6272 | |
| 6273 | while (tx_left > 0) { |
| 6274 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6275 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6276 | u32 status; |
| 6277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6279 | if (status & DescOwn) |
| 6280 | break; |
| 6281 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6282 | /* This barrier is needed to keep us from reading |
| 6283 | * any other fields out of the Tx descriptor until |
| 6284 | * we know the status of DescOwn |
| 6285 | */ |
| 6286 | dma_rmb(); |
| 6287 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6288 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6289 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6291 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6292 | tp->tx_stats.packets++; |
| 6293 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 6294 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6295 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | tx_skb->skb = NULL; |
| 6297 | } |
| 6298 | dirty_tx++; |
| 6299 | tx_left--; |
| 6300 | } |
| 6301 | |
| 6302 | if (tp->dirty_tx != dirty_tx) { |
| 6303 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6304 | /* Sync with rtl8169_start_xmit: |
| 6305 | * - publish dirty_tx ring index (write barrier) |
| 6306 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6307 | * May the current thread miss the stopped queue condition, |
| 6308 | * a racing xmit thread can only have a right view of the |
| 6309 | * ring status. |
| 6310 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6311 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6312 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6313 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | netif_wake_queue(dev); |
| 6315 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6316 | /* |
| 6317 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6318 | * too close. Let's kick an extra TxPoll request when a burst |
| 6319 | * of start_xmit activity is detected (if it is not detected, |
| 6320 | * it is slow enough). -- FR |
| 6321 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6322 | if (tp->cur_tx != dirty_tx) |
| 6323 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | } |
| 6325 | } |
| 6326 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6327 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6328 | { |
| 6329 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6330 | } |
| 6331 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6332 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6334 | u32 status = opts1 & RxProtoMask; |
| 6335 | |
| 6336 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6337 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6339 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6340 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | } |
| 6342 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6343 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6344 | struct rtl8169_private *tp, |
| 6345 | int pkt_size, |
| 6346 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6347 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6348 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6349 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6350 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6351 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6352 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6353 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6354 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6355 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6356 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6357 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6358 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6359 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | } |
| 6361 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6362 | 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] | 6363 | { |
| 6364 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6365 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6367 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6368 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6369 | 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] | 6370 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6371 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | u32 status; |
| 6373 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6374 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6375 | if (status & DescOwn) |
| 6376 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6377 | |
| 6378 | /* This barrier is needed to keep us from reading |
| 6379 | * any other fields out of the Rx descriptor until |
| 6380 | * we know the status of DescOwn |
| 6381 | */ |
| 6382 | dma_rmb(); |
| 6383 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6384 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6385 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6386 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6387 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6389 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6391 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6392 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6393 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6394 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6395 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6396 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6397 | } else if (status & (RxRUNT | RxCRC) && |
| 6398 | !(status & RxRWT) && |
| 6399 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6400 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6402 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6403 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6404 | dma_addr_t addr; |
| 6405 | int pkt_size; |
| 6406 | |
| 6407 | process_pkt: |
| 6408 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6409 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6410 | pkt_size = (status & 0x00003fff) - 4; |
| 6411 | else |
| 6412 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6414 | /* |
| 6415 | * The driver does not support incoming fragmented |
| 6416 | * frames. They are seen as a symptom of over-mtu |
| 6417 | * sized frames. |
| 6418 | */ |
| 6419 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6420 | dev->stats.rx_dropped++; |
| 6421 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6422 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6423 | } |
| 6424 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6425 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6426 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6427 | if (!skb) { |
| 6428 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6429 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6430 | } |
| 6431 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6432 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6433 | skb_put(skb, pkt_size); |
| 6434 | skb->protocol = eth_type_trans(skb, dev); |
| 6435 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6436 | rtl8169_rx_vlan_tag(desc, skb); |
| 6437 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6438 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6439 | dev->stats.multicast++; |
| 6440 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6441 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6442 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6443 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6444 | tp->rx_stats.packets++; |
| 6445 | tp->rx_stats.bytes += pkt_size; |
| 6446 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6447 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6448 | release_descriptor: |
| 6449 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6450 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | count = cur_rx - tp->cur_rx; |
| 6454 | tp->cur_rx = cur_rx; |
| 6455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6456 | return count; |
| 6457 | } |
| 6458 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6459 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6460 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6461 | struct rtl8169_private *tp = dev_instance; |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6462 | u16 status = rtl_get_events(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6463 | |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6464 | if (status == 0xffff || !(status & (RTL_EVENT_NAPI | tp->event_slow))) |
| 6465 | return IRQ_NONE; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6466 | |
Heiner Kallweit | 05bbe55 | 2018-08-10 22:38:29 +0200 | [diff] [blame] | 6467 | rtl_irq_disable(tp); |
| 6468 | napi_schedule_irqoff(&tp->napi); |
| 6469 | |
| 6470 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6473 | /* |
| 6474 | * Workqueue context. |
| 6475 | */ |
| 6476 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6477 | { |
| 6478 | struct net_device *dev = tp->dev; |
| 6479 | u16 status; |
| 6480 | |
| 6481 | status = rtl_get_events(tp) & tp->event_slow; |
| 6482 | rtl_ack_events(tp, status); |
| 6483 | |
| 6484 | if (unlikely(status & RxFIFOOver)) { |
| 6485 | switch (tp->mac_version) { |
| 6486 | /* Work around for rx fifo overflow */ |
| 6487 | case RTL_GIGA_MAC_VER_11: |
| 6488 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6489 | /* XXX - Hack alert. See rtl_task(). */ |
| 6490 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6491 | default: |
| 6492 | break; |
| 6493 | } |
| 6494 | } |
| 6495 | |
| 6496 | if (unlikely(status & SYSErr)) |
| 6497 | rtl8169_pcierr_interrupt(dev); |
| 6498 | |
| 6499 | if (status & LinkChg) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6500 | phy_mac_interrupt(dev->phydev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6501 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 6502 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6503 | } |
| 6504 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6505 | static void rtl_task(struct work_struct *work) |
| 6506 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6507 | static const struct { |
| 6508 | int bitnr; |
| 6509 | void (*action)(struct rtl8169_private *); |
| 6510 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6511 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6512 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 6513 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6514 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6515 | struct rtl8169_private *tp = |
| 6516 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6517 | struct net_device *dev = tp->dev; |
| 6518 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6519 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6520 | rtl_lock_work(tp); |
| 6521 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6522 | if (!netif_running(dev) || |
| 6523 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6524 | goto out_unlock; |
| 6525 | |
| 6526 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6527 | bool pending; |
| 6528 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6529 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6530 | if (pending) |
| 6531 | rtl_work[i].action(tp); |
| 6532 | } |
| 6533 | |
| 6534 | out_unlock: |
| 6535 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6536 | } |
| 6537 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6538 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6539 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6540 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6541 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6542 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 6543 | int work_done= 0; |
| 6544 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6545 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6546 | status = rtl_get_events(tp); |
| 6547 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 6548 | |
| 6549 | if (status & RTL_EVENT_NAPI_RX) |
| 6550 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 6551 | |
| 6552 | if (status & RTL_EVENT_NAPI_TX) |
| 6553 | rtl_tx(dev, tp); |
| 6554 | |
| 6555 | if (status & tp->event_slow) { |
| 6556 | enable_mask &= ~tp->event_slow; |
| 6557 | |
| 6558 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 6559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6560 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6561 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 6562 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 6563 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6564 | rtl_irq_enable(tp, enable_mask); |
| 6565 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | } |
| 6567 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6568 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6570 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6571 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6572 | { |
| 6573 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6574 | |
| 6575 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6576 | return; |
| 6577 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6578 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 6579 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6580 | } |
| 6581 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6582 | static void r8169_phylink_handler(struct net_device *ndev) |
| 6583 | { |
| 6584 | struct rtl8169_private *tp = netdev_priv(ndev); |
| 6585 | |
| 6586 | if (netif_carrier_ok(ndev)) { |
| 6587 | rtl_link_chg_patch(tp); |
| 6588 | pm_request_resume(&tp->pci_dev->dev); |
| 6589 | } else { |
| 6590 | pm_runtime_idle(&tp->pci_dev->dev); |
| 6591 | } |
| 6592 | |
| 6593 | if (net_ratelimit()) |
| 6594 | phy_print_status(ndev->phydev); |
| 6595 | } |
| 6596 | |
| 6597 | static int r8169_phy_connect(struct rtl8169_private *tp) |
| 6598 | { |
| 6599 | struct phy_device *phydev = mdiobus_get_phy(tp->mii_bus, 0); |
| 6600 | phy_interface_t phy_mode; |
| 6601 | int ret; |
| 6602 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6603 | phy_mode = tp->supports_gmii ? PHY_INTERFACE_MODE_GMII : |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6604 | PHY_INTERFACE_MODE_MII; |
| 6605 | |
| 6606 | ret = phy_connect_direct(tp->dev, phydev, r8169_phylink_handler, |
| 6607 | phy_mode); |
| 6608 | if (ret) |
| 6609 | return ret; |
| 6610 | |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 6611 | if (!tp->supports_gmii) |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6612 | phy_set_max_speed(phydev, SPEED_100); |
| 6613 | |
| 6614 | /* Ensure to advertise everything, incl. pause */ |
| 6615 | phydev->advertising = phydev->supported; |
| 6616 | |
| 6617 | phy_attached_info(phydev); |
| 6618 | |
| 6619 | return 0; |
| 6620 | } |
| 6621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6622 | static void rtl8169_down(struct net_device *dev) |
| 6623 | { |
| 6624 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6626 | phy_stop(dev->phydev); |
| 6627 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6628 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6629 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6630 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6631 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6632 | /* |
| 6633 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6634 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6635 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6636 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6637 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6639 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6640 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6642 | rtl8169_tx_clear(tp); |
| 6643 | |
| 6644 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6645 | |
| 6646 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | static int rtl8169_close(struct net_device *dev) |
| 6650 | { |
| 6651 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6652 | struct pci_dev *pdev = tp->pci_dev; |
| 6653 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6654 | pm_runtime_get_sync(&pdev->dev); |
| 6655 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6656 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6657 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6658 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6659 | rtl_lock_work(tp); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6660 | /* Clear all task flags */ |
| 6661 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6663 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6664 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6665 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 6666 | cancel_work_sync(&tp->wk.work); |
| 6667 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6668 | phy_disconnect(dev->phydev); |
| 6669 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6670 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6671 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6672 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6673 | tp->RxPhyAddr); |
| 6674 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6675 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | tp->TxDescArray = NULL; |
| 6677 | tp->RxDescArray = NULL; |
| 6678 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6679 | pm_runtime_put_sync(&pdev->dev); |
| 6680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6681 | return 0; |
| 6682 | } |
| 6683 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6684 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6685 | static void rtl8169_netpoll(struct net_device *dev) |
| 6686 | { |
| 6687 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6688 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 6689 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6690 | } |
| 6691 | #endif |
| 6692 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6693 | static int rtl_open(struct net_device *dev) |
| 6694 | { |
| 6695 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6696 | struct pci_dev *pdev = tp->pci_dev; |
| 6697 | int retval = -ENOMEM; |
| 6698 | |
| 6699 | pm_runtime_get_sync(&pdev->dev); |
| 6700 | |
| 6701 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6702 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6703 | * dma_alloc_coherent provides more. |
| 6704 | */ |
| 6705 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6706 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6707 | if (!tp->TxDescArray) |
| 6708 | goto err_pm_runtime_put; |
| 6709 | |
| 6710 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6711 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6712 | if (!tp->RxDescArray) |
| 6713 | goto err_free_tx_0; |
| 6714 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6715 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6716 | if (retval < 0) |
| 6717 | goto err_free_rx_1; |
| 6718 | |
| 6719 | INIT_WORK(&tp->wk.work, rtl_task); |
| 6720 | |
| 6721 | smp_mb(); |
| 6722 | |
| 6723 | rtl_request_firmware(tp); |
| 6724 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6725 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 6726 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6727 | if (retval < 0) |
| 6728 | goto err_release_fw_2; |
| 6729 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6730 | retval = r8169_phy_connect(tp); |
| 6731 | if (retval) |
| 6732 | goto err_free_irq; |
| 6733 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6734 | rtl_lock_work(tp); |
| 6735 | |
| 6736 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6737 | |
| 6738 | napi_enable(&tp->napi); |
| 6739 | |
| 6740 | rtl8169_init_phy(dev, tp); |
| 6741 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6742 | rtl_pll_power_up(tp); |
| 6743 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6744 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6745 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6746 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6747 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 6748 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6749 | phy_start(dev->phydev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6750 | netif_start_queue(dev); |
| 6751 | |
| 6752 | rtl_unlock_work(tp); |
| 6753 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6754 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6755 | out: |
| 6756 | return retval; |
| 6757 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6758 | err_free_irq: |
| 6759 | pci_free_irq(pdev, 0, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6760 | err_release_fw_2: |
| 6761 | rtl_release_firmware(tp); |
| 6762 | rtl8169_rx_clear(tp); |
| 6763 | err_free_rx_1: |
| 6764 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6765 | tp->RxPhyAddr); |
| 6766 | tp->RxDescArray = NULL; |
| 6767 | err_free_tx_0: |
| 6768 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6769 | tp->TxPhyAddr); |
| 6770 | tp->TxDescArray = NULL; |
| 6771 | err_pm_runtime_put: |
| 6772 | pm_runtime_put_noidle(&pdev->dev); |
| 6773 | goto out; |
| 6774 | } |
| 6775 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 6776 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6777 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6778 | { |
| 6779 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6780 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6781 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6782 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6784 | pm_runtime_get_noresume(&pdev->dev); |
| 6785 | |
| 6786 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6787 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6788 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6789 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6790 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6791 | stats->rx_packets = tp->rx_stats.packets; |
| 6792 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6793 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6794 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6795 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6796 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6797 | stats->tx_packets = tp->tx_stats.packets; |
| 6798 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 6799 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6800 | |
| 6801 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6802 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6803 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6804 | stats->rx_errors = dev->stats.rx_errors; |
| 6805 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6806 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6807 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 6808 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6809 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6810 | /* |
| 6811 | * Fetch additonal counter values missing in stats collected by driver |
| 6812 | * from tally counters. |
| 6813 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6814 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6815 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6816 | |
| 6817 | /* |
| 6818 | * Subtract values fetched during initalization. |
| 6819 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 6820 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6821 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6822 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6823 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6824 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 6825 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 6826 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 6827 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6828 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6829 | } |
| 6830 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6831 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6832 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6833 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6834 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6835 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6836 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6837 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6838 | phy_stop(dev->phydev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6839 | netif_device_detach(dev); |
| 6840 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6841 | |
| 6842 | rtl_lock_work(tp); |
| 6843 | napi_disable(&tp->napi); |
Kai-Heng Feng | 6ad5690 | 2018-09-11 01:51:43 +0800 | [diff] [blame] | 6844 | /* Clear all task flags */ |
| 6845 | bitmap_zero(tp->wk.flags, RTL_FLAG_MAX); |
| 6846 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6847 | rtl_unlock_work(tp); |
| 6848 | |
| 6849 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6850 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6851 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6852 | #ifdef CONFIG_PM |
| 6853 | |
| 6854 | static int rtl8169_suspend(struct device *device) |
| 6855 | { |
| 6856 | struct pci_dev *pdev = to_pci_dev(device); |
| 6857 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6858 | |
| 6859 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6860 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6861 | return 0; |
| 6862 | } |
| 6863 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6864 | static void __rtl8169_resume(struct net_device *dev) |
| 6865 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6866 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6867 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6868 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6869 | |
| 6870 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 6871 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6872 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 6873 | phy_start(tp->dev->phydev); |
| 6874 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6875 | rtl_lock_work(tp); |
| 6876 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6877 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6878 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6879 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6880 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6883 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6884 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6885 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6886 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6887 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6888 | if (netif_running(dev)) |
| 6889 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6890 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6891 | return 0; |
| 6892 | } |
| 6893 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6894 | static int rtl8169_runtime_suspend(struct device *device) |
| 6895 | { |
| 6896 | struct pci_dev *pdev = to_pci_dev(device); |
| 6897 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6898 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6899 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 6900 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6901 | return 0; |
| 6902 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6903 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6904 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6905 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6906 | |
| 6907 | rtl8169_net_suspend(dev); |
| 6908 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6909 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6910 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 6911 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 6912 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6913 | return 0; |
| 6914 | } |
| 6915 | |
| 6916 | static int rtl8169_runtime_resume(struct device *device) |
| 6917 | { |
| 6918 | struct pci_dev *pdev = to_pci_dev(device); |
| 6919 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6920 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 6921 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6922 | |
| 6923 | if (!tp->TxDescArray) |
| 6924 | return 0; |
| 6925 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6926 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6927 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6928 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6929 | |
| 6930 | __rtl8169_resume(dev); |
| 6931 | |
| 6932 | return 0; |
| 6933 | } |
| 6934 | |
| 6935 | static int rtl8169_runtime_idle(struct device *device) |
| 6936 | { |
| 6937 | struct pci_dev *pdev = to_pci_dev(device); |
| 6938 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6939 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 6940 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 6941 | pm_schedule_suspend(device, 10000); |
| 6942 | |
| 6943 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6944 | } |
| 6945 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6946 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6947 | .suspend = rtl8169_suspend, |
| 6948 | .resume = rtl8169_resume, |
| 6949 | .freeze = rtl8169_suspend, |
| 6950 | .thaw = rtl8169_resume, |
| 6951 | .poweroff = rtl8169_suspend, |
| 6952 | .restore = rtl8169_resume, |
| 6953 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6954 | .runtime_resume = rtl8169_runtime_resume, |
| 6955 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6956 | }; |
| 6957 | |
| 6958 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6959 | |
| 6960 | #else /* !CONFIG_PM */ |
| 6961 | |
| 6962 | #define RTL8169_PM_OPS NULL |
| 6963 | |
| 6964 | #endif /* !CONFIG_PM */ |
| 6965 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6966 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6967 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6968 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6969 | switch (tp->mac_version) { |
| 6970 | case RTL_GIGA_MAC_VER_11: |
| 6971 | case RTL_GIGA_MAC_VER_12: |
| 6972 | case RTL_GIGA_MAC_VER_17: |
| 6973 | pci_clear_master(tp->pci_dev); |
| 6974 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6975 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6976 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6977 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6978 | break; |
| 6979 | default: |
| 6980 | break; |
| 6981 | } |
| 6982 | } |
| 6983 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6984 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6985 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6986 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6987 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6988 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6989 | rtl8169_net_suspend(dev); |
| 6990 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6991 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6992 | rtl_rar_set(tp, dev->perm_addr); |
| 6993 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6994 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6995 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6996 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 6997 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6998 | rtl_wol_suspend_quirk(tp); |
| 6999 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7000 | } |
| 7001 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7002 | pci_wake_from_d3(pdev, true); |
| 7003 | pci_set_power_state(pdev, PCI_D3hot); |
| 7004 | } |
| 7005 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7006 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7007 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7008 | { |
| 7009 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7010 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7011 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7012 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7013 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7014 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7015 | netif_napi_del(&tp->napi); |
| 7016 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7017 | unregister_netdev(dev); |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7018 | mdiobus_unregister(tp->mii_bus); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7019 | |
| 7020 | rtl_release_firmware(tp); |
| 7021 | |
| 7022 | if (pci_dev_run_wake(pdev)) |
| 7023 | pm_runtime_get_noresume(&pdev->dev); |
| 7024 | |
| 7025 | /* restore original MAC address */ |
| 7026 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7027 | } |
| 7028 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7029 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7030 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7031 | .ndo_stop = rtl8169_close, |
| 7032 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7033 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7034 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7035 | .ndo_validate_addr = eth_validate_addr, |
| 7036 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7037 | .ndo_fix_features = rtl8169_fix_features, |
| 7038 | .ndo_set_features = rtl8169_set_features, |
| 7039 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7040 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7041 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7042 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7043 | .ndo_poll_controller = rtl8169_netpoll, |
| 7044 | #endif |
| 7045 | |
| 7046 | }; |
| 7047 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7048 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7049 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7050 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7051 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7052 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7053 | u8 default_ver; |
| 7054 | } rtl_cfg_infos [] = { |
| 7055 | [RTL_CFG_0] = { |
| 7056 | .hw_start = rtl_hw_start_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7057 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7058 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7059 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7060 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7061 | }, |
| 7062 | [RTL_CFG_1] = { |
| 7063 | .hw_start = rtl_hw_start_8168, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7064 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7065 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7066 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7067 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7068 | }, |
| 7069 | [RTL_CFG_2] = { |
| 7070 | .hw_start = rtl_hw_start_8101, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7071 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7072 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7073 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7074 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7075 | } |
| 7076 | }; |
| 7077 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7078 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7079 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7080 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7081 | |
Jian-Hong Pan | 7bb05b8 | 2018-08-17 13:07:35 +0800 | [diff] [blame] | 7082 | switch (tp->mac_version) { |
| 7083 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7084 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7085 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7086 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7087 | flags = PCI_IRQ_LEGACY; |
Jian-Hong Pan | 7bb05b8 | 2018-08-17 13:07:35 +0800 | [diff] [blame] | 7088 | break; |
| 7089 | case RTL_GIGA_MAC_VER_39 ... RTL_GIGA_MAC_VER_40: |
Heiner Kallweit | 7c53a72 | 2018-08-12 13:26:26 +0200 | [diff] [blame] | 7090 | /* This version was reported to have issues with resume |
| 7091 | * from suspend when using MSI-X |
| 7092 | */ |
| 7093 | flags = PCI_IRQ_LEGACY | PCI_IRQ_MSI; |
Jian-Hong Pan | 7bb05b8 | 2018-08-17 13:07:35 +0800 | [diff] [blame] | 7094 | break; |
| 7095 | default: |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7096 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7097 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7098 | |
| 7099 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7100 | } |
| 7101 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7102 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7103 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7104 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7108 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7109 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7110 | } |
| 7111 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7112 | static int r8169_mdio_read_reg(struct mii_bus *mii_bus, int phyaddr, int phyreg) |
| 7113 | { |
| 7114 | struct rtl8169_private *tp = mii_bus->priv; |
| 7115 | |
| 7116 | if (phyaddr > 0) |
| 7117 | return -ENODEV; |
| 7118 | |
| 7119 | return rtl_readphy(tp, phyreg); |
| 7120 | } |
| 7121 | |
| 7122 | static int r8169_mdio_write_reg(struct mii_bus *mii_bus, int phyaddr, |
| 7123 | int phyreg, u16 val) |
| 7124 | { |
| 7125 | struct rtl8169_private *tp = mii_bus->priv; |
| 7126 | |
| 7127 | if (phyaddr > 0) |
| 7128 | return -ENODEV; |
| 7129 | |
| 7130 | rtl_writephy(tp, phyreg, val); |
| 7131 | |
| 7132 | return 0; |
| 7133 | } |
| 7134 | |
| 7135 | static int r8169_mdio_register(struct rtl8169_private *tp) |
| 7136 | { |
| 7137 | struct pci_dev *pdev = tp->pci_dev; |
| 7138 | struct phy_device *phydev; |
| 7139 | struct mii_bus *new_bus; |
| 7140 | int ret; |
| 7141 | |
| 7142 | new_bus = devm_mdiobus_alloc(&pdev->dev); |
| 7143 | if (!new_bus) |
| 7144 | return -ENOMEM; |
| 7145 | |
| 7146 | new_bus->name = "r8169"; |
| 7147 | new_bus->priv = tp; |
| 7148 | new_bus->parent = &pdev->dev; |
| 7149 | new_bus->irq[0] = PHY_IGNORE_INTERRUPT; |
| 7150 | snprintf(new_bus->id, MII_BUS_ID_SIZE, "r8169-%x", |
| 7151 | PCI_DEVID(pdev->bus->number, pdev->devfn)); |
| 7152 | |
| 7153 | new_bus->read = r8169_mdio_read_reg; |
| 7154 | new_bus->write = r8169_mdio_write_reg; |
| 7155 | |
| 7156 | ret = mdiobus_register(new_bus); |
| 7157 | if (ret) |
| 7158 | return ret; |
| 7159 | |
| 7160 | phydev = mdiobus_get_phy(new_bus, 0); |
| 7161 | if (!phydev) { |
| 7162 | mdiobus_unregister(new_bus); |
| 7163 | return -ENODEV; |
| 7164 | } |
| 7165 | |
Heiner Kallweit | 242cd9b | 2018-07-17 22:51:33 +0200 | [diff] [blame] | 7166 | /* PHY will be woken up in rtl_open() */ |
| 7167 | phy_suspend(phydev); |
| 7168 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7169 | tp->mii_bus = new_bus; |
| 7170 | |
| 7171 | return 0; |
| 7172 | } |
| 7173 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7174 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7175 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7176 | u32 data; |
| 7177 | |
| 7178 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7179 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7180 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7181 | |
| 7182 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7183 | return; |
| 7184 | |
| 7185 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7186 | return; |
| 7187 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7188 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7189 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7190 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7191 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7192 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7193 | data &= ~(1 << 14); |
| 7194 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7195 | |
| 7196 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7197 | return; |
| 7198 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7199 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7200 | data |= (1 << 15); |
| 7201 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7202 | |
| 7203 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7204 | return; |
| 7205 | } |
| 7206 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7207 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7208 | { |
| 7209 | rtl8168ep_stop_cmac(tp); |
| 7210 | rtl_hw_init_8168g(tp); |
| 7211 | } |
| 7212 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7213 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7214 | { |
| 7215 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7216 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7217 | rtl_hw_init_8168g(tp); |
| 7218 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7219 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7220 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7221 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7222 | default: |
| 7223 | break; |
| 7224 | } |
| 7225 | } |
| 7226 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7227 | /* Versions RTL8102e and from RTL8168c onwards support csum_v2 */ |
| 7228 | static bool rtl_chip_supports_csum_v2(struct rtl8169_private *tp) |
| 7229 | { |
| 7230 | switch (tp->mac_version) { |
| 7231 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7232 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
| 7233 | return false; |
| 7234 | default: |
| 7235 | return true; |
| 7236 | } |
| 7237 | } |
| 7238 | |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7239 | static int rtl_jumbo_max(struct rtl8169_private *tp) |
| 7240 | { |
| 7241 | /* Non-GBit versions don't support jumbo frames */ |
| 7242 | if (!tp->supports_gmii) |
| 7243 | return JUMBO_1K; |
| 7244 | |
| 7245 | switch (tp->mac_version) { |
| 7246 | /* RTL8169 */ |
| 7247 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 7248 | return JUMBO_7K; |
| 7249 | /* RTL8168b */ |
| 7250 | case RTL_GIGA_MAC_VER_11: |
| 7251 | case RTL_GIGA_MAC_VER_12: |
| 7252 | case RTL_GIGA_MAC_VER_17: |
| 7253 | return JUMBO_4K; |
| 7254 | /* RTL8168c */ |
| 7255 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
| 7256 | return JUMBO_6K; |
| 7257 | default: |
| 7258 | return JUMBO_9K; |
| 7259 | } |
| 7260 | } |
| 7261 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7262 | 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] | 7263 | { |
| 7264 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7265 | struct rtl8169_private *tp; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7266 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7267 | int chipset, region, i; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7268 | int jumbo_max, rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7269 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7270 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7271 | if (!dev) |
| 7272 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7273 | |
| 7274 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7275 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7276 | tp = netdev_priv(dev); |
| 7277 | tp->dev = dev; |
| 7278 | tp->pci_dev = pdev; |
| 7279 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Heiner Kallweit | f7ffa9a | 2018-07-17 22:52:09 +0200 | [diff] [blame] | 7280 | tp->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7281 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7282 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7283 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7284 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7285 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7286 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7287 | } |
| 7288 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7289 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7290 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7291 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7292 | /* use first MMIO region */ |
| 7293 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7294 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7295 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7296 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | /* check for weird/broken PCI region reporting */ |
| 7300 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7301 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7302 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7305 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7306 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7307 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7308 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7309 | } |
| 7310 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7311 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7312 | |
| 7313 | if (!pci_is_pcie(pdev)) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7314 | dev_info(&pdev->dev, "not PCI Express\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7315 | |
| 7316 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7317 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7318 | |
Heiner Kallweit | e397286 | 2018-06-29 08:07:04 +0200 | [diff] [blame] | 7319 | if (rtl_tbi_enabled(tp)) { |
| 7320 | dev_err(&pdev->dev, "TBI fiber mode not supported\n"); |
| 7321 | return -ENODEV; |
| 7322 | } |
| 7323 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7324 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7325 | |
| 7326 | if ((sizeof(dma_addr_t) > 4) && |
| 7327 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 7328 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 7329 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 7330 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7331 | |
| 7332 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7333 | if (!pci_is_pcie(pdev)) |
| 7334 | tp->cp_cmd |= PCIDAC; |
| 7335 | dev->features |= NETIF_F_HIGHDMA; |
| 7336 | } else { |
| 7337 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7338 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7339 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7340 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7341 | } |
| 7342 | } |
| 7343 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7344 | rtl_init_rxcfg(tp); |
| 7345 | |
| 7346 | rtl_irq_disable(tp); |
| 7347 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7348 | rtl_hw_initialize(tp); |
| 7349 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7350 | rtl_hw_reset(tp); |
| 7351 | |
| 7352 | rtl_ack_events(tp, 0xffff); |
| 7353 | |
| 7354 | pci_set_master(pdev); |
| 7355 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7356 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7357 | rtl_init_jumbo_ops(tp); |
| 7358 | |
| 7359 | rtl8169_print_mac_version(tp); |
| 7360 | |
| 7361 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7362 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7363 | rc = rtl_alloc_irq(tp); |
| 7364 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7365 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7366 | return rc; |
| 7367 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7368 | |
Heiner Kallweit | 18041b5 | 2018-07-24 22:21:04 +0200 | [diff] [blame] | 7369 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7370 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7371 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7372 | u64_stats_init(&tp->rx_stats.syncp); |
| 7373 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7374 | |
| 7375 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7376 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7377 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7378 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7379 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7380 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7381 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7382 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7383 | if (is_valid_ether_addr(mac_addr)) |
| 7384 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7385 | break; |
| 7386 | default: |
| 7387 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7388 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7389 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7390 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7391 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7392 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7393 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7394 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7395 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7396 | |
| 7397 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7398 | * properly for all devices */ |
| 7399 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7400 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7401 | |
| 7402 | 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] | 7403 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7404 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7405 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7406 | NETIF_F_HIGHDMA; |
Heiner Kallweit | 2d0ec54 | 2018-07-02 22:49:35 +0200 | [diff] [blame] | 7407 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7408 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7409 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7410 | |
| 7411 | /* |
| 7412 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7413 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7414 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7415 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7416 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7417 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7418 | |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7419 | if (rtl_chip_supports_csum_v2(tp)) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7420 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7421 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | eb88f5f | 2018-08-10 22:39:29 +0200 | [diff] [blame] | 7422 | } else { |
| 7423 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7424 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7425 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7426 | dev->hw_features |= NETIF_F_RXALL; |
| 7427 | dev->hw_features |= NETIF_F_RXFCS; |
| 7428 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7429 | /* MTU range: 60 - hw-specific max */ |
| 7430 | dev->min_mtu = ETH_ZLEN; |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7431 | jumbo_max = rtl_jumbo_max(tp); |
| 7432 | dev->max_mtu = jumbo_max; |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7433 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7434 | tp->hw_start = cfg->hw_start; |
| 7435 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7436 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7437 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7438 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7439 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7440 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7441 | &tp->counters_phys_addr, |
| 7442 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7443 | if (!tp->counters) |
| 7444 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7445 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7446 | pci_set_drvdata(pdev, dev); |
| 7447 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7448 | rc = r8169_mdio_register(tp); |
| 7449 | if (rc) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7450 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7451 | |
Heiner Kallweit | 07df5bd | 2018-07-17 21:21:37 +0200 | [diff] [blame] | 7452 | /* chip gets powered up in rtl_open() */ |
| 7453 | rtl_pll_power_down(tp); |
| 7454 | |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7455 | rc = register_netdev(dev); |
| 7456 | if (rc) |
| 7457 | goto err_mdio_unregister; |
| 7458 | |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7459 | netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n", |
| 7460 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 90b989c | 2018-04-17 23:32:15 +0200 | [diff] [blame] | 7461 | (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7462 | pci_irq_vector(pdev, 0)); |
Heiner Kallweit | abe8b2f | 2018-08-10 22:40:37 +0200 | [diff] [blame] | 7463 | |
| 7464 | if (jumbo_max > JUMBO_1K) |
| 7465 | netif_info(tp, probe, dev, |
| 7466 | "jumbo features [frames: %d bytes, tx checksumming: %s]\n", |
| 7467 | jumbo_max, tp->mac_version <= RTL_GIGA_MAC_VER_06 ? |
| 7468 | "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7469 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7470 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7471 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7472 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7473 | if (pci_dev_run_wake(pdev)) |
| 7474 | pm_runtime_put_sync(&pdev->dev); |
| 7475 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7476 | return 0; |
Heiner Kallweit | f1e911d | 2018-07-17 22:51:26 +0200 | [diff] [blame] | 7477 | |
| 7478 | err_mdio_unregister: |
| 7479 | mdiobus_unregister(tp->mii_bus); |
| 7480 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7481 | } |
| 7482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7483 | static struct pci_driver rtl8169_pci_driver = { |
| 7484 | .name = MODULENAME, |
| 7485 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7486 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7487 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7488 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7489 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7490 | }; |
| 7491 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7492 | module_pci_driver(rtl8169_pci_driver); |