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> |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 28 | #include <linux/pci-aspm.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 29 | #include <linux/prefetch.h> |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 30 | #include <linux/ipv6.h> |
| 31 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/irq.h> |
| 35 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 36 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define MODULENAME "r8169" |
| 38 | #define PFX MODULENAME ": " |
| 39 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 40 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 41 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 42 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 43 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 46 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 50 | #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 51 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 52 | #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 53 | #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 54 | #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 55 | #define FIRMWARE_8168H_1 "rtl_nic/rtl8168h-1.fw" |
| 56 | #define FIRMWARE_8168H_2 "rtl_nic/rtl8168h-2.fw" |
| 57 | #define FIRMWARE_8107E_1 "rtl_nic/rtl8107e-1.fw" |
| 58 | #define FIRMWARE_8107E_2 "rtl_nic/rtl8107e-2.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #ifdef RTL8169_DEBUG |
| 61 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 62 | if (!(expr)) { \ |
| 63 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 64 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 65 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 66 | #define dprintk(fmt, args...) \ |
| 67 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #else |
| 69 | #define assert(expr) do {} while (0) |
| 70 | #define dprintk(fmt, args...) do {} while (0) |
| 71 | #endif /* RTL8169_DEBUG */ |
| 72 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 73 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 74 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 75 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 76 | #define TX_SLOTS_AVAIL(tp) \ |
| 77 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 78 | |
| 79 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 80 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 81 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 84 | 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] | 85 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 87 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 89 | |
| 90 | #define R8169_REGS_SIZE 256 |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 91 | #define R8169_RX_BUF_SIZE (SZ_16K - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 93 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 95 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 96 | |
| 97 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 98 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 99 | |
| 100 | /* write/read MMIO register */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 101 | #define RTL_W8(tp, reg, val8) writeb((val8), tp->mmio_addr + (reg)) |
| 102 | #define RTL_W16(tp, reg, val16) writew((val16), tp->mmio_addr + (reg)) |
| 103 | #define RTL_W32(tp, reg, val32) writel((val32), tp->mmio_addr + (reg)) |
| 104 | #define RTL_R8(tp, reg) readb(tp->mmio_addr + (reg)) |
| 105 | #define RTL_R16(tp, reg) readw(tp->mmio_addr + (reg)) |
| 106 | #define RTL_R32(tp, reg) readl(tp->mmio_addr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 109 | RTL_GIGA_MAC_VER_01 = 0, |
| 110 | RTL_GIGA_MAC_VER_02, |
| 111 | RTL_GIGA_MAC_VER_03, |
| 112 | RTL_GIGA_MAC_VER_04, |
| 113 | RTL_GIGA_MAC_VER_05, |
| 114 | RTL_GIGA_MAC_VER_06, |
| 115 | RTL_GIGA_MAC_VER_07, |
| 116 | RTL_GIGA_MAC_VER_08, |
| 117 | RTL_GIGA_MAC_VER_09, |
| 118 | RTL_GIGA_MAC_VER_10, |
| 119 | RTL_GIGA_MAC_VER_11, |
| 120 | RTL_GIGA_MAC_VER_12, |
| 121 | RTL_GIGA_MAC_VER_13, |
| 122 | RTL_GIGA_MAC_VER_14, |
| 123 | RTL_GIGA_MAC_VER_15, |
| 124 | RTL_GIGA_MAC_VER_16, |
| 125 | RTL_GIGA_MAC_VER_17, |
| 126 | RTL_GIGA_MAC_VER_18, |
| 127 | RTL_GIGA_MAC_VER_19, |
| 128 | RTL_GIGA_MAC_VER_20, |
| 129 | RTL_GIGA_MAC_VER_21, |
| 130 | RTL_GIGA_MAC_VER_22, |
| 131 | RTL_GIGA_MAC_VER_23, |
| 132 | RTL_GIGA_MAC_VER_24, |
| 133 | RTL_GIGA_MAC_VER_25, |
| 134 | RTL_GIGA_MAC_VER_26, |
| 135 | RTL_GIGA_MAC_VER_27, |
| 136 | RTL_GIGA_MAC_VER_28, |
| 137 | RTL_GIGA_MAC_VER_29, |
| 138 | RTL_GIGA_MAC_VER_30, |
| 139 | RTL_GIGA_MAC_VER_31, |
| 140 | RTL_GIGA_MAC_VER_32, |
| 141 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 142 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 143 | RTL_GIGA_MAC_VER_35, |
| 144 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 145 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 146 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 147 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 148 | RTL_GIGA_MAC_VER_40, |
| 149 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 150 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 151 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 152 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 153 | RTL_GIGA_MAC_VER_45, |
| 154 | RTL_GIGA_MAC_VER_46, |
| 155 | RTL_GIGA_MAC_VER_47, |
| 156 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 157 | RTL_GIGA_MAC_VER_49, |
| 158 | RTL_GIGA_MAC_VER_50, |
| 159 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 160 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 163 | enum rtl_tx_desc_version { |
| 164 | RTL_TD_0 = 0, |
| 165 | RTL_TD_1 = 1, |
| 166 | }; |
| 167 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 168 | #define JUMBO_1K ETH_DATA_LEN |
| 169 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 170 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 171 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 172 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 173 | |
| 174 | #define _R(NAME,TD,FW,SZ,B) { \ |
| 175 | .name = NAME, \ |
| 176 | .txd_version = TD, \ |
| 177 | .fw_name = FW, \ |
| 178 | .jumbo_max = SZ, \ |
| 179 | .jumbo_tx_csum = B \ |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 182 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 184 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 185 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 186 | u16 jumbo_max; |
| 187 | bool jumbo_tx_csum; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 188 | } rtl_chip_infos[] = { |
| 189 | /* PCI devices. */ |
| 190 | [RTL_GIGA_MAC_VER_01] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 191 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 192 | [RTL_GIGA_MAC_VER_02] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 193 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 194 | [RTL_GIGA_MAC_VER_03] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 195 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_04] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 197 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 198 | [RTL_GIGA_MAC_VER_05] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 199 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 200 | [RTL_GIGA_MAC_VER_06] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 201 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 202 | /* PCI-E devices. */ |
| 203 | [RTL_GIGA_MAC_VER_07] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 204 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 205 | [RTL_GIGA_MAC_VER_08] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 206 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 207 | [RTL_GIGA_MAC_VER_09] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 208 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 209 | [RTL_GIGA_MAC_VER_10] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 210 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 211 | [RTL_GIGA_MAC_VER_11] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 212 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 213 | [RTL_GIGA_MAC_VER_12] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 214 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 215 | [RTL_GIGA_MAC_VER_13] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 216 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 217 | [RTL_GIGA_MAC_VER_14] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 218 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 219 | [RTL_GIGA_MAC_VER_15] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 220 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 221 | [RTL_GIGA_MAC_VER_16] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 222 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 223 | [RTL_GIGA_MAC_VER_17] = |
hayeswang | f75761b | 2014-03-11 15:11:59 +0800 | [diff] [blame] | 224 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 225 | [RTL_GIGA_MAC_VER_18] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 226 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 227 | [RTL_GIGA_MAC_VER_19] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 228 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 229 | [RTL_GIGA_MAC_VER_20] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 230 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 231 | [RTL_GIGA_MAC_VER_21] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 232 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 233 | [RTL_GIGA_MAC_VER_22] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 234 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 235 | [RTL_GIGA_MAC_VER_23] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 236 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 237 | [RTL_GIGA_MAC_VER_24] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 238 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 239 | [RTL_GIGA_MAC_VER_25] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 240 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
| 241 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 242 | [RTL_GIGA_MAC_VER_26] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 243 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
| 244 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 245 | [RTL_GIGA_MAC_VER_27] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 246 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 247 | [RTL_GIGA_MAC_VER_28] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 248 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 249 | [RTL_GIGA_MAC_VER_29] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 250 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 251 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 252 | [RTL_GIGA_MAC_VER_30] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 253 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 254 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 255 | [RTL_GIGA_MAC_VER_31] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 256 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 257 | [RTL_GIGA_MAC_VER_32] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 258 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
| 259 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 260 | [RTL_GIGA_MAC_VER_33] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 261 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
| 262 | JUMBO_9K, false), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 263 | [RTL_GIGA_MAC_VER_34] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 264 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
| 265 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 266 | [RTL_GIGA_MAC_VER_35] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 267 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
| 268 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 269 | [RTL_GIGA_MAC_VER_36] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 270 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
| 271 | JUMBO_9K, false), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 272 | [RTL_GIGA_MAC_VER_37] = |
| 273 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, |
| 274 | JUMBO_1K, true), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 275 | [RTL_GIGA_MAC_VER_38] = |
| 276 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, |
| 277 | JUMBO_9K, false), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 278 | [RTL_GIGA_MAC_VER_39] = |
| 279 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, |
| 280 | JUMBO_1K, true), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 281 | [RTL_GIGA_MAC_VER_40] = |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 282 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 283 | JUMBO_9K, false), |
| 284 | [RTL_GIGA_MAC_VER_41] = |
| 285 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K, false), |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 286 | [RTL_GIGA_MAC_VER_42] = |
| 287 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, |
| 288 | JUMBO_9K, false), |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 289 | [RTL_GIGA_MAC_VER_43] = |
| 290 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, |
| 291 | JUMBO_1K, true), |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 292 | [RTL_GIGA_MAC_VER_44] = |
| 293 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, |
| 294 | JUMBO_9K, false), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 295 | [RTL_GIGA_MAC_VER_45] = |
| 296 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, |
| 297 | JUMBO_9K, false), |
| 298 | [RTL_GIGA_MAC_VER_46] = |
| 299 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, |
| 300 | JUMBO_9K, false), |
| 301 | [RTL_GIGA_MAC_VER_47] = |
| 302 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, |
| 303 | JUMBO_1K, false), |
| 304 | [RTL_GIGA_MAC_VER_48] = |
| 305 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, |
| 306 | JUMBO_1K, false), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 307 | [RTL_GIGA_MAC_VER_49] = |
| 308 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 309 | JUMBO_9K, false), |
| 310 | [RTL_GIGA_MAC_VER_50] = |
| 311 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 312 | JUMBO_9K, false), |
| 313 | [RTL_GIGA_MAC_VER_51] = |
| 314 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 315 | JUMBO_9K, false), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | }; |
| 317 | #undef _R |
| 318 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 319 | enum cfg_version { |
| 320 | RTL_CFG_0 = 0x00, |
| 321 | RTL_CFG_1, |
| 322 | RTL_CFG_2 |
| 323 | }; |
| 324 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 325 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 326 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 327 | { 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] | 328 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 329 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 330 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 331 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 332 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 333 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 334 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 335 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 336 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 337 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 338 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 339 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 340 | { 0x0001, 0x8168, |
| 341 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | {0,}, |
| 343 | }; |
| 344 | |
| 345 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 346 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 347 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 348 | static struct { |
| 349 | u32 msg_enable; |
| 350 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 352 | enum rtl_registers { |
| 353 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 354 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 355 | MAR0 = 8, /* Multicast filter. */ |
| 356 | CounterAddrLow = 0x10, |
| 357 | CounterAddrHigh = 0x14, |
| 358 | TxDescStartAddrLow = 0x20, |
| 359 | TxDescStartAddrHigh = 0x24, |
| 360 | TxHDescStartAddrLow = 0x28, |
| 361 | TxHDescStartAddrHigh = 0x2c, |
| 362 | FLASH = 0x30, |
| 363 | ERSR = 0x36, |
| 364 | ChipCmd = 0x37, |
| 365 | TxPoll = 0x38, |
| 366 | IntrMask = 0x3c, |
| 367 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 368 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 369 | TxConfig = 0x40, |
| 370 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 371 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 372 | |
| 373 | RxConfig = 0x44, |
| 374 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 375 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 376 | #define RXCFG_FIFO_SHIFT 13 |
| 377 | /* No threshold before first PCI xfer */ |
| 378 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 379 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 380 | #define RXCFG_DMA_SHIFT 8 |
| 381 | /* Unlimited maximum PCI burst. */ |
| 382 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 383 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 384 | RxMissed = 0x4c, |
| 385 | Cfg9346 = 0x50, |
| 386 | Config0 = 0x51, |
| 387 | Config1 = 0x52, |
| 388 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 389 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 390 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 391 | Config3 = 0x54, |
| 392 | Config4 = 0x55, |
| 393 | Config5 = 0x56, |
| 394 | MultiIntr = 0x5c, |
| 395 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 396 | PHYstatus = 0x6c, |
| 397 | RxMaxSize = 0xda, |
| 398 | CPlusCmd = 0xe0, |
| 399 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 400 | |
| 401 | #define RTL_COALESCE_MASK 0x0f |
| 402 | #define RTL_COALESCE_SHIFT 4 |
| 403 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 404 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 405 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 406 | RxDescAddrLow = 0xe4, |
| 407 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 408 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 409 | |
| 410 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 411 | |
| 412 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 413 | |
| 414 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 415 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 416 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 417 | FuncEvent = 0xf0, |
| 418 | FuncEventMask = 0xf4, |
| 419 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 420 | IBCR0 = 0xf8, |
| 421 | IBCR2 = 0xf9, |
| 422 | IBIMR0 = 0xfa, |
| 423 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 424 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | }; |
| 426 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 427 | enum rtl8110_registers { |
| 428 | TBICSR = 0x64, |
| 429 | TBI_ANAR = 0x68, |
| 430 | TBI_LPAR = 0x6a, |
| 431 | }; |
| 432 | |
| 433 | enum rtl8168_8101_registers { |
| 434 | CSIDR = 0x64, |
| 435 | CSIAR = 0x68, |
| 436 | #define CSIAR_FLAG 0x80000000 |
| 437 | #define CSIAR_WRITE_CMD 0x80000000 |
| 438 | #define CSIAR_BYTE_ENABLE 0x0f |
| 439 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 440 | #define CSIAR_ADDR_MASK 0x0fff |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 441 | #define CSIAR_FUNC_CARD 0x00000000 |
| 442 | #define CSIAR_FUNC_SDIO 0x00010000 |
| 443 | #define CSIAR_FUNC_NIC 0x00020000 |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 444 | #define CSIAR_FUNC_NIC2 0x00010000 |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 445 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 446 | EPHYAR = 0x80, |
| 447 | #define EPHYAR_FLAG 0x80000000 |
| 448 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 449 | #define EPHYAR_REG_MASK 0x1f |
| 450 | #define EPHYAR_REG_SHIFT 16 |
| 451 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 452 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 453 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 454 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 455 | DBG_REG = 0xd1, |
| 456 | #define FIX_NAK_1 (1 << 4) |
| 457 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 458 | TWSI = 0xd2, |
| 459 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 460 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 461 | #define TX_EMPTY (1 << 5) |
| 462 | #define RX_EMPTY (1 << 4) |
| 463 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 464 | #define EN_NDP (1 << 3) |
| 465 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 466 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 467 | EFUSEAR = 0xdc, |
| 468 | #define EFUSEAR_FLAG 0x80000000 |
| 469 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 470 | #define EFUSEAR_READ_CMD 0x00000000 |
| 471 | #define EFUSEAR_REG_MASK 0x03ff |
| 472 | #define EFUSEAR_REG_SHIFT 8 |
| 473 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 474 | MISC_1 = 0xf2, |
| 475 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 476 | }; |
| 477 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 478 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 479 | LED_FREQ = 0x1a, |
| 480 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 481 | ERIDR = 0x70, |
| 482 | ERIAR = 0x74, |
| 483 | #define ERIAR_FLAG 0x80000000 |
| 484 | #define ERIAR_WRITE_CMD 0x80000000 |
| 485 | #define ERIAR_READ_CMD 0x00000000 |
| 486 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 487 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 488 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 489 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 490 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 491 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 492 | #define ERIAR_MASK_SHIFT 12 |
| 493 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 494 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 495 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 496 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 497 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 498 | EPHY_RXER_NUM = 0x7c, |
| 499 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 500 | #define OCPDR_WRITE_CMD 0x80000000 |
| 501 | #define OCPDR_READ_CMD 0x00000000 |
| 502 | #define OCPDR_REG_MASK 0x7f |
| 503 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 504 | #define OCPDR_DATA_MASK 0xffff |
| 505 | OCPAR = 0xb4, |
| 506 | #define OCPAR_FLAG 0x80000000 |
| 507 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 508 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 509 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 510 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 511 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 512 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 513 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 514 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 515 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 516 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 517 | }; |
| 518 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 519 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 521 | SYSErr = 0x8000, |
| 522 | PCSTimeout = 0x4000, |
| 523 | SWInt = 0x0100, |
| 524 | TxDescUnavail = 0x0080, |
| 525 | RxFIFOOver = 0x0040, |
| 526 | LinkChg = 0x0020, |
| 527 | RxOverflow = 0x0010, |
| 528 | TxErr = 0x0008, |
| 529 | TxOK = 0x0004, |
| 530 | RxErr = 0x0002, |
| 531 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 534 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 535 | RxFOVF = (1 << 23), |
| 536 | RxRWT = (1 << 22), |
| 537 | RxRES = (1 << 21), |
| 538 | RxRUNT = (1 << 20), |
| 539 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 542 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 543 | CmdReset = 0x10, |
| 544 | CmdRxEnb = 0x08, |
| 545 | CmdTxEnb = 0x04, |
| 546 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 548 | /* TXPoll register p.5 */ |
| 549 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 550 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 551 | FSWInt = 0x01, /* Forced software interrupt */ |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 554 | Cfg9346_Lock = 0x00, |
| 555 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 558 | AcceptErr = 0x20, |
| 559 | AcceptRunt = 0x10, |
| 560 | AcceptBroadcast = 0x08, |
| 561 | AcceptMulticast = 0x04, |
| 562 | AcceptMyPhys = 0x02, |
| 563 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 564 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* TxConfigBits */ |
| 567 | TxInterFrameGapShift = 24, |
| 568 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 569 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 570 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 571 | LEDS1 = (1 << 7), |
| 572 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 573 | Speed_down = (1 << 4), |
| 574 | MEMMAP = (1 << 3), |
| 575 | IOMAP = (1 << 2), |
| 576 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 577 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 578 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 579 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 580 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 581 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 582 | PCI_Clock_66MHz = 0x01, |
| 583 | PCI_Clock_33MHz = 0x00, |
| 584 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 585 | /* Config3 register p.25 */ |
| 586 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 587 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 588 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 589 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 590 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 591 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 592 | /* Config4 register */ |
| 593 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 594 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 595 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 596 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 597 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 598 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 599 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 600 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 601 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 602 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | /* TBICSR p.28 */ |
| 605 | TBIReset = 0x80000000, |
| 606 | TBILoopback = 0x40000000, |
| 607 | TBINwEnable = 0x20000000, |
| 608 | TBINwRestart = 0x10000000, |
| 609 | TBILinkOk = 0x02000000, |
| 610 | TBINwComplete = 0x01000000, |
| 611 | |
| 612 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 613 | EnableBist = (1 << 15), // 8168 8101 |
| 614 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 615 | Normal_mode = (1 << 13), // unused |
| 616 | Force_half_dup = (1 << 12), // 8168 8101 |
| 617 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 618 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 619 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 620 | ASF = (1 << 8), // 8168 8101 |
| 621 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 622 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | RxVlan = (1 << 6), |
| 624 | RxChkSum = (1 << 5), |
| 625 | PCIDAC = (1 << 4), |
| 626 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 627 | INTT_0 = 0x0000, // 8168 |
| 628 | INTT_1 = 0x0001, // 8168 |
| 629 | INTT_2 = 0x0002, // 8168 |
| 630 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
| 632 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 633 | TBI_Enable = 0x80, |
| 634 | TxFlowCtrl = 0x40, |
| 635 | RxFlowCtrl = 0x20, |
| 636 | _1000bpsF = 0x10, |
| 637 | _100bps = 0x08, |
| 638 | _10bps = 0x04, |
| 639 | LinkStatus = 0x02, |
| 640 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 643 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 644 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 645 | /* ResetCounterCommand */ |
| 646 | CounterReset = 0x1, |
| 647 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 648 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 649 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 650 | |
| 651 | /* magic enable v2 */ |
| 652 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | }; |
| 654 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 655 | enum rtl_desc_bit { |
| 656 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 658 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 659 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 660 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 661 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 663 | /* Generic case. */ |
| 664 | enum rtl_tx_desc_bit { |
| 665 | /* First doubleword. */ |
| 666 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 667 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 669 | /* Second doubleword. */ |
| 670 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 671 | }; |
| 672 | |
| 673 | /* 8169, 8168b and 810x except 8102e. */ |
| 674 | enum rtl_tx_desc_bit_0 { |
| 675 | /* First doubleword. */ |
| 676 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 677 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 678 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 679 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 680 | }; |
| 681 | |
| 682 | /* 8102e, 8168c and beyond. */ |
| 683 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 684 | /* First doubleword. */ |
| 685 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 686 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 687 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 688 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 689 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 690 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 691 | #define TCPHO_SHIFT 18 |
| 692 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 693 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 694 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 695 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 696 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 697 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 698 | }; |
| 699 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 700 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | /* Rx private */ |
| 702 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 703 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | #define RxProtoUDP (PID1) |
| 706 | #define RxProtoTCP (PID0) |
| 707 | #define RxProtoIP (PID1 | PID0) |
| 708 | #define RxProtoMask RxProtoIP |
| 709 | |
| 710 | IPFail = (1 << 16), /* IP checksum failed */ |
| 711 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 712 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 713 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 714 | }; |
| 715 | |
| 716 | #define RsvdMask 0x3fffc000 |
| 717 | |
| 718 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 719 | __le32 opts1; |
| 720 | __le32 opts2; |
| 721 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | }; |
| 723 | |
| 724 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 725 | __le32 opts1; |
| 726 | __le32 opts2; |
| 727 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | }; |
| 729 | |
| 730 | struct ring_info { |
| 731 | struct sk_buff *skb; |
| 732 | u32 len; |
| 733 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 734 | }; |
| 735 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 736 | struct rtl8169_counters { |
| 737 | __le64 tx_packets; |
| 738 | __le64 rx_packets; |
| 739 | __le64 tx_errors; |
| 740 | __le32 rx_errors; |
| 741 | __le16 rx_missed; |
| 742 | __le16 align_errors; |
| 743 | __le32 tx_one_collision; |
| 744 | __le32 tx_multi_collision; |
| 745 | __le64 rx_unicast; |
| 746 | __le64 rx_broadcast; |
| 747 | __le32 rx_multicast; |
| 748 | __le16 tx_aborted; |
| 749 | __le16 tx_underun; |
| 750 | }; |
| 751 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 752 | struct rtl8169_tc_offsets { |
| 753 | bool inited; |
| 754 | __le64 tx_errors; |
| 755 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 756 | __le16 tx_aborted; |
| 757 | }; |
| 758 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 759 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 760 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 761 | RTL_FLAG_TASK_SLOW_PENDING, |
| 762 | RTL_FLAG_TASK_RESET_PENDING, |
| 763 | RTL_FLAG_TASK_PHY_PENDING, |
| 764 | RTL_FLAG_MAX |
| 765 | }; |
| 766 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 767 | struct rtl8169_stats { |
| 768 | u64 packets; |
| 769 | u64 bytes; |
| 770 | struct u64_stats_sync syncp; |
| 771 | }; |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | struct rtl8169_private { |
| 774 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 775 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 776 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 777 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 778 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 779 | u16 txd_version; |
| 780 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 782 | 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] | 783 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 784 | struct rtl8169_stats rx_stats; |
| 785 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 787 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 788 | dma_addr_t TxPhyAddr; |
| 789 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 790 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | struct timer_list timer; |
| 793 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 794 | |
| 795 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 796 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 797 | |
| 798 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 799 | void (*write)(struct rtl8169_private *, int, int); |
| 800 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 801 | } mdio_ops; |
| 802 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 803 | struct pll_power_ops { |
| 804 | void (*down)(struct rtl8169_private *); |
| 805 | void (*up)(struct rtl8169_private *); |
| 806 | } pll_power_ops; |
| 807 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 808 | struct jumbo_ops { |
| 809 | void (*enable)(struct rtl8169_private *); |
| 810 | void (*disable)(struct rtl8169_private *); |
| 811 | } jumbo_ops; |
| 812 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 813 | struct csi_ops { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 814 | void (*write)(struct rtl8169_private *, int, int); |
| 815 | u32 (*read)(struct rtl8169_private *, int); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 816 | } csi_ops; |
| 817 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 818 | 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] | 819 | int (*get_link_ksettings)(struct net_device *, |
| 820 | struct ethtool_link_ksettings *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 821 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 822 | void (*hw_start)(struct rtl8169_private *tp); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 823 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 824 | unsigned int (*link_ok)(struct rtl8169_private *tp); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 825 | 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] | 826 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 827 | |
| 828 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 829 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 830 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 831 | struct work_struct work; |
| 832 | } wk; |
| 833 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 834 | struct mii_if_info mii; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 835 | dma_addr_t counters_phys_addr; |
| 836 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 837 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 838 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 839 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 840 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 841 | struct rtl_fw { |
| 842 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 843 | |
| 844 | #define RTL_VER_SIZE 32 |
| 845 | |
| 846 | char version[RTL_VER_SIZE]; |
| 847 | |
| 848 | struct rtl_fw_phy_action { |
| 849 | __le32 *code; |
| 850 | size_t size; |
| 851 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 852 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 853 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 854 | |
| 855 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | }; |
| 857 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 858 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 861 | 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] | 862 | module_param_named(debug, debug.msg_enable, int, 0); |
| 863 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | MODULE_LICENSE("GPL"); |
| 865 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 866 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 867 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 868 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 869 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 870 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 871 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 872 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 873 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 874 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 875 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 876 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 877 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 878 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 879 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 880 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 881 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 882 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 883 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 884 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 886 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 887 | { |
| 888 | return &tp->pci_dev->dev; |
| 889 | } |
| 890 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 891 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 892 | { |
| 893 | mutex_lock(&tp->wk.mutex); |
| 894 | } |
| 895 | |
| 896 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 897 | { |
| 898 | mutex_unlock(&tp->wk.mutex); |
| 899 | } |
| 900 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 901 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 902 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 903 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 904 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 905 | } |
| 906 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 907 | struct rtl_cond { |
| 908 | bool (*check)(struct rtl8169_private *); |
| 909 | const char *msg; |
| 910 | }; |
| 911 | |
| 912 | static void rtl_udelay(unsigned int d) |
| 913 | { |
| 914 | udelay(d); |
| 915 | } |
| 916 | |
| 917 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 918 | void (*delay)(unsigned int), unsigned int d, int n, |
| 919 | bool high) |
| 920 | { |
| 921 | int i; |
| 922 | |
| 923 | for (i = 0; i < n; i++) { |
| 924 | delay(d); |
| 925 | if (c->check(tp) == high) |
| 926 | return true; |
| 927 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 928 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 929 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 930 | return false; |
| 931 | } |
| 932 | |
| 933 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 934 | const struct rtl_cond *c, |
| 935 | unsigned int d, int n) |
| 936 | { |
| 937 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 938 | } |
| 939 | |
| 940 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 941 | const struct rtl_cond *c, |
| 942 | unsigned int d, int n) |
| 943 | { |
| 944 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 945 | } |
| 946 | |
| 947 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 948 | const struct rtl_cond *c, |
| 949 | unsigned int d, int n) |
| 950 | { |
| 951 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 952 | } |
| 953 | |
| 954 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 955 | const struct rtl_cond *c, |
| 956 | unsigned int d, int n) |
| 957 | { |
| 958 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 959 | } |
| 960 | |
| 961 | #define DECLARE_RTL_COND(name) \ |
| 962 | static bool name ## _check(struct rtl8169_private *); \ |
| 963 | \ |
| 964 | static const struct rtl_cond name = { \ |
| 965 | .check = name ## _check, \ |
| 966 | .msg = #name \ |
| 967 | }; \ |
| 968 | \ |
| 969 | static bool name ## _check(struct rtl8169_private *tp) |
| 970 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 971 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 972 | { |
| 973 | if (reg & 0xffff0001) { |
| 974 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 975 | return true; |
| 976 | } |
| 977 | return false; |
| 978 | } |
| 979 | |
| 980 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 981 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 982 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 986 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 987 | if (rtl_ocp_reg_failure(tp, reg)) |
| 988 | return; |
| 989 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 990 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 991 | |
| 992 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 993 | } |
| 994 | |
| 995 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 996 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 997 | if (rtl_ocp_reg_failure(tp, reg)) |
| 998 | return 0; |
| 999 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1000 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1001 | |
| 1002 | 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] | 1003 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1004 | } |
| 1005 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1006 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1007 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1008 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1009 | return; |
| 1010 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1011 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1015 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1016 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1017 | return 0; |
| 1018 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1019 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1020 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1021 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | #define OCP_STD_PHY_BASE 0xa400 |
| 1025 | |
| 1026 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 1027 | { |
| 1028 | if (reg == 0x1f) { |
| 1029 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1034 | reg -= 0x10; |
| 1035 | |
| 1036 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 1037 | } |
| 1038 | |
| 1039 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 1040 | { |
| 1041 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1042 | reg -= 0x10; |
| 1043 | |
| 1044 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1045 | } |
| 1046 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 1047 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 1048 | { |
| 1049 | if (reg == 0x1f) { |
| 1050 | tp->ocp_base = value << 4; |
| 1051 | return; |
| 1052 | } |
| 1053 | |
| 1054 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 1055 | } |
| 1056 | |
| 1057 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 1058 | { |
| 1059 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 1060 | } |
| 1061 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1062 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1063 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1064 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1067 | 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] | 1068 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1069 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1071 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1072 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1073 | * According to hardware specs a 20us delay is required after write |
| 1074 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1075 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1076 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1079 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1081 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1083 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1085 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1086 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1087 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1088 | /* |
| 1089 | * According to hardware specs a 20us delay is required after read |
| 1090 | * complete indication, but before sending next command. |
| 1091 | */ |
| 1092 | udelay(20); |
| 1093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | return value; |
| 1095 | } |
| 1096 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1097 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 1098 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1099 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1100 | } |
| 1101 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1102 | 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] | 1103 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1104 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 1105 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1106 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1107 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1108 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1111 | 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] | 1112 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1113 | r8168dp_1_mdio_access(tp, reg, |
| 1114 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1117 | 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] | 1118 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1119 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1120 | |
| 1121 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1122 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 1123 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1124 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1125 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1126 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1129 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1130 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1131 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1132 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1133 | 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] | 1134 | } |
| 1135 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1136 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1137 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1138 | 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] | 1139 | } |
| 1140 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1141 | 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] | 1142 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1143 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1144 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1145 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1146 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1147 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1150 | 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] | 1151 | { |
| 1152 | int value; |
| 1153 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1154 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1155 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1156 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1157 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1158 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1159 | |
| 1160 | return value; |
| 1161 | } |
| 1162 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1163 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1164 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1165 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1168 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1169 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1170 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1174 | { |
| 1175 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1176 | } |
| 1177 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1178 | 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] | 1179 | { |
| 1180 | int val; |
| 1181 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1182 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1183 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1186 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1187 | int val) |
| 1188 | { |
| 1189 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1190 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1191 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1195 | { |
| 1196 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1197 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1198 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1201 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1202 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1203 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1206 | 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] | 1207 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1208 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1209 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1210 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1211 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1212 | |
| 1213 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1216 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1217 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1218 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1219 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1220 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1221 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1222 | } |
| 1223 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1224 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1225 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1226 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1229 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1230 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1231 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1232 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1233 | RTL_W32(tp, ERIDR, val); |
| 1234 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1235 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1236 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1237 | } |
| 1238 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1239 | 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] | 1240 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1241 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1242 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1243 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1244 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1247 | 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] | 1248 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1249 | { |
| 1250 | u32 val; |
| 1251 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1252 | val = rtl_eri_read(tp, addr, type); |
| 1253 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1254 | } |
| 1255 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1256 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1257 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1258 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1259 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1260 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1264 | { |
| 1265 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1266 | } |
| 1267 | |
| 1268 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1269 | { |
| 1270 | switch (tp->mac_version) { |
| 1271 | case RTL_GIGA_MAC_VER_27: |
| 1272 | case RTL_GIGA_MAC_VER_28: |
| 1273 | case RTL_GIGA_MAC_VER_31: |
| 1274 | return r8168dp_ocp_read(tp, mask, reg); |
| 1275 | case RTL_GIGA_MAC_VER_49: |
| 1276 | case RTL_GIGA_MAC_VER_50: |
| 1277 | case RTL_GIGA_MAC_VER_51: |
| 1278 | return r8168ep_ocp_read(tp, mask, reg); |
| 1279 | default: |
| 1280 | BUG(); |
| 1281 | return ~0; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1286 | u32 data) |
| 1287 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1288 | RTL_W32(tp, OCPDR, data); |
| 1289 | 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] | 1290 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1291 | } |
| 1292 | |
| 1293 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1294 | u32 data) |
| 1295 | { |
| 1296 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1297 | data, ERIAR_OOB); |
| 1298 | } |
| 1299 | |
| 1300 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1301 | { |
| 1302 | switch (tp->mac_version) { |
| 1303 | case RTL_GIGA_MAC_VER_27: |
| 1304 | case RTL_GIGA_MAC_VER_28: |
| 1305 | case RTL_GIGA_MAC_VER_31: |
| 1306 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1307 | break; |
| 1308 | case RTL_GIGA_MAC_VER_49: |
| 1309 | case RTL_GIGA_MAC_VER_50: |
| 1310 | case RTL_GIGA_MAC_VER_51: |
| 1311 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1312 | break; |
| 1313 | default: |
| 1314 | BUG(); |
| 1315 | break; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1319 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1320 | { |
| 1321 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1322 | |
| 1323 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1324 | } |
| 1325 | |
| 1326 | #define OOB_CMD_RESET 0x00 |
| 1327 | #define OOB_CMD_DRIVER_START 0x05 |
| 1328 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1329 | |
| 1330 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1331 | { |
| 1332 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1333 | } |
| 1334 | |
| 1335 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1336 | { |
| 1337 | u16 reg; |
| 1338 | |
| 1339 | reg = rtl8168_get_ocp_reg(tp); |
| 1340 | |
| 1341 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1342 | } |
| 1343 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1344 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1345 | { |
| 1346 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1347 | } |
| 1348 | |
| 1349 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1350 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1351 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1352 | } |
| 1353 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1354 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1355 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1356 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1357 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1358 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1359 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1360 | } |
| 1361 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1362 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1363 | { |
| 1364 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1365 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1366 | } |
| 1367 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1368 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1369 | { |
| 1370 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1371 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1372 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1373 | } |
| 1374 | |
| 1375 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1376 | { |
| 1377 | switch (tp->mac_version) { |
| 1378 | case RTL_GIGA_MAC_VER_27: |
| 1379 | case RTL_GIGA_MAC_VER_28: |
| 1380 | case RTL_GIGA_MAC_VER_31: |
| 1381 | rtl8168dp_driver_start(tp); |
| 1382 | break; |
| 1383 | case RTL_GIGA_MAC_VER_49: |
| 1384 | case RTL_GIGA_MAC_VER_50: |
| 1385 | case RTL_GIGA_MAC_VER_51: |
| 1386 | rtl8168ep_driver_start(tp); |
| 1387 | break; |
| 1388 | default: |
| 1389 | BUG(); |
| 1390 | break; |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1395 | { |
| 1396 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1397 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1398 | } |
| 1399 | |
| 1400 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1401 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1402 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1403 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1404 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1405 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1406 | } |
| 1407 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1408 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1409 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1410 | switch (tp->mac_version) { |
| 1411 | case RTL_GIGA_MAC_VER_27: |
| 1412 | case RTL_GIGA_MAC_VER_28: |
| 1413 | case RTL_GIGA_MAC_VER_31: |
| 1414 | rtl8168dp_driver_stop(tp); |
| 1415 | break; |
| 1416 | case RTL_GIGA_MAC_VER_49: |
| 1417 | case RTL_GIGA_MAC_VER_50: |
| 1418 | case RTL_GIGA_MAC_VER_51: |
| 1419 | rtl8168ep_driver_stop(tp); |
| 1420 | break; |
| 1421 | default: |
| 1422 | BUG(); |
| 1423 | break; |
| 1424 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1425 | } |
| 1426 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1427 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1428 | { |
| 1429 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1430 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1431 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1434 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1435 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1436 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1437 | } |
| 1438 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1439 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1440 | { |
| 1441 | switch (tp->mac_version) { |
| 1442 | case RTL_GIGA_MAC_VER_27: |
| 1443 | case RTL_GIGA_MAC_VER_28: |
| 1444 | case RTL_GIGA_MAC_VER_31: |
| 1445 | return r8168dp_check_dash(tp); |
| 1446 | case RTL_GIGA_MAC_VER_49: |
| 1447 | case RTL_GIGA_MAC_VER_50: |
| 1448 | case RTL_GIGA_MAC_VER_51: |
| 1449 | return r8168ep_check_dash(tp); |
| 1450 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1451 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1455 | struct exgmac_reg { |
| 1456 | u16 addr; |
| 1457 | u16 mask; |
| 1458 | u32 val; |
| 1459 | }; |
| 1460 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1461 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1462 | const struct exgmac_reg *r, int len) |
| 1463 | { |
| 1464 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1465 | 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] | 1466 | r++; |
| 1467 | } |
| 1468 | } |
| 1469 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1470 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1471 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1472 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1473 | } |
| 1474 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1475 | 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] | 1476 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1477 | 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] | 1478 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1479 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1480 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1483 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1484 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1485 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1489 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1490 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1491 | mmiowb(); |
| 1492 | } |
| 1493 | |
| 1494 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1495 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1496 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1497 | mmiowb(); |
| 1498 | } |
| 1499 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1500 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1501 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1502 | RTL_W16(tp, IntrMask, bits); |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1503 | } |
| 1504 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1505 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1506 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1507 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1508 | |
| 1509 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1510 | { |
| 1511 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1512 | } |
| 1513 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1514 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1516 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1517 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1518 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1521 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1523 | return RTL_R32(tp, TBICSR) & TBIReset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1526 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1528 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1531 | static unsigned int rtl8169_tbi_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1533 | return RTL_R32(tp, TBICSR) & TBILinkOk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1536 | static unsigned int rtl8169_xmii_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1538 | return RTL_R8(tp, PHYstatus) & LinkStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1541 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1543 | RTL_W32(tp, TBICSR, RTL_R32(tp, TBICSR) | TBIReset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1546 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | { |
| 1548 | unsigned int val; |
| 1549 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1550 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1551 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1554 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1555 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1556 | struct net_device *dev = tp->dev; |
| 1557 | |
| 1558 | if (!netif_running(dev)) |
| 1559 | return; |
| 1560 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1561 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1562 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1563 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1564 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1565 | ERIAR_EXGMAC); |
| 1566 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1567 | ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1568 | } else if (RTL_R8(tp, PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1569 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1570 | ERIAR_EXGMAC); |
| 1571 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1572 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1573 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1574 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1575 | ERIAR_EXGMAC); |
| 1576 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1577 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1578 | } |
| 1579 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1580 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1581 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1582 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1583 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1584 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1585 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1586 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1587 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1588 | ERIAR_EXGMAC); |
| 1589 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1590 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1591 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1592 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1593 | ERIAR_EXGMAC); |
| 1594 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1595 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1596 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1597 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1598 | if (RTL_R8(tp, PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1599 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1600 | ERIAR_EXGMAC); |
| 1601 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1602 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1603 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1604 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1605 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1606 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1610 | static void rtl8169_check_link_status(struct net_device *dev, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1611 | struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1613 | struct device *d = tp_to_dev(tp); |
| 1614 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1615 | if (tp->link_ok(tp)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1616 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1617 | /* This is to cancel a scheduled suspend if there's one. */ |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1618 | pm_request_resume(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1620 | if (net_ratelimit()) |
| 1621 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1622 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1624 | netif_info(tp, ifdown, dev, "link down\n"); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1625 | pm_runtime_idle(d); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1629 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1630 | |
| 1631 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1632 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1633 | u8 options; |
| 1634 | u32 wolopts = 0; |
| 1635 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1636 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1637 | if (!(options & PMEnable)) |
| 1638 | return 0; |
| 1639 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1640 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1641 | if (options & LinkUp) |
| 1642 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1643 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1644 | case RTL_GIGA_MAC_VER_34: |
| 1645 | case RTL_GIGA_MAC_VER_35: |
| 1646 | case RTL_GIGA_MAC_VER_36: |
| 1647 | case RTL_GIGA_MAC_VER_37: |
| 1648 | case RTL_GIGA_MAC_VER_38: |
| 1649 | case RTL_GIGA_MAC_VER_40: |
| 1650 | case RTL_GIGA_MAC_VER_41: |
| 1651 | case RTL_GIGA_MAC_VER_42: |
| 1652 | case RTL_GIGA_MAC_VER_43: |
| 1653 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1654 | case RTL_GIGA_MAC_VER_45: |
| 1655 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1656 | case RTL_GIGA_MAC_VER_47: |
| 1657 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1658 | case RTL_GIGA_MAC_VER_49: |
| 1659 | case RTL_GIGA_MAC_VER_50: |
| 1660 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1661 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1662 | wolopts |= WAKE_MAGIC; |
| 1663 | break; |
| 1664 | default: |
| 1665 | if (options & MagicPacket) |
| 1666 | wolopts |= WAKE_MAGIC; |
| 1667 | break; |
| 1668 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1669 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1670 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1671 | if (options & UWF) |
| 1672 | wolopts |= WAKE_UCAST; |
| 1673 | if (options & BWF) |
| 1674 | wolopts |= WAKE_BCAST; |
| 1675 | if (options & MWF) |
| 1676 | wolopts |= WAKE_MCAST; |
| 1677 | |
| 1678 | return wolopts; |
| 1679 | } |
| 1680 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1681 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1682 | { |
| 1683 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1684 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1685 | |
| 1686 | pm_runtime_get_noresume(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1687 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1688 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1689 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1690 | wol->supported = WAKE_ANY; |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1691 | if (pm_runtime_active(d)) |
| 1692 | wol->wolopts = __rtl8169_get_wol(tp); |
| 1693 | else |
| 1694 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1695 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1696 | rtl_unlock_work(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1697 | |
| 1698 | pm_runtime_put_noidle(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1699 | } |
| 1700 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1701 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1702 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1703 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1704 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1705 | u32 opt; |
| 1706 | u16 reg; |
| 1707 | u8 mask; |
| 1708 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1709 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1710 | { WAKE_UCAST, Config5, UWF }, |
| 1711 | { WAKE_BCAST, Config5, BWF }, |
| 1712 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1713 | { WAKE_ANY, Config5, LanWake }, |
| 1714 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1715 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1716 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1717 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1718 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1719 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1720 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1721 | case RTL_GIGA_MAC_VER_34: |
| 1722 | case RTL_GIGA_MAC_VER_35: |
| 1723 | case RTL_GIGA_MAC_VER_36: |
| 1724 | case RTL_GIGA_MAC_VER_37: |
| 1725 | case RTL_GIGA_MAC_VER_38: |
| 1726 | case RTL_GIGA_MAC_VER_40: |
| 1727 | case RTL_GIGA_MAC_VER_41: |
| 1728 | case RTL_GIGA_MAC_VER_42: |
| 1729 | case RTL_GIGA_MAC_VER_43: |
| 1730 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1731 | case RTL_GIGA_MAC_VER_45: |
| 1732 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1733 | case RTL_GIGA_MAC_VER_47: |
| 1734 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1735 | case RTL_GIGA_MAC_VER_49: |
| 1736 | case RTL_GIGA_MAC_VER_50: |
| 1737 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1738 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1739 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1740 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1741 | 0x0dc, |
| 1742 | ERIAR_MASK_0100, |
| 1743 | MagicPacket_v2, |
| 1744 | 0x0000, |
| 1745 | ERIAR_EXGMAC); |
| 1746 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1747 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1748 | 0x0dc, |
| 1749 | ERIAR_MASK_0100, |
| 1750 | 0x0000, |
| 1751 | MagicPacket_v2, |
| 1752 | ERIAR_EXGMAC); |
| 1753 | break; |
| 1754 | default: |
| 1755 | tmp = ARRAY_SIZE(cfg); |
| 1756 | break; |
| 1757 | } |
| 1758 | |
| 1759 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1760 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1761 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1762 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1763 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1766 | switch (tp->mac_version) { |
| 1767 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1768 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1769 | if (wolopts) |
| 1770 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1771 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1772 | break; |
| 1773 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1774 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1775 | if (wolopts) |
| 1776 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1777 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1778 | break; |
| 1779 | } |
| 1780 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1781 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1785 | { |
| 1786 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1787 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1788 | |
| 1789 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1790 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1791 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1792 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1793 | if (pm_runtime_active(d)) |
| 1794 | __rtl8169_set_wol(tp, wol->wolopts); |
| 1795 | else |
| 1796 | tp->saved_wolopts = wol->wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1797 | |
| 1798 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1799 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1800 | device_set_wakeup_enable(d, wol->wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1801 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1802 | pm_runtime_put_noidle(d); |
| 1803 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1804 | return 0; |
| 1805 | } |
| 1806 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1807 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1808 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1809 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1813 | struct ethtool_drvinfo *info) |
| 1814 | { |
| 1815 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1816 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1818 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1819 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1820 | 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] | 1821 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1822 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1823 | strlcpy(info->fw_version, rtl_fw->version, |
| 1824 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1828 | { |
| 1829 | return R8169_REGS_SIZE; |
| 1830 | } |
| 1831 | |
| 1832 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1833 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | { |
| 1835 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | int ret = 0; |
| 1837 | u32 reg; |
| 1838 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1839 | reg = RTL_R32(tp, TBICSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1841 | (duplex == DUPLEX_FULL)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1842 | RTL_W32(tp, TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } else if (autoneg == AUTONEG_ENABLE) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1844 | RTL_W32(tp, TBICSR, reg | TBINwEnable | TBINwRestart); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1846 | netif_warn(tp, link, dev, |
| 1847 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | ret = -EOPNOTSUPP; |
| 1849 | } |
| 1850 | |
| 1851 | return ret; |
| 1852 | } |
| 1853 | |
| 1854 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1855 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | { |
| 1857 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1858 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1859 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1861 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
| 1863 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1864 | int auto_nego; |
| 1865 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1866 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1867 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1868 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1869 | |
| 1870 | if (adv & ADVERTISED_10baseT_Half) |
| 1871 | auto_nego |= ADVERTISE_10HALF; |
| 1872 | if (adv & ADVERTISED_10baseT_Full) |
| 1873 | auto_nego |= ADVERTISE_10FULL; |
| 1874 | if (adv & ADVERTISED_100baseT_Half) |
| 1875 | auto_nego |= ADVERTISE_100HALF; |
| 1876 | if (adv & ADVERTISED_100baseT_Full) |
| 1877 | auto_nego |= ADVERTISE_100FULL; |
| 1878 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1879 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1880 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1881 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1882 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1883 | |
| 1884 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1885 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1886 | if (adv & ADVERTISED_1000baseT_Half) |
| 1887 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1888 | if (adv & ADVERTISED_1000baseT_Full) |
| 1889 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1890 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1891 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1892 | netif_info(tp, link, dev, |
| 1893 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1894 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1895 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1897 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1898 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1899 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1900 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1901 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1902 | if (speed == SPEED_10) |
| 1903 | bmcr = 0; |
| 1904 | else if (speed == SPEED_100) |
| 1905 | bmcr = BMCR_SPEED100; |
| 1906 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1907 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1908 | |
| 1909 | if (duplex == DUPLEX_FULL) |
| 1910 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1911 | } |
| 1912 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1913 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1914 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1915 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1916 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1917 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1918 | rtl_writephy(tp, 0x17, 0x2138); |
| 1919 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1920 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1921 | rtl_writephy(tp, 0x17, 0x2108); |
| 1922 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1926 | rc = 0; |
| 1927 | out: |
| 1928 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1932 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | { |
| 1934 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1935 | int ret; |
| 1936 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1937 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1938 | if (ret < 0) |
| 1939 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1941 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 1942 | (advertising & ADVERTISED_1000baseT_Full) && |
| 1943 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1945 | } |
| 1946 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | return ret; |
| 1948 | } |
| 1949 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1950 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1951 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1953 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1954 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1955 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1956 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1958 | if (dev->mtu > JUMBO_1K && |
| 1959 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 1960 | features &= ~NETIF_F_IP_CSUM; |
| 1961 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1962 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1965 | static void __rtl8169_set_features(struct net_device *dev, |
| 1966 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | { |
| 1968 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1969 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1971 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1972 | if (features & NETIF_F_RXALL) |
| 1973 | rx_config |= (AcceptErr | AcceptRunt); |
| 1974 | else |
| 1975 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1977 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1978 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1979 | if (features & NETIF_F_RXCSUM) |
| 1980 | tp->cp_cmd |= RxChkSum; |
| 1981 | else |
| 1982 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1983 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1984 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1985 | tp->cp_cmd |= RxVlan; |
| 1986 | else |
| 1987 | tp->cp_cmd &= ~RxVlan; |
| 1988 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1989 | tp->cp_cmd |= RTL_R16(tp, CPlusCmd) & ~(RxVlan | RxChkSum); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1990 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1991 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1992 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1993 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1995 | static int rtl8169_set_features(struct net_device *dev, |
| 1996 | netdev_features_t features) |
| 1997 | { |
| 1998 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1999 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2000 | features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX; |
| 2001 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2002 | rtl_lock_work(tp); |
Dan Carpenter | 85911d7 | 2014-09-19 13:40:25 +0300 | [diff] [blame] | 2003 | if (features ^ dev->features) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2004 | __rtl8169_set_features(dev, features); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2005 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2010 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 2011 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 2013 | return (skb_vlan_tag_present(skb)) ? |
| 2014 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2017 | 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] | 2018 | { |
| 2019 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2021 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2022 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2025 | static int rtl8169_get_link_ksettings_tbi(struct net_device *dev, |
| 2026 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | { |
| 2028 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | u32 status; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2030 | u32 supported, advertising; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2032 | supported = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2034 | cmd->base.port = PORT_FIBRE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2036 | status = RTL_R32(tp, TBICSR); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2037 | advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 2038 | cmd->base.autoneg = !!(status & TBINwEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2040 | cmd->base.speed = SPEED_1000; |
| 2041 | cmd->base.duplex = DUPLEX_FULL; /* Always set */ |
| 2042 | |
| 2043 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 2044 | supported); |
| 2045 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 2046 | advertising); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2047 | |
| 2048 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2051 | static int rtl8169_get_link_ksettings_xmii(struct net_device *dev, |
| 2052 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | { |
| 2054 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 2056 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 2057 | |
| 2058 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2061 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 2062 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | { |
| 2064 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2065 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2067 | rtl_lock_work(tp); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2068 | rc = tp->get_link_ksettings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2069 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2071 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2074 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 2075 | const struct ethtool_link_ksettings *cmd) |
| 2076 | { |
| 2077 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2078 | int rc; |
| 2079 | u32 advertising; |
| 2080 | |
| 2081 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 2082 | cmd->link_modes.advertising)) |
| 2083 | return -EINVAL; |
| 2084 | |
| 2085 | del_timer_sync(&tp->timer); |
| 2086 | |
| 2087 | rtl_lock_work(tp); |
| 2088 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 2089 | cmd->base.duplex, advertising); |
| 2090 | rtl_unlock_work(tp); |
| 2091 | |
| 2092 | return rc; |
| 2093 | } |
| 2094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2096 | void *p) |
| 2097 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2098 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2099 | u32 __iomem *data = tp->mmio_addr; |
| 2100 | u32 *dw = p; |
| 2101 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2103 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2104 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 2105 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2106 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | } |
| 2108 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2109 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 2110 | { |
| 2111 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2112 | |
| 2113 | return tp->msg_enable; |
| 2114 | } |
| 2115 | |
| 2116 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 2117 | { |
| 2118 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2119 | |
| 2120 | tp->msg_enable = value; |
| 2121 | } |
| 2122 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2123 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2124 | "tx_packets", |
| 2125 | "rx_packets", |
| 2126 | "tx_errors", |
| 2127 | "rx_errors", |
| 2128 | "rx_missed", |
| 2129 | "align_errors", |
| 2130 | "tx_single_collisions", |
| 2131 | "tx_multi_collisions", |
| 2132 | "unicast", |
| 2133 | "broadcast", |
| 2134 | "multicast", |
| 2135 | "tx_aborted", |
| 2136 | "tx_underrun", |
| 2137 | }; |
| 2138 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2139 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2140 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2141 | switch (sset) { |
| 2142 | case ETH_SS_STATS: |
| 2143 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2144 | default: |
| 2145 | return -EOPNOTSUPP; |
| 2146 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2147 | } |
| 2148 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2149 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2150 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2151 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2154 | static bool rtl8169_do_counters(struct rtl8169_private *tp, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2155 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2156 | dma_addr_t paddr = tp->counters_phys_addr; |
| 2157 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2158 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2159 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 2160 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2161 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2162 | RTL_W32(tp, CounterAddrLow, cmd); |
| 2163 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2164 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2165 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2166 | } |
| 2167 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2168 | static bool rtl8169_reset_counters(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2169 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2170 | /* |
| 2171 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 2172 | * tally counters. |
| 2173 | */ |
| 2174 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 2175 | return true; |
| 2176 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2177 | return rtl8169_do_counters(tp, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2178 | } |
| 2179 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2180 | static bool rtl8169_update_counters(struct rtl8169_private *tp) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2181 | { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2182 | /* |
| 2183 | * Some chips are unable to dump tally counters when the receiver |
| 2184 | * is disabled. |
| 2185 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2186 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2187 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2188 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2189 | return rtl8169_do_counters(tp, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2190 | } |
| 2191 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2192 | static bool rtl8169_init_counter_offsets(struct rtl8169_private *tp) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2193 | { |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2194 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2195 | bool ret = false; |
| 2196 | |
| 2197 | /* |
| 2198 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2199 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2200 | * reset by a power cycle, while the counter values collected by the |
| 2201 | * driver are reset at every driver unload/load cycle. |
| 2202 | * |
| 2203 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2204 | * values, we collect the initial values at first open(*) and use them |
| 2205 | * as offsets to normalize the values returned by @get_stats64. |
| 2206 | * |
| 2207 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2208 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2209 | * set at open time by rtl_hw_start. |
| 2210 | */ |
| 2211 | |
| 2212 | if (tp->tc_offset.inited) |
| 2213 | return true; |
| 2214 | |
| 2215 | /* If both, reset and update fail, propagate to caller. */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2216 | if (rtl8169_reset_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2217 | ret = true; |
| 2218 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2219 | if (rtl8169_update_counters(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2220 | ret = true; |
| 2221 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2222 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2223 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2224 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2225 | tp->tc_offset.inited = true; |
| 2226 | |
| 2227 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2228 | } |
| 2229 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2230 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2231 | struct ethtool_stats *stats, u64 *data) |
| 2232 | { |
| 2233 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 2234 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2235 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2236 | |
| 2237 | ASSERT_RTNL(); |
| 2238 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2239 | pm_runtime_get_noresume(d); |
| 2240 | |
| 2241 | if (pm_runtime_active(d)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 2242 | rtl8169_update_counters(tp); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2243 | |
| 2244 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2245 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2246 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2247 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2248 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2249 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2250 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2251 | data[5] = le16_to_cpu(counters->align_errors); |
| 2252 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2253 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2254 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2255 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2256 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2257 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2258 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2259 | } |
| 2260 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2261 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2262 | { |
| 2263 | switch(stringset) { |
| 2264 | case ETH_SS_STATS: |
| 2265 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2270 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2271 | { |
| 2272 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2273 | |
| 2274 | return mii_nway_restart(&tp->mii); |
| 2275 | } |
| 2276 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2277 | /* |
| 2278 | * Interrupt coalescing |
| 2279 | * |
| 2280 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2281 | * > 8169, 8168 and 810x line of chipsets |
| 2282 | * |
| 2283 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2284 | * |
| 2285 | * > 2 - the Tx timer unit at gigabit speed |
| 2286 | * |
| 2287 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2288 | * (0xe0) bit 1 and bit 0. |
| 2289 | * |
| 2290 | * For 8169 |
| 2291 | * bit[1:0] \ speed 1000M 100M 10M |
| 2292 | * 0 0 320ns 2.56us 40.96us |
| 2293 | * 0 1 2.56us 20.48us 327.7us |
| 2294 | * 1 0 5.12us 40.96us 655.4us |
| 2295 | * 1 1 10.24us 81.92us 1.31ms |
| 2296 | * |
| 2297 | * For the other |
| 2298 | * bit[1:0] \ speed 1000M 100M 10M |
| 2299 | * 0 0 5us 2.56us 40.96us |
| 2300 | * 0 1 40us 20.48us 327.7us |
| 2301 | * 1 0 80us 40.96us 655.4us |
| 2302 | * 1 1 160us 81.92us 1.31ms |
| 2303 | */ |
| 2304 | |
| 2305 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2306 | struct rtl_coalesce_scale { |
| 2307 | /* Rx / Tx */ |
| 2308 | u32 nsecs[2]; |
| 2309 | }; |
| 2310 | |
| 2311 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2312 | struct rtl_coalesce_info { |
| 2313 | u32 speed; |
| 2314 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2315 | }; |
| 2316 | |
| 2317 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2318 | #define rxtx_x1822(r, t) { \ |
| 2319 | {{(r), (t)}}, \ |
| 2320 | {{(r)*8, (t)*8}}, \ |
| 2321 | {{(r)*8*2, (t)*8*2}}, \ |
| 2322 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2323 | } |
| 2324 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2325 | /* speed delays: rx00 tx00 */ |
| 2326 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2327 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2328 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2329 | { 0 }, |
| 2330 | }; |
| 2331 | |
| 2332 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2333 | /* speed delays: rx00 tx00 */ |
| 2334 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2335 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2336 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2337 | { 0 }, |
| 2338 | }; |
| 2339 | #undef rxtx_x1822 |
| 2340 | |
| 2341 | /* get rx/tx scale vector corresponding to current speed */ |
| 2342 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2343 | { |
| 2344 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2345 | struct ethtool_link_ksettings ecmd; |
| 2346 | const struct rtl_coalesce_info *ci; |
| 2347 | int rc; |
| 2348 | |
| 2349 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2350 | if (rc < 0) |
| 2351 | return ERR_PTR(rc); |
| 2352 | |
| 2353 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2354 | if (ecmd.base.speed == ci->speed) { |
| 2355 | return ci; |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | return ERR_PTR(-ELNRNG); |
| 2360 | } |
| 2361 | |
| 2362 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2363 | { |
| 2364 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2365 | const struct rtl_coalesce_info *ci; |
| 2366 | const struct rtl_coalesce_scale *scale; |
| 2367 | struct { |
| 2368 | u32 *max_frames; |
| 2369 | u32 *usecs; |
| 2370 | } coal_settings [] = { |
| 2371 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2372 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2373 | }, *p = coal_settings; |
| 2374 | int i; |
| 2375 | u16 w; |
| 2376 | |
| 2377 | memset(ec, 0, sizeof(*ec)); |
| 2378 | |
| 2379 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2380 | ci = rtl_coalesce_info(dev); |
| 2381 | if (IS_ERR(ci)) |
| 2382 | return PTR_ERR(ci); |
| 2383 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2384 | scale = &ci->scalev[RTL_R16(tp, CPlusCmd) & 3]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2385 | |
| 2386 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2387 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2388 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2389 | w >>= RTL_COALESCE_SHIFT; |
| 2390 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2391 | } |
| 2392 | |
| 2393 | for (i = 0; i < 2; i++) { |
| 2394 | p = coal_settings + i; |
| 2395 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2396 | |
| 2397 | /* |
| 2398 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2399 | * max_frames to 0. |
| 2400 | */ |
| 2401 | if (!*p->usecs && !*p->max_frames) |
| 2402 | *p->max_frames = 1; |
| 2403 | } |
| 2404 | |
| 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2409 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2410 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2411 | { |
| 2412 | const struct rtl_coalesce_info *ci; |
| 2413 | u16 i; |
| 2414 | |
| 2415 | ci = rtl_coalesce_info(dev); |
| 2416 | if (IS_ERR(ci)) |
| 2417 | return ERR_CAST(ci); |
| 2418 | |
| 2419 | for (i = 0; i < 4; i++) { |
| 2420 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2421 | ci->scalev[i].nsecs[1]); |
| 2422 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2423 | *cp01 = i; |
| 2424 | return &ci->scalev[i]; |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | return ERR_PTR(-EINVAL); |
| 2429 | } |
| 2430 | |
| 2431 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2432 | { |
| 2433 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2434 | const struct rtl_coalesce_scale *scale; |
| 2435 | struct { |
| 2436 | u32 frames; |
| 2437 | u32 usecs; |
| 2438 | } coal_settings [] = { |
| 2439 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2440 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2441 | }, *p = coal_settings; |
| 2442 | u16 w = 0, cp01; |
| 2443 | int i; |
| 2444 | |
| 2445 | scale = rtl_coalesce_choose_scale(dev, |
| 2446 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2447 | if (IS_ERR(scale)) |
| 2448 | return PTR_ERR(scale); |
| 2449 | |
| 2450 | for (i = 0; i < 2; i++, p++) { |
| 2451 | u32 units; |
| 2452 | |
| 2453 | /* |
| 2454 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2455 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2456 | * |
| 2457 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2458 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2459 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2460 | * |
| 2461 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2462 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2463 | * we'll reject it below in `frames % 4 != 0`. |
| 2464 | */ |
| 2465 | if (p->frames == 1) { |
| 2466 | p->frames = 0; |
| 2467 | } |
| 2468 | |
| 2469 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2470 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2471 | return -EINVAL; |
| 2472 | |
| 2473 | w <<= RTL_COALESCE_SHIFT; |
| 2474 | w |= units; |
| 2475 | w <<= RTL_COALESCE_SHIFT; |
| 2476 | w |= p->frames >> 2; |
| 2477 | } |
| 2478 | |
| 2479 | rtl_lock_work(tp); |
| 2480 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2481 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2482 | |
| 2483 | tp->cp_cmd = (tp->cp_cmd & ~3) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2484 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2485 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2486 | |
| 2487 | rtl_unlock_work(tp); |
| 2488 | |
| 2489 | return 0; |
| 2490 | } |
| 2491 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2492 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2494 | .get_regs_len = rtl8169_get_regs_len, |
| 2495 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2496 | .get_coalesce = rtl_get_coalesce, |
| 2497 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2498 | .get_msglevel = rtl8169_get_msglevel, |
| 2499 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2501 | .get_wol = rtl8169_get_wol, |
| 2502 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2503 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2504 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2505 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2506 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2507 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2508 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2509 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | }; |
| 2511 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2512 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2513 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2515 | /* |
| 2516 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2517 | * but they can be identified more specifically through the test below |
| 2518 | * if needed: |
| 2519 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2520 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2521 | * |
| 2522 | * Same thing for the 8101Eb and the 8101Ec: |
| 2523 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2524 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2525 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2526 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2528 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | int mac_version; |
| 2530 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2531 | /* 8168EP family. */ |
| 2532 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2533 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2534 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2535 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2536 | /* 8168H family. */ |
| 2537 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2538 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2539 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2540 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2541 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2542 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2543 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2544 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2545 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2546 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2547 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2548 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2549 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2550 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2551 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2552 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2553 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 2554 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2555 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2556 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2557 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2558 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 2559 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2560 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2561 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2562 | /* 8168DP family. */ |
| 2563 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2564 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2565 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2566 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2567 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 2568 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2569 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2570 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2571 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2572 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2573 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2574 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2575 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2576 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2577 | |
| 2578 | /* 8168B family. */ |
| 2579 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 2580 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 2581 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2582 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2583 | |
| 2584 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2585 | { 0x7cf00000, 0x44900000, RTL_GIGA_MAC_VER_39 }, |
| 2586 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2587 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 2588 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2589 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 2590 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2591 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2592 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 2593 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 2594 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2595 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2596 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2597 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2598 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2599 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2600 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2601 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2602 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2603 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2604 | /* FIXME: where did these entries come from ? -- FR */ |
| 2605 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2606 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2607 | |
| 2608 | /* 8110 family. */ |
| 2609 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2610 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2611 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2612 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2613 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2614 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2615 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2616 | /* Catch-all */ |
| 2617 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2618 | }; |
| 2619 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | u32 reg; |
| 2621 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2622 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2623 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | p++; |
| 2625 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2626 | |
| 2627 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 2628 | netif_notice(tp, probe, dev, |
| 2629 | "unknown MAC, using family default\n"); |
| 2630 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2631 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2632 | tp->mac_version = tp->mii.supports_gmii ? |
| 2633 | RTL_GIGA_MAC_VER_42 : |
| 2634 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2635 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2636 | tp->mac_version = tp->mii.supports_gmii ? |
| 2637 | RTL_GIGA_MAC_VER_45 : |
| 2638 | RTL_GIGA_MAC_VER_47; |
| 2639 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2640 | tp->mac_version = tp->mii.supports_gmii ? |
| 2641 | RTL_GIGA_MAC_VER_46 : |
| 2642 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2647 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2648 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2651 | struct phy_reg { |
| 2652 | u16 reg; |
| 2653 | u16 val; |
| 2654 | }; |
| 2655 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2656 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2657 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2658 | { |
| 2659 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2660 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2661 | regs++; |
| 2662 | } |
| 2663 | } |
| 2664 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2665 | #define PHY_READ 0x00000000 |
| 2666 | #define PHY_DATA_OR 0x10000000 |
| 2667 | #define PHY_DATA_AND 0x20000000 |
| 2668 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2669 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2670 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2671 | #define PHY_WRITE 0x80000000 |
| 2672 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2673 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2674 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2675 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2676 | #define PHY_SKIPN 0xd0000000 |
| 2677 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2678 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2679 | struct fw_info { |
| 2680 | u32 magic; |
| 2681 | char version[RTL_VER_SIZE]; |
| 2682 | __le32 fw_start; |
| 2683 | __le32 fw_len; |
| 2684 | u8 chksum; |
| 2685 | } __packed; |
| 2686 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2687 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2688 | |
| 2689 | 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] | 2690 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2691 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2692 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2693 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2694 | char *version = rtl_fw->version; |
| 2695 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2696 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2697 | if (fw->size < FW_OPCODE_SIZE) |
| 2698 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2699 | |
| 2700 | if (!fw_info->magic) { |
| 2701 | size_t i, size, start; |
| 2702 | u8 checksum = 0; |
| 2703 | |
| 2704 | if (fw->size < sizeof(*fw_info)) |
| 2705 | goto out; |
| 2706 | |
| 2707 | for (i = 0; i < fw->size; i++) |
| 2708 | checksum += fw->data[i]; |
| 2709 | if (checksum != 0) |
| 2710 | goto out; |
| 2711 | |
| 2712 | start = le32_to_cpu(fw_info->fw_start); |
| 2713 | if (start > fw->size) |
| 2714 | goto out; |
| 2715 | |
| 2716 | size = le32_to_cpu(fw_info->fw_len); |
| 2717 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2718 | goto out; |
| 2719 | |
| 2720 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2721 | |
| 2722 | pa->code = (__le32 *)(fw->data + start); |
| 2723 | pa->size = size; |
| 2724 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2725 | if (fw->size % FW_OPCODE_SIZE) |
| 2726 | goto out; |
| 2727 | |
| 2728 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2729 | |
| 2730 | pa->code = (__le32 *)fw->data; |
| 2731 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2732 | } |
| 2733 | version[RTL_VER_SIZE - 1] = 0; |
| 2734 | |
| 2735 | rc = true; |
| 2736 | out: |
| 2737 | return rc; |
| 2738 | } |
| 2739 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2740 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2741 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2742 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2743 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2744 | size_t index; |
| 2745 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2746 | for (index = 0; index < pa->size; index++) { |
| 2747 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2748 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2749 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2750 | switch(action & 0xf0000000) { |
| 2751 | case PHY_READ: |
| 2752 | case PHY_DATA_OR: |
| 2753 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2754 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2755 | case PHY_CLEAR_READCOUNT: |
| 2756 | case PHY_WRITE: |
| 2757 | case PHY_WRITE_PREVIOUS: |
| 2758 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2759 | break; |
| 2760 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2761 | case PHY_BJMPN: |
| 2762 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2763 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2764 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2765 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2766 | } |
| 2767 | break; |
| 2768 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2769 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2770 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2771 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2772 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2773 | } |
| 2774 | break; |
| 2775 | case PHY_COMP_EQ_SKIPN: |
| 2776 | case PHY_COMP_NEQ_SKIPN: |
| 2777 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2778 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2779 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2780 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2781 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2785 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2786 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2787 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2788 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2789 | } |
| 2790 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2791 | rc = true; |
| 2792 | out: |
| 2793 | return rc; |
| 2794 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2795 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2796 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2797 | { |
| 2798 | struct net_device *dev = tp->dev; |
| 2799 | int rc = -EINVAL; |
| 2800 | |
| 2801 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2802 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2803 | goto out; |
| 2804 | } |
| 2805 | |
| 2806 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2807 | rc = 0; |
| 2808 | out: |
| 2809 | return rc; |
| 2810 | } |
| 2811 | |
| 2812 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2813 | { |
| 2814 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2815 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2816 | u32 predata, count; |
| 2817 | size_t index; |
| 2818 | |
| 2819 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2820 | org.write = ops->write; |
| 2821 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2822 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2823 | for (index = 0; index < pa->size; ) { |
| 2824 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2825 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2826 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2827 | |
| 2828 | if (!action) |
| 2829 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2830 | |
| 2831 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2832 | case PHY_READ: |
| 2833 | predata = rtl_readphy(tp, regno); |
| 2834 | count++; |
| 2835 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2836 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2837 | case PHY_DATA_OR: |
| 2838 | predata |= data; |
| 2839 | index++; |
| 2840 | break; |
| 2841 | case PHY_DATA_AND: |
| 2842 | predata &= data; |
| 2843 | index++; |
| 2844 | break; |
| 2845 | case PHY_BJMPN: |
| 2846 | index -= regno; |
| 2847 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2848 | case PHY_MDIO_CHG: |
| 2849 | if (data == 0) { |
| 2850 | ops->write = org.write; |
| 2851 | ops->read = org.read; |
| 2852 | } else if (data == 1) { |
| 2853 | ops->write = mac_mcu_write; |
| 2854 | ops->read = mac_mcu_read; |
| 2855 | } |
| 2856 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2857 | index++; |
| 2858 | break; |
| 2859 | case PHY_CLEAR_READCOUNT: |
| 2860 | count = 0; |
| 2861 | index++; |
| 2862 | break; |
| 2863 | case PHY_WRITE: |
| 2864 | rtl_writephy(tp, regno, data); |
| 2865 | index++; |
| 2866 | break; |
| 2867 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2868 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2869 | break; |
| 2870 | case PHY_COMP_EQ_SKIPN: |
| 2871 | if (predata == data) |
| 2872 | index += regno; |
| 2873 | index++; |
| 2874 | break; |
| 2875 | case PHY_COMP_NEQ_SKIPN: |
| 2876 | if (predata != data) |
| 2877 | index += regno; |
| 2878 | index++; |
| 2879 | break; |
| 2880 | case PHY_WRITE_PREVIOUS: |
| 2881 | rtl_writephy(tp, regno, predata); |
| 2882 | index++; |
| 2883 | break; |
| 2884 | case PHY_SKIPN: |
| 2885 | index += regno + 1; |
| 2886 | break; |
| 2887 | case PHY_DELAY_MS: |
| 2888 | mdelay(data); |
| 2889 | index++; |
| 2890 | break; |
| 2891 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2892 | default: |
| 2893 | BUG(); |
| 2894 | } |
| 2895 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2896 | |
| 2897 | ops->write = org.write; |
| 2898 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2901 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2902 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2903 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2904 | release_firmware(tp->rtl_fw->fw); |
| 2905 | kfree(tp->rtl_fw); |
| 2906 | } |
| 2907 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2910 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2911 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2912 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2913 | |
| 2914 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2915 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2916 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2920 | { |
| 2921 | if (rtl_readphy(tp, reg) != val) |
| 2922 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2923 | else |
| 2924 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2927 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2929 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2930 | { 0x1f, 0x0001 }, |
| 2931 | { 0x06, 0x006e }, |
| 2932 | { 0x08, 0x0708 }, |
| 2933 | { 0x15, 0x4000 }, |
| 2934 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2936 | { 0x1f, 0x0001 }, |
| 2937 | { 0x03, 0x00a1 }, |
| 2938 | { 0x02, 0x0008 }, |
| 2939 | { 0x01, 0x0120 }, |
| 2940 | { 0x00, 0x1000 }, |
| 2941 | { 0x04, 0x0800 }, |
| 2942 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2944 | { 0x03, 0xff41 }, |
| 2945 | { 0x02, 0xdf60 }, |
| 2946 | { 0x01, 0x0140 }, |
| 2947 | { 0x00, 0x0077 }, |
| 2948 | { 0x04, 0x7800 }, |
| 2949 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2951 | { 0x03, 0x802f }, |
| 2952 | { 0x02, 0x4f02 }, |
| 2953 | { 0x01, 0x0409 }, |
| 2954 | { 0x00, 0xf0f9 }, |
| 2955 | { 0x04, 0x9800 }, |
| 2956 | { 0x04, 0x9000 }, |
| 2957 | |
| 2958 | { 0x03, 0xdf01 }, |
| 2959 | { 0x02, 0xdf20 }, |
| 2960 | { 0x01, 0xff95 }, |
| 2961 | { 0x00, 0xba00 }, |
| 2962 | { 0x04, 0xa800 }, |
| 2963 | { 0x04, 0xa000 }, |
| 2964 | |
| 2965 | { 0x03, 0xff41 }, |
| 2966 | { 0x02, 0xdf20 }, |
| 2967 | { 0x01, 0x0140 }, |
| 2968 | { 0x00, 0x00bb }, |
| 2969 | { 0x04, 0xb800 }, |
| 2970 | { 0x04, 0xb000 }, |
| 2971 | |
| 2972 | { 0x03, 0xdf41 }, |
| 2973 | { 0x02, 0xdc60 }, |
| 2974 | { 0x01, 0x6340 }, |
| 2975 | { 0x00, 0x007d }, |
| 2976 | { 0x04, 0xd800 }, |
| 2977 | { 0x04, 0xd000 }, |
| 2978 | |
| 2979 | { 0x03, 0xdf01 }, |
| 2980 | { 0x02, 0xdf20 }, |
| 2981 | { 0x01, 0x100a }, |
| 2982 | { 0x00, 0xa0ff }, |
| 2983 | { 0x04, 0xf800 }, |
| 2984 | { 0x04, 0xf000 }, |
| 2985 | |
| 2986 | { 0x1f, 0x0000 }, |
| 2987 | { 0x0b, 0x0000 }, |
| 2988 | { 0x00, 0x9200 } |
| 2989 | }; |
| 2990 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2991 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2994 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2995 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2996 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2997 | { 0x1f, 0x0002 }, |
| 2998 | { 0x01, 0x90d0 }, |
| 2999 | { 0x1f, 0x0000 } |
| 3000 | }; |
| 3001 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3002 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3003 | } |
| 3004 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3005 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3006 | { |
| 3007 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3008 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 3009 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 3010 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3011 | return; |
| 3012 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3013 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3014 | rtl_writephy(tp, 0x10, 0xf01b); |
| 3015 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3016 | } |
| 3017 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3018 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3019 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3020 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3021 | { 0x1f, 0x0001 }, |
| 3022 | { 0x04, 0x0000 }, |
| 3023 | { 0x03, 0x00a1 }, |
| 3024 | { 0x02, 0x0008 }, |
| 3025 | { 0x01, 0x0120 }, |
| 3026 | { 0x00, 0x1000 }, |
| 3027 | { 0x04, 0x0800 }, |
| 3028 | { 0x04, 0x9000 }, |
| 3029 | { 0x03, 0x802f }, |
| 3030 | { 0x02, 0x4f02 }, |
| 3031 | { 0x01, 0x0409 }, |
| 3032 | { 0x00, 0xf099 }, |
| 3033 | { 0x04, 0x9800 }, |
| 3034 | { 0x04, 0xa000 }, |
| 3035 | { 0x03, 0xdf01 }, |
| 3036 | { 0x02, 0xdf20 }, |
| 3037 | { 0x01, 0xff95 }, |
| 3038 | { 0x00, 0xba00 }, |
| 3039 | { 0x04, 0xa800 }, |
| 3040 | { 0x04, 0xf000 }, |
| 3041 | { 0x03, 0xdf01 }, |
| 3042 | { 0x02, 0xdf20 }, |
| 3043 | { 0x01, 0x101a }, |
| 3044 | { 0x00, 0xa0ff }, |
| 3045 | { 0x04, 0xf800 }, |
| 3046 | { 0x04, 0x0000 }, |
| 3047 | { 0x1f, 0x0000 }, |
| 3048 | |
| 3049 | { 0x1f, 0x0001 }, |
| 3050 | { 0x10, 0xf41b }, |
| 3051 | { 0x14, 0xfb54 }, |
| 3052 | { 0x18, 0xf5c7 }, |
| 3053 | { 0x1f, 0x0000 }, |
| 3054 | |
| 3055 | { 0x1f, 0x0001 }, |
| 3056 | { 0x17, 0x0cc0 }, |
| 3057 | { 0x1f, 0x0000 } |
| 3058 | }; |
| 3059 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3060 | 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] | 3061 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3062 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3065 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3066 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3067 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3068 | { 0x1f, 0x0001 }, |
| 3069 | { 0x04, 0x0000 }, |
| 3070 | { 0x03, 0x00a1 }, |
| 3071 | { 0x02, 0x0008 }, |
| 3072 | { 0x01, 0x0120 }, |
| 3073 | { 0x00, 0x1000 }, |
| 3074 | { 0x04, 0x0800 }, |
| 3075 | { 0x04, 0x9000 }, |
| 3076 | { 0x03, 0x802f }, |
| 3077 | { 0x02, 0x4f02 }, |
| 3078 | { 0x01, 0x0409 }, |
| 3079 | { 0x00, 0xf099 }, |
| 3080 | { 0x04, 0x9800 }, |
| 3081 | { 0x04, 0xa000 }, |
| 3082 | { 0x03, 0xdf01 }, |
| 3083 | { 0x02, 0xdf20 }, |
| 3084 | { 0x01, 0xff95 }, |
| 3085 | { 0x00, 0xba00 }, |
| 3086 | { 0x04, 0xa800 }, |
| 3087 | { 0x04, 0xf000 }, |
| 3088 | { 0x03, 0xdf01 }, |
| 3089 | { 0x02, 0xdf20 }, |
| 3090 | { 0x01, 0x101a }, |
| 3091 | { 0x00, 0xa0ff }, |
| 3092 | { 0x04, 0xf800 }, |
| 3093 | { 0x04, 0x0000 }, |
| 3094 | { 0x1f, 0x0000 }, |
| 3095 | |
| 3096 | { 0x1f, 0x0001 }, |
| 3097 | { 0x0b, 0x8480 }, |
| 3098 | { 0x1f, 0x0000 }, |
| 3099 | |
| 3100 | { 0x1f, 0x0001 }, |
| 3101 | { 0x18, 0x67c7 }, |
| 3102 | { 0x04, 0x2000 }, |
| 3103 | { 0x03, 0x002f }, |
| 3104 | { 0x02, 0x4360 }, |
| 3105 | { 0x01, 0x0109 }, |
| 3106 | { 0x00, 0x3022 }, |
| 3107 | { 0x04, 0x2800 }, |
| 3108 | { 0x1f, 0x0000 }, |
| 3109 | |
| 3110 | { 0x1f, 0x0001 }, |
| 3111 | { 0x17, 0x0cc0 }, |
| 3112 | { 0x1f, 0x0000 } |
| 3113 | }; |
| 3114 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3115 | 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] | 3116 | } |
| 3117 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3118 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3119 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3120 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3121 | { 0x10, 0xf41b }, |
| 3122 | { 0x1f, 0x0000 } |
| 3123 | }; |
| 3124 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3125 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3126 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3127 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3128 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3131 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3132 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3133 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3134 | { 0x1f, 0x0001 }, |
| 3135 | { 0x10, 0xf41b }, |
| 3136 | { 0x1f, 0x0000 } |
| 3137 | }; |
| 3138 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3139 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3140 | } |
| 3141 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3142 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3143 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3144 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3145 | { 0x1f, 0x0000 }, |
| 3146 | { 0x1d, 0x0f00 }, |
| 3147 | { 0x1f, 0x0002 }, |
| 3148 | { 0x0c, 0x1ec8 }, |
| 3149 | { 0x1f, 0x0000 } |
| 3150 | }; |
| 3151 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3152 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3153 | } |
| 3154 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3155 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3156 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3157 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3158 | { 0x1f, 0x0001 }, |
| 3159 | { 0x1d, 0x3d98 }, |
| 3160 | { 0x1f, 0x0000 } |
| 3161 | }; |
| 3162 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3163 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3164 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3165 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3166 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3167 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3168 | } |
| 3169 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3170 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3171 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3172 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 3173 | { 0x1f, 0x0001 }, |
| 3174 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3175 | { 0x1f, 0x0002 }, |
| 3176 | { 0x00, 0x88d4 }, |
| 3177 | { 0x01, 0x82b1 }, |
| 3178 | { 0x03, 0x7002 }, |
| 3179 | { 0x08, 0x9e30 }, |
| 3180 | { 0x09, 0x01f0 }, |
| 3181 | { 0x0a, 0x5500 }, |
| 3182 | { 0x0c, 0x00c8 }, |
| 3183 | { 0x1f, 0x0003 }, |
| 3184 | { 0x12, 0xc096 }, |
| 3185 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3186 | { 0x1f, 0x0000 }, |
| 3187 | { 0x1f, 0x0000 }, |
| 3188 | { 0x09, 0x2000 }, |
| 3189 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3190 | }; |
| 3191 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3192 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3193 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3194 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3195 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3196 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3197 | } |
| 3198 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3199 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3200 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3201 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3202 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3203 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3204 | { 0x03, 0x802f }, |
| 3205 | { 0x02, 0x4f02 }, |
| 3206 | { 0x01, 0x0409 }, |
| 3207 | { 0x00, 0xf099 }, |
| 3208 | { 0x04, 0x9800 }, |
| 3209 | { 0x04, 0x9000 }, |
| 3210 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3211 | { 0x1f, 0x0002 }, |
| 3212 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3213 | { 0x06, 0x0761 }, |
| 3214 | { 0x1f, 0x0003 }, |
| 3215 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3216 | { 0x1f, 0x0000 } |
| 3217 | }; |
| 3218 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3219 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3220 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3221 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3222 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3223 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3224 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3225 | } |
| 3226 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3227 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3228 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3229 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3230 | { 0x1f, 0x0001 }, |
| 3231 | { 0x12, 0x2300 }, |
| 3232 | { 0x1d, 0x3d98 }, |
| 3233 | { 0x1f, 0x0002 }, |
| 3234 | { 0x0c, 0x7eb8 }, |
| 3235 | { 0x06, 0x5461 }, |
| 3236 | { 0x1f, 0x0003 }, |
| 3237 | { 0x16, 0x0f0a }, |
| 3238 | { 0x1f, 0x0000 } |
| 3239 | }; |
| 3240 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3241 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3242 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3243 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3244 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3245 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3246 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3247 | } |
| 3248 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3249 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3250 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3251 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3254 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3255 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3256 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3257 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3258 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3259 | { 0x06, 0x4064 }, |
| 3260 | { 0x07, 0x2863 }, |
| 3261 | { 0x08, 0x059c }, |
| 3262 | { 0x09, 0x26b4 }, |
| 3263 | { 0x0a, 0x6a19 }, |
| 3264 | { 0x0b, 0xdcc8 }, |
| 3265 | { 0x10, 0xf06d }, |
| 3266 | { 0x14, 0x7f68 }, |
| 3267 | { 0x18, 0x7fd9 }, |
| 3268 | { 0x1c, 0xf0ff }, |
| 3269 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3270 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3271 | { 0x12, 0xf49f }, |
| 3272 | { 0x13, 0x070b }, |
| 3273 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3274 | { 0x14, 0x94c0 }, |
| 3275 | |
| 3276 | /* |
| 3277 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3278 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3279 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3280 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3281 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3282 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3283 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3284 | { 0x06, 0x5561 }, |
| 3285 | |
| 3286 | /* |
| 3287 | * Can not link to 1Gbps with bad cable |
| 3288 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3289 | */ |
| 3290 | { 0x1f, 0x0001 }, |
| 3291 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3292 | |
| 3293 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3294 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3295 | }; |
| 3296 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3297 | 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] | 3298 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3299 | /* |
| 3300 | * Rx Error Issue |
| 3301 | * Fine Tune Switching regulator parameter |
| 3302 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3303 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3304 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3305 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3306 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3307 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3308 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3309 | { 0x1f, 0x0002 }, |
| 3310 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3311 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3312 | { 0x05, 0x8330 }, |
| 3313 | { 0x06, 0x669a }, |
| 3314 | { 0x1f, 0x0002 } |
| 3315 | }; |
| 3316 | int val; |
| 3317 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3318 | 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] | 3319 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3320 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3321 | |
| 3322 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3323 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3324 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3325 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3326 | }; |
| 3327 | int i; |
| 3328 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3329 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3330 | |
| 3331 | val &= 0xff00; |
| 3332 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3333 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3334 | } |
| 3335 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3336 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3337 | { 0x1f, 0x0002 }, |
| 3338 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3339 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3340 | { 0x05, 0x8330 }, |
| 3341 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3342 | }; |
| 3343 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3344 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3345 | } |
| 3346 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3347 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3348 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3349 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3350 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3351 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3352 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3353 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3354 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3355 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3356 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3357 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3358 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3359 | |
| 3360 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3361 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3362 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3363 | } |
| 3364 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3365 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3366 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3367 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3368 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3369 | { 0x1f, 0x0001 }, |
| 3370 | { 0x06, 0x4064 }, |
| 3371 | { 0x07, 0x2863 }, |
| 3372 | { 0x08, 0x059c }, |
| 3373 | { 0x09, 0x26b4 }, |
| 3374 | { 0x0a, 0x6a19 }, |
| 3375 | { 0x0b, 0xdcc8 }, |
| 3376 | { 0x10, 0xf06d }, |
| 3377 | { 0x14, 0x7f68 }, |
| 3378 | { 0x18, 0x7fd9 }, |
| 3379 | { 0x1c, 0xf0ff }, |
| 3380 | { 0x1d, 0x3d9c }, |
| 3381 | { 0x1f, 0x0003 }, |
| 3382 | { 0x12, 0xf49f }, |
| 3383 | { 0x13, 0x070b }, |
| 3384 | { 0x1a, 0x05ad }, |
| 3385 | { 0x14, 0x94c0 }, |
| 3386 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3387 | /* |
| 3388 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3389 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3390 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3391 | { 0x1f, 0x0002 }, |
| 3392 | { 0x06, 0x5561 }, |
| 3393 | { 0x1f, 0x0005 }, |
| 3394 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3395 | { 0x06, 0x5561 }, |
| 3396 | |
| 3397 | /* |
| 3398 | * Can not link to 1Gbps with bad cable |
| 3399 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3400 | */ |
| 3401 | { 0x1f, 0x0001 }, |
| 3402 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3403 | |
| 3404 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3405 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3406 | }; |
| 3407 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3408 | 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] | 3409 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3410 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3411 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3412 | { 0x1f, 0x0002 }, |
| 3413 | { 0x05, 0x669a }, |
| 3414 | { 0x1f, 0x0005 }, |
| 3415 | { 0x05, 0x8330 }, |
| 3416 | { 0x06, 0x669a }, |
| 3417 | |
| 3418 | { 0x1f, 0x0002 } |
| 3419 | }; |
| 3420 | int val; |
| 3421 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3422 | 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] | 3423 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3424 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3425 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3426 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3427 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3428 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3429 | }; |
| 3430 | int i; |
| 3431 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3432 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3433 | |
| 3434 | val &= 0xff00; |
| 3435 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3436 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3437 | } |
| 3438 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3439 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3440 | { 0x1f, 0x0002 }, |
| 3441 | { 0x05, 0x2642 }, |
| 3442 | { 0x1f, 0x0005 }, |
| 3443 | { 0x05, 0x8330 }, |
| 3444 | { 0x06, 0x2642 } |
| 3445 | }; |
| 3446 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3447 | 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] | 3448 | } |
| 3449 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3450 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3451 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3452 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3453 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3454 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3455 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3456 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3457 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3458 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3459 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3460 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3461 | |
| 3462 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3463 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3464 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3465 | } |
| 3466 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3467 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3468 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3469 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3470 | { 0x1f, 0x0002 }, |
| 3471 | { 0x10, 0x0008 }, |
| 3472 | { 0x0d, 0x006c }, |
| 3473 | |
| 3474 | { 0x1f, 0x0000 }, |
| 3475 | { 0x0d, 0xf880 }, |
| 3476 | |
| 3477 | { 0x1f, 0x0001 }, |
| 3478 | { 0x17, 0x0cc0 }, |
| 3479 | |
| 3480 | { 0x1f, 0x0001 }, |
| 3481 | { 0x0b, 0xa4d8 }, |
| 3482 | { 0x09, 0x281c }, |
| 3483 | { 0x07, 0x2883 }, |
| 3484 | { 0x0a, 0x6b35 }, |
| 3485 | { 0x1d, 0x3da4 }, |
| 3486 | { 0x1c, 0xeffd }, |
| 3487 | { 0x14, 0x7f52 }, |
| 3488 | { 0x18, 0x7fc6 }, |
| 3489 | { 0x08, 0x0601 }, |
| 3490 | { 0x06, 0x4063 }, |
| 3491 | { 0x10, 0xf074 }, |
| 3492 | { 0x1f, 0x0003 }, |
| 3493 | { 0x13, 0x0789 }, |
| 3494 | { 0x12, 0xf4bd }, |
| 3495 | { 0x1a, 0x04fd }, |
| 3496 | { 0x14, 0x84b0 }, |
| 3497 | { 0x1f, 0x0000 }, |
| 3498 | { 0x00, 0x9200 }, |
| 3499 | |
| 3500 | { 0x1f, 0x0005 }, |
| 3501 | { 0x01, 0x0340 }, |
| 3502 | { 0x1f, 0x0001 }, |
| 3503 | { 0x04, 0x4000 }, |
| 3504 | { 0x03, 0x1d21 }, |
| 3505 | { 0x02, 0x0c32 }, |
| 3506 | { 0x01, 0x0200 }, |
| 3507 | { 0x00, 0x5554 }, |
| 3508 | { 0x04, 0x4800 }, |
| 3509 | { 0x04, 0x4000 }, |
| 3510 | { 0x04, 0xf000 }, |
| 3511 | { 0x03, 0xdf01 }, |
| 3512 | { 0x02, 0xdf20 }, |
| 3513 | { 0x01, 0x101a }, |
| 3514 | { 0x00, 0xa0ff }, |
| 3515 | { 0x04, 0xf800 }, |
| 3516 | { 0x04, 0xf000 }, |
| 3517 | { 0x1f, 0x0000 }, |
| 3518 | |
| 3519 | { 0x1f, 0x0007 }, |
| 3520 | { 0x1e, 0x0023 }, |
| 3521 | { 0x16, 0x0000 }, |
| 3522 | { 0x1f, 0x0000 } |
| 3523 | }; |
| 3524 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3525 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3526 | } |
| 3527 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3528 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3529 | { |
| 3530 | static const struct phy_reg phy_reg_init[] = { |
| 3531 | { 0x1f, 0x0001 }, |
| 3532 | { 0x17, 0x0cc0 }, |
| 3533 | |
| 3534 | { 0x1f, 0x0007 }, |
| 3535 | { 0x1e, 0x002d }, |
| 3536 | { 0x18, 0x0040 }, |
| 3537 | { 0x1f, 0x0000 } |
| 3538 | }; |
| 3539 | |
| 3540 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3541 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3542 | } |
| 3543 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3544 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3545 | { |
| 3546 | static const struct phy_reg phy_reg_init[] = { |
| 3547 | /* Enable Delay cap */ |
| 3548 | { 0x1f, 0x0005 }, |
| 3549 | { 0x05, 0x8b80 }, |
| 3550 | { 0x06, 0xc896 }, |
| 3551 | { 0x1f, 0x0000 }, |
| 3552 | |
| 3553 | /* Channel estimation fine tune */ |
| 3554 | { 0x1f, 0x0001 }, |
| 3555 | { 0x0b, 0x6c20 }, |
| 3556 | { 0x07, 0x2872 }, |
| 3557 | { 0x1c, 0xefff }, |
| 3558 | { 0x1f, 0x0003 }, |
| 3559 | { 0x14, 0x6420 }, |
| 3560 | { 0x1f, 0x0000 }, |
| 3561 | |
| 3562 | /* Update PFM & 10M TX idle timer */ |
| 3563 | { 0x1f, 0x0007 }, |
| 3564 | { 0x1e, 0x002f }, |
| 3565 | { 0x15, 0x1919 }, |
| 3566 | { 0x1f, 0x0000 }, |
| 3567 | |
| 3568 | { 0x1f, 0x0007 }, |
| 3569 | { 0x1e, 0x00ac }, |
| 3570 | { 0x18, 0x0006 }, |
| 3571 | { 0x1f, 0x0000 } |
| 3572 | }; |
| 3573 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3574 | rtl_apply_firmware(tp); |
| 3575 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3576 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3577 | |
| 3578 | /* DCO enable for 10M IDLE Power */ |
| 3579 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3580 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3581 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3582 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3583 | |
| 3584 | /* For impedance matching */ |
| 3585 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3586 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3587 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3588 | |
| 3589 | /* PHY auto speed down */ |
| 3590 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3591 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3592 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3593 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3594 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3595 | |
| 3596 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3597 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3598 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3599 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3600 | |
| 3601 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3602 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3603 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3604 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3605 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3606 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3607 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3608 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3609 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3610 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3611 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3612 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3613 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3614 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3615 | } |
| 3616 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3617 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3618 | { |
| 3619 | const u16 w[] = { |
| 3620 | addr[0] | (addr[1] << 8), |
| 3621 | addr[2] | (addr[3] << 8), |
| 3622 | addr[4] | (addr[5] << 8) |
| 3623 | }; |
| 3624 | const struct exgmac_reg e[] = { |
| 3625 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3626 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3627 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3628 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3629 | }; |
| 3630 | |
| 3631 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3632 | } |
| 3633 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3634 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3635 | { |
| 3636 | static const struct phy_reg phy_reg_init[] = { |
| 3637 | /* Enable Delay cap */ |
| 3638 | { 0x1f, 0x0004 }, |
| 3639 | { 0x1f, 0x0007 }, |
| 3640 | { 0x1e, 0x00ac }, |
| 3641 | { 0x18, 0x0006 }, |
| 3642 | { 0x1f, 0x0002 }, |
| 3643 | { 0x1f, 0x0000 }, |
| 3644 | { 0x1f, 0x0000 }, |
| 3645 | |
| 3646 | /* Channel estimation fine tune */ |
| 3647 | { 0x1f, 0x0003 }, |
| 3648 | { 0x09, 0xa20f }, |
| 3649 | { 0x1f, 0x0000 }, |
| 3650 | { 0x1f, 0x0000 }, |
| 3651 | |
| 3652 | /* Green Setting */ |
| 3653 | { 0x1f, 0x0005 }, |
| 3654 | { 0x05, 0x8b5b }, |
| 3655 | { 0x06, 0x9222 }, |
| 3656 | { 0x05, 0x8b6d }, |
| 3657 | { 0x06, 0x8000 }, |
| 3658 | { 0x05, 0x8b76 }, |
| 3659 | { 0x06, 0x8000 }, |
| 3660 | { 0x1f, 0x0000 } |
| 3661 | }; |
| 3662 | |
| 3663 | rtl_apply_firmware(tp); |
| 3664 | |
| 3665 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3666 | |
| 3667 | /* For 4-corner performance improve */ |
| 3668 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3669 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3670 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3671 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3672 | |
| 3673 | /* PHY auto speed down */ |
| 3674 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3675 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3676 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3677 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3678 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3679 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3680 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3681 | |
| 3682 | /* improve 10M EEE waveform */ |
| 3683 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3684 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3685 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3686 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3687 | |
| 3688 | /* Improve 2-pair detection performance */ |
| 3689 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3690 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3691 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3692 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3693 | |
| 3694 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3695 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3696 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3697 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3698 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3699 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3700 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3701 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3702 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3703 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3704 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3705 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3706 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3707 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3708 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3709 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3710 | |
| 3711 | /* Green feature */ |
| 3712 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3713 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3714 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3715 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3716 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3717 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3718 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3719 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3720 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3721 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3722 | } |
| 3723 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3724 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3725 | { |
| 3726 | /* For 4-corner performance improve */ |
| 3727 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3728 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3729 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3730 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3731 | |
| 3732 | /* PHY auto speed down */ |
| 3733 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3734 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3735 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3736 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3737 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3738 | |
| 3739 | /* Improve 10M EEE waveform */ |
| 3740 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3741 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3742 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3743 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3744 | } |
| 3745 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3746 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3747 | { |
| 3748 | static const struct phy_reg phy_reg_init[] = { |
| 3749 | /* Channel estimation fine tune */ |
| 3750 | { 0x1f, 0x0003 }, |
| 3751 | { 0x09, 0xa20f }, |
| 3752 | { 0x1f, 0x0000 }, |
| 3753 | |
| 3754 | /* Modify green table for giga & fnet */ |
| 3755 | { 0x1f, 0x0005 }, |
| 3756 | { 0x05, 0x8b55 }, |
| 3757 | { 0x06, 0x0000 }, |
| 3758 | { 0x05, 0x8b5e }, |
| 3759 | { 0x06, 0x0000 }, |
| 3760 | { 0x05, 0x8b67 }, |
| 3761 | { 0x06, 0x0000 }, |
| 3762 | { 0x05, 0x8b70 }, |
| 3763 | { 0x06, 0x0000 }, |
| 3764 | { 0x1f, 0x0000 }, |
| 3765 | { 0x1f, 0x0007 }, |
| 3766 | { 0x1e, 0x0078 }, |
| 3767 | { 0x17, 0x0000 }, |
| 3768 | { 0x19, 0x00fb }, |
| 3769 | { 0x1f, 0x0000 }, |
| 3770 | |
| 3771 | /* Modify green table for 10M */ |
| 3772 | { 0x1f, 0x0005 }, |
| 3773 | { 0x05, 0x8b79 }, |
| 3774 | { 0x06, 0xaa00 }, |
| 3775 | { 0x1f, 0x0000 }, |
| 3776 | |
| 3777 | /* Disable hiimpedance detection (RTCT) */ |
| 3778 | { 0x1f, 0x0003 }, |
| 3779 | { 0x01, 0x328a }, |
| 3780 | { 0x1f, 0x0000 } |
| 3781 | }; |
| 3782 | |
| 3783 | rtl_apply_firmware(tp); |
| 3784 | |
| 3785 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3786 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3787 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3788 | |
| 3789 | /* Improve 2-pair detection performance */ |
| 3790 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3791 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3792 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3793 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3794 | } |
| 3795 | |
| 3796 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3797 | { |
| 3798 | rtl_apply_firmware(tp); |
| 3799 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3800 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3801 | } |
| 3802 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3803 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3804 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3805 | static const struct phy_reg phy_reg_init[] = { |
| 3806 | /* Channel estimation fine tune */ |
| 3807 | { 0x1f, 0x0003 }, |
| 3808 | { 0x09, 0xa20f }, |
| 3809 | { 0x1f, 0x0000 }, |
| 3810 | |
| 3811 | /* Modify green table for giga & fnet */ |
| 3812 | { 0x1f, 0x0005 }, |
| 3813 | { 0x05, 0x8b55 }, |
| 3814 | { 0x06, 0x0000 }, |
| 3815 | { 0x05, 0x8b5e }, |
| 3816 | { 0x06, 0x0000 }, |
| 3817 | { 0x05, 0x8b67 }, |
| 3818 | { 0x06, 0x0000 }, |
| 3819 | { 0x05, 0x8b70 }, |
| 3820 | { 0x06, 0x0000 }, |
| 3821 | { 0x1f, 0x0000 }, |
| 3822 | { 0x1f, 0x0007 }, |
| 3823 | { 0x1e, 0x0078 }, |
| 3824 | { 0x17, 0x0000 }, |
| 3825 | { 0x19, 0x00aa }, |
| 3826 | { 0x1f, 0x0000 }, |
| 3827 | |
| 3828 | /* Modify green table for 10M */ |
| 3829 | { 0x1f, 0x0005 }, |
| 3830 | { 0x05, 0x8b79 }, |
| 3831 | { 0x06, 0xaa00 }, |
| 3832 | { 0x1f, 0x0000 }, |
| 3833 | |
| 3834 | /* Disable hiimpedance detection (RTCT) */ |
| 3835 | { 0x1f, 0x0003 }, |
| 3836 | { 0x01, 0x328a }, |
| 3837 | { 0x1f, 0x0000 } |
| 3838 | }; |
| 3839 | |
| 3840 | |
| 3841 | rtl_apply_firmware(tp); |
| 3842 | |
| 3843 | rtl8168f_hw_phy_config(tp); |
| 3844 | |
| 3845 | /* Improve 2-pair detection performance */ |
| 3846 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3847 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3848 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3849 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3850 | |
| 3851 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3852 | |
| 3853 | /* Modify green table for giga */ |
| 3854 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3855 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3856 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3857 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3858 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3859 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3860 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3861 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3862 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3863 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3864 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3865 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3866 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3867 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3868 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3869 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3870 | |
| 3871 | /* uc same-seed solution */ |
| 3872 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3873 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3874 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3875 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3876 | |
| 3877 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3878 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3879 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3880 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3881 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3882 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3883 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3884 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3885 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3886 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3887 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3888 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3889 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3890 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3891 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3892 | |
| 3893 | /* Green feature */ |
| 3894 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3895 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3896 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3897 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3898 | } |
| 3899 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3900 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3901 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3902 | rtl_apply_firmware(tp); |
| 3903 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3904 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3905 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3906 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3907 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3908 | } else { |
| 3909 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3910 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3911 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3912 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3913 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3914 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3915 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3916 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3917 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3918 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3919 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3920 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3921 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3922 | /* Enable PHY auto speed down */ |
| 3923 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3924 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3925 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3926 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3927 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3928 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3929 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3930 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3931 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3932 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3933 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3934 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3935 | /* EEE auto-fallback function */ |
| 3936 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3937 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3938 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3939 | /* Enable UC LPF tune function */ |
| 3940 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3941 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3942 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3943 | |
| 3944 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3945 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3946 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3947 | /* Improve SWR Efficiency */ |
| 3948 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3949 | rtl_writephy(tp, 0x14, 0x5065); |
| 3950 | rtl_writephy(tp, 0x14, 0xd065); |
| 3951 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3952 | rtl_writephy(tp, 0x11, 0x5655); |
| 3953 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3954 | rtl_writephy(tp, 0x14, 0x1065); |
| 3955 | rtl_writephy(tp, 0x14, 0x9065); |
| 3956 | rtl_writephy(tp, 0x14, 0x1065); |
| 3957 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3958 | /* Check ALDPS bit, disable it if enabled */ |
| 3959 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3960 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3961 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3962 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3963 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3964 | } |
| 3965 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3966 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3967 | { |
| 3968 | rtl_apply_firmware(tp); |
| 3969 | } |
| 3970 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3971 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3972 | { |
| 3973 | u16 dout_tapbin; |
| 3974 | u32 data; |
| 3975 | |
| 3976 | rtl_apply_firmware(tp); |
| 3977 | |
| 3978 | /* CHN EST parameters adjust - giga master */ |
| 3979 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3980 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3981 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3982 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3983 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3984 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3985 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3986 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3987 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3988 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3989 | |
| 3990 | /* CHN EST parameters adjust - giga slave */ |
| 3991 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3992 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3993 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3994 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3995 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3996 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3997 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3998 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3999 | |
| 4000 | /* CHN EST parameters adjust - fnet */ |
| 4001 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4002 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4003 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4004 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4005 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4006 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4007 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4008 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4009 | |
| 4010 | /* enable R-tune & PGA-retune function */ |
| 4011 | dout_tapbin = 0; |
| 4012 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 4013 | data = rtl_readphy(tp, 0x13); |
| 4014 | data &= 3; |
| 4015 | data <<= 2; |
| 4016 | dout_tapbin |= data; |
| 4017 | data = rtl_readphy(tp, 0x12); |
| 4018 | data &= 0xc000; |
| 4019 | data >>= 14; |
| 4020 | dout_tapbin |= data; |
| 4021 | dout_tapbin = ~(dout_tapbin^0x08); |
| 4022 | dout_tapbin <<= 12; |
| 4023 | dout_tapbin &= 0xf000; |
| 4024 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4025 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4026 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4027 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4028 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4029 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4030 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4031 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4032 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4033 | |
| 4034 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4035 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4036 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4037 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4038 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4039 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4040 | |
| 4041 | /* enable GPHY 10M */ |
| 4042 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4043 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4044 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4045 | |
| 4046 | /* SAR ADC performance */ |
| 4047 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4048 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4049 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4050 | |
| 4051 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4052 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4053 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4054 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4055 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4056 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4057 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4058 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4059 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4060 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4061 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4062 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4063 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4064 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4065 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4066 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4067 | |
| 4068 | /* disable phy pfm mode */ |
| 4069 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4070 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4071 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4072 | |
| 4073 | /* Check ALDPS bit, disable it if enabled */ |
| 4074 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4075 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4076 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4077 | |
| 4078 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4079 | } |
| 4080 | |
| 4081 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 4082 | { |
| 4083 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 4084 | u16 rlen; |
| 4085 | u32 data; |
| 4086 | |
| 4087 | rtl_apply_firmware(tp); |
| 4088 | |
| 4089 | /* CHIN EST parameter update */ |
| 4090 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4091 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4092 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4093 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4094 | |
| 4095 | /* enable R-tune & PGA-retune function */ |
| 4096 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4097 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4098 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4099 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4100 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4101 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4102 | |
| 4103 | /* enable GPHY 10M */ |
| 4104 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4105 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4106 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4107 | |
| 4108 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 4109 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 4110 | ioffset_p3 = ((data & 0x80)>>7); |
| 4111 | ioffset_p3 <<= 3; |
| 4112 | |
| 4113 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 4114 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 4115 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 4116 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 4117 | ioffset_p0 = ((data & 0x0010)>>4); |
| 4118 | ioffset_p0 <<= 3; |
| 4119 | ioffset_p0 |= (data & (0x07)); |
| 4120 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 4121 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4122 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 4123 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4124 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 4125 | rtl_writephy(tp, 0x16, data); |
| 4126 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4127 | } |
| 4128 | |
| 4129 | /* Modify rlen (TX LPF corner frequency) level */ |
| 4130 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4131 | data = rtl_readphy(tp, 0x16); |
| 4132 | data &= 0x000f; |
| 4133 | rlen = 0; |
| 4134 | if (data > 3) |
| 4135 | rlen = data - 3; |
| 4136 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 4137 | rtl_writephy(tp, 0x17, data); |
| 4138 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4139 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4140 | |
| 4141 | /* disable phy pfm mode */ |
| 4142 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4143 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4144 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4145 | |
| 4146 | /* Check ALDPS bit, disable it if enabled */ |
| 4147 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4148 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4149 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4150 | |
| 4151 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4152 | } |
| 4153 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4154 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 4155 | { |
| 4156 | /* Enable PHY auto speed down */ |
| 4157 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4158 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 4159 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4160 | |
| 4161 | /* patch 10M & ALDPS */ |
| 4162 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4163 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4164 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4165 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4166 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4167 | rtl_writephy(tp, 0x13, 0x8084); |
| 4168 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4169 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4170 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4171 | |
| 4172 | /* Enable EEE auto-fallback function */ |
| 4173 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 4174 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 4175 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4176 | |
| 4177 | /* Enable UC LPF tune function */ |
| 4178 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4179 | rtl_writephy(tp, 0x13, 0x8012); |
| 4180 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4181 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4182 | |
| 4183 | /* set rg_sel_sdm_rate */ |
| 4184 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4185 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4186 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4187 | |
| 4188 | /* Check ALDPS bit, disable it if enabled */ |
| 4189 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4190 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4191 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4192 | |
| 4193 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4194 | } |
| 4195 | |
| 4196 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 4197 | { |
| 4198 | /* patch 10M & ALDPS */ |
| 4199 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4200 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4201 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4202 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4203 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4204 | rtl_writephy(tp, 0x13, 0x8084); |
| 4205 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4206 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4207 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4208 | |
| 4209 | /* Enable UC LPF tune function */ |
| 4210 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4211 | rtl_writephy(tp, 0x13, 0x8012); |
| 4212 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4213 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4214 | |
| 4215 | /* Set rg_sel_sdm_rate */ |
| 4216 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4217 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4218 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4219 | |
| 4220 | /* Channel estimation parameters */ |
| 4221 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4222 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4223 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4224 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4225 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4226 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4227 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4228 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4229 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4230 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4231 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4232 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4233 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4234 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4235 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4236 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4237 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4238 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4239 | rtl_writephy(tp, 0x13, 0x8110); |
| 4240 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4241 | rtl_writephy(tp, 0x13, 0x810f); |
| 4242 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4243 | rtl_writephy(tp, 0x13, 0x8111); |
| 4244 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4245 | rtl_writephy(tp, 0x13, 0x8113); |
| 4246 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4247 | rtl_writephy(tp, 0x13, 0x8115); |
| 4248 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4249 | rtl_writephy(tp, 0x13, 0x810e); |
| 4250 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4251 | rtl_writephy(tp, 0x13, 0x810c); |
| 4252 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4253 | rtl_writephy(tp, 0x13, 0x810b); |
| 4254 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4255 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4256 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4257 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4258 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4259 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4260 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4261 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4262 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4263 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4264 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4265 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4266 | |
| 4267 | /* Force PWM-mode */ |
| 4268 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4269 | rtl_writephy(tp, 0x14, 0x5065); |
| 4270 | rtl_writephy(tp, 0x14, 0xd065); |
| 4271 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4272 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4273 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4274 | rtl_writephy(tp, 0x14, 0x1065); |
| 4275 | rtl_writephy(tp, 0x14, 0x9065); |
| 4276 | rtl_writephy(tp, 0x14, 0x1065); |
| 4277 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4278 | |
| 4279 | /* Check ALDPS bit, disable it if enabled */ |
| 4280 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4281 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4282 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4283 | |
| 4284 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4285 | } |
| 4286 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4287 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4288 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4289 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4290 | { 0x1f, 0x0003 }, |
| 4291 | { 0x08, 0x441d }, |
| 4292 | { 0x01, 0x9100 }, |
| 4293 | { 0x1f, 0x0000 } |
| 4294 | }; |
| 4295 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4296 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4297 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4298 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4299 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4300 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4301 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4302 | } |
| 4303 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4304 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4305 | { |
| 4306 | static const struct phy_reg phy_reg_init[] = { |
| 4307 | { 0x1f, 0x0005 }, |
| 4308 | { 0x1a, 0x0000 }, |
| 4309 | { 0x1f, 0x0000 }, |
| 4310 | |
| 4311 | { 0x1f, 0x0004 }, |
| 4312 | { 0x1c, 0x0000 }, |
| 4313 | { 0x1f, 0x0000 }, |
| 4314 | |
| 4315 | { 0x1f, 0x0001 }, |
| 4316 | { 0x15, 0x7701 }, |
| 4317 | { 0x1f, 0x0000 } |
| 4318 | }; |
| 4319 | |
| 4320 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4321 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4322 | rtl_writephy(tp, 0x18, 0x0310); |
| 4323 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4324 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4325 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4326 | |
| 4327 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4328 | } |
| 4329 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4330 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4331 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4332 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4333 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4334 | rtl_writephy(tp, 0x18, 0x0310); |
| 4335 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4336 | |
| 4337 | rtl_apply_firmware(tp); |
| 4338 | |
| 4339 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4340 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4341 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4342 | rtl_writephy(tp, 0x10, 0x401f); |
| 4343 | rtl_writephy(tp, 0x19, 0x7030); |
| 4344 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4345 | } |
| 4346 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4347 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4348 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4349 | static const struct phy_reg phy_reg_init[] = { |
| 4350 | { 0x1f, 0x0004 }, |
| 4351 | { 0x10, 0xc07f }, |
| 4352 | { 0x19, 0x7030 }, |
| 4353 | { 0x1f, 0x0000 } |
| 4354 | }; |
| 4355 | |
| 4356 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4357 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4358 | rtl_writephy(tp, 0x18, 0x0310); |
| 4359 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4360 | |
| 4361 | rtl_apply_firmware(tp); |
| 4362 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4363 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4364 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4365 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4366 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4367 | } |
| 4368 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4369 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4370 | { |
| 4371 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4372 | |
| 4373 | rtl8169_print_mac_version(tp); |
| 4374 | |
| 4375 | switch (tp->mac_version) { |
| 4376 | case RTL_GIGA_MAC_VER_01: |
| 4377 | break; |
| 4378 | case RTL_GIGA_MAC_VER_02: |
| 4379 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4380 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4381 | break; |
| 4382 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4383 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4384 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4385 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4386 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4387 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4388 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4389 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4390 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4391 | case RTL_GIGA_MAC_VER_07: |
| 4392 | case RTL_GIGA_MAC_VER_08: |
| 4393 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4394 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4395 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4396 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4397 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4398 | break; |
| 4399 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4400 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4401 | break; |
| 4402 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4403 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4404 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4405 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4406 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4407 | break; |
| 4408 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4409 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4410 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4411 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4412 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4413 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4414 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4415 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4416 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4417 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4418 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4419 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4420 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4421 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4422 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4423 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4424 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4425 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4426 | break; |
| 4427 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4428 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4429 | break; |
| 4430 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4431 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4432 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4433 | case RTL_GIGA_MAC_VER_28: |
| 4434 | rtl8168d_4_hw_phy_config(tp); |
| 4435 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4436 | case RTL_GIGA_MAC_VER_29: |
| 4437 | case RTL_GIGA_MAC_VER_30: |
| 4438 | rtl8105e_hw_phy_config(tp); |
| 4439 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4440 | case RTL_GIGA_MAC_VER_31: |
| 4441 | /* None. */ |
| 4442 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4443 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4444 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4445 | rtl8168e_1_hw_phy_config(tp); |
| 4446 | break; |
| 4447 | case RTL_GIGA_MAC_VER_34: |
| 4448 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4449 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4450 | case RTL_GIGA_MAC_VER_35: |
| 4451 | rtl8168f_1_hw_phy_config(tp); |
| 4452 | break; |
| 4453 | case RTL_GIGA_MAC_VER_36: |
| 4454 | rtl8168f_2_hw_phy_config(tp); |
| 4455 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4456 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4457 | case RTL_GIGA_MAC_VER_37: |
| 4458 | rtl8402_hw_phy_config(tp); |
| 4459 | break; |
| 4460 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4461 | case RTL_GIGA_MAC_VER_38: |
| 4462 | rtl8411_hw_phy_config(tp); |
| 4463 | break; |
| 4464 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4465 | case RTL_GIGA_MAC_VER_39: |
| 4466 | rtl8106e_hw_phy_config(tp); |
| 4467 | break; |
| 4468 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4469 | case RTL_GIGA_MAC_VER_40: |
| 4470 | rtl8168g_1_hw_phy_config(tp); |
| 4471 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4472 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4473 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4474 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4475 | rtl8168g_2_hw_phy_config(tp); |
| 4476 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4477 | case RTL_GIGA_MAC_VER_45: |
| 4478 | case RTL_GIGA_MAC_VER_47: |
| 4479 | rtl8168h_1_hw_phy_config(tp); |
| 4480 | break; |
| 4481 | case RTL_GIGA_MAC_VER_46: |
| 4482 | case RTL_GIGA_MAC_VER_48: |
| 4483 | rtl8168h_2_hw_phy_config(tp); |
| 4484 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4485 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4486 | case RTL_GIGA_MAC_VER_49: |
| 4487 | rtl8168ep_1_hw_phy_config(tp); |
| 4488 | break; |
| 4489 | case RTL_GIGA_MAC_VER_50: |
| 4490 | case RTL_GIGA_MAC_VER_51: |
| 4491 | rtl8168ep_2_hw_phy_config(tp); |
| 4492 | break; |
| 4493 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4494 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4495 | default: |
| 4496 | break; |
| 4497 | } |
| 4498 | } |
| 4499 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4500 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | struct timer_list *timer = &tp->timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4504 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4505 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4507 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4508 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4510 | * Let's delay the execution of the timer for a few ticks. |
| 4511 | */ |
| 4512 | timeout = HZ/10; |
| 4513 | goto out_mod_timer; |
| 4514 | } |
| 4515 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4516 | if (tp->link_ok(tp)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4517 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4519 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4521 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
| 4523 | out_mod_timer: |
| 4524 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4528 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4529 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4530 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4531 | } |
| 4532 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4533 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4534 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4535 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4536 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4537 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4540 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4541 | { |
| 4542 | return tp->phy_reset_pending(tp); |
| 4543 | } |
| 4544 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4545 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4546 | struct rtl8169_private *tp) |
| 4547 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4548 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4549 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4550 | } |
| 4551 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4552 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4553 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4554 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4555 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4556 | } |
| 4557 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4558 | 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] | 4559 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4560 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4561 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4562 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4563 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4564 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4565 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4566 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4567 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4568 | |
| 4569 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4570 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4571 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4572 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4573 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4574 | RTL_W8(tp, 0x82, 0x01); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4575 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4576 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4577 | } |
| 4578 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4579 | rtl8169_phy_reset(dev, tp); |
| 4580 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4581 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4582 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4583 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4584 | (tp->mii.supports_gmii ? |
| 4585 | ADVERTISED_1000baseT_Half | |
| 4586 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4587 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4588 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4589 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4590 | } |
| 4591 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4592 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4593 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4594 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4595 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4596 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4597 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4598 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4599 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4600 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4601 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4602 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4603 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4604 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4605 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4606 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4607 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4608 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4609 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4613 | { |
| 4614 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4615 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4616 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4617 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4618 | ret = eth_mac_addr(dev, p); |
| 4619 | if (ret) |
| 4620 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4621 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4622 | pm_runtime_get_noresume(d); |
| 4623 | |
| 4624 | if (pm_runtime_active(d)) |
| 4625 | rtl_rar_set(tp, dev->dev_addr); |
| 4626 | |
| 4627 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4628 | |
| 4629 | return 0; |
| 4630 | } |
| 4631 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4632 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4633 | { |
| 4634 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4635 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4636 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4637 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4638 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4639 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4640 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4641 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4642 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4643 | switch (cmd) { |
| 4644 | case SIOCGMIIPHY: |
| 4645 | data->phy_id = 32; /* Internal PHY */ |
| 4646 | return 0; |
| 4647 | |
| 4648 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4649 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4650 | return 0; |
| 4651 | |
| 4652 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4653 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4654 | return 0; |
| 4655 | } |
| 4656 | return -EOPNOTSUPP; |
| 4657 | } |
| 4658 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4659 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4660 | { |
| 4661 | return -EOPNOTSUPP; |
| 4662 | } |
| 4663 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4664 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4665 | { |
| 4666 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4667 | |
| 4668 | switch (tp->mac_version) { |
| 4669 | case RTL_GIGA_MAC_VER_27: |
| 4670 | ops->write = r8168dp_1_mdio_write; |
| 4671 | ops->read = r8168dp_1_mdio_read; |
| 4672 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4673 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4674 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4675 | ops->write = r8168dp_2_mdio_write; |
| 4676 | ops->read = r8168dp_2_mdio_read; |
| 4677 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4678 | case RTL_GIGA_MAC_VER_40: |
| 4679 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4680 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4681 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4682 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4683 | case RTL_GIGA_MAC_VER_45: |
| 4684 | case RTL_GIGA_MAC_VER_46: |
| 4685 | case RTL_GIGA_MAC_VER_47: |
| 4686 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4687 | case RTL_GIGA_MAC_VER_49: |
| 4688 | case RTL_GIGA_MAC_VER_50: |
| 4689 | case RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4690 | ops->write = r8168g_mdio_write; |
| 4691 | ops->read = r8168g_mdio_read; |
| 4692 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4693 | default: |
| 4694 | ops->write = r8169_mdio_write; |
| 4695 | ops->read = r8169_mdio_read; |
| 4696 | break; |
| 4697 | } |
| 4698 | } |
| 4699 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4700 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4701 | { |
| 4702 | u32 adv; |
| 4703 | int lpa; |
| 4704 | |
| 4705 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4706 | lpa = rtl_readphy(tp, MII_LPA); |
| 4707 | |
| 4708 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4709 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4710 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4711 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4712 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4713 | else |
| 4714 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4715 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4716 | (tp->mii.supports_gmii ? |
| 4717 | ADVERTISED_1000baseT_Half | |
| 4718 | ADVERTISED_1000baseT_Full : 0); |
| 4719 | |
| 4720 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4721 | adv); |
| 4722 | } |
| 4723 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4724 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4725 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4726 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4727 | case RTL_GIGA_MAC_VER_25: |
| 4728 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4729 | case RTL_GIGA_MAC_VER_29: |
| 4730 | case RTL_GIGA_MAC_VER_30: |
| 4731 | case RTL_GIGA_MAC_VER_32: |
| 4732 | case RTL_GIGA_MAC_VER_33: |
| 4733 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4734 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4735 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4736 | case RTL_GIGA_MAC_VER_39: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4737 | case RTL_GIGA_MAC_VER_40: |
| 4738 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4739 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4740 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4741 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4742 | case RTL_GIGA_MAC_VER_45: |
| 4743 | case RTL_GIGA_MAC_VER_46: |
| 4744 | case RTL_GIGA_MAC_VER_47: |
| 4745 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4746 | case RTL_GIGA_MAC_VER_49: |
| 4747 | case RTL_GIGA_MAC_VER_50: |
| 4748 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4749 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4750 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4751 | break; |
| 4752 | default: |
| 4753 | break; |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4758 | { |
| 4759 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 4760 | return false; |
| 4761 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4762 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4763 | rtl_wol_suspend_quirk(tp); |
| 4764 | |
| 4765 | return true; |
| 4766 | } |
| 4767 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4768 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 4769 | { |
| 4770 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4771 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4772 | } |
| 4773 | |
| 4774 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 4775 | { |
| 4776 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4777 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4778 | } |
| 4779 | |
| 4780 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 4781 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4782 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4783 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4784 | |
| 4785 | r810x_phy_power_down(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4786 | |
| 4787 | switch (tp->mac_version) { |
| 4788 | case RTL_GIGA_MAC_VER_07: |
| 4789 | case RTL_GIGA_MAC_VER_08: |
| 4790 | case RTL_GIGA_MAC_VER_09: |
| 4791 | case RTL_GIGA_MAC_VER_10: |
| 4792 | case RTL_GIGA_MAC_VER_13: |
| 4793 | case RTL_GIGA_MAC_VER_16: |
| 4794 | break; |
| 4795 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4796 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4797 | break; |
| 4798 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 4802 | { |
| 4803 | r810x_phy_power_up(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4804 | |
| 4805 | switch (tp->mac_version) { |
| 4806 | case RTL_GIGA_MAC_VER_07: |
| 4807 | case RTL_GIGA_MAC_VER_08: |
| 4808 | case RTL_GIGA_MAC_VER_09: |
| 4809 | case RTL_GIGA_MAC_VER_10: |
| 4810 | case RTL_GIGA_MAC_VER_13: |
| 4811 | case RTL_GIGA_MAC_VER_16: |
| 4812 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4813 | case RTL_GIGA_MAC_VER_47: |
| 4814 | case RTL_GIGA_MAC_VER_48: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4815 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4816 | break; |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4817 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4818 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4819 | break; |
| 4820 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4824 | { |
| 4825 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4826 | switch (tp->mac_version) { |
| 4827 | case RTL_GIGA_MAC_VER_11: |
| 4828 | case RTL_GIGA_MAC_VER_12: |
| 4829 | case RTL_GIGA_MAC_VER_17: |
| 4830 | case RTL_GIGA_MAC_VER_18: |
| 4831 | case RTL_GIGA_MAC_VER_19: |
| 4832 | case RTL_GIGA_MAC_VER_20: |
| 4833 | case RTL_GIGA_MAC_VER_21: |
| 4834 | case RTL_GIGA_MAC_VER_22: |
| 4835 | case RTL_GIGA_MAC_VER_23: |
| 4836 | case RTL_GIGA_MAC_VER_24: |
| 4837 | case RTL_GIGA_MAC_VER_25: |
| 4838 | case RTL_GIGA_MAC_VER_26: |
| 4839 | case RTL_GIGA_MAC_VER_27: |
| 4840 | case RTL_GIGA_MAC_VER_28: |
| 4841 | case RTL_GIGA_MAC_VER_31: |
| 4842 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4843 | break; |
| 4844 | default: |
| 4845 | break; |
| 4846 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4847 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4848 | } |
| 4849 | |
| 4850 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4851 | { |
| 4852 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4853 | switch (tp->mac_version) { |
| 4854 | case RTL_GIGA_MAC_VER_32: |
| 4855 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4856 | case RTL_GIGA_MAC_VER_40: |
| 4857 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4858 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4859 | break; |
| 4860 | |
| 4861 | case RTL_GIGA_MAC_VER_11: |
| 4862 | case RTL_GIGA_MAC_VER_12: |
| 4863 | case RTL_GIGA_MAC_VER_17: |
| 4864 | case RTL_GIGA_MAC_VER_18: |
| 4865 | case RTL_GIGA_MAC_VER_19: |
| 4866 | case RTL_GIGA_MAC_VER_20: |
| 4867 | case RTL_GIGA_MAC_VER_21: |
| 4868 | case RTL_GIGA_MAC_VER_22: |
| 4869 | case RTL_GIGA_MAC_VER_23: |
| 4870 | case RTL_GIGA_MAC_VER_24: |
| 4871 | case RTL_GIGA_MAC_VER_25: |
| 4872 | case RTL_GIGA_MAC_VER_26: |
| 4873 | case RTL_GIGA_MAC_VER_27: |
| 4874 | case RTL_GIGA_MAC_VER_28: |
| 4875 | case RTL_GIGA_MAC_VER_31: |
| 4876 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4877 | default: |
| 4878 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4879 | break; |
| 4880 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4884 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4885 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4886 | return; |
| 4887 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4888 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 4889 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4890 | (RTL_R16(tp, CPlusCmd) & ASF)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4891 | return; |
| 4892 | } |
| 4893 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4894 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4895 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4896 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4897 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4898 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4899 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4900 | |
| 4901 | r8168_phy_power_down(tp); |
| 4902 | |
| 4903 | switch (tp->mac_version) { |
| 4904 | case RTL_GIGA_MAC_VER_25: |
| 4905 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4906 | case RTL_GIGA_MAC_VER_27: |
| 4907 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4908 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4909 | case RTL_GIGA_MAC_VER_32: |
| 4910 | case RTL_GIGA_MAC_VER_33: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4911 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4912 | case RTL_GIGA_MAC_VER_45: |
| 4913 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4914 | case RTL_GIGA_MAC_VER_50: |
| 4915 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4916 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4917 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4918 | case RTL_GIGA_MAC_VER_40: |
| 4919 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4920 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4921 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4922 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4923 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4924 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4929 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4930 | switch (tp->mac_version) { |
| 4931 | case RTL_GIGA_MAC_VER_25: |
| 4932 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4933 | case RTL_GIGA_MAC_VER_27: |
| 4934 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4935 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4936 | case RTL_GIGA_MAC_VER_32: |
| 4937 | case RTL_GIGA_MAC_VER_33: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4938 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4939 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4940 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4941 | case RTL_GIGA_MAC_VER_45: |
| 4942 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4943 | case RTL_GIGA_MAC_VER_50: |
| 4944 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4945 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4946 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4947 | case RTL_GIGA_MAC_VER_40: |
| 4948 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4949 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4950 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4951 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4952 | 0x00000000, ERIAR_EXGMAC); |
| 4953 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | r8168_phy_power_up(tp); |
| 4957 | } |
| 4958 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4959 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 4960 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4961 | { |
| 4962 | if (op) |
| 4963 | op(tp); |
| 4964 | } |
| 4965 | |
| 4966 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4967 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4968 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4972 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4973 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4974 | } |
| 4975 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4976 | static void rtl_init_pll_power_ops(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4977 | { |
| 4978 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 4979 | |
| 4980 | switch (tp->mac_version) { |
| 4981 | case RTL_GIGA_MAC_VER_07: |
| 4982 | case RTL_GIGA_MAC_VER_08: |
| 4983 | case RTL_GIGA_MAC_VER_09: |
| 4984 | case RTL_GIGA_MAC_VER_10: |
| 4985 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4986 | case RTL_GIGA_MAC_VER_29: |
| 4987 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4988 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4989 | case RTL_GIGA_MAC_VER_39: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4990 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4991 | case RTL_GIGA_MAC_VER_47: |
| 4992 | case RTL_GIGA_MAC_VER_48: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4993 | ops->down = r810x_pll_power_down; |
| 4994 | ops->up = r810x_pll_power_up; |
| 4995 | break; |
| 4996 | |
| 4997 | case RTL_GIGA_MAC_VER_11: |
| 4998 | case RTL_GIGA_MAC_VER_12: |
| 4999 | case RTL_GIGA_MAC_VER_17: |
| 5000 | case RTL_GIGA_MAC_VER_18: |
| 5001 | case RTL_GIGA_MAC_VER_19: |
| 5002 | case RTL_GIGA_MAC_VER_20: |
| 5003 | case RTL_GIGA_MAC_VER_21: |
| 5004 | case RTL_GIGA_MAC_VER_22: |
| 5005 | case RTL_GIGA_MAC_VER_23: |
| 5006 | case RTL_GIGA_MAC_VER_24: |
| 5007 | case RTL_GIGA_MAC_VER_25: |
| 5008 | case RTL_GIGA_MAC_VER_26: |
| 5009 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5010 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5011 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5012 | case RTL_GIGA_MAC_VER_32: |
| 5013 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5014 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5015 | case RTL_GIGA_MAC_VER_35: |
| 5016 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5017 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5018 | case RTL_GIGA_MAC_VER_40: |
| 5019 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5020 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5021 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5022 | case RTL_GIGA_MAC_VER_45: |
| 5023 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5024 | case RTL_GIGA_MAC_VER_49: |
| 5025 | case RTL_GIGA_MAC_VER_50: |
| 5026 | case RTL_GIGA_MAC_VER_51: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5027 | ops->down = r8168_pll_power_down; |
| 5028 | ops->up = r8168_pll_power_up; |
| 5029 | break; |
| 5030 | |
| 5031 | default: |
| 5032 | ops->down = NULL; |
| 5033 | ops->up = NULL; |
| 5034 | break; |
| 5035 | } |
| 5036 | } |
| 5037 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5038 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 5039 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5040 | switch (tp->mac_version) { |
| 5041 | case RTL_GIGA_MAC_VER_01: |
| 5042 | case RTL_GIGA_MAC_VER_02: |
| 5043 | case RTL_GIGA_MAC_VER_03: |
| 5044 | case RTL_GIGA_MAC_VER_04: |
| 5045 | case RTL_GIGA_MAC_VER_05: |
| 5046 | case RTL_GIGA_MAC_VER_06: |
| 5047 | case RTL_GIGA_MAC_VER_10: |
| 5048 | case RTL_GIGA_MAC_VER_11: |
| 5049 | case RTL_GIGA_MAC_VER_12: |
| 5050 | case RTL_GIGA_MAC_VER_13: |
| 5051 | case RTL_GIGA_MAC_VER_14: |
| 5052 | case RTL_GIGA_MAC_VER_15: |
| 5053 | case RTL_GIGA_MAC_VER_16: |
| 5054 | case RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5055 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5056 | break; |
| 5057 | case RTL_GIGA_MAC_VER_18: |
| 5058 | case RTL_GIGA_MAC_VER_19: |
| 5059 | case RTL_GIGA_MAC_VER_20: |
| 5060 | case RTL_GIGA_MAC_VER_21: |
| 5061 | case RTL_GIGA_MAC_VER_22: |
| 5062 | case RTL_GIGA_MAC_VER_23: |
| 5063 | case RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 5064 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 5065 | case RTL_GIGA_MAC_VER_35: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5066 | 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] | 5067 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5068 | case RTL_GIGA_MAC_VER_40: |
| 5069 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5070 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5071 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5072 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5073 | case RTL_GIGA_MAC_VER_45: |
| 5074 | case RTL_GIGA_MAC_VER_46: |
| 5075 | case RTL_GIGA_MAC_VER_47: |
| 5076 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5077 | case RTL_GIGA_MAC_VER_49: |
| 5078 | case RTL_GIGA_MAC_VER_50: |
| 5079 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5080 | 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] | 5081 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5082 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5083 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5084 | break; |
| 5085 | } |
| 5086 | } |
| 5087 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5088 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 5089 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 5090 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5091 | } |
| 5092 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5093 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5094 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5095 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5096 | rtl_generic_op(tp, tp->jumbo_ops.enable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5097 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5101 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5102 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5103 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5104 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5108 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5109 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 5110 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | Jumbo_En1); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5111 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5115 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5116 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 5117 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5118 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5122 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5123 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5127 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5128 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5132 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5133 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 5134 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 5135 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5136 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5137 | } |
| 5138 | |
| 5139 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5140 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5141 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 5142 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 5143 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5144 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5148 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5149 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 5150 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5151 | } |
| 5152 | |
| 5153 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5154 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5155 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5156 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5160 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5161 | r8168b_0_hw_jumbo_enable(tp); |
| 5162 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5163 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | (1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5167 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5168 | r8168b_0_hw_jumbo_disable(tp); |
| 5169 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5170 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5171 | } |
| 5172 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5173 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5174 | { |
| 5175 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 5176 | |
| 5177 | switch (tp->mac_version) { |
| 5178 | case RTL_GIGA_MAC_VER_11: |
| 5179 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 5180 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 5181 | break; |
| 5182 | case RTL_GIGA_MAC_VER_12: |
| 5183 | case RTL_GIGA_MAC_VER_17: |
| 5184 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 5185 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 5186 | break; |
| 5187 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 5188 | case RTL_GIGA_MAC_VER_19: |
| 5189 | case RTL_GIGA_MAC_VER_20: |
| 5190 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 5191 | case RTL_GIGA_MAC_VER_22: |
| 5192 | case RTL_GIGA_MAC_VER_23: |
| 5193 | case RTL_GIGA_MAC_VER_24: |
| 5194 | case RTL_GIGA_MAC_VER_25: |
| 5195 | case RTL_GIGA_MAC_VER_26: |
| 5196 | ops->disable = r8168c_hw_jumbo_disable; |
| 5197 | ops->enable = r8168c_hw_jumbo_enable; |
| 5198 | break; |
| 5199 | case RTL_GIGA_MAC_VER_27: |
| 5200 | case RTL_GIGA_MAC_VER_28: |
| 5201 | ops->disable = r8168dp_hw_jumbo_disable; |
| 5202 | ops->enable = r8168dp_hw_jumbo_enable; |
| 5203 | break; |
| 5204 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 5205 | case RTL_GIGA_MAC_VER_32: |
| 5206 | case RTL_GIGA_MAC_VER_33: |
| 5207 | case RTL_GIGA_MAC_VER_34: |
| 5208 | ops->disable = r8168e_hw_jumbo_disable; |
| 5209 | ops->enable = r8168e_hw_jumbo_enable; |
| 5210 | break; |
| 5211 | |
| 5212 | /* |
| 5213 | * No action needed for jumbo frames with 8169. |
| 5214 | * No jumbo for 810x at all. |
| 5215 | */ |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5216 | case RTL_GIGA_MAC_VER_40: |
| 5217 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5218 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5219 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5220 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5221 | case RTL_GIGA_MAC_VER_45: |
| 5222 | case RTL_GIGA_MAC_VER_46: |
| 5223 | case RTL_GIGA_MAC_VER_47: |
| 5224 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5225 | case RTL_GIGA_MAC_VER_49: |
| 5226 | case RTL_GIGA_MAC_VER_50: |
| 5227 | case RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5228 | default: |
| 5229 | ops->disable = NULL; |
| 5230 | ops->enable = NULL; |
| 5231 | break; |
| 5232 | } |
| 5233 | } |
| 5234 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5235 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 5236 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5237 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5238 | } |
| 5239 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5240 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 5241 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5242 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5243 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5244 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5247 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 5248 | { |
| 5249 | struct rtl_fw *rtl_fw; |
| 5250 | const char *name; |
| 5251 | int rc = -ENOMEM; |
| 5252 | |
| 5253 | name = rtl_lookup_firmware_name(tp); |
| 5254 | if (!name) |
| 5255 | goto out_no_firmware; |
| 5256 | |
| 5257 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 5258 | if (!rtl_fw) |
| 5259 | goto err_warn; |
| 5260 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5261 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5262 | if (rc < 0) |
| 5263 | goto err_free; |
| 5264 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5265 | rc = rtl_check_firmware(tp, rtl_fw); |
| 5266 | if (rc < 0) |
| 5267 | goto err_release_firmware; |
| 5268 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5269 | tp->rtl_fw = rtl_fw; |
| 5270 | out: |
| 5271 | return; |
| 5272 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5273 | err_release_firmware: |
| 5274 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5275 | err_free: |
| 5276 | kfree(rtl_fw); |
| 5277 | err_warn: |
| 5278 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 5279 | name, rc); |
| 5280 | out_no_firmware: |
| 5281 | tp->rtl_fw = NULL; |
| 5282 | goto out; |
| 5283 | } |
| 5284 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5285 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 5286 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5287 | if (IS_ERR(tp->rtl_fw)) |
| 5288 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5291 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 5292 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5293 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5294 | } |
| 5295 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5296 | DECLARE_RTL_COND(rtl_npq_cond) |
| 5297 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5298 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 5302 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5303 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5304 | } |
| 5305 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5306 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | { |
| 5308 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5309 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5311 | rtl_rx_close(tp); |
| 5312 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 5313 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5314 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 5315 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5316 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5317 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5318 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 5319 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 5320 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 5321 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 5322 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 5323 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 5324 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 5325 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 5326 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 5327 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
| 5328 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 5329 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5330 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 5331 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 5332 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 5333 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5334 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5335 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5336 | } else { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5337 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5338 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5339 | } |
| 5340 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5341 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5344 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5345 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5346 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5347 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5348 | (InterFrameGap << TxInterFrameGapShift)); |
| 5349 | } |
| 5350 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5351 | static void rtl_hw_start(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5352 | { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5353 | tp->hw_start(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5354 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5355 | } |
| 5356 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5357 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5358 | { |
| 5359 | /* |
| 5360 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 5361 | * register to be written before TxDescAddrLow to work. |
| 5362 | * Switching from MMIO to I/O access fixes the issue as well. |
| 5363 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5364 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 5365 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 5366 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 5367 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5368 | } |
| 5369 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5370 | static u16 rtl_rw_cpluscmd(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5371 | { |
| 5372 | u16 cmd; |
| 5373 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5374 | cmd = RTL_R16(tp, CPlusCmd); |
| 5375 | RTL_W16(tp, CPlusCmd, cmd); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5376 | return cmd; |
| 5377 | } |
| 5378 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5379 | static void rtl_set_rx_max_size(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5380 | { |
| 5381 | /* Low hurts. Let's disable the filtering. */ |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5382 | RTL_W16(tp, RxMaxSize, R8169_RX_BUF_SIZE + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5383 | } |
| 5384 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5385 | 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] | 5386 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5387 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5388 | u32 mac_version; |
| 5389 | u32 clk; |
| 5390 | u32 val; |
| 5391 | } cfg2_info [] = { |
| 5392 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 5393 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 5394 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 5395 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5396 | }; |
| 5397 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5398 | unsigned int i; |
| 5399 | u32 clk; |
| 5400 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5401 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 5402 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5403 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5404 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5405 | break; |
| 5406 | } |
| 5407 | } |
| 5408 | } |
| 5409 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5410 | static void rtl_set_rx_mode(struct net_device *dev) |
| 5411 | { |
| 5412 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5413 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 5414 | int rx_mode; |
| 5415 | u32 tmp = 0; |
| 5416 | |
| 5417 | if (dev->flags & IFF_PROMISC) { |
| 5418 | /* Unconditionally log net taps. */ |
| 5419 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 5420 | rx_mode = |
| 5421 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5422 | AcceptAllPhys; |
| 5423 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5424 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 5425 | (dev->flags & IFF_ALLMULTI)) { |
| 5426 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5427 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5428 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5429 | } else { |
| 5430 | struct netdev_hw_addr *ha; |
| 5431 | |
| 5432 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5433 | mc_filter[1] = mc_filter[0] = 0; |
| 5434 | netdev_for_each_mc_addr(ha, dev) { |
| 5435 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 5436 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5437 | rx_mode |= AcceptMulticast; |
| 5438 | } |
| 5439 | } |
| 5440 | |
| 5441 | if (dev->features & NETIF_F_RXALL) |
| 5442 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5443 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5444 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5445 | |
| 5446 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5447 | u32 data = mc_filter[0]; |
| 5448 | |
| 5449 | mc_filter[0] = swab32(mc_filter[1]); |
| 5450 | mc_filter[1] = swab32(data); |
| 5451 | } |
| 5452 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5453 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5454 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5455 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5456 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 5457 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5458 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5459 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5460 | } |
| 5461 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5462 | static void rtl_hw_start_8169(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5463 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5464 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5465 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) | PCIMulRW); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5466 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5467 | } |
| 5468 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5469 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5470 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5471 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5472 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5473 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5474 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5475 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5476 | rtl_init_rxcfg(tp); |
| 5477 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5478 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 5480 | rtl_set_rx_max_size(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5482 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5483 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5484 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5485 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5486 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5488 | tp->cp_cmd |= rtl_rw_cpluscmd(tp) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5489 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5490 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5491 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5492 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5494 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | } |
| 5496 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5497 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5498 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5499 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | /* |
| 5502 | * Undocumented corner. Supposedly: |
| 5503 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5504 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5505 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5507 | rtl_set_rx_tx_desc_registers(tp); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5508 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5509 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 5510 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 5511 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 5512 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5513 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5514 | rtl_set_rx_tx_config_registers(tp); |
| 5515 | } |
| 5516 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5517 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 5518 | |
| 5519 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5520 | RTL_R8(tp, IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5521 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5522 | RTL_W32(tp, RxMissed, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5523 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 5524 | rtl_set_rx_mode(tp->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | |
| 5526 | /* no early-rx interrupts */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5527 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5529 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5530 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5531 | { |
| 5532 | if (tp->csi_ops.write) |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5533 | tp->csi_ops.write(tp, addr, value); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
| 5537 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5538 | return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5539 | } |
| 5540 | |
| 5541 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5542 | { |
| 5543 | u32 csi; |
| 5544 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5545 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5546 | rtl_csi_write(tp, 0x070c, csi | bits); |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5547 | } |
| 5548 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5549 | static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5550 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5551 | rtl_csi_access_enable(tp, 0x17000000); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5552 | } |
| 5553 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5554 | static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5555 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5556 | rtl_csi_access_enable(tp, 0x27000000); |
| 5557 | } |
| 5558 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5559 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5560 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5561 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5562 | } |
| 5563 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5564 | static void r8169_csi_write(struct rtl8169_private *tp, int addr, int value) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5565 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5566 | RTL_W32(tp, CSIDR, value); |
| 5567 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5568 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5569 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5570 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5571 | } |
| 5572 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5573 | static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5574 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5575 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5576 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5577 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5578 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5579 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5580 | } |
| 5581 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5582 | static void r8402_csi_write(struct rtl8169_private *tp, int addr, int value) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5583 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5584 | RTL_W32(tp, CSIDR, value); |
| 5585 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5586 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5587 | CSIAR_FUNC_NIC); |
| 5588 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5589 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5590 | } |
| 5591 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5592 | static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5593 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5594 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5595 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5596 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5597 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5598 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5599 | } |
| 5600 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5601 | static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5602 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5603 | RTL_W32(tp, CSIDR, value); |
| 5604 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5605 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5606 | CSIAR_FUNC_NIC2); |
| 5607 | |
| 5608 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
| 5609 | } |
| 5610 | |
| 5611 | static u32 r8411_csi_read(struct rtl8169_private *tp, int addr) |
| 5612 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5613 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5614 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5615 | |
| 5616 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5617 | RTL_R32(tp, CSIDR) : ~0; |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5618 | } |
| 5619 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5620 | static void rtl_init_csi_ops(struct rtl8169_private *tp) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5621 | { |
| 5622 | struct csi_ops *ops = &tp->csi_ops; |
| 5623 | |
| 5624 | switch (tp->mac_version) { |
| 5625 | case RTL_GIGA_MAC_VER_01: |
| 5626 | case RTL_GIGA_MAC_VER_02: |
| 5627 | case RTL_GIGA_MAC_VER_03: |
| 5628 | case RTL_GIGA_MAC_VER_04: |
| 5629 | case RTL_GIGA_MAC_VER_05: |
| 5630 | case RTL_GIGA_MAC_VER_06: |
| 5631 | case RTL_GIGA_MAC_VER_10: |
| 5632 | case RTL_GIGA_MAC_VER_11: |
| 5633 | case RTL_GIGA_MAC_VER_12: |
| 5634 | case RTL_GIGA_MAC_VER_13: |
| 5635 | case RTL_GIGA_MAC_VER_14: |
| 5636 | case RTL_GIGA_MAC_VER_15: |
| 5637 | case RTL_GIGA_MAC_VER_16: |
| 5638 | case RTL_GIGA_MAC_VER_17: |
| 5639 | ops->write = NULL; |
| 5640 | ops->read = NULL; |
| 5641 | break; |
| 5642 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5643 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5644 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5645 | ops->write = r8402_csi_write; |
| 5646 | ops->read = r8402_csi_read; |
| 5647 | break; |
| 5648 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5649 | case RTL_GIGA_MAC_VER_44: |
| 5650 | ops->write = r8411_csi_write; |
| 5651 | ops->read = r8411_csi_read; |
| 5652 | break; |
| 5653 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5654 | default: |
| 5655 | ops->write = r8169_csi_write; |
| 5656 | ops->read = r8169_csi_read; |
| 5657 | break; |
| 5658 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | struct ephy_info { |
| 5662 | unsigned int offset; |
| 5663 | u16 mask; |
| 5664 | u16 bits; |
| 5665 | }; |
| 5666 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5667 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5668 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5669 | { |
| 5670 | u16 w; |
| 5671 | |
| 5672 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5673 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5674 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5675 | e++; |
| 5676 | } |
| 5677 | } |
| 5678 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5679 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5680 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5681 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5682 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5683 | } |
| 5684 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5685 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5686 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5687 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5688 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5689 | } |
| 5690 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5691 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5692 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5693 | u8 data; |
| 5694 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5695 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5696 | |
| 5697 | if (enable) |
| 5698 | data |= Rdy_to_L23; |
| 5699 | else |
| 5700 | data &= ~Rdy_to_L23; |
| 5701 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5702 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5703 | } |
| 5704 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5705 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 5706 | EnableBist | \ |
| 5707 | Mac_dbgo_oe | \ |
| 5708 | Force_half_dup | \ |
| 5709 | Force_rxflow_en | \ |
| 5710 | Force_txflow_en | \ |
| 5711 | Cxpl_dbg_sel | \ |
| 5712 | ASF | \ |
| 5713 | PktCntrDisable | \ |
| 5714 | Mac_dbgo_sel) |
| 5715 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5716 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5717 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5718 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5719 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5720 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5721 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5722 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5723 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5724 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5725 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5726 | } |
| 5727 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5728 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5729 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5730 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5731 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5732 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5733 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5734 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5735 | } |
| 5736 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5737 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5738 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5739 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5740 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5741 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5742 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5743 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5744 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5745 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5746 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5747 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5748 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5749 | } |
| 5750 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5751 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5752 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5753 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5754 | { 0x01, 0, 0x0001 }, |
| 5755 | { 0x02, 0x0800, 0x1000 }, |
| 5756 | { 0x03, 0, 0x0042 }, |
| 5757 | { 0x06, 0x0080, 0x0000 }, |
| 5758 | { 0x07, 0, 0x2000 } |
| 5759 | }; |
| 5760 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5761 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5762 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5763 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5764 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5765 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5766 | } |
| 5767 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5768 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5769 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5770 | rtl_csi_access_enable_2(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5771 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5772 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5773 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5774 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5775 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5776 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5777 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5778 | } |
| 5779 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5780 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5781 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5782 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5783 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5784 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5785 | |
| 5786 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5787 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5788 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5789 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5790 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5791 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5792 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5793 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5794 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5795 | } |
| 5796 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5797 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5798 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5799 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5800 | { 0x02, 0x0800, 0x1000 }, |
| 5801 | { 0x03, 0, 0x0002 }, |
| 5802 | { 0x06, 0x0080, 0x0000 } |
| 5803 | }; |
| 5804 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5805 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5806 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5807 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5808 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5809 | 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] | 5810 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5811 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5812 | } |
| 5813 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5814 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5815 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5816 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5817 | { 0x01, 0, 0x0001 }, |
| 5818 | { 0x03, 0x0400, 0x0220 } |
| 5819 | }; |
| 5820 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5821 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5822 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5823 | 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] | 5824 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5825 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5826 | } |
| 5827 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5828 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5829 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5830 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5831 | } |
| 5832 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5833 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5834 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5835 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5836 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5837 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5838 | } |
| 5839 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5840 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5841 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5842 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5843 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5844 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5845 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5846 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5847 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5848 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5849 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5850 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5851 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5852 | } |
| 5853 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5854 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5855 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5856 | rtl_csi_access_enable_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5857 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5858 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5859 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5860 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5861 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5862 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5863 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5866 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5867 | { |
| 5868 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5869 | { 0x0b, 0x0000, 0x0048 }, |
| 5870 | { 0x19, 0x0020, 0x0050 }, |
| 5871 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5872 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5873 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5874 | rtl_csi_access_enable_1(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5875 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5876 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5877 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5878 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5879 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5880 | 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] | 5881 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5882 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5883 | } |
| 5884 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5885 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5886 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5887 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5888 | { 0x00, 0x0200, 0x0100 }, |
| 5889 | { 0x00, 0x0000, 0x0004 }, |
| 5890 | { 0x06, 0x0002, 0x0001 }, |
| 5891 | { 0x06, 0x0000, 0x0030 }, |
| 5892 | { 0x07, 0x0000, 0x2000 }, |
| 5893 | { 0x00, 0x0000, 0x0020 }, |
| 5894 | { 0x03, 0x5800, 0x2000 }, |
| 5895 | { 0x03, 0x0000, 0x0001 }, |
| 5896 | { 0x01, 0x0800, 0x1000 }, |
| 5897 | { 0x07, 0x0000, 0x4000 }, |
| 5898 | { 0x1e, 0x0000, 0x2000 }, |
| 5899 | { 0x19, 0xffff, 0xfe6c }, |
| 5900 | { 0x0a, 0x0000, 0x0040 } |
| 5901 | }; |
| 5902 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5903 | rtl_csi_access_enable_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5904 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5905 | 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] | 5906 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5907 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5908 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5909 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5910 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5911 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5912 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5913 | |
| 5914 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5915 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 5916 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5917 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5918 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5919 | } |
| 5920 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5921 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5922 | { |
| 5923 | static const struct ephy_info e_info_8168e_2[] = { |
| 5924 | { 0x09, 0x0000, 0x0080 }, |
| 5925 | { 0x19, 0x0000, 0x0224 } |
| 5926 | }; |
| 5927 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5928 | rtl_csi_access_enable_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5929 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5930 | 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] | 5931 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5932 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5933 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5934 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5935 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5936 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5937 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5938 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5939 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5940 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5941 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5942 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5943 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5944 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5945 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5946 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5947 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5948 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5949 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5950 | |
| 5951 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5952 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5953 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5954 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5955 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5956 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5957 | } |
| 5958 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5959 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5960 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5961 | rtl_csi_access_enable_2(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5962 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5963 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5964 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5965 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5966 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5967 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5968 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5969 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5970 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5971 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5972 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5973 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5974 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5975 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5976 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5977 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5978 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5979 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5980 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5981 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5982 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5983 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5984 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5985 | } |
| 5986 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5987 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5988 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5989 | static const struct ephy_info e_info_8168f_1[] = { |
| 5990 | { 0x06, 0x00c0, 0x0020 }, |
| 5991 | { 0x08, 0x0001, 0x0002 }, |
| 5992 | { 0x09, 0x0000, 0x0080 }, |
| 5993 | { 0x19, 0x0000, 0x0224 } |
| 5994 | }; |
| 5995 | |
| 5996 | rtl_hw_start_8168f(tp); |
| 5997 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5998 | 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] | 5999 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6000 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6001 | |
| 6002 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6003 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6006 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 6007 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6008 | static const struct ephy_info e_info_8168f_1[] = { |
| 6009 | { 0x06, 0x00c0, 0x0020 }, |
| 6010 | { 0x0f, 0xffff, 0x5200 }, |
| 6011 | { 0x1e, 0x0000, 0x4000 }, |
| 6012 | { 0x19, 0x0000, 0x0224 } |
| 6013 | }; |
| 6014 | |
| 6015 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6016 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6017 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6018 | 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] | 6019 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6020 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6021 | } |
| 6022 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6023 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6024 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6025 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6026 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6027 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 6028 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6029 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6030 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6031 | |
| 6032 | rtl_csi_access_enable_1(tp); |
| 6033 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6034 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6035 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6036 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6037 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6038 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6039 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6040 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6041 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6042 | |
| 6043 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6044 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6045 | |
| 6046 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6047 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6048 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6049 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6050 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6051 | |
| 6052 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6053 | } |
| 6054 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6055 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 6056 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6057 | static const struct ephy_info e_info_8168g_1[] = { |
| 6058 | { 0x00, 0x0000, 0x0008 }, |
| 6059 | { 0x0c, 0x37d0, 0x0820 }, |
| 6060 | { 0x1e, 0x0000, 0x0001 }, |
| 6061 | { 0x19, 0x8000, 0x0000 } |
| 6062 | }; |
| 6063 | |
| 6064 | rtl_hw_start_8168g(tp); |
| 6065 | |
| 6066 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6067 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6068 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6069 | rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1)); |
| 6070 | } |
| 6071 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6072 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 6073 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6074 | static const struct ephy_info e_info_8168g_2[] = { |
| 6075 | { 0x00, 0x0000, 0x0008 }, |
| 6076 | { 0x0c, 0x3df0, 0x0200 }, |
| 6077 | { 0x19, 0xffff, 0xfc00 }, |
| 6078 | { 0x1e, 0xffff, 0x20eb } |
| 6079 | }; |
| 6080 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6081 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6082 | |
| 6083 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6084 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6085 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6086 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 6087 | } |
| 6088 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6089 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 6090 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6091 | static const struct ephy_info e_info_8411_2[] = { |
| 6092 | { 0x00, 0x0000, 0x0008 }, |
| 6093 | { 0x0c, 0x3df0, 0x0200 }, |
| 6094 | { 0x0f, 0xffff, 0x5200 }, |
| 6095 | { 0x19, 0x0020, 0x0000 }, |
| 6096 | { 0x1e, 0x0000, 0x2000 } |
| 6097 | }; |
| 6098 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6099 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6100 | |
| 6101 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6102 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6103 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6104 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
| 6105 | } |
| 6106 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6107 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 6108 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 6109 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6110 | u32 data; |
| 6111 | static const struct ephy_info e_info_8168h_1[] = { |
| 6112 | { 0x1e, 0x0800, 0x0001 }, |
| 6113 | { 0x1d, 0x0000, 0x0800 }, |
| 6114 | { 0x05, 0xffff, 0x2089 }, |
| 6115 | { 0x06, 0xffff, 0x5881 }, |
| 6116 | { 0x04, 0xffff, 0x154a }, |
| 6117 | { 0x01, 0xffff, 0x068b } |
| 6118 | }; |
| 6119 | |
| 6120 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6121 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6122 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6123 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 6124 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6125 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6126 | |
| 6127 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6128 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6129 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6130 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6131 | |
| 6132 | rtl_csi_access_enable_1(tp); |
| 6133 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6134 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6135 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6136 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6137 | 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] | 6138 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6139 | 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] | 6140 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6141 | 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] | 6142 | |
| 6143 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6144 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6145 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6146 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6147 | |
| 6148 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6149 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6150 | |
| 6151 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6152 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6153 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6154 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6155 | 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] | 6156 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6157 | 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] | 6158 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6159 | 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] | 6160 | |
| 6161 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6162 | |
| 6163 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 6164 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6165 | rtl_writephy(tp, 0x1f, 0x0000); |
| 6166 | if (rg_saw_cnt > 0) { |
| 6167 | u16 sw_cnt_1ms_ini; |
| 6168 | |
| 6169 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 6170 | sw_cnt_1ms_ini &= 0x0fff; |
| 6171 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6172 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6173 | data |= sw_cnt_1ms_ini; |
| 6174 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 6175 | } |
| 6176 | |
| 6177 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6178 | data &= ~0xf0; |
| 6179 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6180 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 6181 | |
| 6182 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6183 | data &= ~0x6000; |
| 6184 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6185 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 6186 | |
| 6187 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6188 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6189 | data |= 0x017f; |
| 6190 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 6191 | |
| 6192 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6193 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6194 | data |= 0x047f; |
| 6195 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 6196 | |
| 6197 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 6198 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 6199 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 6200 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
| 6201 | } |
| 6202 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6203 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 6204 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 6205 | rtl8168ep_stop_cmac(tp); |
| 6206 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6207 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6208 | |
| 6209 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6210 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 6211 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 6212 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6213 | |
| 6214 | rtl_csi_access_enable_1(tp); |
| 6215 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6216 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6217 | |
| 6218 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6219 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 6220 | |
| 6221 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 6222 | |
| 6223 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6224 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6225 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6226 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6227 | |
| 6228 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6229 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6230 | |
| 6231 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6232 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6233 | |
| 6234 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6235 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6236 | 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] | 6237 | |
| 6238 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6239 | } |
| 6240 | |
| 6241 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 6242 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6243 | static const struct ephy_info e_info_8168ep_1[] = { |
| 6244 | { 0x00, 0xffff, 0x10ab }, |
| 6245 | { 0x06, 0xffff, 0xf030 }, |
| 6246 | { 0x08, 0xffff, 0x2006 }, |
| 6247 | { 0x0d, 0xffff, 0x1666 }, |
| 6248 | { 0x0c, 0x3ff0, 0x0000 } |
| 6249 | }; |
| 6250 | |
| 6251 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6252 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6253 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6254 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 6255 | |
| 6256 | rtl_hw_start_8168ep(tp); |
| 6257 | } |
| 6258 | |
| 6259 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 6260 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6261 | static const struct ephy_info e_info_8168ep_2[] = { |
| 6262 | { 0x00, 0xffff, 0x10a3 }, |
| 6263 | { 0x19, 0xffff, 0xfc00 }, |
| 6264 | { 0x1e, 0xffff, 0x20ea } |
| 6265 | }; |
| 6266 | |
| 6267 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6268 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6269 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6270 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 6271 | |
| 6272 | rtl_hw_start_8168ep(tp); |
| 6273 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6274 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6275 | 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] | 6276 | } |
| 6277 | |
| 6278 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 6279 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6280 | u32 data; |
| 6281 | static const struct ephy_info e_info_8168ep_3[] = { |
| 6282 | { 0x00, 0xffff, 0x10a3 }, |
| 6283 | { 0x19, 0xffff, 0x7c00 }, |
| 6284 | { 0x1e, 0xffff, 0x20eb }, |
| 6285 | { 0x0d, 0xffff, 0x1666 } |
| 6286 | }; |
| 6287 | |
| 6288 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6289 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6290 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6291 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 6292 | |
| 6293 | rtl_hw_start_8168ep(tp); |
| 6294 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6295 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6296 | 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] | 6297 | |
| 6298 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 6299 | data &= 0xf000; |
| 6300 | data |= 0x0271; |
| 6301 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 6302 | |
| 6303 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 6304 | data &= 0xff00; |
| 6305 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 6306 | |
| 6307 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 6308 | data |= 0x0080; |
| 6309 | r8168_mac_ocp_write(tp, 0xe860, data); |
| 6310 | } |
| 6311 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6312 | static void rtl_hw_start_8168(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6313 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6314 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6315 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6316 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6317 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6318 | rtl_set_rx_max_size(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6319 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6320 | tp->cp_cmd |= RTL_R16(tp, CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6321 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6322 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6323 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6324 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6325 | |
| 6326 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6327 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6328 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 6329 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6330 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6331 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6332 | rtl_set_rx_tx_desc_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6333 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6334 | rtl_set_rx_tx_config_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6335 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6336 | RTL_R8(tp, IntrMask); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6337 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6338 | switch (tp->mac_version) { |
| 6339 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6340 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6341 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6342 | |
| 6343 | case RTL_GIGA_MAC_VER_12: |
| 6344 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6345 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6346 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6347 | |
| 6348 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6349 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6350 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6351 | |
| 6352 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6353 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6354 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6355 | |
| 6356 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6357 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6358 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6359 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6360 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6361 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6362 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6363 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6364 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6365 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6366 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6367 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6368 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6369 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6370 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6371 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6372 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6373 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6374 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6375 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6376 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 6377 | case RTL_GIGA_MAC_VER_26: |
| 6378 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6379 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6380 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6381 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6382 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6383 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6384 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6385 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6386 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6387 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6388 | break; |
| 6389 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6390 | case RTL_GIGA_MAC_VER_32: |
| 6391 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6392 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6393 | break; |
| 6394 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6395 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6396 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6397 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6398 | case RTL_GIGA_MAC_VER_35: |
| 6399 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6400 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6401 | break; |
| 6402 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6403 | case RTL_GIGA_MAC_VER_38: |
| 6404 | rtl_hw_start_8411(tp); |
| 6405 | break; |
| 6406 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6407 | case RTL_GIGA_MAC_VER_40: |
| 6408 | case RTL_GIGA_MAC_VER_41: |
| 6409 | rtl_hw_start_8168g_1(tp); |
| 6410 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6411 | case RTL_GIGA_MAC_VER_42: |
| 6412 | rtl_hw_start_8168g_2(tp); |
| 6413 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6414 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6415 | case RTL_GIGA_MAC_VER_44: |
| 6416 | rtl_hw_start_8411_2(tp); |
| 6417 | break; |
| 6418 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6419 | case RTL_GIGA_MAC_VER_45: |
| 6420 | case RTL_GIGA_MAC_VER_46: |
| 6421 | rtl_hw_start_8168h_1(tp); |
| 6422 | break; |
| 6423 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6424 | case RTL_GIGA_MAC_VER_49: |
| 6425 | rtl_hw_start_8168ep_1(tp); |
| 6426 | break; |
| 6427 | |
| 6428 | case RTL_GIGA_MAC_VER_50: |
| 6429 | rtl_hw_start_8168ep_2(tp); |
| 6430 | break; |
| 6431 | |
| 6432 | case RTL_GIGA_MAC_VER_51: |
| 6433 | rtl_hw_start_8168ep_3(tp); |
| 6434 | break; |
| 6435 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6436 | default: |
| 6437 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6438 | tp->dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6439 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6440 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6441 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6442 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6443 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6444 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6445 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6446 | rtl_set_rx_mode(tp->dev); |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 6447 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6448 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6450 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6451 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 6452 | EnableBist | \ |
| 6453 | Mac_dbgo_oe | \ |
| 6454 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 6455 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6456 | Force_txflow_en | \ |
| 6457 | Cxpl_dbg_sel | \ |
| 6458 | ASF | \ |
| 6459 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6460 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6461 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6462 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6463 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6464 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6465 | { 0x01, 0, 0x6e65 }, |
| 6466 | { 0x02, 0, 0x091f }, |
| 6467 | { 0x03, 0, 0xc2f9 }, |
| 6468 | { 0x06, 0, 0xafb5 }, |
| 6469 | { 0x07, 0, 0x0e00 }, |
| 6470 | { 0x19, 0, 0xec80 }, |
| 6471 | { 0x01, 0, 0x2e65 }, |
| 6472 | { 0x01, 0, 0x6e65 } |
| 6473 | }; |
| 6474 | u8 cfg1; |
| 6475 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6476 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6477 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6478 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6479 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6480 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6481 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6482 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6483 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6484 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6485 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6486 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6487 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6488 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6489 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6490 | 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] | 6491 | } |
| 6492 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6493 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6494 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6495 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6496 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6497 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6498 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6499 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 6500 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6501 | } |
| 6502 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6503 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6504 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6505 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6506 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6507 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6508 | } |
| 6509 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6510 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6511 | { |
| 6512 | static const struct ephy_info e_info_8105e_1[] = { |
| 6513 | { 0x07, 0, 0x4000 }, |
| 6514 | { 0x19, 0, 0x0200 }, |
| 6515 | { 0x19, 0, 0x0020 }, |
| 6516 | { 0x1e, 0, 0x2000 }, |
| 6517 | { 0x03, 0, 0x0001 }, |
| 6518 | { 0x19, 0, 0x0100 }, |
| 6519 | { 0x19, 0, 0x0004 }, |
| 6520 | { 0x0a, 0, 0x0020 } |
| 6521 | }; |
| 6522 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6523 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6524 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6525 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6526 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6527 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6528 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6529 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6530 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6531 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6532 | 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] | 6533 | |
| 6534 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6535 | } |
| 6536 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6537 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6538 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6539 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6540 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6541 | } |
| 6542 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6543 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 6544 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6545 | static const struct ephy_info e_info_8402[] = { |
| 6546 | { 0x19, 0xffff, 0xff64 }, |
| 6547 | { 0x1e, 0, 0x4000 } |
| 6548 | }; |
| 6549 | |
| 6550 | rtl_csi_access_enable_2(tp); |
| 6551 | |
| 6552 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6553 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6554 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6555 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 6556 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6557 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6558 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6559 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6560 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6561 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6562 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6563 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6564 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6565 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6566 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6567 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6568 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6569 | |
| 6570 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6571 | } |
| 6572 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6573 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6574 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6575 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6576 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6577 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6578 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 6579 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6580 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6581 | |
| 6582 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6583 | } |
| 6584 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6585 | static void rtl_hw_start_8101(struct rtl8169_private *tp) |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6586 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6587 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6588 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6589 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6590 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6591 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6592 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6593 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6594 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6595 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6596 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6597 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6598 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6599 | rtl_set_rx_max_size(tp); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6600 | |
| 6601 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6602 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6603 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6604 | rtl_set_rx_tx_desc_registers(tp); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6605 | |
| 6606 | rtl_set_rx_tx_config_registers(tp); |
| 6607 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6608 | switch (tp->mac_version) { |
| 6609 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6610 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6611 | break; |
| 6612 | |
| 6613 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6614 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6615 | break; |
| 6616 | |
| 6617 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6618 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6619 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6620 | |
| 6621 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6622 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6623 | break; |
| 6624 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6625 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6626 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6627 | |
| 6628 | case RTL_GIGA_MAC_VER_37: |
| 6629 | rtl_hw_start_8402(tp); |
| 6630 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6631 | |
| 6632 | case RTL_GIGA_MAC_VER_39: |
| 6633 | rtl_hw_start_8106(tp); |
| 6634 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6635 | case RTL_GIGA_MAC_VER_43: |
| 6636 | rtl_hw_start_8168g_2(tp); |
| 6637 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6638 | case RTL_GIGA_MAC_VER_47: |
| 6639 | case RTL_GIGA_MAC_VER_48: |
| 6640 | rtl_hw_start_8168h_1(tp); |
| 6641 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6642 | } |
| 6643 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6644 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6645 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6646 | RTL_W16(tp, IntrMitigate, 0x0000); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6647 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6648 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6649 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6650 | rtl_set_rx_mode(tp->dev); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6651 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6652 | RTL_R8(tp, IntrMask); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6653 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6654 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6658 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6659 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6660 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6661 | if (new_mtu > ETH_DATA_LEN) |
| 6662 | rtl_hw_jumbo_enable(tp); |
| 6663 | else |
| 6664 | rtl_hw_jumbo_disable(tp); |
| 6665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6666 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6667 | netdev_update_features(dev); |
| 6668 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6669 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6673 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6674 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6675 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6676 | } |
| 6677 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6678 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6679 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6680 | { |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6681 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), |
| 6682 | R8169_RX_BUF_SIZE, DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6683 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6684 | kfree(*data_buff); |
| 6685 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6686 | rtl8169_make_unusable_by_asic(desc); |
| 6687 | } |
| 6688 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6689 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6690 | { |
| 6691 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6692 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6693 | /* Force memory writes to complete before releasing descriptor */ |
| 6694 | dma_wmb(); |
| 6695 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6696 | desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6697 | } |
| 6698 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6699 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6700 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6701 | return (void *)ALIGN((long)data, 16); |
| 6702 | } |
| 6703 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6704 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6705 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6706 | { |
| 6707 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6708 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6709 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | d3b404c | 2018-04-17 23:22:14 +0200 | [diff] [blame] | 6710 | int node = dev_to_node(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6711 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6712 | data = kmalloc_node(R8169_RX_BUF_SIZE, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6713 | if (!data) |
| 6714 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6715 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6716 | if (rtl8169_align(data) != data) { |
| 6717 | kfree(data); |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6718 | data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6719 | if (!data) |
| 6720 | return NULL; |
| 6721 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6722 | |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6723 | mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6724 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6725 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6726 | if (net_ratelimit()) |
| 6727 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6728 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6730 | |
Heiner Kallweit | d731af7 | 2018-04-17 23:26:41 +0200 | [diff] [blame] | 6731 | desc->addr = cpu_to_le64(mapping); |
| 6732 | rtl8169_mark_to_asic(desc); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6733 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6734 | |
| 6735 | err_out: |
| 6736 | kfree(data); |
| 6737 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6741 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6742 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | |
| 6744 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6745 | if (tp->Rx_databuff[i]) { |
| 6746 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6747 | tp->RxDescArray + i); |
| 6748 | } |
| 6749 | } |
| 6750 | } |
| 6751 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6752 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6753 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6754 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6755 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6756 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6757 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6758 | { |
| 6759 | unsigned int i; |
| 6760 | |
| 6761 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6762 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6763 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6764 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6765 | if (!data) { |
| 6766 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6767 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6768 | } |
| 6769 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6771 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6772 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6773 | return 0; |
| 6774 | |
| 6775 | err_out: |
| 6776 | rtl8169_rx_clear(tp); |
| 6777 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6778 | } |
| 6779 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6780 | static int rtl8169_init_ring(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6781 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6782 | rtl8169_init_ring_indexes(tp); |
| 6783 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 6784 | memset(tp->tx_skb, 0, sizeof(tp->tx_skb)); |
| 6785 | memset(tp->Rx_databuff, 0, sizeof(tp->Rx_databuff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6787 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6790 | 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] | 6791 | struct TxDesc *desc) |
| 6792 | { |
| 6793 | unsigned int len = tx_skb->len; |
| 6794 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6795 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6797 | desc->opts1 = 0x00; |
| 6798 | desc->opts2 = 0x00; |
| 6799 | desc->addr = 0x00; |
| 6800 | tx_skb->len = 0; |
| 6801 | } |
| 6802 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6803 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6804 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6805 | { |
| 6806 | unsigned int i; |
| 6807 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6808 | for (i = 0; i < n; i++) { |
| 6809 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6810 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6811 | unsigned int len = tx_skb->len; |
| 6812 | |
| 6813 | if (len) { |
| 6814 | struct sk_buff *skb = tx_skb->skb; |
| 6815 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6816 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6817 | tp->TxDescArray + entry); |
| 6818 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6819 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | tx_skb->skb = NULL; |
| 6821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6822 | } |
| 6823 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6827 | { |
| 6828 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6829 | tp->cur_tx = tp->dirty_tx = 0; |
| 6830 | } |
| 6831 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6832 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6833 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6834 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6835 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6836 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6837 | napi_disable(&tp->napi); |
| 6838 | netif_stop_queue(dev); |
| 6839 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6841 | rtl8169_hw_reset(tp); |
| 6842 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6843 | for (i = 0; i < NUM_RX_DESC; i++) |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 6844 | rtl8169_mark_to_asic(tp->RxDescArray + i); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6846 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6847 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6848 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6849 | napi_enable(&tp->napi); |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 6850 | rtl_hw_start(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6851 | netif_wake_queue(dev); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6852 | rtl8169_check_link_status(dev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6853 | } |
| 6854 | |
| 6855 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6856 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6857 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6858 | |
| 6859 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | 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] | 6863 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6864 | { |
| 6865 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6866 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6867 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6868 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6869 | |
| 6870 | entry = tp->cur_tx; |
| 6871 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6872 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6873 | dma_addr_t mapping; |
| 6874 | u32 status, len; |
| 6875 | void *addr; |
| 6876 | |
| 6877 | entry = (entry + 1) % NUM_TX_DESC; |
| 6878 | |
| 6879 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6880 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6881 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6882 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6883 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6884 | if (net_ratelimit()) |
| 6885 | netif_err(tp, drv, tp->dev, |
| 6886 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6887 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6890 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6891 | status = opts[0] | len | |
| 6892 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6893 | |
| 6894 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6895 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6896 | txd->addr = cpu_to_le64(mapping); |
| 6897 | |
| 6898 | tp->tx_skb[entry].len = len; |
| 6899 | } |
| 6900 | |
| 6901 | if (cur_frag) { |
| 6902 | tp->tx_skb[entry].skb = skb; |
| 6903 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6904 | } |
| 6905 | |
| 6906 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6907 | |
| 6908 | err_out: |
| 6909 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6910 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6911 | } |
| 6912 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6913 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6914 | { |
| 6915 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6916 | } |
| 6917 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6918 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6919 | struct net_device *dev); |
| 6920 | /* r8169_csum_workaround() |
| 6921 | * The hw limites the value the transport offset. When the offset is out of the |
| 6922 | * range, calculate the checksum by sw. |
| 6923 | */ |
| 6924 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6925 | struct sk_buff *skb) |
| 6926 | { |
| 6927 | if (skb_shinfo(skb)->gso_size) { |
| 6928 | netdev_features_t features = tp->dev->features; |
| 6929 | struct sk_buff *segs, *nskb; |
| 6930 | |
| 6931 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6932 | segs = skb_gso_segment(skb, features); |
| 6933 | if (IS_ERR(segs) || !segs) |
| 6934 | goto drop; |
| 6935 | |
| 6936 | do { |
| 6937 | nskb = segs; |
| 6938 | segs = segs->next; |
| 6939 | nskb->next = NULL; |
| 6940 | rtl8169_start_xmit(nskb, tp->dev); |
| 6941 | } while (segs); |
| 6942 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6943 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6944 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6945 | if (skb_checksum_help(skb) < 0) |
| 6946 | goto drop; |
| 6947 | |
| 6948 | rtl8169_start_xmit(skb, tp->dev); |
| 6949 | } else { |
| 6950 | struct net_device_stats *stats; |
| 6951 | |
| 6952 | drop: |
| 6953 | stats = &tp->dev->stats; |
| 6954 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6955 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | /* msdn_giant_send_check() |
| 6960 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6961 | * packet length for IPv6 TCP large packets. |
| 6962 | */ |
| 6963 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6964 | { |
| 6965 | const struct ipv6hdr *ipv6h; |
| 6966 | struct tcphdr *th; |
| 6967 | int ret; |
| 6968 | |
| 6969 | ret = skb_cow_head(skb, 0); |
| 6970 | if (ret) |
| 6971 | return ret; |
| 6972 | |
| 6973 | ipv6h = ipv6_hdr(skb); |
| 6974 | th = tcp_hdr(skb); |
| 6975 | |
| 6976 | th->check = 0; |
| 6977 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6978 | |
| 6979 | return ret; |
| 6980 | } |
| 6981 | |
| 6982 | static inline __be16 get_protocol(struct sk_buff *skb) |
| 6983 | { |
| 6984 | __be16 protocol; |
| 6985 | |
| 6986 | if (skb->protocol == htons(ETH_P_8021Q)) |
| 6987 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 6988 | else |
| 6989 | protocol = skb->protocol; |
| 6990 | |
| 6991 | return protocol; |
| 6992 | } |
| 6993 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6994 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6995 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6996 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6997 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6998 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6999 | if (mss) { |
| 7000 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7001 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 7002 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 7003 | const struct iphdr *ip = ip_hdr(skb); |
| 7004 | |
| 7005 | if (ip->protocol == IPPROTO_TCP) |
| 7006 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 7007 | else if (ip->protocol == IPPROTO_UDP) |
| 7008 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 7009 | else |
| 7010 | WARN_ON_ONCE(1); |
| 7011 | } |
| 7012 | |
| 7013 | return true; |
| 7014 | } |
| 7015 | |
| 7016 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 7017 | struct sk_buff *skb, u32 *opts) |
| 7018 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7019 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7020 | u32 mss = skb_shinfo(skb)->gso_size; |
| 7021 | |
| 7022 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7023 | if (transport_offset > GTTCPHO_MAX) { |
| 7024 | netif_warn(tp, tx_err, tp->dev, |
| 7025 | "Invalid transport offset 0x%x for TSO\n", |
| 7026 | transport_offset); |
| 7027 | return false; |
| 7028 | } |
| 7029 | |
| 7030 | switch (get_protocol(skb)) { |
| 7031 | case htons(ETH_P_IP): |
| 7032 | opts[0] |= TD1_GTSENV4; |
| 7033 | break; |
| 7034 | |
| 7035 | case htons(ETH_P_IPV6): |
| 7036 | if (msdn_giant_send_check(skb)) |
| 7037 | return false; |
| 7038 | |
| 7039 | opts[0] |= TD1_GTSENV6; |
| 7040 | break; |
| 7041 | |
| 7042 | default: |
| 7043 | WARN_ON_ONCE(1); |
| 7044 | break; |
| 7045 | } |
| 7046 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7047 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7048 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7049 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7050 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7051 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7052 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7053 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7054 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7055 | if (transport_offset > TCPHO_MAX) { |
| 7056 | netif_warn(tp, tx_err, tp->dev, |
| 7057 | "Invalid transport offset 0x%x\n", |
| 7058 | transport_offset); |
| 7059 | return false; |
| 7060 | } |
| 7061 | |
| 7062 | switch (get_protocol(skb)) { |
| 7063 | case htons(ETH_P_IP): |
| 7064 | opts[1] |= TD1_IPv4_CS; |
| 7065 | ip_protocol = ip_hdr(skb)->protocol; |
| 7066 | break; |
| 7067 | |
| 7068 | case htons(ETH_P_IPV6): |
| 7069 | opts[1] |= TD1_IPv6_CS; |
| 7070 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 7071 | break; |
| 7072 | |
| 7073 | default: |
| 7074 | ip_protocol = IPPROTO_RAW; |
| 7075 | break; |
| 7076 | } |
| 7077 | |
| 7078 | if (ip_protocol == IPPROTO_TCP) |
| 7079 | opts[1] |= TD1_TCP_CS; |
| 7080 | else if (ip_protocol == IPPROTO_UDP) |
| 7081 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7082 | else |
| 7083 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7084 | |
| 7085 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7086 | } else { |
| 7087 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7088 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7089 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7090 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7091 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7092 | } |
| 7093 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7094 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 7095 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7096 | { |
| 7097 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7098 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7099 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7100 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7101 | dma_addr_t mapping; |
| 7102 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7103 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7104 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7105 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7106 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7107 | 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] | 7108 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7109 | } |
| 7110 | |
| 7111 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7112 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7113 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7114 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 7115 | opts[0] = DescOwn; |
| 7116 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7117 | if (!tp->tso_csum(tp, skb, opts)) { |
| 7118 | r8169_csum_workaround(tp, skb); |
| 7119 | return NETDEV_TX_OK; |
| 7120 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7121 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7122 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7123 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7124 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 7125 | if (net_ratelimit()) |
| 7126 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7127 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7129 | |
| 7130 | tp->tx_skb[entry].len = len; |
| 7131 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7132 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7133 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7134 | if (frags < 0) |
| 7135 | goto err_dma_1; |
| 7136 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7137 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7138 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7139 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7140 | tp->tx_skb[entry].skb = skb; |
| 7141 | } |
| 7142 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7143 | txd->opts2 = cpu_to_le32(opts[1]); |
| 7144 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 7145 | skb_tx_timestamp(skb); |
| 7146 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7147 | /* Force memory writes to complete before releasing descriptor */ |
| 7148 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7149 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7150 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7151 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7152 | txd->opts1 = cpu_to_le32(status); |
| 7153 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7154 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 7155 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7156 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7157 | tp->cur_tx += frags + 1; |
| 7158 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7159 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7160 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7161 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7162 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7163 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7164 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 7165 | * not miss a ring update when it notices a stopped queue. |
| 7166 | */ |
| 7167 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7168 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7169 | /* Sync with rtl_tx: |
| 7170 | * - publish queue status and cur_tx ring index (write barrier) |
| 7171 | * - refresh dirty_tx ring index (read barrier). |
| 7172 | * May the current thread have a pessimistic view of the ring |
| 7173 | * status and forget to wake up queue, a racing rtl_tx thread |
| 7174 | * can't. |
| 7175 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7176 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7177 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7178 | netif_wake_queue(dev); |
| 7179 | } |
| 7180 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7181 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7182 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7183 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7184 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7185 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 7186 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7187 | dev->stats.tx_dropped++; |
| 7188 | return NETDEV_TX_OK; |
| 7189 | |
| 7190 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7191 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7192 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7193 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 7197 | { |
| 7198 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7199 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7200 | u16 pci_status, pci_cmd; |
| 7201 | |
| 7202 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 7203 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 7204 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7205 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 7206 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7207 | |
| 7208 | /* |
| 7209 | * The recovery sequence below admits a very elaborated explanation: |
| 7210 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7211 | * - I did not see what else could be done; |
| 7212 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | * |
| 7214 | * Feel free to adjust to your needs. |
| 7215 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 7216 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7217 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 7218 | else |
| 7219 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 7220 | |
| 7221 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7222 | |
| 7223 | pci_write_config_word(pdev, PCI_STATUS, |
| 7224 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 7225 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 7226 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 7227 | |
| 7228 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7229 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7230 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7231 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7232 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7233 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7234 | } |
| 7235 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 7236 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7237 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7238 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7241 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7242 | { |
| 7243 | unsigned int dirty_tx, tx_left; |
| 7244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7245 | dirty_tx = tp->dirty_tx; |
| 7246 | smp_rmb(); |
| 7247 | tx_left = tp->cur_tx - dirty_tx; |
| 7248 | |
| 7249 | while (tx_left > 0) { |
| 7250 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 7251 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7252 | u32 status; |
| 7253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7254 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 7255 | if (status & DescOwn) |
| 7256 | break; |
| 7257 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7258 | /* This barrier is needed to keep us from reading |
| 7259 | * any other fields out of the Tx descriptor until |
| 7260 | * we know the status of DescOwn |
| 7261 | */ |
| 7262 | dma_rmb(); |
| 7263 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7264 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7265 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7266 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7267 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 7268 | tp->tx_stats.packets++; |
| 7269 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 7270 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 7271 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7272 | tx_skb->skb = NULL; |
| 7273 | } |
| 7274 | dirty_tx++; |
| 7275 | tx_left--; |
| 7276 | } |
| 7277 | |
| 7278 | if (tp->dirty_tx != dirty_tx) { |
| 7279 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7280 | /* Sync with rtl8169_start_xmit: |
| 7281 | * - publish dirty_tx ring index (write barrier) |
| 7282 | * - refresh cur_tx ring index and queue status (read barrier) |
| 7283 | * May the current thread miss the stopped queue condition, |
| 7284 | * a racing xmit thread can only have a right view of the |
| 7285 | * ring status. |
| 7286 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7287 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7288 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7289 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7290 | netif_wake_queue(dev); |
| 7291 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 7292 | /* |
| 7293 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 7294 | * too close. Let's kick an extra TxPoll request when a burst |
| 7295 | * of start_xmit activity is detected (if it is not detected, |
| 7296 | * it is slow enough). -- FR |
| 7297 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7298 | if (tp->cur_tx != dirty_tx) |
| 7299 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7300 | } |
| 7301 | } |
| 7302 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7303 | static inline int rtl8169_fragmented_frame(u32 status) |
| 7304 | { |
| 7305 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 7306 | } |
| 7307 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7308 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7309 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7310 | u32 status = opts1 & RxProtoMask; |
| 7311 | |
| 7312 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 7313 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7314 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 7315 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 7316 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7317 | } |
| 7318 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7319 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 7320 | struct rtl8169_private *tp, |
| 7321 | int pkt_size, |
| 7322 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7323 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 7324 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7325 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7326 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7327 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7328 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7329 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 7330 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7331 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame] | 7332 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7333 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 7334 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7335 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7336 | } |
| 7337 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7338 | 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] | 7339 | { |
| 7340 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7341 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7343 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7345 | 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] | 7346 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7347 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7348 | u32 status; |
| 7349 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 7350 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7351 | if (status & DescOwn) |
| 7352 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7353 | |
| 7354 | /* This barrier is needed to keep us from reading |
| 7355 | * any other fields out of the Rx descriptor until |
| 7356 | * we know the status of DescOwn |
| 7357 | */ |
| 7358 | dma_rmb(); |
| 7359 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 7360 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7361 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 7362 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7363 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7364 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7365 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7366 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7367 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7368 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7369 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7370 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7371 | } |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7372 | if ((status & (RxRUNT | RxCRC)) && |
| 7373 | !(status & (RxRWT | RxFOVF)) && |
| 7374 | (dev->features & NETIF_F_RXALL)) |
| 7375 | goto process_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7376 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7377 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7378 | dma_addr_t addr; |
| 7379 | int pkt_size; |
| 7380 | |
| 7381 | process_pkt: |
| 7382 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 7383 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 7384 | pkt_size = (status & 0x00003fff) - 4; |
| 7385 | else |
| 7386 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7387 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7388 | /* |
| 7389 | * The driver does not support incoming fragmented |
| 7390 | * frames. They are seen as a symptom of over-mtu |
| 7391 | * sized frames. |
| 7392 | */ |
| 7393 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7394 | dev->stats.rx_dropped++; |
| 7395 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7396 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7397 | } |
| 7398 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7399 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 7400 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7401 | if (!skb) { |
| 7402 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7403 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7404 | } |
| 7405 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7406 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7407 | skb_put(skb, pkt_size); |
| 7408 | skb->protocol = eth_type_trans(skb, dev); |
| 7409 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 7410 | rtl8169_rx_vlan_tag(desc, skb); |
| 7411 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 7412 | if (skb->pkt_type == PACKET_MULTICAST) |
| 7413 | dev->stats.multicast++; |
| 7414 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7415 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7416 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7417 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 7418 | tp->rx_stats.packets++; |
| 7419 | tp->rx_stats.bytes += pkt_size; |
| 7420 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7421 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7422 | release_descriptor: |
| 7423 | desc->opts2 = 0; |
Heiner Kallweit | 1d0254d | 2018-04-17 23:25:46 +0200 | [diff] [blame] | 7424 | rtl8169_mark_to_asic(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | count = cur_rx - tp->cur_rx; |
| 7428 | tp->cur_rx = cur_rx; |
| 7429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7430 | return count; |
| 7431 | } |
| 7432 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7433 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7434 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7435 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7436 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7438 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7439 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7440 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7441 | if (status && status != 0xffff) { |
| 7442 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 7443 | if (status) { |
| 7444 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 7445 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7446 | rtl_irq_disable(tp); |
Heiner Kallweit | 9a899a3 | 2018-04-17 23:21:01 +0200 | [diff] [blame] | 7447 | napi_schedule_irqoff(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7450 | return IRQ_RETVAL(handled); |
| 7451 | } |
| 7452 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7453 | /* |
| 7454 | * Workqueue context. |
| 7455 | */ |
| 7456 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 7457 | { |
| 7458 | struct net_device *dev = tp->dev; |
| 7459 | u16 status; |
| 7460 | |
| 7461 | status = rtl_get_events(tp) & tp->event_slow; |
| 7462 | rtl_ack_events(tp, status); |
| 7463 | |
| 7464 | if (unlikely(status & RxFIFOOver)) { |
| 7465 | switch (tp->mac_version) { |
| 7466 | /* Work around for rx fifo overflow */ |
| 7467 | case RTL_GIGA_MAC_VER_11: |
| 7468 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7469 | /* XXX - Hack alert. See rtl_task(). */ |
| 7470 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7471 | default: |
| 7472 | break; |
| 7473 | } |
| 7474 | } |
| 7475 | |
| 7476 | if (unlikely(status & SYSErr)) |
| 7477 | rtl8169_pcierr_interrupt(dev); |
| 7478 | |
| 7479 | if (status & LinkChg) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7480 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7481 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 7482 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7483 | } |
| 7484 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7485 | static void rtl_task(struct work_struct *work) |
| 7486 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7487 | static const struct { |
| 7488 | int bitnr; |
| 7489 | void (*action)(struct rtl8169_private *); |
| 7490 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7491 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7492 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 7493 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 7494 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 7495 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7496 | struct rtl8169_private *tp = |
| 7497 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7498 | struct net_device *dev = tp->dev; |
| 7499 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7500 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7501 | rtl_lock_work(tp); |
| 7502 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7503 | if (!netif_running(dev) || |
| 7504 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7505 | goto out_unlock; |
| 7506 | |
| 7507 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 7508 | bool pending; |
| 7509 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7510 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7511 | if (pending) |
| 7512 | rtl_work[i].action(tp); |
| 7513 | } |
| 7514 | |
| 7515 | out_unlock: |
| 7516 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7517 | } |
| 7518 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7519 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7520 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7521 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 7522 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7523 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 7524 | int work_done= 0; |
| 7525 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7526 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7527 | status = rtl_get_events(tp); |
| 7528 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 7529 | |
| 7530 | if (status & RTL_EVENT_NAPI_RX) |
| 7531 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7532 | |
| 7533 | if (status & RTL_EVENT_NAPI_TX) |
| 7534 | rtl_tx(dev, tp); |
| 7535 | |
| 7536 | if (status & tp->event_slow) { |
| 7537 | enable_mask &= ~tp->event_slow; |
| 7538 | |
| 7539 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7541 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7542 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 7543 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7544 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7545 | rtl_irq_enable(tp, enable_mask); |
| 7546 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7547 | } |
| 7548 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7549 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7551 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7552 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7553 | { |
| 7554 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7555 | |
| 7556 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7557 | return; |
| 7558 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7559 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 7560 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7561 | } |
| 7562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7563 | static void rtl8169_down(struct net_device *dev) |
| 7564 | { |
| 7565 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7566 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7567 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7568 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7569 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7570 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7571 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7572 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7573 | /* |
| 7574 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7575 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7576 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7577 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7578 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7580 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7581 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7583 | rtl8169_tx_clear(tp); |
| 7584 | |
| 7585 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7586 | |
| 7587 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | static int rtl8169_close(struct net_device *dev) |
| 7591 | { |
| 7592 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7593 | struct pci_dev *pdev = tp->pci_dev; |
| 7594 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7595 | pm_runtime_get_sync(&pdev->dev); |
| 7596 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7597 | /* Update counters before going down */ |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 7598 | rtl8169_update_counters(tp); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7599 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7600 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7601 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7603 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7604 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7605 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7606 | cancel_work_sync(&tp->wk.work); |
| 7607 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7608 | pci_free_irq(pdev, 0, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7609 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7610 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7611 | tp->RxPhyAddr); |
| 7612 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7613 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7614 | tp->TxDescArray = NULL; |
| 7615 | tp->RxDescArray = NULL; |
| 7616 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7617 | pm_runtime_put_sync(&pdev->dev); |
| 7618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7619 | return 0; |
| 7620 | } |
| 7621 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7622 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7623 | static void rtl8169_netpoll(struct net_device *dev) |
| 7624 | { |
| 7625 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7626 | |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7627 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), dev); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7628 | } |
| 7629 | #endif |
| 7630 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7631 | static int rtl_open(struct net_device *dev) |
| 7632 | { |
| 7633 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7634 | struct pci_dev *pdev = tp->pci_dev; |
| 7635 | int retval = -ENOMEM; |
| 7636 | |
| 7637 | pm_runtime_get_sync(&pdev->dev); |
| 7638 | |
| 7639 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7640 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7641 | * dma_alloc_coherent provides more. |
| 7642 | */ |
| 7643 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7644 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7645 | if (!tp->TxDescArray) |
| 7646 | goto err_pm_runtime_put; |
| 7647 | |
| 7648 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7649 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7650 | if (!tp->RxDescArray) |
| 7651 | goto err_free_tx_0; |
| 7652 | |
Heiner Kallweit | b1127e6 | 2018-04-17 23:23:35 +0200 | [diff] [blame] | 7653 | retval = rtl8169_init_ring(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7654 | if (retval < 0) |
| 7655 | goto err_free_rx_1; |
| 7656 | |
| 7657 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7658 | |
| 7659 | smp_mb(); |
| 7660 | |
| 7661 | rtl_request_firmware(tp); |
| 7662 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7663 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, dev, |
| 7664 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7665 | if (retval < 0) |
| 7666 | goto err_release_fw_2; |
| 7667 | |
| 7668 | rtl_lock_work(tp); |
| 7669 | |
| 7670 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7671 | |
| 7672 | napi_enable(&tp->napi); |
| 7673 | |
| 7674 | rtl8169_init_phy(dev, tp); |
| 7675 | |
| 7676 | __rtl8169_set_features(dev, dev->features); |
| 7677 | |
| 7678 | rtl_pll_power_up(tp); |
| 7679 | |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7680 | rtl_hw_start(tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7681 | |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 7682 | if (!rtl8169_init_counter_offsets(tp)) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7683 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7684 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7685 | netif_start_queue(dev); |
| 7686 | |
| 7687 | rtl_unlock_work(tp); |
| 7688 | |
| 7689 | tp->saved_wolopts = 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7690 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7691 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7692 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7693 | out: |
| 7694 | return retval; |
| 7695 | |
| 7696 | err_release_fw_2: |
| 7697 | rtl_release_firmware(tp); |
| 7698 | rtl8169_rx_clear(tp); |
| 7699 | err_free_rx_1: |
| 7700 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7701 | tp->RxPhyAddr); |
| 7702 | tp->RxDescArray = NULL; |
| 7703 | err_free_tx_0: |
| 7704 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7705 | tp->TxPhyAddr); |
| 7706 | tp->TxDescArray = NULL; |
| 7707 | err_pm_runtime_put: |
| 7708 | pm_runtime_put_noidle(&pdev->dev); |
| 7709 | goto out; |
| 7710 | } |
| 7711 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7712 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7713 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7714 | { |
| 7715 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7716 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7717 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7718 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7719 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7720 | pm_runtime_get_noresume(&pdev->dev); |
| 7721 | |
| 7722 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7723 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7724 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7725 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7726 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7727 | stats->rx_packets = tp->rx_stats.packets; |
| 7728 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7729 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7730 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7731 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7732 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7733 | stats->tx_packets = tp->tx_stats.packets; |
| 7734 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7735 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7736 | |
| 7737 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7738 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7739 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7740 | stats->rx_errors = dev->stats.rx_errors; |
| 7741 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7742 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7743 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7744 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7745 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7746 | /* |
| 7747 | * Fetch additonal counter values missing in stats collected by driver |
| 7748 | * from tally counters. |
| 7749 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7750 | if (pm_runtime_active(&pdev->dev)) |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 7751 | rtl8169_update_counters(tp); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7752 | |
| 7753 | /* |
| 7754 | * Subtract values fetched during initalization. |
| 7755 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 7756 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7757 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7758 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7759 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7760 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7761 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7762 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 7763 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7764 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7765 | } |
| 7766 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7767 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7768 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7769 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7770 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7771 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7772 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7773 | |
| 7774 | netif_device_detach(dev); |
| 7775 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7776 | |
| 7777 | rtl_lock_work(tp); |
| 7778 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7779 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7780 | rtl_unlock_work(tp); |
| 7781 | |
| 7782 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7783 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7784 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7785 | #ifdef CONFIG_PM |
| 7786 | |
| 7787 | static int rtl8169_suspend(struct device *device) |
| 7788 | { |
| 7789 | struct pci_dev *pdev = to_pci_dev(device); |
| 7790 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7791 | |
| 7792 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 7793 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7794 | return 0; |
| 7795 | } |
| 7796 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7797 | static void __rtl8169_resume(struct net_device *dev) |
| 7798 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7799 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7800 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7801 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7802 | |
| 7803 | rtl_pll_power_up(tp); |
| 7804 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7805 | rtl_lock_work(tp); |
| 7806 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7807 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7808 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7809 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7810 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7811 | } |
| 7812 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7813 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7814 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7815 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7816 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7817 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7818 | |
| 7819 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7820 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7821 | if (netif_running(dev)) |
| 7822 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7823 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7824 | return 0; |
| 7825 | } |
| 7826 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7827 | static int rtl8169_runtime_suspend(struct device *device) |
| 7828 | { |
| 7829 | struct pci_dev *pdev = to_pci_dev(device); |
| 7830 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7831 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7832 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7833 | if (!tp->TxDescArray) { |
| 7834 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7835 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7836 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7837 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7838 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7839 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 7840 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7841 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7842 | |
| 7843 | rtl8169_net_suspend(dev); |
| 7844 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7845 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7846 | rtl8169_rx_missed(dev); |
Heiner Kallweit | e71c9ce | 2018-04-17 23:28:28 +0200 | [diff] [blame^] | 7847 | rtl8169_update_counters(tp); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7848 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7849 | return 0; |
| 7850 | } |
| 7851 | |
| 7852 | static int rtl8169_runtime_resume(struct device *device) |
| 7853 | { |
| 7854 | struct pci_dev *pdev = to_pci_dev(device); |
| 7855 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7856 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 7857 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7858 | |
| 7859 | if (!tp->TxDescArray) |
| 7860 | return 0; |
| 7861 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7862 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7863 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 7864 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7865 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7866 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7867 | rtl8169_init_phy(dev, tp); |
| 7868 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7869 | __rtl8169_resume(dev); |
| 7870 | |
| 7871 | return 0; |
| 7872 | } |
| 7873 | |
| 7874 | static int rtl8169_runtime_idle(struct device *device) |
| 7875 | { |
| 7876 | struct pci_dev *pdev = to_pci_dev(device); |
| 7877 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7878 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7879 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 7880 | pm_schedule_suspend(device, 10000); |
| 7881 | |
| 7882 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7883 | } |
| 7884 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7885 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7886 | .suspend = rtl8169_suspend, |
| 7887 | .resume = rtl8169_resume, |
| 7888 | .freeze = rtl8169_suspend, |
| 7889 | .thaw = rtl8169_resume, |
| 7890 | .poweroff = rtl8169_suspend, |
| 7891 | .restore = rtl8169_resume, |
| 7892 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7893 | .runtime_resume = rtl8169_runtime_resume, |
| 7894 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7895 | }; |
| 7896 | |
| 7897 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7898 | |
| 7899 | #else /* !CONFIG_PM */ |
| 7900 | |
| 7901 | #define RTL8169_PM_OPS NULL |
| 7902 | |
| 7903 | #endif /* !CONFIG_PM */ |
| 7904 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7905 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7906 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7907 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7908 | switch (tp->mac_version) { |
| 7909 | case RTL_GIGA_MAC_VER_11: |
| 7910 | case RTL_GIGA_MAC_VER_12: |
| 7911 | case RTL_GIGA_MAC_VER_17: |
| 7912 | pci_clear_master(tp->pci_dev); |
| 7913 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7914 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7915 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7916 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7917 | break; |
| 7918 | default: |
| 7919 | break; |
| 7920 | } |
| 7921 | } |
| 7922 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7923 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7924 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7925 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7926 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7927 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7928 | rtl8169_net_suspend(dev); |
| 7929 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7930 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7931 | rtl_rar_set(tp, dev->perm_addr); |
| 7932 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7933 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7934 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7935 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7936 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 7937 | rtl_wol_suspend_quirk(tp); |
| 7938 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7939 | } |
| 7940 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7941 | pci_wake_from_d3(pdev, true); |
| 7942 | pci_set_power_state(pdev, PCI_D3hot); |
| 7943 | } |
| 7944 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7945 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7946 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7947 | { |
| 7948 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7949 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7950 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7951 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7952 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7953 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7954 | netif_napi_del(&tp->napi); |
| 7955 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7956 | unregister_netdev(dev); |
| 7957 | |
| 7958 | rtl_release_firmware(tp); |
| 7959 | |
| 7960 | if (pci_dev_run_wake(pdev)) |
| 7961 | pm_runtime_get_noresume(&pdev->dev); |
| 7962 | |
| 7963 | /* restore original MAC address */ |
| 7964 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7965 | } |
| 7966 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7967 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7968 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7969 | .ndo_stop = rtl8169_close, |
| 7970 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7971 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7972 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7973 | .ndo_validate_addr = eth_validate_addr, |
| 7974 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7975 | .ndo_fix_features = rtl8169_fix_features, |
| 7976 | .ndo_set_features = rtl8169_set_features, |
| 7977 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7978 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7979 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7980 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7981 | .ndo_poll_controller = rtl8169_netpoll, |
| 7982 | #endif |
| 7983 | |
| 7984 | }; |
| 7985 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7986 | static const struct rtl_cfg_info { |
Heiner Kallweit | 61cb532 | 2018-04-17 23:27:38 +0200 | [diff] [blame] | 7987 | void (*hw_start)(struct rtl8169_private *tp); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7988 | unsigned int region; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7989 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7990 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7991 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7992 | u8 default_ver; |
| 7993 | } rtl_cfg_infos [] = { |
| 7994 | [RTL_CFG_0] = { |
| 7995 | .hw_start = rtl_hw_start_8169, |
| 7996 | .region = 1, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7997 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 7998 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 7999 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8000 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 8001 | }, |
| 8002 | [RTL_CFG_1] = { |
| 8003 | .hw_start = rtl_hw_start_8168, |
| 8004 | .region = 2, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8005 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8006 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8007 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8008 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 8009 | }, |
| 8010 | [RTL_CFG_2] = { |
| 8011 | .hw_start = rtl_hw_start_8101, |
| 8012 | .region = 2, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8013 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 8014 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8015 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8016 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 8017 | } |
| 8018 | }; |
| 8019 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8020 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8021 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8022 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8023 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8024 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8025 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 8026 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 8027 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8028 | flags = PCI_IRQ_LEGACY; |
| 8029 | } else { |
| 8030 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8031 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8032 | |
| 8033 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8034 | } |
| 8035 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8036 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 8037 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8038 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8039 | } |
| 8040 | |
| 8041 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 8042 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8043 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8044 | } |
| 8045 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8046 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8047 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8048 | u32 data; |
| 8049 | |
| 8050 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 8051 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8052 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8053 | |
| 8054 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 8055 | return; |
| 8056 | |
| 8057 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 8058 | return; |
| 8059 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8060 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8061 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8062 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8063 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8064 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8065 | data &= ~(1 << 14); |
| 8066 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8067 | |
| 8068 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8069 | return; |
| 8070 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8071 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8072 | data |= (1 << 15); |
| 8073 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8074 | |
| 8075 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8076 | return; |
| 8077 | } |
| 8078 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8079 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 8080 | { |
| 8081 | rtl8168ep_stop_cmac(tp); |
| 8082 | rtl_hw_init_8168g(tp); |
| 8083 | } |
| 8084 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8085 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8086 | { |
| 8087 | switch (tp->mac_version) { |
| 8088 | case RTL_GIGA_MAC_VER_40: |
| 8089 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 8090 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 8091 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 8092 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8093 | case RTL_GIGA_MAC_VER_45: |
| 8094 | case RTL_GIGA_MAC_VER_46: |
| 8095 | case RTL_GIGA_MAC_VER_47: |
| 8096 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8097 | rtl_hw_init_8168g(tp); |
| 8098 | break; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8099 | case RTL_GIGA_MAC_VER_49: |
| 8100 | case RTL_GIGA_MAC_VER_50: |
| 8101 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8102 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8103 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8104 | default: |
| 8105 | break; |
| 8106 | } |
| 8107 | } |
| 8108 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8109 | 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] | 8110 | { |
| 8111 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 8112 | const unsigned int region = cfg->region; |
| 8113 | struct rtl8169_private *tp; |
| 8114 | struct mii_if_info *mii; |
| 8115 | struct net_device *dev; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8116 | int chipset, i; |
| 8117 | int rc; |
| 8118 | |
| 8119 | if (netif_msg_drv(&debug)) { |
| 8120 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 8121 | MODULENAME, RTL8169_VERSION); |
| 8122 | } |
| 8123 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8124 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 8125 | if (!dev) |
| 8126 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8127 | |
| 8128 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 8129 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8130 | tp = netdev_priv(dev); |
| 8131 | tp->dev = dev; |
| 8132 | tp->pci_dev = pdev; |
| 8133 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 8134 | |
| 8135 | mii = &tp->mii; |
| 8136 | mii->dev = dev; |
| 8137 | mii->mdio_read = rtl_mdio_read; |
| 8138 | mii->mdio_write = rtl_mdio_write; |
| 8139 | mii->phy_id_mask = 0x1f; |
| 8140 | mii->reg_num_mask = 0x1f; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8141 | mii->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8142 | |
| 8143 | /* disable ASPM completely as that cause random device stop working |
| 8144 | * problems as well as full system hangs for some PCIe devices users */ |
| 8145 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 8146 | PCIE_LINK_STATE_CLKPM); |
| 8147 | |
| 8148 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8149 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8150 | if (rc < 0) { |
| 8151 | netif_err(tp, probe, dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8152 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8153 | } |
| 8154 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8155 | if (pcim_set_mwi(pdev) < 0) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8156 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
| 8157 | |
| 8158 | /* make sure PCI base addr 1 is MMIO */ |
| 8159 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
| 8160 | netif_err(tp, probe, dev, |
| 8161 | "region #%d not an MMIO resource, aborting\n", |
| 8162 | region); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8163 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8164 | } |
| 8165 | |
| 8166 | /* check for weird/broken PCI region reporting */ |
| 8167 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
| 8168 | netif_err(tp, probe, dev, |
| 8169 | "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8170 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8171 | } |
| 8172 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8173 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8174 | if (rc < 0) { |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8175 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8176 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8177 | } |
| 8178 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8179 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8180 | |
| 8181 | if (!pci_is_pcie(pdev)) |
| 8182 | netif_info(tp, probe, dev, "not PCI Express\n"); |
| 8183 | |
| 8184 | /* Identify chip attached to board */ |
| 8185 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 8186 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8187 | tp->cp_cmd = 0; |
| 8188 | |
| 8189 | if ((sizeof(dma_addr_t) > 4) && |
| 8190 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 8191 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 8192 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 8193 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8194 | |
| 8195 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 8196 | if (!pci_is_pcie(pdev)) |
| 8197 | tp->cp_cmd |= PCIDAC; |
| 8198 | dev->features |= NETIF_F_HIGHDMA; |
| 8199 | } else { |
| 8200 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 8201 | if (rc < 0) { |
| 8202 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8203 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8204 | } |
| 8205 | } |
| 8206 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8207 | rtl_init_rxcfg(tp); |
| 8208 | |
| 8209 | rtl_irq_disable(tp); |
| 8210 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8211 | rtl_hw_initialize(tp); |
| 8212 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8213 | rtl_hw_reset(tp); |
| 8214 | |
| 8215 | rtl_ack_events(tp, 0xffff); |
| 8216 | |
| 8217 | pci_set_master(pdev); |
| 8218 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8219 | rtl_init_mdio_ops(tp); |
| 8220 | rtl_init_pll_power_ops(tp); |
| 8221 | rtl_init_jumbo_ops(tp); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 8222 | rtl_init_csi_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8223 | |
| 8224 | rtl8169_print_mac_version(tp); |
| 8225 | |
| 8226 | chipset = tp->mac_version; |
| 8227 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
| 8228 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8229 | rc = rtl_alloc_irq(tp); |
| 8230 | if (rc < 0) { |
| 8231 | netif_err(tp, probe, dev, "Can't allocate interrupt\n"); |
| 8232 | return rc; |
| 8233 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8234 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 8235 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 8236 | __rtl8169_set_wol(tp, 0); |
| 8237 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8238 | if (rtl_tbi_enabled(tp)) { |
| 8239 | tp->set_speed = rtl8169_set_speed_tbi; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8240 | tp->get_link_ksettings = rtl8169_get_link_ksettings_tbi; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8241 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 8242 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 8243 | tp->link_ok = rtl8169_tbi_link_ok; |
| 8244 | tp->do_ioctl = rtl_tbi_ioctl; |
| 8245 | } else { |
| 8246 | tp->set_speed = rtl8169_set_speed_xmii; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8247 | tp->get_link_ksettings = rtl8169_get_link_ksettings_xmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8248 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 8249 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 8250 | tp->link_ok = rtl8169_xmii_link_ok; |
| 8251 | tp->do_ioctl = rtl_xmii_ioctl; |
| 8252 | } |
| 8253 | |
| 8254 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 8255 | u64_stats_init(&tp->rx_stats.syncp); |
| 8256 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8257 | |
| 8258 | /* Get MAC address */ |
Chun-Hao Lin | 89cceb2 | 2014-10-01 23:17:15 +0800 | [diff] [blame] | 8259 | if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 8260 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 8261 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 8262 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 8263 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 8264 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 8265 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 8266 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 8267 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 8268 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8269 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 8270 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8271 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 8272 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 8273 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 8274 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8275 | u16 mac_addr[3]; |
| 8276 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 8277 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
| 8278 | *(u16 *)&mac_addr[2] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8279 | |
| 8280 | if (is_valid_ether_addr((u8 *)mac_addr)) |
| 8281 | rtl_rar_set(tp, (u8 *)mac_addr); |
| 8282 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8283 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8284 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8285 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 8286 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8287 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8288 | |
Heiner Kallweit | 3762149 | 2018-04-17 23:20:03 +0200 | [diff] [blame] | 8289 | netif_napi_add(dev, &tp->napi, rtl8169_poll, NAPI_POLL_WEIGHT); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8290 | |
| 8291 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 8292 | * properly for all devices */ |
| 8293 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8294 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8295 | |
| 8296 | 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] | 8297 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 8298 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8299 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 8300 | NETIF_F_HIGHDMA; |
| 8301 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8302 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 8303 | |
| 8304 | /* |
| 8305 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 8306 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 8307 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8308 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8309 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8310 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8311 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8312 | if (tp->txd_version == RTL_TD_0) |
| 8313 | tp->tso_csum = rtl8169_tso_csum_v1; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8314 | else if (tp->txd_version == RTL_TD_1) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8315 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8316 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
| 8317 | } else |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8318 | WARN_ON_ONCE(1); |
| 8319 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8320 | dev->hw_features |= NETIF_F_RXALL; |
| 8321 | dev->hw_features |= NETIF_F_RXFCS; |
| 8322 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 8323 | /* MTU range: 60 - hw-specific max */ |
| 8324 | dev->min_mtu = ETH_ZLEN; |
| 8325 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 8326 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8327 | tp->hw_start = cfg->hw_start; |
| 8328 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8329 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8330 | |
| 8331 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 8332 | ~(RxBOVF | RxFOVF) : ~0; |
| 8333 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 8334 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8335 | |
| 8336 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 8337 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8338 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 8339 | &tp->counters_phys_addr, |
| 8340 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8341 | if (!tp->counters) |
| 8342 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8343 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 8344 | pci_set_drvdata(pdev, dev); |
| 8345 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8346 | rc = register_netdev(dev); |
| 8347 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8348 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8349 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 8350 | netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8351 | rtl_chip_infos[chipset].name, tp->mmio_addr, dev->dev_addr, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8352 | (u32)(RTL_R32(tp, TxConfig) & 0x9cf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 8353 | pci_irq_vector(pdev, 0)); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8354 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 8355 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 8356 | "tx checksumming: %s]\n", |
| 8357 | rtl_chip_infos[chipset].jumbo_max, |
| 8358 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 8359 | } |
| 8360 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 8361 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8362 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8363 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8364 | netif_carrier_off(dev); |
| 8365 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8366 | if (pci_dev_run_wake(pdev)) |
| 8367 | pm_runtime_put_sync(&pdev->dev); |
| 8368 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8369 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8370 | } |
| 8371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8372 | static struct pci_driver rtl8169_pci_driver = { |
| 8373 | .name = MODULENAME, |
| 8374 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8375 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8376 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 8377 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8378 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8379 | }; |
| 8380 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 8381 | module_pci_driver(rtl8169_pci_driver); |