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 | |
| 1590 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1591 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1592 | u8 options; |
| 1593 | u32 wolopts = 0; |
| 1594 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1595 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1596 | if (!(options & PMEnable)) |
| 1597 | return 0; |
| 1598 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1599 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1600 | if (options & LinkUp) |
| 1601 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1602 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1603 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1604 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1605 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1606 | wolopts |= WAKE_MAGIC; |
| 1607 | break; |
| 1608 | default: |
| 1609 | if (options & MagicPacket) |
| 1610 | wolopts |= WAKE_MAGIC; |
| 1611 | break; |
| 1612 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1613 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1614 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1615 | if (options & UWF) |
| 1616 | wolopts |= WAKE_UCAST; |
| 1617 | if (options & BWF) |
| 1618 | wolopts |= WAKE_BCAST; |
| 1619 | if (options & MWF) |
| 1620 | wolopts |= WAKE_MCAST; |
| 1621 | |
| 1622 | return wolopts; |
| 1623 | } |
| 1624 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1625 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1626 | { |
| 1627 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1628 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1629 | |
| 1630 | pm_runtime_get_noresume(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1631 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1632 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1633 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1634 | wol->supported = WAKE_ANY; |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1635 | if (pm_runtime_active(d)) |
| 1636 | wol->wolopts = __rtl8169_get_wol(tp); |
| 1637 | else |
| 1638 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1639 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1640 | rtl_unlock_work(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1641 | |
| 1642 | pm_runtime_put_noidle(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1643 | } |
| 1644 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1645 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1646 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1647 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1648 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1649 | u32 opt; |
| 1650 | u16 reg; |
| 1651 | u8 mask; |
| 1652 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1653 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1654 | { WAKE_UCAST, Config5, UWF }, |
| 1655 | { WAKE_BCAST, Config5, BWF }, |
| 1656 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1657 | { WAKE_ANY, Config5, LanWake }, |
| 1658 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1659 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1660 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1661 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1662 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1663 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1664 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 1665 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 1666 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1667 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1668 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1669 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1670 | 0x0dc, |
| 1671 | ERIAR_MASK_0100, |
| 1672 | MagicPacket_v2, |
| 1673 | 0x0000, |
| 1674 | ERIAR_EXGMAC); |
| 1675 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1676 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1677 | 0x0dc, |
| 1678 | ERIAR_MASK_0100, |
| 1679 | 0x0000, |
| 1680 | MagicPacket_v2, |
| 1681 | ERIAR_EXGMAC); |
| 1682 | break; |
| 1683 | default: |
| 1684 | tmp = ARRAY_SIZE(cfg); |
| 1685 | break; |
| 1686 | } |
| 1687 | |
| 1688 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1689 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1690 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1691 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1692 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1693 | } |
| 1694 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1695 | switch (tp->mac_version) { |
| 1696 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1697 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1698 | if (wolopts) |
| 1699 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1700 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1701 | break; |
| 1702 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1703 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1704 | if (wolopts) |
| 1705 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1706 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1707 | break; |
| 1708 | } |
| 1709 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1710 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1714 | { |
| 1715 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1716 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1717 | |
| 1718 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1719 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1720 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1721 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1722 | if (pm_runtime_active(d)) |
| 1723 | __rtl8169_set_wol(tp, wol->wolopts); |
| 1724 | else |
| 1725 | tp->saved_wolopts = wol->wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1726 | |
| 1727 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1728 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1729 | device_set_wakeup_enable(d, wol->wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1730 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1731 | pm_runtime_put_noidle(d); |
| 1732 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1733 | return 0; |
| 1734 | } |
| 1735 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1736 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1737 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1738 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1742 | struct ethtool_drvinfo *info) |
| 1743 | { |
| 1744 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1745 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1747 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1748 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1749 | 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] | 1750 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1751 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1752 | strlcpy(info->fw_version, rtl_fw->version, |
| 1753 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1757 | { |
| 1758 | return R8169_REGS_SIZE; |
| 1759 | } |
| 1760 | |
| 1761 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1762 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | { |
| 1764 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | int ret = 0; |
| 1766 | u32 reg; |
| 1767 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1768 | reg = RTL_R32(tp, TBICSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1770 | (duplex == DUPLEX_FULL)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1771 | RTL_W32(tp, TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } else if (autoneg == AUTONEG_ENABLE) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1773 | RTL_W32(tp, TBICSR, reg | TBINwEnable | TBINwRestart); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1775 | netif_warn(tp, link, dev, |
| 1776 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | ret = -EOPNOTSUPP; |
| 1778 | } |
| 1779 | |
| 1780 | return ret; |
| 1781 | } |
| 1782 | |
| 1783 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1784 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | { |
| 1786 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1787 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1788 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1790 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1793 | int auto_nego; |
| 1794 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1795 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1796 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1797 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1798 | |
| 1799 | if (adv & ADVERTISED_10baseT_Half) |
| 1800 | auto_nego |= ADVERTISE_10HALF; |
| 1801 | if (adv & ADVERTISED_10baseT_Full) |
| 1802 | auto_nego |= ADVERTISE_10FULL; |
| 1803 | if (adv & ADVERTISED_100baseT_Half) |
| 1804 | auto_nego |= ADVERTISE_100HALF; |
| 1805 | if (adv & ADVERTISED_100baseT_Full) |
| 1806 | auto_nego |= ADVERTISE_100FULL; |
| 1807 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1808 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1809 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1810 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1811 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1812 | |
| 1813 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1814 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1815 | if (adv & ADVERTISED_1000baseT_Half) |
| 1816 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1817 | if (adv & ADVERTISED_1000baseT_Full) |
| 1818 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1819 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1820 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1821 | netif_info(tp, link, dev, |
| 1822 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1823 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1824 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1826 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1827 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1828 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1829 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1830 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1831 | if (speed == SPEED_10) |
| 1832 | bmcr = 0; |
| 1833 | else if (speed == SPEED_100) |
| 1834 | bmcr = BMCR_SPEED100; |
| 1835 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1836 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1837 | |
| 1838 | if (duplex == DUPLEX_FULL) |
| 1839 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1842 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1843 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1844 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1845 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1846 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1847 | rtl_writephy(tp, 0x17, 0x2138); |
| 1848 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1849 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1850 | rtl_writephy(tp, 0x17, 0x2108); |
| 1851 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1855 | rc = 0; |
| 1856 | out: |
| 1857 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1861 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | { |
| 1863 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1864 | int ret; |
| 1865 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1866 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1867 | if (ret < 0) |
| 1868 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1870 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 1871 | (advertising & ADVERTISED_1000baseT_Full) && |
| 1872 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1874 | } |
| 1875 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | return ret; |
| 1877 | } |
| 1878 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1879 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1880 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1882 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1883 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1884 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1885 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1887 | if (dev->mtu > JUMBO_1K && |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 1888 | tp->mac_version > RTL_GIGA_MAC_VER_06) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1889 | features &= ~NETIF_F_IP_CSUM; |
| 1890 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1891 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1894 | static int rtl8169_set_features(struct net_device *dev, |
| 1895 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | { |
| 1897 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1898 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
Heiner Kallweit | a398457 | 2018-04-28 22:19:15 +0200 | [diff] [blame] | 1900 | rtl_lock_work(tp); |
| 1901 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1902 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1903 | if (features & NETIF_F_RXALL) |
| 1904 | rx_config |= (AcceptErr | AcceptRunt); |
| 1905 | else |
| 1906 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1908 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1909 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1910 | if (features & NETIF_F_RXCSUM) |
| 1911 | tp->cp_cmd |= RxChkSum; |
| 1912 | else |
| 1913 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1914 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1915 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1916 | tp->cp_cmd |= RxVlan; |
| 1917 | else |
| 1918 | tp->cp_cmd &= ~RxVlan; |
| 1919 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1920 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1921 | RTL_R16(tp, CPlusCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1923 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
| 1925 | return 0; |
| 1926 | } |
| 1927 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1928 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1930 | return (skb_vlan_tag_present(skb)) ? |
| 1931 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1934 | 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] | 1935 | { |
| 1936 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1938 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1939 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1942 | static int rtl8169_get_link_ksettings_tbi(struct net_device *dev, |
| 1943 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { |
| 1945 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | u32 status; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1947 | u32 supported, advertising; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1949 | supported = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1951 | cmd->base.port = PORT_FIBRE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1953 | status = RTL_R32(tp, TBICSR); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1954 | advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1955 | cmd->base.autoneg = !!(status & TBINwEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1957 | cmd->base.speed = SPEED_1000; |
| 1958 | cmd->base.duplex = DUPLEX_FULL; /* Always set */ |
| 1959 | |
| 1960 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 1961 | supported); |
| 1962 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 1963 | advertising); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1964 | |
| 1965 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1968 | static int rtl8169_get_link_ksettings_xmii(struct net_device *dev, |
| 1969 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | { |
| 1971 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 1973 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 1974 | |
| 1975 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1978 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 1979 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | { |
| 1981 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1982 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1984 | rtl_lock_work(tp); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 1985 | rc = tp->get_link_ksettings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1986 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1988 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 1991 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 1992 | const struct ethtool_link_ksettings *cmd) |
| 1993 | { |
| 1994 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1995 | int rc; |
| 1996 | u32 advertising; |
| 1997 | |
| 1998 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 1999 | cmd->link_modes.advertising)) |
| 2000 | return -EINVAL; |
| 2001 | |
| 2002 | del_timer_sync(&tp->timer); |
| 2003 | |
| 2004 | rtl_lock_work(tp); |
| 2005 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 2006 | cmd->base.duplex, advertising); |
| 2007 | rtl_unlock_work(tp); |
| 2008 | |
| 2009 | return rc; |
| 2010 | } |
| 2011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2013 | void *p) |
| 2014 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2015 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2016 | u32 __iomem *data = tp->mmio_addr; |
| 2017 | u32 *dw = p; |
| 2018 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2020 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2021 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 2022 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2023 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2026 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 2027 | { |
| 2028 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2029 | |
| 2030 | return tp->msg_enable; |
| 2031 | } |
| 2032 | |
| 2033 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 2034 | { |
| 2035 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2036 | |
| 2037 | tp->msg_enable = value; |
| 2038 | } |
| 2039 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2040 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2041 | "tx_packets", |
| 2042 | "rx_packets", |
| 2043 | "tx_errors", |
| 2044 | "rx_errors", |
| 2045 | "rx_missed", |
| 2046 | "align_errors", |
| 2047 | "tx_single_collisions", |
| 2048 | "tx_multi_collisions", |
| 2049 | "unicast", |
| 2050 | "broadcast", |
| 2051 | "multicast", |
| 2052 | "tx_aborted", |
| 2053 | "tx_underrun", |
| 2054 | }; |
| 2055 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2056 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2057 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2058 | switch (sset) { |
| 2059 | case ETH_SS_STATS: |
| 2060 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2061 | default: |
| 2062 | return -EOPNOTSUPP; |
| 2063 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2064 | } |
| 2065 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2066 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2067 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2068 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2069 | } |
| 2070 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2071 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2072 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2073 | dma_addr_t paddr = tp->counters_phys_addr; |
| 2074 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2075 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2076 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 2077 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2078 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2079 | RTL_W32(tp, CounterAddrLow, cmd); |
| 2080 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2081 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2082 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2083 | } |
| 2084 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2085 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2086 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2087 | /* |
| 2088 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 2089 | * tally counters. |
| 2090 | */ |
| 2091 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 2092 | return true; |
| 2093 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2094 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2097 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2098 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2099 | /* |
| 2100 | * Some chips are unable to dump tally counters when the receiver |
| 2101 | * is disabled. |
| 2102 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2103 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2104 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2105 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2106 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2107 | } |
| 2108 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2109 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2110 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2111 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2112 | bool ret = false; |
| 2113 | |
| 2114 | /* |
| 2115 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2116 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2117 | * reset by a power cycle, while the counter values collected by the |
| 2118 | * driver are reset at every driver unload/load cycle. |
| 2119 | * |
| 2120 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2121 | * values, we collect the initial values at first open(*) and use them |
| 2122 | * as offsets to normalize the values returned by @get_stats64. |
| 2123 | * |
| 2124 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2125 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2126 | * set at open time by rtl_hw_start. |
| 2127 | */ |
| 2128 | |
| 2129 | if (tp->tc_offset.inited) |
| 2130 | return true; |
| 2131 | |
| 2132 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2133 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2134 | ret = true; |
| 2135 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2136 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2137 | ret = true; |
| 2138 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2139 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2140 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2141 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2142 | tp->tc_offset.inited = true; |
| 2143 | |
| 2144 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2147 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2148 | struct ethtool_stats *stats, u64 *data) |
| 2149 | { |
| 2150 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 2151 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2152 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2153 | |
| 2154 | ASSERT_RTNL(); |
| 2155 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2156 | pm_runtime_get_noresume(d); |
| 2157 | |
| 2158 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 2159 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2160 | |
| 2161 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2162 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2163 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2164 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2165 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2166 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2167 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2168 | data[5] = le16_to_cpu(counters->align_errors); |
| 2169 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2170 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2171 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2172 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2173 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2174 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2175 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2176 | } |
| 2177 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2178 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2179 | { |
| 2180 | switch(stringset) { |
| 2181 | case ETH_SS_STATS: |
| 2182 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2183 | break; |
| 2184 | } |
| 2185 | } |
| 2186 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2187 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2188 | { |
| 2189 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2190 | |
| 2191 | return mii_nway_restart(&tp->mii); |
| 2192 | } |
| 2193 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2194 | /* |
| 2195 | * Interrupt coalescing |
| 2196 | * |
| 2197 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2198 | * > 8169, 8168 and 810x line of chipsets |
| 2199 | * |
| 2200 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2201 | * |
| 2202 | * > 2 - the Tx timer unit at gigabit speed |
| 2203 | * |
| 2204 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2205 | * (0xe0) bit 1 and bit 0. |
| 2206 | * |
| 2207 | * For 8169 |
| 2208 | * bit[1:0] \ speed 1000M 100M 10M |
| 2209 | * 0 0 320ns 2.56us 40.96us |
| 2210 | * 0 1 2.56us 20.48us 327.7us |
| 2211 | * 1 0 5.12us 40.96us 655.4us |
| 2212 | * 1 1 10.24us 81.92us 1.31ms |
| 2213 | * |
| 2214 | * For the other |
| 2215 | * bit[1:0] \ speed 1000M 100M 10M |
| 2216 | * 0 0 5us 2.56us 40.96us |
| 2217 | * 0 1 40us 20.48us 327.7us |
| 2218 | * 1 0 80us 40.96us 655.4us |
| 2219 | * 1 1 160us 81.92us 1.31ms |
| 2220 | */ |
| 2221 | |
| 2222 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2223 | struct rtl_coalesce_scale { |
| 2224 | /* Rx / Tx */ |
| 2225 | u32 nsecs[2]; |
| 2226 | }; |
| 2227 | |
| 2228 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2229 | struct rtl_coalesce_info { |
| 2230 | u32 speed; |
| 2231 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2232 | }; |
| 2233 | |
| 2234 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2235 | #define rxtx_x1822(r, t) { \ |
| 2236 | {{(r), (t)}}, \ |
| 2237 | {{(r)*8, (t)*8}}, \ |
| 2238 | {{(r)*8*2, (t)*8*2}}, \ |
| 2239 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2240 | } |
| 2241 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2242 | /* speed delays: rx00 tx00 */ |
| 2243 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2244 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2245 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2246 | { 0 }, |
| 2247 | }; |
| 2248 | |
| 2249 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2250 | /* speed delays: rx00 tx00 */ |
| 2251 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2252 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2253 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2254 | { 0 }, |
| 2255 | }; |
| 2256 | #undef rxtx_x1822 |
| 2257 | |
| 2258 | /* get rx/tx scale vector corresponding to current speed */ |
| 2259 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2260 | { |
| 2261 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2262 | struct ethtool_link_ksettings ecmd; |
| 2263 | const struct rtl_coalesce_info *ci; |
| 2264 | int rc; |
| 2265 | |
| 2266 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2267 | if (rc < 0) |
| 2268 | return ERR_PTR(rc); |
| 2269 | |
| 2270 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2271 | if (ecmd.base.speed == ci->speed) { |
| 2272 | return ci; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | return ERR_PTR(-ELNRNG); |
| 2277 | } |
| 2278 | |
| 2279 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2280 | { |
| 2281 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2282 | const struct rtl_coalesce_info *ci; |
| 2283 | const struct rtl_coalesce_scale *scale; |
| 2284 | struct { |
| 2285 | u32 *max_frames; |
| 2286 | u32 *usecs; |
| 2287 | } coal_settings [] = { |
| 2288 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2289 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2290 | }, *p = coal_settings; |
| 2291 | int i; |
| 2292 | u16 w; |
| 2293 | |
| 2294 | memset(ec, 0, sizeof(*ec)); |
| 2295 | |
| 2296 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2297 | ci = rtl_coalesce_info(dev); |
| 2298 | if (IS_ERR(ci)) |
| 2299 | return PTR_ERR(ci); |
| 2300 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 2301 | scale = &ci->scalev[tp->cp_cmd & INTT_MASK]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2302 | |
| 2303 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2304 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2305 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2306 | w >>= RTL_COALESCE_SHIFT; |
| 2307 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2308 | } |
| 2309 | |
| 2310 | for (i = 0; i < 2; i++) { |
| 2311 | p = coal_settings + i; |
| 2312 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2313 | |
| 2314 | /* |
| 2315 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2316 | * max_frames to 0. |
| 2317 | */ |
| 2318 | if (!*p->usecs && !*p->max_frames) |
| 2319 | *p->max_frames = 1; |
| 2320 | } |
| 2321 | |
| 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2326 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2327 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2328 | { |
| 2329 | const struct rtl_coalesce_info *ci; |
| 2330 | u16 i; |
| 2331 | |
| 2332 | ci = rtl_coalesce_info(dev); |
| 2333 | if (IS_ERR(ci)) |
| 2334 | return ERR_CAST(ci); |
| 2335 | |
| 2336 | for (i = 0; i < 4; i++) { |
| 2337 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2338 | ci->scalev[i].nsecs[1]); |
| 2339 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2340 | *cp01 = i; |
| 2341 | return &ci->scalev[i]; |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | return ERR_PTR(-EINVAL); |
| 2346 | } |
| 2347 | |
| 2348 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2349 | { |
| 2350 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2351 | const struct rtl_coalesce_scale *scale; |
| 2352 | struct { |
| 2353 | u32 frames; |
| 2354 | u32 usecs; |
| 2355 | } coal_settings [] = { |
| 2356 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2357 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2358 | }, *p = coal_settings; |
| 2359 | u16 w = 0, cp01; |
| 2360 | int i; |
| 2361 | |
| 2362 | scale = rtl_coalesce_choose_scale(dev, |
| 2363 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2364 | if (IS_ERR(scale)) |
| 2365 | return PTR_ERR(scale); |
| 2366 | |
| 2367 | for (i = 0; i < 2; i++, p++) { |
| 2368 | u32 units; |
| 2369 | |
| 2370 | /* |
| 2371 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2372 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2373 | * |
| 2374 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2375 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2376 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2377 | * |
| 2378 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2379 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2380 | * we'll reject it below in `frames % 4 != 0`. |
| 2381 | */ |
| 2382 | if (p->frames == 1) { |
| 2383 | p->frames = 0; |
| 2384 | } |
| 2385 | |
| 2386 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2387 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2388 | return -EINVAL; |
| 2389 | |
| 2390 | w <<= RTL_COALESCE_SHIFT; |
| 2391 | w |= units; |
| 2392 | w <<= RTL_COALESCE_SHIFT; |
| 2393 | w |= p->frames >> 2; |
| 2394 | } |
| 2395 | |
| 2396 | rtl_lock_work(tp); |
| 2397 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2398 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2399 | |
Heiner Kallweit | 9a3c81f | 2018-04-28 22:19:21 +0200 | [diff] [blame] | 2400 | tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2401 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2402 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2403 | |
| 2404 | rtl_unlock_work(tp); |
| 2405 | |
| 2406 | return 0; |
| 2407 | } |
| 2408 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2409 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2411 | .get_regs_len = rtl8169_get_regs_len, |
| 2412 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2413 | .get_coalesce = rtl_get_coalesce, |
| 2414 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2415 | .get_msglevel = rtl8169_get_msglevel, |
| 2416 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2418 | .get_wol = rtl8169_get_wol, |
| 2419 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2420 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2421 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2422 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2423 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2424 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2425 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2426 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | }; |
| 2428 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2429 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2430 | u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2432 | /* |
| 2433 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2434 | * but they can be identified more specifically through the test below |
| 2435 | * if needed: |
| 2436 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2437 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2438 | * |
| 2439 | * Same thing for the 8101Eb and the 8101Ec: |
| 2440 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2441 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2442 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2443 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2445 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | int mac_version; |
| 2447 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2448 | /* 8168EP family. */ |
| 2449 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2450 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2451 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2452 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2453 | /* 8168H family. */ |
| 2454 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2455 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2456 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2457 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2458 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2459 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2460 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2461 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2462 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2463 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2464 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2465 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2466 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2467 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2468 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2469 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2470 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2471 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2472 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2473 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2474 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2475 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2476 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2477 | /* 8168DP family. */ |
| 2478 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2479 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2480 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2481 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2482 | /* 8168C family. */ |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2483 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2484 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2485 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2486 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2487 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2488 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2489 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2490 | |
| 2491 | /* 8168B family. */ |
| 2492 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2493 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2494 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2495 | |
| 2496 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2497 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2498 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2499 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2500 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2501 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2502 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2503 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2504 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2505 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2506 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2507 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2508 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2509 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2510 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2511 | /* FIXME: where did these entries come from ? -- FR */ |
| 2512 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2513 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2514 | |
| 2515 | /* 8110 family. */ |
| 2516 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2517 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2518 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2519 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2520 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2521 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2522 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2523 | /* Catch-all */ |
| 2524 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2525 | }; |
| 2526 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | u32 reg; |
| 2528 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2529 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2530 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | p++; |
| 2532 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2533 | |
| 2534 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 2535 | dev_notice(tp_to_dev(tp), |
| 2536 | "unknown MAC, using family default\n"); |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2537 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2538 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2539 | tp->mac_version = tp->mii.supports_gmii ? |
| 2540 | RTL_GIGA_MAC_VER_42 : |
| 2541 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2542 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2543 | tp->mac_version = tp->mii.supports_gmii ? |
| 2544 | RTL_GIGA_MAC_VER_45 : |
| 2545 | RTL_GIGA_MAC_VER_47; |
| 2546 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2547 | tp->mac_version = tp->mii.supports_gmii ? |
| 2548 | RTL_GIGA_MAC_VER_46 : |
| 2549 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2554 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2555 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2558 | struct phy_reg { |
| 2559 | u16 reg; |
| 2560 | u16 val; |
| 2561 | }; |
| 2562 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2563 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2564 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2565 | { |
| 2566 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2567 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2568 | regs++; |
| 2569 | } |
| 2570 | } |
| 2571 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2572 | #define PHY_READ 0x00000000 |
| 2573 | #define PHY_DATA_OR 0x10000000 |
| 2574 | #define PHY_DATA_AND 0x20000000 |
| 2575 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2576 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2577 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2578 | #define PHY_WRITE 0x80000000 |
| 2579 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2580 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2581 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2582 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2583 | #define PHY_SKIPN 0xd0000000 |
| 2584 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2585 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2586 | struct fw_info { |
| 2587 | u32 magic; |
| 2588 | char version[RTL_VER_SIZE]; |
| 2589 | __le32 fw_start; |
| 2590 | __le32 fw_len; |
| 2591 | u8 chksum; |
| 2592 | } __packed; |
| 2593 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2594 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2595 | |
| 2596 | 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] | 2597 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2598 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2599 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2600 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2601 | char *version = rtl_fw->version; |
| 2602 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2603 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2604 | if (fw->size < FW_OPCODE_SIZE) |
| 2605 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2606 | |
| 2607 | if (!fw_info->magic) { |
| 2608 | size_t i, size, start; |
| 2609 | u8 checksum = 0; |
| 2610 | |
| 2611 | if (fw->size < sizeof(*fw_info)) |
| 2612 | goto out; |
| 2613 | |
| 2614 | for (i = 0; i < fw->size; i++) |
| 2615 | checksum += fw->data[i]; |
| 2616 | if (checksum != 0) |
| 2617 | goto out; |
| 2618 | |
| 2619 | start = le32_to_cpu(fw_info->fw_start); |
| 2620 | if (start > fw->size) |
| 2621 | goto out; |
| 2622 | |
| 2623 | size = le32_to_cpu(fw_info->fw_len); |
| 2624 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2625 | goto out; |
| 2626 | |
| 2627 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2628 | |
| 2629 | pa->code = (__le32 *)(fw->data + start); |
| 2630 | pa->size = size; |
| 2631 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2632 | if (fw->size % FW_OPCODE_SIZE) |
| 2633 | goto out; |
| 2634 | |
| 2635 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2636 | |
| 2637 | pa->code = (__le32 *)fw->data; |
| 2638 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2639 | } |
| 2640 | version[RTL_VER_SIZE - 1] = 0; |
| 2641 | |
| 2642 | rc = true; |
| 2643 | out: |
| 2644 | return rc; |
| 2645 | } |
| 2646 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2647 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2648 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2649 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2650 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2651 | size_t index; |
| 2652 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2653 | for (index = 0; index < pa->size; index++) { |
| 2654 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2655 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2656 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2657 | switch(action & 0xf0000000) { |
| 2658 | case PHY_READ: |
| 2659 | case PHY_DATA_OR: |
| 2660 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2661 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2662 | case PHY_CLEAR_READCOUNT: |
| 2663 | case PHY_WRITE: |
| 2664 | case PHY_WRITE_PREVIOUS: |
| 2665 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2666 | break; |
| 2667 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2668 | case PHY_BJMPN: |
| 2669 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2670 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2671 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2672 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2673 | } |
| 2674 | break; |
| 2675 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2676 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2677 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2678 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2679 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2680 | } |
| 2681 | break; |
| 2682 | case PHY_COMP_EQ_SKIPN: |
| 2683 | case PHY_COMP_NEQ_SKIPN: |
| 2684 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2685 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2686 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2687 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2688 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2689 | } |
| 2690 | break; |
| 2691 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2692 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2693 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2694 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2695 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2696 | } |
| 2697 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2698 | rc = true; |
| 2699 | out: |
| 2700 | return rc; |
| 2701 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2702 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2703 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2704 | { |
| 2705 | struct net_device *dev = tp->dev; |
| 2706 | int rc = -EINVAL; |
| 2707 | |
| 2708 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2709 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2710 | goto out; |
| 2711 | } |
| 2712 | |
| 2713 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2714 | rc = 0; |
| 2715 | out: |
| 2716 | return rc; |
| 2717 | } |
| 2718 | |
| 2719 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2720 | { |
| 2721 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2722 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2723 | u32 predata, count; |
| 2724 | size_t index; |
| 2725 | |
| 2726 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2727 | org.write = ops->write; |
| 2728 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2729 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2730 | for (index = 0; index < pa->size; ) { |
| 2731 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2732 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2733 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2734 | |
| 2735 | if (!action) |
| 2736 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2737 | |
| 2738 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2739 | case PHY_READ: |
| 2740 | predata = rtl_readphy(tp, regno); |
| 2741 | count++; |
| 2742 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2743 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2744 | case PHY_DATA_OR: |
| 2745 | predata |= data; |
| 2746 | index++; |
| 2747 | break; |
| 2748 | case PHY_DATA_AND: |
| 2749 | predata &= data; |
| 2750 | index++; |
| 2751 | break; |
| 2752 | case PHY_BJMPN: |
| 2753 | index -= regno; |
| 2754 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2755 | case PHY_MDIO_CHG: |
| 2756 | if (data == 0) { |
| 2757 | ops->write = org.write; |
| 2758 | ops->read = org.read; |
| 2759 | } else if (data == 1) { |
| 2760 | ops->write = mac_mcu_write; |
| 2761 | ops->read = mac_mcu_read; |
| 2762 | } |
| 2763 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2764 | index++; |
| 2765 | break; |
| 2766 | case PHY_CLEAR_READCOUNT: |
| 2767 | count = 0; |
| 2768 | index++; |
| 2769 | break; |
| 2770 | case PHY_WRITE: |
| 2771 | rtl_writephy(tp, regno, data); |
| 2772 | index++; |
| 2773 | break; |
| 2774 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2775 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2776 | break; |
| 2777 | case PHY_COMP_EQ_SKIPN: |
| 2778 | if (predata == data) |
| 2779 | index += regno; |
| 2780 | index++; |
| 2781 | break; |
| 2782 | case PHY_COMP_NEQ_SKIPN: |
| 2783 | if (predata != data) |
| 2784 | index += regno; |
| 2785 | index++; |
| 2786 | break; |
| 2787 | case PHY_WRITE_PREVIOUS: |
| 2788 | rtl_writephy(tp, regno, predata); |
| 2789 | index++; |
| 2790 | break; |
| 2791 | case PHY_SKIPN: |
| 2792 | index += regno + 1; |
| 2793 | break; |
| 2794 | case PHY_DELAY_MS: |
| 2795 | mdelay(data); |
| 2796 | index++; |
| 2797 | break; |
| 2798 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2799 | default: |
| 2800 | BUG(); |
| 2801 | } |
| 2802 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2803 | |
| 2804 | ops->write = org.write; |
| 2805 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2808 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2809 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2810 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2811 | release_firmware(tp->rtl_fw->fw); |
| 2812 | kfree(tp->rtl_fw); |
| 2813 | } |
| 2814 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2817 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2818 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2819 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2820 | |
| 2821 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2822 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2823 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2827 | { |
| 2828 | if (rtl_readphy(tp, reg) != val) |
| 2829 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2830 | else |
| 2831 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2834 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2836 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2837 | { 0x1f, 0x0001 }, |
| 2838 | { 0x06, 0x006e }, |
| 2839 | { 0x08, 0x0708 }, |
| 2840 | { 0x15, 0x4000 }, |
| 2841 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2843 | { 0x1f, 0x0001 }, |
| 2844 | { 0x03, 0x00a1 }, |
| 2845 | { 0x02, 0x0008 }, |
| 2846 | { 0x01, 0x0120 }, |
| 2847 | { 0x00, 0x1000 }, |
| 2848 | { 0x04, 0x0800 }, |
| 2849 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2851 | { 0x03, 0xff41 }, |
| 2852 | { 0x02, 0xdf60 }, |
| 2853 | { 0x01, 0x0140 }, |
| 2854 | { 0x00, 0x0077 }, |
| 2855 | { 0x04, 0x7800 }, |
| 2856 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2858 | { 0x03, 0x802f }, |
| 2859 | { 0x02, 0x4f02 }, |
| 2860 | { 0x01, 0x0409 }, |
| 2861 | { 0x00, 0xf0f9 }, |
| 2862 | { 0x04, 0x9800 }, |
| 2863 | { 0x04, 0x9000 }, |
| 2864 | |
| 2865 | { 0x03, 0xdf01 }, |
| 2866 | { 0x02, 0xdf20 }, |
| 2867 | { 0x01, 0xff95 }, |
| 2868 | { 0x00, 0xba00 }, |
| 2869 | { 0x04, 0xa800 }, |
| 2870 | { 0x04, 0xa000 }, |
| 2871 | |
| 2872 | { 0x03, 0xff41 }, |
| 2873 | { 0x02, 0xdf20 }, |
| 2874 | { 0x01, 0x0140 }, |
| 2875 | { 0x00, 0x00bb }, |
| 2876 | { 0x04, 0xb800 }, |
| 2877 | { 0x04, 0xb000 }, |
| 2878 | |
| 2879 | { 0x03, 0xdf41 }, |
| 2880 | { 0x02, 0xdc60 }, |
| 2881 | { 0x01, 0x6340 }, |
| 2882 | { 0x00, 0x007d }, |
| 2883 | { 0x04, 0xd800 }, |
| 2884 | { 0x04, 0xd000 }, |
| 2885 | |
| 2886 | { 0x03, 0xdf01 }, |
| 2887 | { 0x02, 0xdf20 }, |
| 2888 | { 0x01, 0x100a }, |
| 2889 | { 0x00, 0xa0ff }, |
| 2890 | { 0x04, 0xf800 }, |
| 2891 | { 0x04, 0xf000 }, |
| 2892 | |
| 2893 | { 0x1f, 0x0000 }, |
| 2894 | { 0x0b, 0x0000 }, |
| 2895 | { 0x00, 0x9200 } |
| 2896 | }; |
| 2897 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2898 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2901 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2902 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2903 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2904 | { 0x1f, 0x0002 }, |
| 2905 | { 0x01, 0x90d0 }, |
| 2906 | { 0x1f, 0x0000 } |
| 2907 | }; |
| 2908 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2909 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2910 | } |
| 2911 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2912 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2913 | { |
| 2914 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2915 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2916 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2917 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2918 | return; |
| 2919 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2920 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2921 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2922 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2925 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2926 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2927 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2928 | { 0x1f, 0x0001 }, |
| 2929 | { 0x04, 0x0000 }, |
| 2930 | { 0x03, 0x00a1 }, |
| 2931 | { 0x02, 0x0008 }, |
| 2932 | { 0x01, 0x0120 }, |
| 2933 | { 0x00, 0x1000 }, |
| 2934 | { 0x04, 0x0800 }, |
| 2935 | { 0x04, 0x9000 }, |
| 2936 | { 0x03, 0x802f }, |
| 2937 | { 0x02, 0x4f02 }, |
| 2938 | { 0x01, 0x0409 }, |
| 2939 | { 0x00, 0xf099 }, |
| 2940 | { 0x04, 0x9800 }, |
| 2941 | { 0x04, 0xa000 }, |
| 2942 | { 0x03, 0xdf01 }, |
| 2943 | { 0x02, 0xdf20 }, |
| 2944 | { 0x01, 0xff95 }, |
| 2945 | { 0x00, 0xba00 }, |
| 2946 | { 0x04, 0xa800 }, |
| 2947 | { 0x04, 0xf000 }, |
| 2948 | { 0x03, 0xdf01 }, |
| 2949 | { 0x02, 0xdf20 }, |
| 2950 | { 0x01, 0x101a }, |
| 2951 | { 0x00, 0xa0ff }, |
| 2952 | { 0x04, 0xf800 }, |
| 2953 | { 0x04, 0x0000 }, |
| 2954 | { 0x1f, 0x0000 }, |
| 2955 | |
| 2956 | { 0x1f, 0x0001 }, |
| 2957 | { 0x10, 0xf41b }, |
| 2958 | { 0x14, 0xfb54 }, |
| 2959 | { 0x18, 0xf5c7 }, |
| 2960 | { 0x1f, 0x0000 }, |
| 2961 | |
| 2962 | { 0x1f, 0x0001 }, |
| 2963 | { 0x17, 0x0cc0 }, |
| 2964 | { 0x1f, 0x0000 } |
| 2965 | }; |
| 2966 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2967 | 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] | 2968 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2969 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2972 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2973 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2974 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2975 | { 0x1f, 0x0001 }, |
| 2976 | { 0x04, 0x0000 }, |
| 2977 | { 0x03, 0x00a1 }, |
| 2978 | { 0x02, 0x0008 }, |
| 2979 | { 0x01, 0x0120 }, |
| 2980 | { 0x00, 0x1000 }, |
| 2981 | { 0x04, 0x0800 }, |
| 2982 | { 0x04, 0x9000 }, |
| 2983 | { 0x03, 0x802f }, |
| 2984 | { 0x02, 0x4f02 }, |
| 2985 | { 0x01, 0x0409 }, |
| 2986 | { 0x00, 0xf099 }, |
| 2987 | { 0x04, 0x9800 }, |
| 2988 | { 0x04, 0xa000 }, |
| 2989 | { 0x03, 0xdf01 }, |
| 2990 | { 0x02, 0xdf20 }, |
| 2991 | { 0x01, 0xff95 }, |
| 2992 | { 0x00, 0xba00 }, |
| 2993 | { 0x04, 0xa800 }, |
| 2994 | { 0x04, 0xf000 }, |
| 2995 | { 0x03, 0xdf01 }, |
| 2996 | { 0x02, 0xdf20 }, |
| 2997 | { 0x01, 0x101a }, |
| 2998 | { 0x00, 0xa0ff }, |
| 2999 | { 0x04, 0xf800 }, |
| 3000 | { 0x04, 0x0000 }, |
| 3001 | { 0x1f, 0x0000 }, |
| 3002 | |
| 3003 | { 0x1f, 0x0001 }, |
| 3004 | { 0x0b, 0x8480 }, |
| 3005 | { 0x1f, 0x0000 }, |
| 3006 | |
| 3007 | { 0x1f, 0x0001 }, |
| 3008 | { 0x18, 0x67c7 }, |
| 3009 | { 0x04, 0x2000 }, |
| 3010 | { 0x03, 0x002f }, |
| 3011 | { 0x02, 0x4360 }, |
| 3012 | { 0x01, 0x0109 }, |
| 3013 | { 0x00, 0x3022 }, |
| 3014 | { 0x04, 0x2800 }, |
| 3015 | { 0x1f, 0x0000 }, |
| 3016 | |
| 3017 | { 0x1f, 0x0001 }, |
| 3018 | { 0x17, 0x0cc0 }, |
| 3019 | { 0x1f, 0x0000 } |
| 3020 | }; |
| 3021 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3022 | 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] | 3023 | } |
| 3024 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3025 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3026 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3027 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3028 | { 0x10, 0xf41b }, |
| 3029 | { 0x1f, 0x0000 } |
| 3030 | }; |
| 3031 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3032 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3033 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3034 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3035 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3036 | } |
| 3037 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3038 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3039 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3040 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3041 | { 0x1f, 0x0001 }, |
| 3042 | { 0x10, 0xf41b }, |
| 3043 | { 0x1f, 0x0000 } |
| 3044 | }; |
| 3045 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3046 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3047 | } |
| 3048 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3049 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3050 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3051 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3052 | { 0x1f, 0x0000 }, |
| 3053 | { 0x1d, 0x0f00 }, |
| 3054 | { 0x1f, 0x0002 }, |
| 3055 | { 0x0c, 0x1ec8 }, |
| 3056 | { 0x1f, 0x0000 } |
| 3057 | }; |
| 3058 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3059 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3060 | } |
| 3061 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3062 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3063 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3064 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3065 | { 0x1f, 0x0001 }, |
| 3066 | { 0x1d, 0x3d98 }, |
| 3067 | { 0x1f, 0x0000 } |
| 3068 | }; |
| 3069 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3070 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3071 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3072 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3073 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3074 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3075 | } |
| 3076 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3077 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3078 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3079 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 3080 | { 0x1f, 0x0001 }, |
| 3081 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3082 | { 0x1f, 0x0002 }, |
| 3083 | { 0x00, 0x88d4 }, |
| 3084 | { 0x01, 0x82b1 }, |
| 3085 | { 0x03, 0x7002 }, |
| 3086 | { 0x08, 0x9e30 }, |
| 3087 | { 0x09, 0x01f0 }, |
| 3088 | { 0x0a, 0x5500 }, |
| 3089 | { 0x0c, 0x00c8 }, |
| 3090 | { 0x1f, 0x0003 }, |
| 3091 | { 0x12, 0xc096 }, |
| 3092 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3093 | { 0x1f, 0x0000 }, |
| 3094 | { 0x1f, 0x0000 }, |
| 3095 | { 0x09, 0x2000 }, |
| 3096 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3097 | }; |
| 3098 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3099 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3100 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3101 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3102 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3103 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3104 | } |
| 3105 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3106 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3107 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3108 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3109 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3110 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3111 | { 0x03, 0x802f }, |
| 3112 | { 0x02, 0x4f02 }, |
| 3113 | { 0x01, 0x0409 }, |
| 3114 | { 0x00, 0xf099 }, |
| 3115 | { 0x04, 0x9800 }, |
| 3116 | { 0x04, 0x9000 }, |
| 3117 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3118 | { 0x1f, 0x0002 }, |
| 3119 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3120 | { 0x06, 0x0761 }, |
| 3121 | { 0x1f, 0x0003 }, |
| 3122 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3123 | { 0x1f, 0x0000 } |
| 3124 | }; |
| 3125 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3126 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3127 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3128 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3129 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3130 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3131 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3132 | } |
| 3133 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3134 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3135 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3136 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3137 | { 0x1f, 0x0001 }, |
| 3138 | { 0x12, 0x2300 }, |
| 3139 | { 0x1d, 0x3d98 }, |
| 3140 | { 0x1f, 0x0002 }, |
| 3141 | { 0x0c, 0x7eb8 }, |
| 3142 | { 0x06, 0x5461 }, |
| 3143 | { 0x1f, 0x0003 }, |
| 3144 | { 0x16, 0x0f0a }, |
| 3145 | { 0x1f, 0x0000 } |
| 3146 | }; |
| 3147 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3148 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3149 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3150 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3151 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3152 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3153 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3154 | } |
| 3155 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3156 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3157 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3158 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3159 | } |
| 3160 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3161 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3162 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3163 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3164 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3165 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3166 | { 0x06, 0x4064 }, |
| 3167 | { 0x07, 0x2863 }, |
| 3168 | { 0x08, 0x059c }, |
| 3169 | { 0x09, 0x26b4 }, |
| 3170 | { 0x0a, 0x6a19 }, |
| 3171 | { 0x0b, 0xdcc8 }, |
| 3172 | { 0x10, 0xf06d }, |
| 3173 | { 0x14, 0x7f68 }, |
| 3174 | { 0x18, 0x7fd9 }, |
| 3175 | { 0x1c, 0xf0ff }, |
| 3176 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3177 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3178 | { 0x12, 0xf49f }, |
| 3179 | { 0x13, 0x070b }, |
| 3180 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3181 | { 0x14, 0x94c0 }, |
| 3182 | |
| 3183 | /* |
| 3184 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3185 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3186 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3187 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3188 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3189 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3190 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3191 | { 0x06, 0x5561 }, |
| 3192 | |
| 3193 | /* |
| 3194 | * Can not link to 1Gbps with bad cable |
| 3195 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3196 | */ |
| 3197 | { 0x1f, 0x0001 }, |
| 3198 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3199 | |
| 3200 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3201 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3202 | }; |
| 3203 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3204 | 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] | 3205 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3206 | /* |
| 3207 | * Rx Error Issue |
| 3208 | * Fine Tune Switching regulator parameter |
| 3209 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3210 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3211 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3212 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3213 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3214 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3215 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3216 | { 0x1f, 0x0002 }, |
| 3217 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3218 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3219 | { 0x05, 0x8330 }, |
| 3220 | { 0x06, 0x669a }, |
| 3221 | { 0x1f, 0x0002 } |
| 3222 | }; |
| 3223 | int val; |
| 3224 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3225 | 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] | 3226 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3227 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3228 | |
| 3229 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3230 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3231 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3232 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3233 | }; |
| 3234 | int i; |
| 3235 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3236 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3237 | |
| 3238 | val &= 0xff00; |
| 3239 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3240 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3241 | } |
| 3242 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3243 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3244 | { 0x1f, 0x0002 }, |
| 3245 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3246 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3247 | { 0x05, 0x8330 }, |
| 3248 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3249 | }; |
| 3250 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3251 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3254 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3255 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3256 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3257 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3258 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3259 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3260 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3261 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3262 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3263 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3264 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3265 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3266 | |
| 3267 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3268 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3269 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3272 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3273 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3274 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3275 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3276 | { 0x1f, 0x0001 }, |
| 3277 | { 0x06, 0x4064 }, |
| 3278 | { 0x07, 0x2863 }, |
| 3279 | { 0x08, 0x059c }, |
| 3280 | { 0x09, 0x26b4 }, |
| 3281 | { 0x0a, 0x6a19 }, |
| 3282 | { 0x0b, 0xdcc8 }, |
| 3283 | { 0x10, 0xf06d }, |
| 3284 | { 0x14, 0x7f68 }, |
| 3285 | { 0x18, 0x7fd9 }, |
| 3286 | { 0x1c, 0xf0ff }, |
| 3287 | { 0x1d, 0x3d9c }, |
| 3288 | { 0x1f, 0x0003 }, |
| 3289 | { 0x12, 0xf49f }, |
| 3290 | { 0x13, 0x070b }, |
| 3291 | { 0x1a, 0x05ad }, |
| 3292 | { 0x14, 0x94c0 }, |
| 3293 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3294 | /* |
| 3295 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3296 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3297 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3298 | { 0x1f, 0x0002 }, |
| 3299 | { 0x06, 0x5561 }, |
| 3300 | { 0x1f, 0x0005 }, |
| 3301 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3302 | { 0x06, 0x5561 }, |
| 3303 | |
| 3304 | /* |
| 3305 | * Can not link to 1Gbps with bad cable |
| 3306 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3307 | */ |
| 3308 | { 0x1f, 0x0001 }, |
| 3309 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3310 | |
| 3311 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3312 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3313 | }; |
| 3314 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3315 | 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] | 3316 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3317 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3318 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3319 | { 0x1f, 0x0002 }, |
| 3320 | { 0x05, 0x669a }, |
| 3321 | { 0x1f, 0x0005 }, |
| 3322 | { 0x05, 0x8330 }, |
| 3323 | { 0x06, 0x669a }, |
| 3324 | |
| 3325 | { 0x1f, 0x0002 } |
| 3326 | }; |
| 3327 | int val; |
| 3328 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3329 | 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] | 3330 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3331 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3332 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3333 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3334 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3335 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3336 | }; |
| 3337 | int i; |
| 3338 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3339 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3340 | |
| 3341 | val &= 0xff00; |
| 3342 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3343 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3344 | } |
| 3345 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3346 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3347 | { 0x1f, 0x0002 }, |
| 3348 | { 0x05, 0x2642 }, |
| 3349 | { 0x1f, 0x0005 }, |
| 3350 | { 0x05, 0x8330 }, |
| 3351 | { 0x06, 0x2642 } |
| 3352 | }; |
| 3353 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3354 | 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] | 3355 | } |
| 3356 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3357 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3358 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3359 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3360 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3361 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3362 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3363 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3364 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3365 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3366 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3367 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3368 | |
| 3369 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3370 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3371 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3374 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3375 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3376 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3377 | { 0x1f, 0x0002 }, |
| 3378 | { 0x10, 0x0008 }, |
| 3379 | { 0x0d, 0x006c }, |
| 3380 | |
| 3381 | { 0x1f, 0x0000 }, |
| 3382 | { 0x0d, 0xf880 }, |
| 3383 | |
| 3384 | { 0x1f, 0x0001 }, |
| 3385 | { 0x17, 0x0cc0 }, |
| 3386 | |
| 3387 | { 0x1f, 0x0001 }, |
| 3388 | { 0x0b, 0xa4d8 }, |
| 3389 | { 0x09, 0x281c }, |
| 3390 | { 0x07, 0x2883 }, |
| 3391 | { 0x0a, 0x6b35 }, |
| 3392 | { 0x1d, 0x3da4 }, |
| 3393 | { 0x1c, 0xeffd }, |
| 3394 | { 0x14, 0x7f52 }, |
| 3395 | { 0x18, 0x7fc6 }, |
| 3396 | { 0x08, 0x0601 }, |
| 3397 | { 0x06, 0x4063 }, |
| 3398 | { 0x10, 0xf074 }, |
| 3399 | { 0x1f, 0x0003 }, |
| 3400 | { 0x13, 0x0789 }, |
| 3401 | { 0x12, 0xf4bd }, |
| 3402 | { 0x1a, 0x04fd }, |
| 3403 | { 0x14, 0x84b0 }, |
| 3404 | { 0x1f, 0x0000 }, |
| 3405 | { 0x00, 0x9200 }, |
| 3406 | |
| 3407 | { 0x1f, 0x0005 }, |
| 3408 | { 0x01, 0x0340 }, |
| 3409 | { 0x1f, 0x0001 }, |
| 3410 | { 0x04, 0x4000 }, |
| 3411 | { 0x03, 0x1d21 }, |
| 3412 | { 0x02, 0x0c32 }, |
| 3413 | { 0x01, 0x0200 }, |
| 3414 | { 0x00, 0x5554 }, |
| 3415 | { 0x04, 0x4800 }, |
| 3416 | { 0x04, 0x4000 }, |
| 3417 | { 0x04, 0xf000 }, |
| 3418 | { 0x03, 0xdf01 }, |
| 3419 | { 0x02, 0xdf20 }, |
| 3420 | { 0x01, 0x101a }, |
| 3421 | { 0x00, 0xa0ff }, |
| 3422 | { 0x04, 0xf800 }, |
| 3423 | { 0x04, 0xf000 }, |
| 3424 | { 0x1f, 0x0000 }, |
| 3425 | |
| 3426 | { 0x1f, 0x0007 }, |
| 3427 | { 0x1e, 0x0023 }, |
| 3428 | { 0x16, 0x0000 }, |
| 3429 | { 0x1f, 0x0000 } |
| 3430 | }; |
| 3431 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3432 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3433 | } |
| 3434 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3435 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3436 | { |
| 3437 | static const struct phy_reg phy_reg_init[] = { |
| 3438 | { 0x1f, 0x0001 }, |
| 3439 | { 0x17, 0x0cc0 }, |
| 3440 | |
| 3441 | { 0x1f, 0x0007 }, |
| 3442 | { 0x1e, 0x002d }, |
| 3443 | { 0x18, 0x0040 }, |
| 3444 | { 0x1f, 0x0000 } |
| 3445 | }; |
| 3446 | |
| 3447 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3448 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3449 | } |
| 3450 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3451 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3452 | { |
| 3453 | static const struct phy_reg phy_reg_init[] = { |
| 3454 | /* Enable Delay cap */ |
| 3455 | { 0x1f, 0x0005 }, |
| 3456 | { 0x05, 0x8b80 }, |
| 3457 | { 0x06, 0xc896 }, |
| 3458 | { 0x1f, 0x0000 }, |
| 3459 | |
| 3460 | /* Channel estimation fine tune */ |
| 3461 | { 0x1f, 0x0001 }, |
| 3462 | { 0x0b, 0x6c20 }, |
| 3463 | { 0x07, 0x2872 }, |
| 3464 | { 0x1c, 0xefff }, |
| 3465 | { 0x1f, 0x0003 }, |
| 3466 | { 0x14, 0x6420 }, |
| 3467 | { 0x1f, 0x0000 }, |
| 3468 | |
| 3469 | /* Update PFM & 10M TX idle timer */ |
| 3470 | { 0x1f, 0x0007 }, |
| 3471 | { 0x1e, 0x002f }, |
| 3472 | { 0x15, 0x1919 }, |
| 3473 | { 0x1f, 0x0000 }, |
| 3474 | |
| 3475 | { 0x1f, 0x0007 }, |
| 3476 | { 0x1e, 0x00ac }, |
| 3477 | { 0x18, 0x0006 }, |
| 3478 | { 0x1f, 0x0000 } |
| 3479 | }; |
| 3480 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3481 | rtl_apply_firmware(tp); |
| 3482 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3483 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3484 | |
| 3485 | /* DCO enable for 10M IDLE Power */ |
| 3486 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3487 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3488 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3489 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3490 | |
| 3491 | /* For impedance matching */ |
| 3492 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3493 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3494 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3495 | |
| 3496 | /* PHY auto speed down */ |
| 3497 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3498 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3499 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3500 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3501 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3502 | |
| 3503 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3504 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3505 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3506 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3507 | |
| 3508 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3509 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3510 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3511 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3512 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3513 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3514 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3515 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3516 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3517 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3518 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3519 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3520 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3521 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3522 | } |
| 3523 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3524 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3525 | { |
| 3526 | const u16 w[] = { |
| 3527 | addr[0] | (addr[1] << 8), |
| 3528 | addr[2] | (addr[3] << 8), |
| 3529 | addr[4] | (addr[5] << 8) |
| 3530 | }; |
| 3531 | const struct exgmac_reg e[] = { |
| 3532 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3533 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3534 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3535 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3536 | }; |
| 3537 | |
| 3538 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3539 | } |
| 3540 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3541 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3542 | { |
| 3543 | static const struct phy_reg phy_reg_init[] = { |
| 3544 | /* Enable Delay cap */ |
| 3545 | { 0x1f, 0x0004 }, |
| 3546 | { 0x1f, 0x0007 }, |
| 3547 | { 0x1e, 0x00ac }, |
| 3548 | { 0x18, 0x0006 }, |
| 3549 | { 0x1f, 0x0002 }, |
| 3550 | { 0x1f, 0x0000 }, |
| 3551 | { 0x1f, 0x0000 }, |
| 3552 | |
| 3553 | /* Channel estimation fine tune */ |
| 3554 | { 0x1f, 0x0003 }, |
| 3555 | { 0x09, 0xa20f }, |
| 3556 | { 0x1f, 0x0000 }, |
| 3557 | { 0x1f, 0x0000 }, |
| 3558 | |
| 3559 | /* Green Setting */ |
| 3560 | { 0x1f, 0x0005 }, |
| 3561 | { 0x05, 0x8b5b }, |
| 3562 | { 0x06, 0x9222 }, |
| 3563 | { 0x05, 0x8b6d }, |
| 3564 | { 0x06, 0x8000 }, |
| 3565 | { 0x05, 0x8b76 }, |
| 3566 | { 0x06, 0x8000 }, |
| 3567 | { 0x1f, 0x0000 } |
| 3568 | }; |
| 3569 | |
| 3570 | rtl_apply_firmware(tp); |
| 3571 | |
| 3572 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3573 | |
| 3574 | /* For 4-corner performance improve */ |
| 3575 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3576 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3577 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3578 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3579 | |
| 3580 | /* PHY auto speed down */ |
| 3581 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3582 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3583 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3584 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3585 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3586 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3587 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3588 | |
| 3589 | /* improve 10M EEE waveform */ |
| 3590 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3591 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3592 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3593 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3594 | |
| 3595 | /* Improve 2-pair detection performance */ |
| 3596 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3597 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3598 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3599 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3600 | |
| 3601 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3602 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3603 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3604 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3605 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3606 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3607 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3608 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3609 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3610 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3611 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3612 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3613 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3614 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3615 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3616 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3617 | |
| 3618 | /* Green feature */ |
| 3619 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3620 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3621 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3622 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3623 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3624 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3625 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3626 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3627 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3628 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3629 | } |
| 3630 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3631 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3632 | { |
| 3633 | /* For 4-corner performance improve */ |
| 3634 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3635 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3636 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3637 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3638 | |
| 3639 | /* PHY auto speed down */ |
| 3640 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3641 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3642 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3643 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3644 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3645 | |
| 3646 | /* Improve 10M EEE waveform */ |
| 3647 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3648 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3649 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3650 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3651 | } |
| 3652 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3653 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3654 | { |
| 3655 | static const struct phy_reg phy_reg_init[] = { |
| 3656 | /* Channel estimation fine tune */ |
| 3657 | { 0x1f, 0x0003 }, |
| 3658 | { 0x09, 0xa20f }, |
| 3659 | { 0x1f, 0x0000 }, |
| 3660 | |
| 3661 | /* Modify green table for giga & fnet */ |
| 3662 | { 0x1f, 0x0005 }, |
| 3663 | { 0x05, 0x8b55 }, |
| 3664 | { 0x06, 0x0000 }, |
| 3665 | { 0x05, 0x8b5e }, |
| 3666 | { 0x06, 0x0000 }, |
| 3667 | { 0x05, 0x8b67 }, |
| 3668 | { 0x06, 0x0000 }, |
| 3669 | { 0x05, 0x8b70 }, |
| 3670 | { 0x06, 0x0000 }, |
| 3671 | { 0x1f, 0x0000 }, |
| 3672 | { 0x1f, 0x0007 }, |
| 3673 | { 0x1e, 0x0078 }, |
| 3674 | { 0x17, 0x0000 }, |
| 3675 | { 0x19, 0x00fb }, |
| 3676 | { 0x1f, 0x0000 }, |
| 3677 | |
| 3678 | /* Modify green table for 10M */ |
| 3679 | { 0x1f, 0x0005 }, |
| 3680 | { 0x05, 0x8b79 }, |
| 3681 | { 0x06, 0xaa00 }, |
| 3682 | { 0x1f, 0x0000 }, |
| 3683 | |
| 3684 | /* Disable hiimpedance detection (RTCT) */ |
| 3685 | { 0x1f, 0x0003 }, |
| 3686 | { 0x01, 0x328a }, |
| 3687 | { 0x1f, 0x0000 } |
| 3688 | }; |
| 3689 | |
| 3690 | rtl_apply_firmware(tp); |
| 3691 | |
| 3692 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3693 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3694 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3695 | |
| 3696 | /* Improve 2-pair detection performance */ |
| 3697 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3698 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3699 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3700 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3701 | } |
| 3702 | |
| 3703 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3704 | { |
| 3705 | rtl_apply_firmware(tp); |
| 3706 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3707 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3708 | } |
| 3709 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3710 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3711 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3712 | static const struct phy_reg phy_reg_init[] = { |
| 3713 | /* Channel estimation fine tune */ |
| 3714 | { 0x1f, 0x0003 }, |
| 3715 | { 0x09, 0xa20f }, |
| 3716 | { 0x1f, 0x0000 }, |
| 3717 | |
| 3718 | /* Modify green table for giga & fnet */ |
| 3719 | { 0x1f, 0x0005 }, |
| 3720 | { 0x05, 0x8b55 }, |
| 3721 | { 0x06, 0x0000 }, |
| 3722 | { 0x05, 0x8b5e }, |
| 3723 | { 0x06, 0x0000 }, |
| 3724 | { 0x05, 0x8b67 }, |
| 3725 | { 0x06, 0x0000 }, |
| 3726 | { 0x05, 0x8b70 }, |
| 3727 | { 0x06, 0x0000 }, |
| 3728 | { 0x1f, 0x0000 }, |
| 3729 | { 0x1f, 0x0007 }, |
| 3730 | { 0x1e, 0x0078 }, |
| 3731 | { 0x17, 0x0000 }, |
| 3732 | { 0x19, 0x00aa }, |
| 3733 | { 0x1f, 0x0000 }, |
| 3734 | |
| 3735 | /* Modify green table for 10M */ |
| 3736 | { 0x1f, 0x0005 }, |
| 3737 | { 0x05, 0x8b79 }, |
| 3738 | { 0x06, 0xaa00 }, |
| 3739 | { 0x1f, 0x0000 }, |
| 3740 | |
| 3741 | /* Disable hiimpedance detection (RTCT) */ |
| 3742 | { 0x1f, 0x0003 }, |
| 3743 | { 0x01, 0x328a }, |
| 3744 | { 0x1f, 0x0000 } |
| 3745 | }; |
| 3746 | |
| 3747 | |
| 3748 | rtl_apply_firmware(tp); |
| 3749 | |
| 3750 | rtl8168f_hw_phy_config(tp); |
| 3751 | |
| 3752 | /* Improve 2-pair detection performance */ |
| 3753 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3754 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3755 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3756 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3757 | |
| 3758 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3759 | |
| 3760 | /* Modify green table for giga */ |
| 3761 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3762 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3763 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3764 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3765 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3766 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3767 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3768 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3769 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3770 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3771 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3772 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3773 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3774 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3775 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3776 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3777 | |
| 3778 | /* uc same-seed solution */ |
| 3779 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3780 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3781 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3782 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3783 | |
| 3784 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3785 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3786 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3787 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3788 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3789 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3790 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3791 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3792 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3793 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3794 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3795 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3796 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3797 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3798 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3799 | |
| 3800 | /* Green feature */ |
| 3801 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3802 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3803 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3804 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3805 | } |
| 3806 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3807 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3808 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3809 | rtl_apply_firmware(tp); |
| 3810 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3811 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3812 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 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, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3815 | } else { |
| 3816 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3817 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3818 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3819 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3820 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3821 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 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, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3824 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3825 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3826 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3827 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3828 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3829 | /* Enable PHY auto speed down */ |
| 3830 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3831 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3832 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3833 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3834 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3835 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3836 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3837 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3838 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3839 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3840 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3841 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3842 | /* EEE auto-fallback function */ |
| 3843 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3844 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3845 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3846 | /* Enable UC LPF tune function */ |
| 3847 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3848 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3849 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3850 | |
| 3851 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3852 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3853 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3854 | /* Improve SWR Efficiency */ |
| 3855 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3856 | rtl_writephy(tp, 0x14, 0x5065); |
| 3857 | rtl_writephy(tp, 0x14, 0xd065); |
| 3858 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3859 | rtl_writephy(tp, 0x11, 0x5655); |
| 3860 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3861 | rtl_writephy(tp, 0x14, 0x1065); |
| 3862 | rtl_writephy(tp, 0x14, 0x9065); |
| 3863 | rtl_writephy(tp, 0x14, 0x1065); |
| 3864 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3865 | /* Check ALDPS bit, disable it if enabled */ |
| 3866 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3867 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3868 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3869 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3870 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3871 | } |
| 3872 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3873 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3874 | { |
| 3875 | rtl_apply_firmware(tp); |
| 3876 | } |
| 3877 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3878 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3879 | { |
| 3880 | u16 dout_tapbin; |
| 3881 | u32 data; |
| 3882 | |
| 3883 | rtl_apply_firmware(tp); |
| 3884 | |
| 3885 | /* CHN EST parameters adjust - giga master */ |
| 3886 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3887 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3888 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3889 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3890 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3891 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3892 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3893 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3894 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3895 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3896 | |
| 3897 | /* CHN EST parameters adjust - giga slave */ |
| 3898 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3899 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3900 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3901 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3902 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3903 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3904 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3905 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3906 | |
| 3907 | /* CHN EST parameters adjust - fnet */ |
| 3908 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3909 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3910 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3911 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3912 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3913 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3914 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3915 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3916 | |
| 3917 | /* enable R-tune & PGA-retune function */ |
| 3918 | dout_tapbin = 0; |
| 3919 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3920 | data = rtl_readphy(tp, 0x13); |
| 3921 | data &= 3; |
| 3922 | data <<= 2; |
| 3923 | dout_tapbin |= data; |
| 3924 | data = rtl_readphy(tp, 0x12); |
| 3925 | data &= 0xc000; |
| 3926 | data >>= 14; |
| 3927 | dout_tapbin |= data; |
| 3928 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3929 | dout_tapbin <<= 12; |
| 3930 | dout_tapbin &= 0xf000; |
| 3931 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3932 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3933 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3934 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3935 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3936 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3937 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3938 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3939 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3940 | |
| 3941 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3942 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3943 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3944 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3945 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3946 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3947 | |
| 3948 | /* enable GPHY 10M */ |
| 3949 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3950 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3951 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3952 | |
| 3953 | /* SAR ADC performance */ |
| 3954 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3955 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3956 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3957 | |
| 3958 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3959 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3960 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3961 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3962 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3963 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3964 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3965 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3966 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3967 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3968 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3969 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3970 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3971 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3972 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3973 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3974 | |
| 3975 | /* disable phy pfm mode */ |
| 3976 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 3977 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3978 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3979 | |
| 3980 | /* Check ALDPS bit, disable it if enabled */ |
| 3981 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3982 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3983 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3984 | |
| 3985 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3986 | } |
| 3987 | |
| 3988 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3989 | { |
| 3990 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3991 | u16 rlen; |
| 3992 | u32 data; |
| 3993 | |
| 3994 | rtl_apply_firmware(tp); |
| 3995 | |
| 3996 | /* CHIN EST parameter update */ |
| 3997 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3998 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3999 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4000 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4001 | |
| 4002 | /* enable R-tune & PGA-retune function */ |
| 4003 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4004 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4005 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4006 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4007 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4008 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4009 | |
| 4010 | /* enable GPHY 10M */ |
| 4011 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4012 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4013 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4014 | |
| 4015 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 4016 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 4017 | ioffset_p3 = ((data & 0x80)>>7); |
| 4018 | ioffset_p3 <<= 3; |
| 4019 | |
| 4020 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 4021 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 4022 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 4023 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 4024 | ioffset_p0 = ((data & 0x0010)>>4); |
| 4025 | ioffset_p0 <<= 3; |
| 4026 | ioffset_p0 |= (data & (0x07)); |
| 4027 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 4028 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4029 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 4030 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4031 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 4032 | rtl_writephy(tp, 0x16, data); |
| 4033 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4034 | } |
| 4035 | |
| 4036 | /* Modify rlen (TX LPF corner frequency) level */ |
| 4037 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4038 | data = rtl_readphy(tp, 0x16); |
| 4039 | data &= 0x000f; |
| 4040 | rlen = 0; |
| 4041 | if (data > 3) |
| 4042 | rlen = data - 3; |
| 4043 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 4044 | rtl_writephy(tp, 0x17, data); |
| 4045 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4046 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4047 | |
| 4048 | /* disable phy pfm mode */ |
| 4049 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4050 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4051 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4052 | |
| 4053 | /* Check ALDPS bit, disable it if enabled */ |
| 4054 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4055 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4056 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4057 | |
| 4058 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4059 | } |
| 4060 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4061 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 4062 | { |
| 4063 | /* Enable PHY auto speed down */ |
| 4064 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4065 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 4066 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4067 | |
| 4068 | /* patch 10M & ALDPS */ |
| 4069 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4070 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4071 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4072 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4073 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4074 | rtl_writephy(tp, 0x13, 0x8084); |
| 4075 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4076 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4077 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4078 | |
| 4079 | /* Enable EEE auto-fallback function */ |
| 4080 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 4081 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 4082 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4083 | |
| 4084 | /* Enable UC LPF tune function */ |
| 4085 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4086 | rtl_writephy(tp, 0x13, 0x8012); |
| 4087 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4088 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4089 | |
| 4090 | /* set rg_sel_sdm_rate */ |
| 4091 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4092 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4093 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4094 | |
| 4095 | /* Check ALDPS bit, disable it if enabled */ |
| 4096 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4097 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4098 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4099 | |
| 4100 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4101 | } |
| 4102 | |
| 4103 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 4104 | { |
| 4105 | /* patch 10M & ALDPS */ |
| 4106 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4107 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4108 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4109 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4110 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4111 | rtl_writephy(tp, 0x13, 0x8084); |
| 4112 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4113 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4114 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4115 | |
| 4116 | /* Enable UC LPF tune function */ |
| 4117 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4118 | rtl_writephy(tp, 0x13, 0x8012); |
| 4119 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4120 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4121 | |
| 4122 | /* Set rg_sel_sdm_rate */ |
| 4123 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4124 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4125 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4126 | |
| 4127 | /* Channel estimation parameters */ |
| 4128 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4129 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4130 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4131 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4132 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4133 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4134 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4135 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4136 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4137 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4138 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4139 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4140 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4141 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4142 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4143 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4144 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4145 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4146 | rtl_writephy(tp, 0x13, 0x8110); |
| 4147 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4148 | rtl_writephy(tp, 0x13, 0x810f); |
| 4149 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4150 | rtl_writephy(tp, 0x13, 0x8111); |
| 4151 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4152 | rtl_writephy(tp, 0x13, 0x8113); |
| 4153 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4154 | rtl_writephy(tp, 0x13, 0x8115); |
| 4155 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4156 | rtl_writephy(tp, 0x13, 0x810e); |
| 4157 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4158 | rtl_writephy(tp, 0x13, 0x810c); |
| 4159 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4160 | rtl_writephy(tp, 0x13, 0x810b); |
| 4161 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4162 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4163 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4164 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4165 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4166 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4167 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4168 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4169 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4170 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4171 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4172 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4173 | |
| 4174 | /* Force PWM-mode */ |
| 4175 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4176 | rtl_writephy(tp, 0x14, 0x5065); |
| 4177 | rtl_writephy(tp, 0x14, 0xd065); |
| 4178 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4179 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4180 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4181 | rtl_writephy(tp, 0x14, 0x1065); |
| 4182 | rtl_writephy(tp, 0x14, 0x9065); |
| 4183 | rtl_writephy(tp, 0x14, 0x1065); |
| 4184 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4185 | |
| 4186 | /* Check ALDPS bit, disable it if enabled */ |
| 4187 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4188 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4189 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4190 | |
| 4191 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4192 | } |
| 4193 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4194 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4195 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4196 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4197 | { 0x1f, 0x0003 }, |
| 4198 | { 0x08, 0x441d }, |
| 4199 | { 0x01, 0x9100 }, |
| 4200 | { 0x1f, 0x0000 } |
| 4201 | }; |
| 4202 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4203 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4204 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4205 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4206 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4207 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4208 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4209 | } |
| 4210 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4211 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4212 | { |
| 4213 | static const struct phy_reg phy_reg_init[] = { |
| 4214 | { 0x1f, 0x0005 }, |
| 4215 | { 0x1a, 0x0000 }, |
| 4216 | { 0x1f, 0x0000 }, |
| 4217 | |
| 4218 | { 0x1f, 0x0004 }, |
| 4219 | { 0x1c, 0x0000 }, |
| 4220 | { 0x1f, 0x0000 }, |
| 4221 | |
| 4222 | { 0x1f, 0x0001 }, |
| 4223 | { 0x15, 0x7701 }, |
| 4224 | { 0x1f, 0x0000 } |
| 4225 | }; |
| 4226 | |
| 4227 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4228 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4229 | rtl_writephy(tp, 0x18, 0x0310); |
| 4230 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4231 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4232 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4233 | |
| 4234 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4235 | } |
| 4236 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4237 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4238 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4239 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4240 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4241 | rtl_writephy(tp, 0x18, 0x0310); |
| 4242 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4243 | |
| 4244 | rtl_apply_firmware(tp); |
| 4245 | |
| 4246 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4247 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4248 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4249 | rtl_writephy(tp, 0x10, 0x401f); |
| 4250 | rtl_writephy(tp, 0x19, 0x7030); |
| 4251 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4252 | } |
| 4253 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4254 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4255 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4256 | static const struct phy_reg phy_reg_init[] = { |
| 4257 | { 0x1f, 0x0004 }, |
| 4258 | { 0x10, 0xc07f }, |
| 4259 | { 0x19, 0x7030 }, |
| 4260 | { 0x1f, 0x0000 } |
| 4261 | }; |
| 4262 | |
| 4263 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4264 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4265 | rtl_writephy(tp, 0x18, 0x0310); |
| 4266 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4267 | |
| 4268 | rtl_apply_firmware(tp); |
| 4269 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4270 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4271 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4272 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4273 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4274 | } |
| 4275 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4276 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4277 | { |
| 4278 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4279 | |
| 4280 | rtl8169_print_mac_version(tp); |
| 4281 | |
| 4282 | switch (tp->mac_version) { |
| 4283 | case RTL_GIGA_MAC_VER_01: |
| 4284 | break; |
| 4285 | case RTL_GIGA_MAC_VER_02: |
| 4286 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4287 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4288 | break; |
| 4289 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4290 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4291 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4292 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4293 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4294 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4295 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4296 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4297 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4298 | case RTL_GIGA_MAC_VER_07: |
| 4299 | case RTL_GIGA_MAC_VER_08: |
| 4300 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4301 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4302 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4303 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4304 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4305 | break; |
| 4306 | case RTL_GIGA_MAC_VER_12: |
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; |
| 4309 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4310 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4311 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4312 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4313 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4314 | break; |
| 4315 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4316 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4317 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4318 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4319 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4320 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4321 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4322 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4323 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4324 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4325 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4326 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4327 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4328 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4329 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4330 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4331 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4332 | rtl8168d_1_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_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4335 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4336 | break; |
| 4337 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4338 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4339 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4340 | case RTL_GIGA_MAC_VER_28: |
| 4341 | rtl8168d_4_hw_phy_config(tp); |
| 4342 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4343 | case RTL_GIGA_MAC_VER_29: |
| 4344 | case RTL_GIGA_MAC_VER_30: |
| 4345 | rtl8105e_hw_phy_config(tp); |
| 4346 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4347 | case RTL_GIGA_MAC_VER_31: |
| 4348 | /* None. */ |
| 4349 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4350 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4351 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4352 | rtl8168e_1_hw_phy_config(tp); |
| 4353 | break; |
| 4354 | case RTL_GIGA_MAC_VER_34: |
| 4355 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4356 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4357 | case RTL_GIGA_MAC_VER_35: |
| 4358 | rtl8168f_1_hw_phy_config(tp); |
| 4359 | break; |
| 4360 | case RTL_GIGA_MAC_VER_36: |
| 4361 | rtl8168f_2_hw_phy_config(tp); |
| 4362 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4363 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4364 | case RTL_GIGA_MAC_VER_37: |
| 4365 | rtl8402_hw_phy_config(tp); |
| 4366 | break; |
| 4367 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4368 | case RTL_GIGA_MAC_VER_38: |
| 4369 | rtl8411_hw_phy_config(tp); |
| 4370 | break; |
| 4371 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4372 | case RTL_GIGA_MAC_VER_39: |
| 4373 | rtl8106e_hw_phy_config(tp); |
| 4374 | break; |
| 4375 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4376 | case RTL_GIGA_MAC_VER_40: |
| 4377 | rtl8168g_1_hw_phy_config(tp); |
| 4378 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4379 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4380 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4381 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4382 | rtl8168g_2_hw_phy_config(tp); |
| 4383 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4384 | case RTL_GIGA_MAC_VER_45: |
| 4385 | case RTL_GIGA_MAC_VER_47: |
| 4386 | rtl8168h_1_hw_phy_config(tp); |
| 4387 | break; |
| 4388 | case RTL_GIGA_MAC_VER_46: |
| 4389 | case RTL_GIGA_MAC_VER_48: |
| 4390 | rtl8168h_2_hw_phy_config(tp); |
| 4391 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4392 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4393 | case RTL_GIGA_MAC_VER_49: |
| 4394 | rtl8168ep_1_hw_phy_config(tp); |
| 4395 | break; |
| 4396 | case RTL_GIGA_MAC_VER_50: |
| 4397 | case RTL_GIGA_MAC_VER_51: |
| 4398 | rtl8168ep_2_hw_phy_config(tp); |
| 4399 | break; |
| 4400 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4401 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4402 | default: |
| 4403 | break; |
| 4404 | } |
| 4405 | } |
| 4406 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4407 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | struct timer_list *timer = &tp->timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4411 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4412 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4414 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4415 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4417 | * Let's delay the execution of the timer for a few ticks. |
| 4418 | */ |
| 4419 | timeout = HZ/10; |
| 4420 | goto out_mod_timer; |
| 4421 | } |
| 4422 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4423 | if (tp->link_ok(tp)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4424 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4426 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4428 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4429 | |
| 4430 | out_mod_timer: |
| 4431 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4435 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4436 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4437 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4440 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4441 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4442 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4443 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4444 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4447 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4448 | { |
| 4449 | return tp->phy_reset_pending(tp); |
| 4450 | } |
| 4451 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4452 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4453 | struct rtl8169_private *tp) |
| 4454 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4455 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4456 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4459 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4460 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4461 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4462 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4463 | } |
| 4464 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4465 | 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] | 4466 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4467 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4468 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4469 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4470 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4471 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4472 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4473 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4474 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4475 | |
| 4476 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4477 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4478 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4479 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4480 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4481 | RTL_W8(tp, 0x82, 0x01); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4482 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4483 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4484 | } |
| 4485 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4486 | rtl8169_phy_reset(dev, tp); |
| 4487 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4488 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4489 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4490 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4491 | (tp->mii.supports_gmii ? |
| 4492 | ADVERTISED_1000baseT_Half | |
| 4493 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4494 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4495 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4496 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4497 | } |
| 4498 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4499 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4500 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4501 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4502 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4503 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
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, MAC4, addr[4] | addr[5] << 8); |
| 4506 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4507 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4508 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4509 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4510 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4511 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4512 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4513 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4514 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4515 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4516 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4520 | { |
| 4521 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4522 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4523 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4524 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4525 | ret = eth_mac_addr(dev, p); |
| 4526 | if (ret) |
| 4527 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4528 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4529 | pm_runtime_get_noresume(d); |
| 4530 | |
| 4531 | if (pm_runtime_active(d)) |
| 4532 | rtl_rar_set(tp, dev->dev_addr); |
| 4533 | |
| 4534 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4535 | |
| 4536 | return 0; |
| 4537 | } |
| 4538 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4539 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4540 | { |
| 4541 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4542 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4543 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4544 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4545 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4546 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4547 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4548 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4549 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4550 | switch (cmd) { |
| 4551 | case SIOCGMIIPHY: |
| 4552 | data->phy_id = 32; /* Internal PHY */ |
| 4553 | return 0; |
| 4554 | |
| 4555 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4556 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4557 | return 0; |
| 4558 | |
| 4559 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4560 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4561 | return 0; |
| 4562 | } |
| 4563 | return -EOPNOTSUPP; |
| 4564 | } |
| 4565 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4566 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4567 | { |
| 4568 | return -EOPNOTSUPP; |
| 4569 | } |
| 4570 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4571 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4572 | { |
| 4573 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4574 | |
| 4575 | switch (tp->mac_version) { |
| 4576 | case RTL_GIGA_MAC_VER_27: |
| 4577 | ops->write = r8168dp_1_mdio_write; |
| 4578 | ops->read = r8168dp_1_mdio_read; |
| 4579 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4580 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4581 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4582 | ops->write = r8168dp_2_mdio_write; |
| 4583 | ops->read = r8168dp_2_mdio_read; |
| 4584 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4585 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4586 | ops->write = r8168g_mdio_write; |
| 4587 | ops->read = r8168g_mdio_read; |
| 4588 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4589 | default: |
| 4590 | ops->write = r8169_mdio_write; |
| 4591 | ops->read = r8169_mdio_read; |
| 4592 | break; |
| 4593 | } |
| 4594 | } |
| 4595 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4596 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4597 | { |
| 4598 | u32 adv; |
| 4599 | int lpa; |
| 4600 | |
| 4601 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4602 | lpa = rtl_readphy(tp, MII_LPA); |
| 4603 | |
| 4604 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4605 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4606 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4607 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4608 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4609 | else |
| 4610 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4611 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4612 | (tp->mii.supports_gmii ? |
| 4613 | ADVERTISED_1000baseT_Half | |
| 4614 | ADVERTISED_1000baseT_Full : 0); |
| 4615 | |
| 4616 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4617 | adv); |
| 4618 | } |
| 4619 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4620 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4621 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4622 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4623 | case RTL_GIGA_MAC_VER_25: |
| 4624 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4625 | case RTL_GIGA_MAC_VER_29: |
| 4626 | case RTL_GIGA_MAC_VER_30: |
| 4627 | case RTL_GIGA_MAC_VER_32: |
| 4628 | case RTL_GIGA_MAC_VER_33: |
| 4629 | case RTL_GIGA_MAC_VER_34: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4630 | case RTL_GIGA_MAC_VER_37 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4631 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4632 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4633 | break; |
| 4634 | default: |
| 4635 | break; |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4640 | { |
| 4641 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 4642 | return false; |
| 4643 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4644 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4645 | rtl_wol_suspend_quirk(tp); |
| 4646 | |
| 4647 | return true; |
| 4648 | } |
| 4649 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4650 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4651 | { |
| 4652 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4653 | switch (tp->mac_version) { |
| 4654 | case RTL_GIGA_MAC_VER_11: |
| 4655 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4656 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4657 | case RTL_GIGA_MAC_VER_31: |
| 4658 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4659 | break; |
| 4660 | default: |
| 4661 | break; |
| 4662 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4663 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
David S. Miller | b2d6cee | 2018-05-11 20:53:22 -0400 | [diff] [blame] | 4664 | |
| 4665 | /* give MAC/PHY some time to resume */ |
| 4666 | msleep(20); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4670 | { |
| 4671 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4672 | switch (tp->mac_version) { |
| 4673 | case RTL_GIGA_MAC_VER_32: |
| 4674 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4675 | case RTL_GIGA_MAC_VER_40: |
| 4676 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4677 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4678 | break; |
| 4679 | |
| 4680 | case RTL_GIGA_MAC_VER_11: |
| 4681 | case RTL_GIGA_MAC_VER_12: |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4682 | case RTL_GIGA_MAC_VER_17 ... RTL_GIGA_MAC_VER_28: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4683 | case RTL_GIGA_MAC_VER_31: |
| 4684 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4685 | default: |
| 4686 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4687 | break; |
| 4688 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4692 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4693 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4694 | return; |
| 4695 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4696 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4697 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4698 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4699 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4700 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4701 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4702 | |
| 4703 | r8168_phy_power_down(tp); |
| 4704 | |
| 4705 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4706 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4707 | case RTL_GIGA_MAC_VER_37: |
| 4708 | case RTL_GIGA_MAC_VER_39: |
| 4709 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4710 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4711 | case RTL_GIGA_MAC_VER_45: |
| 4712 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4713 | case RTL_GIGA_MAC_VER_47: |
| 4714 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4715 | case RTL_GIGA_MAC_VER_50: |
| 4716 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4717 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4718 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4719 | case RTL_GIGA_MAC_VER_40: |
| 4720 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4721 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4722 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4723 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4724 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4725 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4726 | } |
| 4727 | } |
| 4728 | |
| 4729 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4730 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4731 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4732 | case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_33: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4733 | case RTL_GIGA_MAC_VER_37: |
| 4734 | case RTL_GIGA_MAC_VER_39: |
| 4735 | case RTL_GIGA_MAC_VER_43: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4736 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4737 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4738 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4739 | case RTL_GIGA_MAC_VER_45: |
| 4740 | case RTL_GIGA_MAC_VER_46: |
Heiner Kallweit | 73570bf | 2018-05-02 21:39:45 +0200 | [diff] [blame] | 4741 | case RTL_GIGA_MAC_VER_47: |
| 4742 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4743 | case RTL_GIGA_MAC_VER_50: |
| 4744 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4745 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4746 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4747 | case RTL_GIGA_MAC_VER_40: |
| 4748 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4749 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4750 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4751 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4752 | 0x00000000, ERIAR_EXGMAC); |
| 4753 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
| 4756 | r8168_phy_power_up(tp); |
| 4757 | } |
| 4758 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4759 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4760 | { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4761 | switch (tp->mac_version) { |
| 4762 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4763 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
| 4764 | break; |
| 4765 | default: |
| 4766 | r8168_pll_power_down(tp); |
| 4767 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4771 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4772 | switch (tp->mac_version) { |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4773 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4774 | case RTL_GIGA_MAC_VER_13 ... RTL_GIGA_MAC_VER_15: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4775 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4776 | default: |
Heiner Kallweit | 4f447d2 | 2018-05-02 21:39:47 +0200 | [diff] [blame] | 4777 | r8168_pll_power_up(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4778 | } |
| 4779 | } |
| 4780 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4781 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4782 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4783 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4784 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_06: |
| 4785 | case RTL_GIGA_MAC_VER_10 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4786 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4787 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4788 | case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4789 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 4790 | case RTL_GIGA_MAC_VER_35: |
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); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4792 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4793 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4794 | 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] | 4795 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4796 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4797 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4798 | break; |
| 4799 | } |
| 4800 | } |
| 4801 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4802 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4803 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4804 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4805 | } |
| 4806 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4807 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4808 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4809 | if (tp->jumbo_ops.enable) { |
| 4810 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4811 | tp->jumbo_ops.enable(tp); |
| 4812 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4813 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4817 | { |
Heiner Kallweit | eda40b8 | 2018-05-02 21:39:54 +0200 | [diff] [blame] | 4818 | if (tp->jumbo_ops.disable) { |
| 4819 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 4820 | tp->jumbo_ops.disable(tp); |
| 4821 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 4822 | } |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4823 | } |
| 4824 | |
| 4825 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4826 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4827 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4828 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4829 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4833 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4834 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4835 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4836 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4840 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4841 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4845 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4846 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4850 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4851 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 4852 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 4853 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4854 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4858 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4859 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 4860 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 4861 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4862 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4866 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4867 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 4868 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4872 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 4873 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 4874 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4878 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4879 | r8168b_0_hw_jumbo_enable(tp); |
| 4880 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4881 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4885 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4886 | r8168b_0_hw_jumbo_disable(tp); |
| 4887 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4888 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4889 | } |
| 4890 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4891 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4892 | { |
| 4893 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4894 | |
| 4895 | switch (tp->mac_version) { |
| 4896 | case RTL_GIGA_MAC_VER_11: |
| 4897 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4898 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4899 | break; |
| 4900 | case RTL_GIGA_MAC_VER_12: |
| 4901 | case RTL_GIGA_MAC_VER_17: |
| 4902 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4903 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4904 | break; |
| 4905 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4906 | case RTL_GIGA_MAC_VER_19: |
| 4907 | case RTL_GIGA_MAC_VER_20: |
| 4908 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4909 | case RTL_GIGA_MAC_VER_22: |
| 4910 | case RTL_GIGA_MAC_VER_23: |
| 4911 | case RTL_GIGA_MAC_VER_24: |
| 4912 | case RTL_GIGA_MAC_VER_25: |
| 4913 | case RTL_GIGA_MAC_VER_26: |
| 4914 | ops->disable = r8168c_hw_jumbo_disable; |
| 4915 | ops->enable = r8168c_hw_jumbo_enable; |
| 4916 | break; |
| 4917 | case RTL_GIGA_MAC_VER_27: |
| 4918 | case RTL_GIGA_MAC_VER_28: |
| 4919 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4920 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4921 | break; |
| 4922 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4923 | case RTL_GIGA_MAC_VER_32: |
| 4924 | case RTL_GIGA_MAC_VER_33: |
| 4925 | case RTL_GIGA_MAC_VER_34: |
| 4926 | ops->disable = r8168e_hw_jumbo_disable; |
| 4927 | ops->enable = r8168e_hw_jumbo_enable; |
| 4928 | break; |
| 4929 | |
| 4930 | /* |
| 4931 | * No action needed for jumbo frames with 8169. |
| 4932 | * No jumbo for 810x at all. |
| 4933 | */ |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 4934 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4935 | default: |
| 4936 | ops->disable = NULL; |
| 4937 | ops->enable = NULL; |
| 4938 | break; |
| 4939 | } |
| 4940 | } |
| 4941 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4942 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4943 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4944 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4945 | } |
| 4946 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4947 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4948 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4949 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4950 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4951 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4952 | } |
| 4953 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4954 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4955 | { |
| 4956 | struct rtl_fw *rtl_fw; |
| 4957 | const char *name; |
| 4958 | int rc = -ENOMEM; |
| 4959 | |
| 4960 | name = rtl_lookup_firmware_name(tp); |
| 4961 | if (!name) |
| 4962 | goto out_no_firmware; |
| 4963 | |
| 4964 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4965 | if (!rtl_fw) |
| 4966 | goto err_warn; |
| 4967 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4968 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4969 | if (rc < 0) |
| 4970 | goto err_free; |
| 4971 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4972 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4973 | if (rc < 0) |
| 4974 | goto err_release_firmware; |
| 4975 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4976 | tp->rtl_fw = rtl_fw; |
| 4977 | out: |
| 4978 | return; |
| 4979 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4980 | err_release_firmware: |
| 4981 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4982 | err_free: |
| 4983 | kfree(rtl_fw); |
| 4984 | err_warn: |
| 4985 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4986 | name, rc); |
| 4987 | out_no_firmware: |
| 4988 | tp->rtl_fw = NULL; |
| 4989 | goto out; |
| 4990 | } |
| 4991 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4992 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4993 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4994 | if (IS_ERR(tp->rtl_fw)) |
| 4995 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4996 | } |
| 4997 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4998 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4999 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5000 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5001 | } |
| 5002 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5003 | DECLARE_RTL_COND(rtl_npq_cond) |
| 5004 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5005 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 5009 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5010 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5011 | } |
| 5012 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5013 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | { |
| 5015 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5016 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5018 | rtl_rx_close(tp); |
| 5019 | |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5020 | switch (tp->mac_version) { |
| 5021 | case RTL_GIGA_MAC_VER_27: |
| 5022 | case RTL_GIGA_MAC_VER_28: |
| 5023 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5024 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5025 | break; |
| 5026 | case RTL_GIGA_MAC_VER_34 ... RTL_GIGA_MAC_VER_38: |
| 5027 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5028 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5029 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5030 | break; |
| 5031 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5032 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5033 | udelay(100); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 5034 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5037 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5040 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5041 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5042 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5043 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5044 | (InterFrameGap << TxInterFrameGapShift)); |
| 5045 | } |
| 5046 | |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 5047 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | { |
Heiner Kallweit | 4fd48c4 | 2018-04-28 22:19:47 +0200 | [diff] [blame] | 5049 | /* Low hurts. Let's disable the filtering. */ |
| 5050 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5051 | } |
| 5052 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5053 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5054 | { |
| 5055 | /* |
| 5056 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 5057 | * register to be written before TxDescAddrLow to work. |
| 5058 | * Switching from MMIO to I/O access fixes the issue as well. |
| 5059 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5060 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 5061 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 5062 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 5063 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5064 | } |
| 5065 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5066 | 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] | 5067 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5068 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5069 | u32 mac_version; |
| 5070 | u32 clk; |
| 5071 | u32 val; |
| 5072 | } cfg2_info [] = { |
| 5073 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 5074 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 5075 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 5076 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5077 | }; |
| 5078 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5079 | unsigned int i; |
| 5080 | u32 clk; |
| 5081 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5082 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 5083 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5084 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5085 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5086 | break; |
| 5087 | } |
| 5088 | } |
| 5089 | } |
| 5090 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5091 | static void rtl_set_rx_mode(struct net_device *dev) |
| 5092 | { |
| 5093 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5094 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 5095 | int rx_mode; |
| 5096 | u32 tmp = 0; |
| 5097 | |
| 5098 | if (dev->flags & IFF_PROMISC) { |
| 5099 | /* Unconditionally log net taps. */ |
| 5100 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 5101 | rx_mode = |
| 5102 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5103 | AcceptAllPhys; |
| 5104 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5105 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 5106 | (dev->flags & IFF_ALLMULTI)) { |
| 5107 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5108 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5109 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5110 | } else { |
| 5111 | struct netdev_hw_addr *ha; |
| 5112 | |
| 5113 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5114 | mc_filter[1] = mc_filter[0] = 0; |
| 5115 | netdev_for_each_mc_addr(ha, dev) { |
| 5116 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 5117 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5118 | rx_mode |= AcceptMulticast; |
| 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | if (dev->features & NETIF_F_RXALL) |
| 5123 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5124 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5125 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5126 | |
| 5127 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5128 | u32 data = mc_filter[0]; |
| 5129 | |
| 5130 | mc_filter[0] = swab32(mc_filter[1]); |
| 5131 | mc_filter[1] = swab32(data); |
| 5132 | } |
| 5133 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5134 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5135 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5136 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5137 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 5138 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5139 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5140 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Heiner Kallweit | 52f8560 | 2018-05-19 10:29:33 +0200 | [diff] [blame] | 5143 | static void rtl_hw_start(struct rtl8169_private *tp) |
| 5144 | { |
| 5145 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 5146 | |
| 5147 | tp->hw_start(tp); |
| 5148 | |
| 5149 | rtl_set_rx_max_size(tp); |
| 5150 | rtl_set_rx_tx_desc_registers(tp); |
| 5151 | rtl_set_rx_tx_config_registers(tp); |
| 5152 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
| 5153 | |
| 5154 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5155 | RTL_R8(tp, IntrMask); |
| 5156 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5157 | rtl_set_rx_mode(tp->dev); |
| 5158 | /* no early-rx interrupts */ |
| 5159 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
| 5160 | rtl_irq_enable_all(tp); |
| 5161 | } |
| 5162 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5163 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5164 | { |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5165 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5166 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5167 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5168 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5170 | tp->cp_cmd |= PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5171 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5172 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5173 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5174 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5176 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5179 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5180 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5181 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | /* |
| 5184 | * Undocumented corner. Supposedly: |
| 5185 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5186 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5187 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5189 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5191 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5192 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5193 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5194 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5195 | } |
| 5196 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5197 | 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] | 5198 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5199 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5200 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5201 | RTL_W32(tp, CSIDR, value); |
| 5202 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5203 | CSIAR_BYTE_ENABLE | func << 16); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5204 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5205 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5206 | } |
| 5207 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5208 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5209 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5210 | u32 func = PCI_FUNC(tp->pci_dev->devfn); |
| 5211 | |
| 5212 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | func << 16 | |
| 5213 | CSIAR_BYTE_ENABLE); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5214 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5215 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5216 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5217 | } |
| 5218 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5219 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u8 val) |
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 | struct pci_dev *pdev = tp->pci_dev; |
| 5222 | u32 csi; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5223 | |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5224 | /* According to Realtek the value at config space address 0x070f |
| 5225 | * controls the L0s/L1 entrance latency. We try standard ECAM access |
| 5226 | * first and if it fails fall back to CSI. |
| 5227 | */ |
| 5228 | if (pdev->cfg_size > 0x070f && |
| 5229 | pci_write_config_byte(pdev, 0x070f, val) == PCIBIOS_SUCCESSFUL) |
| 5230 | return; |
| 5231 | |
| 5232 | netdev_notice_once(tp->dev, |
| 5233 | "No native access to PCI extended config space, falling back to CSI\n"); |
| 5234 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5235 | rtl_csi_write(tp, 0x070c, csi | val << 24); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5236 | } |
| 5237 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5238 | static void rtl_set_def_aspm_entry_latency(struct rtl8169_private *tp) |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5239 | { |
Heiner Kallweit | ff1d733 | 2018-05-02 21:39:56 +0200 | [diff] [blame] | 5240 | rtl_csi_access_enable(tp, 0x27); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | struct ephy_info { |
| 5244 | unsigned int offset; |
| 5245 | u16 mask; |
| 5246 | u16 bits; |
| 5247 | }; |
| 5248 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5249 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5250 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5251 | { |
| 5252 | u16 w; |
| 5253 | |
| 5254 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5255 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5256 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5257 | e++; |
| 5258 | } |
| 5259 | } |
| 5260 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5261 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5262 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5263 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5264 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5265 | } |
| 5266 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5267 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5268 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5269 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5270 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5271 | } |
| 5272 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5273 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5274 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5275 | u8 data; |
| 5276 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5277 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5278 | |
| 5279 | if (enable) |
| 5280 | data |= Rdy_to_L23; |
| 5281 | else |
| 5282 | data &= ~Rdy_to_L23; |
| 5283 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5284 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5285 | } |
| 5286 | |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5287 | static void rtl_hw_aspm_clkreq_enable(struct rtl8169_private *tp, bool enable) |
| 5288 | { |
| 5289 | if (enable) { |
| 5290 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) | ClkReqEn); |
| 5291 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) | ASPM_en); |
| 5292 | } else { |
| 5293 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5294 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
| 5295 | } |
| 5296 | } |
| 5297 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5298 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5299 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5300 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5301 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5302 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5303 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5304 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5305 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5306 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5307 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5308 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5309 | } |
| 5310 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5311 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5312 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5313 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5314 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5315 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5316 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5317 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5318 | } |
| 5319 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5320 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5321 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5322 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5323 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5324 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5325 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5326 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5327 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5328 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5329 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5330 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5331 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5332 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5333 | } |
| 5334 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5335 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5336 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5337 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5338 | { 0x01, 0, 0x0001 }, |
| 5339 | { 0x02, 0x0800, 0x1000 }, |
| 5340 | { 0x03, 0, 0x0042 }, |
| 5341 | { 0x06, 0x0080, 0x0000 }, |
| 5342 | { 0x07, 0, 0x2000 } |
| 5343 | }; |
| 5344 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5345 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5346 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5347 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5348 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5349 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5350 | } |
| 5351 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5352 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5353 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5354 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5355 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5356 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5357 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5358 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5359 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5360 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5361 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5362 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5363 | } |
| 5364 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5365 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5366 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5367 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5368 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5369 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5370 | |
| 5371 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5372 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5373 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5374 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5375 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5376 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5377 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5378 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5379 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5380 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5381 | } |
| 5382 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5383 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5384 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5385 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5386 | { 0x02, 0x0800, 0x1000 }, |
| 5387 | { 0x03, 0, 0x0002 }, |
| 5388 | { 0x06, 0x0080, 0x0000 } |
| 5389 | }; |
| 5390 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5391 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5392 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5393 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5394 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5395 | 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] | 5396 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5397 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5398 | } |
| 5399 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5400 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5401 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5402 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5403 | { 0x01, 0, 0x0001 }, |
| 5404 | { 0x03, 0x0400, 0x0220 } |
| 5405 | }; |
| 5406 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5407 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5408 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5409 | 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] | 5410 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5411 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5412 | } |
| 5413 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5414 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5415 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5416 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5417 | } |
| 5418 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5419 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5420 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5421 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5422 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5423 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5424 | } |
| 5425 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5426 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5427 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5428 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5429 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5430 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5431 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5432 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5433 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5434 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5435 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5436 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 5437 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5438 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5439 | } |
| 5440 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5441 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5442 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5443 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5444 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5445 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5446 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5447 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5448 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5449 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5450 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5453 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5454 | { |
| 5455 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5456 | { 0x0b, 0x0000, 0x0048 }, |
| 5457 | { 0x19, 0x0020, 0x0050 }, |
| 5458 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5459 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5460 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5461 | rtl_set_def_aspm_entry_latency(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5462 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5463 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5464 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5465 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5466 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5467 | 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] | 5468 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5469 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5472 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5473 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5474 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5475 | { 0x00, 0x0200, 0x0100 }, |
| 5476 | { 0x00, 0x0000, 0x0004 }, |
| 5477 | { 0x06, 0x0002, 0x0001 }, |
| 5478 | { 0x06, 0x0000, 0x0030 }, |
| 5479 | { 0x07, 0x0000, 0x2000 }, |
| 5480 | { 0x00, 0x0000, 0x0020 }, |
| 5481 | { 0x03, 0x5800, 0x2000 }, |
| 5482 | { 0x03, 0x0000, 0x0001 }, |
| 5483 | { 0x01, 0x0800, 0x1000 }, |
| 5484 | { 0x07, 0x0000, 0x4000 }, |
| 5485 | { 0x1e, 0x0000, 0x2000 }, |
| 5486 | { 0x19, 0xffff, 0xfe6c }, |
| 5487 | { 0x0a, 0x0000, 0x0040 } |
| 5488 | }; |
| 5489 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5490 | rtl_set_def_aspm_entry_latency(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5491 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5492 | 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] | 5493 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5494 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5495 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5496 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5497 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5498 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5499 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5500 | |
| 5501 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5502 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 5503 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5504 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5505 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5506 | } |
| 5507 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5508 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5509 | { |
| 5510 | static const struct ephy_info e_info_8168e_2[] = { |
| 5511 | { 0x09, 0x0000, 0x0080 }, |
| 5512 | { 0x19, 0x0000, 0x0224 } |
| 5513 | }; |
| 5514 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5515 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5516 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5517 | 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] | 5518 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5519 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5520 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5521 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5522 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5523 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5524 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5525 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5526 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5527 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5528 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5529 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5530 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5531 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5532 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5533 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5534 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5535 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5536 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5537 | |
| 5538 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5539 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5540 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5541 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5542 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5543 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5544 | } |
| 5545 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5546 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5547 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5548 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5549 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5550 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5551 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5552 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5553 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5554 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5555 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5556 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5557 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5558 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5559 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5560 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5561 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5562 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5563 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5564 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5565 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5566 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5567 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5568 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5569 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5570 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5571 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5572 | } |
| 5573 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5574 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5575 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5576 | static const struct ephy_info e_info_8168f_1[] = { |
| 5577 | { 0x06, 0x00c0, 0x0020 }, |
| 5578 | { 0x08, 0x0001, 0x0002 }, |
| 5579 | { 0x09, 0x0000, 0x0080 }, |
| 5580 | { 0x19, 0x0000, 0x0224 } |
| 5581 | }; |
| 5582 | |
| 5583 | rtl_hw_start_8168f(tp); |
| 5584 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5585 | 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] | 5586 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5587 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5588 | |
| 5589 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5590 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5591 | } |
| 5592 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5593 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5594 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5595 | static const struct ephy_info e_info_8168f_1[] = { |
| 5596 | { 0x06, 0x00c0, 0x0020 }, |
| 5597 | { 0x0f, 0xffff, 0x5200 }, |
| 5598 | { 0x1e, 0x0000, 0x4000 }, |
| 5599 | { 0x19, 0x0000, 0x0224 } |
| 5600 | }; |
| 5601 | |
| 5602 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5603 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5604 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5605 | 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] | 5606 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5607 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5608 | } |
| 5609 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5610 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5611 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5612 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5613 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5614 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5615 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5616 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5617 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5618 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5619 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5620 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5621 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5622 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5623 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5624 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5625 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5626 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5627 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5628 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5629 | |
| 5630 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5631 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5632 | |
| 5633 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5634 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5635 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5636 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5637 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5638 | |
| 5639 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5640 | } |
| 5641 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5642 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5643 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5644 | static const struct ephy_info e_info_8168g_1[] = { |
| 5645 | { 0x00, 0x0000, 0x0008 }, |
| 5646 | { 0x0c, 0x37d0, 0x0820 }, |
| 5647 | { 0x1e, 0x0000, 0x0001 }, |
| 5648 | { 0x19, 0x8000, 0x0000 } |
| 5649 | }; |
| 5650 | |
| 5651 | rtl_hw_start_8168g(tp); |
| 5652 | |
| 5653 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5654 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5655 | 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] | 5656 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5657 | } |
| 5658 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5659 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5660 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5661 | static const struct ephy_info e_info_8168g_2[] = { |
| 5662 | { 0x00, 0x0000, 0x0008 }, |
| 5663 | { 0x0c, 0x3df0, 0x0200 }, |
| 5664 | { 0x19, 0xffff, 0xfc00 }, |
| 5665 | { 0x1e, 0xffff, 0x20eb } |
| 5666 | }; |
| 5667 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5668 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5669 | |
| 5670 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5671 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 5672 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5673 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5674 | } |
| 5675 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5676 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5677 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5678 | static const struct ephy_info e_info_8411_2[] = { |
| 5679 | { 0x00, 0x0000, 0x0008 }, |
| 5680 | { 0x0c, 0x3df0, 0x0200 }, |
| 5681 | { 0x0f, 0xffff, 0x5200 }, |
| 5682 | { 0x19, 0x0020, 0x0000 }, |
| 5683 | { 0x1e, 0x0000, 0x2000 } |
| 5684 | }; |
| 5685 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 5686 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5687 | |
| 5688 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5689 | rtl_hw_aspm_clkreq_enable(tp, false); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5690 | 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] | 5691 | rtl_hw_aspm_clkreq_enable(tp, true); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5692 | } |
| 5693 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5694 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5695 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 5696 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5697 | u32 data; |
| 5698 | static const struct ephy_info e_info_8168h_1[] = { |
| 5699 | { 0x1e, 0x0800, 0x0001 }, |
| 5700 | { 0x1d, 0x0000, 0x0800 }, |
| 5701 | { 0x05, 0xffff, 0x2089 }, |
| 5702 | { 0x06, 0xffff, 0x5881 }, |
| 5703 | { 0x04, 0xffff, 0x154a }, |
| 5704 | { 0x01, 0xffff, 0x068b } |
| 5705 | }; |
| 5706 | |
| 5707 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5708 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5709 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5710 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5711 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5712 | |
| 5713 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5714 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5715 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5716 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5717 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5718 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5719 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5720 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5721 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5722 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5723 | 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] | 5724 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5725 | 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] | 5726 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5727 | 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] | 5728 | |
| 5729 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5730 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5731 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5732 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5733 | |
| 5734 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5735 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5736 | |
| 5737 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5738 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5739 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5740 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5741 | 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] | 5742 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5743 | 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] | 5744 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5745 | 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] | 5746 | |
| 5747 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5748 | |
| 5749 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 5750 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5751 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5752 | if (rg_saw_cnt > 0) { |
| 5753 | u16 sw_cnt_1ms_ini; |
| 5754 | |
| 5755 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5756 | sw_cnt_1ms_ini &= 0x0fff; |
| 5757 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5758 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5759 | data |= sw_cnt_1ms_ini; |
| 5760 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5761 | } |
| 5762 | |
| 5763 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5764 | data &= ~0xf0; |
| 5765 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5766 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5767 | |
| 5768 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5769 | data &= ~0x6000; |
| 5770 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5771 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5772 | |
| 5773 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5774 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5775 | data |= 0x017f; |
| 5776 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5777 | |
| 5778 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 5779 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5780 | data |= 0x047f; |
| 5781 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5782 | |
| 5783 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5784 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5785 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5786 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5787 | |
| 5788 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5789 | } |
| 5790 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5791 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 5792 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 5793 | rtl8168ep_stop_cmac(tp); |
| 5794 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5795 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5796 | |
| 5797 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5798 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 5799 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 5800 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5801 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 5802 | rtl_set_def_aspm_entry_latency(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5803 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5804 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5805 | |
| 5806 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5807 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5808 | |
| 5809 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 5810 | |
| 5811 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5812 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5813 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 5814 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5815 | |
| 5816 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5817 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5818 | |
| 5819 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5820 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5821 | |
| 5822 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5823 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5824 | 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] | 5825 | |
| 5826 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5827 | } |
| 5828 | |
| 5829 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 5830 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5831 | static const struct ephy_info e_info_8168ep_1[] = { |
| 5832 | { 0x00, 0xffff, 0x10ab }, |
| 5833 | { 0x06, 0xffff, 0xf030 }, |
| 5834 | { 0x08, 0xffff, 0x2006 }, |
| 5835 | { 0x0d, 0xffff, 0x1666 }, |
| 5836 | { 0x0c, 0x3ff0, 0x0000 } |
| 5837 | }; |
| 5838 | |
| 5839 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5840 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5841 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 5842 | |
| 5843 | rtl_hw_start_8168ep(tp); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5844 | |
| 5845 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 5849 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5850 | static const struct ephy_info e_info_8168ep_2[] = { |
| 5851 | { 0x00, 0xffff, 0x10a3 }, |
| 5852 | { 0x19, 0xffff, 0xfc00 }, |
| 5853 | { 0x1e, 0xffff, 0x20ea } |
| 5854 | }; |
| 5855 | |
| 5856 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5857 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5858 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 5859 | |
| 5860 | rtl_hw_start_8168ep(tp); |
| 5861 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5862 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5863 | 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] | 5864 | |
| 5865 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 5869 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5870 | u32 data; |
| 5871 | static const struct ephy_info e_info_8168ep_3[] = { |
| 5872 | { 0x00, 0xffff, 0x10a3 }, |
| 5873 | { 0x19, 0xffff, 0x7c00 }, |
| 5874 | { 0x1e, 0xffff, 0x20eb }, |
| 5875 | { 0x0d, 0xffff, 0x1666 } |
| 5876 | }; |
| 5877 | |
| 5878 | /* disable aspm and clock request before access ephy */ |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5879 | rtl_hw_aspm_clkreq_enable(tp, false); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5880 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 5881 | |
| 5882 | rtl_hw_start_8168ep(tp); |
| 5883 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5884 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 5885 | 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] | 5886 | |
| 5887 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 5888 | data &= 0xf000; |
| 5889 | data |= 0x0271; |
| 5890 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 5891 | |
| 5892 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 5893 | data &= 0xff00; |
| 5894 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 5895 | |
| 5896 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 5897 | data |= 0x0080; |
| 5898 | r8168_mac_ocp_write(tp, 0xe860, data); |
Kai-Heng Feng | a99790b | 2018-06-21 16:30:39 +0800 | [diff] [blame] | 5899 | |
| 5900 | rtl_hw_aspm_clkreq_enable(tp, true); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5901 | } |
| 5902 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5903 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5904 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5905 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5906 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 5907 | tp->cp_cmd &= ~INTT_MASK; |
| 5908 | tp->cp_cmd |= PktCntrDisable | INTT_1; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5909 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5910 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5911 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5912 | |
| 5913 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5914 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5915 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5916 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5917 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5918 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5919 | switch (tp->mac_version) { |
| 5920 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5921 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5922 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5923 | |
| 5924 | case RTL_GIGA_MAC_VER_12: |
| 5925 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5926 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5927 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5928 | |
| 5929 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5930 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5931 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5932 | |
| 5933 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5934 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5935 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5936 | |
| 5937 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5938 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5939 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5940 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5941 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5942 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5943 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5944 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5945 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5946 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5947 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5948 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5949 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5950 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5951 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5952 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5953 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5954 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5955 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5956 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5957 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5958 | case RTL_GIGA_MAC_VER_26: |
| 5959 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5960 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5961 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5962 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5963 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5964 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5965 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5966 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5967 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5968 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5969 | break; |
| 5970 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5971 | case RTL_GIGA_MAC_VER_32: |
| 5972 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5973 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5974 | break; |
| 5975 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5976 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5977 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5978 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5979 | case RTL_GIGA_MAC_VER_35: |
| 5980 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5981 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5982 | break; |
| 5983 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5984 | case RTL_GIGA_MAC_VER_38: |
| 5985 | rtl_hw_start_8411(tp); |
| 5986 | break; |
| 5987 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5988 | case RTL_GIGA_MAC_VER_40: |
| 5989 | case RTL_GIGA_MAC_VER_41: |
| 5990 | rtl_hw_start_8168g_1(tp); |
| 5991 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5992 | case RTL_GIGA_MAC_VER_42: |
| 5993 | rtl_hw_start_8168g_2(tp); |
| 5994 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5995 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5996 | case RTL_GIGA_MAC_VER_44: |
| 5997 | rtl_hw_start_8411_2(tp); |
| 5998 | break; |
| 5999 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6000 | case RTL_GIGA_MAC_VER_45: |
| 6001 | case RTL_GIGA_MAC_VER_46: |
| 6002 | rtl_hw_start_8168h_1(tp); |
| 6003 | break; |
| 6004 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6005 | case RTL_GIGA_MAC_VER_49: |
| 6006 | rtl_hw_start_8168ep_1(tp); |
| 6007 | break; |
| 6008 | |
| 6009 | case RTL_GIGA_MAC_VER_50: |
| 6010 | rtl_hw_start_8168ep_2(tp); |
| 6011 | break; |
| 6012 | |
| 6013 | case RTL_GIGA_MAC_VER_51: |
| 6014 | rtl_hw_start_8168ep_3(tp); |
| 6015 | break; |
| 6016 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6017 | default: |
| 6018 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6019 | tp->dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6020 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6021 | } |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6024 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6025 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6026 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6027 | { 0x01, 0, 0x6e65 }, |
| 6028 | { 0x02, 0, 0x091f }, |
| 6029 | { 0x03, 0, 0xc2f9 }, |
| 6030 | { 0x06, 0, 0xafb5 }, |
| 6031 | { 0x07, 0, 0x0e00 }, |
| 6032 | { 0x19, 0, 0xec80 }, |
| 6033 | { 0x01, 0, 0x2e65 }, |
| 6034 | { 0x01, 0, 0x6e65 } |
| 6035 | }; |
| 6036 | u8 cfg1; |
| 6037 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 6038 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6039 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6040 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6041 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6042 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6043 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6044 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6045 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6046 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6047 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6048 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6049 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6050 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6051 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6052 | 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] | 6053 | } |
| 6054 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6055 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6056 | { |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 6057 | rtl_set_def_aspm_entry_latency(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6058 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6059 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6060 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6061 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 6062 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6063 | } |
| 6064 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6065 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6066 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6067 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6068 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6069 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6070 | } |
| 6071 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6072 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6073 | { |
| 6074 | static const struct ephy_info e_info_8105e_1[] = { |
| 6075 | { 0x07, 0, 0x4000 }, |
| 6076 | { 0x19, 0, 0x0200 }, |
| 6077 | { 0x19, 0, 0x0020 }, |
| 6078 | { 0x1e, 0, 0x2000 }, |
| 6079 | { 0x03, 0, 0x0001 }, |
| 6080 | { 0x19, 0, 0x0100 }, |
| 6081 | { 0x19, 0, 0x0004 }, |
| 6082 | { 0x0a, 0, 0x0020 } |
| 6083 | }; |
| 6084 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6085 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6086 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6087 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6088 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6089 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6090 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6091 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6092 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6093 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6094 | 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] | 6095 | |
| 6096 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6097 | } |
| 6098 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6099 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6100 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6101 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6102 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6103 | } |
| 6104 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6105 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 6106 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6107 | static const struct ephy_info e_info_8402[] = { |
| 6108 | { 0x19, 0xffff, 0xff64 }, |
| 6109 | { 0x1e, 0, 0x4000 } |
| 6110 | }; |
| 6111 | |
Heiner Kallweit | f37658d | 2018-06-23 09:51:28 +0200 | [diff] [blame^] | 6112 | rtl_set_def_aspm_entry_latency(tp); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6113 | |
| 6114 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6115 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6116 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6117 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 6118 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6119 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6120 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6121 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6122 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6123 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6124 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6125 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6126 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6127 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6128 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6129 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6130 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6131 | |
| 6132 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6133 | } |
| 6134 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6135 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6136 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6137 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6138 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6139 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6140 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 6141 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6142 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6143 | |
| 6144 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6145 | } |
| 6146 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6147 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6148 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6149 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6150 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6151 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6152 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6153 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6154 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6155 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6156 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6157 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6158 | |
Heiner Kallweit | 12d42c5 | 2018-04-28 22:19:30 +0200 | [diff] [blame] | 6159 | tp->cp_cmd &= CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6160 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6161 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6162 | switch (tp->mac_version) { |
| 6163 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6164 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6165 | break; |
| 6166 | |
| 6167 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6168 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6169 | break; |
| 6170 | |
| 6171 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6172 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6173 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6174 | |
| 6175 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6176 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6177 | break; |
| 6178 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6179 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6180 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6181 | |
| 6182 | case RTL_GIGA_MAC_VER_37: |
| 6183 | rtl_hw_start_8402(tp); |
| 6184 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6185 | |
| 6186 | case RTL_GIGA_MAC_VER_39: |
| 6187 | rtl_hw_start_8106(tp); |
| 6188 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6189 | case RTL_GIGA_MAC_VER_43: |
| 6190 | rtl_hw_start_8168g_2(tp); |
| 6191 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6192 | case RTL_GIGA_MAC_VER_47: |
| 6193 | case RTL_GIGA_MAC_VER_48: |
| 6194 | rtl_hw_start_8168h_1(tp); |
| 6195 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6196 | } |
| 6197 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6198 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6202 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6203 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6204 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6205 | if (new_mtu > ETH_DATA_LEN) |
| 6206 | rtl_hw_jumbo_enable(tp); |
| 6207 | else |
| 6208 | rtl_hw_jumbo_disable(tp); |
| 6209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6211 | netdev_update_features(dev); |
| 6212 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6213 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6217 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6218 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6220 | } |
| 6221 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6222 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6223 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6224 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6225 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 6226 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6227 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6228 | kfree(*data_buff); |
| 6229 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6230 | rtl8169_make_unusable_by_asic(desc); |
| 6231 | } |
| 6232 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6233 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6234 | { |
| 6235 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6236 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6237 | /* Force memory writes to complete before releasing descriptor */ |
| 6238 | dma_wmb(); |
| 6239 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6240 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | } |
| 6242 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6243 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6245 | return (void *)ALIGN((long)data, 16); |
| 6246 | } |
| 6247 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6248 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6249 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6250 | { |
| 6251 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6252 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6253 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 6254 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6256 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6257 | if (!data) |
| 6258 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6259 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6260 | if (rtl8169_align(data) != data) { |
| 6261 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6262 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6263 | if (!data) |
| 6264 | return NULL; |
| 6265 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6266 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6267 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6268 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6269 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6270 | if (net_ratelimit()) |
| 6271 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6272 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6274 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 6275 | desc->addr = cpu_to_le64(mapping); |
| 6276 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6277 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6278 | |
| 6279 | err_out: |
| 6280 | kfree(data); |
| 6281 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6285 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6286 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6287 | |
| 6288 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6289 | if (tp->Rx_databuff[i]) { |
| 6290 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | tp->RxDescArray + i); |
| 6292 | } |
| 6293 | } |
| 6294 | } |
| 6295 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6296 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6297 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6298 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6299 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6300 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6301 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6302 | { |
| 6303 | unsigned int i; |
| 6304 | |
| 6305 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6306 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6307 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6308 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6309 | if (!data) { |
| 6310 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6311 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6312 | } |
| 6313 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6316 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6317 | return 0; |
| 6318 | |
| 6319 | err_out: |
| 6320 | rtl8169_rx_clear(tp); |
| 6321 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | } |
| 6323 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6324 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6325 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6326 | rtl8169_init_ring_indexes(tp); |
| 6327 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6328 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 6329 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6330 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6331 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6332 | } |
| 6333 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6334 | 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] | 6335 | struct TxDesc *desc) |
| 6336 | { |
| 6337 | unsigned int len = tx_skb->len; |
| 6338 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6339 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | desc->opts1 = 0x00; |
| 6342 | desc->opts2 = 0x00; |
| 6343 | desc->addr = 0x00; |
| 6344 | tx_skb->len = 0; |
| 6345 | } |
| 6346 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6347 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6348 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6349 | { |
| 6350 | unsigned int i; |
| 6351 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6352 | for (i = 0; i < n; i++) { |
| 6353 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6354 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6355 | unsigned int len = tx_skb->len; |
| 6356 | |
| 6357 | if (len) { |
| 6358 | struct sk_buff *skb = tx_skb->skb; |
| 6359 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6360 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | tp->TxDescArray + entry); |
| 6362 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6363 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6364 | tx_skb->skb = NULL; |
| 6365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | } |
| 6367 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6371 | { |
| 6372 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6373 | tp->cur_tx = tp->dirty_tx = 0; |
| 6374 | } |
| 6375 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6376 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6378 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6379 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6380 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6381 | napi_disable(&tp->napi); |
| 6382 | netif_stop_queue(dev); |
| 6383 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6385 | rtl8169_hw_reset(tp); |
| 6386 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6387 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6388 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6390 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6391 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6392 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6393 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6394 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6395 | netif_wake_queue(dev); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6396 | rtl8169_check_link_status(dev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | } |
| 6398 | |
| 6399 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6400 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6401 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6402 | |
| 6403 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | 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] | 6407 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6408 | { |
| 6409 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6410 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6411 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6412 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6413 | |
| 6414 | entry = tp->cur_tx; |
| 6415 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6416 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6417 | dma_addr_t mapping; |
| 6418 | u32 status, len; |
| 6419 | void *addr; |
| 6420 | |
| 6421 | entry = (entry + 1) % NUM_TX_DESC; |
| 6422 | |
| 6423 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6424 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6425 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6426 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6427 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6428 | if (net_ratelimit()) |
| 6429 | netif_err(tp, drv, tp->dev, |
| 6430 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6431 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6433 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6434 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6435 | status = opts[0] | len | |
| 6436 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6437 | |
| 6438 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6439 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6440 | txd->addr = cpu_to_le64(mapping); |
| 6441 | |
| 6442 | tp->tx_skb[entry].len = len; |
| 6443 | } |
| 6444 | |
| 6445 | if (cur_frag) { |
| 6446 | tp->tx_skb[entry].skb = skb; |
| 6447 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6448 | } |
| 6449 | |
| 6450 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6451 | |
| 6452 | err_out: |
| 6453 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6454 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6455 | } |
| 6456 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6457 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6458 | { |
| 6459 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6460 | } |
| 6461 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6462 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6463 | struct net_device *dev); |
| 6464 | /* r8169_csum_workaround() |
| 6465 | * The hw limites the value the transport offset. When the offset is out of the |
| 6466 | * range, calculate the checksum by sw. |
| 6467 | */ |
| 6468 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6469 | struct sk_buff *skb) |
| 6470 | { |
| 6471 | if (skb_shinfo(skb)->gso_size) { |
| 6472 | netdev_features_t features = tp->dev->features; |
| 6473 | struct sk_buff *segs, *nskb; |
| 6474 | |
| 6475 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6476 | segs = skb_gso_segment(skb, features); |
| 6477 | if (IS_ERR(segs) || !segs) |
| 6478 | goto drop; |
| 6479 | |
| 6480 | do { |
| 6481 | nskb = segs; |
| 6482 | segs = segs->next; |
| 6483 | nskb->next = NULL; |
| 6484 | rtl8169_start_xmit(nskb, tp->dev); |
| 6485 | } while (segs); |
| 6486 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6487 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6488 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6489 | if (skb_checksum_help(skb) < 0) |
| 6490 | goto drop; |
| 6491 | |
| 6492 | rtl8169_start_xmit(skb, tp->dev); |
| 6493 | } else { |
| 6494 | struct net_device_stats *stats; |
| 6495 | |
| 6496 | drop: |
| 6497 | stats = &tp->dev->stats; |
| 6498 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6499 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6500 | } |
| 6501 | } |
| 6502 | |
| 6503 | /* msdn_giant_send_check() |
| 6504 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6505 | * packet length for IPv6 TCP large packets. |
| 6506 | */ |
| 6507 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6508 | { |
| 6509 | const struct ipv6hdr *ipv6h; |
| 6510 | struct tcphdr *th; |
| 6511 | int ret; |
| 6512 | |
| 6513 | ret = skb_cow_head(skb, 0); |
| 6514 | if (ret) |
| 6515 | return ret; |
| 6516 | |
| 6517 | ipv6h = ipv6_hdr(skb); |
| 6518 | th = tcp_hdr(skb); |
| 6519 | |
| 6520 | th->check = 0; |
| 6521 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6522 | |
| 6523 | return ret; |
| 6524 | } |
| 6525 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6526 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6527 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6528 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6529 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6530 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6531 | if (mss) { |
| 6532 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6533 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6534 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6535 | const struct iphdr *ip = ip_hdr(skb); |
| 6536 | |
| 6537 | if (ip->protocol == IPPROTO_TCP) |
| 6538 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6539 | else if (ip->protocol == IPPROTO_UDP) |
| 6540 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6541 | else |
| 6542 | WARN_ON_ONCE(1); |
| 6543 | } |
| 6544 | |
| 6545 | return true; |
| 6546 | } |
| 6547 | |
| 6548 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6549 | struct sk_buff *skb, u32 *opts) |
| 6550 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6551 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6552 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6553 | |
| 6554 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6555 | if (transport_offset > GTTCPHO_MAX) { |
| 6556 | netif_warn(tp, tx_err, tp->dev, |
| 6557 | "Invalid transport offset 0x%x for TSO\n", |
| 6558 | transport_offset); |
| 6559 | return false; |
| 6560 | } |
| 6561 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6562 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6563 | case htons(ETH_P_IP): |
| 6564 | opts[0] |= TD1_GTSENV4; |
| 6565 | break; |
| 6566 | |
| 6567 | case htons(ETH_P_IPV6): |
| 6568 | if (msdn_giant_send_check(skb)) |
| 6569 | return false; |
| 6570 | |
| 6571 | opts[0] |= TD1_GTSENV6; |
| 6572 | break; |
| 6573 | |
| 6574 | default: |
| 6575 | WARN_ON_ONCE(1); |
| 6576 | break; |
| 6577 | } |
| 6578 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6579 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6580 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6581 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6582 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6583 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6584 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6585 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6586 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6587 | if (transport_offset > TCPHO_MAX) { |
| 6588 | netif_warn(tp, tx_err, tp->dev, |
| 6589 | "Invalid transport offset 0x%x\n", |
| 6590 | transport_offset); |
| 6591 | return false; |
| 6592 | } |
| 6593 | |
Heiner Kallweit | 4ff3646 | 2018-05-02 21:40:02 +0200 | [diff] [blame] | 6594 | switch (vlan_get_protocol(skb)) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6595 | case htons(ETH_P_IP): |
| 6596 | opts[1] |= TD1_IPv4_CS; |
| 6597 | ip_protocol = ip_hdr(skb)->protocol; |
| 6598 | break; |
| 6599 | |
| 6600 | case htons(ETH_P_IPV6): |
| 6601 | opts[1] |= TD1_IPv6_CS; |
| 6602 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6603 | break; |
| 6604 | |
| 6605 | default: |
| 6606 | ip_protocol = IPPROTO_RAW; |
| 6607 | break; |
| 6608 | } |
| 6609 | |
| 6610 | if (ip_protocol == IPPROTO_TCP) |
| 6611 | opts[1] |= TD1_TCP_CS; |
| 6612 | else if (ip_protocol == IPPROTO_UDP) |
| 6613 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6614 | else |
| 6615 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6616 | |
| 6617 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6618 | } else { |
| 6619 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 6620 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6621 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6622 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6623 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6624 | } |
| 6625 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6626 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6627 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6628 | { |
| 6629 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6630 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6631 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6632 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6633 | dma_addr_t mapping; |
| 6634 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6635 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6636 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6637 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6638 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6639 | 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] | 6640 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6644 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6646 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6647 | opts[0] = DescOwn; |
| 6648 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6649 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6650 | r8169_csum_workaround(tp, skb); |
| 6651 | return NETDEV_TX_OK; |
| 6652 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6653 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6654 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6655 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6656 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6657 | if (net_ratelimit()) |
| 6658 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6659 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6661 | |
| 6662 | tp->tx_skb[entry].len = len; |
| 6663 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6664 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6665 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6666 | if (frags < 0) |
| 6667 | goto err_dma_1; |
| 6668 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6669 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6670 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6671 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6672 | tp->tx_skb[entry].skb = skb; |
| 6673 | } |
| 6674 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6675 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6676 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6677 | skb_tx_timestamp(skb); |
| 6678 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6679 | /* Force memory writes to complete before releasing descriptor */ |
| 6680 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6681 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6682 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6683 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6684 | txd->opts1 = cpu_to_le32(status); |
| 6685 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6686 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6687 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6688 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6689 | tp->cur_tx += frags + 1; |
| 6690 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6691 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6692 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6693 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6694 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6695 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6696 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6697 | * not miss a ring update when it notices a stopped queue. |
| 6698 | */ |
| 6699 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6701 | /* Sync with rtl_tx: |
| 6702 | * - publish queue status and cur_tx ring index (write barrier) |
| 6703 | * - refresh dirty_tx ring index (read barrier). |
| 6704 | * May the current thread have a pessimistic view of the ring |
| 6705 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6706 | * can't. |
| 6707 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6708 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6709 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6710 | netif_wake_queue(dev); |
| 6711 | } |
| 6712 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6713 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6714 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6715 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6716 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6717 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6718 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6719 | dev->stats.tx_dropped++; |
| 6720 | return NETDEV_TX_OK; |
| 6721 | |
| 6722 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6724 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6725 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6729 | { |
| 6730 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6731 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6732 | u16 pci_status, pci_cmd; |
| 6733 | |
| 6734 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6735 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6736 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6737 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6738 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | |
| 6740 | /* |
| 6741 | * The recovery sequence below admits a very elaborated explanation: |
| 6742 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6743 | * - I did not see what else could be done; |
| 6744 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | * |
| 6746 | * Feel free to adjust to your needs. |
| 6747 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6748 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6749 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6750 | else |
| 6751 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6752 | |
| 6753 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6754 | |
| 6755 | pci_write_config_word(pdev, PCI_STATUS, |
| 6756 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6757 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6758 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6759 | |
| 6760 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6761 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6762 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6763 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6764 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6765 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6768 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6769 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6770 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6771 | } |
| 6772 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6773 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6774 | { |
| 6775 | unsigned int dirty_tx, tx_left; |
| 6776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6777 | dirty_tx = tp->dirty_tx; |
| 6778 | smp_rmb(); |
| 6779 | tx_left = tp->cur_tx - dirty_tx; |
| 6780 | |
| 6781 | while (tx_left > 0) { |
| 6782 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6783 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6784 | u32 status; |
| 6785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6787 | if (status & DescOwn) |
| 6788 | break; |
| 6789 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6790 | /* This barrier is needed to keep us from reading |
| 6791 | * any other fields out of the Tx descriptor until |
| 6792 | * we know the status of DescOwn |
| 6793 | */ |
| 6794 | dma_rmb(); |
| 6795 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6796 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6797 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6798 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 6799 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6800 | tp->tx_stats.packets++; |
| 6801 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 6802 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6803 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6804 | tx_skb->skb = NULL; |
| 6805 | } |
| 6806 | dirty_tx++; |
| 6807 | tx_left--; |
| 6808 | } |
| 6809 | |
| 6810 | if (tp->dirty_tx != dirty_tx) { |
| 6811 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6812 | /* Sync with rtl8169_start_xmit: |
| 6813 | * - publish dirty_tx ring index (write barrier) |
| 6814 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6815 | * May the current thread miss the stopped queue condition, |
| 6816 | * a racing xmit thread can only have a right view of the |
| 6817 | * ring status. |
| 6818 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6819 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6821 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6822 | netif_wake_queue(dev); |
| 6823 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6824 | /* |
| 6825 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6826 | * too close. Let's kick an extra TxPoll request when a burst |
| 6827 | * of start_xmit activity is detected (if it is not detected, |
| 6828 | * it is slow enough). -- FR |
| 6829 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6830 | if (tp->cur_tx != dirty_tx) |
| 6831 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6832 | } |
| 6833 | } |
| 6834 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6835 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6836 | { |
| 6837 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6838 | } |
| 6839 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6840 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6841 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6842 | u32 status = opts1 & RxProtoMask; |
| 6843 | |
| 6844 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6845 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6846 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6847 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6848 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6849 | } |
| 6850 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6851 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6852 | struct rtl8169_private *tp, |
| 6853 | int pkt_size, |
| 6854 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6855 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6856 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6857 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6858 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6859 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6860 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6861 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 6862 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6863 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 6864 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6865 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6866 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6867 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6868 | } |
| 6869 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6870 | 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] | 6871 | { |
| 6872 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6873 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6876 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6877 | 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] | 6878 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6879 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6880 | u32 status; |
| 6881 | |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6882 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6883 | if (status & DescOwn) |
| 6884 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6885 | |
| 6886 | /* This barrier is needed to keep us from reading |
| 6887 | * any other fields out of the Rx descriptor until |
| 6888 | * we know the status of DescOwn |
| 6889 | */ |
| 6890 | dma_rmb(); |
| 6891 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6892 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6893 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6894 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6895 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6896 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6897 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6898 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6899 | dev->stats.rx_crc_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6900 | /* RxFOVF is a reserved bit on later chip versions */ |
| 6901 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 && |
| 6902 | status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6903 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6904 | dev->stats.rx_fifo_errors++; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6905 | } else if (status & (RxRUNT | RxCRC) && |
| 6906 | !(status & RxRWT) && |
| 6907 | dev->features & NETIF_F_RXALL) { |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6908 | goto process_pkt; |
Heiner Kallweit | 6202806 | 2018-04-17 23:30:29 +0200 | [diff] [blame] | 6909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6910 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6911 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6912 | dma_addr_t addr; |
| 6913 | int pkt_size; |
| 6914 | |
| 6915 | process_pkt: |
| 6916 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6917 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6918 | pkt_size = (status & 0x00003fff) - 4; |
| 6919 | else |
| 6920 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6921 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6922 | /* |
| 6923 | * The driver does not support incoming fragmented |
| 6924 | * frames. They are seen as a symptom of over-mtu |
| 6925 | * sized frames. |
| 6926 | */ |
| 6927 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6928 | dev->stats.rx_dropped++; |
| 6929 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6930 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6931 | } |
| 6932 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6933 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6934 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6935 | if (!skb) { |
| 6936 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6937 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6938 | } |
| 6939 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6940 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6941 | skb_put(skb, pkt_size); |
| 6942 | skb->protocol = eth_type_trans(skb, dev); |
| 6943 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6944 | rtl8169_rx_vlan_tag(desc, skb); |
| 6945 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 6946 | if (skb->pkt_type == PACKET_MULTICAST) |
| 6947 | dev->stats.multicast++; |
| 6948 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6949 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6950 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6951 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6952 | tp->rx_stats.packets++; |
| 6953 | tp->rx_stats.bytes += pkt_size; |
| 6954 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6955 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6956 | release_descriptor: |
| 6957 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6958 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | count = cur_rx - tp->cur_rx; |
| 6962 | tp->cur_rx = cur_rx; |
| 6963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6964 | return count; |
| 6965 | } |
| 6966 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6967 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6968 | { |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 6969 | struct rtl8169_private *tp = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6970 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6971 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6972 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6973 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6974 | if (status && status != 0xffff) { |
| 6975 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 6976 | if (status) { |
| 6977 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6978 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6979 | rtl_irq_disable(tp); |
Heiner Kallweit | 9a899a3 | 2018-04-17 23:21:01 +0200 | [diff] [blame] | 6980 | napi_schedule_irqoff(&tp->napi); |
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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6983 | return IRQ_RETVAL(handled); |
| 6984 | } |
| 6985 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6986 | /* |
| 6987 | * Workqueue context. |
| 6988 | */ |
| 6989 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6990 | { |
| 6991 | struct net_device *dev = tp->dev; |
| 6992 | u16 status; |
| 6993 | |
| 6994 | status = rtl_get_events(tp) & tp->event_slow; |
| 6995 | rtl_ack_events(tp, status); |
| 6996 | |
| 6997 | if (unlikely(status & RxFIFOOver)) { |
| 6998 | switch (tp->mac_version) { |
| 6999 | /* Work around for rx fifo overflow */ |
| 7000 | case RTL_GIGA_MAC_VER_11: |
| 7001 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7002 | /* XXX - Hack alert. See rtl_task(). */ |
| 7003 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7004 | default: |
| 7005 | break; |
| 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | if (unlikely(status & SYSErr)) |
| 7010 | rtl8169_pcierr_interrupt(dev); |
| 7011 | |
| 7012 | if (status & LinkChg) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7013 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7014 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 7015 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7016 | } |
| 7017 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7018 | static void rtl_task(struct work_struct *work) |
| 7019 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7020 | static const struct { |
| 7021 | int bitnr; |
| 7022 | void (*action)(struct rtl8169_private *); |
| 7023 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7024 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7025 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 7026 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 7027 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 7028 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7029 | struct rtl8169_private *tp = |
| 7030 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7031 | struct net_device *dev = tp->dev; |
| 7032 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7033 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7034 | rtl_lock_work(tp); |
| 7035 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7036 | if (!netif_running(dev) || |
| 7037 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7038 | goto out_unlock; |
| 7039 | |
| 7040 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 7041 | bool pending; |
| 7042 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7043 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7044 | if (pending) |
| 7045 | rtl_work[i].action(tp); |
| 7046 | } |
| 7047 | |
| 7048 | out_unlock: |
| 7049 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7050 | } |
| 7051 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7052 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7053 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7054 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 7055 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7056 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 7057 | int work_done= 0; |
| 7058 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7059 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7060 | status = rtl_get_events(tp); |
| 7061 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 7062 | |
| 7063 | if (status & RTL_EVENT_NAPI_RX) |
| 7064 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7065 | |
| 7066 | if (status & RTL_EVENT_NAPI_TX) |
| 7067 | rtl_tx(dev, tp); |
| 7068 | |
| 7069 | if (status & tp->event_slow) { |
| 7070 | enable_mask &= ~tp->event_slow; |
| 7071 | |
| 7072 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7074 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7075 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 7076 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7077 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7078 | rtl_irq_enable(tp, enable_mask); |
| 7079 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7080 | } |
| 7081 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7082 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7084 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7085 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7086 | { |
| 7087 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7088 | |
| 7089 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7090 | return; |
| 7091 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7092 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 7093 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7094 | } |
| 7095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7096 | static void rtl8169_down(struct net_device *dev) |
| 7097 | { |
| 7098 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7099 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7100 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7101 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7102 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7103 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7104 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7105 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7106 | /* |
| 7107 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7108 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7109 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7110 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7111 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7113 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7114 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7116 | rtl8169_tx_clear(tp); |
| 7117 | |
| 7118 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7119 | |
| 7120 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7121 | } |
| 7122 | |
| 7123 | static int rtl8169_close(struct net_device *dev) |
| 7124 | { |
| 7125 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7126 | struct pci_dev *pdev = tp->pci_dev; |
| 7127 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7128 | pm_runtime_get_sync(&pdev->dev); |
| 7129 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7130 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7131 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7132 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7133 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7134 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7136 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7137 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7138 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7139 | cancel_work_sync(&tp->wk.work); |
| 7140 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7141 | pci_free_irq(pdev, 0, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7142 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7143 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7144 | tp->RxPhyAddr); |
| 7145 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7146 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7147 | tp->TxDescArray = NULL; |
| 7148 | tp->RxDescArray = NULL; |
| 7149 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7150 | pm_runtime_put_sync(&pdev->dev); |
| 7151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7152 | return 0; |
| 7153 | } |
| 7154 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7155 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7156 | static void rtl8169_netpoll(struct net_device *dev) |
| 7157 | { |
| 7158 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7159 | |
Ville Syrjälä | 6d8b834 | 2018-06-20 15:01:53 +0300 | [diff] [blame] | 7160 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), tp); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7161 | } |
| 7162 | #endif |
| 7163 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7164 | static int rtl_open(struct net_device *dev) |
| 7165 | { |
| 7166 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7167 | struct pci_dev *pdev = tp->pci_dev; |
| 7168 | int retval = -ENOMEM; |
| 7169 | |
| 7170 | pm_runtime_get_sync(&pdev->dev); |
| 7171 | |
| 7172 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7173 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7174 | * dma_alloc_coherent provides more. |
| 7175 | */ |
| 7176 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7177 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7178 | if (!tp->TxDescArray) |
| 7179 | goto err_pm_runtime_put; |
| 7180 | |
| 7181 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7182 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7183 | if (!tp->RxDescArray) |
| 7184 | goto err_free_tx_0; |
| 7185 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 7186 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7187 | if (retval < 0) |
| 7188 | goto err_free_rx_1; |
| 7189 | |
| 7190 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7191 | |
| 7192 | smp_mb(); |
| 7193 | |
| 7194 | rtl_request_firmware(tp); |
| 7195 | |
Heiner Kallweit | ebcd5da | 2018-04-17 23:29:20 +0200 | [diff] [blame] | 7196 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, tp, |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7197 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7198 | if (retval < 0) |
| 7199 | goto err_release_fw_2; |
| 7200 | |
| 7201 | rtl_lock_work(tp); |
| 7202 | |
| 7203 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7204 | |
| 7205 | napi_enable(&tp->napi); |
| 7206 | |
| 7207 | rtl8169_init_phy(dev, tp); |
| 7208 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7209 | rtl_pll_power_up(tp); |
| 7210 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7211 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7212 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7213 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7214 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7215 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7216 | netif_start_queue(dev); |
| 7217 | |
| 7218 | rtl_unlock_work(tp); |
| 7219 | |
| 7220 | tp->saved_wolopts = 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7221 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7222 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7223 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7224 | out: |
| 7225 | return retval; |
| 7226 | |
| 7227 | err_release_fw_2: |
| 7228 | rtl_release_firmware(tp); |
| 7229 | rtl8169_rx_clear(tp); |
| 7230 | err_free_rx_1: |
| 7231 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7232 | tp->RxPhyAddr); |
| 7233 | tp->RxDescArray = NULL; |
| 7234 | err_free_tx_0: |
| 7235 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7236 | tp->TxPhyAddr); |
| 7237 | tp->TxDescArray = NULL; |
| 7238 | err_pm_runtime_put: |
| 7239 | pm_runtime_put_noidle(&pdev->dev); |
| 7240 | goto out; |
| 7241 | } |
| 7242 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7243 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7244 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7245 | { |
| 7246 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7247 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7248 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7249 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7250 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7251 | pm_runtime_get_noresume(&pdev->dev); |
| 7252 | |
| 7253 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7254 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7255 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7256 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7257 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7258 | stats->rx_packets = tp->rx_stats.packets; |
| 7259 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7260 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7261 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7262 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7263 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7264 | stats->tx_packets = tp->tx_stats.packets; |
| 7265 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7266 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7267 | |
| 7268 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7269 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7270 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7271 | stats->rx_errors = dev->stats.rx_errors; |
| 7272 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7273 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7274 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7275 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7276 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7277 | /* |
| 7278 | * Fetch additonal counter values missing in stats collected by driver |
| 7279 | * from tally counters. |
| 7280 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7281 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7282 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7283 | |
| 7284 | /* |
| 7285 | * Subtract values fetched during initalization. |
| 7286 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 7287 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7288 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7289 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7290 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7291 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7292 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7293 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 7294 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7295 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | } |
| 7297 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7298 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7299 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7300 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7301 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7302 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7303 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7304 | |
| 7305 | netif_device_detach(dev); |
| 7306 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7307 | |
| 7308 | rtl_lock_work(tp); |
| 7309 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7310 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7311 | rtl_unlock_work(tp); |
| 7312 | |
| 7313 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7314 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7315 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7316 | #ifdef CONFIG_PM |
| 7317 | |
| 7318 | static int rtl8169_suspend(struct device *device) |
| 7319 | { |
| 7320 | struct pci_dev *pdev = to_pci_dev(device); |
| 7321 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7322 | |
| 7323 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 7324 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7325 | return 0; |
| 7326 | } |
| 7327 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7328 | static void __rtl8169_resume(struct net_device *dev) |
| 7329 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7330 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7331 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7332 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7333 | |
| 7334 | rtl_pll_power_up(tp); |
| 7335 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7336 | rtl_lock_work(tp); |
| 7337 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7338 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7339 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7340 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7341 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7342 | } |
| 7343 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7344 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7345 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7346 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7347 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7348 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7349 | |
| 7350 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7351 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7352 | if (netif_running(dev)) |
| 7353 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7354 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7355 | return 0; |
| 7356 | } |
| 7357 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7358 | static int rtl8169_runtime_suspend(struct device *device) |
| 7359 | { |
| 7360 | struct pci_dev *pdev = to_pci_dev(device); |
| 7361 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7362 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7363 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7364 | if (!tp->TxDescArray) { |
| 7365 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7366 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7367 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7368 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7369 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7370 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 7371 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7372 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7373 | |
| 7374 | rtl8169_net_suspend(dev); |
| 7375 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7376 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7377 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame] | 7378 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7379 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7380 | return 0; |
| 7381 | } |
| 7382 | |
| 7383 | static int rtl8169_runtime_resume(struct device *device) |
| 7384 | { |
| 7385 | struct pci_dev *pdev = to_pci_dev(device); |
| 7386 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7387 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 7388 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7389 | |
| 7390 | if (!tp->TxDescArray) |
| 7391 | return 0; |
| 7392 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7393 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7394 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 7395 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7396 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7397 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7398 | rtl8169_init_phy(dev, tp); |
| 7399 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7400 | __rtl8169_resume(dev); |
| 7401 | |
| 7402 | return 0; |
| 7403 | } |
| 7404 | |
| 7405 | static int rtl8169_runtime_idle(struct device *device) |
| 7406 | { |
| 7407 | struct pci_dev *pdev = to_pci_dev(device); |
| 7408 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7409 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7410 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 7411 | pm_schedule_suspend(device, 10000); |
| 7412 | |
| 7413 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7416 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7417 | .suspend = rtl8169_suspend, |
| 7418 | .resume = rtl8169_resume, |
| 7419 | .freeze = rtl8169_suspend, |
| 7420 | .thaw = rtl8169_resume, |
| 7421 | .poweroff = rtl8169_suspend, |
| 7422 | .restore = rtl8169_resume, |
| 7423 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7424 | .runtime_resume = rtl8169_runtime_resume, |
| 7425 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7426 | }; |
| 7427 | |
| 7428 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7429 | |
| 7430 | #else /* !CONFIG_PM */ |
| 7431 | |
| 7432 | #define RTL8169_PM_OPS NULL |
| 7433 | |
| 7434 | #endif /* !CONFIG_PM */ |
| 7435 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7436 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7437 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7438 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7439 | switch (tp->mac_version) { |
| 7440 | case RTL_GIGA_MAC_VER_11: |
| 7441 | case RTL_GIGA_MAC_VER_12: |
| 7442 | case RTL_GIGA_MAC_VER_17: |
| 7443 | pci_clear_master(tp->pci_dev); |
| 7444 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7445 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7446 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7447 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7448 | break; |
| 7449 | default: |
| 7450 | break; |
| 7451 | } |
| 7452 | } |
| 7453 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7454 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7455 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7456 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7457 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7458 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7459 | rtl8169_net_suspend(dev); |
| 7460 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7461 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7462 | rtl_rar_set(tp, dev->perm_addr); |
| 7463 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7464 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7465 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7466 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7467 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 7468 | rtl_wol_suspend_quirk(tp); |
| 7469 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7470 | } |
| 7471 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7472 | pci_wake_from_d3(pdev, true); |
| 7473 | pci_set_power_state(pdev, PCI_D3hot); |
| 7474 | } |
| 7475 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7476 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7477 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7478 | { |
| 7479 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7480 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7481 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7482 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7483 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7484 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7485 | netif_napi_del(&tp->napi); |
| 7486 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7487 | unregister_netdev(dev); |
| 7488 | |
| 7489 | rtl_release_firmware(tp); |
| 7490 | |
| 7491 | if (pci_dev_run_wake(pdev)) |
| 7492 | pm_runtime_get_noresume(&pdev->dev); |
| 7493 | |
| 7494 | /* restore original MAC address */ |
| 7495 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7496 | } |
| 7497 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7498 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7499 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7500 | .ndo_stop = rtl8169_close, |
| 7501 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7502 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7503 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7504 | .ndo_validate_addr = eth_validate_addr, |
| 7505 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7506 | .ndo_fix_features = rtl8169_fix_features, |
| 7507 | .ndo_set_features = rtl8169_set_features, |
| 7508 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7509 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7510 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7511 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7512 | .ndo_poll_controller = rtl8169_netpoll, |
| 7513 | #endif |
| 7514 | |
| 7515 | }; |
| 7516 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7517 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7518 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7519 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7520 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7521 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7522 | u8 default_ver; |
| 7523 | } rtl_cfg_infos [] = { |
| 7524 | [RTL_CFG_0] = { |
| 7525 | .hw_start = rtl_hw_start_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7526 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7527 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7528 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7529 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7530 | }, |
| 7531 | [RTL_CFG_1] = { |
| 7532 | .hw_start = rtl_hw_start_8168, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7533 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7534 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7535 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7536 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7537 | }, |
| 7538 | [RTL_CFG_2] = { |
| 7539 | .hw_start = rtl_hw_start_8101, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7540 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7541 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7542 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7543 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7544 | } |
| 7545 | }; |
| 7546 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7547 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7548 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7549 | unsigned int flags; |
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 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7552 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 7553 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 7554 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7555 | flags = PCI_IRQ_LEGACY; |
| 7556 | } else { |
| 7557 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7558 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7559 | |
| 7560 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7561 | } |
| 7562 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7563 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7564 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7565 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7569 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7570 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7571 | } |
| 7572 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7573 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7574 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7575 | u32 data; |
| 7576 | |
| 7577 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7578 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7579 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7580 | |
| 7581 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7582 | return; |
| 7583 | |
| 7584 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7585 | return; |
| 7586 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7587 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7588 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7589 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7590 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7591 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7592 | data &= ~(1 << 14); |
| 7593 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7594 | |
| 7595 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7596 | return; |
| 7597 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7598 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7599 | data |= (1 << 15); |
| 7600 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7601 | |
| 7602 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7603 | return; |
| 7604 | } |
| 7605 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7606 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 7607 | { |
| 7608 | rtl8168ep_stop_cmac(tp); |
| 7609 | rtl_hw_init_8168g(tp); |
| 7610 | } |
| 7611 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7612 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7613 | { |
| 7614 | switch (tp->mac_version) { |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7615 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7616 | rtl_hw_init_8168g(tp); |
| 7617 | break; |
Heiner Kallweit | 2a71883 | 2018-05-02 21:39:49 +0200 | [diff] [blame] | 7618 | case RTL_GIGA_MAC_VER_49 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 7619 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7620 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7621 | default: |
| 7622 | break; |
| 7623 | } |
| 7624 | } |
| 7625 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7626 | 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] | 7627 | { |
| 7628 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7629 | struct rtl8169_private *tp; |
| 7630 | struct mii_if_info *mii; |
| 7631 | struct net_device *dev; |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7632 | int chipset, region, i; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7633 | int rc; |
| 7634 | |
| 7635 | if (netif_msg_drv(&debug)) { |
| 7636 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 7637 | MODULENAME, RTL8169_VERSION); |
| 7638 | } |
| 7639 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7640 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 7641 | if (!dev) |
| 7642 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7643 | |
| 7644 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7645 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7646 | tp = netdev_priv(dev); |
| 7647 | tp->dev = dev; |
| 7648 | tp->pci_dev = pdev; |
| 7649 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 7650 | |
| 7651 | mii = &tp->mii; |
| 7652 | mii->dev = dev; |
| 7653 | mii->mdio_read = rtl_mdio_read; |
| 7654 | mii->mdio_write = rtl_mdio_write; |
| 7655 | mii->phy_id_mask = 0x1f; |
| 7656 | mii->reg_num_mask = 0x1f; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7657 | mii->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7658 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7659 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7660 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7661 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7662 | dev_err(&pdev->dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7663 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7664 | } |
| 7665 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7666 | if (pcim_set_mwi(pdev) < 0) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7667 | dev_info(&pdev->dev, "Mem-Wr-Inval unavailable\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7668 | |
Heiner Kallweit | c8d48d9 | 2018-04-17 23:34:22 +0200 | [diff] [blame] | 7669 | /* use first MMIO region */ |
| 7670 | region = ffs(pci_select_bars(pdev, IORESOURCE_MEM)) - 1; |
| 7671 | if (region < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7672 | dev_err(&pdev->dev, "no MMIO resource found\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7673 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7674 | } |
| 7675 | |
| 7676 | /* check for weird/broken PCI region reporting */ |
| 7677 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7678 | dev_err(&pdev->dev, "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7679 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7680 | } |
| 7681 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7682 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7683 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7684 | dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7685 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7686 | } |
| 7687 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 7688 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7689 | |
| 7690 | if (!pci_is_pcie(pdev)) |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7691 | dev_info(&pdev->dev, "not PCI Express\n"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7692 | |
| 7693 | /* Identify chip attached to board */ |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7694 | rtl8169_get_mac_version(tp, cfg->default_ver); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7695 | |
Heiner Kallweit | 0ae0974 | 2018-04-28 22:19:26 +0200 | [diff] [blame] | 7696 | tp->cp_cmd = RTL_R16(tp, CPlusCmd); |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7697 | |
| 7698 | if ((sizeof(dma_addr_t) > 4) && |
| 7699 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 7700 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 7701 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 7702 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7703 | |
| 7704 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 7705 | if (!pci_is_pcie(pdev)) |
| 7706 | tp->cp_cmd |= PCIDAC; |
| 7707 | dev->features |= NETIF_F_HIGHDMA; |
| 7708 | } else { |
| 7709 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7710 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7711 | dev_err(&pdev->dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7712 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 7713 | } |
| 7714 | } |
| 7715 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7716 | rtl_init_rxcfg(tp); |
| 7717 | |
| 7718 | rtl_irq_disable(tp); |
| 7719 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7720 | rtl_hw_initialize(tp); |
| 7721 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7722 | rtl_hw_reset(tp); |
| 7723 | |
| 7724 | rtl_ack_events(tp, 0xffff); |
| 7725 | |
| 7726 | pci_set_master(pdev); |
| 7727 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7728 | rtl_init_mdio_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7729 | rtl_init_jumbo_ops(tp); |
| 7730 | |
| 7731 | rtl8169_print_mac_version(tp); |
| 7732 | |
| 7733 | chipset = tp->mac_version; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7734 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7735 | rc = rtl_alloc_irq(tp); |
| 7736 | if (rc < 0) { |
Heiner Kallweit | 22148df | 2018-04-22 17:15:15 +0200 | [diff] [blame] | 7737 | dev_err(&pdev->dev, "Can't allocate interrupt\n"); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7738 | return rc; |
| 7739 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7740 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 7741 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 7742 | __rtl8169_set_wol(tp, 0); |
| 7743 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7744 | if (rtl_tbi_enabled(tp)) { |
| 7745 | tp->set_speed = rtl8169_set_speed_tbi; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 7746 | tp->get_link_ksettings = rtl8169_get_link_ksettings_tbi; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7747 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 7748 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 7749 | tp->link_ok = rtl8169_tbi_link_ok; |
| 7750 | tp->do_ioctl = rtl_tbi_ioctl; |
| 7751 | } else { |
| 7752 | tp->set_speed = rtl8169_set_speed_xmii; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 7753 | tp->get_link_ksettings = rtl8169_get_link_ksettings_xmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7754 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 7755 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 7756 | tp->link_ok = rtl8169_xmii_link_ok; |
| 7757 | tp->do_ioctl = rtl_xmii_ioctl; |
| 7758 | } |
| 7759 | |
| 7760 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7761 | u64_stats_init(&tp->rx_stats.syncp); |
| 7762 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7763 | |
| 7764 | /* Get MAC address */ |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7765 | switch (tp->mac_version) { |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7766 | u8 mac_addr[ETH_ALEN] __aligned(4); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7767 | case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38: |
| 7768 | case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7769 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7770 | *(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7771 | |
Heiner Kallweit | 353af85 | 2018-05-02 21:39:59 +0200 | [diff] [blame] | 7772 | if (is_valid_ether_addr(mac_addr)) |
| 7773 | rtl_rar_set(tp, mac_addr); |
Heiner Kallweit | b2d43e6 | 2018-05-02 21:39:52 +0200 | [diff] [blame] | 7774 | break; |
| 7775 | default: |
| 7776 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7777 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7778 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7779 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7780 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7781 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7782 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7783 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 7784 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7785 | |
| 7786 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7787 | * properly for all devices */ |
| 7788 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7789 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7790 | |
| 7791 | 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] | 7792 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7793 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7794 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7795 | NETIF_F_HIGHDMA; |
| 7796 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7797 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7798 | |
| 7799 | /* |
| 7800 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7801 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7802 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7803 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7804 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7805 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7806 | |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7807 | switch (rtl_chip_infos[chipset].txd_version) { |
| 7808 | case RTL_TD_0: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7809 | tp->tso_csum = rtl8169_tso_csum_v1; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7810 | break; |
| 7811 | case RTL_TD_1: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7812 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7813 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7814 | break; |
| 7815 | default: |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7816 | WARN_ON_ONCE(1); |
Heiner Kallweit | a4328dd | 2018-04-17 23:33:03 +0200 | [diff] [blame] | 7817 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7818 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7819 | dev->hw_features |= NETIF_F_RXALL; |
| 7820 | dev->hw_features |= NETIF_F_RXFCS; |
| 7821 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 7822 | /* MTU range: 60 - hw-specific max */ |
| 7823 | dev->min_mtu = ETH_ZLEN; |
| 7824 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 7825 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7826 | tp->hw_start = cfg->hw_start; |
| 7827 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7828 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7829 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 7830 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7831 | |
| 7832 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7833 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7834 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 7835 | &tp->counters_phys_addr, |
| 7836 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7837 | if (!tp->counters) |
| 7838 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7839 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 7840 | pci_set_drvdata(pdev, dev); |
| 7841 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7842 | rc = register_netdev(dev); |
| 7843 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 7844 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7845 | |
Heiner Kallweit | 2d6c5a6 | 2018-04-17 23:31:21 +0200 | [diff] [blame] | 7846 | netif_info(tp, probe, dev, "%s, %pM, XID %08x, IRQ %d\n", |
| 7847 | rtl_chip_infos[chipset].name, dev->dev_addr, |
Heiner Kallweit | 90b989c | 2018-04-17 23:32:15 +0200 | [diff] [blame] | 7848 | (u32)(RTL_R32(tp, TxConfig) & 0xfcf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7849 | pci_irq_vector(pdev, 0)); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7850 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 7851 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 7852 | "tx checksumming: %s]\n", |
| 7853 | rtl_chip_infos[chipset].jumbo_max, |
Heiner Kallweit | 6ed0e08 | 2018-04-17 23:36:12 +0200 | [diff] [blame] | 7854 | tp->mac_version <= RTL_GIGA_MAC_VER_06 ? "ok" : "ko"); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7855 | } |
| 7856 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7857 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7858 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7859 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7860 | netif_carrier_off(dev); |
| 7861 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7862 | if (pci_dev_run_wake(pdev)) |
| 7863 | pm_runtime_put_sync(&pdev->dev); |
| 7864 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 7865 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7866 | } |
| 7867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7868 | static struct pci_driver rtl8169_pci_driver = { |
| 7869 | .name = MODULENAME, |
| 7870 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7871 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7872 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7873 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7874 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7875 | }; |
| 7876 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7877 | module_pci_driver(rtl8169_pci_driver); |