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> |
| 18 | #include <linux/mii.h> |
| 19 | #include <linux/if_vlan.h> |
| 20 | #include <linux/crc32.h> |
| 21 | #include <linux/in.h> |
| 22 | #include <linux/ip.h> |
| 23 | #include <linux/tcp.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 28 | #include <linux/prefetch.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 29 | #include <linux/ipv6.h> |
| 30 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/irq.h> |
| 34 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 35 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MODULENAME "r8169" |
| 37 | #define PFX MODULENAME ": " |
| 38 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 39 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 40 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 41 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 42 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 45 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 50 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 51 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 52 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 53 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 54 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 55 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 56 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 57 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #ifdef RTL8169_DEBUG |
| 60 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 61 | if (!(expr)) { \ |
| 62 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 63 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 64 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 65 | #define dprintk(fmt, args...) \ |
| 66 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #else |
| 68 | #define assert(expr) do {} while (0) |
| 69 | #define dprintk(fmt, args...) do {} while (0) |
| 70 | #endif /* RTL8169_DEBUG */ |
| 71 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 72 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 73 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 74 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 75 | #define TX_SLOTS_AVAIL(tp) \ |
| 76 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 77 | |
| 78 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 79 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 80 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 83 | 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] | 84 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 86 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 88 | |
| 89 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 90 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 92 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 94 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 95 | |
| 96 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 97 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 98 | |
| 99 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 100 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 101 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 102 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 103 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 104 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 105 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 108 | RTL_GIGA_MAC_VER_01 = 0, |
| 109 | RTL_GIGA_MAC_VER_02, |
| 110 | RTL_GIGA_MAC_VER_03, |
| 111 | RTL_GIGA_MAC_VER_04, |
| 112 | RTL_GIGA_MAC_VER_05, |
| 113 | RTL_GIGA_MAC_VER_06, |
| 114 | RTL_GIGA_MAC_VER_07, |
| 115 | RTL_GIGA_MAC_VER_08, |
| 116 | RTL_GIGA_MAC_VER_09, |
| 117 | RTL_GIGA_MAC_VER_10, |
| 118 | RTL_GIGA_MAC_VER_11, |
| 119 | RTL_GIGA_MAC_VER_12, |
| 120 | RTL_GIGA_MAC_VER_13, |
| 121 | RTL_GIGA_MAC_VER_14, |
| 122 | RTL_GIGA_MAC_VER_15, |
| 123 | RTL_GIGA_MAC_VER_16, |
| 124 | RTL_GIGA_MAC_VER_17, |
| 125 | RTL_GIGA_MAC_VER_18, |
| 126 | RTL_GIGA_MAC_VER_19, |
| 127 | RTL_GIGA_MAC_VER_20, |
| 128 | RTL_GIGA_MAC_VER_21, |
| 129 | RTL_GIGA_MAC_VER_22, |
| 130 | RTL_GIGA_MAC_VER_23, |
| 131 | RTL_GIGA_MAC_VER_24, |
| 132 | RTL_GIGA_MAC_VER_25, |
| 133 | RTL_GIGA_MAC_VER_26, |
| 134 | RTL_GIGA_MAC_VER_27, |
| 135 | RTL_GIGA_MAC_VER_28, |
| 136 | RTL_GIGA_MAC_VER_29, |
| 137 | RTL_GIGA_MAC_VER_30, |
| 138 | RTL_GIGA_MAC_VER_31, |
| 139 | RTL_GIGA_MAC_VER_32, |
| 140 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 141 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 142 | RTL_GIGA_MAC_VER_35, |
| 143 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 144 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 145 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 146 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 147 | RTL_GIGA_MAC_VER_40, |
| 148 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 149 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 150 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 151 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 152 | RTL_GIGA_MAC_VER_45, |
| 153 | RTL_GIGA_MAC_VER_46, |
| 154 | RTL_GIGA_MAC_VER_47, |
| 155 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 156 | RTL_GIGA_MAC_VER_49, |
| 157 | RTL_GIGA_MAC_VER_50, |
| 158 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 159 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 162 | enum rtl_tx_desc_version { |
| 163 | RTL_TD_0 = 0, |
| 164 | RTL_TD_1 = 1, |
| 165 | }; |
| 166 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 167 | #define JUMBO_1K ETH_DATA_LEN |
| 168 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 169 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 170 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 171 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 172 | |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 173 | #define _R(NAME,TD,FW,SZ) { \ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 174 | .name = NAME, \ |
| 175 | .txd_version = TD, \ |
| 176 | .fw_name = FW, \ |
| 177 | .jumbo_max = SZ, \ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 180 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 182 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 183 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 184 | u16 jumbo_max; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 185 | } rtl_chip_infos[] = { |
| 186 | /* PCI devices. */ |
| 187 | [RTL_GIGA_MAC_VER_01] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 188 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 189 | [RTL_GIGA_MAC_VER_02] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 190 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 191 | [RTL_GIGA_MAC_VER_03] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 192 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 193 | [RTL_GIGA_MAC_VER_04] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 194 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 195 | [RTL_GIGA_MAC_VER_05] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 196 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 197 | [RTL_GIGA_MAC_VER_06] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 198 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 199 | /* PCI-E devices. */ |
| 200 | [RTL_GIGA_MAC_VER_07] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 201 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 202 | [RTL_GIGA_MAC_VER_08] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 203 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 204 | [RTL_GIGA_MAC_VER_09] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 205 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 206 | [RTL_GIGA_MAC_VER_10] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 207 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 208 | [RTL_GIGA_MAC_VER_11] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 209 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 210 | [RTL_GIGA_MAC_VER_12] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 211 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 212 | [RTL_GIGA_MAC_VER_13] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 213 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 214 | [RTL_GIGA_MAC_VER_14] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 215 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 216 | [RTL_GIGA_MAC_VER_15] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 217 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 218 | [RTL_GIGA_MAC_VER_16] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 219 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 220 | [RTL_GIGA_MAC_VER_17] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 221 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 222 | [RTL_GIGA_MAC_VER_18] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 223 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 224 | [RTL_GIGA_MAC_VER_19] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 225 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 226 | [RTL_GIGA_MAC_VER_20] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 227 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 228 | [RTL_GIGA_MAC_VER_21] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 229 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 230 | [RTL_GIGA_MAC_VER_22] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 231 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 232 | [RTL_GIGA_MAC_VER_23] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 233 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 234 | [RTL_GIGA_MAC_VER_24] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 235 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 236 | [RTL_GIGA_MAC_VER_25] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 237 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 238 | [RTL_GIGA_MAC_VER_26] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 239 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 240 | [RTL_GIGA_MAC_VER_27] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 241 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 242 | [RTL_GIGA_MAC_VER_28] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 243 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 244 | [RTL_GIGA_MAC_VER_29] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 245 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 246 | [RTL_GIGA_MAC_VER_30] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 247 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, JUMBO_1K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 248 | [RTL_GIGA_MAC_VER_31] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 249 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 250 | [RTL_GIGA_MAC_VER_32] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 251 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, JUMBO_9K), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 252 | [RTL_GIGA_MAC_VER_33] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 253 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, JUMBO_9K), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 254 | [RTL_GIGA_MAC_VER_34] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 255 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, JUMBO_9K), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 256 | [RTL_GIGA_MAC_VER_35] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 257 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, JUMBO_9K), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 258 | [RTL_GIGA_MAC_VER_36] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 259 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, JUMBO_9K), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 260 | [RTL_GIGA_MAC_VER_37] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 261 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, JUMBO_1K), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 262 | [RTL_GIGA_MAC_VER_38] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 263 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, JUMBO_9K), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 264 | [RTL_GIGA_MAC_VER_39] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 265 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, JUMBO_1K), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 266 | [RTL_GIGA_MAC_VER_40] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 267 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, JUMBO_9K), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 268 | [RTL_GIGA_MAC_VER_41] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 269 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K), |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 270 | [RTL_GIGA_MAC_VER_42] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 271 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, JUMBO_9K), |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 272 | [RTL_GIGA_MAC_VER_43] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 273 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, JUMBO_1K), |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 274 | [RTL_GIGA_MAC_VER_44] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 275 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 276 | [RTL_GIGA_MAC_VER_45] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 277 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 278 | [RTL_GIGA_MAC_VER_46] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 279 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, JUMBO_9K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 280 | [RTL_GIGA_MAC_VER_47] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 281 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, JUMBO_1K), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 282 | [RTL_GIGA_MAC_VER_48] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 283 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, JUMBO_1K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 284 | [RTL_GIGA_MAC_VER_49] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 285 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 286 | [RTL_GIGA_MAC_VER_50] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 287 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 288 | [RTL_GIGA_MAC_VER_51] = |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 289 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, JUMBO_9K), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | }; |
| 291 | #undef _R |
| 292 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 293 | enum cfg_version { |
| 294 | RTL_CFG_0 = 0x00, |
| 295 | RTL_CFG_1, |
| 296 | RTL_CFG_2 |
| 297 | }; |
| 298 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 299 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 300 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 301 | { 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] | 302 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 303 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 304 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 305 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 306 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 307 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 308 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 309 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 310 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 311 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 312 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 313 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 314 | { 0x0001, 0x8168, |
| 315 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | {0,}, |
| 317 | }; |
| 318 | |
| 319 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 320 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 321 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 322 | static struct { |
| 323 | u32 msg_enable; |
| 324 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 326 | enum rtl_registers { |
| 327 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 328 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 329 | MAR0 = 8, /* Multicast filter. */ |
| 330 | CounterAddrLow = 0x10, |
| 331 | CounterAddrHigh = 0x14, |
| 332 | TxDescStartAddrLow = 0x20, |
| 333 | TxDescStartAddrHigh = 0x24, |
| 334 | TxHDescStartAddrLow = 0x28, |
| 335 | TxHDescStartAddrHigh = 0x2c, |
| 336 | FLASH = 0x30, |
| 337 | ERSR = 0x36, |
| 338 | ChipCmd = 0x37, |
| 339 | TxPoll = 0x38, |
| 340 | IntrMask = 0x3c, |
| 341 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 342 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 343 | TxConfig = 0x40, |
| 344 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 345 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 346 | |
| 347 | RxConfig = 0x44, |
| 348 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 349 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 350 | #define RXCFG_FIFO_SHIFT 13 |
| 351 | /* No threshold before first PCI xfer */ |
| 352 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 353 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 354 | #define RXCFG_DMA_SHIFT 8 |
| 355 | /* Unlimited maximum PCI burst. */ |
| 356 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 357 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 358 | RxMissed = 0x4c, |
| 359 | Cfg9346 = 0x50, |
| 360 | Config0 = 0x51, |
| 361 | Config1 = 0x52, |
| 362 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 363 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 364 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 365 | Config3 = 0x54, |
| 366 | Config4 = 0x55, |
| 367 | Config5 = 0x56, |
| 368 | MultiIntr = 0x5c, |
| 369 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 370 | PHYstatus = 0x6c, |
| 371 | RxMaxSize = 0xda, |
| 372 | CPlusCmd = 0xe0, |
| 373 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 374 | |
| 375 | #define RTL_COALESCE_MASK 0x0f |
| 376 | #define RTL_COALESCE_SHIFT 4 |
| 377 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 378 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 379 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 380 | RxDescAddrLow = 0xe4, |
| 381 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 382 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 383 | |
| 384 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 385 | |
| 386 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 387 | |
| 388 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 389 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 390 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 391 | FuncEvent = 0xf0, |
| 392 | FuncEventMask = 0xf4, |
| 393 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 394 | IBCR0 = 0xf8, |
| 395 | IBCR2 = 0xf9, |
| 396 | IBIMR0 = 0xfa, |
| 397 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 398 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 401 | enum rtl8110_registers { |
| 402 | TBICSR = 0x64, |
| 403 | TBI_ANAR = 0x68, |
| 404 | TBI_LPAR = 0x6a, |
| 405 | }; |
| 406 | |
| 407 | enum rtl8168_8101_registers { |
| 408 | CSIDR = 0x64, |
| 409 | CSIAR = 0x68, |
| 410 | #define CSIAR_FLAG 0x80000000 |
| 411 | #define CSIAR_WRITE_CMD 0x80000000 |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 412 | #define CSIAR_BYTE_ENABLE 0x0000f000 |
| 413 | #define CSIAR_ADDR_MASK 0x00000fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 414 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 415 | EPHYAR = 0x80, |
| 416 | #define EPHYAR_FLAG 0x80000000 |
| 417 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 418 | #define EPHYAR_REG_MASK 0x1f |
| 419 | #define EPHYAR_REG_SHIFT 16 |
| 420 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 421 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 422 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 423 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 424 | DBG_REG = 0xd1, |
| 425 | #define FIX_NAK_1 (1 << 4) |
| 426 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 427 | TWSI = 0xd2, |
| 428 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 429 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 430 | #define TX_EMPTY (1 << 5) |
| 431 | #define RX_EMPTY (1 << 4) |
| 432 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 433 | #define EN_NDP (1 << 3) |
| 434 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 435 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 436 | EFUSEAR = 0xdc, |
| 437 | #define EFUSEAR_FLAG 0x80000000 |
| 438 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 439 | #define EFUSEAR_READ_CMD 0x00000000 |
| 440 | #define EFUSEAR_REG_MASK 0x03ff |
| 441 | #define EFUSEAR_REG_SHIFT 8 |
| 442 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 443 | MISC_1 = 0xf2, |
| 444 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 445 | }; |
| 446 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 447 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 448 | LED_FREQ = 0x1a, |
| 449 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 450 | ERIDR = 0x70, |
| 451 | ERIAR = 0x74, |
| 452 | #define ERIAR_FLAG 0x80000000 |
| 453 | #define ERIAR_WRITE_CMD 0x80000000 |
| 454 | #define ERIAR_READ_CMD 0x00000000 |
| 455 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 456 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 457 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 458 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 459 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 460 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 461 | #define ERIAR_MASK_SHIFT 12 |
| 462 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 463 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 464 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 465 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 466 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 467 | EPHY_RXER_NUM = 0x7c, |
| 468 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 469 | #define OCPDR_WRITE_CMD 0x80000000 |
| 470 | #define OCPDR_READ_CMD 0x00000000 |
| 471 | #define OCPDR_REG_MASK 0x7f |
| 472 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 473 | #define OCPDR_DATA_MASK 0xffff |
| 474 | OCPAR = 0xb4, |
| 475 | #define OCPAR_FLAG 0x80000000 |
| 476 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 477 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 478 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 479 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 480 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 481 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 482 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 483 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 484 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 485 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 486 | }; |
| 487 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 488 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 490 | SYSErr = 0x8000, |
| 491 | PCSTimeout = 0x4000, |
| 492 | SWInt = 0x0100, |
| 493 | TxDescUnavail = 0x0080, |
| 494 | RxFIFOOver = 0x0040, |
| 495 | LinkChg = 0x0020, |
| 496 | RxOverflow = 0x0010, |
| 497 | TxErr = 0x0008, |
| 498 | TxOK = 0x0004, |
| 499 | RxErr = 0x0002, |
| 500 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 503 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 504 | RxFOVF = (1 << 23), |
| 505 | RxRWT = (1 << 22), |
| 506 | RxRES = (1 << 21), |
| 507 | RxRUNT = (1 << 20), |
| 508 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 511 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 512 | CmdReset = 0x10, |
| 513 | CmdRxEnb = 0x08, |
| 514 | CmdTxEnb = 0x04, |
| 515 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 517 | /* TXPoll register p.5 */ |
| 518 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 519 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 520 | FSWInt = 0x01, /* Forced software interrupt */ |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 523 | Cfg9346_Lock = 0x00, |
| 524 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 527 | AcceptErr = 0x20, |
| 528 | AcceptRunt = 0x10, |
| 529 | AcceptBroadcast = 0x08, |
| 530 | AcceptMulticast = 0x04, |
| 531 | AcceptMyPhys = 0x02, |
| 532 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 533 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /* TxConfigBits */ |
| 536 | TxInterFrameGapShift = 24, |
| 537 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 538 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 539 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 540 | LEDS1 = (1 << 7), |
| 541 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 542 | Speed_down = (1 << 4), |
| 543 | MEMMAP = (1 << 3), |
| 544 | IOMAP = (1 << 2), |
| 545 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 546 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 547 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 548 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 549 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 550 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 551 | PCI_Clock_66MHz = 0x01, |
| 552 | PCI_Clock_33MHz = 0x00, |
| 553 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 554 | /* Config3 register p.25 */ |
| 555 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 556 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 557 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 558 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 559 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 560 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 561 | /* Config4 register */ |
| 562 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 563 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 564 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 565 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 566 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 567 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 568 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 569 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 570 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 571 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* TBICSR p.28 */ |
| 574 | TBIReset = 0x80000000, |
| 575 | TBILoopback = 0x40000000, |
| 576 | TBINwEnable = 0x20000000, |
| 577 | TBINwRestart = 0x10000000, |
| 578 | TBILinkOk = 0x02000000, |
| 579 | TBINwComplete = 0x01000000, |
| 580 | |
| 581 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 582 | EnableBist = (1 << 15), // 8168 8101 |
| 583 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 584 | Normal_mode = (1 << 13), // unused |
| 585 | Force_half_dup = (1 << 12), // 8168 8101 |
| 586 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 587 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 588 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 589 | ASF = (1 << 8), // 8168 8101 |
| 590 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 591 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | RxVlan = (1 << 6), |
| 593 | RxChkSum = (1 << 5), |
| 594 | PCIDAC = (1 << 4), |
| 595 | PCIMulRW = (1 << 3), |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 596 | #define INTT_MASK GENMASK(1, 0) |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 597 | INTT_0 = 0x0000, // 8168 |
| 598 | INTT_1 = 0x0001, // 8168 |
| 599 | INTT_2 = 0x0002, // 8168 |
| 600 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 603 | TBI_Enable = 0x80, |
| 604 | TxFlowCtrl = 0x40, |
| 605 | RxFlowCtrl = 0x20, |
| 606 | _1000bpsF = 0x10, |
| 607 | _100bps = 0x08, |
| 608 | _10bps = 0x04, |
| 609 | LinkStatus = 0x02, |
| 610 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 613 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 614 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 615 | /* ResetCounterCommand */ |
| 616 | CounterReset = 0x1, |
| 617 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 618 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 619 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 620 | |
| 621 | /* magic enable v2 */ |
| 622 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | }; |
| 624 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 625 | enum rtl_desc_bit { |
| 626 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 628 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 629 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 630 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 631 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 633 | /* Generic case. */ |
| 634 | enum rtl_tx_desc_bit { |
| 635 | /* First doubleword. */ |
| 636 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 637 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 639 | /* Second doubleword. */ |
| 640 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 641 | }; |
| 642 | |
| 643 | /* 8169, 8168b and 810x except 8102e. */ |
| 644 | enum rtl_tx_desc_bit_0 { |
| 645 | /* First doubleword. */ |
| 646 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 647 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 648 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 649 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 650 | }; |
| 651 | |
| 652 | /* 8102e, 8168c and beyond. */ |
| 653 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 654 | /* First doubleword. */ |
| 655 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 656 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 657 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 658 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 659 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 660 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 661 | #define TCPHO_SHIFT 18 |
| 662 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 663 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 664 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 665 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 666 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 667 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 668 | }; |
| 669 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 670 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* Rx private */ |
| 672 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 673 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | #define RxProtoUDP (PID1) |
| 676 | #define RxProtoTCP (PID0) |
| 677 | #define RxProtoIP (PID1 | PID0) |
| 678 | #define RxProtoMask RxProtoIP |
| 679 | |
| 680 | IPFail = (1 << 16), /* IP checksum failed */ |
| 681 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 682 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 683 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 684 | }; |
| 685 | |
| 686 | #define RsvdMask 0x3fffc000 |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 687 | #define CPCMD_QUIRK_MASK (Normal_mode | RxVlan | RxChkSum | INTT_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 690 | __le32 opts1; |
| 691 | __le32 opts2; |
| 692 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 696 | __le32 opts1; |
| 697 | __le32 opts2; |
| 698 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | }; |
| 700 | |
| 701 | struct ring_info { |
| 702 | struct sk_buff *skb; |
| 703 | u32 len; |
| 704 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 705 | }; |
| 706 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 707 | struct rtl8169_counters { |
| 708 | __le64 tx_packets; |
| 709 | __le64 rx_packets; |
| 710 | __le64 tx_errors; |
| 711 | __le32 rx_errors; |
| 712 | __le16 rx_missed; |
| 713 | __le16 align_errors; |
| 714 | __le32 tx_one_collision; |
| 715 | __le32 tx_multi_collision; |
| 716 | __le64 rx_unicast; |
| 717 | __le64 rx_broadcast; |
| 718 | __le32 rx_multicast; |
| 719 | __le16 tx_aborted; |
| 720 | __le16 tx_underun; |
| 721 | }; |
| 722 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 723 | struct rtl8169_tc_offsets { |
| 724 | bool inited; |
| 725 | __le64 tx_errors; |
| 726 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 727 | __le16 tx_aborted; |
| 728 | }; |
| 729 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 730 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 731 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 732 | RTL_FLAG_TASK_SLOW_PENDING, |
| 733 | RTL_FLAG_TASK_RESET_PENDING, |
| 734 | RTL_FLAG_TASK_PHY_PENDING, |
| 735 | RTL_FLAG_MAX |
| 736 | }; |
| 737 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 738 | struct rtl8169_stats { |
| 739 | u64 packets; |
| 740 | u64 bytes; |
| 741 | struct u64_stats_sync syncp; |
| 742 | }; |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | struct rtl8169_private { |
| 745 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 746 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 747 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 748 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 749 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 750 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 752 | 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] | 753 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 754 | struct rtl8169_stats rx_stats; |
| 755 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 757 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 758 | dma_addr_t TxPhyAddr; |
| 759 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 760 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | struct timer_list timer; |
| 763 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 764 | |
| 765 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 766 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 767 | |
| 768 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 769 | void (*write)(struct rtl8169_private *, int, int); |
| 770 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 771 | } mdio_ops; |
| 772 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 773 | struct jumbo_ops { |
| 774 | void (*enable)(struct rtl8169_private *); |
| 775 | void (*disable)(struct rtl8169_private *); |
| 776 | } jumbo_ops; |
| 777 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 778 | int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 779 | int (*get_link_ksettings)(struct net_device *, |
| 780 | struct ethtool_link_ksettings *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 781 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 782 | void (*hw_start)(struct rtl8169_private *tp); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 783 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 784 | unsigned int (*link_ok)(struct rtl8169_private *tp); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 785 | int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 786 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 787 | |
| 788 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 789 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 790 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 791 | struct work_struct work; |
| 792 | } wk; |
| 793 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 794 | struct mii_if_info mii; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 795 | dma_addr_t counters_phys_addr; |
| 796 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 797 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 798 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 799 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 800 | struct rtl_fw { |
| 801 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 802 | |
| 803 | #define RTL_VER_SIZE 32 |
| 804 | |
| 805 | char version[RTL_VER_SIZE]; |
| 806 | |
| 807 | struct rtl_fw_phy_action { |
| 808 | __le32 *code; |
| 809 | size_t size; |
| 810 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 811 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 812 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 813 | |
| 814 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | }; |
| 816 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 817 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 820 | 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] | 821 | module_param_named(debug, debug.msg_enable, int, 0); |
| 822 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | MODULE_LICENSE("GPL"); |
| 824 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 825 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 826 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 827 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 828 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 829 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 830 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 831 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 832 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 833 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 834 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 835 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 836 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 837 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 838 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 839 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 840 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 841 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 842 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 843 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 845 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 846 | { |
| 847 | return &tp->pci_dev->dev; |
| 848 | } |
| 849 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 850 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 851 | { |
| 852 | mutex_lock(&tp->wk.mutex); |
| 853 | } |
| 854 | |
| 855 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 856 | { |
| 857 | mutex_unlock(&tp->wk.mutex); |
| 858 | } |
| 859 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 860 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 861 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 862 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 863 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 864 | } |
| 865 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 866 | struct rtl_cond { |
| 867 | bool (*check)(struct rtl8169_private *); |
| 868 | const char *msg; |
| 869 | }; |
| 870 | |
| 871 | static void rtl_udelay(unsigned int d) |
| 872 | { |
| 873 | udelay(d); |
| 874 | } |
| 875 | |
| 876 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 877 | void (*delay)(unsigned int), unsigned int d, int n, |
| 878 | bool high) |
| 879 | { |
| 880 | int i; |
| 881 | |
| 882 | for (i = 0; i < n; i++) { |
| 883 | delay(d); |
| 884 | if (c->check(tp) == high) |
| 885 | return true; |
| 886 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 887 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 888 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 889 | return false; |
| 890 | } |
| 891 | |
| 892 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 893 | const struct rtl_cond *c, |
| 894 | unsigned int d, int n) |
| 895 | { |
| 896 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 897 | } |
| 898 | |
| 899 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 900 | const struct rtl_cond *c, |
| 901 | unsigned int d, int n) |
| 902 | { |
| 903 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 904 | } |
| 905 | |
| 906 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 907 | const struct rtl_cond *c, |
| 908 | unsigned int d, int n) |
| 909 | { |
| 910 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 911 | } |
| 912 | |
| 913 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 914 | const struct rtl_cond *c, |
| 915 | unsigned int d, int n) |
| 916 | { |
| 917 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 918 | } |
| 919 | |
| 920 | #define DECLARE_RTL_COND(name) \ |
| 921 | static bool name ## _check(struct rtl8169_private *); \ |
| 922 | \ |
| 923 | static const struct rtl_cond name = { \ |
| 924 | .check = name ## _check, \ |
| 925 | .msg = #name \ |
| 926 | }; \ |
| 927 | \ |
| 928 | static bool name ## _check(struct rtl8169_private *tp) |
| 929 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 930 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 931 | { |
| 932 | if (reg & 0xffff0001) { |
| 933 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 934 | return true; |
| 935 | } |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 940 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 941 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 945 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 946 | if (rtl_ocp_reg_failure(tp, reg)) |
| 947 | return; |
| 948 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 949 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 950 | |
| 951 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 952 | } |
| 953 | |
| 954 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 955 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 956 | if (rtl_ocp_reg_failure(tp, reg)) |
| 957 | return 0; |
| 958 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 959 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 960 | |
| 961 | 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] | 962 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 963 | } |
| 964 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 965 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 966 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 967 | if (rtl_ocp_reg_failure(tp, reg)) |
| 968 | return; |
| 969 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 970 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 974 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 975 | if (rtl_ocp_reg_failure(tp, reg)) |
| 976 | return 0; |
| 977 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 978 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 979 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 980 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | #define OCP_STD_PHY_BASE 0xa400 |
| 984 | |
| 985 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 986 | { |
| 987 | if (reg == 0x1f) { |
| 988 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 989 | return; |
| 990 | } |
| 991 | |
| 992 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 993 | reg -= 0x10; |
| 994 | |
| 995 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 996 | } |
| 997 | |
| 998 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 999 | { |
| 1000 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1001 | reg -= 0x10; |
| 1002 | |
| 1003 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1004 | } |
| 1005 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 1006 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 1007 | { |
| 1008 | if (reg == 0x1f) { |
| 1009 | tp->ocp_base = value << 4; |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 1014 | } |
| 1015 | |
| 1016 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 1017 | { |
| 1018 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 1019 | } |
| 1020 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1021 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1022 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1023 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1024 | } |
| 1025 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1026 | 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] | 1027 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1028 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1030 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1031 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1032 | * According to hardware specs a 20us delay is required after write |
| 1033 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1034 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1035 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1038 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1040 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1042 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1044 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1045 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1046 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1047 | /* |
| 1048 | * According to hardware specs a 20us delay is required after read |
| 1049 | * complete indication, but before sending next command. |
| 1050 | */ |
| 1051 | udelay(20); |
| 1052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | return value; |
| 1054 | } |
| 1055 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1056 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 1057 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1058 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1059 | } |
| 1060 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1061 | 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] | 1062 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1063 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 1064 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1065 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1066 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1067 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1070 | 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] | 1071 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1072 | r8168dp_1_mdio_access(tp, reg, |
| 1073 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1076 | 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] | 1077 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1078 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1079 | |
| 1080 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1081 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 1082 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1083 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1084 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1085 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1088 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1089 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1090 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1091 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1092 | 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] | 1093 | } |
| 1094 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1095 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1096 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1097 | 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] | 1098 | } |
| 1099 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1100 | 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] | 1101 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1102 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1103 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1104 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1105 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1106 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1109 | 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] | 1110 | { |
| 1111 | int value; |
| 1112 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1113 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1114 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1115 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1116 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1117 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1118 | |
| 1119 | return value; |
| 1120 | } |
| 1121 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1122 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1123 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1124 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1127 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1128 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1129 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1133 | { |
| 1134 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1135 | } |
| 1136 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1137 | 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] | 1138 | { |
| 1139 | int val; |
| 1140 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1141 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1142 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1145 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1146 | int val) |
| 1147 | { |
| 1148 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1149 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1150 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1154 | { |
| 1155 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1156 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1157 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1160 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1161 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1162 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1165 | 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] | 1166 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1167 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1168 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1169 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1170 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1171 | |
| 1172 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1173 | } |
| 1174 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1175 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1176 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1177 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1178 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1179 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1180 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1183 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1184 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1185 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1186 | } |
| 1187 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1188 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1189 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1190 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1191 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1192 | RTL_W32(tp, ERIDR, val); |
| 1193 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1194 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1195 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1196 | } |
| 1197 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1198 | 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] | 1199 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1200 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1201 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1202 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1203 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1204 | } |
| 1205 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1206 | 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] | 1207 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1208 | { |
| 1209 | u32 val; |
| 1210 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1211 | val = rtl_eri_read(tp, addr, type); |
| 1212 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1213 | } |
| 1214 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1215 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1216 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1217 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1218 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1219 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1223 | { |
| 1224 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1225 | } |
| 1226 | |
| 1227 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1228 | { |
| 1229 | switch (tp->mac_version) { |
| 1230 | case RTL_GIGA_MAC_VER_27: |
| 1231 | case RTL_GIGA_MAC_VER_28: |
| 1232 | case RTL_GIGA_MAC_VER_31: |
| 1233 | return r8168dp_ocp_read(tp, mask, reg); |
| 1234 | case RTL_GIGA_MAC_VER_49: |
| 1235 | case RTL_GIGA_MAC_VER_50: |
| 1236 | case RTL_GIGA_MAC_VER_51: |
| 1237 | return r8168ep_ocp_read(tp, mask, reg); |
| 1238 | default: |
| 1239 | BUG(); |
| 1240 | return ~0; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1245 | u32 data) |
| 1246 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1247 | RTL_W32(tp, OCPDR, data); |
| 1248 | 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] | 1249 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1250 | } |
| 1251 | |
| 1252 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1253 | u32 data) |
| 1254 | { |
| 1255 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1256 | data, ERIAR_OOB); |
| 1257 | } |
| 1258 | |
| 1259 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1260 | { |
| 1261 | switch (tp->mac_version) { |
| 1262 | case RTL_GIGA_MAC_VER_27: |
| 1263 | case RTL_GIGA_MAC_VER_28: |
| 1264 | case RTL_GIGA_MAC_VER_31: |
| 1265 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1266 | break; |
| 1267 | case RTL_GIGA_MAC_VER_49: |
| 1268 | case RTL_GIGA_MAC_VER_50: |
| 1269 | case RTL_GIGA_MAC_VER_51: |
| 1270 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1271 | break; |
| 1272 | default: |
| 1273 | BUG(); |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| 1277 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1278 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1279 | { |
| 1280 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1281 | |
| 1282 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1283 | } |
| 1284 | |
| 1285 | #define OOB_CMD_RESET 0x00 |
| 1286 | #define OOB_CMD_DRIVER_START 0x05 |
| 1287 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1288 | |
| 1289 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1290 | { |
| 1291 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1292 | } |
| 1293 | |
| 1294 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1295 | { |
| 1296 | u16 reg; |
| 1297 | |
| 1298 | reg = rtl8168_get_ocp_reg(tp); |
| 1299 | |
| 1300 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1301 | } |
| 1302 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1303 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1304 | { |
| 1305 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1306 | } |
| 1307 | |
| 1308 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1309 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1310 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1313 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1314 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1315 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1316 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1317 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1318 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1321 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1322 | { |
| 1323 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1324 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1325 | } |
| 1326 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1327 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1328 | { |
| 1329 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1330 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1331 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1332 | } |
| 1333 | |
| 1334 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1335 | { |
| 1336 | switch (tp->mac_version) { |
| 1337 | case RTL_GIGA_MAC_VER_27: |
| 1338 | case RTL_GIGA_MAC_VER_28: |
| 1339 | case RTL_GIGA_MAC_VER_31: |
| 1340 | rtl8168dp_driver_start(tp); |
| 1341 | break; |
| 1342 | case RTL_GIGA_MAC_VER_49: |
| 1343 | case RTL_GIGA_MAC_VER_50: |
| 1344 | case RTL_GIGA_MAC_VER_51: |
| 1345 | rtl8168ep_driver_start(tp); |
| 1346 | break; |
| 1347 | default: |
| 1348 | BUG(); |
| 1349 | break; |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1354 | { |
| 1355 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1356 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1357 | } |
| 1358 | |
| 1359 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1360 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1361 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1362 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1363 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1364 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1365 | } |
| 1366 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1367 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1368 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1369 | switch (tp->mac_version) { |
| 1370 | case RTL_GIGA_MAC_VER_27: |
| 1371 | case RTL_GIGA_MAC_VER_28: |
| 1372 | case RTL_GIGA_MAC_VER_31: |
| 1373 | rtl8168dp_driver_stop(tp); |
| 1374 | break; |
| 1375 | case RTL_GIGA_MAC_VER_49: |
| 1376 | case RTL_GIGA_MAC_VER_50: |
| 1377 | case RTL_GIGA_MAC_VER_51: |
| 1378 | rtl8168ep_driver_stop(tp); |
| 1379 | break; |
| 1380 | default: |
| 1381 | BUG(); |
| 1382 | break; |
| 1383 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1384 | } |
| 1385 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1386 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1387 | { |
| 1388 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1389 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1390 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1391 | } |
| 1392 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1393 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1394 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1395 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1396 | } |
| 1397 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1398 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1399 | { |
| 1400 | switch (tp->mac_version) { |
| 1401 | case RTL_GIGA_MAC_VER_27: |
| 1402 | case RTL_GIGA_MAC_VER_28: |
| 1403 | case RTL_GIGA_MAC_VER_31: |
| 1404 | return r8168dp_check_dash(tp); |
| 1405 | case RTL_GIGA_MAC_VER_49: |
| 1406 | case RTL_GIGA_MAC_VER_50: |
| 1407 | case RTL_GIGA_MAC_VER_51: |
| 1408 | return r8168ep_check_dash(tp); |
| 1409 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1410 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1411 | } |
| 1412 | } |
| 1413 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1414 | struct exgmac_reg { |
| 1415 | u16 addr; |
| 1416 | u16 mask; |
| 1417 | u32 val; |
| 1418 | }; |
| 1419 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1420 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1421 | const struct exgmac_reg *r, int len) |
| 1422 | { |
| 1423 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1424 | 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] | 1425 | r++; |
| 1426 | } |
| 1427 | } |
| 1428 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1429 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1430 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1431 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1432 | } |
| 1433 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1434 | 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] | 1435 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1436 | 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] | 1437 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1438 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1439 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1442 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1443 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1444 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1448 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1449 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1450 | mmiowb(); |
| 1451 | } |
| 1452 | |
| 1453 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1454 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1455 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1456 | mmiowb(); |
| 1457 | } |
| 1458 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1459 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1460 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1461 | RTL_W16(tp, IntrMask, bits); |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1462 | } |
| 1463 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1464 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1465 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1466 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1467 | |
| 1468 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1469 | { |
| 1470 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1471 | } |
| 1472 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1473 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1475 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1476 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1477 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1480 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1482 | return RTL_R32(tp, TBICSR) & TBIReset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1485 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1487 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1490 | static unsigned int rtl8169_tbi_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1492 | return RTL_R32(tp, TBICSR) & TBILinkOk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1495 | static unsigned int rtl8169_xmii_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1497 | return RTL_R8(tp, PHYstatus) & LinkStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1500 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1502 | RTL_W32(tp, TBICSR, RTL_R32(tp, TBICSR) | TBIReset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1505 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | { |
| 1507 | unsigned int val; |
| 1508 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1509 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1510 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1513 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1514 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1515 | struct net_device *dev = tp->dev; |
| 1516 | |
| 1517 | if (!netif_running(dev)) |
| 1518 | return; |
| 1519 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1520 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1521 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1522 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1523 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1524 | ERIAR_EXGMAC); |
| 1525 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1526 | ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1527 | } else if (RTL_R8(tp, PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1528 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1529 | ERIAR_EXGMAC); |
| 1530 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1531 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1532 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1533 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1534 | ERIAR_EXGMAC); |
| 1535 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1536 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1537 | } |
| 1538 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1539 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1540 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1541 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1542 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1543 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1544 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1545 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1546 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1547 | ERIAR_EXGMAC); |
| 1548 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1549 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1550 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1551 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1552 | ERIAR_EXGMAC); |
| 1553 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1554 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1555 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1556 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1557 | if (RTL_R8(tp, PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1558 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1559 | ERIAR_EXGMAC); |
| 1560 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1561 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1562 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1563 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1564 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1565 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1569 | static void rtl8169_check_link_status(struct net_device *dev, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1570 | struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1572 | struct device *d = tp_to_dev(tp); |
| 1573 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1574 | if (tp->link_ok(tp)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1575 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1576 | /* This is to cancel a scheduled suspend if there's one. */ |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1577 | pm_request_resume(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1579 | if (net_ratelimit()) |
| 1580 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1581 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1583 | netif_info(tp, ifdown, dev, "link down\n"); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1584 | pm_runtime_idle(d); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1588 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1589 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1590 | /* Currently we only enable WoL if explicitly told by userspace to circumvent |
| 1591 | * issues on certain platforms, see commit bde135a672bf ("r8169: only enable |
| 1592 | * PCI wakeups when WOL is active"). Let's keep __rtl8169_get_wol() for the |
| 1593 | * case that we want to respect BIOS settings again. |
| 1594 | */ |
| 1595 | #if 0 |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1596 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1597 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1598 | u8 options; |
| 1599 | u32 wolopts = 0; |
| 1600 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1601 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1602 | if (!(options & PMEnable)) |
| 1603 | return 0; |
| 1604 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1605 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1606 | if (options & LinkUp) |
| 1607 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1608 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1609 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1610 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1611 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1612 | wolopts |= WAKE_MAGIC; |
| 1613 | break; |
| 1614 | default: |
| 1615 | if (options & MagicPacket) |
| 1616 | wolopts |= WAKE_MAGIC; |
| 1617 | break; |
| 1618 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1619 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1620 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1621 | if (options & UWF) |
| 1622 | wolopts |= WAKE_UCAST; |
| 1623 | if (options & BWF) |
| 1624 | wolopts |= WAKE_BCAST; |
| 1625 | if (options & MWF) |
| 1626 | wolopts |= WAKE_MCAST; |
| 1627 | |
| 1628 | return wolopts; |
| 1629 | } |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1630 | #endif |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1631 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1632 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1633 | { |
| 1634 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1635 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1636 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1637 | wol->supported = WAKE_ANY; |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1638 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1639 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1640 | } |
| 1641 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1642 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1643 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1644 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1645 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1646 | u32 opt; |
| 1647 | u16 reg; |
| 1648 | u8 mask; |
| 1649 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1650 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1651 | { WAKE_UCAST, Config5, UWF }, |
| 1652 | { WAKE_BCAST, Config5, BWF }, |
| 1653 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1654 | { WAKE_ANY, Config5, LanWake }, |
| 1655 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1656 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1657 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1658 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1659 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1660 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1661 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1662 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1663 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1664 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1665 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1666 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1667 | 0x0dc, |
| 1668 | ERIAR_MASK_0100, |
| 1669 | MagicPacket_v2, |
| 1670 | 0x0000, |
| 1671 | ERIAR_EXGMAC); |
| 1672 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1673 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1674 | 0x0dc, |
| 1675 | ERIAR_MASK_0100, |
| 1676 | 0x0000, |
| 1677 | MagicPacket_v2, |
| 1678 | ERIAR_EXGMAC); |
| 1679 | break; |
| 1680 | default: |
| 1681 | tmp = ARRAY_SIZE(cfg); |
| 1682 | break; |
| 1683 | } |
| 1684 | |
| 1685 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1686 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1687 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1688 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1689 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1690 | } |
| 1691 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1692 | switch (tp->mac_version) { |
| 1693 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1694 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1695 | if (wolopts) |
| 1696 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1697 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1698 | break; |
| 1699 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1700 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1701 | if (wolopts) |
| 1702 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1703 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1704 | break; |
| 1705 | } |
| 1706 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1707 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1711 | { |
| 1712 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1713 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1714 | |
| 1715 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1716 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1717 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1718 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1719 | tp->saved_wolopts = wol->wolopts & WAKE_ANY; |
| 1720 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1721 | if (pm_runtime_active(d)) |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1722 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1723 | |
| 1724 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1725 | |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 1726 | device_set_wakeup_enable(d, tp->saved_wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1727 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1728 | pm_runtime_put_noidle(d); |
| 1729 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1730 | return 0; |
| 1731 | } |
| 1732 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1733 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1734 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1735 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1736 | } |
| 1737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1739 | struct ethtool_drvinfo *info) |
| 1740 | { |
| 1741 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1742 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1744 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1745 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1746 | 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] | 1747 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1748 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1749 | strlcpy(info->fw_version, rtl_fw->version, |
| 1750 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1754 | { |
| 1755 | return R8169_REGS_SIZE; |
| 1756 | } |
| 1757 | |
| 1758 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1759 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | { |
| 1761 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | int ret = 0; |
| 1763 | u32 reg; |
| 1764 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1765 | reg = RTL_R32(tp, TBICSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1767 | (duplex == DUPLEX_FULL)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1768 | RTL_W32(tp, TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | } else if (autoneg == AUTONEG_ENABLE) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1770 | RTL_W32(tp, TBICSR, reg | TBINwEnable | TBINwRestart); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1772 | netif_warn(tp, link, dev, |
| 1773 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | ret = -EOPNOTSUPP; |
| 1775 | } |
| 1776 | |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1781 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | { |
| 1783 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1784 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1785 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1787 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
| 1789 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1790 | int auto_nego; |
| 1791 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1792 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1793 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1794 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1795 | |
| 1796 | if (adv & ADVERTISED_10baseT_Half) |
| 1797 | auto_nego |= ADVERTISE_10HALF; |
| 1798 | if (adv & ADVERTISED_10baseT_Full) |
| 1799 | auto_nego |= ADVERTISE_10FULL; |
| 1800 | if (adv & ADVERTISED_100baseT_Half) |
| 1801 | auto_nego |= ADVERTISE_100HALF; |
| 1802 | if (adv & ADVERTISED_100baseT_Full) |
| 1803 | auto_nego |= ADVERTISE_100FULL; |
| 1804 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1805 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1806 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1807 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1808 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1809 | |
| 1810 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1811 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1812 | if (adv & ADVERTISED_1000baseT_Half) |
| 1813 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1814 | if (adv & ADVERTISED_1000baseT_Full) |
| 1815 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1816 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1817 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1818 | netif_info(tp, link, dev, |
| 1819 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1820 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1823 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1824 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1825 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1826 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1827 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1828 | if (speed == SPEED_10) |
| 1829 | bmcr = 0; |
| 1830 | else if (speed == SPEED_100) |
| 1831 | bmcr = BMCR_SPEED100; |
| 1832 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1833 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1834 | |
| 1835 | if (duplex == DUPLEX_FULL) |
| 1836 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1837 | } |
| 1838 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1839 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1840 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1841 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1842 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1843 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1844 | rtl_writephy(tp, 0x17, 0x2138); |
| 1845 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1846 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1847 | rtl_writephy(tp, 0x17, 0x2108); |
| 1848 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1852 | rc = 0; |
| 1853 | out: |
| 1854 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1858 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | { |
| 1860 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1861 | int ret; |
| 1862 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1863 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1864 | if (ret < 0) |
| 1865 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1867 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 1868 | (advertising & ADVERTISED_1000baseT_Full) && |
| 1869 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1871 | } |
| 1872 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | return ret; |
| 1874 | } |
| 1875 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1876 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1877 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1879 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1880 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1881 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1882 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1884 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1885 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1886 | features &= ~NETIF_F_IP_CSUM; |
| 1887 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1888 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1891 | static int rtl8169_set_features(struct net_device *dev, |
| 1892 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | { |
| 1894 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1895 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1897 | rtl_lock_work(tp); |
| 1898 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1899 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1900 | if (features & NETIF_F_RXALL) |
| 1901 | rx_config |= (AcceptErr | AcceptRunt); |
| 1902 | else |
| 1903 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1905 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1906 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1907 | if (features & NETIF_F_RXCSUM) |
| 1908 | tp->cp_cmd |= RxChkSum; |
| 1909 | else |
| 1910 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1911 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1912 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1913 | tp->cp_cmd |= RxVlan; |
| 1914 | else |
| 1915 | tp->cp_cmd &= ~RxVlan; |
| 1916 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1917 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1918 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1920 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
| 1922 | return 0; |
| 1923 | } |
| 1924 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1925 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1927 | return (skb_vlan_tag_present(skb)) ? |
| 1928 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1931 | 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] | 1932 | { |
| 1933 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1935 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1936 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1939 | static int rtl8169_get_link_ksettings_tbi(struct net_device *dev, |
| 1940 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
| 1942 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | u32 status; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1944 | u32 supported, advertising; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1946 | supported = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1948 | cmd->base.port = PORT_FIBRE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1950 | status = RTL_R32(tp, TBICSR); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1951 | advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1952 | cmd->base.autoneg = !!(status & TBINwEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1954 | cmd->base.speed = SPEED_1000; |
| 1955 | cmd->base.duplex = DUPLEX_FULL; /* Always set */ |
| 1956 | |
| 1957 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 1958 | supported); |
| 1959 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 1960 | advertising); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1961 | |
| 1962 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1965 | static int rtl8169_get_link_ksettings_xmii(struct net_device *dev, |
| 1966 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | { |
| 1968 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 1970 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 1971 | |
| 1972 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1975 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 1976 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | { |
| 1978 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1979 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1981 | rtl_lock_work(tp); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1982 | rc = tp->get_link_ksettings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1983 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1985 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 1988 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 1989 | const struct ethtool_link_ksettings *cmd) |
| 1990 | { |
| 1991 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1992 | int rc; |
| 1993 | u32 advertising; |
| 1994 | |
| 1995 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 1996 | cmd->link_modes.advertising)) |
| 1997 | return -EINVAL; |
| 1998 | |
| 1999 | del_timer_sync(&tp->timer); |
| 2000 | |
| 2001 | rtl_lock_work(tp); |
| 2002 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 2003 | cmd->base.duplex, advertising); |
| 2004 | rtl_unlock_work(tp); |
| 2005 | |
| 2006 | return rc; |
| 2007 | } |
| 2008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2010 | void *p) |
| 2011 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2012 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2013 | u32 __iomem *data = tp->mmio_addr; |
| 2014 | u32 *dw = p; |
| 2015 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2017 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2018 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 2019 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2020 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2023 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 2024 | { |
| 2025 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2026 | |
| 2027 | return tp->msg_enable; |
| 2028 | } |
| 2029 | |
| 2030 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 2031 | { |
| 2032 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2033 | |
| 2034 | tp->msg_enable = value; |
| 2035 | } |
| 2036 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2037 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2038 | "tx_packets", |
| 2039 | "rx_packets", |
| 2040 | "tx_errors", |
| 2041 | "rx_errors", |
| 2042 | "rx_missed", |
| 2043 | "align_errors", |
| 2044 | "tx_single_collisions", |
| 2045 | "tx_multi_collisions", |
| 2046 | "unicast", |
| 2047 | "broadcast", |
| 2048 | "multicast", |
| 2049 | "tx_aborted", |
| 2050 | "tx_underrun", |
| 2051 | }; |
| 2052 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2053 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2054 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2055 | switch (sset) { |
| 2056 | case ETH_SS_STATS: |
| 2057 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2058 | default: |
| 2059 | return -EOPNOTSUPP; |
| 2060 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2061 | } |
| 2062 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2063 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2064 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2065 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2066 | } |
| 2067 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2068 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2069 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2070 | dma_addr_t paddr = tp->counters_phys_addr; |
| 2071 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2072 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2073 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 2074 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2075 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2076 | RTL_W32(tp, CounterAddrLow, cmd); |
| 2077 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2078 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2079 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2080 | } |
| 2081 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2082 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2083 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2084 | /* |
| 2085 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 2086 | * tally counters. |
| 2087 | */ |
| 2088 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 2089 | return true; |
| 2090 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2091 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2092 | } |
| 2093 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2094 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2095 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2096 | /* |
| 2097 | * Some chips are unable to dump tally counters when the receiver |
| 2098 | * is disabled. |
| 2099 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2100 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2101 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2102 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2103 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2104 | } |
| 2105 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2106 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2107 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2108 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2109 | bool ret = false; |
| 2110 | |
| 2111 | /* |
| 2112 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2113 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2114 | * reset by a power cycle, while the counter values collected by the |
| 2115 | * driver are reset at every driver unload/load cycle. |
| 2116 | * |
| 2117 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2118 | * values, we collect the initial values at first open(*) and use them |
| 2119 | * as offsets to normalize the values returned by @get_stats64. |
| 2120 | * |
| 2121 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2122 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2123 | * set at open time by rtl_hw_start. |
| 2124 | */ |
| 2125 | |
| 2126 | if (tp->tc_offset.inited) |
| 2127 | return true; |
| 2128 | |
| 2129 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2130 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2131 | ret = true; |
| 2132 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2133 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2134 | ret = true; |
| 2135 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2136 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2137 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2138 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2139 | tp->tc_offset.inited = true; |
| 2140 | |
| 2141 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2142 | } |
| 2143 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2144 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2145 | struct ethtool_stats *stats, u64 *data) |
| 2146 | { |
| 2147 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 2148 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2149 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2150 | |
| 2151 | ASSERT_RTNL(); |
| 2152 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2153 | pm_runtime_get_noresume(d); |
| 2154 | |
| 2155 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2156 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2157 | |
| 2158 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2159 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2160 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2161 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2162 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2163 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2164 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2165 | data[5] = le16_to_cpu(counters->align_errors); |
| 2166 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2167 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2168 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2169 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2170 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2171 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2172 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2173 | } |
| 2174 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2175 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2176 | { |
| 2177 | switch(stringset) { |
| 2178 | case ETH_SS_STATS: |
| 2179 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2180 | break; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2184 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2185 | { |
| 2186 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2187 | |
| 2188 | return mii_nway_restart(&tp->mii); |
| 2189 | } |
| 2190 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2191 | /* |
| 2192 | * Interrupt coalescing |
| 2193 | * |
| 2194 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2195 | * > 8169, 8168 and 810x line of chipsets |
| 2196 | * |
| 2197 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2198 | * |
| 2199 | * > 2 - the Tx timer unit at gigabit speed |
| 2200 | * |
| 2201 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2202 | * (0xe0) bit 1 and bit 0. |
| 2203 | * |
| 2204 | * For 8169 |
| 2205 | * bit[1:0] \ speed 1000M 100M 10M |
| 2206 | * 0 0 320ns 2.56us 40.96us |
| 2207 | * 0 1 2.56us 20.48us 327.7us |
| 2208 | * 1 0 5.12us 40.96us 655.4us |
| 2209 | * 1 1 10.24us 81.92us 1.31ms |
| 2210 | * |
| 2211 | * For the other |
| 2212 | * bit[1:0] \ speed 1000M 100M 10M |
| 2213 | * 0 0 5us 2.56us 40.96us |
| 2214 | * 0 1 40us 20.48us 327.7us |
| 2215 | * 1 0 80us 40.96us 655.4us |
| 2216 | * 1 1 160us 81.92us 1.31ms |
| 2217 | */ |
| 2218 | |
| 2219 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2220 | struct rtl_coalesce_scale { |
| 2221 | /* Rx / Tx */ |
| 2222 | u32 nsecs[2]; |
| 2223 | }; |
| 2224 | |
| 2225 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2226 | struct rtl_coalesce_info { |
| 2227 | u32 speed; |
| 2228 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2229 | }; |
| 2230 | |
| 2231 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2232 | #define rxtx_x1822(r, t) { \ |
| 2233 | {{(r), (t)}}, \ |
| 2234 | {{(r)*8, (t)*8}}, \ |
| 2235 | {{(r)*8*2, (t)*8*2}}, \ |
| 2236 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2237 | } |
| 2238 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2239 | /* speed delays: rx00 tx00 */ |
| 2240 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2241 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2242 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2243 | { 0 }, |
| 2244 | }; |
| 2245 | |
| 2246 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2247 | /* speed delays: rx00 tx00 */ |
| 2248 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2249 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2250 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2251 | { 0 }, |
| 2252 | }; |
| 2253 | #undef rxtx_x1822 |
| 2254 | |
| 2255 | /* get rx/tx scale vector corresponding to current speed */ |
| 2256 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2257 | { |
| 2258 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2259 | struct ethtool_link_ksettings ecmd; |
| 2260 | const struct rtl_coalesce_info *ci; |
| 2261 | int rc; |
| 2262 | |
| 2263 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2264 | if (rc < 0) |
| 2265 | return ERR_PTR(rc); |
| 2266 | |
| 2267 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2268 | if (ecmd.base.speed == ci->speed) { |
| 2269 | return ci; |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | return ERR_PTR(-ELNRNG); |
| 2274 | } |
| 2275 | |
| 2276 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2277 | { |
| 2278 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2279 | const struct rtl_coalesce_info *ci; |
| 2280 | const struct rtl_coalesce_scale *scale; |
| 2281 | struct { |
| 2282 | u32 *max_frames; |
| 2283 | u32 *usecs; |
| 2284 | } coal_settings [] = { |
| 2285 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2286 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2287 | }, *p = coal_settings; |
| 2288 | int i; |
| 2289 | u16 w; |
| 2290 | |
| 2291 | memset(ec, 0, sizeof(*ec)); |
| 2292 | |
| 2293 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2294 | ci = rtl_coalesce_info(dev); |
| 2295 | if (IS_ERR(ci)) |
| 2296 | return PTR_ERR(ci); |
| 2297 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 2298 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2299 | |
| 2300 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2301 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2302 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2303 | w >>= RTL_COALESCE_SHIFT; |
| 2304 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2305 | } |
| 2306 | |
| 2307 | for (i = 0; i < 2; i++) { |
| 2308 | p = coal_settings + i; |
| 2309 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2310 | |
| 2311 | /* |
| 2312 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2313 | * max_frames to 0. |
| 2314 | */ |
| 2315 | if (!*p->usecs && !*p->max_frames) |
| 2316 | *p->max_frames = 1; |
| 2317 | } |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | |
| 2322 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2323 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2324 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2325 | { |
| 2326 | const struct rtl_coalesce_info *ci; |
| 2327 | u16 i; |
| 2328 | |
| 2329 | ci = rtl_coalesce_info(dev); |
| 2330 | if (IS_ERR(ci)) |
| 2331 | return ERR_CAST(ci); |
| 2332 | |
| 2333 | for (i = 0; i < 4; i++) { |
| 2334 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2335 | ci->scalev[i].nsecs[1]); |
| 2336 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2337 | *cp01 = i; |
| 2338 | return &ci->scalev[i]; |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | return ERR_PTR(-EINVAL); |
| 2343 | } |
| 2344 | |
| 2345 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2346 | { |
| 2347 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2348 | const struct rtl_coalesce_scale *scale; |
| 2349 | struct { |
| 2350 | u32 frames; |
| 2351 | u32 usecs; |
| 2352 | } coal_settings [] = { |
| 2353 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2354 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2355 | }, *p = coal_settings; |
| 2356 | u16 w = 0, cp01; |
| 2357 | int i; |
| 2358 | |
| 2359 | scale = rtl_coalesce_choose_scale(dev, |
| 2360 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2361 | if (IS_ERR(scale)) |
| 2362 | return PTR_ERR(scale); |
| 2363 | |
| 2364 | for (i = 0; i < 2; i++, p++) { |
| 2365 | u32 units; |
| 2366 | |
| 2367 | /* |
| 2368 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2369 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2370 | * |
| 2371 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2372 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2373 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2374 | * |
| 2375 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2376 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2377 | * we'll reject it below in `frames % 4 != 0`. |
| 2378 | */ |
| 2379 | if (p->frames == 1) { |
| 2380 | p->frames = 0; |
| 2381 | } |
| 2382 | |
| 2383 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2384 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2385 | return -EINVAL; |
| 2386 | |
| 2387 | w <<= RTL_COALESCE_SHIFT; |
| 2388 | w |= units; |
| 2389 | w <<= RTL_COALESCE_SHIFT; |
| 2390 | w |= p->frames >> 2; |
| 2391 | } |
| 2392 | |
| 2393 | rtl_lock_work(tp); |
| 2394 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2395 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2396 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 2397 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2398 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2399 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2400 | |
| 2401 | rtl_unlock_work(tp); |
| 2402 | |
| 2403 | return 0; |
| 2404 | } |
| 2405 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2406 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2408 | .get_regs_len = rtl8169_get_regs_len, |
| 2409 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2410 | .get_coalesce = rtl_get_coalesce, |
| 2411 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2412 | .get_msglevel = rtl8169_get_msglevel, |
| 2413 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2415 | .get_wol = rtl8169_get_wol, |
| 2416 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2417 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2418 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2419 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2420 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2421 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2422 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2423 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | }; |
| 2425 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2426 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2427 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2429 | /* |
| 2430 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2431 | * but they can be identified more specifically through the test below |
| 2432 | * if needed: |
| 2433 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2434 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2435 | * |
| 2436 | * Same thing for the 8101Eb and the 8101Ec: |
| 2437 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2438 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2439 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2440 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2442 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | int mac_version; |
| 2444 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2445 | /* 8168EP family. */ |
| 2446 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2447 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2448 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2449 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2450 | /* 8168H family. */ |
| 2451 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2452 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2453 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2454 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2455 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2456 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2457 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2458 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2459 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2460 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2461 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2462 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2463 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2464 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2465 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2466 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2467 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2468 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2469 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2470 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2471 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2472 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2473 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2474 | /* 8168DP family. */ |
| 2475 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2476 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2477 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2478 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2479 | /* 8168C family. */ |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2480 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2481 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2482 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2483 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2484 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2485 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2486 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2487 | |
| 2488 | /* 8168B family. */ |
| 2489 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2490 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2491 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2492 | |
| 2493 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2494 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2495 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2496 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2497 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2498 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2499 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2500 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2501 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2502 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2503 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2504 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2505 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2506 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2507 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2508 | /* FIXME: where did these entries come from ? -- FR */ |
| 2509 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2510 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2511 | |
| 2512 | /* 8110 family. */ |
| 2513 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2514 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2515 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2516 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2517 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2518 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2519 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2520 | /* Catch-all */ |
| 2521 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2522 | }; |
| 2523 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | u32 reg; |
| 2525 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2526 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2527 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | p++; |
| 2529 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2530 | |
| 2531 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2532 | dev_notice(tp_to_dev(tp), |
| 2533 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2534 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2535 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2536 | tp->mac_version = tp->mii.supports_gmii ? |
| 2537 | RTL_GIGA_MAC_VER_42 : |
| 2538 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2539 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2540 | tp->mac_version = tp->mii.supports_gmii ? |
| 2541 | RTL_GIGA_MAC_VER_45 : |
| 2542 | RTL_GIGA_MAC_VER_47; |
| 2543 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2544 | tp->mac_version = tp->mii.supports_gmii ? |
| 2545 | RTL_GIGA_MAC_VER_46 : |
| 2546 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2551 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2552 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2555 | struct phy_reg { |
| 2556 | u16 reg; |
| 2557 | u16 val; |
| 2558 | }; |
| 2559 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2560 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2561 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2562 | { |
| 2563 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2564 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2565 | regs++; |
| 2566 | } |
| 2567 | } |
| 2568 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2569 | #define PHY_READ 0x00000000 |
| 2570 | #define PHY_DATA_OR 0x10000000 |
| 2571 | #define PHY_DATA_AND 0x20000000 |
| 2572 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2573 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2574 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2575 | #define PHY_WRITE 0x80000000 |
| 2576 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2577 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2578 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2579 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2580 | #define PHY_SKIPN 0xd0000000 |
| 2581 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2582 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2583 | struct fw_info { |
| 2584 | u32 magic; |
| 2585 | char version[RTL_VER_SIZE]; |
| 2586 | __le32 fw_start; |
| 2587 | __le32 fw_len; |
| 2588 | u8 chksum; |
| 2589 | } __packed; |
| 2590 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2591 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2592 | |
| 2593 | 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] | 2594 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2595 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2596 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2597 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2598 | char *version = rtl_fw->version; |
| 2599 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2600 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2601 | if (fw->size < FW_OPCODE_SIZE) |
| 2602 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2603 | |
| 2604 | if (!fw_info->magic) { |
| 2605 | size_t i, size, start; |
| 2606 | u8 checksum = 0; |
| 2607 | |
| 2608 | if (fw->size < sizeof(*fw_info)) |
| 2609 | goto out; |
| 2610 | |
| 2611 | for (i = 0; i < fw->size; i++) |
| 2612 | checksum += fw->data[i]; |
| 2613 | if (checksum != 0) |
| 2614 | goto out; |
| 2615 | |
| 2616 | start = le32_to_cpu(fw_info->fw_start); |
| 2617 | if (start > fw->size) |
| 2618 | goto out; |
| 2619 | |
| 2620 | size = le32_to_cpu(fw_info->fw_len); |
| 2621 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2622 | goto out; |
| 2623 | |
| 2624 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2625 | |
| 2626 | pa->code = (__le32 *)(fw->data + start); |
| 2627 | pa->size = size; |
| 2628 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2629 | if (fw->size % FW_OPCODE_SIZE) |
| 2630 | goto out; |
| 2631 | |
| 2632 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2633 | |
| 2634 | pa->code = (__le32 *)fw->data; |
| 2635 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2636 | } |
| 2637 | version[RTL_VER_SIZE - 1] = 0; |
| 2638 | |
| 2639 | rc = true; |
| 2640 | out: |
| 2641 | return rc; |
| 2642 | } |
| 2643 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2644 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2645 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2646 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2647 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2648 | size_t index; |
| 2649 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2650 | for (index = 0; index < pa->size; index++) { |
| 2651 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2652 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2653 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2654 | switch(action & 0xf0000000) { |
| 2655 | case PHY_READ: |
| 2656 | case PHY_DATA_OR: |
| 2657 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2658 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2659 | case PHY_CLEAR_READCOUNT: |
| 2660 | case PHY_WRITE: |
| 2661 | case PHY_WRITE_PREVIOUS: |
| 2662 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2665 | case PHY_BJMPN: |
| 2666 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2667 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2668 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2669 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2670 | } |
| 2671 | break; |
| 2672 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2673 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2674 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2675 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2676 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2677 | } |
| 2678 | break; |
| 2679 | case PHY_COMP_EQ_SKIPN: |
| 2680 | case PHY_COMP_NEQ_SKIPN: |
| 2681 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2682 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2683 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2684 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2685 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2686 | } |
| 2687 | break; |
| 2688 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2689 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2690 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2691 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2692 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2693 | } |
| 2694 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2695 | rc = true; |
| 2696 | out: |
| 2697 | return rc; |
| 2698 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2699 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2700 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2701 | { |
| 2702 | struct net_device *dev = tp->dev; |
| 2703 | int rc = -EINVAL; |
| 2704 | |
| 2705 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2706 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2707 | goto out; |
| 2708 | } |
| 2709 | |
| 2710 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2711 | rc = 0; |
| 2712 | out: |
| 2713 | return rc; |
| 2714 | } |
| 2715 | |
| 2716 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2717 | { |
| 2718 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2719 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2720 | u32 predata, count; |
| 2721 | size_t index; |
| 2722 | |
| 2723 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2724 | org.write = ops->write; |
| 2725 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2726 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2727 | for (index = 0; index < pa->size; ) { |
| 2728 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2729 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2730 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2731 | |
| 2732 | if (!action) |
| 2733 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2734 | |
| 2735 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2736 | case PHY_READ: |
| 2737 | predata = rtl_readphy(tp, regno); |
| 2738 | count++; |
| 2739 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2740 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2741 | case PHY_DATA_OR: |
| 2742 | predata |= data; |
| 2743 | index++; |
| 2744 | break; |
| 2745 | case PHY_DATA_AND: |
| 2746 | predata &= data; |
| 2747 | index++; |
| 2748 | break; |
| 2749 | case PHY_BJMPN: |
| 2750 | index -= regno; |
| 2751 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2752 | case PHY_MDIO_CHG: |
| 2753 | if (data == 0) { |
| 2754 | ops->write = org.write; |
| 2755 | ops->read = org.read; |
| 2756 | } else if (data == 1) { |
| 2757 | ops->write = mac_mcu_write; |
| 2758 | ops->read = mac_mcu_read; |
| 2759 | } |
| 2760 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2761 | index++; |
| 2762 | break; |
| 2763 | case PHY_CLEAR_READCOUNT: |
| 2764 | count = 0; |
| 2765 | index++; |
| 2766 | break; |
| 2767 | case PHY_WRITE: |
| 2768 | rtl_writephy(tp, regno, data); |
| 2769 | index++; |
| 2770 | break; |
| 2771 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2772 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2773 | break; |
| 2774 | case PHY_COMP_EQ_SKIPN: |
| 2775 | if (predata == data) |
| 2776 | index += regno; |
| 2777 | index++; |
| 2778 | break; |
| 2779 | case PHY_COMP_NEQ_SKIPN: |
| 2780 | if (predata != data) |
| 2781 | index += regno; |
| 2782 | index++; |
| 2783 | break; |
| 2784 | case PHY_WRITE_PREVIOUS: |
| 2785 | rtl_writephy(tp, regno, predata); |
| 2786 | index++; |
| 2787 | break; |
| 2788 | case PHY_SKIPN: |
| 2789 | index += regno + 1; |
| 2790 | break; |
| 2791 | case PHY_DELAY_MS: |
| 2792 | mdelay(data); |
| 2793 | index++; |
| 2794 | break; |
| 2795 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2796 | default: |
| 2797 | BUG(); |
| 2798 | } |
| 2799 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2800 | |
| 2801 | ops->write = org.write; |
| 2802 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2805 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2806 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2807 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2808 | release_firmware(tp->rtl_fw->fw); |
| 2809 | kfree(tp->rtl_fw); |
| 2810 | } |
| 2811 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2814 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2815 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2816 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2817 | |
| 2818 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2819 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2820 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2824 | { |
| 2825 | if (rtl_readphy(tp, reg) != val) |
| 2826 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2827 | else |
| 2828 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2831 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2833 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2834 | { 0x1f, 0x0001 }, |
| 2835 | { 0x06, 0x006e }, |
| 2836 | { 0x08, 0x0708 }, |
| 2837 | { 0x15, 0x4000 }, |
| 2838 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2840 | { 0x1f, 0x0001 }, |
| 2841 | { 0x03, 0x00a1 }, |
| 2842 | { 0x02, 0x0008 }, |
| 2843 | { 0x01, 0x0120 }, |
| 2844 | { 0x00, 0x1000 }, |
| 2845 | { 0x04, 0x0800 }, |
| 2846 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2848 | { 0x03, 0xff41 }, |
| 2849 | { 0x02, 0xdf60 }, |
| 2850 | { 0x01, 0x0140 }, |
| 2851 | { 0x00, 0x0077 }, |
| 2852 | { 0x04, 0x7800 }, |
| 2853 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2855 | { 0x03, 0x802f }, |
| 2856 | { 0x02, 0x4f02 }, |
| 2857 | { 0x01, 0x0409 }, |
| 2858 | { 0x00, 0xf0f9 }, |
| 2859 | { 0x04, 0x9800 }, |
| 2860 | { 0x04, 0x9000 }, |
| 2861 | |
| 2862 | { 0x03, 0xdf01 }, |
| 2863 | { 0x02, 0xdf20 }, |
| 2864 | { 0x01, 0xff95 }, |
| 2865 | { 0x00, 0xba00 }, |
| 2866 | { 0x04, 0xa800 }, |
| 2867 | { 0x04, 0xa000 }, |
| 2868 | |
| 2869 | { 0x03, 0xff41 }, |
| 2870 | { 0x02, 0xdf20 }, |
| 2871 | { 0x01, 0x0140 }, |
| 2872 | { 0x00, 0x00bb }, |
| 2873 | { 0x04, 0xb800 }, |
| 2874 | { 0x04, 0xb000 }, |
| 2875 | |
| 2876 | { 0x03, 0xdf41 }, |
| 2877 | { 0x02, 0xdc60 }, |
| 2878 | { 0x01, 0x6340 }, |
| 2879 | { 0x00, 0x007d }, |
| 2880 | { 0x04, 0xd800 }, |
| 2881 | { 0x04, 0xd000 }, |
| 2882 | |
| 2883 | { 0x03, 0xdf01 }, |
| 2884 | { 0x02, 0xdf20 }, |
| 2885 | { 0x01, 0x100a }, |
| 2886 | { 0x00, 0xa0ff }, |
| 2887 | { 0x04, 0xf800 }, |
| 2888 | { 0x04, 0xf000 }, |
| 2889 | |
| 2890 | { 0x1f, 0x0000 }, |
| 2891 | { 0x0b, 0x0000 }, |
| 2892 | { 0x00, 0x9200 } |
| 2893 | }; |
| 2894 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2895 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2898 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2899 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2900 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2901 | { 0x1f, 0x0002 }, |
| 2902 | { 0x01, 0x90d0 }, |
| 2903 | { 0x1f, 0x0000 } |
| 2904 | }; |
| 2905 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2906 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2907 | } |
| 2908 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2909 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2910 | { |
| 2911 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2912 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2913 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2914 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2915 | return; |
| 2916 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2917 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2918 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2919 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2920 | } |
| 2921 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2922 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2923 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2924 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2925 | { 0x1f, 0x0001 }, |
| 2926 | { 0x04, 0x0000 }, |
| 2927 | { 0x03, 0x00a1 }, |
| 2928 | { 0x02, 0x0008 }, |
| 2929 | { 0x01, 0x0120 }, |
| 2930 | { 0x00, 0x1000 }, |
| 2931 | { 0x04, 0x0800 }, |
| 2932 | { 0x04, 0x9000 }, |
| 2933 | { 0x03, 0x802f }, |
| 2934 | { 0x02, 0x4f02 }, |
| 2935 | { 0x01, 0x0409 }, |
| 2936 | { 0x00, 0xf099 }, |
| 2937 | { 0x04, 0x9800 }, |
| 2938 | { 0x04, 0xa000 }, |
| 2939 | { 0x03, 0xdf01 }, |
| 2940 | { 0x02, 0xdf20 }, |
| 2941 | { 0x01, 0xff95 }, |
| 2942 | { 0x00, 0xba00 }, |
| 2943 | { 0x04, 0xa800 }, |
| 2944 | { 0x04, 0xf000 }, |
| 2945 | { 0x03, 0xdf01 }, |
| 2946 | { 0x02, 0xdf20 }, |
| 2947 | { 0x01, 0x101a }, |
| 2948 | { 0x00, 0xa0ff }, |
| 2949 | { 0x04, 0xf800 }, |
| 2950 | { 0x04, 0x0000 }, |
| 2951 | { 0x1f, 0x0000 }, |
| 2952 | |
| 2953 | { 0x1f, 0x0001 }, |
| 2954 | { 0x10, 0xf41b }, |
| 2955 | { 0x14, 0xfb54 }, |
| 2956 | { 0x18, 0xf5c7 }, |
| 2957 | { 0x1f, 0x0000 }, |
| 2958 | |
| 2959 | { 0x1f, 0x0001 }, |
| 2960 | { 0x17, 0x0cc0 }, |
| 2961 | { 0x1f, 0x0000 } |
| 2962 | }; |
| 2963 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2964 | 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] | 2965 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2966 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2969 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2970 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2971 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2972 | { 0x1f, 0x0001 }, |
| 2973 | { 0x04, 0x0000 }, |
| 2974 | { 0x03, 0x00a1 }, |
| 2975 | { 0x02, 0x0008 }, |
| 2976 | { 0x01, 0x0120 }, |
| 2977 | { 0x00, 0x1000 }, |
| 2978 | { 0x04, 0x0800 }, |
| 2979 | { 0x04, 0x9000 }, |
| 2980 | { 0x03, 0x802f }, |
| 2981 | { 0x02, 0x4f02 }, |
| 2982 | { 0x01, 0x0409 }, |
| 2983 | { 0x00, 0xf099 }, |
| 2984 | { 0x04, 0x9800 }, |
| 2985 | { 0x04, 0xa000 }, |
| 2986 | { 0x03, 0xdf01 }, |
| 2987 | { 0x02, 0xdf20 }, |
| 2988 | { 0x01, 0xff95 }, |
| 2989 | { 0x00, 0xba00 }, |
| 2990 | { 0x04, 0xa800 }, |
| 2991 | { 0x04, 0xf000 }, |
| 2992 | { 0x03, 0xdf01 }, |
| 2993 | { 0x02, 0xdf20 }, |
| 2994 | { 0x01, 0x101a }, |
| 2995 | { 0x00, 0xa0ff }, |
| 2996 | { 0x04, 0xf800 }, |
| 2997 | { 0x04, 0x0000 }, |
| 2998 | { 0x1f, 0x0000 }, |
| 2999 | |
| 3000 | { 0x1f, 0x0001 }, |
| 3001 | { 0x0b, 0x8480 }, |
| 3002 | { 0x1f, 0x0000 }, |
| 3003 | |
| 3004 | { 0x1f, 0x0001 }, |
| 3005 | { 0x18, 0x67c7 }, |
| 3006 | { 0x04, 0x2000 }, |
| 3007 | { 0x03, 0x002f }, |
| 3008 | { 0x02, 0x4360 }, |
| 3009 | { 0x01, 0x0109 }, |
| 3010 | { 0x00, 0x3022 }, |
| 3011 | { 0x04, 0x2800 }, |
| 3012 | { 0x1f, 0x0000 }, |
| 3013 | |
| 3014 | { 0x1f, 0x0001 }, |
| 3015 | { 0x17, 0x0cc0 }, |
| 3016 | { 0x1f, 0x0000 } |
| 3017 | }; |
| 3018 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3019 | 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] | 3020 | } |
| 3021 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3022 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3023 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3024 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3025 | { 0x10, 0xf41b }, |
| 3026 | { 0x1f, 0x0000 } |
| 3027 | }; |
| 3028 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3029 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3030 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3031 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3032 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3033 | } |
| 3034 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3035 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3036 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3037 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3038 | { 0x1f, 0x0001 }, |
| 3039 | { 0x10, 0xf41b }, |
| 3040 | { 0x1f, 0x0000 } |
| 3041 | }; |
| 3042 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3043 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3044 | } |
| 3045 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3046 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3047 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3048 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3049 | { 0x1f, 0x0000 }, |
| 3050 | { 0x1d, 0x0f00 }, |
| 3051 | { 0x1f, 0x0002 }, |
| 3052 | { 0x0c, 0x1ec8 }, |
| 3053 | { 0x1f, 0x0000 } |
| 3054 | }; |
| 3055 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3056 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3057 | } |
| 3058 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3059 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3060 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3061 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3062 | { 0x1f, 0x0001 }, |
| 3063 | { 0x1d, 0x3d98 }, |
| 3064 | { 0x1f, 0x0000 } |
| 3065 | }; |
| 3066 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3067 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3068 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3069 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3070 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3071 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3072 | } |
| 3073 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3074 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3075 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3076 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 3077 | { 0x1f, 0x0001 }, |
| 3078 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3079 | { 0x1f, 0x0002 }, |
| 3080 | { 0x00, 0x88d4 }, |
| 3081 | { 0x01, 0x82b1 }, |
| 3082 | { 0x03, 0x7002 }, |
| 3083 | { 0x08, 0x9e30 }, |
| 3084 | { 0x09, 0x01f0 }, |
| 3085 | { 0x0a, 0x5500 }, |
| 3086 | { 0x0c, 0x00c8 }, |
| 3087 | { 0x1f, 0x0003 }, |
| 3088 | { 0x12, 0xc096 }, |
| 3089 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3090 | { 0x1f, 0x0000 }, |
| 3091 | { 0x1f, 0x0000 }, |
| 3092 | { 0x09, 0x2000 }, |
| 3093 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3094 | }; |
| 3095 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3096 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3097 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3098 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3099 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3100 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3101 | } |
| 3102 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3103 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3104 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3105 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3106 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3107 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3108 | { 0x03, 0x802f }, |
| 3109 | { 0x02, 0x4f02 }, |
| 3110 | { 0x01, 0x0409 }, |
| 3111 | { 0x00, 0xf099 }, |
| 3112 | { 0x04, 0x9800 }, |
| 3113 | { 0x04, 0x9000 }, |
| 3114 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3115 | { 0x1f, 0x0002 }, |
| 3116 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3117 | { 0x06, 0x0761 }, |
| 3118 | { 0x1f, 0x0003 }, |
| 3119 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3120 | { 0x1f, 0x0000 } |
| 3121 | }; |
| 3122 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3123 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3124 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3125 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3126 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3127 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3128 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3131 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3132 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3133 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3134 | { 0x1f, 0x0001 }, |
| 3135 | { 0x12, 0x2300 }, |
| 3136 | { 0x1d, 0x3d98 }, |
| 3137 | { 0x1f, 0x0002 }, |
| 3138 | { 0x0c, 0x7eb8 }, |
| 3139 | { 0x06, 0x5461 }, |
| 3140 | { 0x1f, 0x0003 }, |
| 3141 | { 0x16, 0x0f0a }, |
| 3142 | { 0x1f, 0x0000 } |
| 3143 | }; |
| 3144 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3145 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3146 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3147 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3148 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3149 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3150 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3153 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3154 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3155 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3156 | } |
| 3157 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3158 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3159 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3160 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3161 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3162 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3163 | { 0x06, 0x4064 }, |
| 3164 | { 0x07, 0x2863 }, |
| 3165 | { 0x08, 0x059c }, |
| 3166 | { 0x09, 0x26b4 }, |
| 3167 | { 0x0a, 0x6a19 }, |
| 3168 | { 0x0b, 0xdcc8 }, |
| 3169 | { 0x10, 0xf06d }, |
| 3170 | { 0x14, 0x7f68 }, |
| 3171 | { 0x18, 0x7fd9 }, |
| 3172 | { 0x1c, 0xf0ff }, |
| 3173 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3174 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3175 | { 0x12, 0xf49f }, |
| 3176 | { 0x13, 0x070b }, |
| 3177 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3178 | { 0x14, 0x94c0 }, |
| 3179 | |
| 3180 | /* |
| 3181 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3182 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3183 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3184 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3185 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3186 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3187 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3188 | { 0x06, 0x5561 }, |
| 3189 | |
| 3190 | /* |
| 3191 | * Can not link to 1Gbps with bad cable |
| 3192 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3193 | */ |
| 3194 | { 0x1f, 0x0001 }, |
| 3195 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3196 | |
| 3197 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3198 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3199 | }; |
| 3200 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3201 | 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] | 3202 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3203 | /* |
| 3204 | * Rx Error Issue |
| 3205 | * Fine Tune Switching regulator parameter |
| 3206 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3207 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3208 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3209 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3210 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3211 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3212 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3213 | { 0x1f, 0x0002 }, |
| 3214 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3215 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3216 | { 0x05, 0x8330 }, |
| 3217 | { 0x06, 0x669a }, |
| 3218 | { 0x1f, 0x0002 } |
| 3219 | }; |
| 3220 | int val; |
| 3221 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3222 | 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] | 3223 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3224 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3225 | |
| 3226 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3227 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3228 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3229 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3230 | }; |
| 3231 | int i; |
| 3232 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3233 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3234 | |
| 3235 | val &= 0xff00; |
| 3236 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3237 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3238 | } |
| 3239 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3240 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3241 | { 0x1f, 0x0002 }, |
| 3242 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3243 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3244 | { 0x05, 0x8330 }, |
| 3245 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3246 | }; |
| 3247 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3248 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3249 | } |
| 3250 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3251 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3252 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3253 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3254 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3255 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3256 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3257 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3258 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3259 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3260 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3261 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3262 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3263 | |
| 3264 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3265 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3266 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3269 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3270 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3271 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3272 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3273 | { 0x1f, 0x0001 }, |
| 3274 | { 0x06, 0x4064 }, |
| 3275 | { 0x07, 0x2863 }, |
| 3276 | { 0x08, 0x059c }, |
| 3277 | { 0x09, 0x26b4 }, |
| 3278 | { 0x0a, 0x6a19 }, |
| 3279 | { 0x0b, 0xdcc8 }, |
| 3280 | { 0x10, 0xf06d }, |
| 3281 | { 0x14, 0x7f68 }, |
| 3282 | { 0x18, 0x7fd9 }, |
| 3283 | { 0x1c, 0xf0ff }, |
| 3284 | { 0x1d, 0x3d9c }, |
| 3285 | { 0x1f, 0x0003 }, |
| 3286 | { 0x12, 0xf49f }, |
| 3287 | { 0x13, 0x070b }, |
| 3288 | { 0x1a, 0x05ad }, |
| 3289 | { 0x14, 0x94c0 }, |
| 3290 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3291 | /* |
| 3292 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3293 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3294 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3295 | { 0x1f, 0x0002 }, |
| 3296 | { 0x06, 0x5561 }, |
| 3297 | { 0x1f, 0x0005 }, |
| 3298 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3299 | { 0x06, 0x5561 }, |
| 3300 | |
| 3301 | /* |
| 3302 | * Can not link to 1Gbps with bad cable |
| 3303 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3304 | */ |
| 3305 | { 0x1f, 0x0001 }, |
| 3306 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3307 | |
| 3308 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3309 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3310 | }; |
| 3311 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3312 | 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] | 3313 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3314 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3315 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3316 | { 0x1f, 0x0002 }, |
| 3317 | { 0x05, 0x669a }, |
| 3318 | { 0x1f, 0x0005 }, |
| 3319 | { 0x05, 0x8330 }, |
| 3320 | { 0x06, 0x669a }, |
| 3321 | |
| 3322 | { 0x1f, 0x0002 } |
| 3323 | }; |
| 3324 | int val; |
| 3325 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3326 | 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] | 3327 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3328 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3329 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3330 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3331 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3332 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3333 | }; |
| 3334 | int i; |
| 3335 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3336 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3337 | |
| 3338 | val &= 0xff00; |
| 3339 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3340 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3341 | } |
| 3342 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3343 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3344 | { 0x1f, 0x0002 }, |
| 3345 | { 0x05, 0x2642 }, |
| 3346 | { 0x1f, 0x0005 }, |
| 3347 | { 0x05, 0x8330 }, |
| 3348 | { 0x06, 0x2642 } |
| 3349 | }; |
| 3350 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3351 | 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] | 3352 | } |
| 3353 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3354 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3355 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3356 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3357 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3358 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3359 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3360 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3361 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3362 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3363 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3364 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3365 | |
| 3366 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3367 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3368 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3371 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3372 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3373 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3374 | { 0x1f, 0x0002 }, |
| 3375 | { 0x10, 0x0008 }, |
| 3376 | { 0x0d, 0x006c }, |
| 3377 | |
| 3378 | { 0x1f, 0x0000 }, |
| 3379 | { 0x0d, 0xf880 }, |
| 3380 | |
| 3381 | { 0x1f, 0x0001 }, |
| 3382 | { 0x17, 0x0cc0 }, |
| 3383 | |
| 3384 | { 0x1f, 0x0001 }, |
| 3385 | { 0x0b, 0xa4d8 }, |
| 3386 | { 0x09, 0x281c }, |
| 3387 | { 0x07, 0x2883 }, |
| 3388 | { 0x0a, 0x6b35 }, |
| 3389 | { 0x1d, 0x3da4 }, |
| 3390 | { 0x1c, 0xeffd }, |
| 3391 | { 0x14, 0x7f52 }, |
| 3392 | { 0x18, 0x7fc6 }, |
| 3393 | { 0x08, 0x0601 }, |
| 3394 | { 0x06, 0x4063 }, |
| 3395 | { 0x10, 0xf074 }, |
| 3396 | { 0x1f, 0x0003 }, |
| 3397 | { 0x13, 0x0789 }, |
| 3398 | { 0x12, 0xf4bd }, |
| 3399 | { 0x1a, 0x04fd }, |
| 3400 | { 0x14, 0x84b0 }, |
| 3401 | { 0x1f, 0x0000 }, |
| 3402 | { 0x00, 0x9200 }, |
| 3403 | |
| 3404 | { 0x1f, 0x0005 }, |
| 3405 | { 0x01, 0x0340 }, |
| 3406 | { 0x1f, 0x0001 }, |
| 3407 | { 0x04, 0x4000 }, |
| 3408 | { 0x03, 0x1d21 }, |
| 3409 | { 0x02, 0x0c32 }, |
| 3410 | { 0x01, 0x0200 }, |
| 3411 | { 0x00, 0x5554 }, |
| 3412 | { 0x04, 0x4800 }, |
| 3413 | { 0x04, 0x4000 }, |
| 3414 | { 0x04, 0xf000 }, |
| 3415 | { 0x03, 0xdf01 }, |
| 3416 | { 0x02, 0xdf20 }, |
| 3417 | { 0x01, 0x101a }, |
| 3418 | { 0x00, 0xa0ff }, |
| 3419 | { 0x04, 0xf800 }, |
| 3420 | { 0x04, 0xf000 }, |
| 3421 | { 0x1f, 0x0000 }, |
| 3422 | |
| 3423 | { 0x1f, 0x0007 }, |
| 3424 | { 0x1e, 0x0023 }, |
| 3425 | { 0x16, 0x0000 }, |
| 3426 | { 0x1f, 0x0000 } |
| 3427 | }; |
| 3428 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3429 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3430 | } |
| 3431 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3432 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3433 | { |
| 3434 | static const struct phy_reg phy_reg_init[] = { |
| 3435 | { 0x1f, 0x0001 }, |
| 3436 | { 0x17, 0x0cc0 }, |
| 3437 | |
| 3438 | { 0x1f, 0x0007 }, |
| 3439 | { 0x1e, 0x002d }, |
| 3440 | { 0x18, 0x0040 }, |
| 3441 | { 0x1f, 0x0000 } |
| 3442 | }; |
| 3443 | |
| 3444 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3445 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3446 | } |
| 3447 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3448 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3449 | { |
| 3450 | static const struct phy_reg phy_reg_init[] = { |
| 3451 | /* Enable Delay cap */ |
| 3452 | { 0x1f, 0x0005 }, |
| 3453 | { 0x05, 0x8b80 }, |
| 3454 | { 0x06, 0xc896 }, |
| 3455 | { 0x1f, 0x0000 }, |
| 3456 | |
| 3457 | /* Channel estimation fine tune */ |
| 3458 | { 0x1f, 0x0001 }, |
| 3459 | { 0x0b, 0x6c20 }, |
| 3460 | { 0x07, 0x2872 }, |
| 3461 | { 0x1c, 0xefff }, |
| 3462 | { 0x1f, 0x0003 }, |
| 3463 | { 0x14, 0x6420 }, |
| 3464 | { 0x1f, 0x0000 }, |
| 3465 | |
| 3466 | /* Update PFM & 10M TX idle timer */ |
| 3467 | { 0x1f, 0x0007 }, |
| 3468 | { 0x1e, 0x002f }, |
| 3469 | { 0x15, 0x1919 }, |
| 3470 | { 0x1f, 0x0000 }, |
| 3471 | |
| 3472 | { 0x1f, 0x0007 }, |
| 3473 | { 0x1e, 0x00ac }, |
| 3474 | { 0x18, 0x0006 }, |
| 3475 | { 0x1f, 0x0000 } |
| 3476 | }; |
| 3477 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3478 | rtl_apply_firmware(tp); |
| 3479 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3480 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3481 | |
| 3482 | /* DCO enable for 10M IDLE Power */ |
| 3483 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3484 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3485 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3486 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3487 | |
| 3488 | /* For impedance matching */ |
| 3489 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3490 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3491 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3492 | |
| 3493 | /* PHY auto speed down */ |
| 3494 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3495 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3496 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3497 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3498 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3499 | |
| 3500 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3501 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3502 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3503 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3504 | |
| 3505 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3506 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3507 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3508 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3509 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3510 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3511 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3512 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3513 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3514 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3515 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3516 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3517 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3518 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3519 | } |
| 3520 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3521 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3522 | { |
| 3523 | const u16 w[] = { |
| 3524 | addr[0] | (addr[1] << 8), |
| 3525 | addr[2] | (addr[3] << 8), |
| 3526 | addr[4] | (addr[5] << 8) |
| 3527 | }; |
| 3528 | const struct exgmac_reg e[] = { |
| 3529 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3530 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3531 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3532 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3533 | }; |
| 3534 | |
| 3535 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3536 | } |
| 3537 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3538 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3539 | { |
| 3540 | static const struct phy_reg phy_reg_init[] = { |
| 3541 | /* Enable Delay cap */ |
| 3542 | { 0x1f, 0x0004 }, |
| 3543 | { 0x1f, 0x0007 }, |
| 3544 | { 0x1e, 0x00ac }, |
| 3545 | { 0x18, 0x0006 }, |
| 3546 | { 0x1f, 0x0002 }, |
| 3547 | { 0x1f, 0x0000 }, |
| 3548 | { 0x1f, 0x0000 }, |
| 3549 | |
| 3550 | /* Channel estimation fine tune */ |
| 3551 | { 0x1f, 0x0003 }, |
| 3552 | { 0x09, 0xa20f }, |
| 3553 | { 0x1f, 0x0000 }, |
| 3554 | { 0x1f, 0x0000 }, |
| 3555 | |
| 3556 | /* Green Setting */ |
| 3557 | { 0x1f, 0x0005 }, |
| 3558 | { 0x05, 0x8b5b }, |
| 3559 | { 0x06, 0x9222 }, |
| 3560 | { 0x05, 0x8b6d }, |
| 3561 | { 0x06, 0x8000 }, |
| 3562 | { 0x05, 0x8b76 }, |
| 3563 | { 0x06, 0x8000 }, |
| 3564 | { 0x1f, 0x0000 } |
| 3565 | }; |
| 3566 | |
| 3567 | rtl_apply_firmware(tp); |
| 3568 | |
| 3569 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3570 | |
| 3571 | /* For 4-corner performance improve */ |
| 3572 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3573 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3574 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3575 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3576 | |
| 3577 | /* PHY auto speed down */ |
| 3578 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3579 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3580 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3581 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3582 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3583 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3584 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3585 | |
| 3586 | /* improve 10M EEE waveform */ |
| 3587 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3588 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3589 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3590 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3591 | |
| 3592 | /* Improve 2-pair detection performance */ |
| 3593 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3594 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3595 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3596 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3597 | |
| 3598 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3599 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3600 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3601 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3602 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3603 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3604 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3605 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3606 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3607 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3608 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3609 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3610 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3611 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3612 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3613 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3614 | |
| 3615 | /* Green feature */ |
| 3616 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3617 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3618 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3619 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3620 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3621 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3622 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3623 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3624 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3625 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3626 | } |
| 3627 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3628 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3629 | { |
| 3630 | /* For 4-corner performance improve */ |
| 3631 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3632 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3633 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3634 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3635 | |
| 3636 | /* PHY auto speed down */ |
| 3637 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3638 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3639 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3640 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3641 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3642 | |
| 3643 | /* Improve 10M EEE waveform */ |
| 3644 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3645 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3646 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3647 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3648 | } |
| 3649 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3650 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3651 | { |
| 3652 | static const struct phy_reg phy_reg_init[] = { |
| 3653 | /* Channel estimation fine tune */ |
| 3654 | { 0x1f, 0x0003 }, |
| 3655 | { 0x09, 0xa20f }, |
| 3656 | { 0x1f, 0x0000 }, |
| 3657 | |
| 3658 | /* Modify green table for giga & fnet */ |
| 3659 | { 0x1f, 0x0005 }, |
| 3660 | { 0x05, 0x8b55 }, |
| 3661 | { 0x06, 0x0000 }, |
| 3662 | { 0x05, 0x8b5e }, |
| 3663 | { 0x06, 0x0000 }, |
| 3664 | { 0x05, 0x8b67 }, |
| 3665 | { 0x06, 0x0000 }, |
| 3666 | { 0x05, 0x8b70 }, |
| 3667 | { 0x06, 0x0000 }, |
| 3668 | { 0x1f, 0x0000 }, |
| 3669 | { 0x1f, 0x0007 }, |
| 3670 | { 0x1e, 0x0078 }, |
| 3671 | { 0x17, 0x0000 }, |
| 3672 | { 0x19, 0x00fb }, |
| 3673 | { 0x1f, 0x0000 }, |
| 3674 | |
| 3675 | /* Modify green table for 10M */ |
| 3676 | { 0x1f, 0x0005 }, |
| 3677 | { 0x05, 0x8b79 }, |
| 3678 | { 0x06, 0xaa00 }, |
| 3679 | { 0x1f, 0x0000 }, |
| 3680 | |
| 3681 | /* Disable hiimpedance detection (RTCT) */ |
| 3682 | { 0x1f, 0x0003 }, |
| 3683 | { 0x01, 0x328a }, |
| 3684 | { 0x1f, 0x0000 } |
| 3685 | }; |
| 3686 | |
| 3687 | rtl_apply_firmware(tp); |
| 3688 | |
| 3689 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3690 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3691 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3692 | |
| 3693 | /* Improve 2-pair detection performance */ |
| 3694 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3695 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3696 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3697 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3698 | } |
| 3699 | |
| 3700 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3701 | { |
| 3702 | rtl_apply_firmware(tp); |
| 3703 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3704 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3705 | } |
| 3706 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3707 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3708 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3709 | static const struct phy_reg phy_reg_init[] = { |
| 3710 | /* Channel estimation fine tune */ |
| 3711 | { 0x1f, 0x0003 }, |
| 3712 | { 0x09, 0xa20f }, |
| 3713 | { 0x1f, 0x0000 }, |
| 3714 | |
| 3715 | /* Modify green table for giga & fnet */ |
| 3716 | { 0x1f, 0x0005 }, |
| 3717 | { 0x05, 0x8b55 }, |
| 3718 | { 0x06, 0x0000 }, |
| 3719 | { 0x05, 0x8b5e }, |
| 3720 | { 0x06, 0x0000 }, |
| 3721 | { 0x05, 0x8b67 }, |
| 3722 | { 0x06, 0x0000 }, |
| 3723 | { 0x05, 0x8b70 }, |
| 3724 | { 0x06, 0x0000 }, |
| 3725 | { 0x1f, 0x0000 }, |
| 3726 | { 0x1f, 0x0007 }, |
| 3727 | { 0x1e, 0x0078 }, |
| 3728 | { 0x17, 0x0000 }, |
| 3729 | { 0x19, 0x00aa }, |
| 3730 | { 0x1f, 0x0000 }, |
| 3731 | |
| 3732 | /* Modify green table for 10M */ |
| 3733 | { 0x1f, 0x0005 }, |
| 3734 | { 0x05, 0x8b79 }, |
| 3735 | { 0x06, 0xaa00 }, |
| 3736 | { 0x1f, 0x0000 }, |
| 3737 | |
| 3738 | /* Disable hiimpedance detection (RTCT) */ |
| 3739 | { 0x1f, 0x0003 }, |
| 3740 | { 0x01, 0x328a }, |
| 3741 | { 0x1f, 0x0000 } |
| 3742 | }; |
| 3743 | |
| 3744 | |
| 3745 | rtl_apply_firmware(tp); |
| 3746 | |
| 3747 | rtl8168f_hw_phy_config(tp); |
| 3748 | |
| 3749 | /* Improve 2-pair detection performance */ |
| 3750 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3751 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3752 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3753 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3754 | |
| 3755 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3756 | |
| 3757 | /* Modify green table for giga */ |
| 3758 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3759 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3760 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3761 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3762 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3763 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3764 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3765 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3766 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3767 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3768 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3769 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3770 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3771 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3772 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3773 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3774 | |
| 3775 | /* uc same-seed solution */ |
| 3776 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3777 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3778 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3779 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3780 | |
| 3781 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3782 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3783 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3784 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3785 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3786 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3787 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3788 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3789 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3790 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3791 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3792 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3793 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3794 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3795 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3796 | |
| 3797 | /* Green feature */ |
| 3798 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3799 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3800 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3801 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3802 | } |
| 3803 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3804 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3805 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3806 | rtl_apply_firmware(tp); |
| 3807 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3808 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3809 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3810 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3811 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3812 | } else { |
| 3813 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3814 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3815 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3816 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3817 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3818 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3819 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3820 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3821 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3822 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3823 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3824 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3825 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3826 | /* Enable PHY auto speed down */ |
| 3827 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3828 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3829 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3830 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3831 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3832 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3833 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3834 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3835 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3836 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3837 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3838 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3839 | /* EEE auto-fallback function */ |
| 3840 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3841 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3842 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3843 | /* Enable UC LPF tune function */ |
| 3844 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3845 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3846 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3847 | |
| 3848 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3849 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3850 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3851 | /* Improve SWR Efficiency */ |
| 3852 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3853 | rtl_writephy(tp, 0x14, 0x5065); |
| 3854 | rtl_writephy(tp, 0x14, 0xd065); |
| 3855 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3856 | rtl_writephy(tp, 0x11, 0x5655); |
| 3857 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3858 | rtl_writephy(tp, 0x14, 0x1065); |
| 3859 | rtl_writephy(tp, 0x14, 0x9065); |
| 3860 | rtl_writephy(tp, 0x14, 0x1065); |
| 3861 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3862 | /* Check ALDPS bit, disable it if enabled */ |
| 3863 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3864 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3865 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3866 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3867 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3868 | } |
| 3869 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3870 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3871 | { |
| 3872 | rtl_apply_firmware(tp); |
| 3873 | } |
| 3874 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3875 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3876 | { |
| 3877 | u16 dout_tapbin; |
| 3878 | u32 data; |
| 3879 | |
| 3880 | rtl_apply_firmware(tp); |
| 3881 | |
| 3882 | /* CHN EST parameters adjust - giga master */ |
| 3883 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3884 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3885 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3886 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3887 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3888 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3889 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3890 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3891 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3892 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3893 | |
| 3894 | /* CHN EST parameters adjust - giga slave */ |
| 3895 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3896 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3897 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3898 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3899 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3900 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3901 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3902 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3903 | |
| 3904 | /* CHN EST parameters adjust - fnet */ |
| 3905 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3906 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3907 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3908 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3909 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3910 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3911 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3912 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3913 | |
| 3914 | /* enable R-tune & PGA-retune function */ |
| 3915 | dout_tapbin = 0; |
| 3916 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3917 | data = rtl_readphy(tp, 0x13); |
| 3918 | data &= 3; |
| 3919 | data <<= 2; |
| 3920 | dout_tapbin |= data; |
| 3921 | data = rtl_readphy(tp, 0x12); |
| 3922 | data &= 0xc000; |
| 3923 | data >>= 14; |
| 3924 | dout_tapbin |= data; |
| 3925 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3926 | dout_tapbin <<= 12; |
| 3927 | dout_tapbin &= 0xf000; |
| 3928 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3929 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3930 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3931 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3932 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3933 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3934 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3935 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3936 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3937 | |
| 3938 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3939 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3940 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3941 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3942 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3943 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3944 | |
| 3945 | /* enable GPHY 10M */ |
| 3946 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3947 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3948 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3949 | |
| 3950 | /* SAR ADC performance */ |
| 3951 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3952 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3953 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3954 | |
| 3955 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3956 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3957 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3958 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3959 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3960 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3961 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3962 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3963 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3964 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3965 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3966 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3967 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3968 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3969 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3970 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3971 | |
| 3972 | /* disable phy pfm mode */ |
| 3973 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3974 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3975 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3976 | |
| 3977 | /* Check ALDPS bit, disable it if enabled */ |
| 3978 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3979 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3980 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3981 | |
| 3982 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3983 | } |
| 3984 | |
| 3985 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3986 | { |
| 3987 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3988 | u16 rlen; |
| 3989 | u32 data; |
| 3990 | |
| 3991 | rtl_apply_firmware(tp); |
| 3992 | |
| 3993 | /* CHIN EST parameter update */ |
| 3994 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3995 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3996 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3997 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3998 | |
| 3999 | /* enable R-tune & PGA-retune function */ |
| 4000 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4001 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4002 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4003 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4004 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4005 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4006 | |
| 4007 | /* enable GPHY 10M */ |
| 4008 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4009 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4010 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4011 | |
| 4012 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 4013 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 4014 | ioffset_p3 = ((data & 0x80)>>7); |
| 4015 | ioffset_p3 <<= 3; |
| 4016 | |
| 4017 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 4018 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 4019 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 4020 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 4021 | ioffset_p0 = ((data & 0x0010)>>4); |
| 4022 | ioffset_p0 <<= 3; |
| 4023 | ioffset_p0 |= (data & (0x07)); |
| 4024 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 4025 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4026 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 4027 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4028 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 4029 | rtl_writephy(tp, 0x16, data); |
| 4030 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4031 | } |
| 4032 | |
| 4033 | /* Modify rlen (TX LPF corner frequency) level */ |
| 4034 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4035 | data = rtl_readphy(tp, 0x16); |
| 4036 | data &= 0x000f; |
| 4037 | rlen = 0; |
| 4038 | if (data > 3) |
| 4039 | rlen = data - 3; |
| 4040 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 4041 | rtl_writephy(tp, 0x17, data); |
| 4042 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4043 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4044 | |
| 4045 | /* disable phy pfm mode */ |
| 4046 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4047 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4048 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4049 | |
| 4050 | /* Check ALDPS bit, disable it if enabled */ |
| 4051 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4052 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4053 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4054 | |
| 4055 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4056 | } |
| 4057 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4058 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 4059 | { |
| 4060 | /* Enable PHY auto speed down */ |
| 4061 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4062 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 4063 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4064 | |
| 4065 | /* patch 10M & ALDPS */ |
| 4066 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4067 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4068 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4069 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4070 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4071 | rtl_writephy(tp, 0x13, 0x8084); |
| 4072 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4073 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4074 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4075 | |
| 4076 | /* Enable EEE auto-fallback function */ |
| 4077 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 4078 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 4079 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4080 | |
| 4081 | /* Enable UC LPF tune function */ |
| 4082 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4083 | rtl_writephy(tp, 0x13, 0x8012); |
| 4084 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4085 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4086 | |
| 4087 | /* set rg_sel_sdm_rate */ |
| 4088 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4089 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4090 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4091 | |
| 4092 | /* Check ALDPS bit, disable it if enabled */ |
| 4093 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4094 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4095 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4096 | |
| 4097 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4098 | } |
| 4099 | |
| 4100 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 4101 | { |
| 4102 | /* patch 10M & ALDPS */ |
| 4103 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4104 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4105 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4106 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4107 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4108 | rtl_writephy(tp, 0x13, 0x8084); |
| 4109 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4110 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4111 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4112 | |
| 4113 | /* Enable UC LPF tune function */ |
| 4114 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4115 | rtl_writephy(tp, 0x13, 0x8012); |
| 4116 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4117 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4118 | |
| 4119 | /* Set rg_sel_sdm_rate */ |
| 4120 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4121 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4122 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4123 | |
| 4124 | /* Channel estimation parameters */ |
| 4125 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4126 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4127 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4128 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4129 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4130 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4131 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4132 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4133 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4134 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4135 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4136 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4137 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4138 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4139 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4140 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4141 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4142 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4143 | rtl_writephy(tp, 0x13, 0x8110); |
| 4144 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4145 | rtl_writephy(tp, 0x13, 0x810f); |
| 4146 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4147 | rtl_writephy(tp, 0x13, 0x8111); |
| 4148 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4149 | rtl_writephy(tp, 0x13, 0x8113); |
| 4150 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4151 | rtl_writephy(tp, 0x13, 0x8115); |
| 4152 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4153 | rtl_writephy(tp, 0x13, 0x810e); |
| 4154 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4155 | rtl_writephy(tp, 0x13, 0x810c); |
| 4156 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4157 | rtl_writephy(tp, 0x13, 0x810b); |
| 4158 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4159 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4160 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4161 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4162 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4163 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4164 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4165 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4166 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4167 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4168 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4169 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4170 | |
| 4171 | /* Force PWM-mode */ |
| 4172 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4173 | rtl_writephy(tp, 0x14, 0x5065); |
| 4174 | rtl_writephy(tp, 0x14, 0xd065); |
| 4175 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4176 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4177 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4178 | rtl_writephy(tp, 0x14, 0x1065); |
| 4179 | rtl_writephy(tp, 0x14, 0x9065); |
| 4180 | rtl_writephy(tp, 0x14, 0x1065); |
| 4181 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4182 | |
| 4183 | /* Check ALDPS bit, disable it if enabled */ |
| 4184 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4185 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4186 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4187 | |
| 4188 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4189 | } |
| 4190 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4191 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4192 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4193 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4194 | { 0x1f, 0x0003 }, |
| 4195 | { 0x08, 0x441d }, |
| 4196 | { 0x01, 0x9100 }, |
| 4197 | { 0x1f, 0x0000 } |
| 4198 | }; |
| 4199 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4200 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4201 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4202 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4203 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4204 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4205 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4206 | } |
| 4207 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4208 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4209 | { |
| 4210 | static const struct phy_reg phy_reg_init[] = { |
| 4211 | { 0x1f, 0x0005 }, |
| 4212 | { 0x1a, 0x0000 }, |
| 4213 | { 0x1f, 0x0000 }, |
| 4214 | |
| 4215 | { 0x1f, 0x0004 }, |
| 4216 | { 0x1c, 0x0000 }, |
| 4217 | { 0x1f, 0x0000 }, |
| 4218 | |
| 4219 | { 0x1f, 0x0001 }, |
| 4220 | { 0x15, 0x7701 }, |
| 4221 | { 0x1f, 0x0000 } |
| 4222 | }; |
| 4223 | |
| 4224 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4225 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4226 | rtl_writephy(tp, 0x18, 0x0310); |
| 4227 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4228 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4229 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4230 | |
| 4231 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4232 | } |
| 4233 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4234 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4235 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4236 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4237 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4238 | rtl_writephy(tp, 0x18, 0x0310); |
| 4239 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4240 | |
| 4241 | rtl_apply_firmware(tp); |
| 4242 | |
| 4243 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4244 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4245 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4246 | rtl_writephy(tp, 0x10, 0x401f); |
| 4247 | rtl_writephy(tp, 0x19, 0x7030); |
| 4248 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4249 | } |
| 4250 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4251 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4252 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4253 | static const struct phy_reg phy_reg_init[] = { |
| 4254 | { 0x1f, 0x0004 }, |
| 4255 | { 0x10, 0xc07f }, |
| 4256 | { 0x19, 0x7030 }, |
| 4257 | { 0x1f, 0x0000 } |
| 4258 | }; |
| 4259 | |
| 4260 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4261 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4262 | rtl_writephy(tp, 0x18, 0x0310); |
| 4263 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4264 | |
| 4265 | rtl_apply_firmware(tp); |
| 4266 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4267 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4268 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4269 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4270 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4271 | } |
| 4272 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4273 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4274 | { |
| 4275 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4276 | |
| 4277 | rtl8169_print_mac_version(tp); |
| 4278 | |
| 4279 | switch (tp->mac_version) { |
| 4280 | case RTL_GIGA_MAC_VER_01: |
| 4281 | break; |
| 4282 | case RTL_GIGA_MAC_VER_02: |
| 4283 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4284 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4285 | break; |
| 4286 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4287 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4288 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4289 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4290 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4291 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4292 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4293 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4294 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4295 | case RTL_GIGA_MAC_VER_07: |
| 4296 | case RTL_GIGA_MAC_VER_08: |
| 4297 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4298 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4299 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4300 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4301 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4302 | break; |
| 4303 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4304 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4305 | break; |
| 4306 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4307 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4308 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4309 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4310 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4311 | break; |
| 4312 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4313 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4314 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4315 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4316 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4317 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4318 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4319 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4320 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4321 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4322 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4323 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4324 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4325 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4326 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4327 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4328 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4329 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4330 | break; |
| 4331 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4332 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4333 | break; |
| 4334 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4335 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4336 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4337 | case RTL_GIGA_MAC_VER_28: |
| 4338 | rtl8168d_4_hw_phy_config(tp); |
| 4339 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4340 | case RTL_GIGA_MAC_VER_29: |
| 4341 | case RTL_GIGA_MAC_VER_30: |
| 4342 | rtl8105e_hw_phy_config(tp); |
| 4343 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4344 | case RTL_GIGA_MAC_VER_31: |
| 4345 | /* None. */ |
| 4346 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4347 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4348 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4349 | rtl8168e_1_hw_phy_config(tp); |
| 4350 | break; |
| 4351 | case RTL_GIGA_MAC_VER_34: |
| 4352 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4353 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4354 | case RTL_GIGA_MAC_VER_35: |
| 4355 | rtl8168f_1_hw_phy_config(tp); |
| 4356 | break; |
| 4357 | case RTL_GIGA_MAC_VER_36: |
| 4358 | rtl8168f_2_hw_phy_config(tp); |
| 4359 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4360 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4361 | case RTL_GIGA_MAC_VER_37: |
| 4362 | rtl8402_hw_phy_config(tp); |
| 4363 | break; |
| 4364 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4365 | case RTL_GIGA_MAC_VER_38: |
| 4366 | rtl8411_hw_phy_config(tp); |
| 4367 | break; |
| 4368 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4369 | case RTL_GIGA_MAC_VER_39: |
| 4370 | rtl8106e_hw_phy_config(tp); |
| 4371 | break; |
| 4372 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4373 | case RTL_GIGA_MAC_VER_40: |
| 4374 | rtl8168g_1_hw_phy_config(tp); |
| 4375 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4376 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4377 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4378 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4379 | rtl8168g_2_hw_phy_config(tp); |
| 4380 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4381 | case RTL_GIGA_MAC_VER_45: |
| 4382 | case RTL_GIGA_MAC_VER_47: |
| 4383 | rtl8168h_1_hw_phy_config(tp); |
| 4384 | break; |
| 4385 | case RTL_GIGA_MAC_VER_46: |
| 4386 | case RTL_GIGA_MAC_VER_48: |
| 4387 | rtl8168h_2_hw_phy_config(tp); |
| 4388 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4389 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4390 | case RTL_GIGA_MAC_VER_49: |
| 4391 | rtl8168ep_1_hw_phy_config(tp); |
| 4392 | break; |
| 4393 | case RTL_GIGA_MAC_VER_50: |
| 4394 | case RTL_GIGA_MAC_VER_51: |
| 4395 | rtl8168ep_2_hw_phy_config(tp); |
| 4396 | break; |
| 4397 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4398 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4399 | default: |
| 4400 | break; |
| 4401 | } |
| 4402 | } |
| 4403 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4404 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | struct timer_list *timer = &tp->timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4408 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4409 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4411 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4412 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4414 | * Let's delay the execution of the timer for a few ticks. |
| 4415 | */ |
| 4416 | timeout = HZ/10; |
| 4417 | goto out_mod_timer; |
| 4418 | } |
| 4419 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4420 | if (tp->link_ok(tp)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4421 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4423 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4425 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | |
| 4427 | out_mod_timer: |
| 4428 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4432 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4433 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4434 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4435 | } |
| 4436 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4437 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4438 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4439 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4440 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4441 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | } |
| 4443 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4444 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4445 | { |
| 4446 | return tp->phy_reset_pending(tp); |
| 4447 | } |
| 4448 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4449 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4450 | struct rtl8169_private *tp) |
| 4451 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4452 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4453 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4454 | } |
| 4455 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4456 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4457 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4458 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4459 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4460 | } |
| 4461 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4462 | 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] | 4463 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4464 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4465 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4466 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4467 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4468 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4469 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4470 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4471 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4472 | |
| 4473 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4474 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4475 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4476 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4477 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4478 | RTL_W8(tp, 0x82, 0x01); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4479 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4480 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4481 | } |
| 4482 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4483 | rtl8169_phy_reset(dev, tp); |
| 4484 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4485 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4486 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4487 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4488 | (tp->mii.supports_gmii ? |
| 4489 | ADVERTISED_1000baseT_Half | |
| 4490 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4491 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4492 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4493 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4494 | } |
| 4495 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4496 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4497 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4498 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4499 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4500 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4501 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4502 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4503 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4504 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4505 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4506 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4507 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4508 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4509 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4510 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4511 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4512 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4513 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4517 | { |
| 4518 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4519 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4520 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4521 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4522 | ret = eth_mac_addr(dev, p); |
| 4523 | if (ret) |
| 4524 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4525 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4526 | pm_runtime_get_noresume(d); |
| 4527 | |
| 4528 | if (pm_runtime_active(d)) |
| 4529 | rtl_rar_set(tp, dev->dev_addr); |
| 4530 | |
| 4531 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4532 | |
| 4533 | return 0; |
| 4534 | } |
| 4535 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4536 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4537 | { |
| 4538 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4539 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4540 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4541 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4542 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4543 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4544 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4545 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4546 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4547 | switch (cmd) { |
| 4548 | case SIOCGMIIPHY: |
| 4549 | data->phy_id = 32; /* Internal PHY */ |
| 4550 | return 0; |
| 4551 | |
| 4552 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4553 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4554 | return 0; |
| 4555 | |
| 4556 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4557 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4558 | return 0; |
| 4559 | } |
| 4560 | return -EOPNOTSUPP; |
| 4561 | } |
| 4562 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4563 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4564 | { |
| 4565 | return -EOPNOTSUPP; |
| 4566 | } |
| 4567 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4568 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4569 | { |
| 4570 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4571 | |
| 4572 | switch (tp->mac_version) { |
| 4573 | case RTL_GIGA_MAC_VER_27: |
| 4574 | ops->write = r8168dp_1_mdio_write; |
| 4575 | ops->read = r8168dp_1_mdio_read; |
| 4576 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4577 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4578 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4579 | ops->write = r8168dp_2_mdio_write; |
| 4580 | ops->read = r8168dp_2_mdio_read; |
| 4581 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4582 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4583 | ops->write = r8168g_mdio_write; |
| 4584 | ops->read = r8168g_mdio_read; |
| 4585 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4586 | default: |
| 4587 | ops->write = r8169_mdio_write; |
| 4588 | ops->read = r8169_mdio_read; |
| 4589 | break; |
| 4590 | } |
| 4591 | } |
| 4592 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4593 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4594 | { |
| 4595 | u32 adv; |
| 4596 | int lpa; |
| 4597 | |
| 4598 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4599 | lpa = rtl_readphy(tp, MII_LPA); |
| 4600 | |
| 4601 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4602 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4603 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4604 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4605 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4606 | else |
| 4607 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4608 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4609 | (tp->mii.supports_gmii ? |
| 4610 | ADVERTISED_1000baseT_Half | |
| 4611 | ADVERTISED_1000baseT_Full : 0); |
| 4612 | |
| 4613 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4614 | adv); |
| 4615 | } |
| 4616 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4617 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4618 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4619 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4620 | case RTL_GIGA_MAC_VER_25: |
| 4621 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4622 | case RTL_GIGA_MAC_VER_29: |
| 4623 | case RTL_GIGA_MAC_VER_30: |
| 4624 | case RTL_GIGA_MAC_VER_32: |
| 4625 | case RTL_GIGA_MAC_VER_33: |
| 4626 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4627 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4628 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4629 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4630 | break; |
| 4631 | default: |
| 4632 | break; |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4637 | { |
Heiner Kallweit | fe87bef | 2018-06-24 18:40:23 +0200 | [diff] [blame^] | 4638 | if (!netif_running(tp->dev) || !tp->saved_wolopts) |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4639 | return false; |
| 4640 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4641 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4642 | rtl_wol_suspend_quirk(tp); |
| 4643 | |
| 4644 | return true; |
| 4645 | } |
| 4646 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4647 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4648 | { |
| 4649 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4650 | switch (tp->mac_version) { |
| 4651 | case RTL_GIGA_MAC_VER_11: |
| 4652 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4653 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4654 | case RTL_GIGA_MAC_VER_31: |
| 4655 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4656 | break; |
| 4657 | default: |
| 4658 | break; |
| 4659 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4660 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
David S. Miller | b2d6cee | 2018-05-11 20:53:22 -0400 | [diff] [blame] | 4661 | |
| 4662 | /* give MAC/PHY some time to resume */ |
| 4663 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4667 | { |
| 4668 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4669 | switch (tp->mac_version) { |
| 4670 | case RTL_GIGA_MAC_VER_32: |
| 4671 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4672 | case RTL_GIGA_MAC_VER_40: |
| 4673 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4674 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4675 | break; |
| 4676 | |
| 4677 | case RTL_GIGA_MAC_VER_11: |
| 4678 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4679 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4680 | case RTL_GIGA_MAC_VER_31: |
| 4681 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4682 | default: |
| 4683 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4684 | break; |
| 4685 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4689 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4690 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4691 | return; |
| 4692 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4693 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4694 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4695 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4696 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4697 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4698 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4699 | |
| 4700 | r8168_phy_power_down(tp); |
| 4701 | |
| 4702 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4703 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4704 | case RTL_GIGA_MAC_VER_37: |
| 4705 | case RTL_GIGA_MAC_VER_39: |
| 4706 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4707 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4708 | case RTL_GIGA_MAC_VER_45: |
| 4709 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4710 | case RTL_GIGA_MAC_VER_47: |
| 4711 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4712 | case RTL_GIGA_MAC_VER_50: |
| 4713 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4714 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4715 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4716 | case RTL_GIGA_MAC_VER_40: |
| 4717 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4718 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4719 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4720 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4721 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4722 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4727 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4728 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4729 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4730 | case RTL_GIGA_MAC_VER_37: |
| 4731 | case RTL_GIGA_MAC_VER_39: |
| 4732 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4733 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4734 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4735 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4736 | case RTL_GIGA_MAC_VER_45: |
| 4737 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4738 | case RTL_GIGA_MAC_VER_47: |
| 4739 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4740 | case RTL_GIGA_MAC_VER_50: |
| 4741 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4742 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4743 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4744 | case RTL_GIGA_MAC_VER_40: |
| 4745 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4746 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4747 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4748 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4749 | 0x00000000, ERIAR_EXGMAC); |
| 4750 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | r8168_phy_power_up(tp); |
| 4754 | } |
| 4755 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4756 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4757 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4758 | switch (tp->mac_version) { |
| 4759 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4760 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4761 | break; |
| 4762 | default: |
| 4763 | r8168_pll_power_down(tp); |
| 4764 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4768 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4769 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4770 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4771 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4772 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4773 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4774 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4775 | } |
| 4776 | } |
| 4777 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4778 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4779 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4780 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4781 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4782 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4783 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4784 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4785 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4786 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 4787 | case RTL_GIGA_MAC_VER_35: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4788 | 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] | 4789 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4790 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4791 | 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] | 4792 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4793 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4794 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4795 | break; |
| 4796 | } |
| 4797 | } |
| 4798 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4799 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4800 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4801 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4802 | } |
| 4803 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4804 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4805 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4806 | if (tp->jumbo_ops.enable) { |
| 4807 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4808 | tp->jumbo_ops.enable(tp); |
| 4809 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4810 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4814 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4815 | if (tp->jumbo_ops.disable) { |
| 4816 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4817 | tp->jumbo_ops.disable(tp); |
| 4818 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4819 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4823 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4824 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4825 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4826 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4830 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4831 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4832 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4833 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4837 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4838 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4842 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4843 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4847 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4848 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4849 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4850 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4851 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4855 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4856 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4857 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4858 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4859 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4863 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4864 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4865 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4869 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4870 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4871 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4875 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4876 | r8168b_0_hw_jumbo_enable(tp); |
| 4877 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4878 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4882 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4883 | r8168b_0_hw_jumbo_disable(tp); |
| 4884 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4885 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4886 | } |
| 4887 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4888 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4889 | { |
| 4890 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4891 | |
| 4892 | switch (tp->mac_version) { |
| 4893 | case RTL_GIGA_MAC_VER_11: |
| 4894 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4895 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4896 | break; |
| 4897 | case RTL_GIGA_MAC_VER_12: |
| 4898 | case RTL_GIGA_MAC_VER_17: |
| 4899 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4900 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4901 | break; |
| 4902 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4903 | case RTL_GIGA_MAC_VER_19: |
| 4904 | case RTL_GIGA_MAC_VER_20: |
| 4905 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4906 | case RTL_GIGA_MAC_VER_22: |
| 4907 | case RTL_GIGA_MAC_VER_23: |
| 4908 | case RTL_GIGA_MAC_VER_24: |
| 4909 | case RTL_GIGA_MAC_VER_25: |
| 4910 | case RTL_GIGA_MAC_VER_26: |
| 4911 | ops->disable = r8168c_hw_jumbo_disable; |
| 4912 | ops->enable = r8168c_hw_jumbo_enable; |
| 4913 | break; |
| 4914 | case RTL_GIGA_MAC_VER_27: |
| 4915 | case RTL_GIGA_MAC_VER_28: |
| 4916 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4917 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4918 | break; |
| 4919 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4920 | case RTL_GIGA_MAC_VER_32: |
| 4921 | case RTL_GIGA_MAC_VER_33: |
| 4922 | case RTL_GIGA_MAC_VER_34: |
| 4923 | ops->disable = r8168e_hw_jumbo_disable; |
| 4924 | ops->enable = r8168e_hw_jumbo_enable; |
| 4925 | break; |
| 4926 | |
| 4927 | /* |
| 4928 | * No action needed for jumbo frames with 8169. |
| 4929 | * No jumbo for 810x at all. |
| 4930 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4931 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4932 | default: |
| 4933 | ops->disable = NULL; |
| 4934 | ops->enable = NULL; |
| 4935 | break; |
| 4936 | } |
| 4937 | } |
| 4938 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4939 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4940 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4941 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4942 | } |
| 4943 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4944 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4945 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4946 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4947 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4948 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4949 | } |
| 4950 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4951 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4952 | { |
| 4953 | struct rtl_fw *rtl_fw; |
| 4954 | const char *name; |
| 4955 | int rc = -ENOMEM; |
| 4956 | |
| 4957 | name = rtl_lookup_firmware_name(tp); |
| 4958 | if (!name) |
| 4959 | goto out_no_firmware; |
| 4960 | |
| 4961 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4962 | if (!rtl_fw) |
| 4963 | goto err_warn; |
| 4964 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4965 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4966 | if (rc < 0) |
| 4967 | goto err_free; |
| 4968 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4969 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4970 | if (rc < 0) |
| 4971 | goto err_release_firmware; |
| 4972 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4973 | tp->rtl_fw = rtl_fw; |
| 4974 | out: |
| 4975 | return; |
| 4976 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4977 | err_release_firmware: |
| 4978 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4979 | err_free: |
| 4980 | kfree(rtl_fw); |
| 4981 | err_warn: |
| 4982 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4983 | name, rc); |
| 4984 | out_no_firmware: |
| 4985 | tp->rtl_fw = NULL; |
| 4986 | goto out; |
| 4987 | } |
| 4988 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4989 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4990 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4991 | if (IS_ERR(tp->rtl_fw)) |
| 4992 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4993 | } |
| 4994 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4995 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4996 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4997 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4998 | } |
| 4999 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5000 | DECLARE_RTL_COND(rtl_npq_cond) |
| 5001 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5002 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 5006 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5007 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5008 | } |
| 5009 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5010 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | { |
| 5012 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5013 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5015 | rtl_rx_close(tp); |
| 5016 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5017 | switch (tp->mac_version) { |
| 5018 | case RTL_GIGA_MAC_VER_27: |
| 5019 | case RTL_GIGA_MAC_VER_28: |
| 5020 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5021 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5022 | break; |
| 5023 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 5024 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5025 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5026 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5027 | break; |
| 5028 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5029 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5030 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5031 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5032 | } |
| 5033 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5034 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | } |
| 5036 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5037 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5038 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5039 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5040 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5041 | (InterFrameGap << TxInterFrameGapShift)); |
| 5042 | } |
| 5043 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 5044 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 5046 | /* Low hurts. Let's disable the filtering. */ |
| 5047 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5048 | } |
| 5049 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5050 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5051 | { |
| 5052 | /* |
| 5053 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 5054 | * register to be written before TxDescAddrLow to work. |
| 5055 | * Switching from MMIO to I/O access fixes the issue as well. |
| 5056 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5057 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 5058 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 5059 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 5060 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5061 | } |
| 5062 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5063 | 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] | 5064 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5065 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5066 | u32 mac_version; |
| 5067 | u32 clk; |
| 5068 | u32 val; |
| 5069 | } cfg2_info [] = { |
| 5070 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 5071 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 5072 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 5073 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5074 | }; |
| 5075 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5076 | unsigned int i; |
| 5077 | u32 clk; |
| 5078 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5079 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 5080 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5081 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5082 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5083 | break; |
| 5084 | } |
| 5085 | } |
| 5086 | } |
| 5087 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5088 | static void rtl_set_rx_mode(struct net_device *dev) |
| 5089 | { |
| 5090 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5091 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 5092 | int rx_mode; |
| 5093 | u32 tmp = 0; |
| 5094 | |
| 5095 | if (dev->flags & IFF_PROMISC) { |
| 5096 | /* Unconditionally log net taps. */ |
| 5097 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 5098 | rx_mode = |
| 5099 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5100 | AcceptAllPhys; |
| 5101 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5102 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 5103 | (dev->flags & IFF_ALLMULTI)) { |
| 5104 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5105 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5106 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5107 | } else { |
| 5108 | struct netdev_hw_addr *ha; |
| 5109 | |
| 5110 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5111 | mc_filter[1] = mc_filter[0] = 0; |
| 5112 | netdev_for_each_mc_addr(ha, dev) { |
| 5113 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 5114 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5115 | rx_mode |= AcceptMulticast; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | if (dev->features & NETIF_F_RXALL) |
| 5120 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5121 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5122 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5123 | |
| 5124 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5125 | u32 data = mc_filter[0]; |
| 5126 | |
| 5127 | mc_filter[0] = swab32(mc_filter[1]); |
| 5128 | mc_filter[1] = swab32(data); |
| 5129 | } |
| 5130 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5131 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5132 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5133 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5134 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 5135 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5136 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5137 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5138 | } |
| 5139 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 5140 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 5141 | { |
| 5142 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 5143 | |
| 5144 | tp->hw_start(tp); |
| 5145 | |
| 5146 | rtl_set_rx_max_size(tp); |
| 5147 | rtl_set_rx_tx_desc_registers(tp); |
| 5148 | rtl_set_rx_tx_config_registers(tp); |
| 5149 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 5150 | |
| 5151 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5152 | RTL_R8(tp, IntrMask); |
| 5153 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5154 | rtl_set_rx_mode(tp->dev); |
| 5155 | /* no early-rx interrupts */ |
| 5156 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
| 5157 | rtl_irq_enable_all(tp); |
| 5158 | } |
| 5159 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5160 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5161 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5162 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5163 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5164 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5165 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5167 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5168 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5169 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5170 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5171 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5173 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5176 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5177 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5178 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5180 | /* |
| 5181 | * Undocumented corner. Supposedly: |
| 5182 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5183 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5184 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5185 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5186 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5189 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5190 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5191 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5192 | } |
| 5193 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5194 | 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] | 5195 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5196 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5197 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5198 | RTL_W32(tp, CSIDR, value); |
| 5199 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5200 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5201 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5202 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5203 | } |
| 5204 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5205 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5206 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5207 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5208 | |
| 5209 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 5210 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5211 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5212 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5213 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5214 | } |
| 5215 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5216 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5217 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5218 | struct pci_dev *pdev = tp->pci_dev; |
| 5219 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5220 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5221 | /* According to Realtek the value at config space address 0x070f |
| 5222 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 5223 | * first and if it fails fall back to CSI. |
| 5224 | */ |
| 5225 | if (pdev->cfg_size > 0x070f && |
| 5226 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 5227 | return; |
| 5228 | |
| 5229 | netdev_notice_once(tp->dev, |
| 5230 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 5231 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5232 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5233 | } |
| 5234 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5235 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5236 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5237 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | struct ephy_info { |
| 5241 | unsigned int offset; |
| 5242 | u16 mask; |
| 5243 | u16 bits; |
| 5244 | }; |
| 5245 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5246 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5247 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5248 | { |
| 5249 | u16 w; |
| 5250 | |
| 5251 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5252 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5253 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5254 | e++; |
| 5255 | } |
| 5256 | } |
| 5257 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5258 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5259 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5260 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5261 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5262 | } |
| 5263 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5264 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5265 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5266 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5267 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5270 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5271 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5272 | u8 data; |
| 5273 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5274 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5275 | |
| 5276 | if (enable) |
| 5277 | data |= Rdy_to_L23; |
| 5278 | else |
| 5279 | data &= ~Rdy_to_L23; |
| 5280 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5281 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5282 | } |
| 5283 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5284 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 5285 | { |
| 5286 | if (enable) { |
| 5287 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
| 5288 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
| 5289 | } else { |
| 5290 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5291 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 5292 | } |
| 5293 | } |
| 5294 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5295 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5296 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5297 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5298 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5299 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5300 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5301 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5302 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5303 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5304 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5305 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5306 | } |
| 5307 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5308 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5309 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5310 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5311 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5312 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5313 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5314 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5315 | } |
| 5316 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5317 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5318 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5319 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5320 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5321 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5322 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5323 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5324 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5325 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5326 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5327 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5328 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5329 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5330 | } |
| 5331 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5332 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5333 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5334 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5335 | { 0x01, 0, 0x0001 }, |
| 5336 | { 0x02, 0x0800, 0x1000 }, |
| 5337 | { 0x03, 0, 0x0042 }, |
| 5338 | { 0x06, 0x0080, 0x0000 }, |
| 5339 | { 0x07, 0, 0x2000 } |
| 5340 | }; |
| 5341 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5342 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5343 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5344 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5345 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5346 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5347 | } |
| 5348 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5349 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5350 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5351 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5352 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5353 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5354 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5355 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5356 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5357 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5358 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5359 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5360 | } |
| 5361 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5362 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5363 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5364 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5365 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5366 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5367 | |
| 5368 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5369 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5370 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5371 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5372 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5373 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5374 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5375 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5376 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5377 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5378 | } |
| 5379 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5380 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5381 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5382 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5383 | { 0x02, 0x0800, 0x1000 }, |
| 5384 | { 0x03, 0, 0x0002 }, |
| 5385 | { 0x06, 0x0080, 0x0000 } |
| 5386 | }; |
| 5387 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5388 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5389 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5390 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5391 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5392 | 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] | 5393 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5394 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5395 | } |
| 5396 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5397 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5398 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5399 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5400 | { 0x01, 0, 0x0001 }, |
| 5401 | { 0x03, 0x0400, 0x0220 } |
| 5402 | }; |
| 5403 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5404 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5405 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5406 | 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] | 5407 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5408 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5409 | } |
| 5410 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5411 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5412 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5413 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5414 | } |
| 5415 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5416 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5417 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5418 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5419 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5420 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5421 | } |
| 5422 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5423 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5424 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5425 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5426 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5427 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5428 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5429 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5430 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5431 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5432 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5433 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5434 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5435 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5436 | } |
| 5437 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5438 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5439 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5440 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5441 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5442 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5443 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5444 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5445 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5446 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5447 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5448 | } |
| 5449 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5450 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5451 | { |
| 5452 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5453 | { 0x0b, 0x0000, 0x0048 }, |
| 5454 | { 0x19, 0x0020, 0x0050 }, |
| 5455 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5456 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5457 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5458 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5459 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5460 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5461 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5462 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5463 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5464 | 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] | 5465 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5466 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5469 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5470 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5471 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5472 | { 0x00, 0x0200, 0x0100 }, |
| 5473 | { 0x00, 0x0000, 0x0004 }, |
| 5474 | { 0x06, 0x0002, 0x0001 }, |
| 5475 | { 0x06, 0x0000, 0x0030 }, |
| 5476 | { 0x07, 0x0000, 0x2000 }, |
| 5477 | { 0x00, 0x0000, 0x0020 }, |
| 5478 | { 0x03, 0x5800, 0x2000 }, |
| 5479 | { 0x03, 0x0000, 0x0001 }, |
| 5480 | { 0x01, 0x0800, 0x1000 }, |
| 5481 | { 0x07, 0x0000, 0x4000 }, |
| 5482 | { 0x1e, 0x0000, 0x2000 }, |
| 5483 | { 0x19, 0xffff, 0xfe6c }, |
| 5484 | { 0x0a, 0x0000, 0x0040 } |
| 5485 | }; |
| 5486 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5487 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5488 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5489 | 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] | 5490 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5491 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5492 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5493 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5494 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5495 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5496 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5497 | |
| 5498 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5499 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 5500 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5501 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5502 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5503 | } |
| 5504 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5505 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5506 | { |
| 5507 | static const struct ephy_info e_info_8168e_2[] = { |
| 5508 | { 0x09, 0x0000, 0x0080 }, |
| 5509 | { 0x19, 0x0000, 0x0224 } |
| 5510 | }; |
| 5511 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5512 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5513 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5514 | 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] | 5515 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5516 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5517 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5518 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5519 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5520 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5521 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5522 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5523 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5524 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5525 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5526 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5527 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5528 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5529 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5530 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5531 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5532 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5533 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5534 | |
| 5535 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5536 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5537 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5538 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5539 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5540 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Heiner Kallweit | aa1e7d2 | 2018-06-23 09:53:00 +0200 | [diff] [blame] | 5541 | |
| 5542 | rtl_hw_aspm_clkreq_enable(tp, true); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5543 | } |
| 5544 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5545 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5546 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5547 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5548 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5549 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5550 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5551 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5552 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5553 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5554 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5555 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5556 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5557 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5558 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5559 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5560 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5561 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5562 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5563 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5564 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5565 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5566 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5567 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5568 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5569 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5570 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5571 | } |
| 5572 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5573 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5574 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5575 | static const struct ephy_info e_info_8168f_1[] = { |
| 5576 | { 0x06, 0x00c0, 0x0020 }, |
| 5577 | { 0x08, 0x0001, 0x0002 }, |
| 5578 | { 0x09, 0x0000, 0x0080 }, |
| 5579 | { 0x19, 0x0000, 0x0224 } |
| 5580 | }; |
| 5581 | |
| 5582 | rtl_hw_start_8168f(tp); |
| 5583 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5584 | 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] | 5585 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5586 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5587 | |
| 5588 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5589 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5590 | } |
| 5591 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5592 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5593 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5594 | static const struct ephy_info e_info_8168f_1[] = { |
| 5595 | { 0x06, 0x00c0, 0x0020 }, |
| 5596 | { 0x0f, 0xffff, 0x5200 }, |
| 5597 | { 0x1e, 0x0000, 0x4000 }, |
| 5598 | { 0x19, 0x0000, 0x0224 } |
| 5599 | }; |
| 5600 | |
| 5601 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5602 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5603 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5604 | 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] | 5605 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5606 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5607 | } |
| 5608 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5609 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5610 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5611 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5612 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5613 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5614 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5615 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5616 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5617 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5618 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5619 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5620 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5621 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5622 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5623 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5624 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5625 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5626 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5627 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5628 | |
| 5629 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5630 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5631 | |
| 5632 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5633 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5634 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5635 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5636 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5637 | |
| 5638 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5639 | } |
| 5640 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5641 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5642 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5643 | static const struct ephy_info e_info_8168g_1[] = { |
| 5644 | { 0x00, 0x0000, 0x0008 }, |
| 5645 | { 0x0c, 0x37d0, 0x0820 }, |
| 5646 | { 0x1e, 0x0000, 0x0001 }, |
| 5647 | { 0x19, 0x8000, 0x0000 } |
| 5648 | }; |
| 5649 | |
| 5650 | rtl_hw_start_8168g(tp); |
| 5651 | |
| 5652 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5653 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5654 | 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] | 5655 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5656 | } |
| 5657 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5658 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5659 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5660 | static const struct ephy_info e_info_8168g_2[] = { |
| 5661 | { 0x00, 0x0000, 0x0008 }, |
| 5662 | { 0x0c, 0x3df0, 0x0200 }, |
| 5663 | { 0x19, 0xffff, 0xfc00 }, |
| 5664 | { 0x1e, 0xffff, 0x20eb } |
| 5665 | }; |
| 5666 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5667 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5668 | |
| 5669 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5670 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5671 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5672 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5673 | } |
| 5674 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5675 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5676 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5677 | static const struct ephy_info e_info_8411_2[] = { |
| 5678 | { 0x00, 0x0000, 0x0008 }, |
| 5679 | { 0x0c, 0x3df0, 0x0200 }, |
| 5680 | { 0x0f, 0xffff, 0x5200 }, |
| 5681 | { 0x19, 0x0020, 0x0000 }, |
| 5682 | { 0x1e, 0x0000, 0x2000 } |
| 5683 | }; |
| 5684 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5685 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5686 | |
| 5687 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5688 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5689 | 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] | 5690 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5691 | } |
| 5692 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5693 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5694 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5695 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5696 | u32 data; |
| 5697 | static const struct ephy_info e_info_8168h_1[] = { |
| 5698 | { 0x1e, 0x0800, 0x0001 }, |
| 5699 | { 0x1d, 0x0000, 0x0800 }, |
| 5700 | { 0x05, 0xffff, 0x2089 }, |
| 5701 | { 0x06, 0xffff, 0x5881 }, |
| 5702 | { 0x04, 0xffff, 0x154a }, |
| 5703 | { 0x01, 0xffff, 0x068b } |
| 5704 | }; |
| 5705 | |
| 5706 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5707 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5708 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5709 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5710 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5711 | |
| 5712 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5713 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5714 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5715 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5716 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5717 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5718 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5719 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5720 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5721 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5722 | 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] | 5723 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5724 | 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] | 5725 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5726 | 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] | 5727 | |
| 5728 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5729 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5730 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5731 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5732 | |
| 5733 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5734 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5735 | |
| 5736 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5737 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5738 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5739 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5740 | 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] | 5741 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5742 | 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] | 5743 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5744 | 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] | 5745 | |
| 5746 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5747 | |
| 5748 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5749 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5750 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5751 | if (rg_saw_cnt > 0) { |
| 5752 | u16 sw_cnt_1ms_ini; |
| 5753 | |
| 5754 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5755 | sw_cnt_1ms_ini &= 0x0fff; |
| 5756 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5757 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5758 | data |= sw_cnt_1ms_ini; |
| 5759 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5760 | } |
| 5761 | |
| 5762 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5763 | data &= ~0xf0; |
| 5764 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5765 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5766 | |
| 5767 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5768 | data &= ~0x6000; |
| 5769 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5770 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5771 | |
| 5772 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5773 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5774 | data |= 0x017f; |
| 5775 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5776 | |
| 5777 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5778 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5779 | data |= 0x047f; |
| 5780 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5781 | |
| 5782 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5783 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5784 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5785 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5786 | |
| 5787 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5788 | } |
| 5789 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5790 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5791 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5792 | rtl8168ep_stop_cmac(tp); |
| 5793 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5794 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5795 | |
| 5796 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5797 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5798 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5799 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5800 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 5801 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5802 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5803 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5804 | |
| 5805 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5806 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5807 | |
| 5808 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5809 | |
| 5810 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5811 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5812 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5813 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5814 | |
| 5815 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5816 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5817 | |
| 5818 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5819 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5820 | |
| 5821 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5822 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5823 | 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] | 5824 | |
| 5825 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5826 | } |
| 5827 | |
| 5828 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5829 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5830 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5831 | { 0x00, 0xffff, 0x10ab }, |
| 5832 | { 0x06, 0xffff, 0xf030 }, |
| 5833 | { 0x08, 0xffff, 0x2006 }, |
| 5834 | { 0x0d, 0xffff, 0x1666 }, |
| 5835 | { 0x0c, 0x3ff0, 0x0000 } |
| 5836 | }; |
| 5837 | |
| 5838 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5839 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5840 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5841 | |
| 5842 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5843 | |
| 5844 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5848 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5849 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5850 | { 0x00, 0xffff, 0x10a3 }, |
| 5851 | { 0x19, 0xffff, 0xfc00 }, |
| 5852 | { 0x1e, 0xffff, 0x20ea } |
| 5853 | }; |
| 5854 | |
| 5855 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5856 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5857 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5858 | |
| 5859 | rtl_hw_start_8168ep(tp); |
| 5860 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5861 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5862 | 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] | 5863 | |
| 5864 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5865 | } |
| 5866 | |
| 5867 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5868 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5869 | u32 data; |
| 5870 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5871 | { 0x00, 0xffff, 0x10a3 }, |
| 5872 | { 0x19, 0xffff, 0x7c00 }, |
| 5873 | { 0x1e, 0xffff, 0x20eb }, |
| 5874 | { 0x0d, 0xffff, 0x1666 } |
| 5875 | }; |
| 5876 | |
| 5877 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5878 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5879 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5880 | |
| 5881 | rtl_hw_start_8168ep(tp); |
| 5882 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5883 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5884 | 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] | 5885 | |
| 5886 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5887 | data &= 0xf000; |
| 5888 | data |= 0x0271; |
| 5889 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5890 | |
| 5891 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5892 | data &= 0xff00; |
| 5893 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5894 | |
| 5895 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5896 | data |= 0x0080; |
| 5897 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5898 | |
| 5899 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5900 | } |
| 5901 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5902 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5903 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5904 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5905 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5906 | tp->cp_cmd &= ~INTT_MASK; |
| 5907 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5908 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5909 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5910 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5911 | |
| 5912 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5913 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5914 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5915 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5916 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5917 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5918 | switch (tp->mac_version) { |
| 5919 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5920 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5921 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5922 | |
| 5923 | case RTL_GIGA_MAC_VER_12: |
| 5924 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5925 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5926 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5927 | |
| 5928 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5929 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5930 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5931 | |
| 5932 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5933 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5934 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5935 | |
| 5936 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5937 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5938 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5939 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5940 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5941 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5942 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5943 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5944 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5945 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5946 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5947 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5948 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5949 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5950 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5951 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5952 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5953 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5954 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5955 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5956 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5957 | case RTL_GIGA_MAC_VER_26: |
| 5958 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5959 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5960 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5961 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5962 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5963 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5964 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5965 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5966 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5967 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5968 | break; |
| 5969 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5970 | case RTL_GIGA_MAC_VER_32: |
| 5971 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5972 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5973 | break; |
| 5974 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5975 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5976 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5977 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5978 | case RTL_GIGA_MAC_VER_35: |
| 5979 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5980 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5981 | break; |
| 5982 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5983 | case RTL_GIGA_MAC_VER_38: |
| 5984 | rtl_hw_start_8411(tp); |
| 5985 | break; |
| 5986 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5987 | case RTL_GIGA_MAC_VER_40: |
| 5988 | case RTL_GIGA_MAC_VER_41: |
| 5989 | rtl_hw_start_8168g_1(tp); |
| 5990 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5991 | case RTL_GIGA_MAC_VER_42: |
| 5992 | rtl_hw_start_8168g_2(tp); |
| 5993 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5994 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5995 | case RTL_GIGA_MAC_VER_44: |
| 5996 | rtl_hw_start_8411_2(tp); |
| 5997 | break; |
| 5998 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5999 | case RTL_GIGA_MAC_VER_45: |
| 6000 | case RTL_GIGA_MAC_VER_46: |
| 6001 | rtl_hw_start_8168h_1(tp); |
| 6002 | break; |
| 6003 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6004 | case RTL_GIGA_MAC_VER_49: |
| 6005 | rtl_hw_start_8168ep_1(tp); |
| 6006 | break; |
| 6007 | |
| 6008 | case RTL_GIGA_MAC_VER_50: |
| 6009 | rtl_hw_start_8168ep_2(tp); |
| 6010 | break; |
| 6011 | |
| 6012 | case RTL_GIGA_MAC_VER_51: |
| 6013 | rtl_hw_start_8168ep_3(tp); |
| 6014 | break; |
| 6015 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6016 | default: |
| 6017 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6018 | tp->dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6019 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6020 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6022 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6023 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6024 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6025 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6026 | { 0x01, 0, 0x6e65 }, |
| 6027 | { 0x02, 0, 0x091f }, |
| 6028 | { 0x03, 0, 0xc2f9 }, |
| 6029 | { 0x06, 0, 0xafb5 }, |
| 6030 | { 0x07, 0, 0x0e00 }, |
| 6031 | { 0x19, 0, 0xec80 }, |
| 6032 | { 0x01, 0, 0x2e65 }, |
| 6033 | { 0x01, 0, 0x6e65 } |
| 6034 | }; |
| 6035 | u8 cfg1; |
| 6036 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 6037 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6038 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6039 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6040 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6041 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6042 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6043 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6044 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6045 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6046 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6047 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6048 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6049 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6050 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6051 | 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] | 6052 | } |
| 6053 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6054 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6055 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 6056 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6057 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6058 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6059 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6060 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 6061 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6062 | } |
| 6063 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6064 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6065 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6066 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6067 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6068 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6069 | } |
| 6070 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6071 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6072 | { |
| 6073 | static const struct ephy_info e_info_8105e_1[] = { |
| 6074 | { 0x07, 0, 0x4000 }, |
| 6075 | { 0x19, 0, 0x0200 }, |
| 6076 | { 0x19, 0, 0x0020 }, |
| 6077 | { 0x1e, 0, 0x2000 }, |
| 6078 | { 0x03, 0, 0x0001 }, |
| 6079 | { 0x19, 0, 0x0100 }, |
| 6080 | { 0x19, 0, 0x0004 }, |
| 6081 | { 0x0a, 0, 0x0020 } |
| 6082 | }; |
| 6083 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6084 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6085 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6086 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6087 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6088 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6089 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6090 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6091 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6092 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6093 | 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] | 6094 | |
| 6095 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6096 | } |
| 6097 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6098 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6099 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6100 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6101 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6102 | } |
| 6103 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6104 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 6105 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6106 | static const struct ephy_info e_info_8402[] = { |
| 6107 | { 0x19, 0xffff, 0xff64 }, |
| 6108 | { 0x1e, 0, 0x4000 } |
| 6109 | }; |
| 6110 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame] | 6111 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6112 | |
| 6113 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6114 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6115 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6116 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 6117 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6118 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6119 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6120 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6121 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6122 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6123 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6124 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6125 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6126 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6127 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6128 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6129 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6130 | |
| 6131 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6132 | } |
| 6133 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6134 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6135 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6136 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6137 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6138 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6139 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 6140 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6141 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6142 | |
| 6143 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6144 | } |
| 6145 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6146 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6147 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6148 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6149 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6150 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6151 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6152 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6153 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6154 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6155 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6156 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6157 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 6158 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6159 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6160 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6161 | switch (tp->mac_version) { |
| 6162 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6163 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6164 | break; |
| 6165 | |
| 6166 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6167 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6168 | break; |
| 6169 | |
| 6170 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6171 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6172 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6173 | |
| 6174 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6175 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6176 | break; |
| 6177 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6178 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6179 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6180 | |
| 6181 | case RTL_GIGA_MAC_VER_37: |
| 6182 | rtl_hw_start_8402(tp); |
| 6183 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6184 | |
| 6185 | case RTL_GIGA_MAC_VER_39: |
| 6186 | rtl_hw_start_8106(tp); |
| 6187 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6188 | case RTL_GIGA_MAC_VER_43: |
| 6189 | rtl_hw_start_8168g_2(tp); |
| 6190 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6191 | case RTL_GIGA_MAC_VER_47: |
| 6192 | case RTL_GIGA_MAC_VER_48: |
| 6193 | rtl_hw_start_8168h_1(tp); |
| 6194 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6195 | } |
| 6196 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6197 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6201 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6202 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6203 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6204 | if (new_mtu > ETH_DATA_LEN) |
| 6205 | rtl_hw_jumbo_enable(tp); |
| 6206 | else |
| 6207 | rtl_hw_jumbo_disable(tp); |
| 6208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6209 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6210 | netdev_update_features(dev); |
| 6211 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6212 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6213 | } |
| 6214 | |
| 6215 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6216 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6217 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6218 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6219 | } |
| 6220 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6221 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6222 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6224 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 6225 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6226 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6227 | kfree(*data_buff); |
| 6228 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6229 | rtl8169_make_unusable_by_asic(desc); |
| 6230 | } |
| 6231 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6232 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6233 | { |
| 6234 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6235 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6236 | /* Force memory writes to complete before releasing descriptor */ |
| 6237 | dma_wmb(); |
| 6238 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6239 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6240 | } |
| 6241 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6242 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6244 | return (void *)ALIGN((long)data, 16); |
| 6245 | } |
| 6246 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6247 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6248 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6249 | { |
| 6250 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6251 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6252 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 6253 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6255 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6256 | if (!data) |
| 6257 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6258 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6259 | if (rtl8169_align(data) != data) { |
| 6260 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6261 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6262 | if (!data) |
| 6263 | return NULL; |
| 6264 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6265 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6266 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6267 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6268 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6269 | if (net_ratelimit()) |
| 6270 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6271 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6272 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 6274 | desc->addr = cpu_to_le64(mapping); |
| 6275 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6276 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6277 | |
| 6278 | err_out: |
| 6279 | kfree(data); |
| 6280 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | } |
| 6282 | |
| 6283 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6284 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6285 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | |
| 6287 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6288 | if (tp->Rx_databuff[i]) { |
| 6289 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | tp->RxDescArray + i); |
| 6291 | } |
| 6292 | } |
| 6293 | } |
| 6294 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6295 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6297 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6298 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6299 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6300 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6301 | { |
| 6302 | unsigned int i; |
| 6303 | |
| 6304 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6305 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6306 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6307 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6308 | if (!data) { |
| 6309 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6310 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6311 | } |
| 6312 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6315 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6316 | return 0; |
| 6317 | |
| 6318 | err_out: |
| 6319 | rtl8169_rx_clear(tp); |
| 6320 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6321 | } |
| 6322 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6323 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6324 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6325 | rtl8169_init_ring_indexes(tp); |
| 6326 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6327 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 6328 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6329 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6330 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6331 | } |
| 6332 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6333 | 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] | 6334 | struct TxDesc *desc) |
| 6335 | { |
| 6336 | unsigned int len = tx_skb->len; |
| 6337 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6338 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6340 | desc->opts1 = 0x00; |
| 6341 | desc->opts2 = 0x00; |
| 6342 | desc->addr = 0x00; |
| 6343 | tx_skb->len = 0; |
| 6344 | } |
| 6345 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6346 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6347 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6348 | { |
| 6349 | unsigned int i; |
| 6350 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6351 | for (i = 0; i < n; i++) { |
| 6352 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6353 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6354 | unsigned int len = tx_skb->len; |
| 6355 | |
| 6356 | if (len) { |
| 6357 | struct sk_buff *skb = tx_skb->skb; |
| 6358 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6359 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6360 | tp->TxDescArray + entry); |
| 6361 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6362 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6363 | tx_skb->skb = NULL; |
| 6364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | } |
| 6366 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6370 | { |
| 6371 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | tp->cur_tx = tp->dirty_tx = 0; |
| 6373 | } |
| 6374 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6375 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6377 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6378 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6379 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6380 | napi_disable(&tp->napi); |
| 6381 | netif_stop_queue(dev); |
| 6382 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6384 | rtl8169_hw_reset(tp); |
| 6385 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6386 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6387 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6389 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6390 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6391 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6392 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6393 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6394 | netif_wake_queue(dev); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6395 | rtl8169_check_link_status(dev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6396 | } |
| 6397 | |
| 6398 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6399 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6400 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6401 | |
| 6402 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | 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] | 6406 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | { |
| 6408 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6409 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6410 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6411 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6412 | |
| 6413 | entry = tp->cur_tx; |
| 6414 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6415 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6416 | dma_addr_t mapping; |
| 6417 | u32 status, len; |
| 6418 | void *addr; |
| 6419 | |
| 6420 | entry = (entry + 1) % NUM_TX_DESC; |
| 6421 | |
| 6422 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6423 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6424 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6425 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6426 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6427 | if (net_ratelimit()) |
| 6428 | netif_err(tp, drv, tp->dev, |
| 6429 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6430 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6433 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6434 | status = opts[0] | len | |
| 6435 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6436 | |
| 6437 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6438 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6439 | txd->addr = cpu_to_le64(mapping); |
| 6440 | |
| 6441 | tp->tx_skb[entry].len = len; |
| 6442 | } |
| 6443 | |
| 6444 | if (cur_frag) { |
| 6445 | tp->tx_skb[entry].skb = skb; |
| 6446 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6447 | } |
| 6448 | |
| 6449 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6450 | |
| 6451 | err_out: |
| 6452 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6453 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6454 | } |
| 6455 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6456 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6457 | { |
| 6458 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6459 | } |
| 6460 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6461 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6462 | struct net_device *dev); |
| 6463 | /* r8169_csum_workaround() |
| 6464 | * The hw limites the value the transport offset. When the offset is out of the |
| 6465 | * range, calculate the checksum by sw. |
| 6466 | */ |
| 6467 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6468 | struct sk_buff *skb) |
| 6469 | { |
| 6470 | if (skb_shinfo(skb)->gso_size) { |
| 6471 | netdev_features_t features = tp->dev->features; |
| 6472 | struct sk_buff *segs, *nskb; |
| 6473 | |
| 6474 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6475 | segs = skb_gso_segment(skb, features); |
| 6476 | if (IS_ERR(segs) || !segs) |
| 6477 | goto drop; |
| 6478 | |
| 6479 | do { |
| 6480 | nskb = segs; |
| 6481 | segs = segs->next; |
| 6482 | nskb->next = NULL; |
| 6483 | rtl8169_start_xmit(nskb, tp->dev); |
| 6484 | } while (segs); |
| 6485 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6486 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6487 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6488 | if (skb_checksum_help(skb) < 0) |
| 6489 | goto drop; |
| 6490 | |
| 6491 | rtl8169_start_xmit(skb, tp->dev); |
| 6492 | } else { |
| 6493 | struct net_device_stats *stats; |
| 6494 | |
| 6495 | drop: |
| 6496 | stats = &tp->dev->stats; |
| 6497 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6498 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6499 | } |
| 6500 | } |
| 6501 | |
| 6502 | /* msdn_giant_send_check() |
| 6503 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6504 | * packet length for IPv6 TCP large packets. |
| 6505 | */ |
| 6506 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6507 | { |
| 6508 | const struct ipv6hdr *ipv6h; |
| 6509 | struct tcphdr *th; |
| 6510 | int ret; |
| 6511 | |
| 6512 | ret = skb_cow_head(skb, 0); |
| 6513 | if (ret) |
| 6514 | return ret; |
| 6515 | |
| 6516 | ipv6h = ipv6_hdr(skb); |
| 6517 | th = tcp_hdr(skb); |
| 6518 | |
| 6519 | th->check = 0; |
| 6520 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6521 | |
| 6522 | return ret; |
| 6523 | } |
| 6524 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6525 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6526 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6527 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6528 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6529 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6530 | if (mss) { |
| 6531 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6532 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6533 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6534 | const struct iphdr *ip = ip_hdr(skb); |
| 6535 | |
| 6536 | if (ip->protocol == IPPROTO_TCP) |
| 6537 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6538 | else if (ip->protocol == IPPROTO_UDP) |
| 6539 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6540 | else |
| 6541 | WARN_ON_ONCE(1); |
| 6542 | } |
| 6543 | |
| 6544 | return true; |
| 6545 | } |
| 6546 | |
| 6547 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6548 | struct sk_buff *skb, u32 *opts) |
| 6549 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6550 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6551 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6552 | |
| 6553 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6554 | if (transport_offset > GTTCPHO_MAX) { |
| 6555 | netif_warn(tp, tx_err, tp->dev, |
| 6556 | "Invalid transport offset 0x%x for TSO\n", |
| 6557 | transport_offset); |
| 6558 | return false; |
| 6559 | } |
| 6560 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6561 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6562 | case htons(ETH_P_IP): |
| 6563 | opts[0] |= TD1_GTSENV4; |
| 6564 | break; |
| 6565 | |
| 6566 | case htons(ETH_P_IPV6): |
| 6567 | if (msdn_giant_send_check(skb)) |
| 6568 | return false; |
| 6569 | |
| 6570 | opts[0] |= TD1_GTSENV6; |
| 6571 | break; |
| 6572 | |
| 6573 | default: |
| 6574 | WARN_ON_ONCE(1); |
| 6575 | break; |
| 6576 | } |
| 6577 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6578 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6579 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6580 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6581 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6583 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6584 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6585 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6586 | if (transport_offset > TCPHO_MAX) { |
| 6587 | netif_warn(tp, tx_err, tp->dev, |
| 6588 | "Invalid transport offset 0x%x\n", |
| 6589 | transport_offset); |
| 6590 | return false; |
| 6591 | } |
| 6592 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6593 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6594 | case htons(ETH_P_IP): |
| 6595 | opts[1] |= TD1_IPv4_CS; |
| 6596 | ip_protocol = ip_hdr(skb)->protocol; |
| 6597 | break; |
| 6598 | |
| 6599 | case htons(ETH_P_IPV6): |
| 6600 | opts[1] |= TD1_IPv6_CS; |
| 6601 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6602 | break; |
| 6603 | |
| 6604 | default: |
| 6605 | ip_protocol = IPPROTO_RAW; |
| 6606 | break; |
| 6607 | } |
| 6608 | |
| 6609 | if (ip_protocol == IPPROTO_TCP) |
| 6610 | opts[1] |= TD1_TCP_CS; |
| 6611 | else if (ip_protocol == IPPROTO_UDP) |
| 6612 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6613 | else |
| 6614 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6615 | |
| 6616 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6617 | } else { |
| 6618 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6619 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6620 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6621 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6622 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6623 | } |
| 6624 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6625 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6626 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6627 | { |
| 6628 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6629 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6630 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6631 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6632 | dma_addr_t mapping; |
| 6633 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6634 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6635 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6636 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6637 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6638 | 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] | 6639 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6643 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6644 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6645 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6646 | opts[0] = DescOwn; |
| 6647 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6648 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6649 | r8169_csum_workaround(tp, skb); |
| 6650 | return NETDEV_TX_OK; |
| 6651 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6652 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6653 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6654 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6655 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6656 | if (net_ratelimit()) |
| 6657 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6658 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6660 | |
| 6661 | tp->tx_skb[entry].len = len; |
| 6662 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6663 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6664 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6665 | if (frags < 0) |
| 6666 | goto err_dma_1; |
| 6667 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6668 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6669 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6670 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6671 | tp->tx_skb[entry].skb = skb; |
| 6672 | } |
| 6673 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6674 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6675 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6676 | skb_tx_timestamp(skb); |
| 6677 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6678 | /* Force memory writes to complete before releasing descriptor */ |
| 6679 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6680 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6681 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6682 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6683 | txd->opts1 = cpu_to_le32(status); |
| 6684 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6685 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6686 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6687 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6688 | tp->cur_tx += frags + 1; |
| 6689 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6690 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6691 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6692 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6693 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6694 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6695 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6696 | * not miss a ring update when it notices a stopped queue. |
| 6697 | */ |
| 6698 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6699 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6700 | /* Sync with rtl_tx: |
| 6701 | * - publish queue status and cur_tx ring index (write barrier) |
| 6702 | * - refresh dirty_tx ring index (read barrier). |
| 6703 | * May the current thread have a pessimistic view of the ring |
| 6704 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6705 | * can't. |
| 6706 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6707 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6708 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6709 | netif_wake_queue(dev); |
| 6710 | } |
| 6711 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6712 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6713 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6714 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6715 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6716 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6717 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6718 | dev->stats.tx_dropped++; |
| 6719 | return NETDEV_TX_OK; |
| 6720 | |
| 6721 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6722 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6723 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6724 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6725 | } |
| 6726 | |
| 6727 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6728 | { |
| 6729 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6730 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6731 | u16 pci_status, pci_cmd; |
| 6732 | |
| 6733 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6734 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6735 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6736 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6737 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | |
| 6739 | /* |
| 6740 | * The recovery sequence below admits a very elaborated explanation: |
| 6741 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6742 | * - I did not see what else could be done; |
| 6743 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6744 | * |
| 6745 | * Feel free to adjust to your needs. |
| 6746 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6747 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6748 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6749 | else |
| 6750 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6751 | |
| 6752 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | |
| 6754 | pci_write_config_word(pdev, PCI_STATUS, |
| 6755 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6756 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6757 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6758 | |
| 6759 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6760 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6761 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6762 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6763 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6764 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6765 | } |
| 6766 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6767 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6768 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6769 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6770 | } |
| 6771 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6772 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6773 | { |
| 6774 | unsigned int dirty_tx, tx_left; |
| 6775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | dirty_tx = tp->dirty_tx; |
| 6777 | smp_rmb(); |
| 6778 | tx_left = tp->cur_tx - dirty_tx; |
| 6779 | |
| 6780 | while (tx_left > 0) { |
| 6781 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6782 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6783 | u32 status; |
| 6784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6786 | if (status & DescOwn) |
| 6787 | break; |
| 6788 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6789 | /* This barrier is needed to keep us from reading |
| 6790 | * any other fields out of the Tx descriptor until |
| 6791 | * we know the status of DescOwn |
| 6792 | */ |
| 6793 | dma_rmb(); |
| 6794 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6795 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6796 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6797 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6798 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6799 | tp->tx_stats.packets++; |
| 6800 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 6801 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6802 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6803 | tx_skb->skb = NULL; |
| 6804 | } |
| 6805 | dirty_tx++; |
| 6806 | tx_left--; |
| 6807 | } |
| 6808 | |
| 6809 | if (tp->dirty_tx != dirty_tx) { |
| 6810 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6811 | /* Sync with rtl8169_start_xmit: |
| 6812 | * - publish dirty_tx ring index (write barrier) |
| 6813 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6814 | * May the current thread miss the stopped queue condition, |
| 6815 | * a racing xmit thread can only have a right view of the |
| 6816 | * ring status. |
| 6817 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6818 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6819 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6820 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6821 | netif_wake_queue(dev); |
| 6822 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6823 | /* |
| 6824 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6825 | * too close. Let's kick an extra TxPoll request when a burst |
| 6826 | * of start_xmit activity is detected (if it is not detected, |
| 6827 | * it is slow enough). -- FR |
| 6828 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6829 | if (tp->cur_tx != dirty_tx) |
| 6830 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6831 | } |
| 6832 | } |
| 6833 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6834 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6835 | { |
| 6836 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6837 | } |
| 6838 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6839 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6841 | u32 status = opts1 & RxProtoMask; |
| 6842 | |
| 6843 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6844 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6845 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6846 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6847 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | } |
| 6849 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6850 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6851 | struct rtl8169_private *tp, |
| 6852 | int pkt_size, |
| 6853 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6854 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6855 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6856 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6857 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6858 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6859 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6860 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6861 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6862 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6863 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6864 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6865 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6866 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6867 | } |
| 6868 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6869 | 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] | 6870 | { |
| 6871 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6872 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6874 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6876 | 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] | 6877 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6878 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6879 | u32 status; |
| 6880 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6881 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6882 | if (status & DescOwn) |
| 6883 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6884 | |
| 6885 | /* This barrier is needed to keep us from reading |
| 6886 | * any other fields out of the Rx descriptor until |
| 6887 | * we know the status of DescOwn |
| 6888 | */ |
| 6889 | dma_rmb(); |
| 6890 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6891 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6892 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6893 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6894 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6895 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6896 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6897 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6898 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6899 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6900 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6901 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6902 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6903 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6904 | } else if (status & (RxRUNT | RxCRC) && |
| 6905 | !(status & RxRWT) && |
| 6906 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6907 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6909 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6910 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6911 | dma_addr_t addr; |
| 6912 | int pkt_size; |
| 6913 | |
| 6914 | process_pkt: |
| 6915 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6916 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6917 | pkt_size = (status & 0x00003fff) - 4; |
| 6918 | else |
| 6919 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6920 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6921 | /* |
| 6922 | * The driver does not support incoming fragmented |
| 6923 | * frames. They are seen as a symptom of over-mtu |
| 6924 | * sized frames. |
| 6925 | */ |
| 6926 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6927 | dev->stats.rx_dropped++; |
| 6928 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6929 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6930 | } |
| 6931 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6932 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6933 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6934 | if (!skb) { |
| 6935 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6936 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6937 | } |
| 6938 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6939 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6940 | skb_put(skb, pkt_size); |
| 6941 | skb->protocol = eth_type_trans(skb, dev); |
| 6942 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6943 | rtl8169_rx_vlan_tag(desc, skb); |
| 6944 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6945 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6946 | dev->stats.multicast++; |
| 6947 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6948 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6949 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6950 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6951 | tp->rx_stats.packets++; |
| 6952 | tp->rx_stats.bytes += pkt_size; |
| 6953 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6954 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6955 | release_descriptor: |
| 6956 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6957 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | count = cur_rx - tp->cur_rx; |
| 6961 | tp->cur_rx = cur_rx; |
| 6962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6963 | return count; |
| 6964 | } |
| 6965 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6966 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6967 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6968 | struct rtl8169_private *tp = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6969 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6970 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6971 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6972 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6973 | if (status && status != 0xffff) { |
| 6974 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 6975 | if (status) { |
| 6976 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6977 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6978 | rtl_irq_disable(tp); |
Heiner Kallweit | 9a899a3 | 2018-04-17 23:21:01 +0200 | [diff] [blame] | 6979 | napi_schedule_irqoff(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6982 | return IRQ_RETVAL(handled); |
| 6983 | } |
| 6984 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6985 | /* |
| 6986 | * Workqueue context. |
| 6987 | */ |
| 6988 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6989 | { |
| 6990 | struct net_device *dev = tp->dev; |
| 6991 | u16 status; |
| 6992 | |
| 6993 | status = rtl_get_events(tp) & tp->event_slow; |
| 6994 | rtl_ack_events(tp, status); |
| 6995 | |
| 6996 | if (unlikely(status & RxFIFOOver)) { |
| 6997 | switch (tp->mac_version) { |
| 6998 | /* Work around for rx fifo overflow */ |
| 6999 | case RTL_GIGA_MAC_VER_11: |
| 7000 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7001 | /* XXX - Hack alert. See rtl_task(). */ |
| 7002 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7003 | default: |
| 7004 | break; |
| 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | if (unlikely(status & SYSErr)) |
| 7009 | rtl8169_pcierr_interrupt(dev); |
| 7010 | |
| 7011 | if (status & LinkChg) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7012 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7013 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 7014 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7015 | } |
| 7016 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7017 | static void rtl_task(struct work_struct *work) |
| 7018 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7019 | static const struct { |
| 7020 | int bitnr; |
| 7021 | void (*action)(struct rtl8169_private *); |
| 7022 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7023 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7024 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 7025 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 7026 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 7027 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7028 | struct rtl8169_private *tp = |
| 7029 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7030 | struct net_device *dev = tp->dev; |
| 7031 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7032 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7033 | rtl_lock_work(tp); |
| 7034 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7035 | if (!netif_running(dev) || |
| 7036 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7037 | goto out_unlock; |
| 7038 | |
| 7039 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 7040 | bool pending; |
| 7041 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7042 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7043 | if (pending) |
| 7044 | rtl_work[i].action(tp); |
| 7045 | } |
| 7046 | |
| 7047 | out_unlock: |
| 7048 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7049 | } |
| 7050 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7051 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7053 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 7054 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7055 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 7056 | int work_done= 0; |
| 7057 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7058 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7059 | status = rtl_get_events(tp); |
| 7060 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 7061 | |
| 7062 | if (status & RTL_EVENT_NAPI_RX) |
| 7063 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7064 | |
| 7065 | if (status & RTL_EVENT_NAPI_TX) |
| 7066 | rtl_tx(dev, tp); |
| 7067 | |
| 7068 | if (status & tp->event_slow) { |
| 7069 | enable_mask &= ~tp->event_slow; |
| 7070 | |
| 7071 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7073 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7074 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 7075 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7076 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7077 | rtl_irq_enable(tp, enable_mask); |
| 7078 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7079 | } |
| 7080 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7081 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7082 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7083 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7084 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7085 | { |
| 7086 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7087 | |
| 7088 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7089 | return; |
| 7090 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7091 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 7092 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7093 | } |
| 7094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7095 | static void rtl8169_down(struct net_device *dev) |
| 7096 | { |
| 7097 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7098 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7099 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7100 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7101 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7102 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7103 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7104 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7105 | /* |
| 7106 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7107 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7108 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7109 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7110 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7113 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7115 | rtl8169_tx_clear(tp); |
| 7116 | |
| 7117 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7118 | |
| 7119 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | static int rtl8169_close(struct net_device *dev) |
| 7123 | { |
| 7124 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7125 | struct pci_dev *pdev = tp->pci_dev; |
| 7126 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7127 | pm_runtime_get_sync(&pdev->dev); |
| 7128 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7129 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7130 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7131 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7132 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7133 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7136 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7137 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7138 | cancel_work_sync(&tp->wk.work); |
| 7139 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7140 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7141 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7142 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7143 | tp->RxPhyAddr); |
| 7144 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7145 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7146 | tp->TxDescArray = NULL; |
| 7147 | tp->RxDescArray = NULL; |
| 7148 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7149 | pm_runtime_put_sync(&pdev->dev); |
| 7150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7151 | return 0; |
| 7152 | } |
| 7153 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7154 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7155 | static void rtl8169_netpoll(struct net_device *dev) |
| 7156 | { |
| 7157 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7158 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 7159 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7160 | } |
| 7161 | #endif |
| 7162 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7163 | static int rtl_open(struct net_device *dev) |
| 7164 | { |
| 7165 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7166 | struct pci_dev *pdev = tp->pci_dev; |
| 7167 | int retval = -ENOMEM; |
| 7168 | |
| 7169 | pm_runtime_get_sync(&pdev->dev); |
| 7170 | |
| 7171 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7172 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7173 | * dma_alloc_coherent provides more. |
| 7174 | */ |
| 7175 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7176 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7177 | if (!tp->TxDescArray) |
| 7178 | goto err_pm_runtime_put; |
| 7179 | |
| 7180 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7181 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7182 | if (!tp->RxDescArray) |
| 7183 | goto err_free_tx_0; |
| 7184 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 7185 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7186 | if (retval < 0) |
| 7187 | goto err_free_rx_1; |
| 7188 | |
| 7189 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7190 | |
| 7191 | smp_mb(); |
| 7192 | |
| 7193 | rtl_request_firmware(tp); |
| 7194 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7195 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7196 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7197 | if (retval < 0) |
| 7198 | goto err_release_fw_2; |
| 7199 | |
| 7200 | rtl_lock_work(tp); |
| 7201 | |
| 7202 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7203 | |
| 7204 | napi_enable(&tp->napi); |
| 7205 | |
| 7206 | rtl8169_init_phy(dev, tp); |
| 7207 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7208 | rtl_pll_power_up(tp); |
| 7209 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7210 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7211 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7212 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7213 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7214 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7215 | netif_start_queue(dev); |
| 7216 | |
| 7217 | rtl_unlock_work(tp); |
| 7218 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7219 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7220 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7221 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7222 | out: |
| 7223 | return retval; |
| 7224 | |
| 7225 | err_release_fw_2: |
| 7226 | rtl_release_firmware(tp); |
| 7227 | rtl8169_rx_clear(tp); |
| 7228 | err_free_rx_1: |
| 7229 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7230 | tp->RxPhyAddr); |
| 7231 | tp->RxDescArray = NULL; |
| 7232 | err_free_tx_0: |
| 7233 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7234 | tp->TxPhyAddr); |
| 7235 | tp->TxDescArray = NULL; |
| 7236 | err_pm_runtime_put: |
| 7237 | pm_runtime_put_noidle(&pdev->dev); |
| 7238 | goto out; |
| 7239 | } |
| 7240 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7241 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7242 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7243 | { |
| 7244 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7245 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7246 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7247 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7248 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7249 | pm_runtime_get_noresume(&pdev->dev); |
| 7250 | |
| 7251 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7252 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7253 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7254 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7255 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7256 | stats->rx_packets = tp->rx_stats.packets; |
| 7257 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7258 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7259 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7260 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7261 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7262 | stats->tx_packets = tp->tx_stats.packets; |
| 7263 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7264 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7265 | |
| 7266 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7267 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7268 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7269 | stats->rx_errors = dev->stats.rx_errors; |
| 7270 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7271 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7272 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7273 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7274 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7275 | /* |
| 7276 | * Fetch additonal counter values missing in stats collected by driver |
| 7277 | * from tally counters. |
| 7278 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7279 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7280 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7281 | |
| 7282 | /* |
| 7283 | * Subtract values fetched during initalization. |
| 7284 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 7285 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7286 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7287 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7288 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7289 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7290 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7291 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 7292 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7293 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7296 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7297 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7298 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7299 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7300 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7301 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7302 | |
| 7303 | netif_device_detach(dev); |
| 7304 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7305 | |
| 7306 | rtl_lock_work(tp); |
| 7307 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7308 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7309 | rtl_unlock_work(tp); |
| 7310 | |
| 7311 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7312 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7313 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7314 | #ifdef CONFIG_PM |
| 7315 | |
| 7316 | static int rtl8169_suspend(struct device *device) |
| 7317 | { |
| 7318 | struct pci_dev *pdev = to_pci_dev(device); |
| 7319 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7320 | |
| 7321 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 7322 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7323 | return 0; |
| 7324 | } |
| 7325 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7326 | static void __rtl8169_resume(struct net_device *dev) |
| 7327 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7328 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7329 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7330 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7331 | |
| 7332 | rtl_pll_power_up(tp); |
Heiner Kallweit | 92bad85 | 2018-06-24 18:37:36 +0200 | [diff] [blame] | 7333 | rtl8169_init_phy(dev, tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7334 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7335 | rtl_lock_work(tp); |
| 7336 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7337 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7338 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7339 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7340 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7343 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7344 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7345 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7346 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7347 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7348 | if (netif_running(dev)) |
| 7349 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7350 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7351 | return 0; |
| 7352 | } |
| 7353 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7354 | static int rtl8169_runtime_suspend(struct device *device) |
| 7355 | { |
| 7356 | struct pci_dev *pdev = to_pci_dev(device); |
| 7357 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7358 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7359 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7360 | if (!tp->TxDescArray) { |
| 7361 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7362 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7363 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7364 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7365 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7366 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7367 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7368 | |
| 7369 | rtl8169_net_suspend(dev); |
| 7370 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7371 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7372 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7373 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7374 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7375 | return 0; |
| 7376 | } |
| 7377 | |
| 7378 | static int rtl8169_runtime_resume(struct device *device) |
| 7379 | { |
| 7380 | struct pci_dev *pdev = to_pci_dev(device); |
| 7381 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7382 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 7383 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7384 | |
| 7385 | if (!tp->TxDescArray) |
| 7386 | return 0; |
| 7387 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7388 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7389 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7390 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7391 | |
| 7392 | __rtl8169_resume(dev); |
| 7393 | |
| 7394 | return 0; |
| 7395 | } |
| 7396 | |
| 7397 | static int rtl8169_runtime_idle(struct device *device) |
| 7398 | { |
| 7399 | struct pci_dev *pdev = to_pci_dev(device); |
| 7400 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7401 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7402 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 7403 | pm_schedule_suspend(device, 10000); |
| 7404 | |
| 7405 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7406 | } |
| 7407 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7408 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7409 | .suspend = rtl8169_suspend, |
| 7410 | .resume = rtl8169_resume, |
| 7411 | .freeze = rtl8169_suspend, |
| 7412 | .thaw = rtl8169_resume, |
| 7413 | .poweroff = rtl8169_suspend, |
| 7414 | .restore = rtl8169_resume, |
| 7415 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7416 | .runtime_resume = rtl8169_runtime_resume, |
| 7417 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7418 | }; |
| 7419 | |
| 7420 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7421 | |
| 7422 | #else /* !CONFIG_PM */ |
| 7423 | |
| 7424 | #define RTL8169_PM_OPS NULL |
| 7425 | |
| 7426 | #endif /* !CONFIG_PM */ |
| 7427 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7428 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7429 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7430 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7431 | switch (tp->mac_version) { |
| 7432 | case RTL_GIGA_MAC_VER_11: |
| 7433 | case RTL_GIGA_MAC_VER_12: |
| 7434 | case RTL_GIGA_MAC_VER_17: |
| 7435 | pci_clear_master(tp->pci_dev); |
| 7436 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7437 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7438 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7439 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7440 | break; |
| 7441 | default: |
| 7442 | break; |
| 7443 | } |
| 7444 | } |
| 7445 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7446 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7447 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7448 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7449 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7450 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7451 | rtl8169_net_suspend(dev); |
| 7452 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7453 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7454 | rtl_rar_set(tp, dev->perm_addr); |
| 7455 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7456 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7457 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7458 | if (system_state == SYSTEM_POWER_OFF) { |
Heiner Kallweit | 433f9d0 | 2018-06-24 18:39:06 +0200 | [diff] [blame] | 7459 | if (tp->saved_wolopts) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7460 | rtl_wol_suspend_quirk(tp); |
| 7461 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7462 | } |
| 7463 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7464 | pci_wake_from_d3(pdev, true); |
| 7465 | pci_set_power_state(pdev, PCI_D3hot); |
| 7466 | } |
| 7467 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7468 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7469 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7470 | { |
| 7471 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7472 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7473 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7474 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7475 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7476 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7477 | netif_napi_del(&tp->napi); |
| 7478 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7479 | unregister_netdev(dev); |
| 7480 | |
| 7481 | rtl_release_firmware(tp); |
| 7482 | |
| 7483 | if (pci_dev_run_wake(pdev)) |
| 7484 | pm_runtime_get_noresume(&pdev->dev); |
| 7485 | |
| 7486 | /* restore original MAC address */ |
| 7487 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7488 | } |
| 7489 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7490 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7491 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7492 | .ndo_stop = rtl8169_close, |
| 7493 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7494 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7495 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7496 | .ndo_validate_addr = eth_validate_addr, |
| 7497 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7498 | .ndo_fix_features = rtl8169_fix_features, |
| 7499 | .ndo_set_features = rtl8169_set_features, |
| 7500 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7501 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7502 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7503 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7504 | .ndo_poll_controller = rtl8169_netpoll, |
| 7505 | #endif |
| 7506 | |
| 7507 | }; |
| 7508 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7509 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7510 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7511 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7512 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7513 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7514 | u8 default_ver; |
| 7515 | } rtl_cfg_infos [] = { |
| 7516 | [RTL_CFG_0] = { |
| 7517 | .hw_start = rtl_hw_start_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7518 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7519 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7520 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7521 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7522 | }, |
| 7523 | [RTL_CFG_1] = { |
| 7524 | .hw_start = rtl_hw_start_8168, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7525 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7526 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7527 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7528 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7529 | }, |
| 7530 | [RTL_CFG_2] = { |
| 7531 | .hw_start = rtl_hw_start_8101, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7532 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7533 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7534 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7535 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7536 | } |
| 7537 | }; |
| 7538 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7539 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7540 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7541 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7542 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7543 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7544 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7545 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7546 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7547 | flags = PCI_IRQ_LEGACY; |
| 7548 | } else { |
| 7549 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7550 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7551 | |
| 7552 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7553 | } |
| 7554 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7555 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7556 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7557 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7558 | } |
| 7559 | |
| 7560 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7561 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7562 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7563 | } |
| 7564 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7565 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7566 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7567 | u32 data; |
| 7568 | |
| 7569 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7570 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7571 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7572 | |
| 7573 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7574 | return; |
| 7575 | |
| 7576 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7577 | return; |
| 7578 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7579 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7580 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7581 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7582 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7583 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7584 | data &= ~(1 << 14); |
| 7585 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7586 | |
| 7587 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7588 | return; |
| 7589 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7590 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7591 | data |= (1 << 15); |
| 7592 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7593 | |
| 7594 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7595 | return; |
| 7596 | } |
| 7597 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7598 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7599 | { |
| 7600 | rtl8168ep_stop_cmac(tp); |
| 7601 | rtl_hw_init_8168g(tp); |
| 7602 | } |
| 7603 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7604 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7605 | { |
| 7606 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7607 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7608 | rtl_hw_init_8168g(tp); |
| 7609 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7610 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7611 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7612 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7613 | default: |
| 7614 | break; |
| 7615 | } |
| 7616 | } |
| 7617 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7618 | 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] | 7619 | { |
| 7620 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7621 | struct rtl8169_private *tp; |
| 7622 | struct mii_if_info *mii; |
| 7623 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7624 | int chipset, region, i; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7625 | int rc; |
| 7626 | |
| 7627 | if (netif_msg_drv(&debug)) { |
| 7628 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 7629 | MODULENAME, RTL8169_VERSION); |
| 7630 | } |
| 7631 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7632 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7633 | if (!dev) |
| 7634 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7635 | |
| 7636 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7637 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7638 | tp = netdev_priv(dev); |
| 7639 | tp->dev = dev; |
| 7640 | tp->pci_dev = pdev; |
| 7641 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 7642 | |
| 7643 | mii = &tp->mii; |
| 7644 | mii->dev = dev; |
| 7645 | mii->mdio_read = rtl_mdio_read; |
| 7646 | mii->mdio_write = rtl_mdio_write; |
| 7647 | mii->phy_id_mask = 0x1f; |
| 7648 | mii->reg_num_mask = 0x1f; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7649 | mii->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7650 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7651 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7652 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7653 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7654 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7655 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7656 | } |
| 7657 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7658 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7659 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7660 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7661 | /* use first MMIO region */ |
| 7662 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7663 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7664 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7665 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | /* check for weird/broken PCI region reporting */ |
| 7669 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7670 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7671 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7672 | } |
| 7673 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7674 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7675 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7676 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7677 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7678 | } |
| 7679 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7680 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7681 | |
| 7682 | if (!pci_is_pcie(pdev)) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7683 | dev_info(&pdev->dev, "not PCI Express\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7684 | |
| 7685 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7686 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7687 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7688 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7689 | |
| 7690 | if ((sizeof(dma_addr_t) > 4) && |
| 7691 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 7692 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 7693 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 7694 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7695 | |
| 7696 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7697 | if (!pci_is_pcie(pdev)) |
| 7698 | tp->cp_cmd |= PCIDAC; |
| 7699 | dev->features |= NETIF_F_HIGHDMA; |
| 7700 | } else { |
| 7701 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7702 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7703 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7704 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7705 | } |
| 7706 | } |
| 7707 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7708 | rtl_init_rxcfg(tp); |
| 7709 | |
| 7710 | rtl_irq_disable(tp); |
| 7711 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7712 | rtl_hw_initialize(tp); |
| 7713 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7714 | rtl_hw_reset(tp); |
| 7715 | |
| 7716 | rtl_ack_events(tp, 0xffff); |
| 7717 | |
| 7718 | pci_set_master(pdev); |
| 7719 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7720 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7721 | rtl_init_jumbo_ops(tp); |
| 7722 | |
| 7723 | rtl8169_print_mac_version(tp); |
| 7724 | |
| 7725 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7726 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7727 | rc = rtl_alloc_irq(tp); |
| 7728 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7729 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7730 | return rc; |
| 7731 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7732 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7733 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 7734 | __rtl8169_set_wol(tp, 0); |
| 7735 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7736 | if (rtl_tbi_enabled(tp)) { |
| 7737 | tp->set_speed = rtl8169_set_speed_tbi; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 7738 | tp->get_link_ksettings = rtl8169_get_link_ksettings_tbi; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7739 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 7740 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 7741 | tp->link_ok = rtl8169_tbi_link_ok; |
| 7742 | tp->do_ioctl = rtl_tbi_ioctl; |
| 7743 | } else { |
| 7744 | tp->set_speed = rtl8169_set_speed_xmii; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 7745 | tp->get_link_ksettings = rtl8169_get_link_ksettings_xmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7746 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 7747 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 7748 | tp->link_ok = rtl8169_xmii_link_ok; |
| 7749 | tp->do_ioctl = rtl_xmii_ioctl; |
| 7750 | } |
| 7751 | |
| 7752 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7753 | u64_stats_init(&tp->rx_stats.syncp); |
| 7754 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7755 | |
| 7756 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7757 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7758 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7759 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7760 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7761 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7762 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7763 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7764 | if (is_valid_ether_addr(mac_addr)) |
| 7765 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7766 | break; |
| 7767 | default: |
| 7768 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7769 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7770 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7771 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7772 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7773 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7774 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7775 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7776 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7777 | |
| 7778 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7779 | * properly for all devices */ |
| 7780 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7781 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7782 | |
| 7783 | 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] | 7784 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7785 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7786 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7787 | NETIF_F_HIGHDMA; |
| 7788 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7789 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7790 | |
| 7791 | /* |
| 7792 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7793 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7794 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7795 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7796 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7797 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7798 | |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7799 | switch (rtl_chip_infos[chipset].txd_version) { |
| 7800 | case RTL_TD_0: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7801 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7802 | break; |
| 7803 | case RTL_TD_1: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7804 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7805 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7806 | break; |
| 7807 | default: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7808 | WARN_ON_ONCE(1); |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7809 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7810 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7811 | dev->hw_features |= NETIF_F_RXALL; |
| 7812 | dev->hw_features |= NETIF_F_RXFCS; |
| 7813 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7814 | /* MTU range: 60 - hw-specific max */ |
| 7815 | dev->min_mtu = ETH_ZLEN; |
| 7816 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 7817 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7818 | tp->hw_start = cfg->hw_start; |
| 7819 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7820 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7821 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 7822 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7823 | |
| 7824 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7825 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7826 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7827 | &tp->counters_phys_addr, |
| 7828 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7829 | if (!tp->counters) |
| 7830 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7831 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7832 | pci_set_drvdata(pdev, dev); |
| 7833 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7834 | rc = register_netdev(dev); |
| 7835 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7836 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7837 | |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7838 | netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n", |
| 7839 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 90b989c | 2018-04-17 23:32:15 +0200 | [diff] [blame] | 7840 | (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7841 | pci_irq_vector(pdev, 0)); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7842 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 7843 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 7844 | "tx checksumming: %s]\n", |
| 7845 | rtl_chip_infos[chipset].jumbo_max, |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 7846 | tp->mac_version <= RTL_GIGA_MAC_VER_06 ? "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7847 | } |
| 7848 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7849 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7850 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7851 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7852 | netif_carrier_off(dev); |
| 7853 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7854 | if (pci_dev_run_wake(pdev)) |
| 7855 | pm_runtime_put_sync(&pdev->dev); |
| 7856 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7857 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7858 | } |
| 7859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7860 | static struct pci_driver rtl8169_pci_driver = { |
| 7861 | .name = MODULENAME, |
| 7862 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7863 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7864 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7865 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7866 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7867 | }; |
| 7868 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7869 | module_pci_driver(rtl8169_pci_driver); |